Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


sw4stm32 printf not working

Dear All

I would like to redirect printf output to UART.
It seem very simple in this field and many example in internet.

I try that with “System Workbench”(SW4STM32).
The IDE doesn’t show anything wrong.


adding below to “uart.c”


.#ifdef GNUC
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to ‘Yes’) calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
.#else
.#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
.#endif /* GNUC */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);

return ch;
}



calling printf() in “main.c”


printf(“\n\r UART Printf Example: retarget the C library printf function to the UART\n\r”);



The “printf()” seem don’t work in my chip.
But “HAL_UART_Transmit” is function in main.c. That imply the UART port work fine.

Then try adding something GPIO action(output toggle) inside the “PUTCHAR_PROTOTYPE” routine. If printf() running, “PUTCHAR_PROTOTYPE”(fputc() or __io_putchar()) should be call. The GPIO action hasn’t execute, mean “PUTCHAR_PROTOTYPE” hasn’t be call.

Is there any where necessary to modify for such redirection except “uart.c”?

My code is generated by STM32CubeMX and hasn’t “syscall.c”
Is it a root cause of my problem?

Or System Workbench is not support printf() redirection?


Please share your comment.


BR

printf() & scanf() redirection is supported by the library (independent of the IDE).

The library defines a “weak” function called _write() to output the formatted string. If you create an AC6 project, it will include the file syscalls.c that redefines _write() to interate over the string and call __io_putchar(). CubeMX does not create a _write() function so nothing is output (the comments surrounding PUTCHAR_PRTOTYPE are misleading).

Since printf() passes a string to _write() and the HAL accepts a string, I suggest you create a version of _write() that passes the string to the HAL and eliminate the __io_putchar() routine.

Alex


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs