This project demonstrates how to use Anjay Lite in a bare-metal application on the STM32 Nucleo-U385RG-Q development board. The board features an STMicroelectronics microcontroller known for its excellent power efficiency.
Internet connectivity is provided through a BG96 modem. The project includes a simple
modem integration and a network API compatibility layer, implemented in the net.c file,
which provides the required socket API functions.
The security layer is implemented using the mbed TLS library.
This example implements the mandatory LwM2M objects:
as well as an example object:
Temperature data is read from the MCU’s internal temperature sensor.
- STM32 Nucleo-U385RG-Q development board
- Cellular modem: Airgain NL-SWDK2 Shield
- USB Type-C cable to connect the development kit to your PC
- A recent Linux distribution (e.g. Ubuntu 24.04)
gitgcc-arm-none-eabi(see details below)cmake- STM32CubeProgrammer with CLI added to your
PATH - A serial monitor application (e.g.
minicom) to view logs
This project was originally developed with the Airgain NL-SWDK2 Shield in mind as a plug-and-play demo. However, most BG96 development kits should work with only minor peripheral configuration changes.
For details, see the tested modules listed under Other Supported Modules.
To use the Airgain NL-SWDK2 Shield:
-
Set the
JP3jumper fromSTLKtoVIN 5Vto power the Nucleo board from the shield’s external supply. -
Mount the shield directly on top of the Nucleo board.
-
Configure DIP switches:
- SW1-1 (ARD1):
ON - SW1-2 (ARD2):
OFF - SW1-3 (Auto-ON):
OFF
This enables D0/D1 pins for UART communication and allows the MCU to control the modem’s power supply.
- SW1-1 (ARD1):
-
Insert a SIM card.
-
Connect an external power supply (5–15V) to the barrel jack on the modem board.
Important: Always connect both antenna cables and securely attach the antennas before powering on.
git clone https://github.com/AVSystem/Anjay-lite-bare-metal-client --recursiveThe project was generated with CubeMX v6.14.0 and STM32Cube FW_U3 V1.1.0, then reorganized.
If you need to change pin or peripheral configuration, the base CubeMX project is provided as a
backup in deps/ST/anjay-lite-bare-metal-client.ioc.
Note: The current project structure is not directly compatible with newly generated CubeMX outputs.
Anjay Lite configuration is handled via cmake, but for convenience static config files are provided in the config directory.
To update settings, edit config/anj/anj_config.h and rebuild the project.
Application-specific configuration options:
- Endpoint name (default:
anjay-lite-bare-metal-client) Override with:-DCONFIG_ENDPOINT_NAME="your_endpoint_name" - APN name (default:
internet) Override with:-DCONFIG_APN="your_apn_name" - PSK identity (default:
anjay-lite-bare-metal-client) Override with:-DCONFIG_PSK_IDENTITY="your_psk_identity" - PSK key (default:
psk) Override with:-DCONFIG_PSK_KEY="your_psk_key"
The system toolchain version of gcc-arm-none-eabi (from apt/dnf) is incompatible due to a
known bug.
Use the official version from ARM Downloads,
version 11.2 or newer.
Make sure its bin directory is in your PATH.
Verify with:
which arm-none-eabi-gccIt should point to the newly installed compiler.
Install dependencies:
sudo apt-get update && \
sudo apt-get install cmake make build-essentialBuild the project:
mkdir build
cd build/
cmake ..
make -jCMake presets are available — run cmake .. --list-presets inside build/ to see them.
The st-flash tool (v1.8.0) does not yet support U3 microcontrollers.
Instead, use STM32CubeProgrammer version 2.19.0 or newer.
Add its bin folder to your PATH. Check the version with:
STM32_Programmer_CLI -vFlash the board:
STM32_Programmer_CLI -c port=SWD mode=UR reset=HWrst -d anjay-lite-bare-metal-client.elf -v -rstThis project supports firmware updates. application.bin file can be used for firmware update, and it is generated after a successful build.
To bump the firmware version (reported to the server), rebuild the application with e.g.:
cmake .. -DCONFIG_FIRMWARE_VERSION=2.0.0 && make -jLogs are sent via the onboard ST-Link at 115200 baud, 8N1.
On Linux, the device is typically available at /dev/ttyACM0 if no other serial devices are connected.
For the debugger to work, add application.elf as a symbol file. Example configuration
for VSCode with Cortex Debug:
{
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceFolder}",
"executable": "./build/Debug/anjay-lite-bare-metal-client.elf",
"request": "launch",
"symbolFiles": [
{
"file": "./build/Debug/application.elf",
"loadAddress": "0x08008000"
}
],
"type": "cortex-debug",
"runToEntryPoint": "main",
"servertype": "stlink",
"stm32cubeprogrammer": "<stm32cubeprogrammer_path>"
},
]
}To connect with the Coiote IoT Device Management Platform:
- Register at https://eu.iot.avsystem.cloud.
- Create a new device.
- Choose PSK security mode
- Use the endpoint name configured in CMake.
Detailed instructions are available here: Adding devices in Coiote IoT
Besides the Airgain NL-SWDK2 Shield, this project has also been tested with the STEVAL-STMODLTE Development Board.
- Wire the module using jumper wires as shown below:
| STM32 Nucleo Pin | Arduino Pin | Eval Modem Pin | Function |
|---|---|---|---|
| PA2 | D0 (RX) | TXDS – Pin 2 | LPUART1_RX – Modem TX |
| PA3 | D1 (TX) | RXDS – Pin 3 | LPUART1_TX – Modem RX |
| GND | GND | GND – Pin 5/16 | Common Ground |
| PA0 | A0 | PWRen – Pin 9 | Modem Power Control |
-
Power the modem:
- Normally via the onboard micro-USB port.
- If needed, provide an external 5V supply via
VCC (Pin 6/15)andGND (Pin 5/16).
-
Using a physical SIM (instead of the onboard eSIM):
- Insert a SIM card.
- Connect both
Sim_Select0 (Pin 8)andSim_Select1 (Pin 18)to GND.
Note: The onboard eSIM is enabled by default. Perform step 3 only if you plan to use a physical SIM card.
This repository is licensed under the Apache License 2.0 and is intended for evaluation and prototyping purposes.
Please note that it includes the Anjay Lite LwM2M Client SDK as a Git submodule.
Anjay Lite is distributed under a dual-license model:
A non-commercial license is available for evaluation and non-commercial use. For commercial use or production deployments, a valid per-SKU commercial license is required.
For details, see the Anjay Lite LICENSE file or visit avsystem.com.
This product bundles Mbed TLS (https://github.com/Mbed-TLS/mbedtls), also licensed under the terms of the Apache License, version 2.0. See mbedtls/LICENSE file for details.
