|
11 | 11 | /* Flash layout
|
12 | 12 | * ------------ 0x08000000
|
13 | 13 | * |bootloader |
|
14 |
| - * | 16K | |
| 14 | + * |14K | |
| 15 | + * -------------0x08003800 |
| 16 | + * |data | |
| 17 | + * |2K | |
15 | 18 | * ------------ 0x08004000
|
16 | 19 | * |image1 |
|
17 | 20 | * |120K |
|
|
26 | 29 | #define VERSION "\r\nBootloader ver: " MAKE_STR(SW_VERSION_MAJOR) "." \
|
27 | 30 | MAKE_STR(SW_VERSION_MINOR) "." MAKE_STR(SW_VERSION_BUILD) "\r\n"
|
28 | 31 |
|
29 |
| -#define APP_ADDRESS_OFFSET 0x4000 |
30 |
| -#define APP_ADDRESS (FLASH_BASE + APP_ADDRESS_OFFSET) |
| 32 | +#define APP1_ADDRESS_OFFSET 0x4000 |
| 33 | +#define APP1_ADDRESS (FLASH_BASE + APP1_ADDRESS_OFFSET) |
| 34 | +#define APP2_ADDRESS_OFFSET 0x22000 |
| 35 | +#define APP2_ADDRESS (FLASH_BASE + APP2_ADDRESS_OFFSET) |
31 | 36 |
|
32 | 37 | typedef void (*app_func_t)(void);
|
| 38 | +typedef struct __attribute__((__packed__)) |
| 39 | +{ |
| 40 | + uint8_t active_image; |
| 41 | +} config_t; |
| 42 | + |
| 43 | +__attribute__((__section__(".user_data"))) const char data[1]; |
33 | 44 |
|
34 | 45 | int main()
|
35 | 46 | {
|
36 | 47 | app_func_t app;
|
37 |
| - uint32_t jump_addr; |
| 48 | + uint32_t jump_addr, vt_offset, sp_addr; |
| 49 | + config_t *config = (config_t *)data; |
38 | 50 |
|
39 | 51 | uart_init();
|
40 | 52 | print(VERSION);
|
41 | 53 |
|
| 54 | + print("Start application: "); |
| 55 | + if (!config->active_image) |
| 56 | + { |
| 57 | + print("0\r\n"); |
| 58 | + vt_offset = APP1_ADDRESS_OFFSET; |
| 59 | + jump_addr = *(__IO uint32_t *)(APP1_ADDRESS + 4); |
| 60 | + sp_addr = *(__IO uint32_t *)APP1_ADDRESS; |
| 61 | + } |
| 62 | + else |
| 63 | + { |
| 64 | + print("1\r\n"); |
| 65 | + vt_offset = APP2_ADDRESS_OFFSET; |
| 66 | + jump_addr = *(__IO uint32_t *)(APP2_ADDRESS + 4); |
| 67 | + sp_addr = *(__IO uint32_t *)APP2_ADDRESS; |
| 68 | + } |
| 69 | + |
42 | 70 | /* Relocate vector table */
|
43 |
| - NVIC_SetVectorTable(NVIC_VectTab_FLASH, APP_ADDRESS_OFFSET); |
44 |
| - /* Set application address */ |
45 |
| - jump_addr = *(__IO uint32_t *)(APP_ADDRESS + 4); |
46 |
| - app = (app_func_t)jump_addr; |
| 71 | + NVIC_SetVectorTable(NVIC_VectTab_FLASH, vt_offset); |
47 | 72 | /* Initialize application's Stack Pointer */
|
48 |
| - __set_MSP(*(__IO uint32_t *)APP_ADDRESS); |
| 73 | + __set_MSP(sp_addr); |
49 | 74 | /* Start application */
|
| 75 | + app = (app_func_t)jump_addr; |
50 | 76 | app();
|
51 | 77 |
|
52 | 78 | return 0;
|
|
0 commit comments