打印
[技术问答]

新唐M480系列IAP升级(例程)

[复制链接]
6322|17
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wululu|  楼主 | 2018-9-13 16:02 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
有人可以提供一下吗
评论
wululu 2018-9-13 16:06 回复TA
@wululu :微信:867851229 
wululu 2018-9-13 16:06 回复TA
想拜个师傅,有人收徒弟吗 
沙发
zhuotuzi| | 2018-9-13 19:09 | 只看该作者
你们公司没有师傅吗

使用特权

评论回复
板凳
heisexingqisi| | 2018-9-13 23:35 | 只看该作者
去官网看看最新的IAP软件包有没有这个芯片,增芯片刚出的,以前是没。

使用特权

评论回复
地板
643757107| | 2018-9-14 16:29 | 只看该作者
AP是指「在应用上程序设计」,是一个提供使用者切换在APROM或LDROM执行程序代码而不需重置的功能,用户可以设置IAP功能藉由重启芯片,并设置于CBS (CONFIG0[7:6])芯片启动选择位为2或0。当芯片启动带有IAP功能时,任何其他可执行区域页的代码可于任意时刻被映射至第一页(0x0000_0000~0x0000_01FF),用户可藉由ISPADR寄存器填入目标芯片重新映像地址来更改第一个可执行区域页地址,再执行向量页重新映像(Vector Page Re-map)指令。变更重新映像地址后,用户可藉由读取VECMAP(ISPSTA[20:9])来检查是否变更成功。
(下图为M05xDN/DE series 设置IAP后程序代码可执行区域的范例)

使用特权

评论回复
5
643757107| | 2018-9-14 16:34 | 只看该作者

下载BSP去,有例子。

使用特权

评论回复
6
wululu|  楼主 | 2018-9-14 18:02 | 只看该作者
zhuotuzi 发表于 2018-9-13 19:09
你们公司没有师傅吗

我刚刚毕业,没有师傅

使用特权

评论回复
7
wululu|  楼主 | 2018-9-14 18:05 | 只看该作者
643757107 发表于 2018-9-14 16:34
下载BSP去,有例子。

我看了这个历程,就是等待串口的FIFO清空哪里不是很理解,为什么要等待。  感觉新唐的例程没有个README,有时候看半天都挺蒙蔽的,也可能是自己刚毕业。

使用特权

评论回复
8
wululu|  楼主 | 2018-9-14 18:05 | 只看该作者
wululu 发表于 2018-9-14 18:02
我刚刚毕业,没有师傅

您缺徒弟吗

使用特权

评论回复
9
jiekou001| | 2018-9-16 17:48 | 只看该作者
下载BSP了吗,里面自带。

使用特权

评论回复
10
玛尼玛尼哄| | 2018-9-16 20:44 | 只看该作者
/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url]     main.c
* [url=home.php?mod=space&uid=895143]@version[/url]  2.0.0
* [url=home.php?mod=space&uid=247401]@brief[/url]    Use MKROM API to do internal ISP. This sample code is run at APROM,
*           this sample will load an image to LDROM, and than doing Secure boot
*           ISP to update APROM. After finish firmware update, remember to reset
*           the system.
*           The LDROM sample code is Secure boot ISP function.
*
* [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2017 Nuvoton Technology Corp. All rights reserved.
******************************************************************************/
#include <stdio.h>
#include "NuMicro.h"

typedef void (FUNC_PTR)(void);

extern uint32_t  loaderImage1Base, loaderImage1Limit;   /* symbol of image start and end */


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

    /* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */
    PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);

    /* Enable External XTAL (4~24 MHz) */
    CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);

    /* Waiting for 12MHz clock ready */
    CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);

    /* Switch HCLK clock source to HXT */
    CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HXT,CLK_CLKDIV0_HCLK(1));

    /* Set core clock as PLL_CLOCK from PLL */
    CLK_SetCoreClock(FREQ_192MHZ);

    /* Set both PCLK0 and PCLK1 as HCLK/2 */
    CLK->PCLKDIV = CLK_PCLKDIV_PCLK0DIV2 | CLK_PCLKDIV_PCLK1DIV2;

    /* Select IP clock source */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HXT, CLK_CLKDIV0_UART0(1));

    /* Enable IP clock */
    CLK_EnableModuleClock(UART0_MODULE);

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

}


/**
  * @brief    Check User Configuration CONFIG0 bit 6 IAP boot setting. If it's not boot with IAP
  *           mode, modify it and execute a chip reset to make it take effect.
  * [url=home.php?mod=space&uid=266161]@return[/url]   Is boot with IAP mode or not.
  * @retval   0   Success.
  * @retval   -1  Failed on reading or programming User Configuration.
  */
static int  set_IAP_boot_mode(void)
{
    uint32_t  au32Config[2];           /* User Configuration */

    if (FMC_ReadConfig(au32Config, 2) < 0)       /* Read User Configuration CONFIG0 and CONFIG1. */
    {
        printf("\nRead User Config failed!\n");
        return -1;                     /* Failed on reading User Configuration */
    }

    if (au32Config[0] & 0x40)          /* Check if it's boot from APROM/LDROM with IAP. */
    {
        FMC_ENABLE_CFG_UPDATE();       /* Enable User Configuration update. */
        au32Config[0] &= ~0x40;        /* Select IAP boot mode. */
        FMC_WriteConfig(au32Config, 2);/* Update User Configuration CONFIG0 and CONFIG1. */

        SYS->IPRST0 = SYS_IPRST0_CHIPRST_Msk;    /* Perform chip reset to make new User Config take effect. */
    }
    return 0;                          /* success */
}


