AnsweredAssumed Answered

dereferencing type-punned pointer warning on bare project

Question asked by Dave Jones on Mar 28, 2018
Latest reply on Mar 28, 2018 by Clive One

I decided to try out the new TrueStudio. Downloaded and installed it, and also updated STM32CubeMX to the latest, as well as all the latest firmware packages.


I then created a new Cube project for TrueStudio using the STM32L452 with a mix of HAL and LL.


When I compile the project (nothing added by me at this point) I get the following error:


dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]


It is on this code, which comes from stm32l4xx_ll_spi.h that is in the L4 firmware repository (v1.11.0)


__STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  *((__IO uint16_t *)&SPIx->DR) = TxData;


I assume it's because the DR register is defined previously as a __IO uint32_t


I know that it's a warning and not an error, but I really like to fix whatever causes warnings and get compiles without warnings. So, why is this happening on a virgin project created by CubeMX? And what is the suggested way to deal with it?