Fix corrupted %f printf because of disabled heap

newlib requires malloc if printf is used with %f. Since PR 28486, the heap
space in RAM is only reserved if explicitly used by the application
(independent of the value of CONFIG_HEAP_MEM_POOL_SIZE) in order to free
some stack memory. As printf calls malloc internally, this commit forces
Zephyr to build with heap support enabled.
This commit is contained in:
Martin Jäger
2020-11-18 21:05:05 +01:00
parent e5e27c10bc
commit 583924a9b9
2 changed files with 9 additions and 2 deletions
+7
View File
@@ -96,6 +96,13 @@ void setup()
static struct k_timer timestamp_timer;
k_timer_init(&timestamp_timer, timestamp_inc, NULL);
k_timer_start(&timestamp_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
+2 -2
View File
@@ -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