[应用方案]

EC_M031_Multi_App多APP切换

[复制链接]
1465|15
手机看帖
扫描二维码
随时随地手机跟帖
東南博士|  楼主 | 2021-7-31 11:24 | 显示全部楼层 |阅读模式
EC_M031_Multi_App多APP切换

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:31 | 显示全部楼层
M031多功能跳转

708866104c4099f27c.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:31 | 显示全部楼层
746816104c422c1d96.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:32 | 显示全部楼层
459096104c45f3539e.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:33 | 显示全部楼层
992056104c49f5922f.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:34 | 显示全部楼层
739226104c4adc1350.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:35 | 显示全部楼层
78216104c4d8eb20d.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:36 | 显示全部楼层
4106104c518026f4.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:36 | 显示全部楼层
270126104c53b7756c.png

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:37 | 显示全部楼层
范例程序 执行
1. 通过ICP工具连接芯片,进入Config Bits->Setting配置,更改Chip booting selection 为LDROM with IAP。
2. 编译程序,连接ICP工具进入下载模式
 分别打开MultiLD,MultiAP1,MultiAP2工程进行完整编译;
 连接ICP工具,并下载程序;
 MultiLD 程序放置于LDROM;
 MultiAP1程序放置于APROM,偏移地址为0;
 MultiAP2程序放置于APROM,偏移地址为0x4000;
 进行下载。
3. 重新上电复位mcu
 执行代码;
 通过串口输入提示字符即可跳转到所需应用。

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:39 | 显示全部楼层
EC_M031_Multi_App多APP切换

EC_M031_Multi_Ap_V1.00.rar

3.61 MB

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:40 | 显示全部楼层
bootloader源码:

/**************************************************************************//**
* @file     main.c
* @version  V1.00
* @brief    AP1 Base address is 0, AP2 Base address is 0x4000
*           LD Base address is 0x100000
*                   Multiple app jump to each other
* SPDX-License-Identifier: Apache-2.0
* @CopyRight (C) 2018 Nuvoton Technology Corp. All rights reserved.
****************************************************************************/
#include <stdio.h>
#include "NuMicro.h"


/*----------------------------------------------------------------------------*/
/* Define                                                                     */
/*----------------------------------------------------------------------------*/
#define AP1_BASE_ADDRESS 0
#define AP2_BASE_ADDRESS 0x4000
#define LD_BASE_ADDRESS 0x100000

#define FMC_ISPCMD_VECMAP       0x2EUL          /*!< ISP Command: Vector Page Remap  \hideinitializer */
#define V6M_AIRCR_VECTKEY_DATA    0x05FA0000UL
#define V6M_AIRCR_SYSRESETREQ     0x00000004UL

/*----------------------------------------------------------------------------*/
/* Global variable                                                            */
/*----------------------------------------------------------------------------*/



/*----------------------------------------------------------------------------*/
/* Functions                                                                  */
/*----------------------------------------------------------------------------*/


/**
* @brief       Set vector mapping address
* @param[in]   u32PageAddr  The page address to remap to address 0x0. The address must be page alignment.
* @return      To set VECMAP to remap specified page address to 0x0.
* @Details     This function is used to set VECMAP to map specified page to vector page (0x0).
* @note
*              VECMAP only valid when new IAP function is enabled. (CBS = 10'b or 00'b)
*/
void MCU_FMC_SetVectorPageAddr(uint32_t u32PageAddr)
{
    FMC->ISPCMD = FMC_ISPCMD_VECMAP;  /* Set ISP Command Code */
    FMC->ISPADDR = u32PageAddr;       /* The address of specified page which will be map to address 0x0. It must be page alignment. */
    FMC->ISPTRG = 0x1u;               /* Trigger to start ISP procedure */
#if ISBEN
    __ISB();
#endif                                /* To make sure ISP/CPU be Synchronized */

    while (FMC->ISPTRG) {}            /* Waiting for ISP Done */
}


void UART_Init()
{
    /* Reset UART0 */
    SYS_ResetModule(UART0_RST);

    /* Configure UART0 and set UART0 baud rate */
    UART_Open(UART0, 115200);
}

