How to reboot Teensy 3.x without editing Watchdog

Status
Not open for further replies.

jwatte

Well-known member
I want to reboot a Teensy 3.2 and a Teensy 3.5 (separately) from software.

There is a thread on how to do this using the watchdog. Unfortunately, this requires editing the .c files in the teensyduino installed files, which means that any other project compiled by the same installation now needs to kick the watchdog every so often.

Is there another way to, effectively, restart my code?
I don't actually need a full hardware power cycle; I would be OK with something similar to:
- clearing BSS to 0
- unpacking initialized data
- re-setting stack back to the beginning
- turning off interrupts and whatever else is needed for start to be happy
- jumping to code start

The reason is, I have a carrier board where the chip can pull its own power switch. This works great when powered from battery, but when powered from the USB, the power doesn't actually turn off when the battery switch turns off. For various reasons, I'd rather the code got rebooted, and I can catch this state after boot by reading the effective battery voltage.
 
What needs to be changed? Just glancing at "I:\arduino-1.8.1\hardware\teensy\avr\cores\teensy3\mk20dx128.c" I see: void watchdog_isr(void) __attribute__ ((weak, alias("unused_isr")));

Which says 'weak' so you can write your own local code that the linker will pick up.

Also for needed connections there is this code and note:
Code:
	void startup_early_hook(void)		__attribute__ ((weak, alias("startup_default_early_hook")));
// ...
	// programs using the watchdog timer or needing to initialize hardware as
	// early as possible can implement startup_early_hook()
	startup_early_hook();

Perhaps other elements - but from quick scan it looks like it is meant to be usable with only user code changes?
 
Oh, that seems like just what I need!
I'm surprised the Googles didn't point that out, and sent me to a bunch of Watchdog pages instead.
Thanks for the assist.
 
Status
Not open for further replies.
Back
Top