diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-08-07 19:48:59 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-08-07 19:48:59 +0000 |
commit | 8a2387e805a3cc8f8fb18fe2ab4da857bd8c32b6 (patch) | |
tree | 32dd17f71d1756aac95708eaf321bd51dda578c9 /bootloaders | |
parent | fddeda17175c6e27a86d60b92077c07c30d8333a (diff) |
Adding ATmega328 version of the Arduino BT bootloader, along with a Makefile for building it.
Diffstat (limited to 'bootloaders')
-rw-r--r-- | bootloaders/bt/ATmegaBOOT_168.c | 22 | ||||
-rw-r--r-- | bootloaders/bt/ATmegaBOOT_168_atmega328_bt.hex | 162 | ||||
-rwxr-xr-x | bootloaders/bt/Makefile | 109 |
3 files changed, 285 insertions, 8 deletions
diff --git a/bootloaders/bt/ATmegaBOOT_168.c b/bootloaders/bt/ATmegaBOOT_168.c index a85dc9a..c73eefa 100644 --- a/bootloaders/bt/ATmegaBOOT_168.c +++ b/bootloaders/bt/ATmegaBOOT_168.c @@ -79,7 +79,7 @@ /* the current avr-libc eeprom functions do not support the ATmega168 */ /* own eeprom write/read functions are used instead */ -#ifndef __AVR_ATmega168__ +#if !defined(__AVR_ATmega168__) || !defined(__AVR_ATmega328P__) #include <avr/eeprom.h> #endif @@ -189,6 +189,11 @@ #define SIG3 0x06 #define PAGE_SIZE 0x40U //64 words +#elif defined __AVR_ATmega328P__ +#define SIG2 0x95 +#define SIG3 0x0F +#define PAGE_SIZE 0x40U //64 words + #elif defined __AVR_ATmega162__ #define SIG2 0x94 #define SIG3 0x04 @@ -330,7 +335,8 @@ int main(void) UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8; UCSRA = 0x00; UCSRB = _BV(TXEN)|_BV(RXEN); -#elif defined __AVR_ATmega168__ +#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + UBRR0H = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1) >> 8; UBRR0L = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1); @@ -551,7 +557,7 @@ putch(0x0D); if (getch() == ' ') { if (flags.eeprom) { //Write to EEPROM one byte at a time for(w=0;w<length.word;w++) { -#ifdef __AVR_ATmega168__ +#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) while(EECR & (1<<EEPE)); EEAR = (uint16_t)(void *)address.word; EEDR = buff[w]; @@ -669,7 +675,7 @@ putch(0x0D); "rjmp write_page \n\t" "block_done: \n\t" "clr __zero_reg__ \n\t" //restore zero register -#if defined __AVR_ATmega168__ +#if defined __AVR_ATmega168__ || __AVR_ATmega328P__ : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" #else : "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" @@ -701,7 +707,7 @@ putch(0x0D); putch(0x14); for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay if (flags.eeprom) { // Byte access EEPROM read -#ifdef __AVR_ATmega168__ +#if defined __AVR_ATmega168__ || __AVR_ATmega328P__ while(EECR & (1<<EEPE)); EEAR = (uint16_t)(void *)address.word; EECR |= (1<<EERE); @@ -915,7 +921,7 @@ void putch(char ch) while (!(UCSR1A & _BV(UDRE1))); UDR1 = ch; } -#elif defined __AVR_ATmega168__ +#elif defined (__AVR_ATmega168__) || defined(__AVR_ATmega328P__) while (!(UCSR0A & _BV(UDRE0))); UDR0 = ch; #else @@ -938,7 +944,7 @@ char getch(void) return UDR1; } return 0; -#elif defined __AVR_ATmega168__ +#elif defined (__AVR_ATmega168__) || defined(__AVR_ATmega328P__) uint32_t count = 0; while(!(UCSR0A & _BV(RXC0))){ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ @@ -976,7 +982,7 @@ void getNch(uint8_t count) while(!(UCSR1A & _BV(RXC1))); UDR1; } -#elif defined __AVR_ATmega168__ +#elif (defined __AVR_ATmega168__) || defined(__AVR_ATmega328P__) while(!(UCSR0A & _BV(RXC0))); UDR0; #else diff --git a/bootloaders/bt/ATmegaBOOT_168_atmega328_bt.hex b/bootloaders/bt/ATmegaBOOT_168_atmega328_bt.hex new file mode 100644 index 0000000..a50c7c3 --- /dev/null +++ b/bootloaders/bt/ATmegaBOOT_168_atmega328_bt.hex @@ -0,0 +1,162 @@ +:107000000C9434380C9451380C9451380C945138F9
+:107010000C9451380C9451380C9451380C945138CC
+:107020000C9451380C9451380C9451380C945138BC
+:107030000C9451380C9451380C9451380C945138AC
+:107040000C9451380C9451380C9451380C9451389C
+:107050000C9451380C9451380C9451380C9451388C
+:107060000C9451380C94513811241FBECFEFD8E046
+:10707000DEBFCDBF11E0A0E0B1E0E4EEF9E702C071
+:1070800005900D92A230B107D9F712E0A2E0B1E06D
+:1070900001C01D92AC30B107E1F70E942D390C946C
+:1070A000F03C0C940038282F992787FD9095807F1D
+:1070B00090709595879595958795959587959595D4
+:1070C00087958A30C4F0382F395A822F8F708A30D2
+:1070D0007CF0982F995A8091C00085FFFCCF3093A7
+:1070E000C6008091C00085FFFCCF9093C600089534
+:1070F000982F905DF0CF382F305DE7CF982F80919B
+:10710000C00085FFFCCF9093C6000895EF92FF92D8
+:107110000F931F93EE24FF2487018091C00087FD09
+:1071200017C00894E11CF11C011D111D81E0E81637
+:1071300082E1F8068AE7080780E0180770F3E0911B
+:107140000301F091040109958091C00087FFE9CF08
+:107150008091C6001F910F91FF90EF9008951F93AB
+:107160000E948638182F8091C00085FFFCCF1093B5
+:10717000C6000E948638982F8091C00085FFFCCF02
+:107180009093C600113664F01755913674F490331D
+:107190000CF090531295107F892F810F1F91089545
+:1071A00010339CF31053913694F397551295107F3A
+:1071B000892F810F1F910895282F882351F090E087
+:1071C0008091C00087FFFCCF8091C6009F5F92171F
+:1071D000B8F308951F93182F0E948638803211F05B
+:1071E0001F9108958091C00085FFFCCF84E18093BA
+:1071F000C6008091C00085FFFCCF1093C60080912F
+:10720000C00085FFFCCF80E18093C6001F910895E8
+:107210000E948638803209F008958091C00085FF71
+:10722000FCCF84E18093C6008091C00085FFFCCF35
+:1072300080E18093C6000895882359F010920902D6
+:1072400090E02D9A2D989F5F9817D8F3909309029C
+:1072500008951092090283E0F3CF3F924F925F921C
+:107260006F927F928F929F92AF92BF92CF92DF9256
+:10727000EF92FF920F931F93CF93DF9300005698E6
+:107280005E9A1092C50088E08093C40088E18093E4
+:10729000C10086E08093C200259A579A5F9A21E048
+:1072A00040E050E0CA010197F1F72F5F2131D1F79B
+:1072B00080E1809309025F9883E00E941C398091ED
+:1072C000C00085FFFCCF83E58093C6008091C0009D
+:1072D00085FFFCCF85E48093C6008091C00085FFC8
+:1072E000FCCF84E58093C6008091C00085FFFCCF71
+:1072F00080E28093C6008091C00085FFFCCF82E4CD
+:107300008093C6008091C00085FFFCCF84E5809308
+:10731000C6008091C00085FFFCCF80E28093C6004C
+:107320008091C00085FFFCCF80E58093C6008091EE
+:10733000C00085FFFCCF81E48093C6008091C0002F
+:1073400085FFFCCF87E48093C6008091C00085FF55
+:10735000FCCF85E48093C6008091C00085FFFCCF00
+:107360008DE48093C6008091C00085FFFCCF8FE440
+:107370008093C6008091C00085FFFCCF84E4809399
+:10738000C6008091C00085FFFCCF85E48093C600D5
+:107390008091C00085FFFCCF80E28093C600809181
+:1073A000C00085FFFCCF83E38093C6008091C000BE
+:1073B00085FFFCCF80E28093C6008091C00085FFEE
+:1073C000FCCF82E38093C6008091C00085FFFCCF94
+:1073D00080E38093C6008091C00085FFFCCF80E3EE
+:1073E0008093C6008091C00085FFFCCF80E380932E
+:1073F000C6008091C00085FFFCCF80E28093C6006C
+:107400008091C00085FFFCCF81E38093C60080910E
+:10741000C00085FFFCCF8DE08093C6008091C00046
+:1074200085FFFCCF83E58093C6008091C00085FF77
+:10743000FCCF85E48093C6008091C00085FFFCCF1F
+:1074400084E58093C6008091C00085FFFCCF80E278
+:107450008093C6008091C00085FFFCCF82E48093BA
+:10746000C6008091C00085FFFCCF84E58093C600F4
+:107470008091C00085FFFCCF80E28093C6008091A0
+:10748000C00085FFFCCF82E58093C6008091C000DC
+:1074900085FFFCCF8FE48093C6008091C00085FFFC
+:1074A000FCCF8CE48093C6008091C00085FFFCCFA8
+:1074B00085E48093C6008091C00085FFFCCF80E208
+:1074C0008093C6008091C00085FFFCCF80E380934D
+:1074D000C6008091C00085FFFCCF80E28093C6008B
+:1074E0008091C00085FFFCCF86E68093C600809126
+:1074F000C00085FFFCCF80E28093C6008091C00071
+:1075000085FFFCCF87E38093C6008091C00085FF94
+:10751000FCCF84E68093C6008091C00085FFFCCF3D
+:1075200080E38093C6008091C00085FFFCCF80E39C
+:107530008093C6008091C00085FFFCCF8DE08093D2
+:10754000C60034E1F32E2EE1E22E95E9D92E8FE02C
+:10755000C82E00E1B02EAA24A39411E4912EB6E522
+:107560008B2EA2E57A2EF0E26F2EE9E45E2E73E513
+:10757000472E60E5362E0E948638803359F18133DC
+:10758000C9F1803409F472C0813409F486C08234B0
+:1075900021F1853409F474C08035E1F08135D1F0F2
+:1075A0008235C1F0853509F497C0863509F486C067
+:1075B000843609F4A0C0843709F40BC1853709F477
+:1075C00075C18637C1F680E00E94EA380E9486388D
+:1075D0008033A9F60E940839CECF90E08091C00098
+:1075E00087FFFCCF8091C6009F5F9431B9F70E945E
+:1075F0000839C1CF0E948638803209F0BCCF809113
+:10760000C00085FFFCCFF092C6008091C00085FFCE
+:10761000FCCF9092C6008091C00085FFFCCF809285
+:10762000C6008091C00085FFFCCF7092C60080919B
+:10763000C00085FFFCCF6092C6008091C00085FF2E
+:10764000FCCF5092C6008091C00085FFFCCF4092D5
+:10765000C6008091C00085FFFCCF3092C6008091AB
+:10766000C00085FFFCCFB092C60085CF0E9486384F
+:10767000863808F4AFCF0E9486380E9408397BCF45
+:1076800090E08091C00087FFFCCF8091C6009F5F93
+:107690009530B9F70E9408396ECF0E94863880383D
+:1076A00031F1813809F48DC0823809F48EC08839EF
+:1076B00009F089CF83E00E94EA385DCF90E08091A5
+:1076C000C00087FFFCCF8091C6009F5F9430B9F760
+:1076D00080E00E94EA387ACF0E94863880930501C4
+:1076E0000E948638809306010E94083944CF82E0C8
+:1076F0000E94EA3840CF0E948638809308020E9498
+:1077000086388093070280910B028E7F80930B0254
+:107710000E948638853429F480910B028160809321
+:107720000B028091070290910802892B89F000E0FA
+:1077300010E00E948638F801E95FFE4F80830F5FFA
+:107740001F4F80910702909108020817190788F3CC
+:107750000E948638803209F00ECF80910B0280FFA4
+:10776000CFC0A0910702B09108021097E9F0609194
+:10777000050170910601E7E0F1E09B01AD014E0FBC
+:107780005F1FF999FECF32BD21BD819180BDFA9A6C
+:10779000F99A2F5F3F4FE417F50799F76A0F7B1FA0
+:1077A00070930601609305018091C00085FFFCCFB6
+:1077B000F092C6008091C00085FFFCCFB092C60059
+:1077C000DACE81E00E94EA38D6CE8FE00E94EA3815
+:1077D000D2CE0E948638809308020E948638809319
+:1077E00007020E948638853409F484C080910B0218
+:1077F0008E7F80930B028091050190910601880F86
+:10780000991F90930601809305010E94863880326B
+:1078100009F0B1CE8091C00085FFFCCFF092C60088
+:10782000A0910702B09108021097B9F180910B0264
+:10783000182F1170082F0270E0910501F0910601D8
+:107840009F012F5F3F4FB90140E050E01123B1F499
+:10785000002339F494918091C00085FFFCCF909370
+:10786000C6004F5F5F4FCB010196F9014A175B07D6
+:1078700080F4BC012F5F3F4F112351F3F999FECFE4
+:10788000F2BDE1BDF89A90B58091C00085FFFCCFB4
+:10789000E6CF70930601609305018091C00085FDDD
+:1078A000E2CE8091C00085FFF8CFDDCE0E94863801
+:1078B000803209F060CE8091C00085FFFCCFF0924D
+:1078C000C6008091C00085FFFCCFE092C600809189
+:1078D000C00085FFFCCFD092C6008091C00085FF1C
+:1078E000FCCFC092C6008091C00085FFFCCFB09253
+:1078F000C60041CE80910B02816080930B0285CF40
+:10790000809106018823880F880B8A2180930A02C0
+:107910008091050190910601880F991F90930601AF
+:10792000809305018091070280FF09C080910702C2
+:107930009091080201969093080280930702F894B0
+:10794000F999FECF1127E0910501F0910601C7E0FA
+:10795000D1E08091070290910802103091F40091DB
+:10796000570001700130D9F303E000935700E89508
+:107970000091570001700130D9F301E100935700E5
+:10798000E895099019900091570001700130D9F3E2
+:1079900001E000935700E8951395103498F01127F3
+:1079A0000091570001700130D9F305E000935700B2
+:1079B000E8950091570001700130D9F301E100937F
+:1079C0005700E8953296029709F0C7CF103011F0B2
+:1079D0000296E5CF11248091C00085FFE5CEE8CE68
+:0479E000F894FFCF49
+:0279E400800021
+:040000030000700089
+:00000001FF
diff --git a/bootloaders/bt/Makefile b/bootloaders/bt/Makefile new file mode 100755 index 0000000..431f2e7 --- /dev/null +++ b/bootloaders/bt/Makefile @@ -0,0 +1,109 @@ +# Makefile for ATmegaBOOT +# E.Lins, 18.7.2005 +# $Id$ +# +# Instructions +# +# To make bootloader .hex file: +# make diecimila +# make lilypad +# make ng +# etc... +# +# To burn bootloader .hex file: +# make diecimila_isp +# make lilypad_isp +# make ng_isp +# etc... + +# program name should not be changed... +PROGRAM = ATmegaBOOT_168 + +# enter the parameters for the avrdude isp tool +ISPTOOL = stk500v2 +ISPPORT = usb +ISPSPEED = -b 115200 + +MCU_TARGET = atmega168 +LDSECTION = --section-start=.text=0x3800 + +# the efuse should really be 0xf8; since, however, only the lower +# three bits of that byte are used on the atmega168, avrdude gets +# confused if you specify 1's for the higher bits, see: +# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/ +# +# similarly, the lock bits should be 0xff instead of 0x3f (to +# unlock the bootloader section) and 0xcf instead of 0x0f (to +# lock it), but since the high two bits of the lock byte are +# unused, avrdude would get confused. + +ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ +-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m +ISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ +-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m + +STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" +STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \ +-lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt +STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt + + +OBJ = $(PROGRAM).o +OPTIMIZE = -O2 + +DEFS = +LIBS = + +CC = avr-gcc + +# Override is only needed by avr-lib build system. + +override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS) +override LDFLAGS = -Wl,$(LDSECTION) +#override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION) + +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump + +all: + +atmega328_bt: TARGET = atmega328_bt +atmega328_bt: MCU_TARGET = atmega328p +atmega328_bt: AVR_FREQ = 16000000L +atmega328_bt: LDSECTION = --section-start=.text=0x7000 +atmega328_bt: $(PROGRAM)_atmega328_bt.hex + +atmega328_bt_isp: atmega328_bt +atmega328_bt_isp: TARGET = atmega328_bt +atmega328_bt_isp: MCU_TARGET = atmega328p +atmega328_bt_isp: HFUSE = D8 +atmega328_bt_isp: LFUSE = FF +atmega328_bt_isp: EFUSE = 05 +atmega328_bt_isp: isp + +isp: $(TARGET) + $(ISPFUSES) + $(ISPFLASH) + +isp-stk500: $(PROGRAM)_$(TARGET).hex + $(STK500-1) + $(STK500-2) + +%.elf: $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) + +clean: + rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex + +%.lst: %.elf + $(OBJDUMP) -h -S $< > $@ + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.srec: %.elf + $(OBJCOPY) -j .text -j .data -O srec $< $@ + +%.bin: %.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ + |