2017-01-30 01:24 AM
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','?'};