User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

AVRPi-tools: avrdude-6.1/linuxgpio + Arduino IDE/libs

Mon Apr 06, 2015 12:49 pm

As far as I can tell there are 3 options of programming an AVR using avrdude with the Raspberry Pi gpio pins.

First there's Gordon Henderson's avrdude version 5.10, which has patches to bitbang the gpio pins. Gordon also patched Arduino 'boards.txt' and 'programmers.txt' files to have the Gertboard, Gertduino and avrdude 'gpio' programmer recognized by Arduino.

There's also this avrdude that's using 'linuxspi': http://www.raspberrypi.org/forums/viewt ... 44&t=45211 That works great as a standalone very fast avrdude, but reportedly doesn't play nice with the Arduino IDE (which very well may not be a concern to you).

Then there's the current upstream version of avrdude-6.1 (http://download.savannah.gnu.org/releases/avrdude/) which supports bitbanging GPIO pins out of the box. It doesn't need changes to the source code, a simple compile will do. It only needs the 'linuxgpio' programmer enabled in /etc/avrdude.conf to set the correct pins and it works. This seems the cleanest and most future proof option to me. I found it to be very reliable (use the -i option when setting fuses).

AVRPi-tools:
I've launched 2 new Raspberry Pi addon boards. One of them has an ATmega328p (AVRPi-328), and the other one (AVRPi-32U4) the very cool USB HID capable ATmega32U4 (the same as on the Arduino Leonardo). See this topic: http://www.raspberrypi.org/forums/viewt ... 0&t=106575

To support those, I've been working on a script that makes it as easy as possible to set these boards up. It consists of a menu, with "Install everything in 1 easy step", "Custom install" and "Fuse settings" options. There are also options to easily install additional software such as wiringPi, the 'avrpi' tool, and setting up some extra projects (Arduino-Makefile, LUFA, ...).

The script installs the Arduino library and IDE and a pre-compiled avrdude (avrdude_6.1-2_armhf.deb) and config. It also patches Arduino 'boards.txt', 'programmers.txt' and 'USBCore.cpp' files (that last one was necessary to make an ATmega32u4 also work on 8MHz in the Arduino library).

The avrpi-tools setup script is here: https://github.com/onandoffables/avrpi-tools.

Code: Select all

git clone https://github.com/onandoffables/avrpi-tools
cd avrpi-tools
./setup
The setup menu:

Code: Select all

#######################################################################
#                          avrpi-tools                                #
#######################################################################

  Install everything in 1 easy step:
    e)    Arduino IDE/libs + avrdude

  Custom install:
    a)    apt-get dependencies and AVR toolchain (without Arduino)
    b)    install pre-compiled avrdude binary
    c)    compile + install avrdude from source
    p)    patch arduino

  First time - fuses and test:
    s)    change to different board/chip
    f)    set fuses for atmega32u4 on avrpi32u4 board
    t)    make + upload test/blinky.hex
    o)    install Arduino Caterina bootloader
    g)    install Atmel DFU bootloader

  Optional extra:
    x)    uninstall wiringPi
    u)    uninstall avrpi tool
    d)    install dfu-programmer

  Software and projects:
    m)    install Arduino-Makefile
    l)    install LUFA-AVRPI32U4

    q)    quit

Enter your choice:
Everything can be installed and set up from this menu. The repositories mentioned below are called from the setup script if it needs them.

The scripts that download the avrdude-6.1 source, patch avrdude.conf, compile with linuxgpio enabled, create a .deb package and install it are here: https://github.com/onandoffables/avrdude-linuxgpio

The script that patches the Arduino IDE and libs is here: https://github.com/onandoffables/arduino-linuxgpio

'avrpi' tool
The 'avrpi' tool makes it easier to control the board from the Raspberry Pi (reset, flash firmware, start serial terminal etcetera).

Code: Select all

pi@raspberrypi ~ $ avrpi -h
Usage: avrpi [options] <filename>

