cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset Emulated EEPROM (in MCU Flash) when new code is uploaded?

JokerJok
Associate II

Title edited to make clear that this is emulated EEPROM - in the MCU's Flash.


How to reset the EEPROM every time a new code is uploaded?

Is this possible? 

Thank you very much.

 

8 REPLIES 8
urbito
Senior

Hello Joker,

 

Just as an example:

urbito_0-1740472779103.png


You have to find the datasheet for your EEPROM chip and find the Erase Operation command, so in your microcontroller you can send it.

For example, you check in your eeprom for a value that must be FF, if it is not FF, you clean the EEPROM.

 

Hope it helps.

 

Greetings

Hi, thanks for the answer, will the operation be performed only when uploading new code, or every time the MCU is booted?

urbito
Senior

It's up to you and how you make the code work.

My words refer to the hypothetical case where you write your own code to check the EEPROM every time the MCU boots.

Best regards.

You have to write the code to do it - so it will happen whenever you code it to happen!

 

You need to give more details about your system.

JokerJok
Associate II

my MCU is: stm32f030rct

JokerJok_0-1740488653256.png

These are the addresses I want to reset their contents every time I upload new code.

I have some BYTEs that I store in EEPROM, and I reload them every time I boot the system.

But while I'm uploading new code, I would be happy if it were possible to reset the EEPROM every time I write code.

Thanks!

Perhaps use __TIME__ preprocessor define, and mark as a tag in EEPROM. Check if is consistent, erase and re-tag when it's different. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Again, please see How to write your question to maximize your chances to find a solution. It tells you how to properly insert source code  - not as screenshots.

See also: How to insert source code.

 


@JokerJok wrote:

These are the addresses I want to reset their contents every time I upload new code.


Right: so you're not actually using an EEPROM at all - you're emulating EEPROM in the microcontroller's Flash memory!

If you want to erase this emulated EEPROM when reprogramming, just do a complete chip erase before programming. Or, at least, ensure that the part of the Flash used by the emulated EEPROM gets erased during programming.