Software/STM32CubeIDE

STM32CubeIDE BSP Middleware

The stacks the Neuro N6 board support package carries above its modules: USB, Wi-Fi, BLE, TLS, the asset store and the NPU runtime with its networks.

advanced7 min read

The BSP modules stop at the hardware: neuron6_wifi, neuron6_bt and neuron6_npu prepare their peripherals and depend on no stack. The stacks the examples build on are carried under Middlewares/ and Utilities/, each under its own licence (see Licensing). Each example's CubeIDE project already compiles the stacks it uses; wifi_build.json, ble_build.json, tls_build.json and npu_build.json in an example folder list the sources, flags and include paths a stack needs in another project.

PathContentsNeeds
Middlewares/tinyusb/, Utilities/usb/TinyUSB 0.20.0 and the board's configuration and descriptorsEvery example
Middlewares/FreeRTOS/, Utilities/freertos/FreeRTOS Kernel V10.6.2 with the Cortex-M55 port, the board's FreeRTOSConfig.h and the TIM16 HAL time baseBSP_USE_FREERTOS
Middlewares/NeuroN6/MayaW476/The Wi-Fi library, with the IW610 firmwareFreeRTOS, Middlewares/NXP/, Middlewares/lwip/
Middlewares/NXP/, Middlewares/lwip/NXP's Wi-Fi driver and OS abstraction, and lwIP 2.2.1 with NXP's port and HTTP serverFreeRTOS
Middlewares/NeuroN6/BleHost/, Middlewares/nimble/Apache NimBLE 1.10.0's host, brought up on neuron6_btFreeRTOS, Middlewares/mbedtls/
Middlewares/NeuroN6/Tls/, Middlewares/mbedtls/TLS 1.2 and 1.3 on Mbed TLS 3.6.6 and NXP's HTTPS serverFreeRTOS, the Wi-Fi stack
Middlewares/NeuroN6/N6OTA/The asset store: settings a host stores on the boardFreeRTOS
Middlewares/ST/AI_Runtime/, Utilities/npu/ST Edge AI's NPU runtime and network runtime library, and the board's memory poolsneuron6_npu
Middlewares/NeuroN6/PostProcess/, Middlewares/ARM/CMSIS-DSP/, Middlewares/ST/lib_vision_models_pp/Network post-processing, stream metadata and the host protocolThe network examples
Middlewares/NeuroN6/Models/The networks the examples run, generated for this boardThe network examples

USB

Every example builds with the one TinyUSB tree. The BSP's configuration in Utilities/usb/tusb_config.h selects TinyUSB's FreeRTOS abstraction when BSP_USE_FREERTOS is set. The device presents the CDC console, and, in the streaming examples, either a vendor bulk interface that Neuro Studio reads or, with BSP_USB_UVC set, a USB video class camera that any host opens without a driver. An application hands the video class whole frames with tud_video_n_frame_xfer(). Most of the FreeRTOS examples carry their own Utilities/usb/ files beside Core/, which enable DMA in TinyUSB's DWC2 driver.

Wi-Fi

Middlewares/NeuroN6/MayaW476/ is the C form of the MayaW476 library the Arduino core carries: MayaW476.h exposes the library's methods as functions. It brings the radio up over SDIO, downloads the IW610 firmware from external flash at 0x91E00000, hosts an access point or joins a network, and runs the Neuro host server on the board's own access point, through which Neuro Studio connects over TCP for the same stream and controls as over USB and finds the board by a UDP broadcast probe or over mDNS (<hostname>.local, _neuron6._tcp). The application's own connections use lwIP's BSD sockets (lwip/sockets.h) once MayaW476_Status() reports a link.

