Software/STM32CubeIDE

STM32CubeIDE BSP Examples

The thirty-five example projects of the Neuro N6 board support package, what each shows and the hardware it needs.

intermediate8 min read

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.

ExampleShowsMain functionsHardware
BlinkThe green LED on and off with delay()BSP_LED_Init, BSP_LED_On, BSP_LED_OffNeuro N6
BlinkWithoutDelayThe same without blocking loop(), timed with HAL_GetTickBSP_LED_*Neuro N6
DigitalReadSerialThe USER button's state, ten times a secondBSP_PB_Init, BSP_PB_GetStateNeuro N6
ButtonInterruptButton presses counted by interrupt on EXTI line 8BSP_PB_Init in BUTTON_MODE_EXTI, BSP_PB_CallbackNeuro N6
AnalogReadSerialA0 as counts and millivolts, five times a second, with 1.8 V full scaleBSP_ADC_SetResolution, BSP_ADC_GetVdda, BSP_ADC_ReadChannelNeuro N6
FadePWM on the red LED, with the duty inverted for the active-low LEDBSP_PWM_Init, BSP_PWM_StartNeuro N6
RgbLedThe eight colours of the RGB LED, named on the consoleBSP_LED_*Neuro N6
WireScannerEvery address that answers on the sensor bus, every two secondsBSP_I2C1_Init, BSP_I2C1_IsReadyNeuro N6, with or without a camera carrier
ReadAccelerationAccelerometer and gyroscope in milli-g and millidegrees per second, ten times a secondBSP_MOTION_SENSOR_Init, Enable, GetAxesNeuro N6
ReadMagneticFieldThe magnetometer in milligauss with the field's magnitude, ten times a secondBSP_MOTION_SENSOR_*Neuro N6
ReadDistanceDistance in millimetres and its status from the time of flight sensor, about ten times a secondBSP_RANGING_SENSOR_Init, Start, IsMeasurementReady, GetDistanceOV5640, TFT or STCam carrier
SpeakerToneA tone close to 1 kHz from a looped buffer, one second on and one offBSP_AUDIO_OUT_Init, Play, Mute, UnMuteTFT carrier
MicrophoneLevelA level bar with the RMS and peak of each buffer, ten times a secondBSP_AUDIO_IN_Init, BSP_AUDIO_IN_Record and the IN callbacksNeuro N6
LcdColourBarsEight colour bars on the panel, shifting one place each second, from a 768 KB frame buffer in PSRAMBSP_LCD_Init, ConfigLayer, FillRect, DisplayOnTFT carrier
LcdCameraPreviewThe camera on the panel at 800 x 480: the capture pipe writes RGB565 straight into the frame buffer the display scans outBSP_CAMERA_SetCarrier, Init, ConfigPipe, Start; BSP_LCD_*TFT carrier
ReadThermalThe thermal camera's centre, coldest and hottest temperatures in degrees Celsius, once a secondBSP_THERMAL_PowerOn, Init, VideoStart, GetFrame, SetFlip180Thermal carrier
CheckThermalBrings 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 secondsBSP_THERMAL_*, BSP_I2C1_IsReadyThermal carrier

Camera and video streaming

ExampleShowsHardware
Camera_JpegStream_USBVGA 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_USBThe 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 itOV5640 carrier
Camera_UvcStream_USB_FreeRTOSThat camera under FreeRTOS, as a USB task and a capture taskOV5640 carrier
Camera_UvcStream_VD66GY_USBThe 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 carrierVD66GY on the Thermal or Neuro Vision carrier
Camera_UvcStream_VD65G4_USBThe same with the one-lane VD65G4 sensor. Its lane swaps, bus address, oscillator and lane rate are constants in neuron6_conf.hVD65G4 sensor
Thermal_Stream_USBThe FLIR Lepton to Neuro Studio over the USB vendor interface, about nine frames per second, with a temperature for every pixel, bare metalThermal carrier
Camera_GlobalShutterThermal_USB_FreeRTOSEverything 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 USBThermal 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).

ExampleNetworkTransportHardware
Camera_Nia416Stream_USB_FreeRTOSNIA Triad-416 detector at 416 x 416, a box and class name for each of the 80 COCO classes, at 30 frames per secondUSB, to Neuro StudioOV5640 carrier
Camera_Nia416Stream_WiFi_FreeRTOSThe 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 panelWi-Fi or USBOV5640-W or TFT-W carrier
Camera_PalmDetect_USB_FreeRTOSMediaPipe's palm detector at 192 x 192: a box and seven landmarks for each hand. The smallest network example, one model and one post-processorUSBOV5640 carrier
Camera_HandLandmarks_USB_FreeRTOSTwo 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 cropUSBOV5640 carrier
Camera_YoloV8Seg_USB_FreeRTOSYOLOv8n instance segmentation at 256 x 256: a box, class and mask for each objectUSBOV5640 carrier
Camera_YoloV8Pose_WiFi_FreeRTOSYOLOv8n 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 whyWi-FiOV5640-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.

ExampleShows
WiFiApi_FreeRTOSA 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_FreeRTOSAn 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_FreeRTOSA non-connectable BLE beacon named Neuro-N6, with a counter in its manufacturer data, on neuron6_bt and HCI commands alone
BlePeripheral_FreeRTOSA 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).