controlling auto reset in a teensy like the arduino mini pro

Status
Not open for further replies.

digitalstables

New member
Hello,
I want to migrate from an arduino mini pro to a tensy 3.2. My problem is that I think i need the reset function. Let me explain.

The arduino boards have a peculiarity that they reset themselves when they accept a serial connection. If you put a capacitor between reset and ground, it makes so it does not auto-reset. I take advantage of this to increase the security of my application, so this function is critical to move away from the arduino mini pro to the Teensy.
What i do is that i put a capacitor between the reset pin and a toggle switch. From the other side of the switch i go to ground. I measure the voltage of the point where the capacitor meets the a switch and i use that value to allow or deny functions sent via the serial port. I call the capacitor, the "Lock Capacitor", because it functions as a lock.
I am building an application where the arduino controls the power to the raspberry pi. The cool thing about the setup, is that if the switch is set so that the arduino autoresets, the pi would just keep rebooting itself. If it set the other way, then the pi will function normally but you will not be able to do certain functions. Essentially, even if a hacker was to take control of the pi, they could not, remotely,modify the firmware.

I really hope i can do something like this with the teensy, because from the specs, it is perfect for my app. The memory is killing me in the Arduino Mini Pro , and I could use a second serial port. Also, I apologise if this is the wrong forum for this question.

Thanks
 
There was a post regarding this recently by Paul (this week past days it seems) - if the Teensy is running Serial USB code the RESET function is triggered there. If that is removed it won't reboot on command from the host. Ideally you could add in private code to decide how to respond as desired.

FOUND THE LINK :: pjrc.com/threads/55523-Teensy-3-2-Lock-Bits-and-firmware-updates

just over a week ago ...

... Funny it was easier to search the source for the function then use that keyword to search the forum - than search the forum back that far ...
 
Last edited:
thanks for that, it does not seem to be what i was looking for, since messing with the security bytes can brick the hardware. I wonder if Paul as any suggestion on how to simulate the same behaviour. I read that the Teensy 3.0 still has a reset pin. Perhaps I could use that? I really need 64kb of ram, i cant shrink my code to the mini pro 32 with out stripping functionality.
Any other suggestions would be appreciated
 
thanks for that, it does not seem to be what i was looking for, since messing with the security bytes can brick the hardware. I wonder if Paul as any suggestion on how to simulate the same behaviour. I read that the Teensy 3.0 still has a reset pin. Perhaps I could use that? I really need 64kb of ram, i cant shrink my code to the mini pro 32 with out stripping functionality.
Any other suggestions would be appreciated

That wasn't the key part of that link - as I understood the issue. The linked post does not relate to the security bytes ...

The linked post as indicated above - shows where in the code the Teensy responds to 'usb request' to go into bootloader mode. If you take that out completely it takes a physical button press to program as the linked post indicates. However you could selectively alter that based on input and code in any chosen fashion.
 
The arduino boards have a peculiarity that they reset themselves when they accept a serial connection. If you put a capacitor between reset and ground, it makes so it does not auto-reset.

Arduino Pro Mini connects the serial DTR signal to the AVR's reset pin, using a 0.1uF capacitor. Many 6-pin serial cables connect RTS to that pin, rather than DTR. Whatever signal connect to that pin, when it makes a high-to-low transition the AVR chip get a reset pulse and reboots.

The default behavior of serial ports is for DTR and RTS to be logic high when the port is not in use by any application. When an application opens the port, DTR goes low to indicate a program on the PC side is using the port. RTS is a little more complicated. The Arduino software does special steps to make RTS behave the same way as DTR, because so many people connect their Pro Mini or similar boards to FTDI-like 6 pin cables where RTS is on the 6th pin, rather than DTR as the Pro Mini was designed to use.

If you use other software, it may handle RTS different. It RTS/CTS flow control is turned on, it'll play havoc with a Pro Mini which is connected by one of those cables.

I'm explaining all this, partly so you can understand what's really happening, partly so there's a searchable message with this info and how it relates to Teensy, and maybe even so you can consider whether this really provides the security you desire.

Teensy does NOT reboot when DTR or RTS change. A different approach is used.


What i do is that i put a capacitor between the reset pin and a toggle switch. From the other side of the switch i go to ground. I measure the voltage of the point where the capacitor meets the a switch and i use that value to allow or deny functions sent via the serial port. I call the capacitor, the "Lock Capacitor", because it functions as a lock. .... Essentially, even if a hacker was to take control of the pi, they could not, remotely,modify the firmware.

The good news is Teensy's auto-reboot is implemented completely in software, so you can change it to whatever you like only by editing code. There's no need for a capacitor other other circuitry to be added.

However, this code is buried in the core library. Make sure you keep a backup copy, since installing a new version of Teensyduino will refresh all those core lib files.

Teensy actually uses 2 different auto-reboot methods, depending on whether it's implementing USB serial. If you haven't used Teensy yet, one of the features that's quite different from Arduino is the Tools > USB Type menu. The default in that menu is "Serial" so you get a USB device very similar to regular Arduino. But you can choose many other things, some without Serial. In those non-Serial cases, a USB HID interface is added to emulate serial, so you can still use Serial.print(). In those cases, auto-reboot is done with a HID feature report.

In the Serial mode, Teensy uses a baud rate command. If the PC tries to set the baud rate to 134 (a speed pretty much nobody ever uses, but works on all operating systems - even older Macintosh where the driver only allowed specific settings from a list) then Teensy does the auto-reboot into bootloader mode. When you look at that code, it actually sets a timer which causes the reboot to happen 15 USB frames later. Drivers on some versions of Windows have terrible bugs if Teensy reboots before the USB control transfer with that command is able to fully complete and the driver receives the ack response.

So, all you need to do is find the usb_dev.c file and edit it. Inside Arduino with Teensyduino added, it'll be in the hardware/teensy/avr/cores/teensy3 folder. On the Raspberry Pi or any other Linux system, hopefully you know where you extracted the Arduino software. On Windows, the installer defaults to putting Arduino in C:\Program Files (x86)\Arduino. On a Mac, you need to control-click Arduino and click "Show Package Contents", then click Contents/Java to get to the hardware folder, and from there it's the same as Windows & Linux.

When you edit that code, you can look for the 134 baud stuff. Or the USB start-of-frame interrupt, which decrements that 15 count. Or you can look for the _reboot_Teensyduino_() function, which is called to actually do the reboot request after the 15 frame delay.

If you want to make Teensy never automatically do into programming mode, just delete or comment out that code. Then Teensy will effectively ignore the reboot requests. You can still get Teensy into bootloader mode by pressing the button. This is also how Teensy is different from most Arduino boards. On Teensy, the button is dedicated to entering programming mode. It is NOT a reset button, as on normal Arduino. Pressing the button does NOT cause Teensy to restart your program. It's 100% dedicated for the purpose of giving you a way to get back into programming code. We make every Teensy this way because you *can* edit that USB code in all sorts of ways that would, without a reliable way to get back into programming mode, effectively brick your Teensy.

If you really want a toggle switch like you have now, then you'd need to add code in that function to read a pin. Since that is C-only code, not C++, you will have a couple extra things to do to make that work, but hopefully this long-winded message has given you a strong understanding to be able to craft the solution you want.
 
Status
Not open for further replies.
Back
Top