cancel
Showing results for 
Search instead for 
Did you mean: 

dereferencing type-punned pointer warning on bare project

Dave Jones
Associate III
Posted on March 28, 2018 at 20:53

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?

3 REPLIES 3
Posted on March 28, 2018 at 20:57

This keeps being reported, the problem is that GNU/GCC is complaining about a valid casting construct. ie Hey something looks odd here, take a look to see if it describes what you want. And yes, it instructs it to do what we want without creating some unnamed union/structure which other compilers will reject.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III
Posted on March 28, 2018 at 21:14

I really like to fix whatever causes warnings

Well, the message is from GCC - so nothing specific to ST.

The way to find out about GCC warnings is to stick the message into google; in particular, the bit in the square brackets:

[-Wstrict-aliasing]

which is telling you the command-line option which controls this warning.

Note: when Googling, you need to omit the hyphen - otherwise Google takes that to mean 'exclude this term from the search'

Thus: 

https://www.google.co.uk/search?q=Wstrict-aliasing