4. SDK Directory Structure

This chapter describes each directory and file according to the real file tree of Nsing.N32H49x_Library.1.2.0. All paths are relative to the SDK root.

4.1 Top-Level Structure

  • ๐Ÿ“ Entries ending with / are directories
  • ๐Ÿ“„ All other entries are files
Nsing.N32H49x_Library.1.2.0/
โ”œโ”€โ”€ .vscode/
โ”‚   โ”œโ”€โ”€ launch.json
โ”‚   โ”œโ”€โ”€ settings.json
โ”‚   โ””โ”€โ”€ tasks.json
โ”œโ”€โ”€ firmware/
โ”‚   โ”œโ”€โ”€ CMSIS/
โ”‚   โ”œโ”€โ”€ n32h49x_algo_lib/
โ”‚   โ”œโ”€โ”€ n32h49x_std_periph_driver/
โ”‚   โ”œโ”€โ”€ n32h49x_usbfsd_driver/
โ”‚   โ””โ”€โ”€ n32h49x_usbhs_driver/
โ”œโ”€โ”€ jlink/
โ”‚   โ””โ”€โ”€ flash.jlink
โ”œโ”€โ”€ middlewares/
โ”‚   โ”œโ”€โ”€ fat_fs/
โ”‚   โ”œโ”€โ”€ FreeRTOSv202212.01/
โ”‚   โ””โ”€โ”€ lwip-2.2.0/
โ”œโ”€โ”€ projects/
โ”‚   โ””โ”€โ”€ n32h49x_EVAL/
โ””โ”€โ”€ N32H49x Version History.txt
Relative path Purpose
firmware/ Firmware library: CMSIS core and device support files, the standard peripheral driver library, the algorithm library, and the USB drivers
projects/n32h49x_EVAL/ Evaluation board project: board support, peripheral examples, and application projects
middlewares/ Middleware sources: the FatFs file system, the FreeRTOS kernel, and the lwIP stack
jlink/flash.jlink J-Link Commander download script, called by the download target of the GCC project
.vscode/ VS Code GDB debug, build task, and editor configuration
N32H49x Version History.txt SDK version record, listing additions and fixes version by version

4.2 Firmware Library

๐Ÿ“ firmware/CMSIS

core/ holds the Arm CMSIS-Core headers, and a Cortex-M4F project uses core_cm4.h and arm_math.h from it;
device/ holds the N32H49x device support files.

CMSIS/
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ arm_common_tables.h
โ”‚   โ”œโ”€โ”€ arm_const_structs.h
โ”‚   โ”œโ”€โ”€ arm_math.h
โ”‚   โ”œโ”€โ”€ cmsis_armcc.h
โ”‚   โ”œโ”€โ”€ cmsis_armclang.h
โ”‚   โ”œโ”€โ”€ cmsis_compiler.h
โ”‚   โ”œโ”€โ”€ cmsis_gcc.h
โ”‚   โ”œโ”€โ”€ cmsis_iccarm.h
โ”‚   โ”œโ”€โ”€ cmsis_version.h
โ”‚   โ”œโ”€โ”€ core_cm4.h
โ”‚   โ””โ”€โ”€ mpu_armv7.h
โ””โ”€โ”€ device/
    โ”œโ”€โ”€ startup/
    โ”‚   โ”œโ”€โ”€ startup_n32h49x.s
    โ”‚   โ”œโ”€โ”€ startup_n32h49x_EWARM.s
    โ”‚   โ””โ”€โ”€ startup_n32h49x_gcc.s
    โ”œโ”€โ”€ n32h49x.h
    โ”œโ”€โ”€ n32h49x_conf.h
    โ”œโ”€โ”€ n32h49x_flash.ld
    โ”œโ”€โ”€ system_n32h49x.c
    โ””โ”€โ”€ system_n32h49x.h
๐Ÿ“ firmware/n32h49x_std_periph_driver

