Generated: 2026-06-15 Version: CUni360S-Z DEMO V3.4 (SDK V3.6) IDE: CCore Eclipse CDT (C*Core C0 architecture)
Firmware demo for the C*Core CUni360S-Z secure MCU — a Chinese-designed RISC SoC targeting financial/identification terminals (POS, card readers). Demonstrates all on-chip peripherals and hardware crypto engines (SM1/2/3/4, DES/3DES, AES, RSA, SHA, TRNG) plus smart card (ISO 7816), USB device classes, and certificate (X.509/PKCS7) handling.
CUni360S-Z_Demo/
├── .project/.cproject # Eclipse CDT project (name: CUni360S-Z_Demo_V1)
├── linkmap # Linker script (NOT .ld — plain text, GCC-style)
├── gdbinit # GDB remote debug config (JTAG localhost:3333)
├── include/ # Core headers: types, memmap, interrupts, boot
├── src/
│ ├── main.c # Entry point — init sequence + demo dispatch
│ ├── ccore/ # C*Core startup: vectors, interrupt table
│ ├── drv/ # Peripheral drivers + register definitions
│ │ └── inc/ # All driver headers + xxx_reg.h register maps
│ ├── app/ # Application-layer protocol implementations
│ │ ├── apdu/ # APDU command dispatcher (smart card)
│ │ ├── cert/ # SM2 cert generation, X.509, PKCS7, Base64
│ │ ├── icc/ # ICC/ISO 7816 T0/T1 + EMV L1
│ │ ├── mcc/ # Magnetic card reader (MCC ADC)
│ │ ├── norflash/ # External NOR flash via SPI3
│ │ ├── rtc/ # RTC application
│ │ └── usb/ # USB device classes (CCID/CDC/HID/UMS)
│ ├── demo/ # Demo function per peripheral/feature
│ └── common/ # Debug printf, assert
├── build_config/ # Build config (project_type:0)
├── debug_eflash/ # TCL scripts for flash erase/program
├── Debug/ # Build output (.elf, .bin, .map, .o, .d)
└── .metadata/ # Eclipse workspace state — IGNORE
| Task | Location | Notes |
|---|---|---|
| Add a new peripheral demo | src/demo/ + toggle in test_demo.h |
Pattern: xxx_demo.c/.h |
| Use crypto (AES/DES/SM4/SM2/RSA) | src/drv/inc/alg_drv.h |
Hardware engine APIs |
| Smart card / ISO 7816 | src/app/icc/ |
T0/T1, EMV L1 |
| Certificate operations | src/app/cert/ |
X.509, PKCS7, SM2 certs |
| USB class implementation | src/app/usb/ |
Enable in usb_config.h |
| Memory map / register base | include/memmap.h |
All peripheral base addresses |
| Type definitions | include/type.h |
UINT8/16/32, bool, FlagStatus |
| Boot / clock / power | src/drv/inc/cpm_drv.h |
SysClk, module clocks, card LDO |
| Linker layout | linkmap |
eFlash 512K@0x400000, RAM 64K@0x800000 |
| Debug via GDB | gdbinit |
target remote localhost:3333 |
| Resource | Detail |
|---|---|
| Core | C*Core C0 (NOT ARM) — little endian |
| Clock | OSC 120MHz, default sys = 60MHz (div 2) |
| eFlash | 0x00400000, 512KB |
| RAM | 0x00800000, 64KB |
| Stack | Top at 0x80fffc, heap ends 0x2000 below |
| Crypto HW | SM1(0x63f1c000), SM2, SM4(0x00de0000), AES(0x00cf0000), DES(0x00c90000), SHA(0x63f64000), TRNG(0x63f40000) |
| Peripherals | SPI×3, SCI/UART×2, I2C, USB, ADC, PWM, PIT, PIT32, DMA, EDMA, CRC×2, RTC, WDT, EPORT, PCI, USI×2 |
| Smart card I/F | USI2/USI3 (ISO 7816), voltage: 1.8V/3V/3.3V/5V selectable |
#ifndef NAME_H_ / #define NAME_H_ (never #pragma once)UINT8/UINT16/UINT32/INT8/INT16/INT32 from type.h — NOT uint8_tMODULE_ActionCase() — e.g., UART_Init(), CPM_SysClkSelect(), AES_EnDecrypt()#define PERIPH ((PERIPH_TypeDef *)(BASE_ADDR)) then PERIPH->REG |= bitmodule_drv.c / module_reg.h (driver+register split)// ~~~~ banner or /* Author */ blockCARD0_POWER_ON, USB_POWER_ON etc. — do{}while(0) wrappersassert_param(expr) macro, IS_xxx_RANGE() guard macrosmy_printf (aliased via #define printf my_printf) — costs ~2KB RAM, controlled by DEBUG_LOGmain.c: "两个不能同时打开"CACHE_Init(cacheOff, ...) is skippedInit_Trng() before any SM2 key generation (internally uses TRNG)ModuleClk_On(MODULE_CLK_xxx) before using any peripheral; ModuleClk_Off() to save powerreback_boot() checks I2C_SDA pin — if LOW, calls EnBootMode(0) and infinite loops (returns to bootloader)usb_config.h (currently CCID=1, others=0)EFLASH_Init(g_sys_clk) at startup with current system clock frequencysrc/demo/test_demo.h contains #define XXX_DEMO switches — uncomment ONE to run that demo. Currently ALG_DEMO is active.Debug/ contains .a files — pre-compiled algorithm/bootstrap librariesvector_table.o(.rodata*) section, placed at eFlash entry via KEEP() in linkmap.bss section gets +0x08 bytes padding (alignment guard).text section filled with 0xbebe pattern (debug signature)# Build: Eclipse CDT managed build (Project → Build)
# Or from CLI:
make -C Debug all # Using generated makefiles
# Flash & Debug: GDB with JTAG
# 1. Connect JTAG debugger, start OpenOCD/gdbserver on port 3333
# 2. Run GDB with gdbinit:
ccore-gdb Debug/CUni360S-Z_Demo.elf -x gdbinit
# Flash via TCL scripts (alternative):
# Edit gdbinit to uncomment monitor script lines for flash_erase.tcl / flash_pro.tcl
.metadata/: Eclipse workspace state — do NOT version control or editDebug/: Contains build artifacts AND mirror source tree for debugging — generated, don't editwhile(1) super-loop architecture.a files in Debug/ — source not included in SDKSCI_BT: UART1 named "SCI_BT" (Bluetooth SCI) — SCI2 is the main debug UART at 115200 baudCARD0 = ICC slot, CARD1 = second card slot — voltage selectable via CPM_SLPCFGR bits