Using Atmel Start to build firmware for the Itsy Bitsy M0 Express - BitKnitting/wakey_circuitpython GitHub Wiki
Goal
Build and debug a C source project for the Itsy Bitsy M0 Express based on an Atmel Start project.
On a Mac.
Why Start with Atmel Start
Atmel Start + the SamD21 datasheet are the best two tools to explore implementations of C Source for things like Waking up from standby mode when an External Interrupt is triggered. The datasheet has all you need to know. Unfortunately, what you need to know is littered in different sections. The Atmel Start project gives us the steps we need to take to implement stuff like waking up from standby.
What is Atmel Start
Atmel Start is a Web User Interface that lets us point-n-click together a C project + files to compile/link into a .elf file (e.g.: Makefile for the gcc toolchain). The C project inserts the ASF4 APIs. From Atmel: ”…the Atmel Software Framework, provides a rich set of proven drivers and code modules developed by experts to reduce customer design-time. It simplifies the usage of microcontrollers by providing an abstraction to the hardware through drivers and high-value middlewares. ASF is a free and open-source code library designed to be used for evaluation, prototyping, design, and production phases. The ASF4 driver architecture is built of three layers; HAL (Hardware Abstraction Layer), HPL (Hardware Proxy Layer), and HRI (Hardware Register Interface).
Create and Download
The steps are visual so I created a Youtube video that walks through what I did to create an Atmel Start project that will be the base for the C source to wake up on interrupt.
Save the project as .zip. For some strange reason, Atmel start puts .atzip as the file extension. We change this to .zip.
IMPORTANT: Modify the .ld File
The ../samd21a/gcc/gcc/samd21g18a_flash.ld must be modified to start code above the (in my case Circuit Python's) bootloader. Change .text :
to .text 0x2000:
Modify main.c
Here is the main.c file I used:
#include <atmel_start.h>
static void time_to_sleep(void){
__DSB(); // Complete any pending buffer writes.
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();
}
static void cb_eic_extint3(void) {
// gunk...checking if can set bp.
uint8_t i,j;
i = 5;
j = i + 3;
i = j + i;
}
int main(void)
{
/* Initializes MCU, drivers and middleware */
atmel_start_init();
ext_irq_register(PIN_PA19,cb_eic_extint3);
/* Replace with your application code */
while (1) {
time_to_sleep();
}
}
Build The Binary
Modifying the Makefile
The makefile is in the gcc folder.
Run mm
Before we can build, we will modify the Makefile. I wrote mm.py to do this. The first line:
#!/anaconda3/bin/python
gives the directive to interpret the rest through Python. I place this file in /usr/local/bin
. This makes mm available from any folder. Keeping in mind I am new to the nuances of Make, the script shows what I needed to change to build correctly from the gcc folder with debugging options turned on.
Run make
The result will be something like:
MacBook-Pro-3:gcc margaret$ ls
AtmelStart.bin AtmelStart.elf AtmelStart.lss Makefile
AtmelStart.eep AtmelStart.hex AtmelStart.map Makefile_old
YIPPEE!!! ...On To Debugging...