void SYS_Init(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Enable HIRC */
    CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

    /* Waiting for HIRC clock ready */
    CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

    /* Switch HCLK clock source to HIRC */
    CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

    /* Set both PCLK0 and PCLK1 as HCLK/2 */
    CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);

    /* Switch UART0 clock source to HIRC */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HIRC, CLK_CLKDIV0_UART0(1));

    /* Enable UART peripheral clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    SystemCoreClockUpdate();

    /*----------------------------------------------------------------------*/
    /* Init I/O Multi-function                                              */
    /*----------------------------------------------------------------------*/
    /* Set GPB multi-function pins for UART0 RXD and TXD */
    SYS->GPB_MFPH = (SYS->GPB_MFPH & ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk)) |
                    (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD);

    /* Lock protected registers */
    SYS_LockReg();
}
int main(void)
{
    uint8_t u8Item;

    /* Init System, IP clock and multi-function I/O. */
    SYS_Init();

    UART_Init();
    printf("\n\n\n");
    printf("\nLDROM START, Boot Address = 0x100000 \n");

    do
    {
        printf("+----------------------------------------+\n");
        printf("|               Select                   |\n");
        printf("+----------------------------------------+\n");
        printf("| [0] Run APROM1 program(Address=0x0)                 \n");
        printf("| [1] Run APROM2 program(Address=0x4000)  \n");
        printf("+----------------------------------------+\n");
        printf("Please select...\n");

        u8Item = getchar();

        switch (u8Item)
        {
            case '0':
                SYS_UnlockReg();
                /* Enable FMC ISP function */
                FMC->ISPCTL |=  FMC_ISPCTL_ISPEN_Msk;
                /*Disable all interrupts*/
                NVIC->ICER[0] = 0xFFFFFFFF;
                MCU_FMC_SetVectorPageAddr(AP1_BASE_ADDRESS);

                SYS->RSTSTS = (SYS_RSTSTS_PORF_Msk | SYS_RSTSTS_PINRF_Msk);
                FMC->ISPCTL &= ~(FMC_ISPCTL_ISPEN_Msk | FMC_ISPCTL_BS_Msk);
                SCB->AIRCR = (V6M_AIRCR_VECTKEY_DATA | V6M_AIRCR_SYSRESETREQ);
                break;

            case '1':
                SYS_UnlockReg();
                /* Enable FMC ISP function */
                FMC->ISPCTL |=  FMC_ISPCTL_ISPEN_Msk;
                /*Disable all interrupts*/
                NVIC->ICER[0] = 0xFFFFFFFF;
                MCU_FMC_SetVectorPageAddr(AP2_BASE_ADDRESS);

                SYS->RSTSTS = (SYS_RSTSTS_PORF_Msk | SYS_RSTSTS_PINRF_Msk);
                FMC->ISPCTL &= ~(FMC_ISPCTL_ISPEN_Msk | FMC_ISPCTL_BS_Msk);
                SCB->AIRCR = (V6M_AIRCR_VECTKEY_DATA | V6M_AIRCR_SYSRESETREQ);
                break;
        }
    } while (1);
}

/*** (C) COPYRIGHT 2021 Nuvoton Technology Corp. ***/

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:41 | 显示全部楼层
APP1源码:

/**************************************************************************//**
* @file     main.c
* @version  V1.00
* @brief    AP1 Base address is 0, AP2 Base address is 0x4000
*           LD Base address is 0x100000
*                   Multiple app jump to each other
* SPDX-License-Identifier: Apache-2.0
* @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
****************************************************************************/
#include <stdio.h>
#include "NuMicro.h"


/*----------------------------------------------------------------------------*/
/* Define                                                                     */
/*----------------------------------------------------------------------------*/
#define AP1_BASE_ADDRESS 0
#define AP2_BASE_ADDRESS 0x4000
#define LD_BASE_ADDRESS 0x100000

/*----------------------------------------------------------------------------*/
/* Global variable                                                            */
/*----------------------------------------------------------------------------*/



/*----------------------------------------------------------------------------*/
/* Functions                                                                  */
/*----------------------------------------------------------------------------*/

void SYS_Init(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Enable HIRC */
    CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

    /* Waiting for HIRC clock ready */
    CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

    /* Switch HCLK clock source to HIRC */
    CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

    /* Set both PCLK0 and PCLK1 as HCLK/2 */
    CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);

    /* Switch UART0 clock source to HIRC */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HIRC, CLK_CLKDIV0_UART0(1));

    /* Enable UART peripheral clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    SystemCoreClockUpdate();

    /*----------------------------------------------------------------------*/
    /* Init I/O Multi-function                                              */
    /*----------------------------------------------------------------------*/
    /* Set GPB multi-function pins for UART0 RXD and TXD */
    SYS->GPB_MFPH = (SYS->GPB_MFPH & ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk)) |
                    (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD);

    /* Lock protected registers */
    SYS_LockReg();
}

/*----------------------------------------------------------------------*/
/* Init UART0                                                           */
/*----------------------------------------------------------------------*/
void UART0_Init(void)
{
    /* Reset UART0 */
    SYS_ResetModule(UART0_RST);

    /* Configure UART0 and set UART0 baud rate */
    UART_Open(UART0, 115200);
}

int main(void)
{
    uint8_t u8Item;

    /* Init System, IP clock and multi-function I/O. */
    SYS_Init();

    /* Init UART0 for printf */
    UART0_Init();
    printf("\n\n\n");
    printf("\nAPROM AP1 START, Boot Address = 0x0 \n");

    do
    {
        printf("+----------------------------------------+\n");
        printf("|               Select                   |\n");
        printf("+----------------------------------------+\n");
        printf("| [0] Run LDROM program(Address=0x100000) \n");
        printf("| [1] Run APROM2 program(Address=0x4000)  \n");
        printf("+----------------------------------------+\n");
        printf("Please select...\n");

        u8Item = getchar();

        switch (u8Item)
        {
            case '0':
                SYS_UnlockReg();
                /* Enable FMC ISP function */
                FMC_Open();
                /*Disable all interrupts*/
                NVIC->ICER[0] = 0xFFFFFFFF;

                FMC_SetVectorPageAddr(LD_BASE_ADDRESS);
                /* Reset CPU only to reset to new vector page */
                // SYS_ResetCPU();
                /* Reset System to reset to new vector page. */
                NVIC_SystemReset();
                break;

            case '1':
                SYS_UnlockReg();
                /* Enable FMC ISP function */
                FMC_Open();
                /*Disable all interrupts*/
                NVIC->ICER[0] = 0xFFFFFFFF;

                FMC_SetVectorPageAddr(AP2_BASE_ADDRESS);
                /* Reset CPU only to reset to new vector page */
                // SYS_ResetCPU();
                /* Reset System to reset to new vector page. */
                NVIC_SystemReset();
                break;
        }
    } while (1);
}

