AnsweredAssumed Answered

Modify of HAL library?

Question asked by Jang Wonyong on Apr 9, 2018
Latest reply on Apr 10, 2018 by Doug Kehn

HI,

I use SPI of HAL Library in STM32F0.
However, due to unaligned memory access, HardFault occurs in the HAL_SPI_TransmitReceive () function.
So I modified the HAL library as follows.

 

uint8_t data_lo, data_hi;

uint16_t data16;

 

//hspi->Instance->DR = *((uint16_t*)hspi->pTxBuffPtr); <-original

data_lo = *hspi->pTxBuffPtr;
data_hi = *(hspi->pTxBuffPtr + 1);
data16 = (uint16_t)data_lo | ((uint16_t)data_hi << 8);
hspi->Instance->DR = data16;

 

//*((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR; <-original

data16 = hspi->Instance->DR;
*hspi->pRxBuffPtr = (uint8_t)data16;
*(hspi->pRxBuffPtr + 1) = (uint8_t)(data16 >> 8);

 

However, if the HAL library is updated, it needs to be modified again. How can I use it without modification?

 

Translated into Google Translator.

Outcomes