9G-CM0 新唐CM0+EWARM入门开发过程简介

一,准备EWARM + 新唐CM0软件包

1,在https://www.mcu123.net/bbs/viewthread.php?tid=16064&highlight=CD-EWARM-5501-1908
 下载 IAR Embedded Workbench for ARM version 5.50 软件
 CD-EWARM-5501-1908_mcu123.zip
    ftp://mcu123:mcu123@mcu123.com/已整理目录/开发工具软件/ARM/CD-EWARM-5501-1908_mcu123.zip
    相关文件“IAR_EWARM5.4和谐文件.rar ”可以在GOOGLE上搜索到
    https://bbs.mcu123.net/bbs/thread-15164-1-1.html
    并下载:
    IAR_EWARM5[1].4和谐文件.rar   

2,在https://www.nuvoton.com/NuvotonMOSS/Community/ProductInfo.aspx?tp_GUID=403a9c50-52c2-4463-9057-2595190602c5
 下载 “NuMicro IAR Embedded Workbench? driver (Build 4033) V1.02.zip”
 NuMicro IAR Embedded Workbench driver  (Build 4033) V1.02.zip
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Documents/NuMicro%20IAR%20Embedded%20Workbench%20driver%20%20(Build%204033)%20V1.02.zip
     
 下载“NUC1xx Nu-Tiny-EVB_001 Board Schemetic v1.0.pdf”文档
 NUC1xxNuTinyEVB_001BoardSchemeticv10.pdf
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Documents/NUC1xxNuTinyEVB_001BoardSchemeticv10.pdf

 下载“NUC1xx Nu-Tiny-EVB and Nu-Link-Me Board user manual EN  v1.0.pdf”文档
 NUC1xxNuTinyEVBandNuLinkMeBoardusermanualENv10.pdf
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Documents/NUC1xxNuTinyEVBandNuLinkMeBoardusermanualENv10.pdf

 下载“NUC1xx Nu-Link-Me_001 Board Schematic v1.0.pdf”文档
 NUC1xxNuLinkMe_001BoardSchematicv10.pdf
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Documents/NUC1xxNuLinkMe_001BoardSchematicv10.pdf

3,在https://www.nuvoton.com/NuvotonMOSS/Community/ProductInfo.aspx?tp_GUID=7052964b-b71b-46b7-91b2-221afeddd575
 上下载 “NUC1xxBSP_v1.1.2.zip”
 NUC1xxBSP_v1.1.2.zip
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Documents/NUC1xxBSP_v1.1.2.zip

4,新唐官方资料网址
 新唐CM0官方资料主页
 https://www.nuvoton.com/hq/chs/Pages/default.aspx
 新唐CM0主页资料入口
 ARM单片机 -> ARM Cortex?-M0 单片机 NuMicro? 家族
 新唐CM0主页资料网址
 https://www.nuvoton.com/NuvotonMOSS/Community/ProductInfo.aspx?tp_GUID=5cc43799-121d-42c9-9ac0-3b4a6cbdb7c3
 新唐CM0在线选型工具
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Pages/SelectGuide.aspx
 新唐CM0在线培训教程
 https://www.nuvoton.com/hq/enu/ProductAndSales/ProductLines/IndustrialIC/ARMMicrocontroller/ARMCortexTMM0/Pages/onlineEtraining.aspx

5,在https://www.segger.com/cms/jlink-software.html
    下载Software and documentation pack V4.14g软件
 Setup_JLinkARM_V414g.zip
 https://www.segger.com/cms/admin/uploads/userfiles/file/J-Link/Setup_JLinkARM_V414g.zip
   
二,建立CM0的EWARM+Nu-LINK开发环境

1,双击“IAR_EWARM5[1].4和谐文件.rar”,运行里面的“EWARM_FULL_ARM540.exe”,选择“Product”中的“Embedded Workbench For ARM v5.40”,然后点击“Generate”
 把产生的“License key”“License number”密码和序列号记录下来;

2,双击“CD-EWARM-5501-1908_mcu123.zip”运行里面的“autorun.exe”,在“Welcome to IAR Systems”中选择“Install IAR Embedded Workbench”,按常规的软件安装方式
 把“IAR Embedded Workbench For ARM”安装到电脑上;

3,双击“NuMicro IAR Embedded Workbench driver  (Build 4033) V1.02.zip”运行里面的“Nu-Link_IAR_Driver 1.02.exe”,便会在“C:\Program Files\Nuvoton Tools\Nu-Link_IAR”
 目录中安装上相关的“Nu-LINK”的驱动。

