Close

Delving into Picolibc

ken-yapKen Yap wrote 04/05/2025 at 10:48 • 3 min read • Like

Picolibc is a set of standard C libraries, libc and libm, for smaller embedded systems with limited ROM and RAM. It's derived from newlib and AVR libc. It is actively developed and can be cloned from Github. ARM and RISC-V are the main testing targets.

As you can see from the screenshot, there is a link to a very informative presentation about the history of Picolibc. Keith Packard is familiar to me from his previous work with Freededsktop and the X desktop server. I must look into the other interesting projects in Keith's rabbit hole.

The reason I started looking into picolibc was the need to have a crt0.o for an upcoming bare metal MCU project. The libc and libm might be used later. Surprisingly there were few source candidates on the Internet for the MCU architecture I had in mind, but I found one under the picocrt subdirectory of picolibc.

A look in the newlib-cygwin source shows the difference in the size of the targets.

$ ls newlib-cygwin/newlib/libc/sys
a29khif  d10v      h8300hms  Makefile.inc  or1k   sh         sysnecv850  tic80   z8ksim
amdgcn   epiphany  h8500hms  mmixware      rdos   sysmec     sysvi386    tirtos
arm      esp       m88kbug   netware       rtems  sysnec810  sysvnecv70  w65

Compare this to the list of picolib targets for crt0.o:

$ ls picolibc/picocrt/machine
aarch64  arc  arc64  arm  m68k  mips  msp430  nios2  powerpc  riscv  sh  sparc  x86  xtensa

Many of the modern 32 and 64 bit MCUs are covered. ARM gets you the RPi, STM32, and so forth. Xtensa gets you the ESP32 family. RISC-V gets you the rising MCUs, including the newer ESP32s.

The build system is modern, it uses meson and ninja. Once configured, compiling was super-fast.

The task that took most time for me was finding and installing an appropriate cross toolchain for the MCU. When that is done, you have to write a meson configuration file to generate the MCU configuration, or use one of the existing ones. It's possible that the tool prefix won't be what the configuration expects. You can either customise the config file, or make symlinks to the tool names expected. For example I have this link in /usr/local/bin:

/usr/local/bin/arm-none-eabi-gcc -> ~/.arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/14.2.1-1.1/bin/arm-none-eabi-gcc

After building, several versions of crt0.o were created, for none, normal, minimal, semihosted, and hosted. I'll probably be using the normal one which sets up the MCU for a C program and then calls main().

More later when I start on the MCU project in question.

Like

Discussions

Rich text editor