Hello Mates,
Compiler is the GNU C for arm
IDE is STM32CubeIDE
I have all my non volatile data in a struct, this struct is loaded from the eeprom during power on cycle, to keep data integrity I'm using a CRC in the struct end
When turning on the device I read the EEPROM from my choosen address + the config size to buffer
Load the buffer to the struct using memcpy
Calculate the buffer CRC, which is all the data except the last two bytes (short int) which is the CRC and compare with the struct CRC.
But GNU C compilers uses struct padding and automatic alignment (which is the change in position of datatypes to better fit the data in memory, optimizing it access), so the last variable in your struct not necessarily is the last byte in the struct memory.
So, how should I approach this? Should I do my CRC calculation out of the struct? Like the next byte or so?