AnsweredAssumed Answered

stm32f4xx_hal_spi.c, HAL_SPI_TransmitReceive - conversion of HW register pointer

Question asked by Marcin Wolcendorf on Jun 4, 2018
Latest reply on Jun 6, 2018 by Marcin Wolcendorf

Hi Everyone,


In HAL_SPI_TransmitReceive, around line 937, there is a gem like that:

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

Isn't it a bit dangerous to convert the HW register, which always have a specific size and  usually also access restrictions (in case of DR - reading it will delete the received data, for example), instead of converting the data read from the buffer? Wouldn't it be better to have something like that instead:

hspi->Instance->DR = (uint32_t)(*pTxData);