arm-none-eabi-gcc version 10.3.1 (but compiler does not matter)
Describe the bug
Calling function HAL_SPI_Receive_IT() or HAL_SPI_TransmitReceive_IT() with buffer not aligned to 16 bits crashes MCU
How To Reproduce
Call HAL_SPI_Receive_IT() with unaligned buffer and more then 1 byte to send
Additional context
Real problem however is in SPI_2linesTxISR_8BIT() function that tries to optimize send using 16 bits access if there is more data.
For Cortex-M0+ unaligned read results in fault.
static void SPI_2linesTxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
{
/* Transmit data in packing Bit mode */
if (hspi->TxXferCount >= 2U &&
((uint32_t)(hspi->pTxBuffPtr) & 1) == 0) // <= !!!! Additional check to use 8 bit for unaligned buffer here fixes the problem
{
hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr); // <= !!! Crashes here on Cortex-M0+
hspi->pTxBuffPtr += sizeof(uint16_t);
hspi->TxXferCount -= 2U;
}
...
Describe the set-up
Describe the bug Calling function
HAL_SPI_Receive_IT()
orHAL_SPI_TransmitReceive_IT()
with buffer not aligned to 16 bits crashes MCUHow To Reproduce
HAL_SPI_Receive_IT()
with unaligned buffer and more then 1 byte to sendAdditional context Real problem however is in
SPI_2linesTxISR_8BIT()
function that tries to optimize send using 16 bits access if there is more data. For Cortex-M0+ unaligned read results in fault.