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:
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user