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. 校验成功,执行跳转
|
// 4. 校验成功,执行跳转
|
||||||
USB_PutString("Valid APP found, jumping to application...\r\n");
|
USB_PutString("Valid APP found, jumping to application...\r\n");
|
||||||
// 获取APP的堆栈指针和跳转地址
|
jump_to_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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no legal APP
|
// no legal APP
|
||||||
|
|||||||
@@ -229,22 +229,7 @@ void Main_Menu(void)
|
|||||||
{
|
{
|
||||||
USB_PutString("Start to execute the user application...\r\n");
|
USB_PutString("Start to execute the user application...\r\n");
|
||||||
HAL_Delay(1000);
|
HAL_Delay(1000);
|
||||||
USER_USB_DEVICE_DeInit();
|
jump_to_app();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
else if ((key == 0x34) && (FlashProtection == 1))
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ typedef void (*pFunction)(void);
|
|||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
void Main_Menu(void);
|
void Main_Menu(void);
|
||||||
|
void jump_to_app(void);
|
||||||
|
|
||||||
#endif /* __MENU_H */
|
#endif /* __MENU_H */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user