Avr Usb
Avr Usb
== Goal ==
* Build AVR USB development environment
* It should be:
* Self-Sufficient
* The board should have USB bootloader to update program
* Failure recovery well considered
* Given two boards, even if s/he mistakenly overrides USB bootloader, it shou
ld be possible to update bootloader using another board.
== Hardware ==
* Fast enough
* It should run maximam speed
* 20MHz clock
* Vcc should be 5V
* Use Zener diode method to lower D-/D+ signal
* http://avrusb.wikidot.com/hardware
== Bootstrap process of development environment ==
1. [wiki:USBserialAVRwriter]: Build a AVR-programmer with USB-serial (FT232RL)
module
* http://akizukidenshi.com/catalog/items2.php?p=1&q=%22K-01977%22
* Connection:
* reset=!rts sck=!dtr mosi=!txd miso=!cts
* xtal
* Changes in /etc/avrdude.conf
{{{
programmer
id
= "fsij";
desc = "design fsij serial, reset=!rts sck=!dtr mosi=!txd miso=!cts";
type = serbb;
reset = ~7;
sck = ~4;
mosi = ~3;
miso = ~8;
;
#
}}}
2. Test ATmega88 with SerialAVRwriter.
* Application: LED on/off for PC5-pin.
{{{
#define F_CPU 20000000
#include <avr/io.h>
#include <util/delay.h>
main()
{
DDRC |= _BV(DDC5);
PORTC = 0;
while(1) {
PORTC ^= _BV(PC5); // toggle PC5
_delay_ms(500);
}
}
}}}
3. Write the firmware of USBasp into ATmega88, using USBserialAVRwriter.
* I used http://www.fischl.de/usbasp/usbasp.2007-10-23.tar.gz
* Chages in Makefile:
{{{
TARGET=atmega88
HFUSE=0xdd
LFUSE=0xff
}}}
* Compilation
{{{
Compilation started at Wed Jul 2 09:22:35
make main.hex
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -c usbdrv/usbdrv.c -o usbdrv/usbd
rv.o
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -x assembler-with-cpp -c usbdrv/u
sbdrvasm.S -o usbdrv/usbdrvasm.o
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -c usbdrv/oddebug.c -o usbdrv/odd
ebug.o
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -c isp.c -o isp.o
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -c clock.c -o clock.o
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -c main.c -o main.o
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega88 -o main.bin usbdrv/usbdrv.o usbdr
v/usbdrvasm.o usbdrv/oddebug.o isp.o clock.o main.o -Wl,-Map,main.map
rm -f main.hex main.eep.hex
avr-objcopy -j .text -j .data -O ihex main.bin main.hex
Compilation finished at Wed Jul 2 09:22:38
}}}
* Program (using USBserialAVRwriter)
{{{
usbasp.2007-10-23/firmware$ avrdude -c fsij -p atmega88 -P /dev/ttyUSB0 -U flash
:w:main.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.59s
avrdude: Device signature = 0x1e930a
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: input file main.hex auto detected as Intel Hex
avrdude: writing flash (3828 bytes):
Writing | ################################################## | 100% 751.32s
avrdude:
avrdude:
avrdude:
avrdude:
avrdude:
avrdude:
verifying ...
1 bytes of hfuse verified
reading input file "0xff"
writing lfuse (1 bytes):
+++ main.c
2008-07-02 14:40:41.000000000 +0900
@@ -100,6 +100,8 @@
0x1e, 0x94, 0x06, 0
#elif defined (__AVR_ATmega328P__)
0x1e, 0x95, 0x0f, 0
+#elif defined (__AVR_ATmega644P__)
+
0x1e, 0x96, 0x0a, 0
#else
# error "Device signature is not known, please edit main.c!"
#endif
}}}
{{{
--- Makefile~ 2008-02-06 03:42:35.000000000 +0900
+++ Makefile
2008-07-02 20:46:09.000000000 +0900
@@ -14,10 +14,10 @@
#
make flash # to load the boot loader into flash
#
make lock
# to protect the boot loader from overwriting
-F_CPU = 16000000
-DEVICE = atmega168
-BOOTLOADER_ADDRESS = 3800
-FUSEOPT = $(FUSEOPT_168)
+F_CPU = 20000000
+DEVICE = atmega644p
+BOOTLOADER_ADDRESS = e000
+FUSEOPT = $(FUSEOPT_644P)
LOCKOPT = -U lock:w:0x2f:m
PROGRAMMER = -c stk500v2 -P avrdoper
@@ -26,6 +26,7 @@
FUSEOPT_8 = -U hfuse:w:0xc0:m -U lfuse:w:0x9f:m
FUSEOPT_88 = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0x00:m
FUSEOPT_168 = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0x00:m
+FUSEOPT_644P = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0xfe:m
# You may have to change the order of these -U commands.
#--------------------------------------------------------------------@@ -70,6 +71,31 @@
#
| | +--------------- SUT 1..0 (crystal osc, BOD enabled)
#
| +------------------ CKOUT (if 0: Clock output enabled)
#
+-------------------- CKDIV8 (if 0: divide by 8)
+#--------------------------------------------------------------------+# ATMega644P
+#--------------------------------------------------------------------+# Fuse extended byte:
+# 0xfe = 1 1 1 1 1 1 1 0
+#
\-+-/
+#
+------ BODLEVEL 0..2 (110 = 1.8 V)
+#
+# Fuse high byte:
+# 0xd0 = 1 1 0 1 0 0 0 0 <-- BOOTRST (boot reset vector at 0x7000)
+#
^ ^ ^ ^ ^ \+/
+#
| | | | | +------- BOOTSZ (00 = 8k bytes)
+#
| | | | + --------- EESAVE (preserve EEPROM over chip erase)
+#
| | | +-------------- WDTON (if 0: watchdog always on)
+#
| | +---------------- SPIEN (allow serial programming)
+#
| +------------------ JTAGEN (JTAG wire enable if 0)
+#
+-------------------- OCDEN (OCD enable if 0)
+#
+# Fuse low byte:
+# 0xdf = 1 1 0 1 1 1 1 1
+#
^ ^ \ / \--+--/
+#
| | |
+------- CKSEL 3..0 (external >8M crystal)
+#
| | +--------------- SUT 1..0 (crystal osc, BOD enabled)
+#
| +------------------ CKOUT (if 0: Clock output enabled)
+#
+-------------------- CKDIV8 (if 0: divide by 8)
###############################################################################
}}}
* Edit bootloaderconfig.h, if needed
* compile
{{{
$ make main.hex
}}}
6. Build final board. [[Image(Self-USBprogrammable-ATmega644P.jpg)]]
7. Using USBasp, write USBaspLoader firmware into ATmega644P (and ATmega88).
* At the beginning, put short-pin onto JP3 for slow mode, if it doesn't work
well.
{{{
USBaspLoader.2008-02-05/firmware# avrdude -p m644p -c usbasp -U flash:w:main.hex
:i
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e960a
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 (33052 bytes):
Writing | ################################################## | 100% 6.06s
avrdude:
avrdude:
avrdude:
avrdude:
avrdude:
verifying ...
1 bytes of hfuse verified
reading input file "0xdf"
writing lfuse (1 bytes):
verifying ...
1 bytes of lfuse verified
reading input file "0xfe"
writing efuse (1 bytes):
main()
{
DDRA |= _BV(DDA0);
PORTA = 0;
while(1) {
PORTA ^= _BV(PA0); // toggle PA0
_delay_ms(500);
}
}
}}}
* Compile
{{{
$ avr-gcc -mmcu=atmega644p -o avr-pa0.bin avr-pa0.c
$ avr-objcopy -j .text -j .data -O ihex avr-pa0.bin avr-pa0.hex
}}}
* Program
{{{
# avrdude -p atmega644p -c USBasp -v -U flash:w:avr-pa0.hex:i
avrdude: Version 5.5, compiled on Mar 4 2008 at 22:20:21
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/home/gniibe/.avrduderc"
User configuration file does not exist or is not a regular file, skippi
ng
Using Port
Using Programmer
AVR Part
Chip Erase delay
PAGEL
BS2
RESET disposition
RETRY pulse
serial program mode
parallel program mode
Timeout
StabDelay
CmdexeDelay
SyncLoops
ByteDelay
PollIndex
PollValue
Memory Detail
W
-00
00
00
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
/dev/parport0
USBasp
ATMEGA644P
9000 us
PD7
PA0
dedicated
SCK
yes
yes
200
100
25
32
0
3
0x53
Block Poll
Polled
Memory Type Mode Delay Size Indx Paged Size
ReadBack
----------- ---- ----- ----- ---- ------ -------------eeprom
65
10 128
0 no
2048
0xff 0xff
flash
33
6 256
0 yes
65536
0xff 0xff
lock
0
0
0
0 no
1
0x00 0x00
Page
Size #Pages MinW Max
---- ------ ----- --8
0 9000 90
256
256 4500 45
0 9000 90
lfuse
00 0x00 0x00
hfuse
00 0x00 0x00
efuse
00 0x00 0x00
signature
0 0x00 0x00
calibration
0 0x00 0x00
0 no
0 9000 90
0 no
0 9000 90
0 no
0 9000 90
0 no
0 no
avrdude:
avrdude:
avrdude:
avrdude:
avrdude:
safemode:
safemode:
safemode:
safemode:
lfuse
hfuse
efuse
Fuses
reads as 0
reads as 0
reads as 0
OK
#
}}}
---= Information =
== Downloader ==
* http://www.obdev.at/products/avrusb/usbasploader.html
== Programmer ==
=== Firmware ===
* USBaspLoader: USBasp compatible bootloader http://www.obdev.at/products/avrus
b/usbasploader.html
=== Software ===
* AVRdude: http://www.bsdhome.com/avrdude/
=== Hardware ===
* USBasp: http://www.fischl.de/usbasp/index.html
* ATmega48/88/168 AVR writer: ~~https://www3.t-agency.net/~wsnak/kit/172/index
.htm~~
http://www.wsnak.com/kit/172/index.htm
* USBprog: http://www.embedded-projects.net/index.php?page_id=165
* Kit 32+5 Euro: http://shop.embedded-projects.net/product_info.php?info=p6_usb
prog-v3-0--adaptor-preassembled-.html&XTCsid=c402f7c4dcad9a3530089f2e05402bc9
* !AvrUsb500v2 (stk500 V2 compatible): http://tuxgraphics.org/electronics/20070
5/article07052.shtml
== Links ==
Some pages are in Japanese...
C002 USB B
C010 12MHz
C011 3.6V (2)
P172 #172 ATmega48/88/168 /AVR
()
}}}
=== : 2008 06 17 ===
* Sunhayato USB CK 20
* 760()
* 20MHz
* 500(10)
* 3.6V() NEC RD3.6E 0.5W
* 100(5)
* ATmega88 20PU
* 2504
* ATmega644P 20PU
* 5502
60
70
50
500
5
2
2
300
140
100
3
1500
600
2640