LCD_QSPIBoot/asw/bootapp.c
2025-05-21 15:35:29 +08:00

118 lines
3.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*******************************************************************************
* the includes
******************************************************************************/
#include "bootapp.h"
#include "norflash.h"
#include "uartapp.h"
/*******************************************************************************
* the defines
******************************************************************************/
#define ENABLE_INT() __set_PRIMASK(0) /* 使能全局中断 */
#define DISABLE_INT() __set_PRIMASK(1) /* 禁止全局中断 */
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct
{
uint32_t startflag;
uint32_t len;
uint32_t AppCRC;
uint32_t reverse;
} APPCRC_type;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the const
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void BspQspiBoot_JumpToApp(void)
{
uint32_t i = 0;
void (*AppJump)(void); /* 声明一个函数指针 */
__IO uint32_t AppAddr = 0x90000000; /* APP 地址 */
/* 关闭全局中断 */
DISABLE_INT();
/* 设置所有时钟到默认状态使用HSI时钟 */
HAL_RCC_DeInit();
/* 关闭滴答定时器,复位到默认值 */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/* 关闭所有中断,清除所有中断挂起标志 */
for (i = 0; i < 8; i++)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
/* 使能全局中断 */
ENABLE_INT();
/* 跳转到应用程序首地址是MSP地址+4是复位中断服务程序地址 */
AppJump = (void (*)(void))(*((uint32_t*)(AppAddr + 4)));
/* 设置主堆栈指针 */
__set_MSP(*(uint32_t*)AppAddr);
/* 在RTOS工程这条语句很重要设置为特权级模式使用MSP指针 */
__set_CONTROL(0);
/* 跳转到系统BootLoader */
AppJump();
/* 跳转成功的话,不会执行到这里,用户可以在这里添加代码 */
}
void WriteCRCInfo(uint32_t len, uint32_t crc)
{
APPCRC_type appcrc;
appcrc.startflag = 0xAA5555AA;
appcrc.len = len;
appcrc.AppCRC = crc;
appcrc.reverse = 0xAAAAAAAA;
NORFLASH_Write_NoCheck((uint8_t*)&appcrc, EX_FLASH_CRC_ADDR, 0x10);
}
uint8_t ReadCRCInfo(uint32_t* len, uint32_t* crc)
{
APPCRC_type* appcrc = (APPCRC_type*)EX_FLASH_CRC_ADDR;
if (appcrc->startflag == 0xAA5555AA)
{
*len = appcrc->len;
*crc = appcrc->AppCRC;
return 1;
}
else
{
return 0;
}
}
uint8_t Boot_checkApp(void)
{
uint32_t len, crc;
if (ReadCRCInfo(&len, &crc) == 1)
{
if (crc_calc(EX_FLASH_START_ADDR, len) == crc)
{
return 1;
}
else
{
return 0;
}
}
return 0;
}