Skip to main content
Graduate II
May 30, 2023
Question

Does anyone know of an example showing SPI implemented with DMA on freeRTOS? I was not able to get this running. When I check the data variable in DMA2_Stream0_IRQHandler, it is always 0 when I expect it to be 1. I'm using the STM32F407G DISCO.

  • May 30, 2023
  • 5 replies
  • 1248 views

I have SPI set in Master Receive Mode Only and my code does work when not passing data to DMA.

    This topic has been closed for replies.

    5 replies

    ST Employee
    May 30, 2023

    Hello @LMorr.3​,

    Have you checked the CubeFW example of SPI data buffer transmission and reception with DMA?

    It's not with freeRTOS though

    LMorr.3Author
    Graduate II
    May 30, 2023

    Thanks, I'm looking at that sample code now. One issue is that I'm not clear on what libraries I should be using. HAL libraries are discouraged, which leave me with bare-metal. I wish someone would just post a simple explanation on how CMSISV1, CMSISV2, HAL, LL, and all the other 'libraries' work together and which ones are deprecated. Seems like a very messy approach grown over the years by folks who are way to deep to get a new-comer's eye view on getting setup. All official docs recommend HAL but then sample code now shows library usage I've not come across yet ( LL_ ) so I'll have to learn about that before I can proceed. Still not sure if I should now focus on coding with LL instead of bare metal, CMSIS or HAL.

    LMorr.3Author
    Graduate II
    May 30, 2023

    To partly answer my own questions: HAL does not seem to support DMA for Master receive only mode. Its functions expect DMA to be setup for tx as well or exits with HAL_ERROR. Will look at using CMSIS to see if that helps.

    Also, I think LL is no longer supported.

    LMorr.3Author
    Graduate II
    May 30, 2023

    UPDATE:

    I always see hdmarx status 'HAL_DMA_STATE_ABORT' in DMA2_Stream0_IRQHandler each time I call HAL_SPI_Receive_DMA(hspi,pData, Size)

    Not sure what would cause that.

    LMorr.3Author
    Graduate II
    June 1, 2023

    I am all set now, thanks!