Fedora and Atmel AVR MCUs

For programming of Atmel AVR microcontrollers I am using JTAGICE mkII USB programmer/debugger. This device is easy to operate from Windows and AVR Studio (4), but the support for Linux is limited from Atmel side. As there is a variety of existing solutions this article is limited to only one of them with ZIGBIT900 running BitCloud ZigBit stack.

However the complete Atmel toolchain is based on GNU GCC (for Windows packed as WinAVR) - thus it is unlimited in functionality and code size. This is a good reason to try this out on Linux. While it is easy to cross compile the source codes to your AVR device, it is not that easy to get the correct programming HW to work. Thanks to Fedora project there is a complete toolchain for you to program and debug the devices.

This should make you ready to you first "hello world", or better in MCU world first "blink".

I will demonstrate that on Atmels BitCloud stack (ZigBee implementation called ZigBit) and its example "Blink". The only disadvantage is this stack is provided only as a library, there is no source code for it. Generally you do not need it for your application, so this is OK.

As a device I am using MCU Atmel ATmega1281V + transciever AT86RF212 operating in 868MHz ISM band. This combination of devices is possible to buy as a ZigBit900 module. You need to build your own PCB for that in this case, or you can buy it as MeshBean board development kit from Atmel (those were originaly developed by Meshnetics).

Building the Blink example

First download the BitCloud stack for ZigBit900 from Atmels site (you need to go thru brief registration). While this stack is bit overhead for just a blink application, this is just somethink that has to get you started.

When you are done downloading, just unpack it and go to the subdirectory with "Sample Applications/Blink", open Configuration file with your favorit editor and set up the board to MESHBEAN_BOARD. If you are thinking about where do I got this value, the you need to go deeper into the stack to understand it. Generally the stack is divided into several parts like BSP (description of various additional sensors, buttons and leds on the board), HAL (hardware abstraction of the main MCU), ZDO (ZigBit Data Objects - implementation od the ZigBee itself) etc. You will find description in documentation. Various types of the boards you will find under BSP BoardConfig. You can setup also other options in the example Configuration. Then everything is as simple as typing:

make

Compiling the app to a .bin, .hex etc. Then you need to transfer the binary stream into the flash of your MCU.

Programming the MCU

Connect the JTAGICE mkII with your PC thru USB and power it on. You should see something like this

NOTE: On F13 you need to use avarice-2.10-4 - at the moment it is in updates-testing. You need to be a root to access the USB and program the device.

If you wanna use a real time debugging feature of the JTAGICE, you can let the avarice run as a deamon

avarice --jtag usb --mkII :4242

create gdb.conf with

file blink.elf
target remote localhost:4242

and start

avr-gdb -x gdb.conf
or
ddd --debugger "avr-gdb -x gdb.conf"

However you may run into many problems here - 1. you do not have a sources of some functions using stacks, 2. avr-gdb is crashing etc. Crashes were caused by incorrect avr-gdb version in Fedora, which is now fixed.

With avr-gdb you may try:

break APL_TaskHandler
cont
break blinkTimerFired
cont

you have to be very carefull debugging this kind of code, because most of the time, code is running in the stack without source, it only hands over to your code at certain events.