From: Manfred Steiner Date: Tue, 3 Sep 2024 11:54:42 +0000 (+0200) Subject: Arduino Bootloader (not tested) X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=01882a1536228e2cd312318f4db5744ee979a342;p=nano-x.git Arduino Bootloader (not tested) --- diff --git a/software/bootloader-arduino/.vscode/c_cpp_properties.json b/software/bootloader-arduino/.vscode/c_cpp_properties.json index b3212bc..773ff69 100644 --- a/software/bootloader-arduino/.vscode/c_cpp_properties.json +++ b/software/bootloader-arduino/.vscode/c_cpp_properties.json @@ -9,7 +9,7 @@ "defines": [], "compilerPath": "/usr/bin/avr-gcc", "compilerArgs": [ - "-mmcu=atmega644p", + "-mmcu=atmega1284p", "-Os", "-DF_CPU=12000000", "-DBAUD_RATE=115200", diff --git a/software/bootloader-arduino/Makefile b/software/bootloader-arduino/Makefile index 67d4eb0..665918a 100644 --- a/software/bootloader-arduino/Makefile +++ b/software/bootloader-arduino/Makefile @@ -1,30 +1,10 @@ -#.PHONY: all info flash picocom clean -#$(shell mkdir -p dist >/dev/null) -#$(shell mkdir -p build >/dev/null) -#$(shell mkdir -p sim >/dev/null) - -#NAME="bootloader-arduino_nano-644" -#DEVICE="atmega644p" -#SRC= $(wildcard src/*.c) -#OBJ = $(SRC:src/%.c=build/%.o) -#OBJ_SIM = $(SRC:src/%.c=sim/%.o) - -#CC= avr-gcc -#CFLAGS_DEFINES= -DF_CPU=12000000 -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -#LFLAGS_DEFINES= -DF_CPU=12000000 -#CFLAGS= -Wall -mmcu=$(DEVICE) -Os $(CFLAGS_DEFINES) -c -#LFLAGS= -Wall -mmcu=$(DEVICE) -Os $(LFLAGS_DEFINES) -Wl,--section-start=.text=0xe000 - -#CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -O1 $(CFLAGS_DEFINES) -g -c -#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -O1 $(LFLAGS_DEFINES) -g -Wl,--section-start=.text=0xe000 - .PHONY: all info flash picocom clean $(shell mkdir -p dist >/dev/null) $(shell mkdir -p build >/dev/null) $(shell mkdir -p sim >/dev/null) $(shell mkdir -p sim/build >/dev/null) -NAME="bootloader-arduino_nano-644" +NAME="bootloader-arduino_nano-1284" SRC= $(wildcard src/*.c src/*.cpp src/*/*.c src/*/*.cpp) HDR= $(wildcard src/*.h src/*.hpp src/*/*.h src/*/*.hpp) OBJ_CPP = $(SRC:src/%.cpp=build/%.o) @@ -32,16 +12,16 @@ OBJ = $(OBJ_CPP:src/%.c=build/%.o) OBJ_SIM_CPP = $(SRC:src/%.cpp=sim/build/%.o) OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o) -DEVICE=atmega644p +DEVICE=atmega1284p CC= avr-g++ CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c #LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -Wl,--section-start=.text=0xe000 +LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -Wl,--section-start=.text=0x1e000 CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c #LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,--section-start=.text=0xe000 +LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,--section-start=.text=0x1e000 all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info @@ -64,7 +44,7 @@ info: @avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf .depend: $(SRC) $(HDR) - $(CC) --mcu=$(DEVICE) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend + $(CC) -mmcu=$(DEVICE) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend -include .depend @@ -109,30 +89,26 @@ simuc: sim/$(NAME).elf gdb: sim/$(NAME).elf avr-gdb $< -isp-644p: - avrdude -c usbasp -p m644p +isp-1284p: + avrdude -c usbasp -p m1284p -isp-flash-644p: dist/$(NAME).elf all - avrdude -c usbasp -p m644p -e -U flash:w:$< +isp-flash-1284p: dist/$(NAME).elf all + avrdude -c usbasp -p m1284p -e -U flash:w:$< -flash-644p: dist/$(NAME).elf all - avrdude -c arduino -p m644p -P /dev/ttyUSB0 -b 115200 -e -U flash:w:$< +flash-1284p: dist/$(NAME).elf all + avrdude -c arduino -p m1284p -P /dev/ttyUSB0 -b 115200 -e -U flash:w:$< picocom: # picocom sends CR for ENTER -> convert cr (\r) to lf (\n) picocom -b 115200 --omap crlf /dev/ttyUSB0 -isp-erase-644p: - avrdude -c usbasp -p m644p -e +isp-erase-1284p: + avrdude -c usbasp -p m1284p -e -isp-fuse-644p: - #avrdude -c usbasp -p m644p -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFF:m -U lock:w:0xFF:m - #avrdude -c usbasp -p m644p -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m - # LFUSE=0xEE -> startuptime 1K CLOCKS + 0ms -> 83us - #avrdude -c usbasp -p m644p -U lfuse:w:0xEE:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m +isp-fuse-1284p: # LFUSE=0xE7 -> startuptime 16K CLOCKS + 4.1ms -> 5.4ms - avrdude -c usbasp -p m644p -U lfuse:w:0xE7:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m + avrdude -c usbasp -p m1284p -U lfuse:w:0xEF:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m clean: @rm -r dist diff --git a/software/bootloader-arduino/README.md b/software/bootloader-arduino/README.md index bdcf921..81b4a47 100644 --- a/software/bootloader-arduino/README.md +++ b/software/bootloader-arduino/README.md @@ -1,19 +1,19 @@ -# Arduino-Bootloader (STK500) für Nano-644 +# Arduino-Bootloader (STK500) für Nano-1284 Dieser Bootloader ermöglicht die Programmierung über das "Arduino-System". Als Kommunikationsprotokoll kommt das [STK500 Protokoll]( https://www.microchip.com/content/dam/mchp/documents/OTH/ApplicationNotes/ApplicationNotes/doc2525.pdf) zur Anwendung (Kommunikationsablauf siehe Datei [protocol](protocol)). -Beim Bootloader in [src/main.c](src/main.c) handelt es sich um eine Anpassung von [https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/atmega/ATmegaBOOT_168.c](https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/atmega/ATmegaBOOT_168.c) an die Hardware des Nano-644 Boards. +Beim Bootloader in [src/main.c](src/main.c) handelt es sich um eine Anpassung von [https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/atmega/ATmegaBOOT_168.c](https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/atmega/ATmegaBOOT_168.c) an die Hardware des Nano-1284 Boards. Diese Anpassung der Quelltext-Datei umfasst: -* Microcontroller Atmega644P (mit 64KiB Flash, davon die hinteren 8KiB für den Bootloader) +* Microcontroller ATmega1284P (mit 128KiB Flash, davon die hinteren 8KiB für den Bootloader) * Frequenz 12MHz * 3 LEDs (rot, gelb, grün) * Assembler-Anweisungen durch Macros aus `avr/boot.h` ersetzt * Quelltextkorrekturen, damit der Bootloader auch bei einer Page-Size von 256 Byte funktioniert Der Bootloader kann entweder selbst aus der Quelltextdatei erzeugt werden (siehe [Übersetzung](#%C3%BCbersetzung)), oder es wird eine der bereits fertigen Dateien im Ordner [release](release) verwendet: -* [release/bootloader-arduino_nano-644.elf](release/bootloader-arduino_nano-644.elf) -* [release/bootloader-arduino_nano-644.hex](release/bootloader-arduino_nano-644.hex) +* [release/bootloader-arduino_nano-1284.elf](release/bootloader-arduino_nano-1284.elf) +* [release/bootloader-arduino_nano-1284.hex](release/bootloader-arduino_nano-1284.hex) ## Übersetzung @@ -48,7 +48,7 @@ Sobald sich am µC ein Bootloader befindet ist kein Programmiergerät mehr erfor UART-Schnittstelle (Option `-P`) und Name der ELF-Programmdatei (nach `flash:w:`) sind anzupassen... ```sh -avrdude -c arduino -p m644p -P /dev/ttyUSB0 -b 115200 -e -U flash:w:programm.elf +avrdude -c arduino -p m1284p -P /dev/ttyUSB0 -b 115200 -e -U flash:w:programm.elf ``` ## Einbindung in die Arduino IDE @@ -58,52 +58,52 @@ Zunächst den Ordner mit der Arduino Installation finden. Unter Linux ist das de /usr/share/arduino/hardware/arduino/avr ``` -Dort im Unterordner `bootloaders` einen Ordner `atmeg644` anlegen und darin die Intel-Hex Datei des Bootloaders ablegen. +Dort im Unterordner `bootloaders` einen Ordner `atmeg1284` anlegen und darin die Intel-Hex Datei des Bootloaders ablegen. ```sh make -sudo mkdir /usr/share/arduino/hardware/arduino/avr/bootloaders/atmega644 -cp dist/bootloader-arduino_nano-644.hex /usr/share/arduino/hardware/arduino/avr/bootloaders/atmega644/ +sudo mkdir /usr/share/arduino/hardware/arduino/avr/bootloaders/atmega1284 +cp dist/bootloader-arduino_nano-1284.hex /usr/share/arduino/hardware/arduino/avr/bootloaders/atmega1284/ ``` Danach in der Datei `/usr/share/arduino/hardware/arduino/avr/boards.txt` folgende Einträge ergänzen: ``` ######################################################### -nano644.name=Nano-644 - -nano644.vid.0=0x1a86 -nano644.pid.0=0x7522 -nano644.upload_port.0.vid=0x1a86 -nano644.upload_port.0.pid=0x7522 - -nano644.upload.tool=avrdude -nano644.upload.tool.default=avrdude -nano644.upload.tool.network=arduino_ota -nano644.upload.protocol=arduino -nano644.upload.maximum_size=57344 -nano644.upload.maximum_data_size=4096 -nano644.upload.speed=115200 - -nano644.bootloader.tool=avrdude -nano644.bootloader.tool.default=avrdude -nano644.bootloader.low_fuses=0xFF -nano644.bootloader.high_fuses=0xD8 -nano644.bootloader.extended_fuses=0xFF -nano644.bootloader.unlock_bits=0xFE -nano644.bootloader.lock_bits=0xEF -nano644.bootloader.file=atmega644/bootloader-arduino_nano-644.hex - -nano644.build.mcu=atmega644p -nano644.build.f_cpu=12000000L -nano644.build.board=AVR_NANO644 -nano644.build.core=arduino -nano644.build.variant=standard +nano1284.name=Nano-1284 + +nano1284.vid.0=0x1a86 +nano1284.pid.0=0x7522 +nano1284.upload_port.0.vid=0x1a86 +nano1284.upload_port.0.pid=0x7522 + +nano1284.upload.tool=avrdude +nano1284.upload.tool.default=avrdude +nano1284.upload.tool.network=arduino_ota +nano1284.upload.protocol=arduino +nano1284.upload.maximum_size=122880 +nano1284.upload.maximum_data_size=16384 +nano1284.upload.speed=115200 + +nano1284.bootloader.tool=avrdude +nano1284.bootloader.tool.default=avrdude +nano1284.bootloader.low_fuses=0xEF +nano1284.bootloader.high_fuses=0xD8 +nano1284.bootloader.extended_fuses=0xFE +nano1284.bootloader.unlock_bits=0xFE +nano1284.bootloader.lock_bits=0xEF +nano1284.bootloader.file=atmega1284/bootloader-arduino_nano-1284.hex + +nano1284.build.mcu=atmega1284p +nano1284.build.f_cpu=12000000L +nano1284.build.board=AVR_NANO1284 +nano1284.build.core=arduino +nano1284.build.variant=standard ############################################################## ``` Nach dem Start der Arduino-IDE kann: -* über das Menü *Werkzeuge->Board* das ***Nano-644*** gewählt werden +* über das Menü *Werkzeuge->Board* das ***Nano-1284*** gewählt werden * über das Menü *Werkzeuge->Programmer* der ***ArduinoISP*** gewählt werden diff --git a/software/bootloader-arduino/release/.gitkeep b/software/bootloader-arduino/release/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/software/bootloader-arduino/release/bootloader-arduino_nano-644.elf b/software/bootloader-arduino/release/bootloader-arduino_nano-644.elf deleted file mode 100755 index 55dab47..0000000 Binary files a/software/bootloader-arduino/release/bootloader-arduino_nano-644.elf and /dev/null differ diff --git a/software/bootloader-arduino/release/bootloader-arduino_nano-644.hex b/software/bootloader-arduino/release/bootloader-arduino_nano-644.hex deleted file mode 100644 index dbb4b22..0000000 --- a/software/bootloader-arduino/release/bootloader-arduino_nano-644.hex +++ /dev/null @@ -1,98 +0,0 @@ -:10E000000C943E700C9450700C9450700C945070A2 -:10E010000C9450700C9450700C9450700C94507080 -:10E020000C9450700C9450700C9450700C94507070 -:10E030000C9450700C9450700C9450700C94507060 -:10E040000C9450700C9450700C9450700C94507050 -:10E050000C9450700C9450700C9450700C94507040 -:10E060000C9450700C9450700C9450700C94507030 -:10E070000C9450700C9450700C94507011241FBE6E -:10E08000CFEFD0E1DEBFCDBF22E0A0E0B1E001C024 -:10E090001D92AC30B207E1F70E9435710C94FC720E -:10E0A0000C9400709091C00095FFFCCF8093C60047 -:10E0B0000895CF93982F8595859585958595805D55 -:10E0C0009F709A3014F0C7E501C0C0E3C90F0E94E9 -:10E0D00052708C2FCF910C945270CF92DF92EF92AE -:10E0E000FF92C12CD12C76018091C00087FD15C014 -:10E0F0008FEFC81AD80AE80AF80A81EBC81681E738 -:10E10000D8068BE0E806F10478F317B818B8E09168 -:10E110000001F09101010995E7CF8091C600FF90C1 -:10E12000EF90DF90CF900895CF930E946D70C82F2D -:10E130000E945270C13614F089EA03C0C0331CF04B -:10E1400080ED8C0F01C08C2FCF910895CF930E944A -:10E150009470C82F0E94947090E1C99F800D112483 -:10E16000CF910895CF93C82FCC2321F00E946D70DA -:10E17000C150FACFCF910895CF93C82F0E946D70F0 -:10E18000803251F484E10E9452708C2F0E945270B0 -:10E1900080E1CF910C945270809102018F5F809347 -:10E1A0000201853041F417B818B8E0910001F091F0 -:10E1B0000101CF910994CF9108950E946D70803232 -:10E1C00031F484E10E94527080E10C94527080918D -:10E1D00002018F5F80930201853039F417B818B8B7 -:10E1E000E0910001F091010109940895CF93DF932C -:10E1F00000D000D0CDB7DEB719821A821B821C82F4 -:10E2000089819A81AB81BC8181159042A140B10581 -:10E2100080F48091C00087FD0CC089819A81AB8118 -:10E22000BC810196A11DB11D89839A83AB83BC83F8 -:10E23000E7CF0F900F900F900F90DF91CF9108953F -:10E24000CF93C82F429A0E94F670439A0E94F670AC -:10E2500018B8CC2341F0449A0E94F67044980E946A -:10E26000F670C150F6CFCF91089500008CE187B9C8 -:10E2700018B882E08093C0008CE08093C4001092B4 -:10E28000C50088E18093C10086E08093C20098E0D9 -:10E290009093C9008093CA0084E00E94207113E02B -:10E2A00001E0E5E0FE2EF1E1EF2E0E946D7080337B -:10E2B00009F447C0813319F50E946D708032B9F4BA -:10E2C00084E10E94527081E40E94527086E50E94AF -:10E2D000527082E50E94527080E20E94527089E47E -:10E2E0000E94527083E50E94527080E56CC180915B -:10E2F00002018F5F809302018530B9F671C18034CD -:10E3000039F40E946D708638E0F00E946D7019C07B -:10E31000813491F40E946D70803811F481EF44C013 -:10E32000813811F481E040C0823811F480E13CC0B2 -:10E330008839C9F583E038C0823431F484E10E9421 -:10E34000B2700E94DD70B1CF853411F485E0F7CF53 -:10E35000982F9D7F9035A9F3813599F3853549F440 -:10E360000E946D70809304010E946D70809305017E -:10E37000E8CF8635E1F40E946D70803389F40E9405 -:10E380006D700E946D70C82F0E946D70C11102C027 -:10E390008EE10AC0C13011F486E906C08AE004C0EB -:10E3A00083E00E94B27080E00E94BC707ECF843611 -:10E3B00009F0A5C00E946D70809308020E946D70E4 -:10E3C0008093070280910B028E7F80930B020E9444 -:10E3D0006D70853429F480910B02816080930B026B -:10E3E000C6E0D1E06E012091070230910802C6011B -:10E3F000865091408217930730F40E946D70F601A9 -:10E4000081936F01F0CF0E946D70803209F0E1C0FE -:10E4100020910B028091040190910501880F991FB2 -:10E42000909305018093040120FF23C0E6E0F1E012 -:10E430002091070230910802CF0186509140821747 -:10E44000930708F05AC0F999FECF8091040190918A -:10E45000050192BD81BD819180BDFA9AF99A8091A2 -:10E4600004019091050101969093050180930401A8 -:10E47000DFCF8091070280FF09C080910702909151 -:10E48000080201969093080280930702F894409145 -:10E49000040150910501F999FECF07B600FCFDCFAC -:10E4A000FA0110935700E89507B600FCFDCF20E075 -:10E4B00030E0FA01E20FF31F898190E0982F88275E -:10E4C0006881860F911D0C0100935700E895112477 -:10E4D0002E5F3F4F22962115F1E03F0751F7309311 -:10E4E0000A0220930902FA01F0925700E89507B654 -:10E4F00000FCFDCFE0925700E89584E164C08437CA -:10E5000009F051C00E946D70809308020E946D70E6 -:10E51000809307028091040190910501880F991F53 -:10E5200090930501809304010E946D7090910B02FD -:10E53000853411F4916001C09E7F90930B020E947C -:10E540006D70803209F041C084E10E945270C0E0D9 -:10E55000D0E08091070290910802C817D907A8F56A -:10E5600080910B0280FF0BC0F999FECF80910401CE -:10E570009091050192BD81BDF89A80B507C081FDDB -:10E5800007C0E0910401F091050184910E9452704E -:10E59000809104019091050101969093050180936B -:10E5A00004012196D6CF853719F50E946D7080320F -:10E5B00081F484E10E9452708EE10E94527086E9DB -:10E5C0000E9452708AE00E94527080E10E94527054 -:10E5D0006CCE809102018F5F80930201853009F437 -:10E5E00017B818B8E0910001F091010109955DCECE -:0CE5F000863709F05ACED7CEF894FFCF42 -:040000030000E00019 -:00000001FF diff --git a/software/bootloader-arduino/src/main.c b/software/bootloader-arduino/src/main.c index 7f9c87c..cf6cede 100644 --- a/software/bootloader-arduino/src/main.c +++ b/software/bootloader-arduino/src/main.c @@ -289,9 +289,9 @@ int main () { // Write to FLASH one page at a time if (address.byte[1] > 127) { //Only possible with m128, m256 will need 3rd address byte. FIXME - // RAMPZ = 0x01; + RAMPZ = 0x01; } else { - // RAMPZ = 0x00; + RAMPZ = 0x00; } // address * 2 -> byte location @@ -374,8 +374,9 @@ int main () { else { if (!flags.rampz) { putch(pgm_read_byte_near(address.word)); - // putch(pgm_read_byte_far(address.word + 0x10000)); - } + } else { + putch(pgm_read_byte_far(address.word + 0x10000)); + } address.word++; } }