Most firmware is written in C, and for good reasons. It runs on nearly every chip, it maps closely to the hardware, and almost all vendor code assumes it. Still, C leaves memory safety, concurrency and testability up to the programmer, so developers keep looking at other languages and styles. This article covers two of those options: Go, and functional programming. It explains where each realistically fits in embedded work and where it doesn’t.
If you’re new to firmware in general, start with the overview of embedded firmware development. The C baseline these alternatives get compared against is covered in embedded C programming for microcontrollers.
Go for embedded systems: two different worlds
“Go for embedded” can mean two quite different things, and mixing them up causes a lot of confusion.
Standard Go on embedded Linux
The regular Go toolchain targets operating systems, not bare chips. It works well on embedded Linux devices such as gateways, routers, industrial PCs and Raspberry Pi–class boards. Cross-compiling is simple:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o sensor-gw .
This produces a single statically linked binary with no runtime dependencies to install on the device. That’s a big part of Go’s appeal for networked devices. You copy one file, and it runs.
Typical uses include:
- IoT gateways that collect data from sensors and forward it to the cloud
- Device management agents, update services and local web dashboards
- Protocol bridges (Modbus to MQTT, for example) and other network-heavy services
Libraries such as periph.io give Go programs access to GPIO, I2C and SPI through the Linux kernel’s interfaces. The catch is size. A standard Go binary is usually several megabytes, and the runtime expects an OS, virtual memory and plenty of RAM. That rules out microcontrollers.
TinyGo on microcontrollers
TinyGo is a separate Go compiler built on LLVM. It targets microcontrollers and WebAssembly. It supports a long list of boards, including Raspberry Pi Pico (RP2040), many Adafruit and Arduino boards (SAMD21, SAMD51, nRF52840), BBC micro:bit and various others. Support depth varies by chip, so check the current target list before choosing hardware.
TinyGo provides a machine package for pins and peripherals (GPIO, UART, SPI, I2C, ADC, PWM). There’s also a community drivers repository for common sensors and displays.
A TinyGo blink example
package main
import (
"machine"
"time"
)
func main() {
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
for {
led.High()
time.Sleep(500 * time.Millisecond)
led.Low()
time.Sleep(500 * time.Millisecond)
}
}
Building and flashing for a Raspberry Pi Pico:
tinygo flash -target=pico main.go
The resulting binary is small, often a few kilobytes for a program like this, which is far smaller than a standard Go build.
What you give up with TinyGo
TinyGo is a real Go compiler, but it isn’t a full copy of the standard toolchain:
- Standard library coverage is partial. Many packages work and some don’t. Packages that lean heavily on reflection or OS features are the usual problems.
- Goroutines are cooperative on microcontrollers. They switch at blocking points such as channel operations and
time.Sleep, not preemptively. A goroutine stuck in a tight loop can starve the others. - Each goroutine needs its own stack, which costs RAM on small chips.
- Interrupt handling is available through TinyGo’s runtime, but you’re working further from the hardware’s documentation than you would be in C. Most vendor examples and errata assume C.
- Debugging and vendor tooling are less mature than the C ecosystem.
Garbage collection and real-time behavior
Go manages memory with a garbage collector. On embedded Linux, Go’s concurrent collector usually has short pauses, which is fine for network services. It still isn’t designed for hard real-time guarantees.
On microcontrollers, TinyGo uses a simpler collector, and collection can pause your program at points you don’t directly control. The common way to manage this is to avoid allocating in steady state: allocate buffers at startup, reuse them, and keep allocation out of time-critical paths. TinyGo can also be built with garbage collection disabled, in which case code that would allocate on the heap fails to build. That’s a useful way to find hidden allocations.
For anything with tight timing, such as motor control, precise sampling or safety functions, a common pattern is to keep that part in C (or Rust) on a microcontroller and put Go on a Linux processor alongside it.
Where Go fits well (and where it doesn’t)
Good fits:
- Embedded Linux devices doing networking, data handling and device management
- Prototypes and hobby projects on TinyGo-supported boards, especially for people who already know Go
- Teams that share code or skills between cloud services and edge gateways
Poor fits:
- Hard real-time control loops
- Very small MCUs (a few KB of RAM)
- Safety-certified products, where qualified C toolchains and coding standards are the norm
- Projects that depend heavily on vendor SDKs, middleware or RTOS features that only exist in C
If the language itself is what you’re weighing, our comparison of whether Go is easier than Python covers the learning-curve side.
Functional programming in embedded systems
What “functional” means here
Functional programming (FP) favors:
- Pure functions, whose output depends only on their inputs, with no hidden side effects
- Immutable data, which isn’t modified after it’s created
- Composition, building behavior from small functions
- Explicit state, passed in and returned instead of stored in globals
Classic FP languages such as Haskell rely on garbage collection and heap allocation, which is a poor match for small microcontrollers. But FP ideas are useful in embedded code, and several practical routes exist.
Functional style in plain C
You don’t need a new language to get many of the benefits. Code that keeps hardware access at the edges and makes the core logic pure is much easier to test on a PC:
#include <stdint.h>
typedef struct {
int32_t avg_x16; /* running average, scaled by 16 */
} filter_t;
/* Pure: same inputs always give the same output, no globals touched. */
static inline filter_t filter_step(filter_t f, int16_t sample)
{
/* Exponential moving average with alpha = 1/16 */
f.avg_x16 += sample - (f.avg_x16 >> 4);
return f;
}
The interrupt or main loop reads the ADC and stores the result. All the logic lives in functions like filter_step(), which can be unit-tested on a host machine without any hardware. (Right-shifting a negative signed value is implementation-defined in C, so this version assumes the sample and average stay non-negative, as raw ADC readings do.)
Other habits in the same spirit:
- Mark inputs
constand pointer parametersconstwherever possible. - Return new state instead of modifying globals. This is the “reducer” pattern,
state = step(state, event), and it works well for state machines in embedded C. - Use lookup tables instead of chains of branches where it makes the logic clearer.
Rust: functional features without a garbage collector
Rust borrows heavily from functional languages. It has algebraic data types (enum with data), pattern matching, closures, iterators, and Option/Result instead of null pointers and error codes. It does all this without a garbage collector, and iterator chains usually compile down to plain loops. On Cortex-M, RISC-V and other targets, Rust’s no_std ecosystem (including the embedded-hal traits) has become a serious option for new projects. For developers who want FP-style code on a microcontroller, Rust is the most practical choice today.
Haskell DSLs that generate C
Another approach is to write in a functional language that generates C for the target. The Haskell code never runs on the device.
- Copilot, developed with NASA involvement, is a stream-based language for runtime monitors. It generates C99 that runs in constant memory and constant time.
- Ivory, from Galois, is a Haskell-embedded language for writing memory-safe C. It was used in research projects such as the SMACCMPilot autopilot.
These tools are niche. They show up mostly in research and high-assurance work, but they demonstrate that FP and small targets aren’t incompatible.
Synchronous dataflow languages (Lustre and SCADE)
Lustre is a declarative, dataflow language from academic research. You describe outputs as functions of inputs over time. SCADE, a commercial toolset based on Lustre’s ideas, has a qualified code generator that produces C for safety-critical systems. It has a long history in avionics and rail. This is arguably the most established “functional-flavored” approach in embedded systems, although it’s rarely called FP.
Erlang and Elixir on devices
The BEAM virtual machine behind Erlang and Elixir is built around immutable data, lightweight processes and supervision trees that restart failed parts of a system.
- Nerves packages Elixir applications into minimal embedded Linux firmware images for boards such as the Raspberry Pi and BeagleBone.
- AtomVM is a much smaller BEAM implementation that runs on microcontrollers, including ESP32, STM32 and RP2040.
Both suit connected devices where fault tolerance matters more than microsecond timing.
Comparing the options
| Option | Runs on | Memory management | Real-time suitability | Typical use |
|---|---|---|---|---|
| C | Almost everything | Manual/static | Strong | General firmware |
| Standard Go | Embedded Linux | Garbage collected | Soft real-time at best | Gateways, network services |
| TinyGo | Many MCUs | Simple GC (can be disabled) | Limited | Hobby, prototypes, simple devices |
| Functional-style C | Almost everything | Manual/static | Strong | Testable logic in existing C projects |
| Rust | MCUs and Linux | Ownership, no GC | Strong | New firmware wanting safety and FP features |
| Haskell DSLs (Copilot, Ivory) | Generate C for MCUs | Generated C, static | Designed for it | Research, high-assurance monitors |
| Lustre / SCADE | Generates C | Static | Designed for it | Avionics, rail, safety-critical control |
| Elixir (Nerves) / AtomVM | Linux SoCs / some MCUs | Garbage collected | Soft real-time | Fault-tolerant connected devices |
Choosing a path
A few practical rules of thumb:
- Hardware first. On a small MCU, your realistic choices are C, C++, Rust, and possibly TinyGo or MicroPython for simple projects. On an embedded Linux board, Go, Elixir, Python and others all become viable.
- Keep timing-critical code close to the metal. Whatever you choose for application logic, interrupt handlers and control loops usually stay in C, C++ or Rust. See how to write an interrupt service routine in C.
- Adopt functional habits before a functional language. Pure functions, explicit state and host-side tests pay off in any language.
- Check the ecosystem. Vendor SDKs, RTOS support, debugger integration and certification requirements often decide the language more than personal preference.
Common questions
Which is faster, C++ or Go?
For CPU-bound work, well-written C++ is generally faster than Go and gives more control over memory layout and allocation. Go is often fast enough for network services and is usually quicker to write and deploy. On microcontrollers the comparison matters less than whether the runtime fits at all.
Is functional programming better than object-oriented programming?
Neither is better everywhere. Most embedded code mixes styles. Modules with private state look a lot like objects, while pure calculation functions and state transitions benefit from a functional approach. Choose the style that makes each part easiest to test and reason about.
Is functional programming still used?
Yes. Pure FP languages remain a minority choice, but FP features have spread into mainstream languages, including Rust, modern C++ (lambdas, ranges), Kotlin and Swift. In embedded systems, the clearest uses are Rust, code-generating DSLs and dataflow tools such as SCADE.
What is “os” in Go?
In Go, os is a standard library package that provides operating-system functions such as files, environment variables and processes. It’s available in standard Go on embedded Linux. On microcontrollers under TinyGo, where there’s no operating system, much of it doesn’t apply.