Skip to main content
TVegh.1
Associate
May 18, 2022
Solved

How to make printf working with semihosting?

After setting up the environment regarding the description (st.com/resource/en/application_note/dm00354244-stm32-microcontroller-debug-toolbox-stmicroelectronics.pdf) it is still not working.

Build is OK.

Download OK.

OCD starts.

The getchar() function receives the typed character in console, but none of the functions - which are using stdout - are working. I've tried printf(), putchar(), puts().

I set:

<main.c>

#include <stdio.h>

extern void initialise_monitor_handles(void);

int main(void)

{

 /* USER CODE BEGIN 1 */

 initialise_monitor_handles();

printf("Semihosting OK\n");

 /* USER CODE END 1 */

...

....

<linker>

@ MCU GCC Linker -> Libraries -> rdimon

@ MCU GCC Linker -> Misc..-> -specs=rdimon.specs -lrdimon -lc

@ MCU settings -> Runtime lib: Reduced C

<Debug config>

ST-LINK (OpenOCD)

monitor arm semihosting enable

I'm using a Nucleo's ST-LINKv2 as a debugger, SWD lines to external board where the MCU is a Stm32L431RCT6, SWO line is not connected.

IDE: STM32CubeIDE Version: 1.9.0

I'm struggling now. I've read all available resources but not found any mention about a 'partially working' thing.

Thanks!

Tamas

    This topic has been closed for replies.
    KnarfB
    KnarfBBest answer
    Super User
    May 19, 2022

    Do you have syscalls.c excluded from build? Any other __io_putchar or _write lurking around in your project?

    hth

    KnarfB

    2 replies

    KnarfB
    KnarfBBest answer
    Super User
    May 19, 2022

    Do you have syscalls.c excluded from build? Any other __io_putchar or _write lurking around in your project?

    hth

    KnarfB

    TVegh.1
    TVegh.1Author
    Associate
    May 19, 2022

    Yes, that was it. :D

    I had a _write definition in my project.

    Thanks!