我正在使用此代码从具有 quad SPI 的闪存芯片读取数据:
- // send read command and read page data
- OSPI_RegularCmdTypeDef sCommand;
- memset(&sCommand, 0, sizeof(sCommand));
- sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
- sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
- sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
- sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
- sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
- sCommand.Instruction = CMD_FAST_READ_QUAD_OUTPUT;
- sCommand.AddressMode = HAL_OSPI_ADDRESS_1_LINE;
- sCommand.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE;
- sCommand.AddressSize = HAL_OSPI_ADDRESS_16_BITS;
- sCommand.Address = flashSource >> 11;
- sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
- sCommand.DataMode = HAL_OSPI_DATA_4_LINES;
- sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
- sCommand.DummyCycles = 8;
- sCommand.NbData = len;
- sCommand.DQSMode = HAL_OSPI_DQS_DISABLE;
- sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
- if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE)
- != HAL_OK) {
- error("HAL_OSPI_Command error");
- }
- if (HAL_OSPI_Receive(&hospi1, ramDestination,
- HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
- error("HAL_OSPI_Receive error");
- }
时钟是25 MHz,看起来是可以工作的,接收到的数据是我写给它的,但是读的时候有间隙:
我已经尝试启用 D-cache 和 I-cache,并在发布模式下编译它,但没有任何变化。目标 RAM 是 RAM_D1。我还在 CubeMX 中尝试了不同的“Fifo Threshold”设置,但没有任何变化。我怎样才能加快速度?
我在 HAL 代码中看到,每个字节都会调用 OSPI_WaitFlagStateUntilTimeout,这个函数看起来不太好。也许有人已经实现了更快的代码,或者总是会有差距,我需要一些不同的东西,比如 DMA 传输?