Skip to main content
Senior II
June 1, 2025
Question

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

  • June 1, 2025
  • 2 replies
  • 1788 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.

2 replies

ST 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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
freeflyerAuthor
Senior II
June 5, 2025

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