Get the latest tech news

Bare metal printf – C standard library without OS


Guide to implementing a C standard library for bare metal hardware using Newlib, enabling powerful functions like printf and malloc without relying on an operating system. This step-by-step guide demonstrates how to configure and integrate Newlib on RISC-V architecture, showing you how to redirect standard I/O through UART for embedded systems development.

Open Table of contents When running printf on a typical, fully operational, end-user system (e.g., a Mac or a Linux laptop), we invoke a pretty complex machinery. When we develop a binary for an everyday OS, we typically don’t have to think about this, and the compiler will inject the standard startup runtime which takes care of setting up the process for proper execution and passing the control on to the main function. Of course, in absolutely minimal environments, the size of the final software image can be a concern, as well as the amount of instructions we’re injecting, but looking at the ELF file that we build in our project, it’s at 220K which doesn’t really sound too bad.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Standard Library

Standard Library

Photo of Bare metal printf

Bare metal printf

Related news:

News photo

Writing your own C++ standard library from scratch

News photo

GNU Make Standard Library

News photo

Using the Rust standard library with the NuttX RTOS