syscalls.c and tiny_printf.c used together

Share code examples or discuss embedded software, including device drivers, interrupt handlers, middleware and application code.

Moderators: Markus Girdland, Mattias Norlander

phoenix2000
Posts: 15
Joined: Sun Aug 12, 2018 11:02 am

syscalls.c and tiny_printf.c used together

Postby phoenix2000 » Tue Aug 14, 2018 7:36 am

Hi everyone
My board is stm32f429i discovery. I tried to redirect the printf as the videos of Atollic page on youtube says.
I'mean I added the syscalls.c to Src and changed the _write function as I should. But I got nothing on SWV consol although If I used ITM_SendChar('h'); Instead of printf, I could see h character.
Anyway, at last, it was solved after that I added the tiny_printf.c to Src too. which was not mentioned anywhere.
So does anybody know why?

Mattias Norlander
Posts: 263
Joined: Fri Apr 29, 2016 10:01 am

Re: syscalls.c and tiny_printf.c used together

Postby Mattias Norlander » Fri Aug 31, 2018 2:33 pm

Different mcus (cortex-M0 --> M7) uses different run-time library combinations depending on which features of printf() you use etc.
Some of these will call putc() and other functions instead of _write(). That can create a problem.
As you correctly guessed adding tiny_printf.c will override run-time library and make sure you get a function that calls _write().

Which video link are you referring to?

phoenix2000
Posts: 15
Joined: Sun Aug 12, 2018 11:02 am

Re: syscalls.c and tiny_printf.c used together

Postby phoenix2000 » Tue Jan 15, 2019 8:35 am

Mattias Norlander wrote:Different mcus (cortex-M0 --> M7) uses different run-time library combinations depending on which features of printf() you use etc.
Some of these will call putc() and other functions instead of _write(). That can create a problem.
As you correctly guessed adding tiny_printf.c will override run-time library and make sure you get a function that calls _write().

Which video link are you referring to?

https://www.youtube.com/watch?v=qSzme7qcBb0&t=4s

msimunic
Posts: 2
Joined: Mon Dec 17, 2018 9:24 am

Re: syscalls.c and tiny_printf.c used together

Postby msimunic » Sat Jan 26, 2019 1:52 pm

Hi,
I'm kind of newbie to Atollic and GCC to STM32, so I would appreciate help.
I'm using STM32L053R8 (Nucleo) and I would like to use printf for printing to UART2 (USB VCP).
When building the project printf() call is missing from Call Graph list (static stack analyzer).
I'm using a project generated using STM32CubeMX v5.0.1 (latest version at the moment).
There is syscalls.c in the project, but there is no tiny_printf.c. In file syscalls.c there is _write() which calls __io_putchar().
__io_putchar is rewrited in CubeMX generated code and inside __io_putchar there is call to HAL_UART_Transmit().

Reading this forum I understand that I need to redirect printf() but also that depending on platform printf() can call various functions ie. putc or putchar() or ... something else?

Please, can someone point me to what exactly source code should be placed in tiny_printf.c. Is that device dependant (STM32L053R8) or independent?
Also, why I can't do that just in syscalls.c?
Where is documented which sub-functions are called by printf() for which platform, using GCC?
How compiler optimization affect those calls?

Thnx

phoenix2000
Posts: 15
Joined: Sun Aug 12, 2018 11:02 am

Re: syscalls.c and tiny_printf.c used together

Postby phoenix2000 » Sun Jan 27, 2019 4:58 pm

Hi
Try this library: https://github.com/mpaland/printf
I use it and have no more problem. as you can see in its page, you just need to change this:

Code: Select all

void _putchar(char character)
{
  // send char to console etc.
}

to redirect the printf. :mrgreen:


Return to “Embedded target code development discussions”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest