-
大小: 6.92KB文件類型: .rar金幣: 1下載: 0 次發(fā)布日期: 2024-04-19
- 語言: C/C++
- 標(biāo)簽: Bootloader??STM32??boot??STM32??
資源簡(jiǎn)介
stm32 BootLoader程序(main.c)
代碼片段和文件信息
#include?“Net_Config.h“
#include?“flash_if.h“
#include?“stm32f4xx_rcc.h“
#include?“stm32f4xx_pwr.h“
#include?“stm32f4xx_flash.h“
#include?“stm32f4xx_iwdg.h“
#include?“eth_stm32f4xx.h“
#include?“stm32f4xx_rtc.h“
#include?“StdFun.h“
#include?“Matrix.h“
#include?“uart_app.h“
#include?“SysTick.h“
#include?
#include?“main.h“
static?void?timer_poll(void);
static?void?IWDG_Init(void);
typedef??void?(*pFunction)(void);
pFunction?Jump_To_Application;
uint32_t?JumpAddress;
Bool FirmwareUpdate?=?FALSE;
/*?Net_Config.c?*/
extern?struct?http_cfg??http_config;
extern?U8?own_hw_adr[];
extern?LOCALM?localm[];
static?const?VERSION?DeviceVersion?__attribute__((at(0x08004000)))?=?{
SPONTAG
MATRIXBIRTHDAY
CFG_MAJOR
CFG_MINOR
CFG_YEAR
CFG_MONTH
CFG_DAY
};
void?GPIOBiosControl_Init(void)
{
GPIO_InitTypeDef??GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA?ENABLE);
GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType?=?GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_PuPd?=?GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA?&GPIO_InitStructure);
//? RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB?ENABLE);
//? GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_12;
//? GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IN;
//? GPIO_InitStructure.GPIO_OType?=?GPIO_OType_OD;
//? GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_25MHz;
//? GPIO_InitStructure.GPIO_PuPd?=?GPIO_PuPd_NOPULL;
//? GPIO_Init(GPIOB?&GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD?ENABLE);
GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType?=?GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_PuPd?=?GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD?&GPIO_InitStructure);
GPIO_SetBits(GPIOD?GPIO_Pin_8);
}
int?main(void)
{
uint16_t timeout?=?0;
uint32_t dwSponTag?=?0;
uint8_t netsock?=?0;
uint8_t GrpIpAddr[4];
BOOL? bFlag?=?FALSE;
uint32_t????ij;
GPIOBiosControl_Init();
bFlag?=?GPIOA->IDR?&?0x0400;
for?(i?=?0;?i?3000;?i++)//延時(shí)大約1S
for?(j?=?0;?j?10000;?j++);
bFlag?=?GPIOA->IDR?&?0x0400;
StdMemcpy(&dwSponTag?(void?*)((__IO?uint32_t?*)0x08040000)?4);
if?((dwSponTag?==?SPONTAG)?&&?bFlag)
{
GPIO_SetBits(GPIOD?GPIO_Pin_8);
//進(jìn)應(yīng)用程序段
/*?Check?if?valid?stack?address?(RAM?address)?then?jump?to?user?application?*/
if?(((*(__IO?uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS)?&?0x2FFE0000?)?==?0x20000000)
{
/*?Jump?to?user?application?*/
JumpAddress?=?*(__IO?uint32_t*)?(USER_FLASH_FIRST_PAGE_ADDRESS?+?4);
Jump_To_Application?=?(pFunction)?JumpAddress;
/*?Initialize?user?application‘s?Stack?Pointer?*/
__set_MSP(*(__IO?uint32_t*)?USER_FLASH_FIRST_PAGE_ADDRESS);
Jump_To_Application();
}
}?
else?
{
GPIO_ResetBits(GPIOD?GPIO_Pin_8);//
評(píng)論
共有 條評(píng)論