Repository

Looks good to me!

User Tools

Site Tools


projects:electronics:microcontroller:toolchain

Toolchain

First step is always to streamline the toolchain to ease development.

There is a wide variety of tools available for writing code, will list these here eventually.


Programmer

AVRISP-U

The programming kit I am using is Kanda's STK200-X starter kit, which comes with the AVRISP-U ISP programmer. This programmer has an accompanying Windows AVRISP-U software (download link), which ideally should be linked as an external tool to Microchip Studio for rapid deployment.

Tip

The AVRISP-U software can be directly loaded with a compiled hex via the command line, but note the boilerplate directories and files required (extrapolated from existing integration):

./
+-- MYPROG.asmproj
+-- Release   # "Debug" also works
    +-- MYPROG.hex
MYPROG.asmproj
<Project>
  <PropertyGroup>
    <avrdevice>ATmega16</avrdevice>
  </PropertyGroup>
</Project>
avrisp-u C:\path\to\MYPROG.asmproj

This is useful to bypass the Microchip Studio integration (although you still can't remove the subsequent step to hit F5 for the actual programming).

Makefile
PROGNAME=ledflash200
 
default:
    @mkdir -p Release
    avrasm2 -fI -o "Release/${PROGNAME}.hex" -W+ie -i m16def.inc ${PROGNAME}.asm
    @echo "<Project><PropertyGroup><avrdevice>ATmega16</avrdevice></PropertyGroup></Project>" >> ${PROGNAME}.asmproj
    avrisp-u ${PROGNAME}.asmproj

USBasp

The USBasp programmer is open source and only requires an ATmega8. This protocol is straightforward to flash with via AVRDUDE. See schematic below:

For Windows, since libusb is a perennial issue, Zadig can be used to quickly install compatible USB drivers which USBASP can interface with. One can get pretty good mileage with libusb-win32.

Note that the usbasp protocol is intended to run at higher speeds, but typical chips require programming speeds of at most 1/4 clock speeds. If the firmware of the usbasp programmer supports it, the clock rate can be reduced by specifying -B in avrdude.

AVRDUDE

AVRDUDE (Linux, Windows) is a utility program that provides a uniform interface for different hardware programmers on a platform-independent basis. For example, writing a flash program to an ATmega16 chip connected via the USBASP interface only requires the following command:

avrdude -p m16 -c usbasp -U flash:w:[PROGRAM].hex

Some devices may require additional library support from libusb and libftdi1, which is complicated to build from scratch. A working alternative is to use Greuel's fork of AVRDUDE which patches functionality of libusb and libftdi1 to work on Windows.

AVRISP-U compatibility

To get it to work with Kanda's AVRISP-U programmer requires adding the following configuration (adapted from a rather dated 2014 version which mislabels the PID value and adds an extra serial number check), for AVRDUDE 7.0:

avrdude.conf
programmer
  id         = "avrisp-u";
  desc       = "Kanda AVRISP-U FT2232D-based programmer";
  type       = "avrftdi";
  connection_type = usb;
  usbvid     = 0x0403;
  usbpid     = 0x6010;
  usbvendor  = "";
  usbproduct = "";
  usbdev     = "A";
  usbsn      = "";
#ISP-signals - lower ADBUS-Nibble (default)
  reset  = 5;
  sck    = 1;
  mosi   = 2;
  miso   = 3;
#LED SIGNALs - higher ADBUS-Nibble
  pgmled = ~11;
#Buffer Signal - ACBUS - Nibble
  buff   = 6;
;

Now write whatever you want, note write tested using program in Intel hex format:

avrdude -p m16 -c avrisp-u -U flash:w:[PROGRAM].hex

Note

For sanity check, on Windows, the correct VID and PID values can be looked up in Device Manager, associated with the FTDI driver listed under "USB controllers", e.g.

Device USB\VID_0403&PID_6010&MI_00\7&2194c0b3&0&0000 was started.

Driver Name: oem109.inf
Class Guid: {36fc9e60-c465-11cf-8056-444553540000}
Service: FTDIBUS
Lower Filters: 
Upper Filters: 

If pin-out configuration is wrong, the following message will be returned, so it is a good indicator of operation before actually programming anything:

> avrdude -p m16 -c avrisp-u

E avrftdi_program_enable(889): Device is not responding to program enable. Check connection.
avrdude.exe: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

Warning

Programming with AVRDUDE via AVRISP-U works, but this workflow requires the following steps:

  1. Attach AVRISP-U programmer and write using AVRDUDE.
  2. Disconnect AVRISP-U programmer from the board.
  3. Connect USB 5V supply to the board.

The disconnection step is necessary because the programmer can also power on via the 5V rail form the board. When initially powered on, the programmer somehow overrides the flash program written to the chip. Disconnecting the 10-pin ISP every time before testing a program is not ideal, so better to stick to the AVRISP-U software on Windows, which can both power and write to the board.

DFU-PROGRAMMER

dfu-programmer is only applicable to certain models of chips which already come with a preloaded bootloader, so the chip can be induced into DFU mode to upload software in a non-conflicting flash memory space.


Assembler / Compiler

For ease of development, customized header files for the chip for which a program is written for should be used, which provide convenient definitions to chip-specific registers, ports, etc. These are supplied in Microchip Studio (paths below for version 7.0.2594):

  • Assembly: C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\ATmega_DFP\1.1.130\avrasm\inc\m16def.inc
  • C: C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\iom16a.h

AVRASM2

AVRASM2 is the OEM assembler for Atmel chips, which is packaged together with Microchip Studio (supersedes Atmel Studio). File is located at C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\avrasm2.exe, and compilation can be called with:

avrasm2 -fI -o "MYPROG.hex" -W+ie -i m16def.inc .\MYPROG.asm

The Microchip Studio GUI software itself is actually decently powerful, especially if you have a compatible programmer, and it also includes a simulator for debugging. Supports both C and Assembly.

AVR-GCC

The main method to retrieve precompiled binaries for AVR-GCC is currently from Microchip website. Otherwise one can also consider building it themselves from the source.

Tip

A good practice to separate compilation environment is by pulling up a separate shell with binaries loaded loaded in the path. Consider deploying with the following script:

start_avrgcc.cmd
set Path=%Path%;C:\PATH\TO\avr8-gnu-toolchain\bin
set Path=%Path%;C:\PATH\TO\avr8-gnu-toolchain\avr\bin
start cmd

Note that the AVR-AS assembler binary exists, but this should not be called directly, instead using the AVR-GCC compiler to indirectly call the assembler.

Note

Instructions for Ubuntu 22.04 LTS. Install the compiler, AVR binary utilities, AVR C library, and the GNU AVR debugger:

sudo apt-get install gcc-avr binutils-avr avr-libc gdb-avr

Development boards

Atmel STK600

The STK600 is a development board provided by Atmel, and requires Microchip Studio for operation. Quick start guide for the STK600, instructions reproduced below for STK600-ATMEGA2560 device board (Microchip Studio should be installed):

  1. Use mounting screws/clips to secure the chip board (or routing board + chip adapter boards)
    • Ensure the white dot of daughter board is located on the same corner
  2. If no external clock, flip the clock switch to INT
  3. Connect computer to the USB B port, and switch on the STK600
  4. In Microchip Studio, access the STK600 interface tool via Tools > Device Programming > STK600, and select ATmega2560 device and click apply.
  5. Under board settings tab, write 3.3V to VTarget (or corresponding to your board)
  6. For ISP programming, connect the 6-pin ISP interface and set the ISP frequency to no more than 1/4 of CPU clock frequency. The application can be uploaded from the tool
projects/electronics/microcontroller/toolchain.txt · Last modified: 19 months ago ( 2 May 2023) by 127.0.0.1