Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By jcmvbkbc
#10439
sshakuf wrote:I used the same code as before, I don't understand why was it not aligned ?
the same structure. same size.

Because its natural alignment is 1 byte: none of its fields needs bigger alignment. spi_flash_write apparently expects a buffer of uint32_t, and it must be aligned to 32 bits. So your structure may start at any byte, you was just lucky when it worked.

sshakuf wrote:Do you mean that the struct in the memory did not start in an aligned 4 bit address ?

4 byte. Yes.
User avatar
By scargill
#11903 If I may make a suggestion -go grab TUANs MQTT code - and in there go take a look at MQTT/config.c and mqtt/config.h - it's all in there, it's simple. He has used the area starting C000 to Ffff - a 16 BLock. He alternates between C000 and E000 I believe to store an updated STRUCT with all the vars in - I've added LOADS to his original. He uses F000 just as a toggle. So the idea is you store the block of vars at say C000 and when you do you tell F000 where to look. On next backup you store the block at E000 - and IF that is successful inform F to move and back and forth. So if a backup fails for any reason - power failure in the middle, the previous version continues to work, restored at power up - absolutely works a treat.

Now if someone can tell me how to put a lookup table in FLASH without it ever appearing in RAM (other than the one byte pulled out at each read) I'd be a happy man.
User avatar
By smarthousesys
#33852 Just been through this. What a total mess of misinformation and examples that just happen to work by chance. Both the read and write areas for system_rtc_mem_write/read must be 4 byte aligned. Use __attribute__((aligned(4))) if you want to force a buffer to 4 byte alignment e.g. char buff[32] __attribute__((aligned(4)));