ich habe nochmal daran weitergearbeitet aus der App heraus den
Bootloader aufzurufen. Das klappt auch, aber jetzt habe ich ein kleines
Problem mit dem Stackinit im gcc-avr (4.1.1).
Der Stack wird in __jmpMain() deklariert, aber der Code dafür wird in
execBootloader() eingefügt, d.h. in main() werden Calls ohne gesetzten
Stackpointer ausgeführt. Ich habe extra noch checkBootloaderPin() als
noinline eingefügt, der call wird auch generiert aber trotzdem wird der
Stack nicht in main initialisiert. Hat jemand eine Idee warum das so
ist?
1 | void __jumpMain (void) __attribute__ ((naked)) __attribute__
|
2 | ((section (".init9")));
|
3 |
|
4 | void __jumpMain(void)
|
5 | {
|
6 | asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
|
7 | asm volatile ( "clr __zero_reg__" ); // GCC
|
8 | depends on register r1 set to 0
|
9 | asm volatile ( "out %0, __zero_reg__" :: "I"
|
10 | (_SFR_IO_ADDR(SREG)) ); // set SREG to 0
|
11 | asm volatile ( "rjmp main"); //
|
12 | jump to main()
|
13 | }
|
14 |
|
15 | //void __attribute__ ((noreturn)) execBootloader(void)
|
16 | void execBootloader();
|
17 | {
|
18 | ...
|
19 | }
|
20 |
|
21 | int __attribute__ ((noinline)) checkBootloaderPin()
|
22 | {
|
23 | return !(PROG_IN & (1<<PROG_PIN));
|
24 | }
|
25 |
|
26 | //void __attribute__ ((noreturn)) main(void)
|
27 | int main(void)
|
28 | {
|
29 | if(checkBootloaderPin())
|
30 | {
|
31 | execBootloader();
|
32 | }
|
33 |
|
34 | boot_rww_enable(); // enable application section
|
35 |
|
36 | asm volatile ( "push r1" "\n\t" // Jump to Reset vector in
|
37 | Application Section
|
38 | "push r1" "\n\t"
|
39 | "ret" "\n\t"
|
40 | ::);
|
41 | for(;;);
|
42 | }
|