Pages: [1]   Go Down
Author Topic: Arduino bootloader advice needed [solved]  (Read 614 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I'm currently working on controlling an Arduino over wireless. One of the things I want is: being able to upload a new sketch.
I have it nearly all setup but some things are not working.
Because I'm communicating over the serial port directly (not using USB and as such not having a reset line) I send a command to Arduino to use the watch dog to hard reset Arduino. Trying to do an upload after this reset always fails smiley-sad. When pressing the reset button it works  smiley-eek.
So I looked at the bootloader code at https://github.com/arduino/Arduino/blob/master/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168.c and found this
Code:
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;

#ifdef WATCHDOG_MODS
ch = MCUSR;
MCUSR = 0;

WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0;

// Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
if (! (ch & _BV(EXTRF))) // if its a not an external reset...
app_start(); // skip bootloader
#else
asm volatile("nop\n\t");
#endif
This looks really great because I see indeed that a restart from a WDT skips the bootloader.
Also the whole section is in a #ifdef which may be the root cause why the Arduino mega and duemilenove do not handle watchdogs properly.
As my project is mega oriented I need a new bootloader anyway. Creating a new bootloader looks easy and promising ....... but
When I look at the code in github I see that all the code is 3 years old.

So my question is: "Is this the latest bootloader code?" "Is the bootloader code still open?"

[EDIT ANSWER]
The latest bootloader for the AVR chips (not the for the arduino mega) is in the optiboot folder. The code is delivered with each and every Arduino IDE so it is still open.

Best regards
Jantje
« Last Edit: December 18, 2012, 04:30:11 pm by Jantje » Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27115
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried looking at the bootloader for the Fio?

"The Arduino Fio is intended for wireless applications. The user can upload sketches with an a FTDI cable or Sparkfun breakout board. Additionally, by using a modified USB-to-XBee adaptor such as XBee Explorer USB, the user can upload sketches wirelessly. "
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have found that the atmega folder is an old folder (stil used for the duemilanove). The "new" bootloader code is in the optiboot folder.
It is really simple to compile the bootloader (just go to the folder in a command prompt and run omake). I compiled the code "as is" and it is 100% (binary compared) the same as the hex file delivered with arduino (tested with Arduino IDE 1.0.1).
But as soon as I change something in the file it compiles but when burned on a Arduino the L led starts flashing and never stops. I can upload code but it looks like the code never starts
I have tried several code changes, but all with the same result.
If I restore the code in original state, compile and "burn" all is fine.
I must be doing something wrong smiley-confuse. And I guess it is something very basic.
Any help is appreciated

@crossroads
I'm not sure how the fio relates to my problem. I want to upload to a mega (need the extra pins and memory) via wifi ( I need 3000m² coverage).

Best regards
Jantje

The changes I tried in optiboot.c
Code:
  // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
  watchdogConfig(WATCHDOG_OFF); //added this line

  //if (!(ch & _BV(EXTRF))) appStart(); removed this line

Code:
  // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
  if (!(ch & _BV(EXTRF)) watchdogConfig(WATCHDOG_OFF); //added this line
  //if (!(ch & _BV(EXTRF))) appStart(); //removed this line

Code:
  // Adaboot no-wait mod
  //ch = MCUSR;
  //MCUSR = 0; //removed the whole Adaboot no-wait mod
  //if (!(ch & _BV(EXTRF))) appStart();
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27115
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was thinking if you were creating a modified bootloader, then borrowing xbee code from the Fio might help.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was thinking if you were creating a modified bootloader, then borrowing xbee code from the Fio might help.
Well if I fail to remove a mod I don't think I have much chances of importing xbee code.

Could this be related to the fact I burn using the Arduino as isp?
Anyone any idea on why my (removing a) mod does not work?
Anyone any idea what this code is for in the original mod (see first post)
Code:
#else
asm volatile("nop\n\t");
#endif

Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A update
I have learned plenty of things about the Arduino bootloader and AVR bootloading by now and I now know why my changes didn't work  smiley-cool
They didn't work because the mod for the watchdog has been used by now for many other implementations. In other words the bootloader itself uses the watchdog to reset itself.

The bad news is that I still don't know how to fix this in software.
The good news is that it does work with simply attaching a header (I used A5 for testing) to the reset pin to reboot and start the bootloader.

So I learned a lot and I have a solution  smiley-grin
I just wished I had lost less time
Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: [1]   Go Up
Jump to: