cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 SPI Transmit DMA

Castor Tindareus
Associate
Posted on April 06, 2017 at 16:15

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 )

{

   R

xCmpltFlag = 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?.

#bug #stm32f3 #dma #spi
0 REPLIES 0