The standard peripheral driver library: inc/ holds the driver headers and src/ holds the same-named implementations, one pair per driver module.

n32h49x_std_periph_driver/
โ”œโ”€โ”€ inc/
โ”‚   โ”œโ”€โ”€ misc.h
โ”‚   โ”œโ”€โ”€ n32h49x_adc.h
โ”‚   โ”œโ”€โ”€ n32h49x_cordic.h
โ”‚   โ”œโ”€โ”€ n32h49x_crc.h
โ”‚   โ”œโ”€โ”€ n32h49x_dac.h
โ”‚   โ”œโ”€โ”€ n32h49x_dbg.h
โ”‚   โ”œโ”€โ”€ n32h49x_dma.h
โ”‚   โ”œโ”€โ”€ n32h49x_dsmu.h
โ”‚   โ”œโ”€โ”€ n32h49x_dvp.h
โ”‚   โ”œโ”€โ”€ n32h49x_eth.h
โ”‚   โ”œโ”€โ”€ n32h49x_exti.h
โ”‚   โ”œโ”€โ”€ n32h49x_fdcan.h
โ”‚   โ”œโ”€โ”€ n32h49x_femc.h
โ”‚   โ”œโ”€โ”€ n32h49x_flash.h
โ”‚   โ”œโ”€โ”€ n32h49x_gpio.h
โ”‚   โ”œโ”€โ”€ n32h49x_i2c.h
โ”‚   โ”œโ”€โ”€ n32h49x_iwdg.h
โ”‚   โ”œโ”€โ”€ n32h49x_lptim.h
โ”‚   โ”œโ”€โ”€ n32h49x_pwr.h
โ”‚   โ”œโ”€โ”€ n32h49x_rcc.h
โ”‚   โ”œโ”€โ”€ n32h49x_rtc.h
โ”‚   โ”œโ”€โ”€ n32h49x_sdio.h
โ”‚   โ”œโ”€โ”€ n32h49x_sdram.h
โ”‚   โ”œโ”€โ”€ n32h49x_spi.h
โ”‚   โ”œโ”€โ”€ n32h49x_tim.h
โ”‚   โ”œโ”€โ”€ n32h49x_usart.h
โ”‚   โ”œโ”€โ”€ n32h49x_vrefbuf.h
โ”‚   โ”œโ”€โ”€ n32h49x_wwdg.h
โ”‚   โ”œโ”€โ”€ n32h49x_xspi.h
โ”‚   โ””โ”€โ”€ n32h49x_xspi_v2.h
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ misc.c
    โ”œโ”€โ”€ n32h49x_adc.c
    โ”œโ”€โ”€ n32h49x_cordic.c
    โ”œโ”€โ”€ n32h49x_crc.c
    โ”œโ”€โ”€ n32h49x_dac.c
    โ”œโ”€โ”€ n32h49x_dbg.c
    โ”œโ”€โ”€ n32h49x_dma.c
    โ”œโ”€โ”€ n32h49x_dsmu.c
    โ”œโ”€โ”€ n32h49x_dvp.c
    โ”œโ”€โ”€ n32h49x_eth.c
    โ”œโ”€โ”€ n32h49x_exti.c
    โ”œโ”€โ”€ n32h49x_fdcan.c
    โ”œโ”€โ”€ n32h49x_femc.c
    โ”œโ”€โ”€ n32h49x_flash.c
    โ”œโ”€โ”€ n32h49x_gpio.c
    โ”œโ”€โ”€ n32h49x_i2c.c
    โ”œโ”€โ”€ n32h49x_iwdg.c
    โ”œโ”€โ”€ n32h49x_lptim.c
    โ”œโ”€โ”€ n32h49x_pwr.c
    โ”œโ”€โ”€ n32h49x_rcc.c
    โ”œโ”€โ”€ n32h49x_rtc.c
    โ”œโ”€โ”€ n32h49x_sdio.c
    โ”œโ”€โ”€ n32h49x_sdram.c
    โ”œโ”€โ”€ n32h49x_spi.c
    โ”œโ”€โ”€ n32h49x_tim.c
    โ”œโ”€โ”€ n32h49x_usart.c
    โ”œโ”€โ”€ n32h49x_vrefbuf.c
    โ”œโ”€โ”€ n32h49x_wwdg.c
    โ”œโ”€โ”€ n32h49x_xspi.c
    โ””โ”€โ”€ n32h49x_xspi_v2.c
