diff --git a/Makefile.dep b/Makefile.dep index 7b73c2e2c8..1274aa3ca4 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -479,6 +479,14 @@ ifneq (,$(filter posix_select,$(USEMODULE))) USEMODULE += xtimer endif +ifneq (,$(filter picolibc,$(USEMODULE))) + # allow custom picolibc syscalls implementations by adding + # picolibc_syscalls_XXX to USEMODULE + ifeq (,$(filter picolibc_syscalls_%,$(USEMODULE))) + USEMODULE += picolibc_syscalls_default + endif +endif + ifneq (,$(filter posix_sockets,$(USEMODULE))) USEMODULE += bitfield USEMODULE += random diff --git a/cpu/cortexm_common/Makefile.dep b/cpu/cortexm_common/Makefile.dep index 472b903407..edc2835da9 100644 --- a/cpu/cortexm_common/Makefile.dep +++ b/cpu/cortexm_common/Makefile.dep @@ -4,11 +4,15 @@ USEMODULE += cortexm_common # include common periph code USEMODULE += cortexm_common_periph -# all cortex MCU's use newlib as libc -USEMODULE += newlib - -# use the nano-specs of Newlib when available -USEMODULE += newlib_nano +ifeq (1,$(PICOLIBC)) + # Use Picolibc when explicitly selected + USEMODULE += picolibc +else + # all cortex MCU's use newlib as libc + USEMODULE += newlib + # use the nano-specs of Newlib when available + USEMODULE += newlib_nano +endif # Export the peripheral drivers to be linked into the final binary: USEMODULE += periph diff --git a/makefiles/libc/picolibc.mk b/makefiles/libc/picolibc.mk new file mode 100644 index 0000000000..04055b4973 --- /dev/null +++ b/makefiles/libc/picolibc.mk @@ -0,0 +1,17 @@ +ifneq (,$(filter picolibc,$(USEMODULE))) + # Test if picolibc.specs is available + ifeq ($(shell $(LINK) -specs=picolibc.specs -E - 2>/dev/null >/dev/null &1 | grep -q "use of wchar_t values across objects may fail" ; echo $$?),0) + CFLAGS += -fshort-wchar + LINKFLAGS += -Wl,--no-wchar-size-warning + endif + endif +endif + +ifeq (1,$(USE_PICOLIBC)) + LINKFLAGS += -specs=picolibc.specs + CFLAGS += -specs=picolibc.specs +endif + +LINKFLAGS += -lc diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 31abbf9e59..510e6fecd8 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -85,6 +85,7 @@ PSEUDOMODULES += newlib PSEUDOMODULES += newlib_gnu_source PSEUDOMODULES += newlib_nano PSEUDOMODULES += openthread +PSEUDOMODULES += picolibc PSEUDOMODULES += pktqueue PSEUDOMODULES += posix_headers PSEUDOMODULES += printf_float diff --git a/makefiles/stdio.inc.mk b/makefiles/stdio.inc.mk index 4f4959be16..4c7749d2f9 100644 --- a/makefiles/stdio.inc.mk +++ b/makefiles/stdio.inc.mk @@ -8,7 +8,7 @@ STDIO_MODULES = \ stdio_uart \ # -ifneq (,$(filter newlib,$(USEMODULE))) +ifneq (,$(filter newlib picolibc,$(USEMODULE))) ifeq (,$(filter $(STDIO_MODULES),$(USEMODULE))) USEMODULE += stdio_uart endif diff --git a/sys/Makefile.include b/sys/Makefile.include index a449b90e99..a5cb26e796 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -68,10 +68,18 @@ ifneq (,$(filter newlib,$(USEMODULE))) include $(RIOTMAKE)/libc/newlib.mk endif +ifneq (,$(filter picolibc,$(USEMODULE))) + include $(RIOTMAKE)/libc/picolibc.mk +endif + ifneq (,$(filter newlib_syscalls_default,$(USEMODULE))) include $(RIOTBASE)/sys/newlib_syscalls_default/Makefile.include endif +ifneq (,$(filter picolibc_syscalls_default,$(USEMODULE))) + include $(RIOTBASE)/sys/picolibc_syscalls_default/Makefile.include +endif + ifneq (,$(filter arduino,$(USEMODULE))) include $(RIOTBASE)/sys/arduino/Makefile.include endif