[技术问答] 新唐M480系列IAP升级(例程)

[复制链接]
7428|17
 楼主| wululu 发表于 2018-9-13 16:02 | 显示全部楼层 |阅读模式
有人可以提供一下吗

评论

@wululu :微信:867851229  发表于 2018-9-13 16:06
想拜个师傅,有人收徒弟吗  发表于 2018-9-13 16:06
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后程序代码可执行区域的范例)
0000002-3.jpg

643757107 发表于 2018-9-14 16:34 | 显示全部楼层
382105b9b72990d67f.png
下载BSP去,有例子。
 楼主| wululu 发表于 2018-9-14 18:02 | 显示全部楼层
zhuotuzi 发表于 2018-9-13 19:09
你们公司没有师傅吗

我刚刚毕业,没有师傅
 楼主| wululu 发表于 2018-9-14 18:05 | 显示全部楼层
643757107 发表于 2018-9-14 16:34
下载BSP去,有例子。

我看了这个历程,就是等待串口的FIFO清空哪里不是很理解,为什么要等待。  感觉新唐的例程没有个README,有时候看半天都挺蒙蔽的,也可能是自己刚毕业。
 楼主| wululu 发表于 2018-9-14 18:05 | 显示全部楼层
wululu 发表于 2018-9-14 18:02
我刚刚毕业,没有师傅

您缺徒弟吗
jiekou001 发表于 2018-9-16 17:48 | 显示全部楼层
下载BSP了吗,里面自带。
玛尼玛尼哄 发表于 2018-9-16 20:44 | 显示全部楼层
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  2.0.0
  4. * [url=home.php?mod=space&uid=247401]@brief[/url]    Use MKROM API to do internal ISP. This sample code is run at APROM,
  5. *           this sample will load an image to LDROM, and than doing Secure boot
  6. *           ISP to update APROM. After finish firmware update, remember to reset
  7. *           the system.
  8. *           The LDROM sample code is Secure boot ISP function.
  9. *
  10. * [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2017 Nuvoton Technology Corp. All rights reserved.
  11. ******************************************************************************/
  12. #include <stdio.h>
  13. #include "NuMicro.h"

  14. typedef void (FUNC_PTR)(void);

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


  16. void SYS_Init(void)
  17. {
  18.     /* Unlock protected registers */
  19.     SYS_UnlockReg();

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

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

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

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

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

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

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

  34.     /* Enable IP clock */
  35.     CLK_EnableModuleClock(UART0_MODULE);

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

  39. }


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

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

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

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


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

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

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

  77.     /*
  78.      * program the whole image to specified flash area
  79.      */
  80.     pu32Loader = (uint32_t *)image_base;
  81.     for (i = 0; i < u32ImageSize; i += FMC_FLASH_PAGE_SIZE)
  82.     {

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

  90.     /* Verify loader */
  91.     for (i = 0; i < u32ImageSize; i += FMC_FLASH_PAGE_SIZE)
  92.     {
  93.         for (j = 0; j < FMC_FLASH_PAGE_SIZE; j += 4)
  94.         {
  95.             u32Data = FMC_Read(flash_addr + i + j);        /* read a word from flash memory */

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

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


  108. int32_t main (void)
  109. {
  110.     FUNC_PTR    *func;                 /* function pointer */

  111.     SYS_Init();
  112.     UART_Open(UART0, 115200);

  113.     printf("\n");
  114.     printf("+-----------------------------------------+\n");
  115.     printf("|      M480 update firmware by HSUSBD     |\n");
  116.     printf("+-----------------------------------------+\n");

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

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

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

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

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

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

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

  162.     while(1);
  163. }



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

玛尼玛尼哄 发表于 2018-9-16 20:44 | 显示全部楼层
USB口的,去下载BSP,还提供很多串口升级的,U盘升级的。
 楼主| wululu 发表于 2018-9-17 09:37 | 显示全部楼层
玛尼玛尼哄 发表于 2018-9-16 20:44
USB口的,去下载BSP,还提供很多串口升级的,U盘升级的。

好的 谢谢
 楼主| wululu 发表于 2018-9-17 10:27 | 显示全部楼层

这个更新的方式是通过HSUSBD怎么设置或者引导的
wanduzi 发表于 2018-9-18 22:42 | 显示全部楼层
具体怎么选择引导方式应该手册里给的有一个说明。比如用不用跳线。
wanduzi 发表于 2018-9-18 22:43 | 显示全部楼层
IAP boot mode
看看手册有没有这几个关键词。
13717024871 发表于 2021-8-31 17:49 | 显示全部楼层
有新唐M480系列 FS USB不是HS  IAP升级
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

21

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部