๐Ÿ“ firmware/n32h49x_algo_lib

The algorithm library in two sets, Keil and GCC, with the same header names and interfaces and the implementations in .lib and .a respectively.

n32h49x_algo_lib/
โ”œโ”€โ”€ gcc/
โ”‚   โ”œโ”€โ”€ inc/
โ”‚   โ”‚   โ”œโ”€โ”€ n32h49x_aes.h
โ”‚   โ”‚   โ”œโ”€โ”€ n32h49x_algo_common.h
โ”‚   โ”‚   โ”œโ”€โ”€ n32h49x_des.h
โ”‚   โ”‚   โ”œโ”€โ”€ n32h49x_hash.h
โ”‚   โ”‚   โ”œโ”€โ”€ n32h49x_rng.h
โ”‚   โ”‚   โ””โ”€โ”€ n32h49x_sm4.h
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ”œโ”€โ”€ AES.a
โ”‚       โ”œโ”€โ”€ Common.a
โ”‚       โ”œโ”€โ”€ DES.a
โ”‚       โ”œโ”€โ”€ HASH.a
โ”‚       โ”œโ”€โ”€ RNG.a
โ”‚       โ””โ”€โ”€ SM4.a
โ””โ”€โ”€ keil/
    โ”œโ”€โ”€ inc/
    โ”‚   โ”œโ”€โ”€ n32h49x_aes.h
    โ”‚   โ”œโ”€โ”€ n32h49x_algo_common.h
    โ”‚   โ”œโ”€โ”€ n32h49x_des.h
    โ”‚   โ”œโ”€โ”€ n32h49x_hash.h
    โ”‚   โ”œโ”€โ”€ n32h49x_rng.h
    โ”‚   โ””โ”€โ”€ n32h49x_sm4.h
    โ””โ”€โ”€ lib/
        โ”œโ”€โ”€ n32h49x_aes.lib
        โ”œโ”€โ”€ n32h49x_common.lib
        โ”œโ”€โ”€ n32h49x_des.lib
        โ”œโ”€โ”€ n32h49x_hash.lib
        โ”œโ”€โ”€ n32h49x_rng.lib
        โ””โ”€โ”€ n32h49x_sm4.lib
๐Ÿ“ firmware/n32h49x_usbfsd_driver

The full-speed device driver, with nine headers in inc/ and six implementation files in src/.

n32h49x_usbfsd_driver/
โ”œโ”€โ”€ inc/
โ”‚   โ”œโ”€โ”€ usbfsd_core.h
โ”‚   โ”œโ”€โ”€ usbfsd_def.h
โ”‚   โ”œโ”€โ”€ usbfsd_init.h
โ”‚   โ”œโ”€โ”€ usbfsd_int.h
โ”‚   โ”œโ”€โ”€ usbfsd_lib.h
โ”‚   โ”œโ”€โ”€ usbfsd_mem.h
โ”‚   โ”œโ”€โ”€ usbfsd_regs.h
โ”‚   โ”œโ”€โ”€ usbfsd_sil.h
โ”‚   โ””โ”€โ”€ usbfsd_type.h
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ usbfsd_core.c
    โ”œโ”€โ”€ usbfsd_init.c
    โ”œโ”€โ”€ usbfsd_int.c
    โ”œโ”€โ”€ usbfsd_mem.c
    โ”œโ”€โ”€ usbfsd_regs.c
    โ””โ”€โ”€ usbfsd_sil.c
