main.c
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**************************************************************************
* STM32F407ZET6芯片有512K的FLASH,有192K的RAM(128K SRAM和64K CCM)
*
* Bootloader功能介绍:
* 在芯片上电之后,首先运行的是Bootloader,Bootloader引导程序根据Flash上Flag段
* 的数据选择将哪一部分的固件加载到运行区间。
*
* BootLoader预留空间为16K
****************************************************************************/
#include "delay.h"
#include "string.h"
#include "usart1.h"
#include "uart5.h"
#include "iap.h"
#include "led.h"
#include "flash.h"
#include "ymodem.h"
int main(void)
{
uint32_t handle;
uint8_t ret;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//设置系统中断优先级分组4
delay_init();
usart1_init();
uart5_init();
LED_Init();
display_bootloader_extry_information();
handle = STMFLASH_ReadWord(FLAG_BASE_ADDR);
switch(handle) //选择加载那一部分的固件
{
case BOOTLOADER_LOAD: //升级段
load_process();
break;
case BOOTLOADER_RUN: //运行段
ret= uart_boot_detect();
if(LOCAL_BOOT_NONE == ret)
{
app_run();
}
else
{
printf("User instuction deteced!\r\n");
uart_boot();
}
break;
case BOOTLOADER_DEFAULT:
default :
printf("No valid firmware detected!\r\n");
uart_boot();
break;
}
while(1)
{
printf("unreachable!\r\n");
delay_ms(5000);
}
}