Skip to content

STM32 Example Code

Note: These are legacy C reference examples. For new development, use the Rust SDK examples with the Rust SDK instead.

C example code for using the Xylolabs API on STM32 microcontrollers.

File Structure

File Description
wb55_wireless_example.c STM32WB55 BLE sensor node, XMBP over BLE to gateway

Design Principles

HAL-Based, CubeMX Compatible

All examples use the STM32 HAL library generated by STM32CubeMX. No LL (low-level) register access is required. This makes the code portable across STM32 families with minimal changes to peripheral initialization code.

// HAL usage example
HAL_I2S_Receive_DMA(&hi2s1, (uint16_t *)dma_buf, DMA_BUF_SAMPLES);
HAL_UART_Transmit(&huart1, at_cmd, strlen(at_cmd), HAL_MAX_DELAY);
int16_t adc_raw = HAL_ADC_GetValue(&hadc1);

Static Memory

No malloc/free is used. All buffers are static globals sized at compile time. STM32 targets have limited RAM (WB55: 256KB); static allocation prevents heap fragmentation in long-running deployments.

XAP Default Codec

XAP (LC3-based) encoding requires a hardware FPU (Cortex-M4F or better) and at least ~64KB of RAM. The STM32WB55 (256KB RAM, Cortex-M4F) meets these requirements and uses XAP as the default codec for 4ch ADC audio at 48 kHz.

LTE-M1 via UART AT Commands

STM32 communicates with the cellular network through an external LTE-M1 modem connected via UART. AT commands follow the 3GPP standard with modem-specific extensions (Quectel BG96, SIM7080, etc.).

// AT command sequence for HTTP POST
HAL_UART_Transmit(&huart1, "AT+QHTTPCFG=\"contextid\",1\r\n", ...);
HAL_UART_Transmit(&huart1, "AT+QHTTPPOST=...\r\n", ...);
HAL_UART_Transmit(&huart1, xmbp_buf, packet_len, ...);

Legacy C Build

STM32CubeIDE

  1. Open STM32CubeIDE and create a new STM32 project for your target (WB55, WBA55, U585)
  2. Configure peripherals in CubeMX (I2S, UART, ADC, IWDG)
  3. Add the example .c file to the Core/Src/ directory
  4. Add sdk/c/common/include/ and sdk/c/stm32/ to include paths
  5. Build with Project > Build All (Ctrl+B)

CMake (arm-none-eabi)

cmake_minimum_required(VERSION 3.22)
set(CMAKE_TOOLCHAIN_FILE arm-none-eabi-toolchain.cmake)
project(xylolabs_stm32_example C ASM)

add_executable(wb55_wireless
    Core/Src/wb55_wireless_example.c
    Core/Src/stm32wbxx_hal_msp.c
    Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal.c
    # ... other HAL sources
)

target_include_directories(wb55_wireless PRIVATE
    Core/Inc
    Drivers/STM32WBxx_HAL_Driver/Inc
    sdk/c/common/include
    sdk/c/stm32
)

target_compile_definitions(wb55_wireless PRIVATE STM32WB55xx USE_HAL_DRIVER)

Common LTE-M1 Modems

Modem Interface AT Command Set
Quectel BG96/BG95 UART AT 3GPP + Quectel extensions
SIMCom SIM7080G UART AT 3GPP + SIMCom extensions
u-blox SARA-R4/R5 UART AT 3GPP + u-blox extensions
Nordic nRF9160 SPI/UART AT or native SDK

API Documentation Reference

  • API Reference -- XMBP protocol, ingest sessions, audio uploads, API key management, device management