STM32CubeIDE BSP Examples
The thirty-five example projects of the Neuro N6 board support package, what each shows and the hardware it needs.
The board support package carries thirty-five examples in Examples/, each with its own CubeIDE projects under STM32CubeIDE/ and its own README.md. They divide into standalone examples, which each show one module, and larger applications that stream the cameras over USB and Wi-Fi, run neural networks on the NPU, and use Wi-Fi, TLS and BLE. Building and uploading are described in Getting Started.
Each example's own code is released under CC0 1.0, except the main.c of the two YOLOv8 examples, which is AGPL-3.0, and may be copied into another project without carrying the BSP's licence; the files that say so carry SPDX-License-Identifier: CC0-1.0. The main.c of BSPTest, Camera_JpegStream_USB, Thermal_Stream_USB and Camera_GlobalShutterThermal_USB_FreeRTOS, which derive from ST templates, keep ST's BSD-3-Clause terms, as do the template-derived files in every example's Core/. Every example keeps the board reachable over USB: b on the console sends the board to its boot loader.
Standalone examples
Each standalone example is one file, Core/Src/main.c, with a comment saying what it does, a setup() and a loop(), followed by the scaffolding common to every example. Output goes to the USB console.
| Example | Shows | Main functions | Hardware |
|---|---|---|---|
Blink | The green LED on and off with delay() | BSP_LED_Init, BSP_LED_On, BSP_LED_Off | Neuro N6 |
BlinkWithoutDelay | The same without blocking loop(), timed with HAL_GetTick | BSP_LED_* | Neuro N6 |
DigitalReadSerial | The USER button's state, ten times a second | BSP_PB_Init, BSP_PB_GetState | Neuro N6 |
ButtonInterrupt | Button presses counted by interrupt on EXTI line 8 | BSP_PB_Init in BUTTON_MODE_EXTI, BSP_PB_Callback | Neuro N6 |
AnalogReadSerial | A0 as counts and millivolts, five times a second, with 1.8 V full scale | BSP_ADC_SetResolution, BSP_ADC_GetVdda, BSP_ADC_ReadChannel | Neuro N6 |
Fade | PWM on the red LED, with the duty inverted for the active-low LED | BSP_PWM_Init, BSP_PWM_Start | Neuro N6 |
RgbLed | The eight colours of the RGB LED, named on the console | BSP_LED_* | Neuro N6 |
WireScanner | Every address that answers on the sensor bus, every two seconds | BSP_I2C1_Init, BSP_I2C1_IsReady | Neuro N6, with or without a camera carrier |
ReadAcceleration | Accelerometer and gyroscope in milli-g and millidegrees per second, ten times a second | BSP_MOTION_SENSOR_Init, Enable, GetAxes | Neuro N6 |
ReadMagneticField | The magnetometer in milligauss with the field's magnitude, ten times a second | BSP_MOTION_SENSOR_* | Neuro N6 |
ReadDistance | Distance in millimetres and its status from the time of flight sensor, about ten times a second | BSP_RANGING_SENSOR_Init, Start, IsMeasurementReady, GetDistance | OV5640, TFT or STCam carrier |
SpeakerTone | A tone close to 1 kHz from a looped buffer, one second on and one off | BSP_AUDIO_OUT_Init, Play, Mute, UnMute | TFT carrier |
MicrophoneLevel | A level bar with the RMS and peak of each buffer, ten times a second | BSP_AUDIO_IN_Init, BSP_AUDIO_IN_Record and the IN callbacks | Neuro N6 |
LcdColourBars | Eight colour bars on the panel, shifting one place each second, from a 768 KB frame buffer in PSRAM | BSP_LCD_Init, ConfigLayer, FillRect, DisplayOn | TFT carrier |
LcdCameraPreview | The camera on the panel at 800 x 480: the capture pipe writes RGB565 straight into the frame buffer the display scans out | BSP_CAMERA_SetCarrier, Init, ConfigPipe, Start; BSP_LCD_* | TFT carrier |
ReadThermal | The thermal camera's centre, coldest and hottest temperatures in degrees Celsius, once a second | BSP_THERMAL_PowerOn, Init, VideoStart, GetFrame, SetFlip180 | Thermal carrier |
CheckThermal | Brings the thermal camera up one step at a time (power and reset lines, its answer on the sensor bus, boot, status, commands, identity and video) and prints each step, with a frame drawn in characters every five seconds | BSP_THERMAL_*, BSP_I2C1_IsReady | Thermal carrier |
Camera and video streaming
| Example | Shows | Hardware |
|---|---|---|
Camera_JpegStream_USB | VGA at 60 frames per second, encoded to JPEG by the hardware encoder fed directly from the camera, to Neuro Studio over the USB vendor interface. Also builds under FreeRTOS as two tasks (Appli_FreeRTOS) | OV5640 carrier |
Camera_UvcStream_USB | The same picture as a standard USB video camera: Motion-JPEG, 640 x 480, 60 frames per second on an isochronous endpoint, with the console beside it | OV5640 carrier |
Camera_UvcStream_USB_FreeRTOS | That camera under FreeRTOS, as a USB task and a capture task | OV5640 carrier |
Camera_UvcStream_VD66GY_USB | The VD66GY as a USB camera at 640 x 480 and 60 frames per second, its raw picture finished by the camera pipe with ST's daylight tuning. UVC_CARRIER in main.c selects the carrier | VD66GY on the Thermal or Neuro Vision carrier |
Camera_UvcStream_VD65G4_USB | The same with the one-lane VD65G4 sensor. Its lane swaps, bus address, oscillator and lane rate are constants in neuron6_conf.h | VD65G4 sensor |
Thermal_Stream_USB | The FLIR Lepton to Neuro Studio over the USB vendor interface, about nine frames per second, with a temperature for every pixel, bare metal | Thermal carrier |
Camera_GlobalShutterThermal_USB_FreeRTOS | Everything on the Thermal carrier at once, as four tasks: the VD66GY as VGA JPEG at 60 frames per second, the Lepton with a temperature for every pixel, and the motion and magnetic readings carried on each picture, to Neuro Studio over USB | Thermal carrier |
The USB camera examples set BSP_USB_UVC in neuron6_conf.h. A host opens them as NeuroN6 Camera.
Neural networks
Each network example streams the camera as XGA (1024 x 768) Motion-JPEG and runs a network on the NPU on a centred 768 x 768 square of the picture scaled to the network's input, carrying the results on each frame as metadata, mapped back onto the whole frame. Each needs its network's weights in external flash, written with harness/n6weights.py <model.json> --write (see Middleware).
| Example | Network | Transport | Hardware |
|---|---|---|---|
Camera_Nia416Stream_USB_FreeRTOS | NIA Triad-416 detector at 416 x 416, a box and class name for each of the 80 COCO classes, at 30 frames per second | USB, to Neuro Studio | OV5640 carrier |
Camera_Nia416Stream_WiFi_FreeRTOS | The same detector over Wi-Fi from the board's own access point, NeuroN6-Cam, with the board password, which the console prints, or an access point Neuro Studio stored on the board, on 2.4 GHz. The stream stays on USB until a Neuro host connects over Wi-Fi, and that host finds the board by probe or mDNS, with an optional link key. With NIA_LCD set to 1 in neuron6_conf.h it also shows the camera and the detections on a TFT-W carrier's panel | Wi-Fi or USB | OV5640-W or TFT-W carrier |
Camera_PalmDetect_USB_FreeRTOS | MediaPipe's palm detector at 192 x 192: a box and seven landmarks for each hand. The smallest network example, one model and one post-processor | USB | OV5640 carrier |
Camera_HandLandmarks_USB_FreeRTOS | Two networks: the palm detector finds a hand, then a 224 x 224 landmark model runs on a crop of that hand, made by the auxiliary pipe in hardware at full sensor resolution, for 21 three-dimensional landmarks. Once a hand is found the landmark model aims its own crop | USB | OV5640 carrier |
Camera_YoloV8Seg_USB_FreeRTOS | YOLOv8n instance segmentation at 256 x 256: a box, class and mask for each object | USB | OV5640 carrier |
Camera_YoloV8Pose_WiFi_FreeRTOS | YOLOv8n pose estimation at 256 x 256, 17 body points per person that Neuro Studio joins into a skeleton, from the board's own access point. Built to run unattended: it watches its own tasks and restarts the board on a failure, defining BSP_FaultCallback to do so, and the next start reports why | Wi-Fi | OV5640-W carrier, or TFT-W with BSP_CAMERA_DEFAULT_CARRIER set to BSP_CAMERA_CARRIER_INVERTED in neuron6_conf.h |
The two YOLOv8 networks are under AGPL-3.0, which reaches a product built from them, so each example's main.c is AGPL-3.0 as well, and the examples also carry ST software under SLA0044. Each of the two examples carries a RESTRICTED-LICENCE file. harness/compile.sh and harness/examples/cubebuild.sh --all skip them unless NEURON6_BUILD_RESTRICTED=1 is set; naming one to cubebuild.sh, or importing it into STM32CubeIDE, builds it like any other example. Their READMEs set out the licence terms.
Wi-Fi, TLS and BLE
These examples need the MAYA-W476 module of the -W carriers and its firmware in external flash at 0x91E00000.
| Example | Shows |
|---|---|
WiFiApi_FreeRTOS | A console over the whole Wi-Fi API and lwIP's sockets: hosting and joining networks with WPA2 or WPA3, the board password (pass), addressing, scanning, power save, name lookup, network time, stored settings, the link key, and TCP and UDP sockets. Each command is one or two library calls, listed at the top of main.c. bt, btinfo, btscan and btadv bring BLE up on the same module, and btpower reads back the BLE transmit power the controller uses |
WiFiTls_FreeRTOS | An HTTPS server on port 443 with a key and certificate the board makes at every start, serving a status page, JSON and LED control, and an HTTPS client that accepts a server only if its certificate chains to Let's Encrypt's roots, is in date and names it. It joins the network stored on the board or hosts NeuroN6-TLS, WPA3 with WPA2 beside it, with the board password. The board is reached by its address, and the client needs a network with internet access for the time |
BleBeacon_FreeRTOS | A non-connectable BLE beacon named Neuro-N6, with a counter in its manufacturer data, on neuron6_bt and HCI commands alone |
BlePeripheral_FreeRTOS | A device a phone connects to and pairs with, on the Apache NimBLE host: Device Information, Battery, a Neuro N6 service with the LED, the button and the acceleration, and a Nordic UART Service that echoes. Writing the LED or the UART needs an encrypted link. Pairing uses LE Secure Connections, Just Works by default or a passkey with PAIRING_WITH_PASSKEY |
Console
BSPTest is a USB console with one command per BSP module, each bringing its module up and printing what it reads, from the LEDs, sensors and header pins to the camera at each resolution, the encoder, the NPU and the radio. It builds bare metal and under FreeRTOS (Appli_FreeRTOS).