4. SDK Directory Structure

This chapter describes the directories and files of Nsing.N32G41x_Library.1.1.0 from its actual file tree, and lists only directories and files that are present in the package. All paths are relative to the SDK root. Device support packs, production tools and other support files outside the package are covered in the Documentation and Tool Navigation chapter.

4.1 Top-Level Layout

  • ๐Ÿ“ Entries ending in / are directories
  • ๐Ÿ“„ All other entries are files
Nsing.N32G41x_Library.1.1.0/
โ”œโ”€โ”€ .vscode/
โ”‚   โ”œโ”€โ”€ launch.json
โ”‚   โ”œโ”€โ”€ settings.json
โ”‚   โ””โ”€โ”€ tasks.json
โ”œโ”€โ”€ firmware/
โ”‚   โ”œโ”€โ”€ CMSIS/
โ”‚   โ””โ”€โ”€ n32g41x_std_periph_driver/
โ”œโ”€โ”€ jlink/
โ”‚   โ””โ”€โ”€ flash.jlink
โ”œโ”€โ”€ Middlewares/
โ”‚   โ””โ”€โ”€ FreeRTOSv202604.01-LTS/
โ”œโ”€โ”€ projects/
โ”‚   โ””โ”€โ”€ n32g41x_EVAL/
โ””โ”€โ”€ readme.txt
Relative path Purpose
firmware/ Firmware library: CMSIS core and device support files, and the standard peripheral driver library
Middlewares/ FreeRTOS kernel sources, referenced by the FreeRTOS example project
projects/n32g41x_EVAL/ Evaluation board projects: board support, peripheral examples and application projects
jlink/flash.jlink J-Link Commander download script called by the download target of the GCC project
.vscode/ VS Code GDB debugging, build task and editor configuration
readme.txt SDK version record and change notes for each version

4.2 Firmware Library

๐Ÿ“ firmware/CMSIS

core/ holds the Arm CMSIS-Core headers; a Cortex-M4 project uses core_cm4.h from it. device/ holds the N32G41x device support files and the three startup files.

CMSIS/
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ cmsis_armcc.h
โ”‚   โ”œโ”€โ”€ cmsis_armclang.h
โ”‚   โ”œโ”€โ”€ cmsis_armclang_ltm.h
โ”‚   โ”œโ”€โ”€ cmsis_compiler.h
โ”‚   โ”œโ”€โ”€ cmsis_gcc.h
โ”‚   โ”œโ”€โ”€ cmsis_iccarm.h
โ”‚   โ”œโ”€โ”€ cmsis_version.h
โ”‚   โ”œโ”€โ”€ core_armv81mml.h
โ”‚   โ”œโ”€โ”€ core_armv8mbl.h
โ”‚   โ”œโ”€โ”€ core_armv8mml.h
โ”‚   โ”œโ”€โ”€ core_cm0.h
โ”‚   โ”œโ”€โ”€ core_cm0plus.h
โ”‚   โ”œโ”€โ”€ core_cm1.h
โ”‚   โ”œโ”€โ”€ core_cm23.h
โ”‚   โ”œโ”€โ”€ core_cm3.h
โ”‚   โ”œโ”€โ”€ core_cm33.h
โ”‚   โ”œโ”€โ”€ core_cm35p.h
โ”‚   โ”œโ”€โ”€ core_cm4.h
โ”‚   โ”œโ”€โ”€ core_cm7.h
โ”‚   โ”œโ”€โ”€ core_sc000.h
โ”‚   โ”œโ”€โ”€ core_sc300.h
โ”‚   โ”œโ”€โ”€ mpu_armv7.h
โ”‚   โ”œโ”€โ”€ mpu_armv8.h
โ”‚   โ””โ”€โ”€ tz_context.h
โ””โ”€โ”€ device/
    โ”œโ”€โ”€ startup/
    โ”‚   โ”œโ”€โ”€ startup_n32g41x.s
    โ”‚   โ”œโ”€โ”€ startup_n32g41x_EWARM.S
    โ”‚   โ””โ”€โ”€ startup_n32g41x_gcc.s
    โ”œโ”€โ”€ n32g41x.h
    โ”œโ”€โ”€ n32g41x_conf.h
    โ”œโ”€โ”€ n32g41x_flash.ld
    โ”œโ”€โ”€ system_n32g41x.c
    โ””โ”€โ”€ system_n32g41x.h
