abcminiuser / lufa

LUFA - the Lightweight USB Framework for AVRs.
http://www.lufa-lib.org
1.04k stars 325 forks source link

CDC BootLoader not Leonardo Compatible #42

Open NicoHood opened 9 years ago

NicoHood commented 9 years ago

I tried to compile the latest CDC BootLoader for my Pro Micro(well not a leo but a 32u4) and it turn out that i cannot reupload sketches to the board. The Arduino software tries to touch the Serial at 1200 and tries to reupload the Code. But its not working:

Connecting to programmer: .avrdude: Send: . [1b] 
avrdude: Send: S [53] 
avrdude: ser_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

With the older Pro Micro source (recompiled with the older Lufa) its working fine. I am trying to figure out why this happens.

I also have a similar problem with my HoodLoader2 project. After a serial touch the leds start flickering, usb is detached but no sketch and no bootloader starts. Just the leds are flickering. I am wondering if i set the Watchdog timer wrong in my source.

Any Idea?

abcminiuser commented 9 years ago

That looks like the bootloader isn't responding to any commands from the host -- are you sure the programmer is using the correct virtual COM port number?

NicoHood commented 9 years ago

I think the problem is that the Arduino Software uses a special Bootkey on a specific address: https://github.com/arduino/Arduino/blob/master/hardware/arduino/bootloaders/caterina/Caterina.c#L69 yours: https://github.com/abcminiuser/lufa/blob/master/Bootloaders/CDC/BootloaderCDC.c#L64 So what the bootloader does is to start the sketch again. And the sketch has no bootloader protocol implemented of course.

They write this key inside the sketch, do a watchdog reset and then the bootloader knows that it should execute the bootloader code and not start the application. Because both read the same memory location. So you'd have to change this to suit for an Arduino Leonardo/Micro.

I am also developing a CDC BootLoader and i am wondering why they used exactly this address. I am programming a 16u2 and a 32u2 and dont know what ram address is the best for this bootloader. Mabe the last, but how can i find the last one. I read some stuff about the stack etc. I somehow has to pass the information to the bootloader so i cannot simply use your no init trick. Any suggestions?

NicoHood commented 9 years ago

To add leonardo compatibility you definitely have to set the bootloader key to exactly 0x0800. Thats how i did it with a 8 bit key and another address. https://github.com/NicoHood/HoodLoader2

Its not perfect, it would be better to define the specific address as reserved but therefore you need compiler flags and the arduino ide wont take these flags. I also filed a bug there too.

abcminiuser commented 9 years ago

Hrm, I guess they have their reasons. I can fix the address of the boot key by placing it into its own section and forcing the start address of the section to 0x800, but they also use their own different key value. I suppose I can either make my version accept either, or have a compile time option to change the key to match the Caterina bootloader.

NicoHood commented 9 years ago

yeah, the fixed section sounds good. the only reason why i didnt use it was that the hex converter from nick gammon for the atmega board programm couldnt convert my hex file then.

Passing the magic bootkey in the makefile would be nice. and an option for the address and maybe size (8 or 16 bit) as well, if possible.

NicoHood commented 9 years ago

https://github.com/abcminiuser/lufa/blob/master/Bootloaders/CDC/BootloaderCDC.c#L64 The Key can be stored in RAMEND, see this discussion: https://github.com/arduino/Arduino/issues/2474

This way the application can restart the program and run the bootloader.