cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f1 HAL SPI DMA with CRC timeout

Sandor Peli
Associate
Posted on April 28, 2017 at 10:40

I have two STM32F103 connected together with SPI in full duplex mode. They changing 700 halword with DMA and CRC enabled. The communication is fine (no crc or other error) but there is this line of code in the 

SPI_DMATransmitReceiveCplt() in the stm32F1xx_hal_spi.c which blocks the code till the SPI_TIMEOUT_VALUE. It is 10 ms. What is the meaning of this blocking? If I change this value to 1 on booth controller it even works fine, but it allways wait till the timeout. I don't want to waste here so many time.

May I lower this timeout or set it 0? Or despite the proper CRC there is some kind of error during the communication which cause this hanging?

/* CRC Calculation handling */

if(hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)

{

/* Check if CRC is done on going (RXNE flag set) */

if(SPI_WaitOnFlagUntilTimeout(hspi, SPI_FLAG_RXNE, SET, SPI_TIMEOUT_VALUE) == HAL_OK)

{

/* Wait until RXNE flag is set to send data */

if(SPI_WaitOnFlagUntilTimeout(hspi, SPI_FLAG_RXNE, RESET, SPI_TIMEOUT_VALUE) != HAL_OK)

{

SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);

}

}

/* Read CRC */

tmpreg = hspi->Instance->DR;

UNUSED(tmpreg);

/* Check if CRC error occurred */

if(__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_CRCERR) != RESET)

{

SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC);

__HAL_SPI_CLEAR_CRCERRFLAG(hspi);

}

}

#crc #timeout #spi
0 REPLIES 0