Try   HackMD

Developing with 新唐科技(Nuvoton)'s ARM Cortex-M Development Board

tags: Nuvoton, NUC472, Cortex-M4, MCU, arm-none-eabi-gcc

Development Environment

Developing with NuTiny-SDK-NUC472

Use the NUC472-NuTiny's LED Sample as the Example

$ git clone https://github.com/OpenNuvoton/NUC472_442BSP $ cd NUC472_442BSP/SampleCode/NUC472-NuTiny/LED/
  1. Add the Makefile into the LED sample code directory.
    ​​​[LED]$ ls -l ​​​total 20 ​​​drwxr-xr-x 2 zack zack 4096 Oct 22 14:32 GCC ​​​drwxr-xr-x 2 zack zack 4096 Oct 22 14:32 IAR ​​​drwxr-xr-x 2 zack zack 4096 Oct 22 14:32 KEIL ​​​-rw-r--r-- 1 zack zack 3420 Oct 22 14:32 main.c ​​​-rw-r--r-- 1 zack zack 3090 Oct 22 15:05 Makefile
    PS. If it is downstream Nuvoton OpenOCD, the TARGETCHIP in the Makefile should be set as "target/numicroM4.cfg".
  2. Build the LED application with make:
    ​​​[LED]$ make ​​​arm-none-eabi-gcc -I../../../../NUC472_442BSP/Library/CMSIS/Include -I../../../../NUC472_442BSP/Library/StdDriver/inc -I../../../../NUC472_442BSP/Library/Device/Nuvoton/NUC472_442/Include -I. -ggdb -Os -Wall -Wextra -Warray-bounds -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T../../../../NUC472_442BSP/Library/Device/Nuvoton/NUC472_442/Source/GCC/gcc_arm.ld main.c ../../../../NUC472_442BSP/Library/StdDriver/src/clk.c ../../../../NUC472_442BSP/Library/StdDriver/src/gpio.c ../../../../NUC472_442BSP/Library/StdDriver/src/sys.c ../../../../NUC472_442BSP/Library/Device/Nuvoton/NUC472_442/Source/system_NUC472_442.c ../../../../NUC472_442BSP/Library/Device/Nuvoton/NUC472_442/Source/GCC/startup_NUC472_442.S -o LED.elf ​​​... ​​​arm-none-eabi-objcopy -O ihex LED.elf LED.hex ​​​arm-none-eabi-objcopy -O binary LED.elf LED.bin
  3. Connect the NuTiny-SDK-NUC472 to your host via the USB cable.
  4. Flash the built image into NuTiny-SDK-NUC472 with make flash:
    ​​​$ make flash
    ​​​openocd -f "interface/nulink.cfg" -f "target/numicro_m4.cfg" \
    ​        -c "program LED.elf verify reset exit"
    ​​​Open On-Chip Debugger 0.12.0-rc2+dev-00007-gdc1e6d4d4 (2022-11-13-14:48)
    ​​​Licensed under GNU GPL v2
    ​​​For bug reports, read
    ​        http://openocd.org/doc/doxygen/bugs.html
    ​​​hla_swd
    ​​​Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    ​​​Info : clock speed 1000 kHz
    ​​​Info : Nu-Link firmware_version 6535, product_id (0x00012009)
    ​​​Info : Adapter is Nu-Link
    ​​​Info : IDCODE: 0x2BA01477
    ​​​Info : [NuMicro.cpu] Cortex-M4 r0p1 processor detected
    ​​​Info : [NuMicro.cpu] target has 6 breakpoints, 4 watchpoints
    ​​​Info : starting gdb server for NuMicro.cpu on 3333
    ​​​Info : Listening on port 3333 for gdb connections
    ​​​[NuMicro.cpu] halted due to breakpoint, current mode: Thread 
    ​​​xPSR: 0x01000000 pc: 0x00000f5c msp: 0x20010000
    ​​​[NuMicro.cpu] halted due to debug-request, current mode: Thread 
    ​​​xPSR: 0x01000000 pc: 0x00000f5c msp: 0x20010000
    ​​​** Programming Started **
    ​​​Info : Device ID: 0x00047201
    ​​​Info : Device Name: NUC472HI8AE
    ​​​Info : bank base = 0x00000000, size = 0x00080000
    ​​​Warn : Adding extra erase range, 0x00001770 .. 0x000017ff
    ​​​Info : Nuvoton NuMicro: Sector Erase ... (0 to 2)
    ​​​Info : Nuvoton NuMicro: Flash Write ...
    ​​​** Programming Finished **
    ​​​** Verify Started **
    ​​​** Verified OK **
    ​​​** Resetting Target **
    ​​​shutdown command invoked
    
  5. After flash, the onboard LED should become blinking.

