AnsweredAssumed Answered

STM32F417: SPI via DMA

Question asked by winkler.tom on Nov 30, 2012
Latest reply on Nov 30, 2012 by Clive One
Dear STM324 Developers,


I'm working on a custom board based on the STM32F417 mcu. 
I want to connect my board to an other system via SPI2. This other system will act as SPI master (slave mode is not supported on this device) while the STM is slave. I'm so far only interested in data that is transmitted from the STM to the master and I'm ignoring all data coming in from the master.


I got the setup working based on SPI interrupts. The SPI clock (400kHz) is driven by the master.
My code for SPI interrupt based transfer of 16 bytes can be found in pastebin:
[[this link/image has been flagged as malicious by our security scan software and has been deleted]]


In the next step I wanted to add DMA but so far was unable to get it running.
My extended code which uses DMA for data reception can be found in pastebin:
[[this link/image has been flagged as malicious by our security scan software and has been deleted]]

Upon startup of the board I get a DMA interrupt DMA_FLAG_TEIF4 (transfer error). The interrupt is cleared by my code. The next thing I get is another interrupt: DMA_FLAG_FEIF4 (fifo error). After that the board is still alive (LED is toogled in the loop at the end of spi test function) but when I try to transfer data via SPI (i.e., master generates clock) nothing happens. I think that DMA is disabled due to the transfer/fifo error.
My understanding is that the DMA initially tries to fill the fifo. That's why I'm seeing DMA interrupts upon boot even though there is no active SPI clock at this point. However, filling the fifo seems to fail.
As an alternative I also tried "direct mode" (fifo disabled) but interestingly got the same result (transfer error followed by fifo error).
When I check the fill state of the fifo when getting the interrupts then the fifo state is reported as empty.


And one more observation: I also tried to reduce the DMA buffer size from 16 to 1 element. In this case I get one successful transfer (DMA_FLAG_TCIF4 = transfer complete) followed again by a DMA_FLAG_TEIF4 (transfer error) and a DMA_FLAG_FEIF4 (fifo error). In the DMA_FLAG_TCIF4 handler I reset the DMA buffer size and I also reset the memory base address.




All in all: I spent the past three days on getting the DMA for SPI2 working but so far without luck. I'd be happy if someone could point out what I might be doing wrong.


Thank you,
Thomas

Outcomes