[options] is any of the following:
  -f <file>   flash <file>    flash <file> to avrpi board
  -u <file>   upload <file>   upload <file> using caterina bootloader
  -d <file>   upload <file>   upload <file> using Atmel DFU bootloader
  -i          info            show info about chip
  -r          reset           reset AVR chip
  -b          bootloader      enter bootloader mode (HWB fuses set)
  -m          minicom         start minicom on /dev/ttyAMA0 @ 9600
  -n          screen          start screen on /dev/ttyAMA0 @ 9600
  -h          help            show this info
  -c          config          edit avrpi config file
  -s          show            show config
Other boards:
The pins "avrdude-6.1 linuxgpio" uses are the same ones that "Gordon's avrdude-5.10 gpio" uses. So it was little effort to add the Gertboard and Gertduino boards in the mix. I also took the liberty of adding Alex's new RasPiO Duino board in the setup menu.

From 'boards.txt' and 'board.mk' in Arduino-Makefile:

Code: Select all

BOARD_TAG = avrpi328_8     # AVRPi-328 ATmega328 @ 8 MHz
BOARD_TAG = avrpi328_12    # AVRPi-328 ATmega328 @ 12 MHz
BOARD_TAG = avrpi328_16    # AVRPi-328 ATmega328 @ 16 MHz
BOARD_TAG = avrpi32u4_8    # AVRPi-32U4 ATmega32U4 @ 8 MHz
BOARD_TAG = avrpi32u4_8cat # AVRPi-32U4 ATmega32U4 @ 8 MHz Caterina bootloader
BOARD_TAG = gert168        # Gertboard ATmega168 @ 12 MHz
BOARD_TAG = gert328        # Gertboard ATmega328 @ 12 MHz
BOARD_TAG = gertduino48    # Gertduino ATmega48 @ 8 MHz
BOARD_TAG = gertduino328   # Gertduino ATmega328 @ 16 MHz
BOARD_TAG = raspioduino    # RasPiO Duino ATmega328 @ 12 MHz
Note that for Gertduino, you still need the 'reset_off' and 'reset_unexport' scripts which are also provided and installed when using the Arduino IDE. Flashing firmware to Gertduino with the avrpi tool (avrpi -f blinky.hex) takes care of handling the reset pin correctly and the firmware automatically runs.

So if you're using one of those boards, you can also use this setup. There's also going to be support for some ATtiny's or AT90's for boards that you've soldered up yourself. Let me know if you want boards/chips added, or do the fork/patch/pullrequest thing.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: AVRPi-tools: avrdude-6.x/linuxgpio + Arduino IDE/libs

Sat Jan 02, 2016 8:57 pm

Update to avrdude-6.2 (2015-11-16) in the setup above.

Changelog:

Code: Select all

2015-11-16  Joerg Wunsch <[email protected]>

	* configure.ac: Released version 6.2.

2015-10-31  Joerg Wunsch <[email protected]>

	Submitted by Martino Facchin:
	bug #45727: Wrong atmega8u2 flash parameters
	* avrdude.conf.in (ATmega8U2): correct page and block size

2015-10-31  Joerg Wunsch <[email protected]>

	Submitted by Pasquale Cocchini:
	bug #46020: Add TIAO TUMPA to the conf file.
	* avrdude.conf.in (tumpa): New entry.

2015-10-31  Joerg Wunsch <[email protected]>

	Submitted by Pasquale Cocchini:
	bug #46021: Please add read in the memory lock section of ATtiny85
	* avrdude.conf.in (ATtiny25/45/85): add read pattern for lock bits

2015-10-31  Joerg Wunsch <[email protected]>

	* Makefile.am (libavrdude_a_SOURCES): reflect recent changes
	(pgm.h is gone, config.h is new).

2015-04-09  Joerg Wunsch <[email protected]>

	bug #44717: avrdude creates empty flash dump
	* update.c (do_op): When about to write an empty flash dump file,
	warn about this to avoid surprises.
	* avrdude.1: Document the truncation of trailing 0xFF bytes for
	flash memory areas.
	* doc/avrdude.texi: (Dito.)

2015-04-09  Joerg Wunsch <[email protected]>

	Annual ChangeLog rotation.
Because this topic needs pictures, here's selecting the 'linuxgpio' programmer in the Arduino IDE (version 1.0.5 in Jessie):

Image

And using 'Arduino-Makefile' in Geany:

Image
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

Return to “HATs and other add-ons”