diff --git a/src/setup.cpp b/src/setup.cpp index 7792394..9406d59 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -96,6 +96,13 @@ void setup() static struct k_timer timestamp_timer; k_timer_init(×tamp_timer, timestamp_inc, NULL); k_timer_start(×tamp_timer, K_MSEC(1000), K_MSEC(1000)); + + /* + * printf from newlib-nano requires malloc, but Zephyr garbage-collects heap management if it + * is not used anywhere in the code. Below dummy calls force Zephyr to build with heap support. + */ + void *temp = k_malloc(4); + k_free(temp); } #endif diff --git a/zephyr/prj.conf b/zephyr/prj.conf index 3e1e69b..573637a 100644 --- a/zephyr/prj.conf +++ b/zephyr/prj.conf @@ -1,7 +1,7 @@ # Main application configuration (overrides board-specific settings) -# default is 1024 -CONFIG_HEAP_MEM_POOL_SIZE=1024 +# only very small heap necessary for malloc in printf statements with %f +CONFIG_HEAP_MEM_POOL_SIZE=256 CONFIG_CPLUSPLUS=y