CH32V307 Picolibc to the rescue

 

With our shiny new risv32 gcc, let's look at the generated code size.

The demo is a small graphic demo using a SSD1306

With vanilla libc build with our shiny riscv32gcc : Code = 50 kB


Let's build and install picolibc

In order to do so, create a cross.txt containing :

[binaries]
c = 'riscv64-unknown-elf-gcc'
ar = 'riscv64-unknown-elf-ar'
as = 'riscv64-unknown-elf-as'
ld = 'riscv64-unknown-elf-ld'
strip = 'riscv64-unknown-elf-strip'

[host_machine]
system = 'unknown'
cpu_family = 'riscv'
cpu = 'riscv'
endian = 'little'

[properties]
c_args = [ '-nostdlib', '-msave-restore', '-fno-common' ]
# default multilib is 64 bit
c_args_ = [ '-march=rv32imac', '-mabi=ilp32']
needs_exe_wrapper = true
skip_sanity_check = true


make sure our shiny new riscv gcc is in your path, then

mkdir build && cd build && meson --cross-file ../cross.txt .. && ninja && ninja install

then use --specs=picolibc.specs to compile AND to link.

So using our example, what is the result ? 30 kB!
50 kB => 30 kB

Not bad!

Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring