芯片复制HK32F030Mxx API函数
- 芯片复制* Include files
- ******************************************************************************/
- 芯片复制#include "iap.h"
- 芯片复制#include "basic.h"
- 芯片复制#include "flash.h"
- #include "uart.h"
- #include "modem.h"
- #include "User_Timer.h"
- /*******************************************************************************
- * Local type definitions ('typedef')
- ******************************************************************************/
- /*******************************************************************************
- * Local pre-processor symbols/macros ('#define')
- ******************************************************************************/
- /*******************************************************************************
- * Global variable definitions (declared in header file with 'extern')
- ******************************************************************************/
- uint32_t JumpAddress;
- func_ptr_t JumpToApplication;
- /*******************************************************************************
- * Local function prototypes ('static')
- ******************************************************************************/
- static en_result_t IAP_JumpToApp(uint32_t u32Addr);
- static void IAP_ResetConfig(void);
- /*******************************************************************************
- * Local variable definitions ('static')
- ******************************************************************************/
- /*******************************************************************************
- * Function implementation - global ('extern') and local ('static')
- ******************************************************************************/
- /**
- *******************************************************************************
- ** \brief Initialize IAP
- **
- ** \param [in] None
- **
- ** \retval None
- **
- ******************************************************************************/
- void IAP_Init(void)
- {
- SystemClock_Init();
- LED_Init();
- UART_Init();
- }
- /**
- *******************************************************************************
- ** \brief UART receive byte.
- **
- ** \param [out] u8RxData Pointer to Rx data.
- **
- ** \retval Ok Receive data finished.
- ** \retval Error Don't receive data.
- **
- ******************************************************************************/
- void IAP_Main(void)
- {
- uint32_t u32AppFlag;
- en_result_t enRet;
- while (1)
- {
- enRet = Modem_Process(BOOT_WAIT_TIME);
- if ((enRet == Ok) || (enRet == ErrorTimeout))
- {
- u32AppFlag = *(__IO uint32_t *)BOOT_PARA_ADDRESS;
- if ((0xFFFF != u32AppFlag))
- {
- if (Error == IAP_JumpToApp(APP_ADDRESS))
- {
- LED0_OFF();
- LED1_ON();
- }
- }
- else
- {
- LED0_ON();
- LED1_ON();
- }
- }
- else
- {
- LED1_OFF();
- LED0_ON();
- }
- }
- }
- /**
- *******************************************************************************
- ** \brief IAP main function
- **
- ** \param [in] u32Addr APP address
- **
- ** \retval Error APP address error
- **
- ******************************************************************************/
- static en_result_t IAP_JumpToApp(uint32_t u32Addr)
- {
- uint32_t u32StackTop = *((__IO uint32_t *)u32Addr);
- /* Check if user code is programmed starting from address "u32Addr" */
- /* Check stack top pointer. */
- if ((u32StackTop > SRAM_BASE) && (u32StackTop <= (SRAM_BASE + RAM_SIZE)))
- {
- IAP_ResetConfig();
- /* Jump to user application */
- JumpAddress = *(__IO uint32_t *)(u32Addr + 4);
- JumpToApplication = (func_ptr_t)JumpAddress;
- /* Initialize user application's Stack Pointer */
- __set_MSP(*(__IO uint32_t *)u32Addr);
- JumpToApplication();
- }
- return Error;
- }

芯片解密