-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
m328pb: source compiles fine but bootloader does not work #360
Comments
Wondering whether you have tried the hex from See atmega328pb_build_info.txt in there. You probably want to try Im very curious about this myself so can you please report back how this works out for you? |
However, the autobaud urboot firmware works fine. It will work with 8MHz or 16MHz, at 57600 bps or 115200 bps. In paticular, the following hex file is compatible with optiboot/arduino.
|
Reference from MiniCore. It is said somehow UART0 bootloader does not work. |
This is the exact file I used and linked above, the one worked for me. @mcuee: |
My problem seems not to be limited only to the m328pb: compiling for the m8 also gives a different result compared what's in the repo! Why are all the executables that I compile missing a few bytes? Am I missing an argument of avr-gcc? |
You can refer to this issue on the building of optiboot under Windows. I use git bash plus the Atmel toolchain. You can change the Makefiles as per your requirement.
Click to see the detailed build log for makeall.arduino.sh
|
Right, can you clarify which optiboot tag are you pulling from git also maybe provide a avrdude commands you are using? I can test the whole 1:1 procedure using atmel-ice over on my side and at least give you some kind of feedback. FWIW the ATMEGA32PB does not seem to be supported by avr-libc-2.1.0 so Im getting (optiboot-8.0)
PS: Im wondering whether having something like Docker or Podman to be used for compiling Optiboot rather than figuring out the toolchain combination would be a way to go in situations like these. |
Yes this is a good way to build optiboot as well as avrdude. Just FYI, if you want to try latest snapshot of avrdude under Linux/macOS/Windows, you can try my snapshot release here, built using the Docker Container provided by Arduino. That being said, it is not that difficult to build optiboot under Windows, I am OS-neutral guy so I will always try to build things like optiboot across Linux/Windows/macOS natively. You can refer to my issues in different optiboot related repos.
|
@mcuee Ill try to use the https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/avr8-gnu-toolchain-3.7.0.1796-linux.any.x86_64.tar.gz to compile the optiboot for atmega328pb on Linux and then create a Dockerfile - if you have Dockerfile for this combination available I would be happy to test this. |
As of now I am not using Docker for Optiboot myself since I have no issues building Optiboot under Linux/macOS/Windows natively. It will be great that you can share the Docker file here for others to use. But one suggestion, you may want to use the older version which may produce tighter codes. Or even better if you can switch between the two toolchain. The Atmel toolchain (5.4.0 or 7.3.0) does not support ATmega328PB though so you may need to copy the file from either Arduino toolchain or Microchip Studio DFPs. https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/avr8-gnu-toolchain-3.7.0.1796-linux.any.x86_64.tar.gz (newer avr-gcc 7.3.0 version). https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/SoftwareLibraries/Firmware/avr8-gnu-toolchain-3.6.2.1778-linux.any.x86_64.tar.gz (older avr-gcc 5.4.0 version) Yet the other option is to use the toolchain from DxCore which adds support for building optiboot_x and optiboot_dx (version 7.3.0). It has the support for ATmega328PB already. |
@mcuee can you suggest why Im getting the following error? maco@lists:~/dl/optiboot-8.0/optiboot/bootloaders/optiboot$ ./testc.sh
+ GCC='../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -mmcu=atmega328pb -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/'
+ OBJCOPY=../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objcopy
+ OBJDUMP=../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objdump
+ SIZE=../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-size
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -mmcu=atmega328pb -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/ -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L -DBAUD_RATE=9600 -DLED=B5 optiboot.c -c
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -mmcu=atmega328pb -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/ -Wl,-Tlink_optiboot.ld -Wl,--relax -nostartfiles optiboot.o -o optiboot.elf
/home/maco/dl/avr8-gnu-toolchain-linux_x86_64/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: cannot open linker script file link_optiboot.ld: No such file or directory
collect2: error: ld returned 1 exit status |
@0xCAFEAFFE |
I tried optiboot-master and the optiboot-8.0 tag, both result in slightly different executables of the same size, both don't work. avrdude arguments to flash bootloader via USBasp: avrdude arguments to upload using optiboot: |
Ohh, that's interesting, thank you for pointing that out! Curious, that the precompiled .hex still worked with the wrong setting.. Up next: I'll try building in a linux VM.. |
I think this is because the file |
This is what I get under Linux.
|
My board is using 16MHz external clock (ATmega328PB Xplained Mini, clock from the on-board debugger).
|
It does not work with 115200bps but it does work at 125000bps (and even 250000bps).
|
So I have tried to re-run @mcuee compilation process by running: #!/bin/bash
set -e
set -x
GCC="../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/"
OBJCOPY="../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objcopy"
OBJDUMP="../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objdump"
SIZE="../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-size"
$GCC -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L -DBAUD_RATE=9600 -DLED=B5 -DLED_START_FLASHES=3 -c -o optiboot.o optiboot.c
#$GCC -Wl,-Tlink_optiboot.ld -Wl,--relax -nostartfiles optiboot.o -o optiboot.elf
$GCC -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L -DBAUD_RATE=9600 -DLED=B5 -DLED_START_FLASHES=3 -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -o optiboot.elf optiboot.o
$OBJCOPY -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot.elf optiboot.hex
$OBJDUMP -h -S optiboot.elf > optiboot.lst
$SIZE -C optiboot.elf And the result: maco@lists:~/dl/optiboot-8.0/optiboot/bootloaders/optiboot$ ./testc.sh
+ GCC='../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/'
+ OBJCOPY=../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objcopy
+ OBJDUMP=../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objdump
+ SIZE=../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-size
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/ -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L -DBAUD_RATE=9600 -DLED=B5 -DLED_START_FLASHES=3 -c -o optiboot.o optiboot.c
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -B ../../../../atpack/gcc/dev/atmega328pb/ -I ../../../../atpack/include/ -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L -DBAUD_RATE=9600 -DLED=B5 -DLED_START_FLASHES=3 -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -o optiboot.elf optiboot.o
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot.elf optiboot.hex
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-objdump -h -S optiboot.elf
+ ../../../../avr8-gnu-toolchain-linux_x86_64/bin/avr-size -C optiboot.elf
AVR Memory Usage
----------------
Device: Unknown
Program: 494 bytes
(.text + .data + .bootloader)
Data: 0 bytes
(.data + .bss + .noinit)
maco@lists:~/dl/optiboot-8.0/optiboot/bootloaders/optiboot$ cat optiboot.hex
:107E000001C0E5C0112484B7882361F0982F9A70CF
:107E1000923041F081FF02C097EF94BF282E80E09E
:107E2000C1D0EEC085E08093810082E08093C000E5
:107E300088E18093C10086E08093C20087E680934A
:107E4000C4008EE0AFD0259A86E028E13EEF91E0B5
:107E5000309385002093840096BBB09BFECF1D9A83
:107E6000A8954091C00047FD02C0815089F793E07A
:107E7000E92EDD24D39425E0C22E31E1B32E86D045
:107E8000813479F483D0182F93D0123811F480E024
:107E900004C088E0113809F083E071D080E16FD030
:107EA000EECF823419F484E18BD0F8CF853411F40D
:107EB00085E0FACF853541F469D0C82F67D0D82F37
:107EC000CC0FDD1F75D0EACF863519F484E078D069
:107ED000DECF843609F034C059D058D0F82E56D0B1
:107EE000A82E00E011E048018FEF881A980A4ED0C2
:107EF000F80180838401F810F6CF5AD0F5E4AF1270
:107F000001C0FFCFFE01E7BEE89507B600FCFDCF3C
:107F1000FE01A0E0B1E0CD0102962D913C91090156
:107F2000D7BEE89511243296DC01F812F4CFFE0199
:107F3000C7BEE89507B600FCFDCFB7BEE895AECF4B
:107F4000843771F423D022D0F82E20D031D08E0186
:107F5000F80185918F0113D0FA94F110F9CF9ECFDB
:107F6000853739F425D08EE10AD085E908D086E13D
:107F700094CF813509F0A6CF88E014D0A3CF90919B
:107F8000C00095FFFCCF8093C60008958091C0008B
:107F900087FFFCCF8091C00084FD01C0A89580912F
:107FA000C6000895E0E6F0E098E1908380830895AC
:107FB000EDDF803219F088E0F5DFFFCF84E1DFCF1D
:107FC000CF93C82FE3DFC150E9F7CF91F1CFFC0188
:107FD0000A0167BFE895112407B600FCFDCF667063
:0E7FE00029F0452B19F481E187BFE89508953B
:027FFE00000879
:0400000300007E007B
:00000001FF The diff in HEX files from the first post from @0xCAFEAFFE is very different. Its very close to the HEX from #360 (comment) |
@mcuee the Dockerfile (and docs) used to generate the above optiboot.hex (1:1) for Atmega328PB, 8MHz, 9600, B5 available here: https://github.com/hecko/optiboot_docker_build @0xCAFEAFFE would this help you? Can you test the generated hex file wheter this works for you? Also, can you confirm that you are using internal 8MHz oscillator (as suggested by fuses selection)? |
Thanks @hecko, that does indeed help, your .hex file is working for me with the internal 8MHz RC oscillator! The .hex file from mcuee does not quite work (optiboot answers but avrdude reads back garbage) because the baud rate of 57600bd is not compatible with the 8MHz clock. |
Attached - please let us know how you get on with this. |
Oh dear.. I found my mistake and I am embarrassed to admit it: I made a "temporary" change to my sfr_defs.h a while ago and forgot about it in the meantime.. Thanks to everyone! |
Is the bootloader using U2X? It. The baud rate generator on classic AVRs was shit, that's why some cores support UART clock crystals, because that was the only way to get decent calculation accuracy . 115200 is also a particularly bad speed for 16 MHz classic AVR. 76800 (2/3rds of 115200 baud would work much better at 16 MHz, though for 12 MHz or for 16.5 MHz, 115200 baud is better.... https://docs.google.com/spreadsheets/d/1uzU_HqWEpK-wQUo4Q7FBZGtHOo_eY4P_BAzmVbKCj6Y/edit?usp=sharing |
Yes, Optiboot does use the U2X setting by default! |
I'll soon be tearing my hair out, I'm simply trying to compile optiboot (unmodified for now) from source for an ATmega328PB and can't get it to work:
Hardware:
The MCU is sitting on a custom PCB with a CH340 bus converter, the circuit was designed for an m88pa and previously worked well, now I need more memory, therefore the upgrade to the m328pb.
I don't see the hardware being at fault because bootloader and application work just fine if I use a precompiled .hex file of optiboot_flash from MCUdude's MiniCore. My fuse bits are E2 DC FF, external programmer is a USBasp.
Toolchain:
I'm on a Windows machine, after not getting anywhere with Microchip Studio (7.0.2542) or the makefile (not 100% independent of OS) I reverted to building manually in the commandline using avr-gcc 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_1778, supplied with above version of Microchip Studio).
I am using the most recent source of optiboot and run the following commands to compile, link, translate and disassemble:
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=8000000L -DBAUD_RATE=9600 -DLED=B5 optiboot.c -c
avr-gcc -Wl,-Tlink_optiboot.ld -Wl,--relax -nostartfiles optiboot.o -o optiboot.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot.elf optiboot.hex
avr-objdump -d optiboot.o > optiboot.asm
avr-size -C optiboot.elf
The arguments I pieced together from the makefile, the commands produce the expected files, no warnings, no errors, no output except avr-size of course:
The disassembly and the executable are attached here, masquerading as text files as GitHub does not allow all file extensions:
optiboot_asm.txt
optiboot_hex.txt
I can of course upload the executable to my MCU with the USBasp but then the bootloader does not respond to avrdude (version 7.0 via AVRDUDESS 2.14) at all:
I don't know what I am missing, unfortunately there is no precompiled .hex file for the ATmega328PB that I could compare my output to. If someone could provide a working .hex or .lst file, that might already help figuring out what's wrong.
Any input appreciated.
The text was updated successfully, but these errors were encountered: