Bootloader for ATmega32U4 with RS485 support

I'm looking for a Bootloader for ATmega32U4 (not using USB) with RS485 support.
I bet I have to customize it a bit, because I have to handle the RS485 address (stored in EEPROM).

In the past I used the Chip45Boot3 bootloader, it works well but it transfer the plain HEX file.

I'm looking for something better. I found OptiBoot but I'm quite scared because I didn't find a clear procedure about how to add a new MCU. In fact, it supports atmega32 but not the atmega32u4 and the Arduino IDE refuses to burn the bootloader due to a chip signature mismatch.

Any hint is appreciated!

the ATmega32 and ATmega32u4 are very different chips.

If you have a recent download (via git, not the "releases") of optiboot, you could find that support for the USB chips (including 32u4) was added via pull request: Add support for AVR-USB-MCU-families ATmegaXYu2/4/6 and AT90USBXYZ6/7 eg. Arduino Uno USB-MCU / Micro by Virtual-Java · Pull Request #327 · Optiboot/optiboot · GitHub
"make atmega32u4" should work.
I don't know if it works together with the "rs485 support", and what rs485 support there is probably doesn't match what you need (no addressing, just manipulation of a "transmitting" pin.)
But it does compile :slight_smile:

make atmega32u4 RS485=B4
"/Library/Developer/CommandLineTools/usr/bin/make" atmega32u4atUART UART?=1 LED_START_FLASHES?=0
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_495) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 115200, Real: 117647, UBRRL = 16, Difference=2.1%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega32u4 -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0              -DRS485=B4 -DUART=1   -c -o optiboot.o optiboot.c
optiboot.c:429:2: warning: #warning BAUD_RATE off by greater than 2% [-Wcpp]
 #warning BAUD_RATE off by greater than 2%
  ^
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega32u4 -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0              -DRS485=B4 -DUART=1 -Wl,-Tlink_optiboot.ld -Wl,--relax -nostartfiles -o optiboot_atmega32u4_UART1___BB.elf optiboot.o 
avr-size optiboot_atmega32u4_UART1___BB.elf
   text    data     bss     dec     hex filename
    494       0       0     494     1ee optiboot_atmega32u4_UART1___BB.elf

Thanks! I'm following the instructions here:

  1. cloned the github repository
  2. installed the gcc-avr package (Local Development Environment option)
  3. make atmega32u4:
$ make atmega32u4
"make" atmega32u4atUART UART?=1 LED_START_FLASHES?=0
make[1]: ingresso nella directory «/home/mark/optiboot/optiboot/bootloaders/optiboot»
avr-gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 115200, Real: 117647, UBRRL = 16, Difference=2.1%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega32u4 -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0               -DUART=1   -c -o optiboot.o optiboot.c
optiboot.c:352:22: fatal error: inttypes.h: File o directory non esistente
compilation terminated.
make[1]: *** [<incorporato>: optiboot.o] Errore 1
make[1]: uscita dalla directory «/home/mark/optiboot/optiboot/bootloaders/optiboot»
make: *** [Makefile.usbmcus:149: atmega32u4] Errore 2

Clearly there is something to set about the include dirs, but I found nothing about in the documentation. Would you mind to put me on the right way?

How exactly was this installed? You used a package manager on some linux system? (which one?) Did it catch the avr-libc and avr-binutils dependencies?

I usually use the download from https://www.microchip.com/en-us/tools-resources/develop/microchip-studio/gcc-compilers (for PC and Mac), but I'm not using linux.

Edit: I checked. I have a VM of Linux Mint, and used the package manager to install avr-gcc. It has inttypes.h in /usr/lib/avr/include

1 Like

I'm using Ubuntu 22.04 and I installed the required package using sudo apt install gcc-avr.
The other two packages are not mentioned so I didn't install them. Now I installed avr-libc, but avr-binutils is not available from apt.

Now I have the include file under /usr/lib/avr/include as well!

And it compiles! :sunglasses:
Time to try it without changes and then begin to adjust to my needs!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.