Differences between revisions 4 and 12 (spanning 8 versions)
Revision 4 as of 2012-06-15 20:54:29
Size: 10148
Editor: fungi
Comment:
Revision 12 as of 2012-06-27 03:05:52
Size: 10783
Editor: fungi
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
I picked up a [[http://www.adafruit.com/products/46|USBtinyISP AVR Programmer Kit]], [[http://www.adafruit.com/products/174|Barebones AVR dev. board]] and [[http://www.adafruit.com/products/382|28-pin ZIF socket]] from Adafruit on the theory that it would be easier to preprogram the Atmega168 on a dedicated target board. Unfortunately, I followed the !SpiffChorder instructions slightly out of order and burned the external clocking fuse before writing the firmware, thus rendering the unclocked devboard useless... so instead I programmed the microcontroller in-circuit later once the 12MHz crystal and associated components were in place to clock it correctly. I used a machine running [[http://www.debian.org/|Debian GNU/Linux]] and installed their packages for [[http://packages.debian.org/avrdude|avrdude]] and [[http://packages.debian.org/avr-libc|avr-libc]]. You can test the rig after connecting the 6-pin USBtiny cable to ''CON1'' with it set to provide power (and make sure nothing is connected on ''CON2''). <<TableOfContents>>
= Getting an AVR Programmer =
I picked up a [[http://www.adafruit.com/products/46|USBtinyISP AVR Programmer Kit]] from [[http://www.adafruit.com/|Adafruit Industries]] for about US$25 including shipping. I also ordered a [[http://www.adafruit.com/products/174|Barebones AVR dev. board]] and [[http://www.adafruit.com/products/382|28-pin ZIF socket]] on the theory that it would be easier to preprogram the Atmega168 on a dedicated target board. While that '''should''' work, I followed the !SpiffChorder instructions slightly out of order and burned the external clocking fuse before writing the firmware (thus rendering the unclocked devboard useless for this purpose). Instead I programmed the microcontroller in-circuit [[../KeyerBreadboard|on a solderless breadboard]] later, once the 12MHz crystal and associated components were in place to clock it correctly. I used a machine running [[http://www.debian.org/|Debian GNU/Linux]] and installed their packages for [[http://packages.debian.org/avrdude|avrdude]] and [[http://packages.debian.org/avr-libc|avr-libc]].

= Testing the Programmer =
You can test the rig after connecting the 6-pin USBtiny cable to ''CON1'' with it set to provide power (and make sure nothing is connected on ''CON2'').
Line 17: Line 22:
Assuming it's all working, unpack the latest !SpiffChorder sources (I used 0.99) modify the ''USBaspLoader'' firmware Makefile, program the IC and set its fuses. = Writing the USB Bootloader =
Assuming your programmer is tested and working as above, unpack the latest !SpiffChorder sources (I used 0.99), modify the ''USBaspLoader'' firmware Makefile, program the IC and set its fuses.
Line 51: Line 57:

Line 60: Line 64:

Line 153: Line 155:
Now '''disconnect''' the programmer and '''then''' hold down all three thumb buttons (or short ''N'', ''C'' and ''F'' to ''GND'') while connecting the circuit via USB. If you have the LEDs wired, you should see ''LN'' and ''LF'' light up, indicating it's ready for programming through the virtual USBasp programmer. = Testing the USB Bootloader =
'''D
isconnect''' the programmer and '''then''' hold down all three thumb buttons (or short ''N'', ''C'' and ''F'' to ''GND'') while connecting the circuit via USB. If you have the LEDs wired, you should see ''LN'' and ''LF'' light up indicating it's ready for programming through the virtual USBasp programmer. Test to make sure you're communicating with it successfully.
Line 168: Line 171:
}}}

= Writing the SpiffChorder Firmware =
Now that USBasp is working, you'll be able to modify and update your !SpiffChorder as often as you like right through its USB connection to your machine without needing to break out your 'tiny.

{{{
Line 212: Line 220:

Line 223: Line 229:

Getting an AVR Programmer

I picked up a USBtinyISP AVR Programmer Kit from Adafruit Industries for about US$25 including shipping. I also ordered a Barebones AVR dev. board and 28-pin ZIF socket on the theory that it would be easier to preprogram the Atmega168 on a dedicated target board. While that should work, I followed the SpiffChorder instructions slightly out of order and burned the external clocking fuse before writing the firmware (thus rendering the unclocked devboard useless for this purpose). Instead I programmed the microcontroller in-circuit on a solderless breadboard later, once the 12MHz crystal and associated components were in place to clock it correctly. I used a machine running Debian GNU/Linux and installed their packages for avrdude and avr-libc.

Testing the Programmer

You can test the rig after connecting the 6-pin USBtiny cable to CON1 with it set to provide power (and make sure nothing is connected on CON2).

$ sudo avrdude -c usbtiny -p atmega168

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Writing the USB Bootloader

Assuming your programmer is tested and working as above, unpack the latest SpiffChorder sources (I used 0.99), modify the USBaspLoader firmware Makefile, program the IC and set its fuses.

$ unzip -q SpiffChorder-0.99.zip
$ cd SpiffChorder/USBaspLoader.2008-02-05/firmware
$ sed -i 's/^\(PROGRAMMER = -c\) .*/\1 usbtiny/' Makefile
$ make
avr-gcc -Wall -Os -I. -mmcu=atmega168 -DF_CPU=12000000  -x assembler-with-cpp -c usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o
avr-gcc -Wall -Os -I. -mmcu=atmega168 -DF_CPU=12000000  -c usbdrv/oddebug.c -o usbdrv/oddebug.o
avr-gcc -Wall -Os -I. -mmcu=atmega168 -DF_CPU=12000000  -c main.c -o main.o
usbdrv/usbdrv.h:198: warning: ‘usbFunctionDescriptor’ used but never defined
avr-gcc -Wall -Os -I. -mmcu=atmega168 -DF_CPU=12000000  -o main.bin usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o -Wl,--section-start=.text=3800
rm -f main.hex main.eep.hex
avr-objcopy -j .text -j .data -O ihex main.bin main.hex
avr-size main.hex
   text    data     bss     dec     hex filename
      0    2134       0    2134     856 main.hex
$ cp hexfiles/mega168_12mhz.hex main.hex
$ sudo make flash
avrdude -c usbtiny -p atmega168 -U flash:w:main.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: writing flash (16342 bytes):

Writing | ################################################## | 100% 9.58s

avrdude: 16342 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex contains 16342 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 8.56s

avrdude: verifying ...
avrdude: 16342 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

$ sudo make fuse
avrdude -c usbtiny -p atmega168 -U hfuse:w:0xd5:m -U lfuse:w:0xff:m -U efuse:w:0x00:m
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406
avrdude: reading input file "0xd5"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd5:avrdude: load data hfuse data from input file 0xd5:
avrdude: input file 0xd5 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0x00"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x00:
avrdude: load data efuse data from input file 0x00:
avrdude: input file 0x00 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

$ sudo make lock
avrdude -c usbtiny -p atmega168 -U lock:w:0x2f:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406
avrdude: reading input file "0x2f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x2f:
avrdude: load data lock data from input file 0x2f:
avrdude: input file 0x2f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Testing the USB Bootloader

Disconnect the programmer and then hold down all three thumb buttons (or short N, C and F to GND) while connecting the circuit via USB. If you have the LEDs wired, you should see LN and LF light up indicating it's ready for programming through the virtual USBasp programmer. Test to make sure you're communicating with it successfully.

$ sudo avrdude -c usbasp -p atmega168

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Writing the SpiffChorder Firmware

Now that USBasp is working, you'll be able to modify and update your SpiffChorder as often as you like right through its USB connection to your machine without needing to break out your 'tiny.

$ cd ../..
$ sudo make program

Compiling: main.c
avr-gcc -c -mmcu=atmega168 -I. -gdwarf-2 -DF_CPU=12000000UL -Iusbdrv  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99 -MD -MP -MF .dep/main.o.d main.c -o main.o -Ikeymaps/ -include nasa_us.h

Compiling: usbdrv/usbdrv.c
avr-gcc -c -mmcu=atmega168 -I. -gdwarf-2 -DF_CPU=12000000UL -Iusbdrv  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=usbdrv/usbdrv.lst  -std=gnu99 -MD -MP -MF .dep/usbdrv.o.d usbdrv/usbdrv.c -o usbdrv/usbdrv.o

Compiling: usbdrv/oddebug.c
avr-gcc -c -mmcu=atmega168 -I. -gdwarf-2 -DF_CPU=12000000UL -Iusbdrv  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=usbdrv/oddebug.lst  -std=gnu99 -MD -MP -MF .dep/oddebug.o.d usbdrv/oddebug.c -o usbdrv/oddebug.o

Assembling: usbdrv/usbdrvasm.S
avr-gcc -c -mmcu=atmega168 -I. -x assembler-with-cpp -Wa,-adhlns=usbdrv/usbdrvasm.lst,-gstabs  -DF_CPU=12000000UL usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o

Linking: spiffchorder.elf
avr-gcc -mmcu=atmega168 -I. -gdwarf-2 -DF_CPU=12000000UL -Iusbdrv  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=usbdrv/usbdrv.o  -std=gnu99 -MD -MP -MF .dep/spiffchorder.elf.d usbdrv/usbdrv.o usbdrv/oddebug.o main.o usbdrv/usbdrvasm.o --output spiffchorder.elf -Wl,-Map=spiffchorder.map,--cref  -Wl,-u,vfprintf -lprintf_min -Wl,-u,vfscanf -lscanf_min

Creating load file for Flash: spiffchorder.hex
avr-objcopy -O ihex -R .eeprom spiffchorder.elf spiffchorder.hex

Creating load file for EEPROM: spiffchorder.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O ihex spiffchorder.elf spiffchorder.eep
avr-objcopy: --change-section-lma .eeprom=0x00000000 never used
avrdude -p atmega168  -c usbasp    -U flash:w:spiffchorder.hex

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "spiffchorder.hex"
avrdude: input file spiffchorder.hex auto detected as Intel Hex
avrdude: writing flash (5922 bytes):

Writing | ################################################## | 100% 1.33s

avrdude: 5922 bytes of flash written
avrdude: verifying flash memory against spiffchorder.hex:
avrdude: load data flash data from input file spiffchorder.hex:
avrdude: input file spiffchorder.hex auto detected as Intel Hex
avrdude: input file spiffchorder.hex contains 5922 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.95s

avrdude: verifying ...
avrdude: 5922 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


back to The Man-Machine...

CCL: ManMachine/KeyerProgramming (last edited 2012-06-27 03:05:52 by fungi)

CC0 To the extent possible under law, the creator of this work has waived all copyright and related or neighboring rights to it.