Software reset Teensy 3.1

For my tank project it was useful to be able to sense when a reset signal is sent and restart the Teensy via software. A quick google later and I found this post by kam42, which describes a macro which does exactly what I needed.

For the sake of completeness, heres a full sketch that would reset every 5 seconds. Don’t do this as I doubt constantly restarting is particularly healthy for the chip.

[c]
#define CPU_RESTART_ADDR (uint32_t *)0xE000ED0C
#define CPU_RESTART_VAL 0x5FA0004
#define CPU_RESTART (*CPU_RESTART_ADDR = CPU_RESTART_VAL);

void setup() {
}

void loop() {
CPU_RESTART
delay(5000);
}
[/c]

This will break the USB serial connection, so your serial monitor will fail, and you’ll have to reconnect.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.