TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Has any Rust developer moved to embedded device programming?

89 点作者 detuks超过 2 年前
Hi! Was wondering if any Rust developer have moved to embedded land. Did you switch to C&#x2F;C++ or stayed with Rust? What MCU did you work with? Any tips?<p>I have good understanding of Rust and soon will need to program ESP32 chip. Write a driver and and http&#x2F;tcp api on it.<p>Currently I jave seen mixed messages about Rust in embedded. Ecosystem moves fast, but semms like old C&#x2F;C++ devs stay with their lang. So I&#x27;m curious what Rust devs have to say abou it.

18 条评论

reynoldsbd超过 2 年前
I&#x27;m fortunate enough to have just landed on a new team working with embedded Rust. Here are some of my takes, in no particular order.<p>The language and ecosystem have come a long way in a very short time. It&#x27;s easy to use safe `no_std` Rust on the stable toolchain for 98% of your code, and there are crates available for all kinds of things like memory management, register access, or even async runtimes.<p>Compared with C, Rust is absolutely a game changer in terms of reliability&#x2F;safety&#x2F;productivity. Every line of C code is a potential liability, because humans make mistakes. Having a compiler that smacks me down is invaluable; it results in a safer and more reliable program, and it helps me get it right the first time. Like many others, my experience with Rust is nearly always &quot;if it compiles, it works&quot;. This is _especially_ valuable for embedded programming, because debugging is often way harder when working with hardware.<p>One major drawback is lack of support&#x2F;engagement from hardware vendors. They pretty much assume you are using C, and all of their IDEs&#x2F;SDKs&#x2F;codegen tools&#x2F;whatever are written with that assumption. This probably isn&#x27;t going to change any time soon (ever?). What this means is that if you want to use Rust, you&#x27;ll be on the hook for figuring out a lot of low-level things like linker scripts, boot sequence, or memory&#x2F;clock initialization. Often this means reading or reverse-engineering the vendor&#x27;s SDK to figure out how these work. If you&#x27;re working at a big company on a serious product, you might have done this anyways. But for a hobbyist, this can be a huge barrier.
评论 #32498617 未加载
评论 #32509705 未加载
评论 #32498135 未加载
quake超过 2 年前
I&#x27;ve done some small embedded Rust applications on various STM32 and RP2040 boards. I&#x27;ve been doing embedded dev in C professionally for 7 years and Rust full-time for 2.5, mix or system and bare metal.<p>It&#x27;s very hard to unlatch your brain from some of the common C&#x2F;C++ embedded principles of static context variables and thinking of the hardware registers as &quot;owned&quot; memory, which you have to do in Rust. The auto-generated HAL crates aren&#x27;t that great unless you&#x27;re using the most common ones like stm32f4 or RP2040. Even then, it&#x27;s hard to create a portable device driver without delving into generic-hell.<p>That all said, the ecosystem is moving fast, and a lot of my gripes above are just a product of the embedded rust ecosystem being very new in comparison to C. I do love rtic as a framework, and while I&#x27;ve given embassy a try I think it&#x27;s trying to do too much aside from being a good async runtime, it should just focus on the runtime and not with stuff like creating its own entire HAL. Hubris and humility are fascinating but I just haven&#x27;t gotten around to tinkering with them yet.<p>Lots of good tooling too, and the fact that most of your original C&#x2F;C++ debugging tools are compatible with rust binaries is just the icing on the cake.<p>I know that there&#x27;s the whole Ferrocene project, but until that produces results, stick with C if you&#x27;re doing safety-critical applications, especially if they need to be certified
评论 #32496227 未加载
thenewwazoo超过 2 年前
I had the pleasure of writing embedded Rust in the automotive space for a couple of years about 4 years ago, and it was an absolute game-changer even at that early stage. Being able to write generic drivers that I could easily test outside an embedded context sped development up an incredible amount. Writing the business logic wasn&#x27;t necessarily any easier with Rust than C, but anything having to do with hardware (and especially concurrency) turned into a if-it-compiles-it&#x27;s-correct affair.<p>At that time, I was pushing the cutting edge of what was possible alongside what&#x27;s now the Embedded WG, but the job didn&#x27;t work out. I am <i>incredibly</i> interested in finding another embedded Rust role, but have had nothing fall into my lap (my current FAANG handcuffs are quite golden). If you have the opportunity, you should absolutely take it.<p>C code is a liability, but sometimes liabilities are worth the risk if the payoff is good enough. If you want to move to Rust, you will need to show how the tradeoff changes in Rust&#x27;s favor. Sometimes that&#x27;s easy, sometimes that&#x27;s hard. It depends entirely on your industry and product. For my part, I absolutely believe it is already a competitive differentiator.
garphunkle超过 2 年前
I&#x27;ve been working in embedded for 5 years and am curious how rust could solve my biggest headaches:<p>* Managing build configurations - I use CMake to build a single application for multiple hardware platforms. This is accomplished almost exclusively through linking, e.g., a single header file &quot;ble-ncp-driver.h&quot; with multiple &quot;ble-ncp-driver.cpp&quot; files for each target platform. I call this the &quot;fat driver&quot; approach which has proven to be easier to work with than creating a UART abstraction or ADC abstraction. Does rust&#x27;s package system address this?<p>* Automated device testing - fluid leaks are similar to bugs in software. They are systemic in nature and cannot be easily understood through static analysis. We spent equal time maintaining a test bench as product development.<p>* Preemptive operating systems - more trouble than they are worth. Often, devs get bogged down writing messages queues to pass items between task contexts and timing analysis requires detailed event tracing.<p>Given I don&#x27;t see teams struggle with memory ownership (easy to do if you never, ever malloc), what else can rust bring to embedded dev?
评论 #32495703 未加载
评论 #32495245 未加载
评论 #32495450 未加载
评论 #32516609 未加载
评论 #32495668 未加载
评论 #32495364 未加载
评论 #32495316 未加载
gbin超过 2 年前
I started to explore the area, mostly arm based (rp2040 and STM) and a little bit of ESP32.<p>Tool chain wise:<p>ESP32 support is very recent and still based on the C tool chain and this makes it very fragile (you can break your environment easily and it is never clear how to recover except recompiling the entire tooolchain from 0)<p>Arm is a little better because the support is native.<p>The community is trying to make a generic embedded Hal platform API and implement it for specific devices. And it is pretty bad: almost no documentation, very few examples, tons of autogenerated code where you need to come back to the C world to understand the actual concepts.<p>Once you start to get going Rust is a blast to program in and the generated code is pretty efficient.<p>A small project I shared to help people starting on a raspberry pi clone (lilygo): <a href="https:&#x2F;&#x2F;github.com&#x2F;gbin&#x2F;rp2040-mandel-pico" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gbin&#x2F;rp2040-mandel-pico</a>
maneesh超过 2 年前
Our company builds a wearable device using an NRF5x chip, and our firmware is written in C. We are moving to Rust for our newest device, in order to run graphical output and RT operations. It is looking pretty sweet!
评论 #32494858 未加载
junon超过 2 年前
Not exactly embedded but I&#x27;m writing an operating system kernel in Rust, having done so previously with C.<p>I love it so far. There are still some rough edges in the tooling, but overall I&#x27;m very happy. The resulting binaries are much larger than C projects, but I&#x27;m also opting into a lot of functionality you probably wouldn&#x27;t always need in smaller environments.
评论 #32494893 未加载
ostenning超过 2 年前
The Rust ESP32 ecosystem isn&#x27;t as mature as STM32 unfortunately, I would be cautious about beginning a production ESP32 product written in Rust.<p>STM32s however are a different story... I&#x27;m using the stm32h7 microcontroller with Rust in a production product. Its really great.<p>Hopefully the ESP32 support matures sooner rather than later, which I think would be great for more Rust IoT uptake and Rust embedded as a whole.<p>I would love to see Rust become the defacto standard in embedded development.
AlbertoGP超过 2 年前
I took a look and realized that I wasn’t yet ready for it.<p>Last year a recruiter contacted me about assisting Volkswagen transition from C++ to Rust for their CARIAD embedded automotive platform.<p>My experience with Rust is only on application development, not embedded systems, but the job sounded quite interesting and I took a look at Embedded Rust. After discussing it a bit with them, my response to them was to recommend going with someone else, because the way Rust is used in that domain amounts to almost a different language and my experience was not adequate. I said that what they needed was someone that had battled with those arcane details already, not a Rust generalist.<p>I do think Rust would be good for such systems, but that at the moment it’s weighted down by architecture astronautics.
contingencies超过 2 年前
Not a Rust dev but I like the language. I&#x27;ve learned embedded over the last few years. I used to hate C and avoid it like the plague. On a good day now I kind of enjoy it, in some sick perverse twisted way. I&#x27;d say in general the embedded space is more project-centric in general thus new stacks are not at as significant a disadvantage as in backend land at the lower end of the project complexity and regulatory ingress spectrum. You will see gaps in terms of device driver availability and maturity and integration level with silicon vendor toolkits. However, since most projects do not use too much exotic hardware writing one or two I2C or SPI drivers won&#x27;t take forever, you&#x27;re probably OK to go Rust. But realistically, for complex stuff, you&#x27;re going to run in to wall after wall that will eat time and money. If you can meld C&#x2F;C++ and Rust in one binary or reach godlike device driver implementation status then you&#x27;ll be relatively free of issues but while I&#x27;m sure that&#x27;s possible once you&#x27;re at the point where you&#x27;re writing the whole stack you might be best to look for a job with a silicon vendor overhauling their toolkit for Rust support, since base library and code generation will help shift more product than any one shop. Try writing to TI&#x2F;NXP&#x2F;Renesas&#x2F;STM&#x2F;Freescale&#x2F;Microchip&#x2F;NXP&#x2F;Atmel&#x27;s HR department and asking for scope: I&#x27;d be surprised if you received zero interest.
ecesena超过 2 年前
We rebuilt solo v2 [1] firmware in rust, compared to v1 in C [2]. I haven&#x27;t written any rust code so take what I say with a grain of salt, but generally speaking I think our experience has been very positive.<p>Rust forced us to structure the code a bit better, that makes it easier for multiple people to collaborate on it. Slightly harder learning curve, but that wasn&#x27;t an issue in our case.<p>In the history of solo, we had a couple security bugs that rust would probably have prevented, so this is a plus for the language. Moreover, the cryptography community is pretty active and we can leverage solid + well maintained libraries.<p>One downside has been collaboration with other OS projects. When we had the C firmware and fido2 library, in less than 1 year we&#x27;ve got 3 other products embedding our code and also a couple manufacturers making demos with it -- a great win. With rust to my knowledge we&#x27;re not there yet, but of course we&#x27;re very positive.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;solokeys&#x2F;solo2" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;solokeys&#x2F;solo2</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;solokeys&#x2F;solo1" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;solokeys&#x2F;solo1</a>
dcz_self超过 2 年前
I&#x27;m not a Rust-only developer, but a general systems programmer, and my foray into embedded is limited to a side project (see my profile), but no, I haven&#x27;t switched to C&#x2F;C++. Rust brings too much goodness to give it up.<p>Rust-embedded is an easy ecosystem to work with (if immature), and if you want more flexibility, Tock OS [0] is trying to cover that space (also immature, but I&#x27;m working on it).<p>[0] <a href="https:&#x2F;&#x2F;www.tockos.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.tockos.org&#x2F;</a>
adolph超过 2 年前
I’ve been super curious about both Rust and ESP. It seems like Espressif is interested enough to commission a Rust dev board (ESP32-C3-DevKit-RUST-1) and training using it.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;esp-rs&#x2F;esp-rust-board&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;esp-rs&#x2F;esp-rust-board&#x2F;</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;ferrous-systems&#x2F;espressif-trainings" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ferrous-systems&#x2F;espressif-trainings</a>
评论 #32496162 未加载
phoehne超过 2 年前
I recently moved to an embedded software role. I sought out this move because I love writing code for very small computers, fiddling with registers, Blinky lights, etc. I didn&#x27;t realize how important an <i>accredited</i> RTOS was for many commercial projects. It&#x27;s not really about middle-aged devs being stuck on grungy-old tech. It&#x27;s about being able to support a device for the next 10, 20, or 30 years with a consistent tool chain. This is especially true for devices that have some sort of industry accreditation, like medical devices. It&#x27;s very expensive to get that accreditation and if you change the embedded language, that will probably start the process all over again.<p>That doesn&#x27;t mean there aren&#x27;t companies looking at Rust, because C code is hard to get right. We use a mix of emulators, FPGA simulators, unit testing, static analysis, manual code reviews, and various coding standards to try to avoid introducing a bug. It would be nice to work in a language that took certain classes of memory errors off the table. I&#x27;m sure Rust has some monsters lurking in the shadows, but at the level I&#x27;ve tried to adopt it, I haven&#x27;t found them.<p>With that out of the way, I like Rust. I think there&#x27;s good quality basic tooling like IDE support and debugging. but It&#x27;s a little bit of a crap shoot as to what board support you can get. A lot of times I&#x27;ve been able to get by with &quot;close enough&quot; HAL crates. Chances are you will find a board but may have to write a driver for a particular device. (By driver I mean something that understands how that device works and knows what bits to write at which address to set registers, or I2C commands, or whatever). It&#x27;s not as bad as it sounds, but you will learn to read spec sheets. Many CPU&#x27;s are a mix of features supported by the IP the chip manufacturer decides to put into their product. Like they might not support some optional components in that specific chip.<p>Be careful about ESP32. I believe some are based on the Extensa cores and I think some are based on RISC-V. Those are different architectures. I agree with the people below that recommended STM32 which is a more predictable ecosystem since they&#x27;re all ARM. M0, M3, M4, etc. are all well understood, highly supported cores. ST&#x27;s licensing (I believe) requires you get a license for the IP before you can distribute a commercial product based on their architecture. I haven&#x27;t looked at Espressif&#x27;s restrictions.
_whiteCaps_超过 2 年前
Oxide has an embedded Rust RTOS:<p><a href="https:&#x2F;&#x2F;hubris.oxide.computer&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hubris.oxide.computer&#x2F;</a>
LaffertyDev超过 2 年前
I&#x27;m a rough beginner in the embedded space. Would love to use Rust, but in my experience it becomes more hassle than its worth for some of the more off-the-shelf controllers. Would love to find more knowledge &#x2F; tutorials to help guide me in the right direction, though.
jmartin2683超过 2 年前
I write Rust full-time for work and use it on embedded projects for fun. The ecosystem around embedded-hal is great.
nottorp超过 2 年前
Being dependent on any programming language is a trap. For your esp you need intimate knowlegde of the hardware and the language is irellevant.