This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I configure newlib printf?

Im using GCC + Eclipse with the S110 SoftDevice and the HRS example code. Everything is working well except for printf (which I've added a call to via app_trace). I've set the ENABLE_DEBUG_LOG_SUPPORT #define. I've also called app_trace_init().

I get a Hard_Fault when I call app_trace. Stepping through the assembly:

  1. printf is entered.
  2. printf attempts to dereference _impure_ptr (part of the thread support for errno in newlib), but _impure_ptr points to 0x8000222, which I believe is in the region of the SoftDevice and not readable.
  3. At this point, a Hard_Fault occurs.

Does newlib need to be initialized (i.e. do I need to call _init or _fini somewhere)? Has anyone else used printf with GCC + newlib?

I'm using the gcc_nrf51_s110_xxac.ld linker script that comes with the SDK--so my memory and flash regions should be correct.

Parents Reply Children
  • But doesn't the nosys library just provide stubs for functions that are undefined? i.e., since retarget.c defines _read and _write, those versions will be used instead of the stubs in nosys. I can test this by commenting out _write in retarget.c--when I print the symbols with nm, _write comes from somewhere else (nosys I assume) and _read comes from retarget.c. Can't I let nosys define stubs for functions I don't care about like _exit?

  • Yes. I was unaware of the retarget.c feature since I don't use anything but the CMSIS headers from the Nordic SDK.

    I've also run into trouble where two things (e.g. retarget.o and -lnosys) define the same symbol, especially if they both come from libraries, as the order the libraries are read by the linker becomes important. In BSPACM I use weak symbols for the stubs to avoid some of these problems.

Related