FunctionPurpose
MayaW476_Begin(ssid, psk, security)Joins a WPA2 or WPA3 network, and rejoins after a lost link
MayaW476_BeginAP(ssid, psk, channel, security)Hosts a WPA2 or WPA3 access point at 192.168.10.1/24, leasing .10 to .99. A NULL passphrase uses the board password
MayaW476_BeginStored()Goes to the network a host stored on the board. A stored access point with no passphrase uses the board password
MayaW476_DevicePassword(), MayaW476_SoftApPassword()The board password, and the passphrase of the access point the board hosts
MayaW476_Start(TRANSPORT_WIFI_SOFTAP)The board's own access point and the Neuro host server on it. Returns -3 for TRANSPORT_WIFI_STA or a joined network, and the stream stays on USB
MayaW476_RadioStart()Loads the firmware with no network, for BLE
MayaW476_Status(), MayaW476_Disconnect(), MayaW476_End()Link state and shutdown
MayaW476_Config(), MayaW476_SetDNS(), MayaW476_SetHostname()Fixed address, DNS servers and hostname
MayaW476_LocalIP(), SSID(), RSSI(), BSSID(), Channel(), MacAddress()Link information
MayaW476_ScanNetworks(), ScanSSID(), ScanRSSI(), ScanEncryption(), ScanChannel()Scanning
MayaW476_HostByName(), MayaW476_GetTime(), MayaW476_SetTimeServer()Name lookup and network time
MayaW476_LowPowerMode(), MayaW476_NoLowPowerMode()IEEE power save
MayaW476_SetLinkKey()A key a connecting Neuro host must prove

The begin functions take WIFI_SECURITY_WPA2, WIFI_SECURITY_WPA3_SAE and WIFI_SECURITY_WPA2_WPA3, with a passphrase of 8 to 63 characters, or 64 hex digits for WPA2. Open, WEP, WPA and mixed WPA/WPA2 networks are refused with WL_CONNECT_FAILED or WL_AP_FAILED and one console line that says why, and stored settings get the same check. Protected management frames are required under WPA3 alone and offered otherwise. The library confines the radio to 2.4 GHz, caps the conducted transmit power at 8 dBm and locks the region to World Wide Safe Mode; access point channels are 1 to 11, 0 selects one automatically, and a channel above 11 is replaced by 6.

The board password is 16 characters in four groups of four, xxxx-xxxx-xxxx-xxxx, from the chip's random number generator. The first call to MayaW476_DevicePassword() stores it in the asset store, as record 3, and restarts the board once. While the board hosts its access point, MayaW476_SoftApAnnounce() gives the access point's name and passphrase as the META_BOARD_SOFTAP record, sent to a USB host only.

The library needs FreeRTOS with the configuration in Utilities/freertos, the HAL's SDIO driver from Utilities/hal or Drivers/, the asset store, and three functions from the application: NeuroN6_DbgPrint(), and NeuroN6_NetAttach() and NeuroN6_IpAnnounceFrame() from NeuroN6_FrameQueue.h. The radio firmware is programmed with python harness/n6weights.py Middlewares/NeuroN6/MayaW476/firmware/firmware.json --write. The library runs the SDIO bus to the radio at 8.163 MHz, the same clock as neuron6_wifi.

BLE

Middlewares/NeuroN6/BleHost/ brings Apache NimBLE's host up over the HCI link neuron6_bt carries. The application uses NimBLE's own API (host/ble_hs.h) for advertising, scanning, connections in both roles, GATT server and client, and LE Secure Connections pairing; bonds are kept in RAM.

FunctionPurpose
BleHost_Init()From a task: loads the radio firmware with MayaW476_RadioStart(), raises the HCI link, resets the controller and initialises NimBLE
BleHost_Start()Starts the host task. NimBLE's sync_cb follows, from which advertising or scanning starts
BleHost_GetStats()HCI link counters
c
BleHost_Init();
ble_hs_cfg.sync_cb = on_sync;
ble_svc_gap_init();
ble_gatts_count_cfg(my_services);
ble_gatts_add_svcs(my_services);
BleHost_Start();

An application that needs only advertising uses neuron6_bt directly, as BleBeacon_FreeRTOS does.

TLS

