cancel
Showing results for 
Search instead for 
Did you mean: 

BUG on stm32f0xx_hal_spi.c V1.5.0

matteo239955_st
Associate II
Posted on January 30, 2017 at 10:24

If you start a transfer on SPI with not aligned byte array could be generated a Fault!

Incredible... 

unsigned char FirstArray[5] = {'c','i','a','o','!'};

unsigned char SecondArray[5] = {'c','i','a','o','?'};

while(HAL_SPI_Transmit(&hspi1, (unsigned char *)

FirstArray

, 5, 200) != HAL_OK);

while(HAL_SPI_Transmit(&hspi1, (unsigned char *)SecondArray

,

5

, 200) != HAL_OK); //BOOOOOOMMMMMMMMM

the problem is here:

line 594 - file stm32f0xx_hal_spi.c   V1.5.0

if ((hspi->Init.Mode == SPI_MODE_SLAVE) || (hspi->TxXferCount == 0x01))

{

if (hspi->TxXferCount > 1U)

{

/* write on the data register in packing mode */

hspi->Instance->DR = *((uint16_t *)pData);

pData += sizeof(uint16_t);

hspi->TxXferCount -= 2U;

}

else

{

*((__IO uint8_t *)&hspi->Instance->DR) = (*pData++);

hspi->TxXferCount--;

}

}

if the array is not aligned, when you try to cast to a pointer of 16bit, it generate a Fault Interrupt...

Bye.

walkaround:

__align(2) unsigned char FirstArray[5] = {'c','i','a','o','!'};

__align(2) unsigned char SecondArray[5] = {'c','i','a','o','?'};

0 REPLIES 0