Skip to main content
DavePfz
Associate III
June 29, 2026
Solved

Using QSPI with FreeRTOS

  • June 29, 2026
  • 5 replies
  • 104 views

I am trying to adapt the QSPI Flash (QSPI_MemoryMapped) example found in the STM32WB5MM-DK to run with FreeRTOS. My hardware uses different ports for the QSPI connection but all has been set up through the ST32CubeMX program.

What I did then was to copy the code from the example into my project as a FreeRTOS task. However, the code pulls in some header files that don’t make sense to me. For example: stm32wbxx_hal_tim_ex.h results in the error “unknown type name 'HAL_StatusTypeDef”

I’m not sure why this is happening, or even why this header file is being pulled int, I so would appreciate any pointers. My guess is that is has to do the the HAL timer versus the FreeRTOS timer, but even then don’t know were to look!

Since I am using the flash without a fie system, maybe the QSPI_ReadWrite_DMA or QSPI_ReadWrite_IT would be better. If so, please suggest...

Thanks

Best answer by DavePfz

I don’t know if this solves all of my problems, but I can now compile without errors. The order of the include files is important. It must be:

#include "stm32wbxx_hal.h"

#include "stm32wbxx_hal_def.h”

Still open to suggestions!

5 replies

DavePfz
DavePfzAuthorBest answer
Associate III
June 29, 2026

I don’t know if this solves all of my problems, but I can now compile without errors. The order of the include files is important. It must be:

#include "stm32wbxx_hal.h"

#include "stm32wbxx_hal_def.h”

Still open to suggestions!

Pavel A.
June 29, 2026

> Still open to suggestions!

In memory-mapped mode, the QSPI controller automatically reads the flash, there are no interrupts that need attention of the program. 

But note that QSPI flash in memory-mapped mode is not writable. If you need to write, you switch to “indirect” mode, do the write and return to the memory-mapped mode. Obviously, the code doing this cannot run off the memory-mapped flash. Any RTOS task that can touch the memory-mapped area needs to be blocked during this time.

 

 

DavePfz
DavePfzAuthor
Associate III
June 30, 2026

Can you provide more detail? When I look at the example, which runs OK on the STM32WB5MM-DK, I don’t see sch a change.

Thanks

Pavel A.
June 30, 2026

Answer of the sidekick AI:

“In QUADSPI/QSPI memory-mapped mode, the external memory is intended for read access only; write operations are not supported in memory-mapped mode and must be done using indirect mode instead.

Detailed Explanation:


In memory-mapped mode, the QUADSPI interface makes the external Quad-SPI memory appear like internal memory on the bus, so it can be accessed directly by AHB masters and used for continuous reads and execution in place (XIP).

However, this mode is strictly limited to reading the external memory contents.
If you need to program, erase, or otherwise write to the external flash, you must switch to indirect mode, where transfers are managed through the QUADSPI registers by software or DMA.”

 

DavePfz
DavePfzAuthor
Associate III
July 2, 2026

No need to repeat what you said earlier. A close examination of the code provided in the example shows that for write operations it does call HAL_QSPI_Transmit_DMA() which implements indirect write mode.