Skip to main content
Graduate II
June 1, 2025
Question

How to modify stm32-w25qxx example code to use SPI with DMA ?

  • June 1, 2025
  • 1 reply
  • 684 views

I am using this example to read data from an external flash (W25Q128) using SPI on a NUCLEO-L433RC-P board...

https://stm32world.com/wiki/STM32_W25Qxx

The code is here...

https://github.com/lbthomsen/stm32-w25qxx

How do I modify this example to use SPI with DMA ?

The end result is to read a WAV file from the external flash and play it using the internal DAC.

I have enabled DMA for SPI...

freeflyer_0-1748781574422.png

 

But don't know what other modifications I need to make.

In w25qxx.c, I tried changing...

if (HAL_SPI_Receive(w25qxx->spiHandle, buf, len, HAL_MAX_DELAY) == HAL_OK) {

to...

if (HAL_SPI_Receive_DMA(w25qxx->spiHandle, buf, len) == HAL_OK) {

but when I step through the code it jumps to the HardFault_Handler.

I will need to use double DMA buffers, so that the DAC reads from one buffer whilst the external flash writes to the other buffer (for glitchless playback)

 

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    June 2, 2025

    Hello @freeflyer 

    Could you share your SPI and DMA setting please?


    @freeflyer wrote:

    but when I step through the code it jumps to the HardFault_Handler.


    On which instruction it goes to hardfault?

    Please refer to the article below to debug hardfault:

    How to debug a HardFault on an Arm® Cortex®-M STM3... - STMicroelectronics Community

    freeflyerAuthor
    Graduate II
    June 5, 2025

    I managed to fix it after trying lots of different things but cant remember how !