Middlewares/NeuroN6/Tls/ brings up Mbed TLS and NXP's HTTPS server on the board, for TLS 1.2 and 1.3 over Wi-Fi.

FunctionPurpose
N6Tls_Init()Starts the STM32N6's random number generator as the entropy source, gives Mbed TLS FreeRTOS mutexes and starts the PSA cryptography API
N6Tls_SetTime(), N6Tls_GetTime()The clock certificates are checked against
N6Tls_MakeIdentity(&id, dnsName, ipv4)Makes an ECDSA P-256 key and a self-signed certificate for the board, held in RAM
N6Tls_CertPem(), N6Tls_Fingerprint(), N6Tls_WipeKey()Certificate output and key disposal
N6Tls_Connect(), N6Tls_Write(), N6Tls_Read(), N6Tls_Close()A client connection that checks the server's chain, dates and name, and refuses without the time

The identity's certificate and key are passed to NXP's HTTP server as its TLS parameters. WiFiTls_FreeRTOS runs an HTTPS server and client.

Asset store

Middlewares/NeuroN6/N6OTA/ holds small persistent data a host writes to the board, such as the Wi-Fi settings Neuro Studio stores. The application never writes flash: it stages the data in PSRAM, arms a backup register and resets, and the boot loader programs it to two 4 KB copies at 0x90282000. A read takes the newest copy that passes its check.

FunctionPurpose
n6_asset_read(), n6_asset_present(), n6_asset_stage()The asset
n6_asset_record_read(), n6_asset_record_stage()Typed records beside it
n6_asset_apply()Resets into the boot loader, which writes the staged data
n6_asset_last_result()Result of the last write

n6_asset_host.c handles the host's commands for the store, received over the USB cable.

Neural networks

neuron6_npu prepares the accelerator; ST Edge AI's runtime in Middlewares/ST/AI_Runtime/ runs a network on it. A network is generated with ST Edge AI Core against the board's memory pools, Utilities/npu/NeuroN6_MemPool.mpool, which places weights in the external flash pool from 0x90300000 and activations in NPU RAM and the PSRAM pool. harness/n6model.py runs the generation with the options and input contract the board uses (uint8, channels last, epoch controller on):

bash
python harness/n6model.py model.onnx --name nia416 --out Middlewares/NeuroN6/Models/Nia416

It writes the network (<name>.c), its epoch controller blobs, its weights (<name>_atonbuf.xSPI1.raw), ST Edge AI's report, the one translation unit a project compiles (<name>_model.c) and model.json, which records the weights' address, size and checksums. --address places the weights elsewhere in the pool, 64 KB aligned, so that two networks of a cascade are resident at once. ST Edge AI Core is found in its default install folder or through NEURON6_STEDGEAI, and the install whose bundled runtime matches the one in Middlewares/ST/AI_Runtime is preferred. The weights are programmed with harness/n6weights.py <model.json> --write.

NetworkFolderInputWeights atLicence
NIA Triad-416 detector, 80 COCO classesModels/Nia416416 x 4160x90300000Ohm Lab Model Licence
MediaPipe palm detectorModels/PalmDet192 x 1920x90300000Apache-2.0
MediaPipe hand landmarksModels/HandLm224 x 2240x90420000Apache-2.0
YOLOv8n instance segmentationModels/YoloV8Seg256 x 2560x90300000AGPL-3.0
YOLOv8n pose estimationModels/YoloV8Pose256 x 2560x90300000AGPL-3.0

The generated network code is also under SLA0044. harness/compile.sh and harness/examples/cubebuild.sh --all leave the two YOLOv8 examples out unless NEURON6_BUILD_RESTRICTED=1 is set.

Middlewares/NeuroN6/PostProcess/ decodes the networks' outputs (PostProcess_NIA416(conf, iou) and the palm, hand landmark and YOLOv8 post-processors), maps the results back onto the camera frame, and publishes them as metadata on the vendor stream for Neuro Studio. n6_host_contract.h defines the host protocol's traffic classes, command formats and CRC.