Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

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