Skip to main content
Graduate
July 17, 2025
Solved

SPI with DMA failing on second pass

  • July 17, 2025
  • 2 replies
  • 356 views

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

 

 

    This topic has been closed for replies.
    Best answer by Saket_Om

    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.

    2 replies

    Saket_OmAnswer
    Technical Moderator
    July 18, 2025

    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.
    VOAuthor
    Graduate
    July 18, 2025

    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.