cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 SPI with DMA is not working, Transmit only used. stuck at HAL_SPI_STATE_BUSY_TX

JohnsAby
Associate II

I have done the implementation of 3 wire SPI using DMA and when I do SPI transfer using

HAL_SPI_Transmit_DMA(&SPIx_handle, (uint8_t *)TxBuffer, 8u); the HAL_SPI_GetState(&SPIx_handle) is stuck at HAL_SPI_STATE_BUSY_TX.

Not changing the state.

My configuration of SPI and DMA is similar to this query : STM32F405 SPI Transmit using DMA not working

Thanks in advance

Edit: First time posting query here, if anything needed additionally please comment

Edit 2: Earlier mentioned HAL_SPI_STATE_BUSY, updated to HAL_SPI_STATE_BUSY_TX

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> Issue is when the NSS is high, Clock also present. 

The "NSS" signal on the STM32F4 is not a CS signal. It pulses at the end of each byte in TI mode, which is presumably what you have selected. You'll need to use a different method.

0693W00000GY2xbQAD.png 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

24 REPLIES 24
TDK
Guru

Ensure MX_DMA_Init is called before MX_SPI_Init.

If that's not it, show how you're using it or post the SPI and DMA register values.

If you feel a post has answered your question, please click "Accept as Solution".

Hi TDX,

Thanks for the response.

MX_DMA_Init is done before MX_SPI_Init

DMA2 Stream 4 and SPI5 is used.

0693W00000GXbLuQAL.png0693W00000GXbLVQA1.png 

please find the above images attached.

TDK
Guru

The DMA stream isn't enabled. Might be some flags set in DMA2_HISR.

Since NDTR=0, it could be that the transfer is complete, but you don't have the DMA transfer complete interrupt implemented or handled correctly, or interrupts are disabled.

If you feel a post has answered your question, please click "Accept as Solution".

0693W00000GXj7qQAD.pngHi TDK,

Thanks for the response.

DMA stream is Enabled and TC and HF bits in HISR are getting set after Transfer.

NDTR is getting populated during transfer.

Still then

_inline_ static void spi5_dataTransfer(uint16_t *TxBuffer)
{
  HAL_GPIO_WritePin(SPIx_NSS_Port, SPIx_NSS_Pin, GPIO_PIN_RESET);
  HAL_SPI_Transmit_DMA(&SPIx_handle, (uint8_t *)TxBuffer, 8u);
  HAL_GPIO_WritePin(SPIx_NSS_Port, SPIx_NSS_Pin, GPIO_PIN_SET);
  while (HAL_SPI_GetState(&SPIx_handle) != HAL_SPI_STATE_READY);
}

the control is not stopping at while(mentioned above).

And SPI state remains in "HAL_SPI_STATE_BUSY_TX" state.

Please help me to understand, what made you think "but you don't have the DMA transfer complete interrupt implemented or handled correctly, or interrupts are disabled".

Kindly reply, its helping me to understand more.

You appear to try to use SPI with CRC, is it intentional?

Do you use C++?

JW

TDK
Guru

Since TCIE is set and TCIF is set, and the cpu isn't jumping into the handler, the corresponding NVIC enable bit isn't set, interrupts are disabled, or a higher priority interrupt is being ran.

If you feel a post has answered your question, please click "Accept as Solution".

Hi JW,

Thanks for the response

I use C language.

My SPI is configured without CRC (SPI_CRCCALCULATION_DISABLE)

Hi TDK,

Thanks for the response

The NVIC is enabled, I will check by modifying interrupt priority.

Sorry I misread the bits in SPI_CR1, indeed, you don't have CRCEN set (rather, BIDIMODE and BIDIOE).

JW