Store variable value to recover after reset

Status
Not open for further replies.

jesusangel

Active member
Hello, I have a teensy 3.2 project working correctly for a few years with spi flash to store supplied amount, until the process starts I can save user and date and after the process stops I save this amount, but if a energy's cut occurs I can't know that value.

In a normal process the electronic can store that value houndred times, so writing this value to spi flash to recover after reset will cause to waste the maximum number of writing/erase allowed by the flash memory after some time of working.

Is there a way to store that value in a part of internal memory that stays non-volatile after reset/reboot and that don't degrade the memory?

Thank you in advance
 
Thank you for your answer, I know about internal eeprom of the teensy as a part of the flash memory, The problem is the endurance, you can only write 100.000 times.

I was thinking in some memory as other chips have a reset reason, so after rebooting you can know if it was a soft reset, watchdog, power cut, etc.

Regards

For Teensy 3.2, 3.5, and 3.6 there is a separate memory called EEPROM:

For the Teensy LC, 4.0, and 4.1, the EEPROM library uses the flash memory the program and initial variable contents are stored in.
 
Last edited:
If the T_3.2 had an RTC battery it may have some storage bytes kept alive. I know the T_3.6 does. Not sure if that section functions without the crystal installed.
 
If the T_3.2 had an RTC battery it may have some storage bytes kept alive. I know the T_3.6 does. Not sure if that section functions without the crystal installed.

Thank you for your time, yes, it has RTC battery and crystal intalled to maintain time while not connected to power. Any advice where to start?
 
Thank you for your time, yes, it has RTC battery and crystal intalled to maintain time while not connected to power. Any advice where to start?

It has probably been too long and non-specific keyword to forum search - not sure if the sample was T_3.6 or other - it was by 'Frank B'. The Manual PDF will have some section on the RTC areas. I found Manual notes for the T_4x's 1062 and got a couple bytes to work.
 
Thank you for your time, yes, it has RTC battery and crystal intalled to maintain time while not connected to power. Any advice where to start?

This is a guess, only a guess, do not pass go... ;)

But looking at the startup code for T3.x code yyou see:
Code:
#if defined(KINETISK)
	// RTC initialization
	if (RTC_SR & RTC_SR_TIF) {
		// this code will normally run on a power-up reset
		// when VBAT has detected a power-up.  Normally our
		// compiled-in time will be stale.  Write a special
		// flag into the VBAT register file indicating the
		// RTC is set with known-stale time and should be
		// updated when fresh time is known.
		#if ARDUINO >= 10600
		rtc_set((uint32_t)&__rtc_localtime);
		#else
		rtc_set(TIME_T);
		#endif
		[COLOR="#FF0000"]*(uint32_t *)0x4003E01C = 0x5A94C3A5[/COLOR];
	}
	if ((RCM_SRS0 & RCM_SRS0_PIN) && [COLOR="#FF0000"](*(uint32_t *)0x4003E01C == 0x5A94C3A5)[/COLOR]) {
		// this code should run immediately after an upload
		// where the Teensy Loader causes the Mini54 to reset.
		// Our compiled-in time will be very fresh, so set
		// the RTC with this, and clear the VBAT resister file
		// data so we don't mess with the time after it's been
		// set well.
		#if ARDUINO >= 10600
		rtc_set((uint32_t)&__rtc_localtime);
		#else
		rtc_set(TIME_T);
		#endif
		[COLOR="#FF0000"]*(uint32_t *)0x4003E01C = 0;[/COLOR]
	}
#endif

I like magic numbers ;)
So if you look at the T3.2 or in my case t3.6 manual for memory locations you see: 0x4003_E000 62 VBAT register file
And I only see this one memory location (4 bytes) referenced in the source.

How much space is available does anyone else use it or the like not sure.

But that is where I would start.

Edit: T3.6 manual 4.15 (VBat register file)

This device includes a 128-byte register file that is powered in all power modes and is powered by VBat

it is only reset during VBAT power-on reset
 
Status
Not open for further replies.
Back
Top