Skip to main content

Crate hsm_firmware

Crate hsm_firmware 

Source
Expand description

Mini-HSM firmware entry point.

Boot sequence:

  1. Initialise embassy-rp peripherals.
  2. Configure GPIOs:
    • GP15 input with pull-up : touch button (active-low).
    • GP16 output : green status LED.
    • GP17 output : yellow touch-awaiting LED.
  3. Build the USB-HID stack and split it into reader/writer.
  4. Build the ATECC HAL on I2C0 (SCL=GP5, SDA=GP4).
  5. Spawn the auxiliary tasks: USB run, state machine, animation, touch.
  6. Fire Event::BootComplete so the state machine leaves the boot state.
  7. Enter the dispatch loop in the main task.

ยงstatic_cell instead of static mut

Two pieces of state need to live in static storage so the embassy USB stack can borrow them with a 'static lifetime: the descriptor buffers and the HID class state. The idiomatic way to allocate these without unsafe is [static_cell::StaticCell], which lets the runtime check at boot that the storage is initialised exactly once. The price paid is a one-shot init call returning &'static mut T; the runtime cost is a single atomic flag flip.

Modulesยง

animation ๐Ÿ”’
LED animation task.
channels ๐Ÿ”’
Global communication primitives between firmware tasks.
hal_rp2040 ๐Ÿ”’
ATECC HAL implementation for the RP2040.
state ๐Ÿ”’
State machine task.
tasks ๐Ÿ”’
Async tasks running on the firmware.
touch ๐Ÿ”’
Touch button sampling task.
usb ๐Ÿ”’
USB-HID device stack.

Structsยง

EmbassyClock ๐Ÿ”’
Clock backed by embassy_time::Instant. Provides milliseconds since boot, monotonic, used by the PIN session timeout.

Staticsยง

HID_STATE ๐Ÿ”’
Storage for the HID class state. Kept separate from USB_BUFFERS because State is invariant over its lifetime parameter, which forces it to share a single named lifetime with the device borrow.
USB_BUFFERS ๐Ÿ”’
Storage for the USB descriptor / control buffers. The contents are borrowed by the USB device for the rest of the program. Initialised once at boot via init.

Functionsยง

__cortex_m_rt_main ๐Ÿ”’
__embassy_main ๐Ÿ”’