/*** (C) COPYRIGHT 2021 Nuvoton Technology Corp. ***/

使用特权

评论回复
東南博士|  楼主 | 2021-7-31 11:42 | 显示全部楼层
APP2源码:

/**************************************************************************//**
* @file     main.c
* @version  V1.00
* @brief    AP1 Base address is 0, AP2 Base address is 0x4000
*           LD Base address is 0x100000
*                   Multiple app jump to each other
* SPDX-License-Identifier: Apache-2.0
* @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
****************************************************************************/
#include <stdio.h>
#include "NuMicro.h"


/*----------------------------------------------------------------------------*/
/* Define                                                                     */
/*----------------------------------------------------------------------------*/
#define AP1_BASE_ADDRESS 0
#define AP2_BASE_ADDRESS 0x4000
#define LD_BASE_ADDRESS 0x100000

/*----------------------------------------------------------------------------*/
/* Global variable                                                            */
/*----------------------------------------------------------------------------*/



/*----------------------------------------------------------------------------*/
/* Functions                                                                  */
/*----------------------------------------------------------------------------*/

void SYS_Init(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Enable HIRC */
    CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

    /* Waiting for HIRC clock ready */
    CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

    /* Switch HCLK clock source to HIRC */
    CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

    /* Set both PCLK0 and PCLK1 as HCLK/2 */
    CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);

    /* Switch UART0 clock source to HIRC */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HIRC, CLK_CLKDIV0_UART0(1));

    /* Enable UART peripheral clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    SystemCoreClockUpdate();

    /*----------------------------------------------------------------------*/
    /* Init I/O Multi-function                                              */
    /*----------------------------------------------------------------------*/
    /* Set GPB multi-function pins for UART0 RXD and TXD */
    SYS->GPB_MFPH = (SYS->GPB_MFPH & ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk)) |
                    (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD);

    /* Lock protected registers */
    SYS_LockReg();
}

/*----------------------------------------------------------------------*/
/* Init UART0                                                           */
/*----------------------------------------------------------------------*/
void UART0_Init(void)
{
    /* Reset UART0 */
    SYS_ResetModule(UART0_RST);

    /* Configure UART0 and set UART0 baud rate */
    UART_Open(UART0, 115200);
}

int main(void)
{
    uint8_t u8Item;

    /* Init System, IP clock and multi-function I/O. */
    SYS_Init();
    /* Init UART0 for printf */
    UART0_Init();
    printf("\n\n\n");
    printf("\nAPROM AP2 START, Boot Address = 0x4000 \n");

    do
    {
        printf("+----------------------------------------+\n");
        printf("|               Select                   |\n");
        printf("+----------------------------------------+\n");
        printf("| [0] Run LDROM program(Address=0x100000) \n");
        printf("| [1] Run APROM1 program(Address=0x0)                  \n");
        printf("+----------------------------------------+\n");
        printf("Please select...\n");

        u8Item = getchar();

        switch (u8Item)
        {
            case '0':
                SYS_UnlockReg();
                /* Enable FMC ISP function */
                FMC_Open();
                /*Disable all interrupts*/
                NVIC->ICER[0] = 0xFFFFFFFF;

                FMC_SetVectorPageAddr(LD_BASE_ADDRESS);
                /* Reset CPU only to reset to new vector page */
                // SYS_ResetCPU();
                /* Reset System to reset to new vector page. */
                NVIC_SystemReset();
                break;

            case '1':
                SYS_UnlockReg();
                /* Enable FMC ISP function */
                FMC_Open();
                /*Disable all interrupts*/
                NVIC->ICER[0] = 0xFFFFFFFF;

                FMC_SetVectorPageAddr(AP1_BASE_ADDRESS);
                /* Reset CPU only to reset to new vector page */
                // SYS_ResetCPU();
                /* Reset System to reset to new vector page. */
                NVIC_SystemReset();
                break;
        }
    } while (1);
}

/*** (C) COPYRIGHT 2021 Nuvoton Technology Corp. ***/

使用特权

评论回复
god9987| | 2021-7-31 21:29 | 显示全部楼层
多个APP 这个有不同APP更新的IAP吗?

使用特权

评论回复
god9987| | 2021-7-31 21:30 | 显示全部楼层
如果可以的话,能不能使用GPRS或者无线进行更新?最好是2G的联网模块!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

367

主题

6048

帖子

34

粉丝