Index of /~ts1/fonasp

[ICO]NameLast modifiedSizeDescription

[DIR]Parent Directory  -  
[   ]README.ja08-May-2009 15:21 3.0K 
[   ]fonasp-0.1.zip09-Apr-2009 17:09 19K 

fonasp - AVR serial programmer for La Fonera

fonasp is a program that runs on La Fonera to write program flash,
data EEPROM and fuses of Atmel AVR microcontroller.

La Fonera and AVR are connected like below:

    FON2100                     AVR
    -------------------         ----
    Pin 1 of SW1 (GPIO3) <--R-- MISO  
    Pin 2 of SW1 (GPIO4) -----> SCK   
    Pin 5 of SW1 (GPIO1) -----> MOSI  
    Pin 6 of SW1 (GPIO7) -----> RESET 

Another configuration is possible if you edit avrspi_gpio.c.

SW1 pins of FON2100 have 10K pull-down resisters and bypass capacitors.
Capacitors (C142-145) have to be removed.

Note that if your AVR runs at 5V, since Fonera GPIO is 3.3V,
a series resister at MISO pin (R) is needed. I used 4.7K.

Optionally RESET can be pulled up by <=4.7K (or <=3.3K if your AVR is 3.3V)
because GPIO is pulled down by 10K and AVR internal pull-up is ~100K,
so Hi-Z GPIO can reset AVR without strong pull-up.
(Alternatively, of course, you can remove pull-down resisters on Fonera.)

I tested this program on FON2100 only. FON2200 should work as well,
but I don't know if its GPIO configuration is same as 2100.

Supported AVR microcontroller is ATmega48, ATmega88 and ATmega168.
P/PA variants should work without modification.
Recent devices other than these might work as well with little or no
To write ATmega168 program flash, "-p 128" option is needed because 
default page size is 64 (bytes).
I tested ATmega48 only.

fonasp accepts program code and EEPROM data in binary format.
To convert linked AVR executable (ELF format) to binary, objcopy command
can be used:
    avr-gcc <object files>... -o firmware.elf
    avr-objcopy -O binary firmware.elf firmware.bin
If your executable has .eeprom and/or .fuse section, sections to convert
must be specified:
    avr-objcopy -O binary -j .text -j .data firmware.elf firmware.bin
Likewise, if you have initial contents of EEPROM in your program .eeprom
section (i.e. using EEMEM macro), it can be extracted to binary like this:
    avr-objcopy -O binary -j .eeprom firmware.elf firmware.eeprom

Resulted binary files can then be transfered to La Fonera and flashed 
like this:
    fonera# ./fonasp /tmp/firmware.bin
    fonera# ./fonasp -e /tmp/firmware.eeprom

fonasp does not use kernel GPIO driver.
Instead it directly reads and writes hardware registers so bit-banging
is fairly fast.

To build fonasp yourself, you need cross toolchain (GCC and friends)
for Fonera.
I used one from officical Fonera firmware source code.
Just "make" the source tree on Linux box and wait for a while,
cross gcc and friends are built and placed under staging-dir-mips directory.
On 64-bit Ubuntu the build process failed for some reason, but worked
ok on 32-bit Debian. Resulted toolchain can be used on 64-bit system
as well.

This program is written by Takeshi Sone and released under the terms of
GNU GPL version 2.

Takeshi Sone <ts1 at>