HowTo: Rust on the photon

TL;DR

Hello Particle community,

I’m here to present some of the recent work I’ve been doing to add Rust support to the photon.

(Full disclaimer: I’m under contract to improve Rust’s embedded development story and one of the tasks involves adding Rust support to well known development boards and I picked the photon. Yay!)

My focus is making sure that the tooling and development experience for this board is as good as possible on the three major OSes. To that goal I have created a template Cargo project to get you writing code for your photon as quickly as possible. Give it a try! I have successfully tested it on Linux and on Windows and expect that it should also work well on macOS.

I have also been creating a safe API on top of the Firmware API, and already have working part of the Cloud API, the USB Serial API, the delay API and the digital output API. Furthermore, I have created memory safe abstractions for sharing data between the application thread and the cloud functions so all the examples in the project template are written in 100% safe Rust! :tada:

Do let me know if anything doesn’t work for you by opening an issue in this issue tracker. Also let me know if I should prioritize work on some particular API that’s currently missing. And, by the way, you can help me with that: Adding more low level bindings is easy as adding the function signature to this block as explained here; building safe APIs on top of that require some discussion about the invariants we want to preserve and how we want to do error handling so chime in the discussion.

Happy Rusting!

cc @dbrgn @zach

9 Likes

@zachary

2 Likes

Can’t wait to try it!

3 Likes

Wow! Great work! :smiley:

3 Likes

This is awesome, can’t wait to try it out!

If there’s anything you need in our firmware stack to facilitate your work, feel free to make pull requests, or raise opportunities for improvement with @mdma, who I’m sure would love to help.

Once this is fleshed out, I’d love to start a conversation about how we can support it in our cloud compiler so people can build Rust firmware applications without needing to set up a local toolchain.

3 Likes

Thanks for sharing this!!

1 Like

If there's anything you need in our firmware stack to facilitate your work, feel free to make pull requests, or raise opportunities for improvement with @mdma, who I'm sure would love to help.

Will do!

Once this is fleshed out, I'd love to start a conversation about how we can support it in our cloud compiler so people can build Rust firmware applications without needing to set up a local toolchain.

Sure. Sounds like a great idea to me.

I’ve been off the forums for a long time, but I saw this today and I think it’s awesome! Are there any updates to this project @japaric?

@japaric Just curious what ended up happening here. Is the approach feasible? Was there just not enough interest?

@emdash, not enough interest and Particle is growing fast with too many other priorities.

Rats :frowning:

@japaric Would it help if I contributed hardware and time to the cause?

@emdash if you’re interested in what’s happening in the Rust Embedded space, check out https://rust-embedded.github.io/blog/! There’s also an online book: https://rust-embedded.github.io/book/ Since the Photon uses an ARM cortex microcontroller, all this stuff should run on the Photon too.

Of course the problem starts when you’re looking for drivers. There is no Rust driver for the Cypress Wi-Fi chip, for example.

As far as I can tell, the main reason why this effort stalled, was that @japaric et all from the Rust community wanted to build generic solutions which work across the entire Rust Embedded ecosystem, while Particle probably would be interested in tight integration with their own ecosystem. Which makes sense of course, since the Particle ecosystem allows fast prototyping and quick iterations.

So if someone wanted to have good long-term integration of the Photon into the Rust Embedded ecosystem, an embedded-hal compatible WiFi driver for the Cypress chip (independent from the Photon) would be an amazing start. I’m not sure how many binary blobs and confidential datasheets are involved though. However, once a driver were available, high-level libraries can be written quite easily. And it would make the Particle boards quite attractive, since - as far as I know - no other Rust WiFi driver exists right now.

The alternative is generating bindings against the Particle C firmware. But since only Particle products would benefit from that, I’m not sure whether the community would make that effort without someone being paid to do all the hard work.

1 Like

More discussion can be found here: Rust on Particle: development discussion

Thanks for the link, I will definitely read through that discussion.
@dbrgn

Pretty much the one thing Particle offers that I can’t live without is OTA updates via cellular. We’re just not at the stage where we could build that kind of infrastructure in house even if we wanted to. Given that, my short term priorities are confined to the latter approach – targeting rust to the Particle DeviceOS API.

While I am sympathetic to the rust-embedded team’s larger goals, it always seems to be not quite mature enough for my use-case. I would really like to get away from C/C++. Any amount of C/C++ I can port over to Rust would be a win. I feel like every time I think I’m going to be able to switch, there’s one little thing holding it up.