2021-03-09 18:17:28 +08:00
|
|
|
/*
|
|
|
|
* @Description:
|
|
|
|
* @Date: 2021-03-09 10:21:58
|
|
|
|
* @LastEditors: CK.Zh
|
2021-03-10 12:03:49 +08:00
|
|
|
* @LastEditTime: 2021-03-10 11:15:23
|
2021-03-09 18:17:28 +08:00
|
|
|
* @FilePath: \NaviKit_EC_stm32\App\Src\isp.c
|
|
|
|
*/
|
|
|
|
#include <isp.h>
|
2021-02-24 15:52:23 +08:00
|
|
|
#include "cmsis_os2.h" // ::CMSIS:RTOS2
|
|
|
|
|
|
|
|
void ISP_Jump(){
|
|
|
|
typedef void (*pFunction)(void);
|
|
|
|
pFunction Jump_to_ISP;
|
|
|
|
Jump_to_ISP = (pFunction) (*(__IO uint32_t*)(ISP_ADDRESS + 4));//ISP's program's reset vector (pc pointer initial value)
|
|
|
|
__set_MSP(*(__IO uint32_t*) ISP_ADDRESS);
|
|
|
|
Jump_to_ISP();
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ISP_Judge()
|
|
|
|
{//Judge that if need jump to ISP area
|
|
|
|
RTC_HandleTypeDef hrtc;
|
|
|
|
hrtc.Instance = RTC;
|
|
|
|
if(HAL_RTCEx_BKUPRead(&hrtc,MAGIC_VALUE_ADDRESS) == MAGIC_VALUE)
|
|
|
|
{
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
__HAL_RCC_BKP_CLK_ENABLE();
|
|
|
|
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_HSE_DIV128);
|
|
|
|
__HAL_RCC_RTC_ENABLE();
|
|
|
|
HAL_PWR_EnableBkUpAccess();
|
|
|
|
|
|
|
|
HAL_RTCEx_BKUPWrite(&hrtc,MAGIC_VALUE_ADDRESS,0x0000);
|
|
|
|
|
|
|
|
__HAL_RCC_RTC_DISABLE();
|
|
|
|
__HAL_RCC_PWR_CLK_DISABLE();
|
|
|
|
__HAL_RCC_BKP_CLK_DISABLE();
|
|
|
|
|
|
|
|
HAL_PWR_DisableBkUpAccess();
|
|
|
|
|
|
|
|
ISP_Jump();
|
|
|
|
}
|
|
|
|
}
|
2021-03-09 18:17:28 +08:00
|
|
|
|
|
|
|
|
2021-02-24 15:52:23 +08:00
|
|
|
bool ISP_Prepare(){
|
|
|
|
RTC_HandleTypeDef hrtc;
|
|
|
|
|
|
|
|
hrtc.Instance = RTC;
|
|
|
|
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
__HAL_RCC_BKP_CLK_ENABLE();
|
|
|
|
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_HSE_DIV128);
|
|
|
|
__HAL_RCC_RTC_ENABLE();
|
|
|
|
HAL_PWR_EnableBkUpAccess();
|
|
|
|
|
|
|
|
HAL_RTCEx_BKUPWrite(&hrtc,MAGIC_VALUE_ADDRESS,MAGIC_VALUE);
|
|
|
|
|
|
|
|
osDelay(10);
|
|
|
|
if(HAL_RTCEx_BKUPRead(&hrtc,MAGIC_VALUE_ADDRESS) == MAGIC_VALUE)
|
|
|
|
{//write successful
|
|
|
|
TaskBeep(400,5);
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Enter to EC update state.");
|
|
|
|
log_i("EC will reboot ,then run ISP automatic.");
|
2021-02-24 15:52:23 +08:00
|
|
|
HAL_NVIC_SystemReset();
|
2021-03-10 12:03:49 +08:00
|
|
|
return true;
|
2021-02-24 15:52:23 +08:00
|
|
|
}
|
|
|
|
else{
|
2021-03-09 18:17:28 +08:00
|
|
|
log_e("Backup register writen error, can not enter EC update state.");
|
|
|
|
return false;
|
2021-02-24 15:52:23 +08:00
|
|
|
}
|
|
|
|
}
|