mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
加入api , jump_to_app()
This commit is contained in:
@@ -191,21 +191,7 @@ int main(void)
|
||||
{
|
||||
// 4. 校验成功,执行跳转
|
||||
USB_PutString("Valid APP found, jumping to application...\r\n");
|
||||
// 获取APP的堆栈指针和跳转地址
|
||||
uint32_t JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
|
||||
Jump_To_Application = (pFunction) JumpAddress;
|
||||
// 在跳转前反初始化所有Bootloader用过的外设
|
||||
USER_USB_DEVICE_DeInit();
|
||||
HAL_RCC_DeInit();
|
||||
HAL_DeInit();
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
__disable_irq();
|
||||
|
||||
// 设置APP的堆栈指针并跳转
|
||||
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
|
||||
Jump_To_Application();
|
||||
jump_to_app();
|
||||
}
|
||||
}
|
||||
// no legal APP
|
||||
|
||||
@@ -229,22 +229,7 @@ void Main_Menu(void)
|
||||
{
|
||||
USB_PutString("Start to execute the user application...\r\n");
|
||||
HAL_Delay(1000);
|
||||
USER_USB_DEVICE_DeInit();
|
||||
HAL_RCC_DeInit();
|
||||
HAL_DeInit();
|
||||
//user code here
|
||||
SysTick->CTRL = 0X00;//禁止SysTick
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
__disable_irq();
|
||||
|
||||
//set JumpAddress
|
||||
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
|
||||
/* Jump to user application */
|
||||
Jump_To_Application = (pFunction) JumpAddress;
|
||||
/* Initialize user application's Stack Pointer */
|
||||
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
|
||||
Jump_To_Application();
|
||||
jump_to_app();
|
||||
}
|
||||
else if ((key == 0x34) && (FlashProtection == 1))
|
||||
{
|
||||
@@ -281,6 +266,37 @@ void Main_Menu(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Public functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Jumps to the user application loaded in the Flash memory.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void jump_to_app(void)
|
||||
{
|
||||
USER_USB_DEVICE_DeInit();
|
||||
// 手动配置USB引脚为GPIO输出,强制拉低DP线以模拟拔出
|
||||
USER_USBD_LL_Simulate_Disconnect();
|
||||
// 给予PC足够的时间来识别设备断开
|
||||
HAL_Delay(1000);
|
||||
HAL_RCC_DeInit();
|
||||
HAL_DeInit();
|
||||
//user code here
|
||||
SysTick->CTRL = 0X00;//禁止SysTick
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
__disable_irq();
|
||||
|
||||
//set JumpAddress
|
||||
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
|
||||
/* Jump to user application */
|
||||
Jump_To_Application = (pFunction) JumpAddress;
|
||||
/* Initialize user application's Stack Pointer */
|
||||
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
|
||||
Jump_To_Application();
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file STM32F4xx_IAP/inc/menu.h
|
||||
* @file STM32F4xx_IAP/inc/menu.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 10-October-2011
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MENU_H
|
||||
@@ -34,6 +34,7 @@ typedef void (*pFunction)(void);
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Main_Menu(void);
|
||||
void jump_to_app(void);
|
||||
|
||||
#endif /* __MENU_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user