๐Ÿ“ firmware/n32g41x_std_periph_driver

The standard peripheral driver library: inc/ holds the driver headers and src/ the implementation files of the same name, one pair per driver module.

n32g41x_std_periph_driver/
โ”œโ”€โ”€ inc/
โ”‚   โ”œโ”€โ”€ misc.h
โ”‚   โ”œโ”€โ”€ n32g41x_adc.h
โ”‚   โ”œโ”€โ”€ n32g41x_can.h
โ”‚   โ”œโ”€โ”€ n32g41x_comp.h
โ”‚   โ”œโ”€โ”€ n32g41x_crc.h
โ”‚   โ”œโ”€โ”€ n32g41x_dbg.h
โ”‚   โ”œโ”€โ”€ n32g41x_dma.h
โ”‚   โ”œโ”€โ”€ n32g41x_exti.h
โ”‚   โ”œโ”€โ”€ n32g41x_flash.h
โ”‚   โ”œโ”€โ”€ n32g41x_gpio.h
โ”‚   โ”œโ”€โ”€ n32g41x_i2c.h
โ”‚   โ”œโ”€โ”€ n32g41x_iwdg.h
โ”‚   โ”œโ”€โ”€ n32g41x_opamp.h
โ”‚   โ”œโ”€โ”€ n32g41x_pwr.h
โ”‚   โ”œโ”€โ”€ n32g41x_rcc.h
โ”‚   โ”œโ”€โ”€ n32g41x_rtc.h
โ”‚   โ”œโ”€โ”€ n32g41x_spi.h
โ”‚   โ”œโ”€โ”€ n32g41x_tim.h
โ”‚   โ”œโ”€โ”€ n32g41x_usart.h
โ”‚   โ””โ”€โ”€ n32g41x_wwdg.h
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ misc.c
    โ”œโ”€โ”€ n32g41x_adc.c
    โ”œโ”€โ”€ n32g41x_can.c
    โ”œโ”€โ”€ n32g41x_comp.c
    โ”œโ”€โ”€ n32g41x_crc.c
    โ”œโ”€โ”€ n32g41x_dbg.c
    โ”œโ”€โ”€ n32g41x_dma.c
    โ”œโ”€โ”€ n32g41x_exti.c
    โ”œโ”€โ”€ n32g41x_flash.c
    โ”œโ”€โ”€ n32g41x_gpio.c
    โ”œโ”€โ”€ n32g41x_i2c.c
    โ”œโ”€โ”€ n32g41x_iwdg.c
    โ”œโ”€โ”€ n32g41x_opamp.c
    โ”œโ”€โ”€ n32g41x_pwr.c
    โ”œโ”€โ”€ n32g41x_rcc.c
    โ”œโ”€โ”€ n32g41x_rtc.c
    โ”œโ”€โ”€ n32g41x_spi.c
    โ”œโ”€โ”€ n32g41x_tim.c
    โ”œโ”€โ”€ n32g41x_usart.c
    โ””โ”€โ”€ n32g41x_wwdg.c
Relative path Purpose
firmware/CMSIS/device/n32g41x.h Device header: peripheral register structures, base addresses and interrupt numbers
firmware/CMSIS/device/system_n32g41x.c System clock initialisation;
requires exactly one of N32G412 or N32G415 to be defined, and defaults to HSI multiplied by the PLL at 80 MHz (N32G412) or 96 MHz (N32G415)
firmware/CMSIS/device/system_n32g41x.h System clock configuration macros such as SYSCLK_SRC and SYSCLK_FREQ, and the available frequency options
firmware/CMSIS/device/n32g41x_conf.h Includes all driver headers in one place and defines assert_param
firmware/CMSIS/device/startup/startup_n32g41x.s Keil MDK-ARM startup file
firmware/CMSIS/device/startup/startup_n32g41x_EWARM.S IAR EWARM startup file
firmware/CMSIS/device/startup/startup_n32g41x_gcc.s GCC startup file
firmware/CMSIS/device/n32g41x_flash.ld GCC linker script
firmware/n32g41x_std_periph_driver/inc/misc.h NVIC and SysTick configuration functions, documented as the NVIC module in Chapter 5
firmware/n32g41x_std_periph_driver/inc/n32g41x_spi.h Driver header shared by SPI and I2S

