MCUdude / MightyCore

Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535
Other
637 stars 181 forks source link

Upload once successfully but can't after that #256

Closed unebonnevie closed 1 year ago

unebonnevie commented 1 year ago

Hi,

I followed the installation instructions on the MigthCore github site for my ATMEGA644 using the standard pin config. See image for the setup. I flash the bootloader successfully, and I do see LED attached to PB0 blinking. Please also see the text output file attached when I flashed the bootloader. Below is the snippet I saw when flashing the bootloader. The bootloader is VERY large -- 65536 bytes! That can't be!

avrdude: input file C:\Users\asle\AppData\Local\Arduino15\packages\MightyCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega644p/16000000L/optiboot_flash_atmega644p_UART0_115200_16000000L_B0_BIGBOOT.hex contains 65536 bytes

Loaded up the Blink example and uploaded it successfullly, with the programmer unplugged. See image below. Now attempted to upload the same Blink sketch again, and I get an error. See image below. To do it successfully, I would have burn the bootloader again, and it will give me a one-time successful upload.

Please advise! Thank you!

MightCoreIDESetup

blink

blink_error_2nd_time_upload

success_case_of_first_upload_after_bootloader_burnt.txt

bootloader_flashing_text_output.txt

unebonnevie commented 1 year ago

Here is the AVRDude command dumped out by the Arduino IDE. It's the same for the very first successful upload, after the boot loader was burnt, and is the same command used on the 2nd upload, which fails to do so.

C:\Users\asle\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18/bin/avrdude -CC:\Users\asle\AppData\Local\Arduino15\packages\MightyCore\hardware\avr\2.1.3/avrdude.conf -v -patmega644p -carduino -PCOM3 -b115200 -D -Uflash:w:C:\Users\asle\AppData\Local\Temp\arduino_build_314197/Blink.ino.hex:i

My theory on what is wrong here: From my original post, I saw that the Opti bootloader got flashed, but the bootloader is 65536 bytes in size, filling up the ATMEGA644 flash space. On the first upload of the Blink program, it is successful, because the boot loader was running and somehow erase itself, since the Blink program took over some flash space that the Opti bootloader occupied for 64KB!!! And the 2nd try to upload the same Blink program via the bootloader, the bootloader is already dead from the first upload, thus the program seen.

So, the real problem is: Why the Opti bootloader has 65536 bytes!???? `

MCUdude commented 1 year ago

but the bootloader is 65536 bytes in size, filling up the ATMEGA644 flash space.

This is not correct, the bootloader size is a little more than 512 bytes large. Avrdude reports 65536 bytes because the bootloader is located at the very end of the flash memory. If you dump the flash memory (using Avrdude directly), you can see that the bootloader takes up very little space in the flash memory.

If uploading only works once, it's highly likely that your auto-reset circuit isn't present or working properly. Have you connected a 100nF capacitor between the DTR or RTS line on your USB to serial adapter and to the RESET pin on the ATmega644P? And do you have a 10k pullup on the reset pin? If you have a schematic, that would be helpful.

unebonnevie commented 1 year ago

Have you connected a 100nF capacitor between the DTR or RTS line on your USB to serial adapter and to the RESET pin on the ATmega644P?

Thank you! That was the problem! I saw your documentation, but didn't go for the 0.1uF to the USB-serial chip's DTR pin and the MCU's RESET pin, because I thought it was OK, since it was able to flash the very first time.

With 0.1uF connected, I am able to flash through the bootloader.