4,双击“Setup_JLinkARM_V414g.zip”运行里面的“Setup_JLinkARM_V414g.exe”,便会在“C:\Program Files\SEGGER\JLinkARM_V414g”
 目录中安装上相关的“J-LINK”的驱动。

三,建立CM0的EWARM基本工程

1,在电脑开始菜单中打开“IAR Embedded Workbench IDE”,在“EWARM”的IDE菜单中选择“Project”->“Create New Project”创建一个新工程,在“Create New Project”选择“OK”存储目录
 到D:\works\9G-CM0\nuc140\project\iar下面,工程名叫“nuc140.ewp”,点击“OK”完成,点击“File”下的“Save Workspace”保存工作空间到目录中的“nuc140.eww”;

2,在“D:\works\9G-CM0\nuc140”下建立文件夹“include”,“driver”,“library”,“source”,等子目录,在“D:\works\9G-CM0\nuc140\project\iar下建立子目录“config”,并把
 “NUC1xxBSP_v1.1.2.zip”解压到“D:\works\9G-CM0\nuc140\library”目录;

3,在“EWARM”的IDE菜单中选择“Project”->“Options”中的“General Options”的“Target”中的“Device”中选择“Nuvoton NUC140xE”,在“Linker”菜单中选择“Linker configuration file”里选择
 “override default”并填上“$PROJ_DIR$\config\NUC140_Flash.icf”;

4,在“Options for node 'nuc140'”的“Category:”中选择上“Debugger”,在“Setup”->“Driver”中选择“Third-Party Driver”,然后在“Third-Party Driver”选择驱动到
 “C:\Program Files\Nuvoton Tools\Nu-Link_IAR\Nu-Link_IAR.dll”;

5,在“Debugger”的“Download”勾选择“Use flash loader”和“override default .board file”并填入“$TOOLKIT_DIR$\config\flashloader\Nuvoton\FlashNUC1xxxE.board”,把
 “D:\works\9G-CM0\nuc140\library\NUC1xxBSP\NuvotonPlatform_IAR\Sample\Driver\Smpl_DrvGPIO”下的“Smpl_DrvGPIO.icf”复制到“D:\works\9G-CM0\nuc140\project\iar\config”
 并改名为“NUC140_Flash.icf”;
 
6,在“IAR Embedded Workbench IDE”的“Workspace”下的“Files”中右击选择“Add”->“Add Group”并填入“BOOT”,另外同样建立“DRV”,“SRC”,“INC”“LIB”等目录,然后在“BOOT”上右击
 选择“Add”->“Add Files” 然后选择“D:\works\9G-CM0\nuc140\library\NUC1xxBSP\CMSIS\CM0\startup\iar”下的“ startup_NUCxxx_iar.s”;
 
7,在“D:\works\9G-CM0\nuc140\source”中建立“main.c”,然后添加到工程的“SRC”中,并在“main.c”中填入下面内容:
  #include <Nuvoton\ionuc140.h>

  void SystemInit(void){}
  
  void GPIO_Init(void){ GPIOC_PMD = 0x55555555;GPIOA_PMD = 0x55555555;}     /* LEDs on PORT C defined as Output   */
  
  int main(void)
  {
   int i;
    
   GPIO_Init();
   while(1)
   {
    for(i=0;i<3000000;i++);  
          GPIOC_DOUT &= 0x00000000; /* switch on LEDs                    */
    GPIOA_DOUT &= 0x00000000;
    for(i=0;i<3000000;i++);  
          GPIOC_DOUT |= 0xFFFFFFFF; /* switch off LEDs                    */
    GPIOA_DOUT |= 0xFFFFFFFF;
   }
  }
  
8,在“Debugger”的“Download”勾选择“Use flash loader”和“override default .board file”并填入“$TOOLKIT_DIR$\config\flashloader\Nuvoton\LDROMNUC1xx.board”,可以把
 相应的程序烧进LDROM区;

9,在“EWARM”的IDE菜单中选择“Nu-Link”->“ICP Programming Tool”中,可以不擦除整片FLASH改变配置位从APPROM区切换到LDROM区,
 FLASH的1能修改成0;

四,调试CM0的EWARM基本工程

1,在“EWARM”的IDE菜单中选择“Project”->“Options”中“Category:”中选择上“Debugger”,在“Setup”->“Driver”中选择“J-Link/J-Trace”;

2,在“Debugger”的“Download”勾选择“Use flash loader”和“override default .board file”并填入“$TOOLKIT_DIR$\config\flashloader\Nuvoton\LDROMNUC1xx.board”,可以把
 相应的程序烧进LDROM区;

(待续)