Skip to content

Conversation

kaspar030
Copy link

This adds an example based on Ariel OS.

Currently WIP, as Ariel likes to keep control of the usb builder, as does postcard-rpc. Ownership conflict.


| EndpointTy | kind | handler |
| ---------- | ---- | ------- |
| PingEndpoint | blocking | ping_handler |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that we should probably pick a different handler for the docs, I need to remove this from my examples too. As of today, ping is built-in to postcard-rpc, so it's confusing to users if there is a "builtin" one and a provided one.

let mut config = embassy_usb::Config::new(0x16c0, 0x27DD);
config.manufacturer = Some("OneVariable");
config.product = Some("ov-twin");
config.serial_number = Some("12345678");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be dynamic and not const - it should use the serial number of the device, e.g. from flash memory or whatever


type AppMutex = embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
type AppDriver = usb::UsbDriver;
type AppStorage = WireStorage<AppMutex, AppDriver, 256, 256, 64, 256>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Ariel have opinions on configurable params like this? For example setting the relevant buffer sizes here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat ... we define env variables for those and set them from the build system. The usb descriptor sizes, we didn't expose yet, though.


/// Helper to get unique ID from flash
pub fn get_unique_id() -> Option<u64> {
// TODO
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ariel has a device id in bytes form (I think platform specific length), this needs wiring up and convert to u64.


pub struct Context;

type AppMutex = embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On ariel, any application might run in isr, one-thread or multi-threaded mode, so I tend to default to the criticalsection mutex.

loop {
// Somehow at least on nrf52840dk, this is needed, otherwise the
// `ariel_os_embassy::init_task()` task starves.
Timer::after(Duration::from_millis(100)).await;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stumped me. Somehow the other task (on the same executor) is starved without this delay here, and USB doesn't enumerate anymore.

pub cell: StaticCell<Mutex<M, EUsbWireTxInner<D>>>,
}

/// A helper type for `static` storage of buffers and driver components
Copy link
Author

@kaspar030 kaspar030 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is WireStorage without the USB state. The impl is copy&pasted and then I removed some lines.

A lot can be deduplicated here, also in the original implementation. Ideally they'd all share snippets. It took me some time to get an idea of what's postcard specific and what not. Also, the poststation variant has only some small differences, which are IMO hard to spot.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally they'd all share snippets

Or maybe the no-usb-state version could be a field of the original one.

// In principle you might want to call msos_feature() just on a specific function,
// if your device also has other functions that still use standard class drivers.

// TODO: increase ariel MSOS descriptors
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO (Ariel defaults for MSOS are too small. Works without on Linux.)

@jamesmunns jamesmunns added the Q2 '25 Triage Items tracked as part of https://github.com/jamesmunns/postcard/issues/241 label Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q2 '25 Triage Items tracked as part of https://github.com/jamesmunns/postcard/issues/241
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants