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


Redirect Printf through UART2

HI there,

I’m looking for the redirection of printf to UART2.

My MCU is a STM32F103VDT and I use UART2 to print debug on serial console.

On Keil I used this code to redirect the printf trough UART2:

int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */

if ((char)ch == ‘\n’) /* Add a LF before \n — LF -> CR LF */
{
HAL_UART_Transmit(&huart2,(uint8_t*)”\r”,1,1);
}

HAL_UART_Transmit(&huart2,(uint8_t*)&ch,1,1); // 1 tick waiting (1ms) enough for 87us/byte at 115200

return ch;
}



But now this code not works when I compile with System WorkBench AC6.

Exploring the forum I found a hint regarding the redirection of UART.

It’s suggest to use this code to redirect the printf (I add my code into the function):

void __io_putchar(uint8_t ch)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */

if ((char)ch == ‘\n’) /* Add a LF before \n — LF -> CR LF */
{
HAL_UART_Transmit(&huart2,(uint8_t*)”\r”,1,1);
}

HAL_UART_Transmit(&huart2,(uint8_t*)&ch,1,1); // 1 tick waiting (1ms) enough for 87us/byte at 115200

//return ch;
}


But this code not works.

Any suggestion?

Thanks


Are you creating the project through CubeMX then importing it in?
Im using the F7 and also had some headaches to get the printf working, but have finally suceeded ;

When you make a project via SW4STM32, it includes a file in there called syscalls.c . the CubeMX generated project in my case at least, does not have it. Within is the extern definition for the _ _io_putchar() also the _write(0 and _read(). So I created a basic project for the same target then located this file and copy it into the project Src folder.

In main.c , #include “stdio.h” , also create the new implementation for this method ;

void __io_putchar(uint8_t ch) {
HAL_UART_Transmit(&huart3, &ch, 1, 1);
}


For me this sort of worked - it did spit out the printf output but only after 1024bytes had been buffered, then write() was called!
To resolve that “mode” we need the printf to flush immediately, can be done using the following call. I inserted

setbuf(stdout, NULL);

after the uart init is done but prior to using printf().
hope it helps....

I have syscall.c in my SW4STM32 project.
I do this below:
“In main.c , #include “stdio.h” , also create the new implementation for this method ;
void __io_putchar(uint8_t ch) {
HAL_UART_Transmit(&huart1, &ch, 1, 1);
}

However I get no printf output . Calling HAL_UART_Transmit(&huart3, &ch, 1, 1); directly works.

I get a warning message that probably explains the problem:
’__io_putchar’ defined but not used -Wunused-function main.c /myproject/Core/Src line 150 C/C++ Problem

Why is __io_putchar not being used ?


Thank you vikas, searched for hours. Your answer helped me get it working.