r/MSP430 • u/electr0mancer • Sep 06 '21
Memory access in MSP430 G2352
Hello,
I am trying to save the last state of a state machine. Now the problem is that if there is a power cut, the code starts from the beginning. Is there any way to access a memory location and to save the previous state of the system in that location so that even after there is a power cut, the machine goes back to the last state?
Thanks
3
u/txmail Sep 07 '21
Depending on your write frequency you might also want to look at adding a external FeRAM (FRAM) which will increase the endurance vs writing to flash.
1
u/electr0mancer Sep 09 '21
Hello,
I cant add external Flash for my application, but i am trying to limit the write cycles.
Thank you very much.
2
u/FUZxxl Sep 08 '21
You can erase and rewrite flash, but the number of cycles is limited. Refer to the documentation for details. Consider using a part with FRAM or an EEPROM if you want to write to non-volatile storage frequently.
1
5
u/hoshiadam Sep 06 '21
Yes, you can specify a memory range to use as storage, and then use Flash Read and Flash Write commands to load/write the state into flash memory.
Some things to consider/read up on:
Flash has limited write cycles. So if you are writing the state multiple times per second, you will want to write to a range of memory (like 1 page of flash memory, which for that device is 512 bytes).
If your state machine is slow / writes rarely, you could use the Information Memory, which is a section of Flash set aside for storing data. Each page in that is 64 bytes.
Any states that transition quickly probably should not be written to flash.
Remember to reinitialize all your variables when you go into your state as if you had entered it normally.