SAMG55 SDK
Mar 16, 2025 - ⧖ 7 minI've been looking into the SAMG55 chip, along with one of my friends at work, as it has some potential to be used in some new hardware designs.
Both of us are Zig curious, and as I previously wrote, I had played around getting zig to run on an STM32 blackpill.
So, we wanted to see if we would be able to get Zig running with the SAMG55.
For starters though, I needed to be able to get some C program running on the SAMG55 Xplained Pro dev kit I ordered. In contrast to the blackpill project, I was hoping Atmel (Microchip now...) would have some easy to use HAL or even a BSP C library with some example code that could be built with the standard GCC arm toolchain.
Well, I should know by now that microcontroller vendors seem to only want to make everyone's life "easier" 😬
Dealing with the Microchip of it All...
In my opinion, ideally, in life, every C project should have a make file, so I
can type make, and then everything builds perfectly with no errors.
This is almost never the case. Microcontroller vendors (and Microchip especially) love to push their proprietary Eclipse/NetBeans/Whatever IDE forks onto embedded software engineers, along with a host of "easy to use" code generation tools. I don't want to have to run a heavy Java program just to compile a hello world blinky program...
In the SAMG55 case, Atmel, who are now owned by Microchip, provide a lovely IDE called Atmel studio, which in the documentation for the SAMG55 Dev Kit is the recommended way to get started with the board.
However, Microchip now want you to use their lovely IDE, called MPLAB X 👀
MPLAB X comes bundled with Microchips own lovely compiler, XC32, which you can use to compile ARM code instead of the GCC toolchain. However, this
Great, so now I need to download MPLAB X and the XC32 compiler?
Well, I've previously been able to get around using MPLAB X for compiling PIC16 firmware with Microchips XC8 compiler, so I should be able to handle this.
I unfortunately succumbed to downloading MPLAB X, and the device "pack" for the SAMG55. However, thankfully, after digging around in the MPLAB X program files, I was able to find the relevant supporting files that MPLAB X was using when compiling for the SAMG55. At the very least, Microchip stuck to CMSIS, and there were GCC and CMSIS compatible linker scripts and startup code available for the taking buries in the MPLAB X program files.
Excellent, I've now got enough files to bundle together in a repo, write a
quick makefile and achieve my dreams of compiling something for this SAMG55 dev
kit by typing make in my terminal?
Well, not quite.
Board Support Package?
At the beginning of this post, I mentioned I was quite keen on not having to write a BSP myself, and was hoping there would be something from Atmel/Microchip resembling a BSP I could include, perhaps with some code examples even?
Well, I found some code examples at least...
The documentation for the SAMG55 board recommended to use something called Atmel Start, which from what I can gather was some sort of code generation tool for low level drivers. Either way, doesn't matter, its deprecated now because Microchip.
Microchip have their own code generation, called MPLAB Code Configuration (MCC?), oh wait, I mean MPLAB Harmony for ARM chips. MCC Melody, which seems to be the version for AVR/PIC chips, is accessible as a plugin for MPLAB X (great, I have that downloaded already... oh but its not for ARM Chips). MPLAB Harmony, helpfully stated on Microchip website, is accessible in MPLAB Harmony? Does that mean I need to download another IDE 😒
Not so fast, through a bit more digging, there are some code examples hosted on github for use with MPLAB Harmony and the SAMG55! Amazing!
Well, they are all written using the X32 compiler, well maybe that's ok?
Looking around, doesn't seem like there is a BSP or HAL library with these examples. After a painful bit of rummaging, it seems that MPLAB Harmony uses some Jinja templating and python code to generates the BSP from scratch for each project.
Oh no, the MPLAB Harmony tool is worse than I thought. I read some documentation for it, and it seems to be a graphical coding tool, that requires you to layout all the peripherals required for your project in the "Easy View" window, connecting them up with arrows and configuring them with wizards. Please for the love of god, who is making these tools, why do they think this is how software engineers want to write code? Seriously, the pdf with getting started instructions for generating a blinky hello world app in MPLAB Harmony is 26 pages!
So, I might have got a bit ahead of myself then. I think finding a vendor BSP library to use and include in a blinky project is too much to ask. Oh well, at least I have some not quite usable example code in a github repo to get started.
Building my own SDK
So we are back to bare metal programming, albeit with some examples I can't (refuse) to compile, some CMSIS startup code, a device header file, and a data sheet. Better than nothing.
So after reading the datasheet and the example code (to figure out what needed initialising etc.), I'd managed to get a nice baremetal blinky program, and it compiles! Watch out LED's, you're about to get flashed!
Bollocks, how do I program this thing? Here we go again...
EDBG
So the SAMG55 Xplained Pro has a debugger built into the dev kit (Great!). However, its not a JLink, or ST-Link, or ICE, its something called EDBG. I don't know what that is, and I don't really want to know. But I don't know how I interact with it. It seems that there is potential for connecting a JLink up over JTAG to the board, but I can't be bothered to solder some header pins (or figure out which pins are which for connecting to the JLink). Back to MPLAB X then.
MPLAB X seems to have a bunch of python scripts buried in the program code that allow it to program different devices with different programming options, like using a JLink, or the sam-ba bootloader (a cursed thing I have had to deal with at work, and don't want to give any more airtime than is required). There was also a script for something called CMSIS DAP. Some research indicates that CMSIS DAP is some firmware that can be used to program Cortex-M microcontrollers using JTAG or SWD, similarly to a JLink. It also seems to be what the Atmel ICE programmer (which seems to be the official method for programming the SAM chips) uses.
After some more digging on the internet, I came across a site of an absolute legend, who clearly outlined exactly what is going on with all these programming/debugging tools in the context of Atmel SAM chips, as they are used for some arduino boards.
Even better, there is a page specifically talking about EDBG, which is a command line tool another (different?) legend has created for programming devices that use the CMSIS-DAP protocol!
Amazing! So I have my blinky application compiled with GCC, and now I can program it to the board! Some tweaking of the delay in the application and finally, the LED blink!
Zig?
Well, that was enough faffing around for one day. At least now I can compile code for this thing in C.
My plan for the future would be to develop a BSP or HAL for the chip, maybe I should revisit the MPLAB Harmony tool and see if it can give me anything to start on that? My friend and I previously wrote our own HAL for PIC16's, so perhaps we can copy how we went about doing that.
I would also like to try integrating FreeRTOS onto this board. Then, we could write a Zig application, and integrate it with FreeRTOS and the HAL, both written in C. If we can easily work with Zig while using a C HAL and FreeRTOS, then that would be the real test of how viable using Zig for professional embedded software would be in my opinion.
Lot's to be getting on with!