Atmel SAML21 ASF compiling and FLASH programming on Linux

This article illustrates how to install the GNU Toolchain for SAML21, install the ASF libraries, compile a default example and write on the SAML21 FLASH under Linux

Atmel ARM GNU Toolchain installing

  • Download the Atmel ARM GNU Toolchain 5.3.1 - Linux 64-bit from this link

  • Untar the archive:

$ tar -xvzf arm-gnu-toolchain-5.3.1.487-linux.any.x86_64.tar.gz
$ cd arm-none-eabi
~/arm-none-eabi$

Add to your PATH the directory ~/arm-none-eabi/bin

$ export PATH=$PATH:~/arm-none-eabi/bin

Atmel ASF library installing

Download the Atmel Software Framework from the following link to your home directory:

Unzip it:

$ unzip asf-standalone-archive-3.31.0.46.zip

Compile the first led toggle example

Wire a led as shown below:

Move inside the led-toggle default example:

$ cd xdk-asf-3.31.0/sam0/applications/led_toggle/saml21_xplained_pro_b/gcc

Edit the file led_toggle.c and change all the LED_0_PIN define with PIN_PA16 the compile by typing:

~/xdk-asf-3.31.0/sam0/applications/led_toggle/saml21_xplained_pro_b/gcc$ make

The result will be:

CC      common/utils/interrupt/interrupt_sam_nvic.o
MKDIR   sam0/applications/led_toggle/
CC      sam0/applications/led_toggle/led_toggle.o
MKDIR   sam0/boards/saml21_xplained_pro_b/
CC      sam0/boards/saml21_xplained_pro_b/board_init.o
MKDIR   sam0/drivers/port/
CC      sam0/drivers/port/port.o
MKDIR   sam0/drivers/system/clock/clock_saml21/
CC      sam0/drivers/system/clock/clock_saml21/clock.o
CC      sam0/drivers/system/clock/clock_saml21/gclk.o
MKDIR   sam0/drivers/system/interrupt/
CC      sam0/drivers/system/interrupt/system_interrupt.o
MKDIR   sam0/drivers/system/pinmux/
CC      sam0/drivers/system/pinmux/pinmux.o
CC      sam0/drivers/system/system.o
MKDIR   sam0/utils/cmsis/saml21/source/gcc/
CC      sam0/utils/cmsis/saml21/source/gcc/startup_saml21.o
CC      sam0/utils/cmsis/saml21/source/system_saml21.o
MKDIR   sam0/utils/syscalls/gcc/
CC      sam0/utils/syscalls/gcc/syscalls.o
LN      led_toggle_flash.elf
SIZE    led_toggle_flash.elf
led_toggle_flash.elf  :
section              size         addr
.text               0x858          0x0
.relocate             0x4   0x20000000
.lpram                0x0   0x30000000
.bss                 0x3c   0x20000004
.stack             0x2000   0x20000040
.ARM.attributes      0x28          0x0
.comment             0x59          0x0
.debug_info        0x8bf5          0x0
.debug_abbrev      0x1476          0x0
.debug_aranges      0x228          0x0
.debug_ranges       0x210          0x0
.debug_macro      0x1a0b9          0x0
.debug_line        0x5900          0x0
.debug_str        0x9749b          0x0
.debug_frame        0x4ec          0x0
.debug_loc         0x1923          0x0
Total             0xc5a1f


   text    data     bss     dec     hex filename
  0x858     0x4  0x203c   10392    2898 led_toggle_flash.elf
OBJDUMP led_toggle_flash.lss
NM      led_toggle_flash.sym
OBJCOPY led_toggle_flash.hex
OBJCOPY led_toggle_flash.bin

The file led_toggle_flash.bin is the binary file to give to the edbg programmer described below.

Atmel EDBG programmer installing

  • Clone ant9000 fork on GitHub of EDBG programmer by typing:
$ git clone git clone https://github.com/ant9000/edbg.git
$ sudo cp 90-atmel-edbg.rules /etc/udev/rules.d/
$ sudo udevadm control --reload
  • Install the libudev library
$ sudo apt-get install libudev-dev
  • Move inside the __edbg__directory and launch make:
$ cd edbg
~/edbg$ make

Use the Atmel EDBG programmer

Read the SAM L21 FLASH contents

~/edbg$ ./edbg -b -r -f flash.dump -t atmel_cm0p
...
~/edbg$ ls -al flash.dump 
-rw-r--r-- 1 root root 262144 Jul 19 17:50 flash.dump

Write the SAM L21 FLASH contents

~/edbg$ ./edbg -b -p -v -f flash.dump -t atmel_cm0p

Links

Credits

Many thanks to Antonio Galea for the contents of this article