Skip to content

makefile cpp project for WSL for the saml21 mcu from atmel

Notifications You must be signed in to change notification settings

timkruse/saml21-helloworld-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAML21 baremetal cpp hello world makefile project

Here is an extended hello world project for the SAML21G18B Cortex-M0+ controller by Atmel with full integration in VS Code like build, clean and program tasks are setup and debugging is configured without the need of an extension. You only need a Windows 10 with WSL enabled as the makefile was intentionally created for unix like systems and has now been ported to Windows/WSL.

Workflow after Setup has been done

  1. Make the project via make all
  2. Start openocd via make server_start in a second shell or background however
  3. Hook up a serial terminal and connect to processor
  4. Flash the program via make program
  5. Type in led on and led off to toggle the userled on the sammyl21 board
  6. Stop openocd via make server_stop

Prerequisites

  1. ARM Toolchain
  2. Atmel/Advanced Software Framework (ASF)
  3. OpenOCD

Setup

  1. open makefile and change the path variables according to your installation
#	ARM GCC installation path
ARM_GCC_PATH := /mnt/d/arm-dev/gcc-arm-none-eabi-8-2019-q3-update
#	OpenOCD installation path 
OPENOCD_PATH := /mnt/d/arm-dev/OpenOCD-20190715-0.10.0
#	ASF installation path
ASF_PATH := /mnt/d/arm-dev/xdk-asf-3.45.0
  1. make sure you are in the projects directory with the current shell
$ cd [path to project]
  1. Link project to the ASF
$ make links
  1. In file xdk-asf/system_saml1.c add the weak attribute to the functions SystemInit and SystemCoreClockUpdate
void __attribute__((weak)) SystemInit(void){...}
void __attribute__((weak)) SystemCoreClockUpdate(void){...}

Adding this attribute to the functions let's us override them somewhere else without causing the gcc to raise a multiple definition of 'function' error.

  1. build it
$ make all

Don't forget to multithread this with the argument -j [Number of concurrent jobs]

$ make -j 4 all

Flash and Debug

  1. make sure you are in the projects directory
$ cd [path to project]
  1. Configure your debugging hardware in the openocd.cfg file. The one I used is the ARM-USB-OCD-H with the SWD adapter by Olimex.
# 1. Setup your debugger
source [find interface/ftdi/olimex-arm-usb-ocd-h.cfg]
# 2. and the SWD adapter if needed
source [find interface/ftdi/olimex-arm-jtag-swd.cfg]
  1. start openocd server Either manually in a seperate shell (makes sense if the debugging/flashing fails)
$ openocd

or in the same shell but started in the background

$ make server_start

To kill it if run in the background run

$ make server_stop
  1. run debug command (this automatically flashes the target but leaves open the gdb console)
$ make debug

or only for programming the target

$ make program

Configure VS Code's C/C++ plugin for IntelliSense

Scan through the file .vscode/c_cpp_properties.json and change all paths to your installation. In case you are using a different gcc version you can get the default includes by running

echo | [full path to your gcc]/bin/arm-none-eabi-gcc -Wp,-v -x c++ - -fsyntax-only

Debugging in VS Code

Scan through the file .vscode/launch.json and configure all paths to your installation

Changes to be made for similar processors

  1. In the makefile you have to change the make links target in such a way that the files for your processor are linked.
  2. In openocd.cfg you have to setup your processor and your debugger

About

makefile cpp project for WSL for the saml21 mcu from atmel

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published