CMSIS, Standard and Device Libraries for the Makefile

NUC472/442 BSP provides the libraries:

Debugging

Debug with GDB via OpenOCD and Nu-Link.

  1. Start the gdb server with Nu-Link and the numicro M4 configs:
    ​​​$ openocd -f "interface/nulink.cfg" -f "target/numicro_m4.cfg"
    ​​​Open On-Chip Debugger 0.12.0-rc2+dev-00007-gdc1e6d4d4 (2022-11-13-14:48)
    ​​​Licensed under GNU GPL v2
    ​​​For bug reports, read
    ​        http://openocd.org/doc/doxygen/bugs.html
    ​​​hla_swd
    ​​​Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    ​​​Info : Listening on port 6666 for tcl connections
    ​​​Info : Listening on port 4444 for telnet connections
    ​​​Info : clock speed 1000 kHz
    ​​​Info : Nu-Link firmware_version 6535, product_id (0x00012009)
    ​​​Info : Adapter is Nu-Link
    ​​​Info : IDCODE: 0x2BA01477
    ​​​Info : [NuMicro.cpu] Cortex-M4 r0p1 processor detected
    ​​​Info : [NuMicro.cpu] target has 6 breakpoints, 4 watchpoints
    ​​​Info : starting gdb server for NuMicro.cpu on 3333
    ​​​Info : Listening on port 3333 for gdb connections
    ​​​[NuMicro.cpu] halted due to breakpoint, current mode: Thread 
    ​​​xPSR: 0x01000000 pc: 0x00000f5c msp: 0x20010000
    
    It shows that the gdb server is listening on port 3333.
  2. Have the gdb client connecting to the gdb server to debug the LED.elf flashed on the MCU chip Nuvoton NUC472HI8AE:
    ​​​$ arm-none-eabi-gdb LED.elf ​​​GNU gdb (GDB) 12.1 ​​​... ​​​Reading symbols from LED.elf... ​​​(gdb) target remote localhost:3333 ​​​Remote debugging using localhost:3333 ​​​warning: Overlapping regions in memory map: ignoring ​​​Reset_Handler () at ../../../../NUC472_442BSP/Library/Device/Nuvoton/NUC472_442/Source/GCC/startup_NUC472_442.S:268 ​​​268 ldr r1, =__etext ​​​(gdb) hbreak main.c:86 ​​​Hardware assisted breakpoint 1 at 0x3a2: file main.c, line 86. ​​​(gdb) continue ​​​Continuing. ​​​Breakpoint 1, main () at main.c:86 ​​​86 PB10 = 0; ​​​(gdb) list ​​​81 /* Configure PB.10 as Output mode */ ​​​82 GPIO_SetMode(PB, BIT10, GPIO_MODE_OUTPUT); ​​​83 ​​​84 while(1) ​​​85 { ​​​86 PB10 = 0; ​​​87 CLK_SysTickDelay(500000); ​​​88 PB10 = 1; ​​​89 CLK_SysTickDelay(500000); ​​​90 } ​​​(gdb) hbreak 88 ​​​Hardware assisted breakpoint 2 at 0x3ae: file main.c, line 88. ​​​(gdb) continue ​​​Continuing. ​​​halted: PC: 0x000003a4 ​​​Breakpoint 2, main () at main.c:88 ​​​88 PB10 = 1; ​​​(gdb) continue ​​​Continuing. ​​​halted: PC: 0x000003b0 ​​​Breakpoint 1, main () at main.c:86 ​​​86 PB10 = 0; ​​​(gdb) continue ​​​Continuing. ​​​halted: PC: 0x000003a4 ​​​Breakpoint 2, main () at main.c:88 ​​​88 PB10 = 1; ​​​(gdb)
    Use hbreak (hardware-assisted breakpoint) to add a break point, instead of break.
    Reference: 5.1.1 Setting Breakpoints

Reference