Writing bootloader on ATMEGA328P using XGecu programmer - Page 1
Forum section: electronics / general

author: Cricri
author_rank: Contributor
timestamp: September 12, 2024, 12:58:05 pm
content: I believe I have accidentally damaged an Arduino Uno bootloader while writing on the chip with my XGecu T48 programmerReason of my suspicion is the Uno doesn't work since then (even a simple blink program).I read how to use another Arduino to flash the bootloader on another chip, but I don't stockpile Arduinos, and I'm assuming that surely I can write the Arduino bootloader on a blank 328P DIP using the T48 programmer.Can someone help explain how to do this? I'm quite the noob and don't want to also ruin my blank chip. I'm under the impression I need to configure some of the settings that I don't know what they are, and if I don't get those correctly, I might blow the wrong fuses and end up with a (very light) paperweight.Thanks!*EDIT* Also, can't find a hex file for the bootloader to program anyway, so getting help getting the right file for my scenario would be great too!

author: Cricri
author_rank: Contributor
timestamp: September 12, 2024, 01:28:08 pm
content: Found this video:That's a XGecu TL866, but hopefully the same procedure on T48.Still need the BIN file though

author: Peabody
author_rank: Super Contributor
timestamp: September 12, 2024, 03:07:55 pm
content: There are different Arduino bootloaders (and fuse settings) for the different Arduinos that use that CPU - Uno, Nano, Pro Mini 16Mhz, Pro Mini 8MHz. If you use the Arduino IDE, it will let you pick the one you want. Attached are the programmer options available in the IDE, v1.8.8. However, IDE v2 may offer more.

author: Cricri
author_rank: Contributor
timestamp: September 12, 2024, 03:55:08 pm
content: Thanks, but I was trying to use the XGecu programmer, so my problem wasn't with settings within the Arduino software.I eventually found a cheap chinese Arduino Strong, uploaded ArduinoISP on it, then used is as "Arduino as ISP" programmer and "Burn Bootloader" onto not only my spare Atmega328P, but also on the original one which wasn't working anymore, uploaded the blink sample and confirmed both 328P are not working properly as Arduino BL. So not only fixed, but now I've got a spare 328P with BL on it

author: Peabody
author_rank: Super Contributor
timestamp: September 12, 2024, 04:05:17 pm
content: Which Arduino did you flash it as?

author: Cricri
author_rank: Contributor
timestamp: September 12, 2024, 04:16:44 pm
content: Quote from: Peabody on September 12, 2024, 04:05:17 pmThat's the bit that got me thinking my 328P was unrecoverable: for the Nano Strong to work properly in the Arduino IDE, I've got to set board as Nano, and processor as "328P (old bootloader)" when uploading, otherwise I can't upload on itThat took me a while to figure out!But after I uploaded ArduinoISP, if I do "Burn Bootloader" on my proper Atmega328P, it wasn't working! It wasn't working with the new 328P either. I then tried to use a Seeduino running a 168P, and when trying to "Burn bootloader", it complained it didn't find a 168P. That was the lightbulb moment. I switched back to the strong, and select the "328P", NOT "old bootloader" before doing "Burn bootloader", and that worked. That's when I thought that therefore, my old chip was salvageable, and indeed I was then able to properly burn the bootloader on the old 328P as well.

author: Peabody
author_rank: Super Contributor
timestamp: September 12, 2024, 04:31:08 pm
content: Ok, well the boards.txt file in the IDE has information on all the different target boards, including the fuse settings and the bootloader hex filename for each one. The best one for the 328P is probably the Uno. It uses the Optiboot bootloader, which takes up only 512 bytes. The Nano and others use up 2K, even the "new" bootloader Nano. Then if you use the Arduino IDE to program them thereafter, you would need to call them Unos so the IDE knows to use the extra 1.5K of flash.

author: Cricri
author_rank: Contributor
timestamp: September 12, 2024, 07:18:03 pm
content: Thanks.So back my XGecu T48 programmer, if I loaded .hex bootloader file as (e.g. ATmegaBOOT_168_atmega328.hex) "intel hex", and program the Atmega328P chip with the T48 proggammer, would that work?

author: Peabody
author_rank: Super Contributor
timestamp: September 12, 2024, 08:53:02 pm
content: I don't know. I've only ever used a 2nd Arduino and the Arduino IDE to burn a 328P bootloader. But how do you set the fuses using your T48? You have to do that too.But don't you now have two working 328P's, one of which can be the programmer? Why do you need to use the T48?

author: Cricri
author_rank: Contributor
timestamp: September 12, 2024, 09:57:37 pm
content: Yes, I now keep the Nano Strong as a programmer since I still have the Seeduino and the Uno (none of which I actually use!), but it's more faff than just dropping the dip into the T48 zif socket! On the plus side, hopefully I won't have to do that again, and if I'm going to use one, I'll use the Uno, and even if I bugger this one again, I now also have a spare 328P with bootloader.

author: westfw
author_rank: Super Contributor
timestamp: September 13, 2024, 12:32:34 am
content: QuoteYep. Writing to an AVR with a "real" programmer erases ALL of the flash first, including the bootloader. (For reasons I don't understand, the programming interface doesn't have the ability to do partial erases of the chip, even though the bootloader has no problem doing that.)QuoteThe "Standard" Arduino Uno ATmega328p bootloader is here:https://github.com/arduino/ArduinoCore-avr/tree/master/bootloaders/optibootAnd there's a newer version here:https://github.com/Optiboot/optiboot/tree/master/optiboot/bootloaders/optibootThere are several steps to programming an AVR with the Arduino bootloader:Erase chip and clear protection bits (happens at the same time.)Set fuses appropriate for your "board."Burn the bootloaer.Set the relevant protection bits (if you care.)The Arduino IDE does all of these, using AVRDUDE "behind the scenes", when you do a "burn bootloader" command, but it looks like neither the IDE not AVRDude support the "universal" type chip programmers.The fuses values required are listed in the Makefiles of the directories linked above. Extended: 0x05, High: 0xDE, Low: 0xFFIf you need a .bin file rather than a .hex, you can use objcopy.

author: Cricri
author_rank: Contributor
timestamp: September 14, 2024, 10:22:05 pm
content: Thanks, very helpful! I managed with ArduinoISP in the meantime, but will keep this in mind for next... although hopefully they shan't be one!