Getting Megacore to work with Atmega2560

Hi all

I'm quite new to custom bootloaders. I need optiboot feature which can differentiate between software reset and power loss. Thus I use Megacore on my atmega2560.

My code was fully working when I was using the stock atmega2560 bootloader however when I used Megacore, the code stops working.

I uploaded the bootloader through a Nano. Here's my setting when I was about to burn the bootloader to mega:

Board: ATmega2560
Clock: External 16 Mhz
BOD: 2.7V
LTO: disabled
Pinout: Arduino MEGA pinout
Bootloader: Yes(UART0)

Programmer: Arduino as ISP

I look around in the avr folder of megacore and I opened the boards.txt file. I went to the mega2560 section and I noticed this:

2560.menu.bootloader.uart0.bootloader.file=optiboot_flash/bootloaders/{build.mcu}/{build.clock_speed}/optiboot_flash_{build.mcu}_{upload.port}_{upload.speed}_{build.clock_speed}_{build.bootloader_led}_BIGBOOT.hex

My questions:

  1. I noticed there's Arduino as ISP (Megacore) option in the programmer. Should I use this one instead?
  2. Should I replace optiboot_flash/bootloaders/{build.mcu}/{build.clock_speed}/optiboot_flash_{build.mcu}{upload.port}{upload.speed}{build.clock_speed}{build.bootloader_led}_BIGBOOT.hex with stk500boot_v2_mega2560.hex?

Please provide a detailed description of what you mean by "the code stops working".

jch700:

  1. I noticed there's Arduino as ISP (Megacore) option in the programmer. Should I use this one instead?
  2. Should I replace optiboot_flash/bootloaders/{build.mcu}/{build.clock_speed}/optiboot_flash_{build.mcu}{upload.port}{upload.speed}{build.clock_speed}{build.bootloader_led}_BIGBOOT.hex with stk500boot_v2_mega2560.hex?
  1. "(MegaCore)" only shows that the 'programmer' is defined in MegaCore. the sketch is still the one bundled with IDE
  2. if you want to return to old bootoader use the Arduino AVR core's Mega board selection to Burn Bootloader

I can't imagine how the bootloader would cause your code to not work

Appreciate the replies. I forgot to mention that I’m using a naked mega. I don’t think this is a deal-breaker is it?

I don’t think there’s anything wrong with the code. since it works with the stock bootloader (stk500boot_v2_mega2560). That’s why I didn’t post them. bootloader_megacore_log attached shows the output I got after I burned the bootloader.

I’m using an MPU6050 library. With the stock bootloader, it works just fine. With megacore, I got some compilation errors as shown in MPU6050_compile_log attached.

I’m not sure what megacore added that cause all these [-fpermissive] errors…

bootloader_megacore_log.txt (10.2 KB)

MPU6050_compile_log.txt (17.1 KB)

The reason is that Arduino AVR Boards uses the -fpermissive compilation flag, but MegaCore doesn't.

The reason Arduino added the -fpermissive compilation flag to Arduino AVR Boards platform is because an update to a new compiler version caused some low quality, but reasonably functional, code which previously only caused a warning to now cause a compilation error. That low quality code was reasonably common in 3rd party Arduino libraries and sketches which Arduino doesn't have the power to fix, so updating the compiler would have caused some breakage.

The fix for that issue was to add the -fpermissive compiler flag. That downgraded those new errors to warnings. Unfortunately, it also caused some horrible code that had always before caused errors to now only cause warnings, so it's questionable whether it was actually a good idea to use -fpermissive. The opinion of MCUdude, the author of MegaCore is that -fpermissive is not a good idea, and that people just need to fix their garbage code.

So these errors are telling you something important. If they are caused by your own code, then you should fix it. If they are caused by someone else's code, you can either fix it yourself, ask them to fix it, or if that fails, look around for some higher quality alternative code.

This has absolutely nothing to do with the bootloader, so please forget about that and focus on the broken code instead.

Thanks for the enlightenment :slight_smile:

You’re welcome. If you’re interested in this subject, I have a few references for you:
Adding the flag to Arduino AVR Boards: https://github.com/arduino/ArduinoCore-avr/commit/06868f4cd39a9dba82b5014d1208feb1e1f0d750#diff-d638a47d1ca0e2a5585fb34c7d7fb0f9

MCUdude/hansibull’s statement on the subject: https://github.com/MCUdude/MightyCore/issues/93#issuecomment-382999620

Proposal to remove it from Arduino AVR boards: https://github.com/arduino/ArduinoCore-avr/issues/268

jch700:
Appreciate the replies. I forgot to mention that I'm using a naked mega. I don't think this is a deal-breaker is it?

I don't think there's anything wrong with the code. since it works with the stock bootloader (stk500boot_v2_mega2560). That's why I didn't post them. bootloader_megacore_log attached shows the output I got after I burned the bootloader.

I'm using an MPU6050UPSers library. With the stock bootloader, it works just fine. With megacore, I got some compilation errors as shown in MPU6050_compile_log attached.

I'm not sure what megacore added that cause all these [-fpermissive] errors...

Thank you for the explanation. It is clear for me.