cancel
Showing results for 
Search instead for 
Did you mean: 

printf calling default __io_putchar instead of redefinition

EthanMankins
Senior

I am using the Nucleo-H743ZI with a c++ project, and have used this code many times before with this board and c++; however, now the printf() function no longer prints to uart:

int __io_putchar(int ch) { HAL_UART_Transmit(&huart3, (uint8_t*) &ch, 1, 0xFFFF); return ch; } [...] printf("hello\n");

 I can send chars using HAL_UART_Transmit(&huart3, (uint8_t*) &ch, 1, 0xFFFF);

I stepped through the disassembly and found that __io_putchar is called with the following:

112 __io_putchar(*ptr++); 08003718: ldr r3, [r7, #8] 0800371a: adds r2, r3, #1 0800371c: str r2, [r7, #8] 0800371e: ldrb r3, [r3, #0] 08003720: mov r0, r3 08003722: nop.w

To the best I can tell, it seems like the default weak __io_putchar is being called.

In the memory map file it is listed as:

.text._Z12__io_putchari 0x00000000 0x24 ./Core/Src/main.o

 Ant ideas what is going wrong and how to fix it?

 

Thanks,
Ethan

1 ACCEPTED SOLUTION

Accepted Solutions

Shouldn't you be using extern "C" to prevent the name mangling?

extern "C" int __io_putchar(int ch) { ...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

Shouldn't you be using extern "C" to prevent the name mangling?

extern "C" int __io_putchar(int ch) { ...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Could've sworn I had tried that, but that fixed it...