Martin's corner on the web

Optiboot on the micro IoT gateway

The uIoT gateway shield has FTDI plug that I used mostly for serial debugging, while for programming I used a clone of the USBTiny programmer. I wanted to adapt optiboot for the uIoT gateway, as that will make it easier for the end user to upload sketches. The challenges of having a bootloader on it are a few, most important is the changing clock frequency.

The uIoT gateway is clocked from ENC28J60’s clkout pin, that defaults to 6.25Mhz after powering up, and you can set it to 12.5Mhz as I described here. Once you set that higher frequency, it will run @ 12.5Mhz until that is changed by the software or upon power-down/power-up cycle (but not a RESET), so you have two possible situations when trying to upload a sketch – you can be either running @ 6.25Mhz or 12.5Mhz… not cool when it comes to bootloading, since we need to define a baud rate. It also happens that the maximum baud rate that I could get is 38400 @ 6.25Mhz, so if the sketch later sets the frequency to 12.5Mhz the bootloader will actually work @ 38400*2=76800 baud.. yuck, this is non standard baud rate. So I decided to go for 19200 @ 6.25Mhz and if you are running on double speed – that will become the common baud rate of 38400. True it is a bit slower, but it works.  It took a while to make optiboot work at 19200 baud rate, mostly it was switching at software UART during compile time so I had to comment out that part of the code. Other adjustments were to blink the led on the uIoT shield properly, as it is on other pin compared to “normal” Arduino. I also created two new entries in the “boards.txt”, adjusted fuses and got it all working 🙂

##############################################################
suno.name=Simon K. with Optiboot @6.25Mhz
suno.upload.protocol=arduino
suno.upload.maximum_size=32256
suno.upload.speed=19200
suno.bootloader.low_fuses=0xFF
suno.bootloader.high_fuses=0xDE
suno.bootloader.extended_fuses=0x05
suno.bootloader.path=optiboot
suno.bootloader.file=optiboot_uiot.hex
suno.bootloader.unlock_bits=0x3F
suno.bootloader.lock_bits=0x0F
suno.build.mcu=atmega328p
suno.build.f_cpu=6250000L
suno.build.core=arduino
suno.build.variant=standard
##############################################################
zuno.name=Simon K. with Optiboot @12.50Mhz
zuno.upload.protocol=arduino
zuno.upload.maximum_size=32256
zuno.upload.speed=38400
zuno.bootloader.low_fuses=0xFF
zuno.bootloader.high_fuses=0xDE
zuno.bootloader.extended_fuses=0x05
zuno.bootloader.path=optiboot
zuno.bootloader.file=optiboot_uiot.hex
zuno.bootloader.unlock_bits=0x3F
zuno.bootloader.lock_bits=0x0F
zuno.build.mcu=atmega328p
zuno.build.f_cpu=12500000L
zuno.build.core=arduino
zuno.build.variant=standard

##############################################################

optiboot IMG_1850 IMG_1848 IMG_1851