Skip to main content
Associate
October 15, 2024
Solved

Apparent error on the HAL SPI library when using DMA.

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.
Imen.DBest answer
ST 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.

 
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks

3 replies

Andrew Neil
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?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
EngScnAuthor
Associate
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.DBest answer
ST 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.

 
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks