cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F091RC - How to have printf output on /dev/ttyACM0

Mant Sandy
Associate III
Posted on July 14, 2017 at 13:35

With mbed-os  `printf('Hello world');` would print 'Hello world' on ttyACM0

How can I achieve the same this using STMCube32 HAL API's?

Initially printf() was giving me some undefined reference errors in sbrk() system call errors.

I added `-specs=nosys.specs` to linker flags. the compilation was successful.

But cat /dev/ttyACM0 does not show any prints.

How can I get printf working on ttyACM0?

8 REPLIES 8
Mant Sandy
Associate III
Posted on July 28, 2017 at 10:30

I am waiting for a reply.

Can some one please share your thoughts??

Without debug logs, I am finding it difficult to debug my application..

:(

Posted on July 28, 2017 at 10:47

With mbed-os  `printf('Hello world');` would print 'Hello world' on ttyACM0

How can I achieve the same this using STMCube32 HAL API's?

...

I am waiting for a reply.

Perhaps because hardly anybody using this combination ?

Or is able/willing to share ?

You could try a different approach, like implementing UART output directly.

Or implementing the missing clib stuff to redirect the printf() output.

I don't use an OS on the MCU, so I have no example. But try a search here on this forum or elsewhere.

Max
ST Employee
Daniel Glasser
Associate III
Posted on July 31, 2017 at 22:44

I have a few STM32CubeMX projects that implement a CDC-ACM on the USB_OTG_FS interface on STM32F7xx and STM32F4xx using the HAL driver and USB device stack's CDC virtual serial port.  In order to make 'print()' send output to the port, you must write a few functions to direct the output from that function to the USB CDC-ACM.

With 'newlib' or 'newlib nano', there are a few ways to do this.  My favorite is to write a function with the name '_write_r()' that, in turn, calls the USB stack.  In my experience, you can instead implement your own 'write()' function, and if you're not using an rtos, you should end up with the same result (maybe even with an RTOS).  See

https://stackoverflow.com/questions/32031929/implementing-write-write-or-write-r-with-newlib

for more information on what implementing '_write_r()' and friends involves.

I don't currently have access to my project, or I'd give more details.  It will be a few days before I'm back at my desk and can pull an example up.

David SIORPAES
ST Employee
Posted on January 29, 2018 at 10:30

There's an example on how to do printf over UART in STM32F4 Cube firmware package under 'Projects/STM32446E-Nucleo/Examples/UART/UART_Printf'. Should be simple to adapt it to your board as there's nothing specific to the MCU family.

Posted on January 29, 2018 at 11:15

I believe answering to this (old) thread is akin to flogging a dead horse ...

Posted on January 29, 2018 at 12:33

Not helped by the forum itself promoting a selection of Dead Horses under 'Related Content' and 'Recommended Content'.

>:(