2021-03-25 03:54 PM
I'm using this code to read from a flash chip with 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");
}
The clock is 25 MHz and looks like it works, the received data is what I wrote to it, but there are gaps when reading:
I already tried to enable D-cache and I-cache, and compiled it in release mode, but no changes. The destination RAM is RAM_D1. I also tried different "Fifo Threshold" settings in CubeMX, but no changes. How can I speed it up?
I saw in the HAL code that OSPI_WaitFlagStateUntilTimeout is called for each byte, and the function doesn't look nice. Maybe someone has already implemented faster code, or would there be always a gap and I need something different, like DMA transfer?
Solved! Go to Solution.
2021-04-02 12:45 PM
I found the problem. I forgot to click the "MDMA global interrupt" checkbox in CubeMX.
2021-04-01 10:42 AM
I tried HAL_OSPI_Transmit_DMA, but the HAL_OSPI_TxCpltCallback is never called. How do I need to configure the peripherals with CubeMX for it? Do I need to call anything else for it?
Is there a website with good documentation for the HAL functions? In the comments in the implementation file it says I should call HAL_NVIC_SetPriority and HAL_NVIC_EnableIRQ. I've enabled the "OCTOSPI1 global interrupt" in the "NVIC Settings" in CubeMX. Looks like it is not sufficient, still no callback called.
2021-04-02 12:45 PM
I found the problem. I forgot to click the "MDMA global interrupt" checkbox in CubeMX.