Skip to main content
Visitor II
October 15, 2024
Solved

Apparent error on the HAL SPI library when using DMA.

  • October 15, 2024
  • 2 replies
  • 1252 views

Even after setting up a DMA stream to a SPI_RX DMA request, the HAL_SPI_Receive_DMA() function return error code 1 when called. I've solved this problem by also setting up a DMA stream to the SPI_TX request, even though I won't use it. 

Problem occurred when using SPI1 on Full-Duplex Master mode in the STM32F412 uC, STM32CubeIDE Version: 1.16.1

    This topic has been closed for replies.
    Best answer by Imen.D

    Hello @EngScn ,

    In Full-Duplex mode, both the TX and RX DMA streams need to be configured. 

    Ensure that the SPI is disabled before calling the HAL_SPI_Receive_DMA () function to avoid overrun errors.

     

    2 replies

    Super User
    October 15, 2024

    @EngScn wrote:

    Problem occurred when using SPI1 on Full-Duplex Master mode 


    Surely, in a Full-Duplex master, you would have to have a TX running - so the behaviour is as expected?

     


    @EngScn wrote:

    function return error code 1


    What does that code indicate?

    EngScnAuthor
    Visitor II
    October 15, 2024


    Surely, in a Full-Duplex master, you would have to have a TX running - so the behaviour is as expected?


    I would like to have only my RX using DMA. My TX would be transmitting data in polling mode. I believe this should justify using a DMA stream only to the RX channel?



    What does that code indicate?


    HAL_SPI_Receive_DMA() returns a HAL_StatusTypeDef, for code 1 that would be HAL_ERROR.

    Imen.DAnswer
    Technical Moderator
    October 15, 2024

    Hello @EngScn ,

    In Full-Duplex mode, both the TX and RX DMA streams need to be configured. 

    Ensure that the SPI is disabled before calling the HAL_SPI_Receive_DMA () function to avoid overrun errors.