Skip to main content
Graduate II
November 26, 2024
Solved

printf calling default __io_putchar instead of redefinition

  • November 26, 2024
  • 1 reply
  • 2217 views

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

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

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

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

    1 reply

    Graduate II
    November 26, 2024

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

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

    Graduate II
    December 2, 2024

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