cancel
Showing results for 
Search instead for 
Did you mean: 

SPI/DMA error on STM32F4

Tamás
Associate II

I'm trying to implement an SPI slave using DMA on a NUCLEO-F429ZI board. It basically works but when transactions from the master come too often (about 1ms) I start getting SPI overrun errors (i.e. HAL_SPI_ErrorCallback() is called). I would like to know if I'm doing anything wrong using HAL. I have attached my main.c and stm32f4xx_hal_msp.c. I've been struggling with this for a while to find the problem, so any help is appreciated. Thank you!

3 REPLIES 3
S.Ma
Principal

Here is how I do:

DMA is in cyclic mode, no interrupt (TX and RX, SPI 4 wires)

Add EXTI interrupt on NSS signal, rise and fall edge. (even though HAL doesn't provide this feature, if NSS is HW Alternate function, however it works in the silicon)

Master should pause between NSS toggle and SCK activity for EXTI interrupt to be processed.

Maybe you init DMA on NSS rise or fall edge depends on application scheme.

Thanks for your reply. Do you suggest setting hspi1.Init.NSS = SPI_NSS_SOFT (not to use hardware NSS)?

S.Ma
Principal

Behaviour of NSS for Slave is to automatically cut MISO MOSI if there are multiple slaves around.

Then it's an alternate function and you'll need to activate EXTI on this pin.

You'll get a callback interrupt when there is a falling edge (then you can setup the DMA pointers to the beginning of a rolling SRAM buffer), and process what you have received at NSS rising edge... this is application specific, the described scheme works for me. Others exists...