I have a custom board using the 32U4.
I am using the "Export Compiled Binary" option in the Arduino IDE (selecting the Leonardo profile). I can load my binary just fine via AVRDUDESS and the sketch runs successfully.
However...
When I try to burn the other hex file (".with_bootloader.hex") to load the bootloader, the process finishes with no errors. However the sketch does not run, instead the built in LED just slowly flashes every second.
What gives? Doesn't the ".with_bootloader.hex" file contain both the sketch and the bootloader?
Welcome
It should. Did you set the fuses correctly for the Leonardo? I do not know if avrdudess does that for you.
This is from boards.txt for the Leonardo (16 MHz)
leonardo.bootloader.tool=avrdude
leonardo.bootloader.low_fuses=0xff
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardo.bootloader.file=caterina/Caterina-Leonardo.hex
leonardo.bootloader.unlock_bits=0x3F
leonardo.bootloader.lock_bits=0x2F
When you burn the bootloader using the IDE, it takes care of those bits. It only needs to be done once.
Note:
Never seen unlock_bits before Not sure how to match it with the datasheet.
The lock bits are set to the value of the bootloader.unlock_bits
property in the "erase" action's command that is run during a "Burn Bootloader" operation, prior to the "bootloader" action command:
(note the -Ulock:w:{bootloader.unlock_bits}:m
part of the command template)
The lock bits are set to the value of the bootloader.lock_bits
"bootloader" action command that is run at the end of a "Burn Bootloader" operation:
(note the -Ulock:w:{bootloader.lock_bits}:m
part of the command template)
So the use of the bootloader.unlock_bits
property is to define the lock bits configuration the chip should be put in to prepare it to be written with the bootloader binary.
The use of the bootloader.lock_bits
property is to define the lock bits configuration the chip should have at the completion of a "Burn Bootloader" operation.
1 Like
I can confirm that all the fuses are set correctly. I've tried both the Leonardo defaults (as you show from boards.txt) and a reduced set that maintains only the critical fuses (oscillator etc). The behavior is the same.
I did some more reading last night and it would seem that the bootloader does make it on to the board OK. I get both the "breathing" LED effect when programming and the "slow flash" behavior which, I think, indicates the presence of the bootloader but the absence of a valid sketch.
I've been using a USBasp for programming, on a lark I tried an Arduino-as-ISP and got the same results. A second issue is that I cannot further test the bootloader function by uploading a sketch via USB - my board gives only a "device unrecognized" error from windows, unclear if this is related or unrelated to the above problems.
The board needs a sketch for it to be recognised and for it to be able to react on the software reset issued by the IDE when you perform an upload.
Part of the sketch that you upload contains the functionality to identify itself to your operating system and to react on that software reset.
I'm afraid that that is how far I can help you.
Well that at least is helpful to know - I was really tearing my hair out on the USB-recognition issue too. So sounds like if I can solve this bootloader problem I might hit two birds with one stone.
I might try rolling back the IDE tonight and see if an older version produces any differences in the .with_bootloader.hex binaries. I can't find anything else wrong in my setup, perhaps its in the file itself.