cancel
Showing results for 
Search instead for 
Did you mean: 

SPI with DMA failing on second pass

VO
Associate III

I'm looking for some guidance on using DMA with SPI. I have the M4 core on an STM32H755 set up as a master in full duplex mode, and as long as I invoke the SPI transfer using interrupts, the program runs fine. When I try to migrate to DMA, however, I note that the program is successful on the first pass only, triggering the callback, etc., but on the second time through, I always get an error, apparently because the transmit is still busy (?) I have used SPI and DMA often before without incident, but I don't know what else to check in this case. Any insights are appreciated. See the screen shots of where the code is finally failing. Line 2508 is in the HAL SPI driver C file, the point at which the driver attempts to start the DMA with IT, and the second shot shows the result of this call in the HAL DMA file, line 695.

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello @VO 

It appears that the DMA peripheral is currently engaged with another task or has not been properly unlocked after the initial SPI DMA transfer. I recommend investigating the following areas:

  • Verify if the DMA channel is still active or busy from a previous operation.
  • Ensure that the DMA transfer complete flags are properly cleared.
  • Confirm that the DMA peripheral is correctly unlocked or reset before initiating a new transfer.
  • Check for any potential conflicts with other peripherals sharing the same DMA channel.
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

View solution in original post

2 REPLIES 2
Saket_Om
ST Employee

Hello @VO 

It appears that the DMA peripheral is currently engaged with another task or has not been properly unlocked after the initial SPI DMA transfer. I recommend investigating the following areas:

  • Verify if the DMA channel is still active or busy from a previous operation.
  • Ensure that the DMA transfer complete flags are properly cleared.
  • Confirm that the DMA peripheral is correctly unlocked or reset before initiating a new transfer.
  • Check for any potential conflicts with other peripherals sharing the same DMA channel.
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
VO
Associate III

Thank you. It seems there was something interfering with the transfer complete flag, or else, as you mentioned, the unlock was not working correctly. It is hard to say which, so I essentially started fresh from a known good state and now the DMA is working as it should.