Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run bootloader after a software reset #350

Open
ghost opened this issue Jul 12, 2022 · 3 comments
Open

Run bootloader after a software reset #350

ghost opened this issue Jul 12, 2022 · 3 comments
Labels
Discussion More conversation than actual bug or change.

Comments

@ghost
Copy link

ghost commented Jul 12, 2022

For a custom board I cannot relay on a hardware reset. The running application will reset the MCU when receives a specific string.
My need is to enter the bootloader not only at power on, but also on software reset.
I looked at the options here, but I can't find nothing about.

Is there anything ready (perhaps undocumented) or it's like a "feature request" and I have to change the code?

@WestfW
Copy link
Member

WestfW commented Jul 18, 2022

You can do this, but you need to be careful to:

  1. Disable interrupts and interrupt sources (eg timers) that may be running in the application.
  2. Make sure the MCUSR (reset reason) is zeroed.
  3. Derive the correct start address for optiboot (FLASHEND-BOOTLOADERSIZE. Or maybe derived from reading the fuses?)

There is an example here: https://github.com/Optiboot/optiboot/blob/master/optiboot/examples/demo_reset/demo_reset.ino#L129 (it should still work...)

@WestfW WestfW added the Discussion More conversation than actual bug or change. label Jul 19, 2022
@aviatorhh
Copy link

Can this still be confirmed working by someone?
I tried it on an ATmega328P

void reset() {
        typedef void (*do_reboot_t)(void);
        const do_reboot_t do_reboot = (do_reboot_t)((FLASHEND - 511) >> 1);

        cli(); TCCR0A = TCCR1A = TCCR2A = 0; // make sure interrupts are off and timers are reset.
        MCUSR = 0;
        do_reboot();
}

but with no joy. The system seems to hang with a flickering LED (Uno Board).
I wanted to run avrdude after a remotely triggered software reset.
I tried FLASHEND - 1023 and also 2047 - too lazy to read the fuses at the moment :-)

@WestfW
Copy link
Member

WestfW commented May 5, 2024

Hmm. Doesn't work here either. I'm using a modified ASCIITable sketch for testing, and there are some signs that perhaps the UART ISR is getting called before things are fully initialized, but even with added code that should be making sure that the UART is disabled before the do_reboot(), it still fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion More conversation than actual bug or change.
Projects
None yet
Development

No branches or pull requests

2 participants