newlib-nano, printf requires malloc

Asked by Nestor Lopez Casado

I'd like to use printf for basic debugging on a cortex-m0 with minimal ram size. I dont want to use any dynamic memory allocation, effectively having 0 heap size.

newlib-nano already provides a great code size improvement compared to the classic newlib, but stills uses malloc and friends. Which is the best approach to overcome the dynamic memory allocation ? Should I code my own printf ?

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Nestor Lopez Casado
Solved:
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#1

Hi, Nestor,

It does use a malloc to allocate needed libc data structures. The malloc used in nano is small in size and RAM though.

To eliminate it completely, either write your own printf, or further improve newlib-nano, which is part of newlib mainline now. We welcome all good ideas to be included in nano.

Thanks,
Joey

Revision history for this message
TM (tm1234) said :
#2

Hi Nestor

I've one or other of these successfully on Cortex-M1/3 targets. Would they be of any use to you in this context?

http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
http://www.sparetimelabs.com/printfrevisited/printfrevisited.php

Hope this helps.

Revision history for this message
Nestor Lopez Casado (xnlopez) said :
#3

Hi TM, Joey,

Thanks for the answers,

Joey, the use of a tiny malloc is good. My issue here is that I would like to have no heap at all.

TM, I had seen those implementations. I think I will end up using one of them. As Joey suggests, it could be interesting to try to push the simplest printf versions to newlib-nano so that it gets leaner and better.

Thanks,
Nestor.