Atmega16U2 on custom board - looking for help uploading Hoodloader

Hello!

I hope this is the right place to ask. Essentially I am trying to understand the bigger picture while trying something I have not done before.

So I designed and prototyped a simple board with a mosfet, 3 buttons, a 5V LDO and a Atmega16u2 which I am planning to program using the Arduino IDE. I know that the standard bootloader only does USB2Serial for the UNO and I also know about the Hoodloader bootloader which allows the 16u2 to execute a sketch while still forwarding the serial to the 328p. So I figured the 16u2 will not mind much if there is no 328p present but will execute my sketch anyway if I manage to flash the bootloader onto the 16u2 and upload a sketch via Arduino IDE. So far the idea.

Unfortunately I designed the board before researching uploading the boot/hood-loader so now after I completed the prototype I figured it's best being done via ICSP headers - which ofc I did not include in my board. At the same time I found tutorials about flashing chips using "dfu-programmer", but trying to upload the hoodloader yields a "bootloader and code overlap." error from dfu-programmer. So I figured - hang on, you don't understand the big picture good enough to proceed with what you are doing.

So a few questions I'd be happy if somebody could answer:

  • can I upload the bootloader via usb in the first place or will I have to use ICSP? The chip is detected as an 16u2 in DFU mode by my computer (mac os high sierra).
  • if yes: how?
  • if no: what's the general idea behind this architecture? I'm having trouble wrapping my head around this.
  • last question: is there maybe even a better option than hoodloader to upload sketches to a bare 16u2 using arduino ide?

Thank you very much!
0xDEADBEEF

0xDEADBEEF:

  • last question: is there maybe even a better option than hoodloader to upload sketches to a bare 16u2 using arduino ide?

I don’t have any actual experience with this, but I think you should now use HoodLoader2:

Hoodloader/HoodLoader2 are the only Arduino hardware packages I know for the ATmega16U2. It’s a bit strange that there aren’t more since this family of chips are quite common, but the USB aspects are very complex and if that functionality is not implemented then the chips are not so attractive. Also, the ATmega32U4 is already fairly well supported via the Leonardo and Micro board definitions so the main benefit would be to add support for the other chips like ATmega16U2 and ATmega8U2.

As for the DFU issue you’re having, unfortunately I don’t have any experience with this. Hopefully someone else here will be able to provide assistance. I know there is quite a bit of documentation in the HoodLoader2 Wiki so you might browse through that to see if it will be helpful:

Thanks for your reply!
I am indeed referring to HoodLoader2 and I've gone through the wiki. However, the wiki assumes it is being used on an Arduino instead of a custom pcb as in my case. Reading the wiki is what led me to assume using ICSP headers and an Arduino would be the straightforward way to do this, however I did not include ICSP pads on my board.

So the main issue I'm trying to understand is the role of USB in that regard. Is it possible per se to flash the bootloader via USB and if not why. After all, USB was the main reason of choice to use the 16U2 instead of a 328p, as I'd have both available. I guess I could solder some jumper wires to the chip and use an Arduino to flash. But in the first place I'd like to understand the big picture before I proceed.

thanks!