AnsweredAssumed Answered

STM32F3 SPI Transmit DMA

Question asked by Castor Tindareus on Apr 6, 2017

Hello! I use dma on spi3 rx & tx (STM32F302K8U6). When I call HAL_SPI_Transmit_DMA before HAL_SPI_Receive_DMA data from slave came damaged. Pseudocode:

void WriteFifo( uint8_t * buf, uint16_t size )

{

   TxCmpltFlag = 0;

   __START_SPI_TRANSACTION; // Software NSS

   HAL_SPI_Transmit_DMA( &hspi3, buf, size );

}

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{

   __STOP_SPI_TRANSACTION; // Software NSS

   TxCpmltFlag = 1;

}

void ReadFifo( uint8_t * buf, uint16_t size )

{

   RxCmpltFlag = 0;

   __START_SPI_TRANSACTION; // Software NSS

   HAL_SPI_Receive_DMA( &hspi3, buf, size );

}

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{

   __STOP_SPI_TRANSACTION; // Software NSS

   Pseudocode

}

void Proc( void )

{

   if( NeedTx&RxCmpltFlag&TxCmpltFlag ) WriteFifo( Tbuf, size);

   if( NeedRx&RxCmpltFlag&TxCmpltFlag) ReadFifo( Rbuf, size);

   

}

I found it when start to use FW 1.7.0 for STM32F3 in Cube MX 4.20.0. This fixed by add following code in line 3608 of stm32f3xx_hal_spi.c

 

if(SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_EMPTY, Timeout, Tickstart) != HAL_OK)
{
   SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   return HAL_TIMEOUT;
}

 

I did't have this problem on FW 1.3.0 for STM32F3. Maybe there's a bug in FW 1.7.0? or  how to use HAL Drivers correct?.

Outcomes