Hallo zusammen. Schon sehr lange versuche ich vergebend einen Bootloader/bzw. Flash zu programmieren mittels AVR selbst. Dazu habe ich einen stark vereinfachten Aufbau gestartet welcher aber nicht klappt: Der zweite Teil ist das originale Nutzungsbeispiel von boot.h Ich lese den Flash nach dem starten des Programmes aus, er ist nicht beschrieben (mit 0x00).
1 | #include <avr/io.h> |
2 | #include <avr/interrupt.h> |
3 | #include <avr/boot.h> |
4 | #define F_CPU 8000000
|
5 | #include <util/delay.h> |
6 | |
7 | int main(void) |
8 | {
|
9 | uint8_t inhalt[SPM_PAGESIZE] = {0x00}; |
10 | boot_program_page((uint16_t)0x0000, inhalt); |
11 | while(1); |
12 | }
|
13 | |
14 | void boot_program_page (uint32_t page, uint8_t *buf) |
15 | {
|
16 | uint16_t i; |
17 | uint8_t sreg; |
18 | |
19 | /* Disable interrupts.*/
|
20 | sreg = SREG; |
21 | cli(); |
22 | |
23 | eeprom_busy_wait (); |
24 | |
25 | boot_page_erase (page); |
26 | boot_spm_busy_wait (); /* Wait until the memory is erased. */ |
27 | |
28 | for (i=0; i<SPM_PAGESIZE; i+=2) |
29 | {
|
30 | /* Set up little-endian word. */
|
31 | uint16_t w = *buf++; |
32 | w += (*buf++) << 8; |
33 | |
34 | boot_page_fill (page + i, w); |
35 | }
|
36 | boot_page_write (page); /* Store buffer in flash page. */ |
37 | boot_spm_busy_wait(); /* Wait until the memory is written.*/ |
38 | |
39 | /* Reenable RWW-section again. We need this if we want to jump back */
|
40 | /* to the application after bootloading. */
|
41 | boot_rww_enable (); |
42 | |
43 | /* Re-enable interrupts (if they were ever enabled). */
|
44 | SREG = sreg; |
45 | }
|