Go Down

Topic: Entering bootloader with watchdog reset! (Read 154 times) previous topic - next topic


So I want to enter the bootloader of an Arduino nano (Chinese version with old bootloader). I tried using an watchdog reset but it doesn't enter bootloader and only ends in an infinite watchdog reset loop (I know this is an known issue)! I read in this Post: https://forum.arduino.cc/index.php?topic=38157.0
that this problem is related to the following lines in ATMEGA Boot:
Code: [Select]
 // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.[color=#222222][/color]
     if (! (ch &  _BV(EXTRF))) // if its a not an external reset...[color=#222222][/color]
           app_start();  // skip bootloader

ch is MCUSR, I set it to 0 when restarting!
But what is EXTRF?
I know I could comment out this line to get it to work! But to do this I would need to build an ISP Programmer, which I only want to do if its absolutly needed! 
So is there any possible option to reset this Arduino Nano to enter bootloader correctly? or do I have to change Bootloader?

and if I have to change bootloader would Optiboot be a better solution for my Problem?



MCUSR is status register and EXTRF is the external reset flag - a bit in MCUSR. I'm recommending to read ATmega328P data sheet if you want know more about it.
Why would you built the ISP programmer. Any cheap ISP programmer is good, like most common USBasp. You can also use another Arduino as ISP programmer.
There is a possibility to call the bootloader directly, a jump to the address of the bootloader. Not the same as reset but it should work.
Optiboot is good choice and it is smaller than bootloader usually used in chinese Nanos. It takes 512B in compare with 1kB for the old bootloader. Optiboot image is created for 115200 baud trnsfer speed, the old bootloader has it for 57600 baud, but you can compile it for your needs of course.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0


Okay! Thank you! 
With ISP Programmer I meant an Arduino one....
I may have an look into jumping to the right address... But I guess this isnt very consistent/reliable?
I know Optiboot has these advantages, but would it help with jumping into the bootloader? 


Truly, I've never tried exactly this myself. I've just used jump to 0 address to start the APP directly. The difference against the RESET or like watchdog it does, is in e.g. I/O initial setting. They are in the high impedance state after the reset.
Anyhow, I do not see any essential problem to do this. You would inform us about the result.
The address of the bootloader is in e.g. according the datasheet for 328P -  boot regions and their sizes. You can use ASM instruction for jump JMP or define the function and just call it.
Code: [Select]

// ASM call
__asm__ __volatile__("JMP 0x7C00" );

// C function
void (*b)() = (void (*)())0x7C00;
// then somewhere in program

Old bootloader uses 1024 so the address should be 7c00h.

Personally, I would prefer watchdog with Optiboot.

Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0


Thanks a lot! 
I will try to jump to this address, since it easy to implement. However I dont think this will work because watchdogs is defined in the main loop of the bootloader therefor it propably will still escape the bootloader...

Else I will just use optiboot!


What do you hope to accomplish by entering the bootloader?


I tried to send a command over serial to it to restart it self and then upload a Programm over an Mkr Zero! Sadly 
Budvar10's suggested "address jumb" didn't work, because the extrf flag wasnt correct! But now I updated the Bootloader and added a reset pin from the master and everything works finenow

Go Up