๐Ÿ“ firmware/n32h49x_usbhs_driver

The high-speed host/device driver, organized in three layers: driver/ (controller driver), device/ (device stack and device classes), and host/ (host stack and host classes).

n32h49x_usbhs_driver/
โ”œโ”€โ”€ driver/
โ”‚   โ”œโ”€โ”€ inc/
โ”‚   โ””โ”€โ”€ src/
โ”œโ”€โ”€ device/
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ””โ”€โ”€ class/
โ”‚       โ”œโ”€โ”€ audio/
โ”‚       โ”œโ”€โ”€ cdc/
โ”‚       โ”œโ”€โ”€ customhid/
โ”‚       โ”œโ”€โ”€ hid_cdc_composite/
โ”‚       โ”œโ”€โ”€ hid_keyboard/
โ”‚       โ”œโ”€โ”€ hid_msc_composite/
โ”‚       โ”œโ”€โ”€ mouse/
โ”‚       โ”œโ”€โ”€ msc/
โ”‚       โ””โ”€โ”€ msc_cdc_composite/
โ””โ”€โ”€ host/
    โ”œโ”€โ”€ core/
    โ””โ”€โ”€ class/
        โ”œโ”€โ”€ CDC/
        โ”œโ”€โ”€ HID/
        โ””โ”€โ”€ MSC/
Relative path Purpose
firmware/CMSIS/device/n32h49x.h Device header: peripheral register structures, base addresses, and interrupt numbers
firmware/CMSIS/device/system_n32h49x.c System clock initialization;
HSI through the PLL gives 240 MHz by default, and the PLL multiplier must be an even number between 8 and 76
firmware/CMSIS/device/n32h49x_conf.h Includes all driver headers in one place and defines assert_param
firmware/CMSIS/device/startup/startup_n32h49x.s Keil MDK-ARM startup file
firmware/CMSIS/device/startup/startup_n32h49x_EWARM.s IAR EWARM startup file
firmware/CMSIS/device/startup/startup_n32h49x_gcc.s GCC startup file
firmware/CMSIS/device/n32h49x_flash.ld GCC linker script
firmware/n32h49x_std_periph_driver/inc/misc.h NVIC and SysTick configuration functions, corresponding to the NVIC module in chapter 5
firmware/n32h49x_std_periph_driver/inc/n32h49x_spi.h Driver header shared by SPI and I2S
firmware/n32h49x_algo_lib/keil/lib/n32h49x_common.lib Common algorithm functions;
the Keil library file name differs from that of the header n32h49x_algo_common.h

4.3 Projects Directory

projects/ contains only the n32h49x_EVAL/ evaluation board project directory, with board support, peripheral examples, and application projects.

๐Ÿ“ projects/n32h49x_EVAL/bsp

Board support code, referenced by the example projects through the bsp/inc header path.

bsp/
โ”œโ”€โ”€ inc/
โ”‚   โ”œโ”€โ”€ bsp_eval.h
โ”‚   โ”œโ”€โ”€ delay.h
โ”‚   โ””โ”€โ”€ log.h
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ bsp_eval.c
    โ”œโ”€โ”€ delay.c
    โ”œโ”€โ”€ log.c
    โ””โ”€โ”€ print_remap.c
๐Ÿ“ projects/n32h49x_EVAL/examples

Peripheral examples, grouped by peripheral category: 34 categories and 184 example projects in total.

