cancel
Showing results for 
Search instead for 
Did you mean: 

How to make printf working with semihosting?

TVegh.1
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

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

hth

KnarfB

View solution in original post

2 REPLIES 2
KnarfB
Principal III

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

hth

KnarfB

TVegh.1
Associate

Yes, that was it. :D

I had a _write definition in my project.

Thanks!