Rust SDK for embedded IoT development
Implementing the Hydrogen Protocol is relatively simple; creating secure, low-power embedded firmware is not. To support device designers, the Hydrogen Plumbing project is developing a cross-platform Rust SDK that supports application and protocol development on nearly any Arm or RISC-V device.
The Hydrogen Protocol SDK provides modular abstraction layers for MCUs, network interfaces, and protocols. Modify code to swap in new network chipsets or upgrade processors without a complete firmware rewrite or dependencies on vendor-specific SDKs.
Multitasking + async/await without RTOS
Robust asynchronous code is crucial for IoT applications to free up processors or reduce power consumption while waiting on external network events. The Hydrogen Protocol SDK uses Embassy, an embedded application development framework that enables Rust's async/await functionality and safe, simple multitasking without an embedded RTOS kernel. This design reduces the footprint of embedded firmware and eliminates the need for complex code based on MCU-dependent interrupts.
/* Embedded Hydrogen SDK example */
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use hydrogen::adapter::{Sidewalk, LoRa, LoRaWAN, Cellular};
// payload
const MSG_SIZE:usize = 4;
const HEARTBEAT_MSG:[u8; MSG_SIZE] = [0x2d, 0x2c, 0x2b, 0x2a];
// lora wan credentials are stored on secure element
const LORA_WAN_PROFILE:u8 = 0x3;
// async heartbeat task
#[embassy::task]
async fn heartbeat() {
// init adapters
// credentials are generated at build and stored on secure element
let mut sidewalk = Sidewalk::new([Sidewalk::Connection::BLE]);
let mut lora = LoRa::new(LoRa::Connection::US_SF7_BW250);
let mut lora_wan = LoRaWAN::new(&lora, LORA_WAN_PROFILE);
let mut nbiot = Cellular::new(Cellular::Connection::NBIoT);
// send heartbeat message
loop {
// Hydrogen Protocol encapsulated in Amazon Sidewalk message
sidewalk.send(HEARTBEAT_MSG, MSG_SIZE);
// Hydrogen Protocol message over LoRa
lora.send(HEARTBEAT_MSG, MSG_SIZE);
// Hydrogen Protocol encapsulated in LoRaWAN message
lora_wan.send(HEARTBEAT_MSG, MSG_SIZE);
// Hydrogen Protocol over NB-IoT with native IPv6 support
nbiot.send(HEARTBEAT_MSG, MSG_SIZE);
// sleep
Timer::after(Duration::from_secs(5)).await;
}
}
#[embassy::main]
async fn main(spawner: Spawner) {
// spawn async heartbeat task
spawner.spawn(heartbeat()).unwrap();
// main application...
}
Why Rust?
While Rust's memory safety offers obvious advantages (and much-needed protection) for embedded applications, Rust's advantages accelerating embedded firmware development might be less well known.
The Rust compiler's ability to re-target code for multiple processor architectures and its growing infrastructure for managing hardware abstraction layers means a single toolset and codebase can deploy on Arm7, Arm8, or even RISC-V MCUs. The Hydrogen Protocol SDK also builds on probe-rs, a firmware deployment and debugging framework that eliminates dependencies on vendor-specific device IDEs and programming interfaces.