STM32 IOT01A example

This example application runs out of the box on the STM32 IOT01A development kits. The example can also be compiled with a dfu flag to enable firmware update capabilities.

It uses the on board peripherals such as WiFi and the temperature sensor to send data to an HTTP endpoint such as Drogue Cloud, and (if the dfu feature is enabled) retrieve firmware updates.

There are multiple variants of this kit, so the example must be compiled and run using feature flags.

The example can operate using plain TCP, or using TLS by enabling the tls feature flag.

Prerequisites

Hardware

  • STM32 IOT01A development kit

Software

  • To build the example, you need to have rustup.

  • To flash the example on the device, you need probe-run installed (cargo install probe-run).

  • A Drogue Cloud instance. See drogue-cloud for how to run that, or use the sandbox (requires TLS).

Configuring

Credentials for your local WiFi network will come from these entries in ~/.drogue/config.toml:

wifi-ssid = "..."
wifi-password = "..."

HTTP authentication will come from these entries in ~/.drogue/config.toml:

http-username = "..."
http-password = "..."

For Drogue Cloud, the username/password is stored in this form: device_id@application.

The example config.toml file for connecting to public Drogue cloud sandbox application could look like this:

hostname = "http.sandbox.drogue.cloud" # Replace with your own Drogue Cloud instance if you are not using the sandbox
port = "443"
wifi-ssid = "..."                      # The WiFi network SSID
wifi-password = "..."                  # The WiFi network pre-shared key
http-username = "device1@wifi-workshop"
http-password = "mysecretpassword"

Just enter your wifi details and you should be ready to go.

If you have the B-L4S5I-IOT01A board, set the following environment variables:

export CHIP=STM32L4S5VI CHIP_FEATURE=b-l4s5i-iot01a

If you have the B-475E-IOT01A board, use the following settings instead:

export CHIP=STM32L475VGTx CHIP_FEATURE=b-l475e-iot01a

Running with plain TCP

You can configure the IP constant to point to any HTTP server to receive events, or you can use drogue cloud locally. For simplicity, start a local HTTP server in python that echoes the HTTP payload back:

curl -s https://raw.githubusercontent.com/drogue-iot/drogue-device/main/apps/drogue-temperature/server.py | python3

To run the firmware using a given chip:

DEFMT_LOG=info PROBE_RUN_CHIP=${CHIP} cargo run --release --features ${CHIP_FEATURE},debug --no-default-features

Running with TLS

When the tls flag is enabled, the example is configured to use the Drogue Cloud sandbox. To use this example with your own Drogue Cloud instance, you need to edit the HOST and PORT constants in src/main.rs.

To run the firmware using a given chip:

DEFMT_LOG=info PROBE_RUN_CHIP=${CHIP} cargo run --release --features ${CHIP_FEATURE},tls,debug --no-default-features

Once flashed, the device will reset and attempt to join the WiFi network. If successful, it will print a message to the RTT log. You can then press the blue/user button on the board to send a test message from the device.

Enabling firmware update capabilities

For this step, we need to flash a bootloader as well as the application. When the dfu flag is enabled, the example is configured to enable firmware updates using Drogue Cloud sandbox.

Flashing the bootloader

To flash the bootloader for a given chip:

cargo flash --manifest-path ../bootloader/Cargo.toml --release --features ${CHIP_FEATURE} --no-default-features --chip ${CHIP}

Running the application

To run the application using a given chip:

DEFMT_LOG=info PROBE_RUN_CHIP=${CHIP} cargo run --release --features ${CHIP_FEATURE},tls,dfu,debug --no-default-features

Once flashed, the device will reset and attempt to join the WiFi network as before, in addition to polling the Drogue Cloud for firmware update commands.

Troubleshooting

If you’re experiencing problems, try setting the VID:PID values to that of your probe (you can find that from lsusb once your board is powered).

<ENV> cargo run <ARGS> -- --probe <VID>:<PID>

Additionally, the B-L4S5I-IOT01A board can have issues with running probe multiple times, leading to errors like

Error: An error with the usage of the probe occured

Caused by:
    Operation timed out

If you experience that, the best way to restore the board is to reconnect it and use st-flash utility to write any binary to it, like

st-flash write ../target/thumbv7em-none-eabihf/release/iot01a-wifi.d 0x8000000

After reconnecting the board again, you should be able to use cargo run again.