examples/
โ”œโ”€โ”€ ADC/
โ”œโ”€โ”€ ALGO/
โ”œโ”€โ”€ CORDIC/
โ”œโ”€โ”€ Cortex-M4F/
โ”œโ”€โ”€ CRC/
โ”œโ”€โ”€ DAC/
โ”œโ”€โ”€ DMA/
โ”œโ”€โ”€ DSMU/
โ”œโ”€โ”€ DVP/
โ”œโ”€โ”€ ETH/
โ”œโ”€โ”€ EXTI/
โ”œโ”€โ”€ FDCAN/
โ”œโ”€โ”€ FEMC/
โ”œโ”€โ”€ Flash/
โ”œโ”€โ”€ GPIO/
โ”œโ”€โ”€ I2C/
โ”œโ”€โ”€ I2S/
โ”œโ”€โ”€ IWDG/
โ”œโ”€โ”€ LPTIM/
โ”œโ”€โ”€ NVIC/
โ”œโ”€โ”€ PWR/
โ”œโ”€โ”€ RCC/
โ”œโ”€โ”€ RTC/
โ”œโ”€โ”€ SDIO/
โ”œโ”€โ”€ SDRAM/
โ”œโ”€โ”€ SPI/
โ”œโ”€โ”€ TIM/
โ”œโ”€โ”€ USART/
โ”œโ”€โ”€ USBFSD/
โ”œโ”€โ”€ USBHS/
โ”œโ”€โ”€ VREFBUF/
โ”œโ”€โ”€ WWDG/
โ”œโ”€โ”€ XSPI/
โ””โ”€โ”€ XSPI_V2/
๐Ÿ“ projects/n32h49x_EVAL/applications

Application projects;
currently only GCC_demo, which provides a GCC Makefile build.

applications/
โ””โ”€โ”€ GCC_demo/
    โ”œโ”€โ”€ GCC/
    โ”‚   โ””โ”€โ”€ Makefile
    โ”œโ”€โ”€ inc/
    โ”‚   โ”œโ”€โ”€ main.h
    โ”‚   โ””โ”€โ”€ n32h49x_it.h
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ main.c
    โ”‚   โ””โ”€โ”€ n32h49x_it.c
    โ””โ”€โ”€ readme.txt
Relative path Purpose
projects/n32h49x_EVAL/bsp/inc/bsp_eval.h Port, pin, clock, and active-level macros for LED1 to LED3, KEY1 to KEY3, the WKUP button, and USB VBUS on both boards, selected by DEMO_BOARD
projects/n32h49x_EVAL/bsp/src/log.c Log UART initialization log_init: USART1, TX on PA9 and RX on PA10, 115200-8-N-1
projects/n32h49x_EVAL/bsp/inc/log.h The log_info, log_warning, log_error, and log_debug macros, controlled by LOG_ENABLE and LOG_LEVEL
projects/n32h49x_EVAL/bsp/inc/delay.h SysTick delay functions SysTick_Delay_Us and SysTick_Delay_Ms
projects/n32h49x_EVAL/bsp/src/print_remap.c Standard I/O redirection functions _write and _read
projects/n32h49x_EVAL/bsp/src/bsp_eval.c Board-level helpers such as reading the button state and driving the LEDs
projects/n32h49x_EVAL/examples/ Example projects of the 34 peripheral categories, each with both a Keil and an IAR project
projects/n32h49x_EVAL/applications/GCC_demo/ LED blink GCC project: the Makefile sets the target platform to n32h49x and uses startup_n32h49x_gcc.s and n32h49x_flash.ld, with the all, clean, download, and debug targets

4.4 Standard Example Structure

Each example directory contains sources, headers, a Keil and an IAR project, and a description file. Take examples/GPIO/LedBlink/ as an example:

