Pages: [1]   Go Down
Author Topic: Arduino Mega ADK (ATMEGA2560): execute code before bootloader?  (Read 578 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I'm using an Arduino Mega ADK (based on ATMEGA2560). I need to execute code before the bootloader in order to turn off the watchdog timer in order to avoid a reset cycle after the watchdog timer caused a reset. Is it possible to run code before the bootloader?

I tried using
Code:
  void wdt_init(void) __attribute__((naked)) __attribute__((section(".init1")));
but apparently, this is not called before the bootloader.

Any ideas apart from modifying the bootloader (I have no idea how to do that and apparently custom hardware is needed to burn it)?

Many thanks,
Michael
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have the bootloader fuses enabled the reset vector is redirected to a specific bootloader start address. No code runs before the bootloader. If you need some extra code to 'tame' the watchdog timer, you need to put it in there yourself = recompile the bootloader.

The extra hardware you speak of is just 20-50 bucks, depending on the amount of luxury you need. And I highly recommend to get an ISP.
Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

Pages: [1]   Go Up
Jump to: