r/rust • • 2h ago

Embedded std?

I was wondering if there were any projects like micro python to port std in to make a barebones os designed for microcontrollers? I understand that the std relies on OS level syscalls, so can we do something like implement a basic fat32 file system to accommodate certain write or read requests. In general this would be used to run std in projects without a OS? Does this already exist, and how hard would it be to make a basic version?

9 Upvotes

6 comments sorted by

16

u/Agile_Cost_5141 2h ago

You're basically describing what the `std` crate does when you target `thumbv7em-none-eabihf` or similar. A lot of folks don't realize that `std` works on bare metal just fine as long as you provide the linker script and a few symbols. The filesystem part is the real sticking point though.

I messed with this a while back trying to get `std::fs` working on an STM32 with an SD card. Even a minimal FAT32 implementation that plays nice with the standard library's expectations is a mountain of edge cases. Stuff like directory traversal, long file names, handling power loss during writes. It snowballs fast.

The Rust embedded working group has been chipping away at stuff like `embedded-nal` for networking and `embedded-storage` for flash, but nobody's really gone all-in on a full `std` shim layer for microcontrollers. Probably because the people who need bare metal std are a pretty small group compared to the async/RTOS crowd. If you're serious about it, looking at how Redox OS handles syscall stubs might be a decent starting point since they already abstracted a lot of that for their microkernel.

13

u/film42 2h ago

My wife (who works in healthcare) saw the title of this post and asked β€œwhat are you reading???”

1

u/AstraKernel 33m ago

Lol πŸ˜…

2

u/No_Frame3855 2h ago

Yeah what other people have said + Espressif has their own std for embedded

2

u/AstraKernel 2h ago

I'm not an expert, but IMO "std" is not usually necessary for MCU projects. ESP-HAL does support "std", but I rarely use it. I generally prefer using the HAL with "no_std".

Afik, a lot of what you can do with micro python, and much more, is already possible with "no_std".

For a SD card, there is a crate that supports FAT32.

If you don't mind me asking, what is the purpose?