/**
  * @brief    Load an image to specified flash address. The flash area must have been enabled by
  *           caller. For example, if caller want to program an image to LDROM, FMC_ENABLE_LD_UPDATE()
  *           must be called prior to calling this function.
  * @return   Image is successfully programmed or not.
  * @retval   0   Success.
  * @retval   -1  Program/verify failed.
  */
static int  load_image_to_flash(uint32_t image_base, uint32_t image_limit, uint32_t flash_addr, uint32_t max_size)
{
    uint32_t   i, j, u32Data, u32ImageSize, *pu32Loader;

    u32ImageSize = max_size;           /* Give the maximum size of programmable flash area. */

    printf("Program image to flash address 0x%x...", flash_addr);    /* information message */

    /*
     * program the whole image to specified flash area
     */
    pu32Loader = (uint32_t *)image_base;
    for (i = 0; i < u32ImageSize; i += FMC_FLASH_PAGE_SIZE)
    {

        FMC_Erase(flash_addr + i);     /* erase a flash page */
        for (j = 0; j < FMC_FLASH_PAGE_SIZE; j += 4)                 /* program image to this flash page */
        {
            FMC_Write(flash_addr + i + j, pu32Loader[(i + j) / 4]);
        }
    }
    printf("OK.\nVerify ...");

    /* Verify loader */
    for (i = 0; i < u32ImageSize; i += FMC_FLASH_PAGE_SIZE)
    {
        for (j = 0; j < FMC_FLASH_PAGE_SIZE; j += 4)
        {
            u32Data = FMC_Read(flash_addr + i + j);        /* read a word from flash memory */

            if (u32Data != pu32Loader[(i+j)/4])            /* check if the word read from flash be matched with original image */
            {
                printf("data mismatch on 0x%x, [0x%x], [0x%x]\n", flash_addr + i + j, u32Data, pu32Loader[(i+j)/4]);
                return -1;             /* image program failed */
            }

            if (i + j >= u32ImageSize) /* check if it reach the end of image */
                break;
        }
    }
    printf("OK.\n");
    return 0;                          /* success */
}


int32_t main (void)
{
    FUNC_PTR    *func;                 /* function pointer */

    SYS_Init();
    UART_Open(UART0, 115200);

    printf("\n");
    printf("+-----------------------------------------+\n");
    printf("|      M480 update firmware by HSUSBD     |\n");
    printf("+-----------------------------------------+\n");

    SYS_UnlockReg();                   /* Unlock register lock protect */
    FMC_Open();                        /* Enable FMC ISP function */

    /*
     *  Check if User Configuration CBS is boot with IAP mode.
     *  If not, modify it.
     */
    if (set_IAP_boot_mode() < 0)
    {
        printf("Failed to set IAP boot mode!\n");
        FMC_Close();                       /* Disable FMC ISP function */
        while(1);
    }

    FMC_ENABLE_LD_UPDATE();    /* Enable LDROM update capability */
    /*
     *  The binary image of LDROM code is embedded in this sample.
     *  load_image_to_flash() will program this LDROM code to LDROM.
     */
    if (load_image_to_flash((uint32_t)&loaderImage1Base, (uint32_t)&loaderImage1Limit, FMC_LDROM_BASE, FMC_LDROM_SIZE) != 0)
    {
        printf("Load image to LDROM failed!\n");
        FMC_Close();                       /* Disable FMC ISP function */
        while(1);
    }
    FMC_DISABLE_LD_UPDATE();   /* Disable LDROM update capability */

    printf("\n\nChange VECMAP and branch to LDROM...\n");
    printf("\nAfter update the firmware, please press the reset button...\n");
    while (!(UART0->FIFOSTS & UART_FIFOSTS_TXEMPTY_Msk));      /* Wait for UART3 TX FIFO cleared */

    /*  NOTE!
     *     Before change VECMAP, user MUST disable all interrupts.
     *     The following code CANNOT locate in address 0x0 ~ 0x200.
     */

    /* FMC_SetVectorPageAddr(FMC_LDROM_BASE) */
    FMC->ISPCMD = FMC_ISPCMD_VECMAP;              /* ISP command */
    FMC->ISPADDR = FMC_LDROM_BASE;                /* Vector remap address */
    FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;           /* Trigger ISP command */
    while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;  /* Wait for ISP command done. */

    /*
     *  The reset handler address of an executable image is located at offset 0x4.
     *  Thus, this sample get reset handler address of LDROM code from FMC_LDROM_BASE + 0x4.
     */
    func = (FUNC_PTR *)*(uint32_t *)(FMC_LDROM_BASE + 4);
    /*
     *  Branch to the LDROM code's reset handler in way of function call.
     */
    func();

    while(1);
}



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

使用特权

评论回复
11
玛尼玛尼哄| | 2018-9-16 20:44 | 只看该作者
USB口的,去下载BSP,还提供很多串口升级的,U盘升级的。

使用特权

评论回复
12
wululu|  楼主 | 2018-9-17 09:37 | 只看该作者
玛尼玛尼哄 发表于 2018-9-16 20:44
USB口的,去下载BSP,还提供很多串口升级的,U盘升级的。

好的 谢谢

使用特权

评论回复
13
wululu|  楼主 | 2018-9-17 10:27 | 只看该作者

这个更新的方式是通过HSUSBD怎么设置或者引导的

使用特权

评论回复
14
wanduzi| | 2018-9-18 22:42 | 只看该作者
具体怎么选择引导方式应该手册里给的有一个说明。比如用不用跳线。

使用特权

评论回复
15
wanduzi| | 2018-9-18 22:43 | 只看该作者
IAP boot mode
看看手册有没有这几个关键词。

使用特权

评论回复
16
13717024871| | 2021-8-31 17:49 | 只看该作者
有新唐M480系列 FS USB不是HS  IAP升级

使用特权

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

本版积分规则

4

主题

21

帖子

0

粉丝