LedBlink/
โ”œโ”€โ”€ EWARM/
โ”‚   โ”œโ”€โ”€ LedBlink.ewd
โ”‚   โ”œโ”€โ”€ LedBlink.ewp
โ”‚   โ””โ”€โ”€ LedBlink.eww
โ”œโ”€โ”€ inc/
โ”‚   โ”œโ”€โ”€ main.h
โ”‚   โ””โ”€โ”€ n32h49x_it.h
โ”œโ”€โ”€ MDK-ARM/
โ”‚   โ”œโ”€โ”€ LedBlink.uvoptx
โ”‚   โ””โ”€โ”€ LedBlink.uvprojx
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.c
โ”‚   โ””โ”€โ”€ n32h49x_it.c
โ””โ”€โ”€ readme.txt
Relative path Purpose
src/main.c Example main program: peripheral initialization and the main loop
src/n32h49x_it.c Interrupt service functions
inc/main.h, inc/n32h49x_it.h Example header and interrupt function declarations
MDK-ARM/LedBlink.uvprojx Keil project: target name N32H49X, device N32H497xG, compile macros N32H49X and USE_STDPERIPH_DRIVER, ROM from 0x08000000 with length 0x100000, RAM from 0x20000000 with length 0x90000
EWARM/LedBlink.eww IAR workspace: configuration name also N32H49X, the linker file is N32H497xG.icf from the toolchain directory, and the startup file is startup_n32h49x_EWARM.s
readme.txt Bilingual notes: function description, use environment, instructions (system clock and I/O configuration, test steps and phenomena), and attention items

Every example names its MDK-ARM project files <example>.uvprojx / <example>.uvoptx and its EWARM project <example>.eww / <example>.ewp / <example>.ewd;
no example directory contains a GCC project. The following cases differ from the standard structure:

Case Examples Structure
Grouped sub-projects USART/485/, USART/LIN/, USART/IrDA_Tx&Rx/, USBHS/USBHS_Device/, USBHS/USBHS_Host/, USBHS/USBHS_Dual_Role/ The parent directory only groups and has no project;
each sub-project carries its own readme.txt, src/, inc/, MDK-ARM/, and EWARM/ and is counted separately
Project naming inside groups Sub-projects of USBHS/USBHS_Device/ and USBHS/USBHS_Host/ The project files are uniformly named project.uvprojx and project.eww, differing from the directory name
Auxiliary sources USART/LIN/LIN_Master/, USART/IrDA_Tx&Rx/Transmit_Receive/, USBHS/USBHS_Device/CDC/ src/ and inc/ hold additional helper implementations and configuration headers such as lin_master.c, bsp_Tim_38K.c, and usbd_cdc_core.c

Example projects reference firmware/ and bsp/ through relative paths. When copying an example, keep its directory level under projects/n32h49x_EVAL/examples/<category>/, otherwise the header paths and source paths in the project must be updated as well.

4.5 Development Aids

Relative path Purpose
jlink/flash.jlink J-Link Commander script: reset, load build/output.hex, reset, run, quit
.vscode/launch.json gdb-arm debug configuration: connects arm-none-eabi-gdb to the GDB server at localhost:2331, loads the program, resets, and sets a breakpoint at main
.vscode/tasks.json make_debug build task, running make debug in the working directory projects/n32h49x_EVAL/applications/GCC_demo/GCC
.vscode/settings.json Editor settings and file associations (n32h49x.h and n32h49x_flash.h associated with C)
projects/n32h49x_EVAL/applications/GCC_demo/GCC/Makefile GCC build script: all produces build/output.elf, .hex, and .bin;
download calls JLink.exe with -device N32H497xG -if SWD to run jlink/flash.jlink;
debug starts JLinkGDBServer.exe

Outside the SDK root, the SDK package also provides the following development support files, whose official versions are listed in the โ€œDocumentation and Tool Navigationโ€ chapter:

Resource Purpose
KEIL PACK package Keil support package: the .pack installer, the .pdsc device description, Flash programming algorithms, and .svd files
IAR model patch Adds the Nations device descriptions to the IAR toolchain;
after installation, linker files such as N32H497xG.icf reside in the config/linker/Nsing/N32H49x/ directory of the toolchain
J-Link model patch package J-Link device description files that make J-Link recognize parts such as N32H497xG
Flash programming algorithm source projects Keil and IAR Flash programming algorithm source projects, for building your own .FLM files
NSLink and production tools Online and offline production programming tools