cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to get the debug messages output (ST-LINK attached UART) of STM32H750B-DK

tarbal
Associate III

I use STM32H750B-DK board. It has UART3 connected to the ST-LINK USB.

I tried
uint8_t Test[] = "Hello World !!!\r\n";
HAL_UART_Transmit(&huart3,Test,sizeof(Test),10);
printf("Hello World 1 !!!\r\n");

HAL_UART_Transmit output has passed to the terminal.
printf doesn't print anything.
syscalls.c defines 
extern int __io_putchar(int ch) __attribute__((weak));
The implementation is hidden and it definitely doesn't deal with the UART3.

The actual function used in the printf implementation is:

__attribute__((weak)) int _write(int file, char *ptr, int len)
{
  (void)file;
  int DataIdx;


//  UART3_TX((uint8_t *)ptr, len, 1000);

  for (DataIdx = 0; DataIdx < len; DataIdx++)
  {
    __io_putchar(*ptr++);
  }

  return len;
}


I redefined the weak _write() in the main.c

int _write(int file, char *data, int len)
{
   if ((file != STDOUT_FILENO) && (file != STDERR_FILENO))
   {
      errno = EBADF;
      return -1;
   }

   // arbitrary timeout 1000
   HAL_StatusTypeDef status =
      HAL_UART_Transmit(&huart3, (uint8_t*)data, len, 1000);

   // return # of bytes written - as best we can tell
   return (status == HAL_OK ? len : 0);
}


Surprise!!!
Breakpoint in main.c defined _write() has not hit. The weak _write() of syscalls.c continues working.

I tried a dirty solution.
Defined in the main.c following function:
HAL_StatusTypeDef UART3_TX(uint8_t *data, uint16_t len, uint32_t Timeout)
{
     return HAL_UART_Transmit(&huart3, data, len, Timeout);
}
I tried to call the function In the syscalls's version of the _write. The linker doesn't see UART3_TX().

What is going on? How can I make my debug output working?
Why it became unexpectedly complicated?

3 REPLIES 3

The linker is pretty methodical, you're going to need to look at what it is being fed as input, and what the .MAP describes in the resultant output.

Kind of suggests that syscalls.c isn't being pulled in.

use strlen() not sizeof() for strings, with trailing NULs

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

Thank you.
This response doesn't help me getting printf working.

tarbal
Associate III

I found the mistake. The  _write() in the main.c does redefine _write() in the syscalls and the printf works. No help is required anymore.