Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Passing info from bootloader to application

2014-08-18 by Chuck Hackett

I have an ATMega1284p based application. I have a bootloader installed. My application needs to know the reason for a start/restart (power-on, reset button, brown-out, WDT, etc.).

Before I started using the bootloader my application did this be saving the MCUSR immediately upon startup:

uint8_t mcucsr_mirror __attribute__ ((section (".noinit")));

__attribute__ ((no_instrument_function)) void Restart_ProcessRestart(void) \

__attribute__((naked)) \

__attribute__((section(".init3")));

void Restart_ProcessRestart(void)

{

mcucsr_mirror = MCUSR;

MCUSR = 0;

wdt_disable();

….

With the bootloader installed the MCUSR is getting destroyed by the bootloader so the application does not have access to it.

I have the source to the bootloader.

What is the best way to pass 1 byte of information from the bootloader to the application?

I know that I could define a common ‘mailbox’ memory location but I would like to keep the bootloader application independent.

The current ‘main’ called by the bootloader is defined as:

void (*app_start)(void) = 0x0000;

Can the ‘main’ being called by the bootloader be defined with parameters?

void (*app_start)(uint8_t MCUSR) = 0x0000;

Will this work if an application which does not care about the MCUSR defines it’s ‘main’ as ‘normal’?

void main(void);

If this is not appropriate, can I pass the value in a register?

If so, what register (as I recall GCC requires R1 to be 0)?

I assume assembly code will be required. I have not done assembly programming on the AVR so applicable assembly snippets would be appreciated.

Nope, this is not for homework – I’m 65 and way past school J

Cheers,

Chuck Hackett

"Good judgment comes from experience, experience comes from bad judgment"

7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.