Using the SM32U4 with AVRA on Linux

Hello!

I’m making a quick post here (that will be updated for at least the duration of the term) for programming the SM32U4 micro-controller with the Linux toolkit targeted at the Benny Boards. It works for me on Nixos, but ymmv, especially on older distros such as Ubuntu.

Required Tools

Avrdude

AVRA

Install these for your required distro before continuing.

In addition, please download the m32U4def.ico file and place it in your current working directory.

Assembling a Program

Download (or make) an assembly program for your device and place it in the working directory.

You can assemble it using AVRA:

avra file.asm

Which outputs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
AVRA: advanced AVR macro assembler (version 1.4.2)
Pass 1...
Warning : No .DEVICE definition found. Cannot make useful address range check !
Warning : No .DEVICE definition found. Cannot make useful address range check !
Warning : No .DEVICE definition found. Cannot make useful address range check !
Pass 2...
m32U4def.inc(44) : PRAGMA PARTINC directive currently ignored
m32U4def.inc(48) : PRAGMA AVRPART directive currently ignored
m32U4def.inc(53) : PRAGMA AVRPART directive currently ignored
m32U4def.inc(1301) : PRAGMA AVRPART directive currently ignored
m32U4def.inc(1302) : PRAGMA AVRPART directive currently ignored
m32U4def.inc(1303) : PRAGMA AVRPART directive currently ignored
m32U4def.inc(1304) : PRAGMA AVRPART directive currently ignored
done


Assembly complete with no errors (3 warnings).
Segment usage:
   Code      :        78 words (156 bytes)
   Data      :         0 bytes
   EEPROM    :         0 bytes

Which should produce a number of files, one being a hex file.

This works because I commented line 47 in the inc file that was broken on the AVRA version I used. If you use the file that the lab guide links to, it Will Not Work

Flashing a Program

For the Benny Board, you can use avrdude to flash hex files to your Benny Board.

To Flash, make sure that your usb port is plugged to the USB next to the 2-pin white connector on the left side of the board. In addition, the board does not show up as a serial device until the rst button is pressed and the board is in flashing mode. Just make sure to press the rst button and then run the flashing command, it should work.

sudo avrdude -c avr109 -p m32u4 -P /dev/ttyACM0 -U flash:w:file.hex

Which outputs:

1
2
3
4
5
6
7
Reading 156 bytes for flash from input file file.hex
Writing 156 bytes to flash
Writing | ################################################## | 100% 0.04 s 
Reading | ################################################## | 100% 0.00 s 
156 bytes of flash verified

Avrdude done.  Thank you.

If that does not work, it is possible that you either did not properly flash after pushing the rst button or perhaps the serial device your board is connected to is different than the default one. You could try searching for a different serial device (which is located in /dev/ttyACM or /dev/ttyUSB in general.

Epilogue

Hopefully with that, one should be able to assemble and flash your assembly files to your microcontroller. I believe there is a requirement to use a specific simulator later in the term; I will add instructions for that once we get to that point.