Go Down

Topic: How to combine usbdfu and usbtoserial code for ATMega8U2? (Read 3977 times) previous topic - next topic

erictj

Hey there-

I'm trying to get the ATMega8U2 code compiled and loaded for a custom board I'm working on.  I'm after the same functionality that the Uno and Mega2560 have, with the 8U2 (and later boards, the 16U2) handling USB duties to program the board from the Arduino IDE.

However, I want to load our own USB Vendor and Product IDs to the code.

I'm able to successfully load the Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex onto the 8U2, and then successfully flash the main MCU with it--so I'm pretty sure the circuit is working fine. 

However, when I load the Arduino-usbdfu.hex via the make clean; make; make program, and then load the Arduino-usbserial.hex via the make clean; make; make dfu, it seems to hang the chip, with the Arduino IDE showing "Serial port '/dev/tty.usbmodemfa131' already in use. Try quiting any programs that may be using it."

When doing it this route, I also get the "Bootloader and code overlap. Use --suppress-bootloader-mem to ignore" message from dfu-programmer.

I'm thinking that if I can combine the two hex files like the Arduino-COMBINED file, and then flash the chip via the AVRISPmkII, then I can solve the problem. 

Question is, how do I combine both those files so that I can flash it all at once?  Is it as simple as a concatenation of files?

Any other thoughts or suggestions?

Thank you!

hiduino

You can try burning just the DFU bootloader only, and then booting up the 8U2 in DFU mode.  Then use the Atmel FLIP software to download the usbserial to the 8U2.


erictj

Thanks.  I gave that a shot, and was still having trouble.  Regardless of how I get the bootloader and the app (usbserial in this case) uploaded to the board, it always fails on trying to flash the board via the Arduino IDE. The error I get is:

Code: [Select]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

avrdude done.  Thank you.


Here is a way to combine the app.hex and the bootloader.hex files together to make a combined, single hex you can upload (Thanks to Axel Wachtler for this tip!):

(sed '$d' app.hex; cat boot.hex) > app_boot.hex

This also works, but the order is important. -D in the second command prevents the flash erase.

avrdude <OPTIONS> -U app.hex; avrdude <OPTIONS> -D -U boot.hex;

My bootloader (arduino-usbdfu.hex) seems to work fine.  Compiling arduino-usbserial.hex completes without errors and I can flash it to the 8U2 with no problems, but does not work when trying to upload to the main board via the Arduino IDE.  I believe this is due to my avr-gcc version, which is 4.5.1.  I'm going to try 4.3.3 to see if I can get Arduino-usbserial.hex to work correcly.

I can use my own usbdfu.hex, and the original Arduino-usbserial.hex, and the 8U2 will flash the main board no probs.  When I compile the same Arduino-usbserial.hex and flash the 8U2, it fails.  It's got to be my compiler version, as far as I can tell.

Thanks for the response!  I'll post back when I have a solution.

erictj

Wanted to post the solution to the problem I was having, for anyone else who might have the same issue later.

Turns out, trying to compile the Arduino-usbdfu and Arduino-usbtoserial with an older GCC was a bad idea. 

I built a new toolchain, using avr-libc 1.8.0 and avr-gcc 4.7.2, and using the simple combine script above, was able to get everything working fine.

Also, if you're on Mac, I put together a current toolchain builder, in case you don't want to wait for a CrossPack-AVR update.  You can find it here:  https://github.com/Pinoccio/pinoccio-firmware/blob/master/install-avr-gcc.sh

Thanks for everyone's help!

Coding Badly


Go Up