Hardware reset on Teensy LC

Status
Not open for further replies.

sixeight

Well-known member
Is it possible to perform a hardware reset on the Teensy LC started from the code? I have a problem that hardware serial midi communication is lost every so often. The only solution so far is resetting the teensy. I would like to do this automatically.

On the Arduino forum thay recommend connecting an output pin to the reset pin, but I see no reset pin on the Teensy LC. (http://forum.arduino.cc/index.php?topic=49581.0)

How can I get this working? Any ideas?
 
If you look at the Teensy LC schematic, you'll see that the reset signal is not brought out to a pad, it just goes to the "bootloader KL02 chip" on the LC. So this method won't really work.

So far I've only discovered one method how to induce a reset on a LC, namely enabling the COP watchdog and letting it reset the chip. However that means that you have to manually "reset" the watchdog every second. The purpose of the watchdog is actually pretty much exactly your situation - it "watches" whether the program operates, assuming that when it does operate correctly, it does reset the watchdog every second.

If this "solution" would be good enough for you, I can post some concrete code (tomorrow, it's getting late).
 
For the record, here's a sample sketch:
Code:
void setup() {
  pinMode(13, OUTPUT);

  // blink a few times
  for(int i = 0; i<5; i++) {
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);

    // service the COP
    SIM_SRVCOP = 0x55;
    SIM_SRVCOP = 0xAA;
  }
  
  // COP is not serviced, the Teensy LC will reset within 1 sec
}

void loop() {
}

// redefine the startup_early_hook which by default
//  disables the COP
#ifdef __cplusplus
extern "C" {
#endif
void startup_early_hook() {
  // empty
}
#ifdef __cplusplus
}
#endif
Notes: You can also reset the Teensy at any time by writing an invalid value (i.e. not 0x55, 0xAA in this order) to SIM_SRVCOP.

By default, the COP needs to be serviced every second (2^10 cycles on 1kHz clock). This can be configured differently by changing SIM_COPC register, however this is the "longest" setting there is. See the KL26Z datasheet, section 3.4.10.2.

EDIT: This applies only to Teensy LC; 3.x also have a watchdog, but use different registers.
 
Last edited:
Ah, cool! I didn't realise that it also applies to M0+, since (as Paul mentioned elsewhere), Freescale does not describe (or even list) the SCB registers in the manual.

So, just to re-record the instruction from Paul on Adafruit forums:
Code:
// request reset
SCB_AIRCR = 0x05FA0004;
Works for me (on LC).
 
Thank you flabbergast and Paul. This works.

Thank you two from me too!

Came home today to find our humidifier on but no humidification happening. So I implemented this watchdog on her to reset it every second if it somehow gets stuck somewhere. I hope that fixes it... if not, I have to figure out why the code executes but the ultrasonics, etc. are not firing on demand...
 
Hardware reset on Teensy LC for a specified time

Thanks all for the contributions.

SCB_AIRCR = 0x05FA0004; works for a simple reset for Teeny LC.

I have a different requirement. (Ideally I want to press and hold the reset button for some specified time and release to emulate a USB keyboard hot plug/ device enumeration in device manager).
Since LC don't have the reset pin, is this possible with software?

Thanks in advance.
 
Status
Not open for further replies.
Back
Top