A template project for BSE flight software projects. Built to work with Atmel START generated ASF4 projects, on the Atmel SAMD21J18A processor.
Note: the Atmel START library in this repo is the bearbones minimal configuration; projects using this template should add required components and libraries.
Run make
. The produced binaries will end up in build/
To upload your code to the microcontroller, and then run or debug it using gdb:
- Make sure you've built the code with
make
- Make sure you're connected to the board or debugger
- From within this project directory, start
openocd
- In a new terminal within this project directory, run
make connect
(it's fine if an error about "No executable specified" comes up) - At the
(gdb)
prompt runload
to upload the binary to the microcontroller - Run
monitor reset halt
to reset the microcontroller and start debugging - Type
c
to run (continue) the program- If you want to step through your code, set any breakpoints you need before this (ex. via
break main
)
- If you want to step through your code, set any breakpoints you need before this (ex. via
Tips:
- To halt the code and get back to the debugger, do
Ctrl-C
- To rebuild the code without closing gdb, run
make
at the(gdb)
prompt and repeat steps 5-7
You can use the vscode debugger interface instead of the gdb textual interface to debug programs by installing the Cortex-Debug vscode extension from the marketplace.
To upload, run and debug using vscode:
- Make sure you've built the code with
make
- Make sure you're connected to the board or debugger
- Under the "Run and Debug" vscode menu on the left, click the green arrow to start debugging
- Make sure the "Debug (OpenOCD)" configuration is selected in the dropdown to the right of the arrow
- Wait for the debugger to start up (your bottom bar will turn orange once it does)
- If it doesn't start up, check the "Output" and "Debug Console" panes of vscode for error messages
- On the hovering toolbar that comes up, click the play button to run (continue) the program
- If you want to step through your code, set any breakpoints you need before this using the interface to the left of any code file you have open in vscode
- Install Chocolatey
- Run
choco install make
from a shell with administrator priveledges (right click -> Run as administrator) - Download and extract the "Arm GNU Toolchain for 32-bit Devices" for Windows from here.
- The Microchip link asks you to make an account, so either ask your BSE leader for the BSE account credentials or create your own account.
- To avoid dealing with an account AND to get some newer GCC and (importantly) GDB features, use this link instead.
- Make sure to add the bin folder to your path (e.g. Control Panel -> System -> Advanced system settings -> Environment variables -> Path -> Edit -> New ->
C:\Users\<username>\<path>\arm-none-eabi\bin
).
- Download and extract the newest Windows version of OpenOCD from here.
- Install homebrew here
- Install ARM developer tools:
If the last command fails but tells you to "Install the Command Line Tools" using
brew tap PX4/homebrew-px4 brew update brew search px4 brew install gcc-arm-none-eabi-80
xcode-select --install
, do so.
- gdb is not supported on M1, so you must run it with rosetta. use
arch -x86_64 /bin/bash (or zsh)
to run a terminal with rosetta (You can create an alias for easy switching by adding this to your .zshrc:
alias arm="env /usr/bin/arch -arm64 /bin/zsh --login"
alias intel="env /usr/bin/arch -x86_64 /bin/zsh --login"
- Install brew for x86 using this command:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- Add /usr/local/opt to your path -- the brew install script should recommend commands to do this for you
- try to install gdb.. good luck
- Install openocd:
brew install openocd
- Install the "Arm GNU Toolchain for 32-bit Devices" for Linux from here.
- The Microchip link asks you to make an account, so either ask your BSE leader for the BSE account credentials or create your own account.
- To avoid dealing with an account AND to get some newer GCC and (importantly) GDB features, use this link instead. You may need to use the second-to-latest version if you can't find a 64-bit linux installer (i.e. "64-bit Tarball").
- Make sure to add (or symlink) the bin folder into your path (e.g. add
export PATH=/path/to/arm-none-eabi/bin/:$PATH
to the end of~/.bashrc
and restart your terminal or runsource ~/.bashrc
).
- Install openocd:
sudo apt install openocd
. Unfortunately this doesn't seem to add required udev rules, so you'll need to:- Download the udev rules:
wget https://repo.or.cz/openocd.git/blob_plain/HEAD:/contrib/60-openocd.rules
- Set the rules' owner to root:
sudo chown root:root 60-openocd.rules
- Set the rules' permissions:
sudo chmod 644 60-openocd.rules
- Move the rules:
sudo mv 60-openocd.rules /etc/udev/rules.d/
- Add yourself to the plugdev group:
sudo usermod -a -G plugdev $USERNAME
- Probably log out or reboot. Just running
sudo udevadm control --reload
might also work.
- Download the udev rules:
- Install the Arm GNU Toolchain as above.
- openocd is probably in your package manager, but if not there are instructions here. Make sure to put (or symlink) the bin folder in your path.
- You may need to follow the instructions above to add the udev rules.
Follow this procedure if you'd like to add Atmel Start ASF libraries, change chip configuration or pinout, etc.
- Go to start.atmel.com
- Click on "Load project from file" and upload
./asf-samd21/atmel_start_config.atstart
- As desired, add software components, configure pinmux, package, or clocks
- Click "Export project", make sure "Makefile (standalone)" is selected, and click "Download pack"
- Change the
.atzip
file extension on the file you downloaded to.zip
and extract it - Delete the
main.c
file in the downloaded directory - Delete the contents of
./asf-samd21/
and copy all files in the downloaded directory there - Modify
ATMEL_SRC_DIRS
andATMEL_INCLUDE_DIRS
in./Makefile
according to the instructions there. You may need to make further modifications in./Makefile
based on changes made by Atmel Start to./asf-samd21/gcc/Makefile
(to see what changed, dogit diff ./asf-samd21/gcc/Makefile
).