4.3 Projects Directory

projects/ contains only the evaluation board project directory n32g41x_EVAL/, made up of board support, peripheral examples and application projects.

๐Ÿ“ projects/n32g41x_EVAL/bsp

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

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

Peripheral examples, organised by peripheral category with a number of example projects in each.

examples/
โ”œโ”€โ”€ ADC/
โ”œโ”€โ”€ bxCAN/
โ”œโ”€โ”€ COMP/
โ”œโ”€โ”€ Cortex-M4/
โ”œโ”€โ”€ CRC/
โ”œโ”€โ”€ DMA/
โ”œโ”€โ”€ EXTI/
โ”œโ”€โ”€ Flash/
โ”œโ”€โ”€ FreeRTOS/
โ”œโ”€โ”€ GPIO/
โ”œโ”€โ”€ I2C/
โ”œโ”€โ”€ I2S/
โ”œโ”€โ”€ IWDG/
โ”œโ”€โ”€ NVIC/
โ”œโ”€โ”€ OPAMP/
โ”œโ”€โ”€ PWR/
โ”œโ”€โ”€ RCC/
โ”œโ”€โ”€ RTC/
โ”œโ”€โ”€ SPI/
โ”œโ”€โ”€ TIM/
โ”œโ”€โ”€ USART/
โ””โ”€โ”€ WWDG/
๐Ÿ“ projects/n32g41x_EVAL/applications

Application projects demonstrating complete use cases beyond the example directory.

applications/
โ”œโ”€โ”€ BOOT_As_ExtFLASH/
โ”‚   โ”œโ”€โ”€ inc/
โ”‚   โ”‚   โ”œโ”€โ”€ main.h
โ”‚   โ”‚   โ””โ”€โ”€ n32g41x_it.h
โ”‚   โ”œโ”€โ”€ MDK-ARM/
โ”‚   โ”‚   โ”œโ”€โ”€ BOOT_As_ExtFLASH.uvoptx
โ”‚   โ”‚   โ””โ”€โ”€ BOOT_As_ExtFLASH.uvprojx
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ main.c
โ”‚       โ””โ”€โ”€ n32g41x_it.c
โ”œโ”€โ”€ GCC_demo/
โ”‚   โ”œโ”€โ”€ GCC/
โ”‚   โ”‚   โ””โ”€โ”€ Makefile
โ”‚   โ”œโ”€โ”€ inc/
โ”‚   โ”‚   โ”œโ”€โ”€ main.h
โ”‚   โ”‚   โ””โ”€โ”€ n32g41x_it.h
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ main.c
โ”‚       โ””โ”€โ”€ n32g41x_it.c
โ””โ”€โ”€ JumpToBOOT/
    โ”œโ”€โ”€ inc/
    โ”‚   โ”œโ”€โ”€ main.h
    โ”‚   โ””โ”€โ”€ n32g41x_it.h
    โ”œโ”€โ”€ MDK-ARM/
    โ”‚   โ”œโ”€โ”€ project.uvoptx
    โ”‚   โ””โ”€โ”€ project.uvprojx
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ main.c
        โ””โ”€โ”€ n32g41x_it.c
Relative path Purpose
projects/n32g41x_EVAL/bsp/inc/n32g41x_stb.h Port, pin, clock and active-level macros for LED1 to LED3, KEY1 to KEY3 and the WKUP key
projects/n32g41x_EVAL/bsp/src/log.c Log UART initialisation log_init: USART1 with PA9 as TX and PA10 as RX, 115200 bps
projects/n32g41x_EVAL/bsp/inc/log.h log_info, log_warning, log_error and log_debug macros, controlled by LOG_ENABLE and LOG_LEVEL
projects/n32g41x_EVAL/bsp/inc/delay.h SysTick delay functions SysTick_Delay_Us and SysTick_Delay_Ms
projects/n32g41x_EVAL/bsp/src/print_remap.c Standard input and output redirection functions _write and _read
projects/n32g41x_EVAL/applications/BOOT_As_ExtFLASH/ Programs the BOOT area as extended Flash: when the BOOT area is write-protected, pressing the PA4 key removes the write protection through the option bytes and resets; otherwise it erases one page starting at 0x1FFF0000, writes data and verifies it word by word, reporting the result on the log UART.
A Keil project only
projects/n32g41x_EVAL/applications/GCC_demo/ A GCC project that blinks the LEDs: the Makefile defines N32G412 and uses startup_n32g41x_gcc.s and n32g41x_flash.ld, with the all, clean, download and debug targets
projects/n32g41x_EVAL/applications/JumpToBOOT/ Jumps from the application to the BOOT: after the WKUP key is pressed it reads the stack top at 0x1FFF0000 and the reset vector at 0x1FFF0004 and jumps there.
A Keil project only

