
I've been writing C for embedded systems long enough that I stopped thinking about most of its footguns — I just work around them out of habit. Null pointer here, a buffer that might overrun there, an interrupt that touches shared state without a lock. You learn to feel for the edges. So when a few people on my team started bringing up Rust in random conversations over the last year, I figured I owed it an honest look instead of a reflexive shrug. This isn't me announcing anything about what Siliqs firmware runs on — it's just me spending some weekend hours with embedded-hal and trying to figure out what the fuss is about.
What Rust actually gets right
The headline feature is memory safety without a garbage collector, and for embedded that combination matters a lot. A GC is a non-starter on a microcontroller with limited RAM and no tolerance for unpredictable pause times — so most of the "safe systems language" options collapse to basically just Rust. The borrow checker enforces, at compile time, that you're not aliasing mutable memory in ways that cause use-after-free or data races. In C, I catch that class of bug by memory, discipline, and static analysis tools bolted on after the fact. In Rust, the compiler simply won't build the code.
The type system is the other thing that impressed me more than I expected. Rust makes you deal with the "what if this fails" case explicitly — Option and Result types instead of a return code you can silently ignore. Enums that actually enforce exhaustive matching. It's the kind of thing where the compiler nags you before the bug reaches a customer site, rather than a debugger showing you three weeks later that some code path never checked for a sensor timeout.
And the tooling is genuinely modern. cargo as a package manager and build system beats hand-rolled Makefiles and vendored SDK trees in almost every way I can think of. embedded-hal gives you a set of traits for GPIO, SPI, I2C, UART that peripheral crates implement against, so in theory you can write driver code that isn't glued to one specific chip's HAL.
Where the friction is real
That "in theory" is doing some work, though. The embedded Rust crate ecosystem is smaller than C's — decades smaller. If you need a driver for some slightly obscure RS485 transceiver or an oddball sensor, there's a real chance nobody has written a embedded-hal-based crate for it yet, and you're the one writing it. In C, there's a much better chance a vendor SDK or some engineer's forum post already solved it, warts and all.
Then there's the learning curve. My team is fluent in C — genuinely fluent, the kind where debugging a stack corruption issue at 2am is second nature. Rust's ownership model is not something you pick up in an afternoon. Lifetimes, borrowing, the async story in embedded Rust (which is still evolving) — there's a real ramp, and ramp time has a cost when you're also shipping product.
So, rewrite or not?
Here's where I've landed, personally: a wholesale rewrite of a working, field-proven C codebase is almost never worth it. The risk-reward is bad — you're trading known bugs you've already found for unknown bugs in a rewrite, in exchange for safety guarantees on code that was already stable. That math doesn't work.
What does seem worth exploring is incremental adoption — writing a new, isolated module in Rust where the safety guarantees pay for themselves, and where C interop is well-understood (which it is; Rust's FFI story with C is solid). A new parsing routine for untrusted input over a wire protocol, for instance, is exactly the kind of code where memory safety bugs are historically nasty and where a small, self-contained Rust module could sit next to the existing C without disrupting anything.
To be clear, none of this is a Siliqs roadmap item — I'm not proposing we touch the RS485/Modbus stack or the LoRa mesh firmware. I'm just a firmware engineer who spent some evenings with a language I'd been curious about, and came away thinking it's a genuinely good tool for specific jobs, not a strictly-better replacement for C. I'll probably keep poking at it on the side.

我寫嵌入式 C 寫得夠久,久到大部分的坑我已經懶得多想,純粹靠習慣繞開。這裡一個 null pointer,那裡一個可能溢位的 buffer,還有中斷程式碼在沒上鎖的情況下碰共享狀態。你會慢慢練出一種感覺邊界的直覺。所以當團隊裡有幾個人這一年陸續提到 Rust,我覺得該認真花點時間看一下,而不是反射性地聳肩帶過。這篇不是在宣布 Siliqs 韌體要換什麼——純粹是我花了幾個週末摸 embedded-hal,想搞清楚大家在興奮什麼。
Rust 真的做對的地方
它的招牌賣點是「沒有 garbage collector 的記憶體安全」,這個組合對嵌入式來說很重要。GC 在記憶體有限、又不能容忍不可預測暫停時間的 microcontroller 上基本上是不可行選項,所以大部分「安全系統語言」的候選名單一下子就縮到剩 Rust。Borrow checker 會在編譯期就強制檢查你有沒有以會導致 use-after-free 或資料競爭的方式對可變記憶體做別名操作。在 C 裡,我是靠記憶、紀律,還有事後補上的靜態分析工具去抓這類 bug;在 Rust 裡,編譯器根本就不讓你 build 過。
型別系統是另一件讓我意外驚艷的事。Rust 強迫你明確處理「如果這裡失敗了怎麼辦」——用 Option 跟 Result 型別,而不是一個你可以默默忽略的回傳碼。Enum 真的會強制你窮盡所有分支去 match。這種東西的好處是編譯器會在 bug 送到客戶現場之前先煩你,而不是三週後某個除錯過程才發現有個路徑根本沒檢查感測器逾時。
工具鏈也確實很現代。cargo 作為套件管理器兼建置系統,在幾乎所有面向都贏過手刻的 Makefile 跟 vendor 塞進來的 SDK 樹。embedded-hal 提供一組給 GPIO、SPI、I2C、UART 用的 trait,讓周邊裝置的 crate 去實作,理論上你可以寫出不綁死在特定晶片 HAL 上的驅動程式碼。
摩擦點也是真的
「理論上」這三個字背後藏了不少功夫。嵌入式 Rust 的 crate 生態系比 C 小——小了幾十年份的積累。如果你需要一顆稍微冷門的 RS485 收發器或某個怪感測器的驅動,很可能根本沒人寫過基於 embedded-hal 的 crate,你就得自己動手。換成 C 的話,通常有更高機率廠商 SDK 或某個工程師的論壇貼文已經先解過這題了,即便寫得不太漂亮。
再來是學習曲線。我的團隊對 C 非常熟——熟到半夜兩點在追 stack corruption 都算基本功。Rust 的 ownership model 不是花一個下午就能上手的東西。Lifetime、borrowing,還有嵌入式 Rust 的 async 故事(目前還在演進中)——這條坡道是真實存在的,而爬坡的時間在你同時還要出貨的情況下是有成本的。
那到底要不要重寫?
我個人的結論是:把一個已經在現場驗證過、穩定運作的 C codebase 整個重寫,幾乎不划算。風險報酬比不好——你是拿已知、已經抓出來的 bug,去換一個重寫版本裡未知的 bug,而換來的安全保證卻是套在原本就已經穩定的程式碼上。這筆帳算不過來。
比較值得探索的是漸進式採用——在新的、獨立的模組裡寫 Rust,讓安全保證能真正發揮價值,同時 Rust 與 C 之間的 interop 已經算成熟(確實如此,Rust 的 C FFI 故事很扎實)。舉例來說,一個處理未受信任輸入的新解析程式,正好是那種歷史上記憶體安全 bug 特別麻煩的程式碼,適合用一個小而獨立的 Rust 模組放在既有 C 旁邊,不打擾原本的架構。
要說清楚,這些都不是 Siliqs 的路線圖項目——我不是在提議去動 RS485/Modbus stack 或 LoRa mesh 韌體。我只是一個花了幾個晚上研究一個一直好奇的語言的韌體工程師,得到的結論是它對特定工作來說確實是個好工具,但不是能全面取代 C 的「更好的選擇」。我大概會繼續私下玩下去。