wiki.js/configuration/Reset_Control.md

8.5 KiB

title description published date tags editor dateCreated
Reset_Control true 2022-04-01T12:59:52.289Z undefined 2020-01-06T01:54:04.493Z

Background

The Arduino Mega platform is great in that it provides a low cost, low barrier to entry platform for projects. Unfortunately, these conveniences come with some disadvantages.

Specifically, in an effort to make the programming process as painless as possible, most (possibly all) versions of the Arduino Mega 2560 board will reset themselves when a new serial connection is initiated. Needless to say, it's pretty inconvenient for the computer controlling your engine to reboot if you're driving the car and the serial connection to your logger becomes unstable and has to reconnect (hint: the engine stops).

This feature will enable you to prevent that from happening.

Options

There are basically three ways to that can be used for reset control.

  1. Some board versions have Prog - Run switch for reset control. When switch is set to Prog, the Arduino Mega board will reset normally and firmware upload is possible to do. When switch is set to Run, the Arduino Mega board will not reset and no firmware upload is possible. So in normal operation set the switch to Run and only use Prog -selection when updating firmware. This way doesn't require changes in TS. reset.jpg{.align-center width=350}
  2. For boards that don't have dedicated reset control -switch, it's possible to connect a wire between reset pin and control pin in arduino.
  3. If the Arduino Mega is version that has ATmega16U2 chip for USB-serial connection, it's possible to update the ATmega16U2 with custom firmware, connect a wire from ATmega16U2 pin to control pin and enable the Advanced Reset Control Features needs to be enabled in TS Project Properties

Settings in Tuner Studio

In case of options 2 or 3 are used for reset control, Tuner Studio has dedicated "Reset Control" -menu to change how the speeduino FW handles reset protection.

2018-02-27_21_11_05-reset_control.png{.align-center width=450}

Control Type

(* indicates that it only works with option 3 and to see the selection, Advanced Reset Control Features needs to be enabled in Project Properties):

  • Disabled: No reset control is enabled
  • *Prevent When Running: As long as the engine is running, the Arduino will not automatically reset itself, because the control pin will be held high as long as the engine is running. It will only be possible to update the Speeduino firmware when the car is not running or the control pin is otherwise held low.
  • *Prevent Always: The control pin is always held high. It will only be possible to update the Speeduino firmware if the control pin is held low by jumper, switch, or some other means.
  • Serial Command: Similar to "Prevent Always," except that no custom bootloader is required. The control pin will normally be held high. To update the Speeduino firmware, you will need to first send the character 'U' to it over the serial connection. This will let it know that an update is coming and it will reset itself upon receiving any more data.

Control Pin

  • Select the pin used for Reset Control. This is the Arduino Mega -pin you need to run wire to reset or 16u2 -pin. See wiring -section for more info.

Wiring

Standard 16u2 Firmware or No 16u2 (Option 2)

This is as simple as running a wire from the control pin to the reset pin on your Arduino.

Custom 16u2 Firmware (Option 3)

The custom 16u2 firmware differs from the stock one in that it uses one of the 16u2's GPIO pins to recognize when the board should / should not be allowed to reset. The pin used is PB7, as illustrated.

reset_control_16u2_pins.jpg

How you connect the control pin to PB7 is up to you, but if you are connecting from a pin on the Speeduino's proto area, you may wish to use right-angle pin headers on the Arduino to make separating the Speeduino shield from the Arduino MCU (also illustrated).

Updating the Bootloader

Using the Option 3 for "When the engine is running" and "Prevent Always" reset control modes requires updating the usb-serial firmware on your Arduino's ATmega16U2 chip (these modes are unavailable if your board uses something else to perform usb serial functionality, such as an FTDI or CH340 chip).

A hex file for the updated bootloader can be found in the following locations:

To perform the update, you will need a copy of dfu-programmer. Directions for installing dfu-programmer for Mac can be found here. It may also be possible to use Atmel's flip programmer but it has not been tested.

The procedure is as follows (directions are for Windows but are very similar for Linux and Mac):

  1. Extract both dfu-programmer and the updated bootloader into the directory of your choice.

  2. Plug your Arduino into a USB port and wait for the computer to recognize it.

  3. Briefly short the 16U2's RESET and GND pins. This will cause the 16U2 to enter DFU mode.

  4. If you are prompted by Windows to install a driver, do not let Windows install the driver automatically. Instead, browse to the .inf file that came with dfu-programmer.

  5. Use the following commands to backup your existing usb-serial firmware and install the new one (prepend sudo on Mac and Linux):

    1. dfu-programmer atmega16u2 read > arduino-usbserial-backup.hex
    2. dfu-programmer atmega16u2 erase
    3. dfu-programmer atmega16u2 flash Speeduino-usbserial-atmega16u2-Mega2560-Rev3.hex
    4. dfu-programmer atmega16u2 reset
  6. The bootloader update is complete. You should now disconnect and reconnect the Arduino to your computer.

In Windows, your Arduino will now appear as a generic USB Serial Device in the Device Manager so you will likely need to reconfigure TunerStudio to use the new port. If you like, you can check the "Bus reported device description" property in the device's Details tab to verify that "Speeduino Mega 2560" is shown.

Updating the Speeduino Firmware With "Serial Command" Selected

Performing a Speeduino firmware update using the Serial Command method is a multi-step process:

  1. Using the serial terminal program of your choice (this was tested using PuTTY), open a serial connection to your Speeduino. At this time, you may wish to enter a "?" to verify that the serial connection is working properly.
  2. Enter "U" in the terminal. If all goes well, it should respond with the message "Comms halted. Next byte will reset the Arduino."
  3. Without entering any more characters, close the serial terminal.
  4. Finally, start the firmware upload. The Arduino should now reset and accept the firmware upload as normal.

(TODO: Screenshots)

Updating the Speeduino Firmware With the Updated 16U2 Bootloader Installed

If you have reset control set to "When engine is running," there is no special procedure required to update your Speeduino firmware. As long as the engine is not running, the Arduino will behave just as any other and you can update it the same way you would any other time.

If you have reset control set to "Always," you will either need to temporarily disable it from inside TunerStudio in order to update your Speeduino firmware.