• IAP升级--重点


    typedef  void (*pFunction)(void);
    pFunction Jump_To_Application;
    uint32_t JumpAddress;
    Boot_para_s boot_struct;
    
    static void Jump_To_App(void )
    {
        if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
        {
            JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
            Jump_To_Application = (pFunction) JumpAddress;
    
            __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
            
            LocalPrintf("Jump To App...
    ");
            Jump_To_Application();
        }
        LocalPrintf("not find app prj...
    ");
    }
    
    static void StoreSwitch(void)
    {
        uint8_t res = 0,tmp_data[1024];
        uint32_t wr_size = 0,wr_addr, total_size;
    
        FeedWatchDog(); 
        McuFlashRead(BOOT_PARA_CONFIG_ADDR,(uint8_t*)&boot_struct.uApp_UpDataFlg,sizeof(Boot_para_s));
    
        if(boot_struct.uApp_UpDataFlg != VALID_VAL_DWORD_AA)
        {
            LocalPrintf("Not find updataflg
    ");
            goto jump_lab;
        }
    
        LocalPrintf("app updata size is %d bytes
    ", boot_struct.uApp_DataSize);
        if(boot_struct.uApp_DataSize > APPLICATION_FLASH_SIZE)
        {
            McuFlashErase(APPLICATION_UPDATE_ADDRESS,APPLICATION_FLASH_SIZE);
            BootParaInit();
            goto jump_lab;
        }
    
        res = McuFlashErase(APPLICATION_ADDRESS,APPLICATION_FLASH_SIZE);
        if(!res)
        {
            goto jump_lab;
        }
    
        IRQ_DISABLE();
        total_size = boot_struct.uApp_DataSize;
        wr_addr    = 0;
        while(total_size > 0)
        {
            FeedWatchDog();
            if(total_size >= 1024)
            {
                wr_size = 1024;
            }
            else
            {
                wr_size = total_size;
            }
            McuFlashRead(APPLICATION_UPDATE_ADDRESS+wr_addr,tmp_data,wr_size);
            res = McuFlashWrite(APPLICATION_ADDRESS+wr_addr,tmp_data,wr_size);
            if(!res)
            {
                LocalPrintf("app updata fail!
    ");
                break;
            }
            wr_addr    += wr_size;
            total_size -= wr_size;
            LocalPrintf("app total size is %d
    ", total_size);
        }
        IRQ_ENABLE();
        if(total_size == 0)
        {
            LocalPrintf("app updata OK!
    ");
            BootParaInit();
        }
    jump_lab:    
        FeedWatchDog();
    }
    /* USER CODE BEGIN Private defines */
    #define IRQ_DISABLE()         (__disable_irq())
    #define IRQ_ENABLE()         (__enable_irq())
    #define VALID_VAL_DWORD_AA      0xAAAAAAAA
    #define INVALID_VAL_DWORD_55  0x55555555
    /*编译宏*/
    #define APP_VALID_FLG        0  //0:app1      1:app2
    
    
    typedef struct
    {
        uint32_t uApp_UpDataFlg;
        uint32_t uApp_DataSize;
    }Boot_para_s;
    /* USER CODE END Private defines */
    /*--------------------------------------------------------------------------
                                                                          0ooo
                                                                ooo0       (   )
                                                                (   )      ) /
                                                                  (      (_/
                                                                  \_)
    ----------------------------------------------------------------------------*/
    真正的对手会灌输给你大量的勇气 --卡夫卡
  • 相关阅读:
    MongoDB存储
    python 查看文件名和文件路径
    Python遍历文件个文件夹
    Python图片缩放
    python opencv
    Python3 关于UnicodeDecodeError/UnicodeEncodeError: ‘gbk’ codec can’t decode/encode bytes类似的文本编码问题
    jmter使用
    HttpRunnerManager使用
    PostMan使用
    工作中的思想
  • 原文地址:https://www.cnblogs.com/firstparke/p/8423854.html
Copyright © 2020-2023  润新知