1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "gd32f30x.h"
- #include "boot.h"
- #include "gd32_flash.h"
- #include "main.h"
- #include <string.h>
- void BootLoader_Clear(void);
- load_a load_A;
- static void JumpToApp(void);
- #define FMC_READ(addrx) (*(volatile uint32_t *)(uint32_t)(addrx))
- void BootLoader_Brance(uint32_t app_byte)
- {
- GD32_EraseFlash(GD32_A_START_PAGE,GD32_A_PAGE_NUM);//擦除A区原有程序
- for(uint8_t i=0;i<app_byte/4;i++)
- {
- uint32_t app_programmer=0;
-
-
- }
- JumpToApp();
- }
- static void JumpToApp(void)
- {
- uint32_t i=0;
- void (*SysMemBootJump)(void); /* 声明一个函数指针 */
- __IO uint32_t BootAddr =GD32_A_SADDR;
-
- rcu_deinit();
- /* 关闭全局中断 */
- __set_PRIMASK(1) ;
- /* 关闭滴答定时器,复位到默认值 */
- SysTick->CTRL = 0;
- SysTick->LOAD = 0;
- SysTick->VAL = 0;
- /* 关闭所有中断,清除所有中断挂起标志 */
- for (i = 0; i < 8; i++)
- {
- NVIC->ICER[i]=0xFFFFFFFF;
- NVIC->ICPR[i]=0xFFFFFFFF;
- }
- /* 使能全局中断 */
- __set_PRIMASK(0) ;
- /* 跳转到系统BootLoader,首地址是MSP,地址+4是复位中断服务程序地址 */
- SysMemBootJump = (void (*)(void)) (*((uint32_t *) (BootAddr + 4)));
- /* 设置主堆栈指针 */
- __set_MSP(*(uint32_t *)BootAddr);
-
- /* 在RTOS工程,这条语句很重要,设置为特权级模式,使用MSP指针 */
- __set_CONTROL(0);
- /* 跳转到系统BootLoader */
- SysMemBootJump();
- /* 跳转成功的话,不会执行到这里,用户可以在这里添加代码 */
- while (1)
- {
- }
- }
|