4.4 Standard Structure of an Example

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

LedBlink/
โ”œโ”€โ”€ EWARM/
โ”‚   โ”œโ”€โ”€ project.ewd
โ”‚   โ”œโ”€โ”€ project.ewp
โ”‚   โ””โ”€โ”€ project.eww
โ”œโ”€โ”€ inc/
โ”‚   โ”œโ”€โ”€ main.h
โ”‚   โ””โ”€โ”€ n32g41x_it.h
โ”œโ”€โ”€ MDK-ARM/
โ”‚   โ”œโ”€โ”€ project.uvoptx
โ”‚   โ””โ”€โ”€ project.uvprojx
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.c
โ”‚   โ””โ”€โ”€ n32g41x_it.c
โ””โ”€โ”€ readme.txt
Relative path Purpose
src/main.c Example main program: peripheral initialisation and the main loop
src/n32g41x_it.c Interrupt service routines
inc/main.h, inc/n32g41x_it.h Example header and interrupt function declarations
MDK-ARM/project.uvprojx Keil project with two targets, N32G412 (device N32G412RBL7) and N32G415 (device N32G415RBL7), each defining the matching compile macro and USE_STDPERIPH_DRIVER
EWARM/project.eww IAR workspace with two configurations, N32G412 and N32G415
readme.txt Chinese and English notes: function description, development environment (tools and supported chips), usage (system configuration and how to run) and cautions

Project files in the example directories are consistently named project.uvprojx / project.uvoptx and project.eww / project.ewp / project.ewd, and no example directory contains a GCC project. The following cases differ from the standard structure:

Case Example Structure
Paired sub-projects sharing one description file SPI/SPI_9Bit/ The parent directory holds readme.txt, and SPI_9Bit_Master/ and SPI_9Bit_Slave/ each contain a complete src/, inc/, MDK-ARM/ and EWARM/
Shared code directory RTC/Common/ Only inc/User_RTC_Config.h and src/User_RTC_Config.c, with no project files
Helper sources bxCAN/CAN_LoopBack/, I2C/EEPROM_Polling/, SPI/SPI_FLASH/ src/ and inc/ also contain helper drivers such as can_config.c, i2c_eeprom.c and spi_flash.c

Example projects reference firmware/ and bsp/ through relative paths. When copying an example, keep it at the same level under projects/n32g41x_EVAL/examples/<category>/, otherwise the header 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 The gdb-arm debug configuration: connects arm-none-eabi-gdb to a GDB server on localhost:2331, loads the program, resets and sets a breakpoint at main
.vscode/tasks.json The make_debug build task, which runs make debug in the GCC project directory
.vscode/settings.json Editor settings and file associations
projects/n32g41x_EVAL/applications/GCC_demo/GCC/Makefile GCC build script: all produces build/output.elf, .hex and .bin;
download calls JLink.exe with jlink/flash.jlink;
debug starts JLinkGDBServer.exe

The following support resources are not inside the SDK root and must be obtained from the official download centre; their names and versions are listed in the Documentation and Tool Navigation chapter:

Resource Purpose
Nsingtech.N32G41x_DFP Keil device support pack: the .pack installer, the .pdsc device description, the Flash/N32G41x_64.FLM and Flash/N32G41x_128.FLM programming algorithms, and the device register description file
N32G41x_Keil_FLASH_Programming_Algorithm Keil Flash programming algorithm source project, which builds the two programming algorithms above
Nations_Device_PACK_Add_To_IAR_Tool IAR device patch installer, which adds the N32G41x device models to IAR
JLink_tool_adds_Nations_chip J-Link device patch, which adds the N32G41x device models to J-Link