cancel
Showing results for 
Search instead for 
Did you mean: 

SPI4 Rx DMA doesn't work on STM32F4

diverger
Associate III
Posted on September 11, 2017 at 10:03

My tool chain is STM32F429 with STM32CubeMX, and MDK.

I'm using SPI4 to read data from a ADC, though I configure SPI4 as 'duplex master',  I only need to read from it. When not using DMA, I call 'HAL_SPI_Receive()' to read data. And there are clock output on SPI_SCK pin. But when I configure it to use DMA (DMA2 Stream 0, P2M, PSIZE = 16bit, MSIZE = 16bit), and after calling '

HAL_SPI_Receive_DMA' 

nothing output on SPI_SCK pin.  As known, DMA only start after data received, so I don't think the problem is in my DMA configuration. The key point is why there is no clock output on SPI_SCK pin. 

 

It seems

'HAL_SPI_Receive()' will send some dummy bytes to slave and at the same time read back some data. Won't  'HAL_SPI_Receive_DMA()' send dummy bytes?

#willitblend #stm32f4 #spi #dma
6 REPLIES 6
Posted on September 11, 2017 at 13:22

An SPI Master would need to be generating output traffic for the clock to be generated, being a symmetrical bus.

DMA for TX and RX are independent, I'd expect you'd need to set both of them up, and have a block of dummy data if that's what you need to send.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on September 12, 2017 at 03:24

Yes, I must enable DMA for both Tx and Rx, and call 'HAL_SPI_TransmitReceive_DMA()'.  Then the clocks will appear on SCK pin.

What misleading is '

HAL_SPI_Receive()' will send dummy bytes, but the 'DMA' version won't!!!! 

Posted on September 27, 2017 at 10:27

I have the same problem. To use HAL_'SPI_Receive_DMA()' I have to configure also DMA for TX. Moreover 'SPI_Transmit_DMA()' does not work at all. I get HAL_'SPI_ERROR_DMA'. Problem only occurs on SPI4 when I used SPI5, DMA work correctly.

170009CGIL4
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 22, 2018 at 16:00

Hi, I am also facing same problem by seeing your post

==>

An SPI Master would need to be generating output traffic for the clock to be generated, being a symmetrical bus.

DMA for TX and RX are independent, I'd expect you'd need to set both of them up, and have a block of dummy data if that's what you need to send.

<==

It is resulting in hardfault have any one faced this problem.

Posted on June 22, 2018 at 17:18

>>It is resulting in hardfault have any one faced this problem.

Yes, usually by not touching memory addresses that I shouldn't. Identify what your faulting code is doing.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..