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


Retargeting printf

I’m trying to retarget the printf function in order to print formatted output to USART3 on my STM32 NUCLEO F746ZG.

This is the code in the uart.h file I created:

1 #ifdef GNUC
2 /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to ‘Yes’) calls __io_putchar() */
3 #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
4 #else
5 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
6 #endif /* GNUC */

(Please note that the lines 1 and 6 have a couple of underscores before and after the GNUC keyword, but I didn’t succeed in innserting it in the post...)

This is the code in the corresponding uart.c file:

1 PUTCHAR_PROTOTYPE {
2 HAL_UART_Transmit (&huart3, (uint8_t *)&ch, 1, 0xFFFF);
3 return ch;
4 }

Nothing happens if I run the application........

In particular:
If I directly call the HAL_UART_Transmit function, I can send characters.
If I call the printf function, the PUTCHAR_PROTOTYPE function is not executed.

I guess the printf is calling something else than the PUTCHAR_PROTOTYPE function.
By the way, I didn’t see the “small printf” option in the System Workbench linker options.

What’s wrong with this code?

Thanks in advance

Hi flavio.renga,

For using printf, you need also to have the syscalls.c file in the src directory of your project.

Souleymane
AC6

Thank you very much Souleymane!
Now it works!

A simple curiosity: why CubeMX doesn’t add this file automatically?!

Cheers

Flavio

What about retargeting getchar() function?

My simple goal is, for the moment, to wait until the ‘p’ key is pressed on the PC console.
I’m having problem with it...

Infact, I’ve tried to retarget the getchar() function in the same way I’ve done for the printf() function, but without success.

If I use directly the HAL_UART_Receive() function, all is right.
If I try redefining the io_getchar(void), function, I get problems.


---------------

Hereafter the working code:

> // Wait for ‘p’ char pressed
> HAL_UART_Receive (&huart3, (uint8_t *)&c, 1, 0xFFFF);
> while (c != ‘p’) {
> HAL_UART_Receive (&huart3, (uint8_t *)&c, 1, 0xFFFF);
> }

---------------

Instead, if I use the following code, the program stucks into the GETCHAR_PROTOTYPE routine:

> #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)
> #define GETCHAR_PROTOTYPE int __io_getchar(void)
> #else
> #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
> #define GETCHAR_PROTOTYPE int fgetc(FILE *f)
> #endif /* GNUC */

...

> GETCHAR_PROTOTYPE {
> int ch;
> HAL_UART_Receive (&huart3, (uint8_t *)&ch, 1, 0xFFFF);
> return ch;
> }

...

> // Wait for ‘p’ char pressed
> c = getchar();
> while (c != ‘p’) {
> c = getchar();
> }


In particular, the char is correctly captured by HAL_UART_Receive (I can see the char by using the breackpoints), but the GETCHAR_PROTOTYPE repeats infinitely without exiting and the while loop is never reached.

What is wrong with the code?

Thanks in advance!

Flavio

Thank you! With these instructions I was able to make printf work.

This thread is almost identical:
https://community.st.com/thread/10610Question
From there I was able to get a hint of where to get the file. I copied syscalls.c file directly from an example project for F4 that can be found in:
STM32Cube_FW_F4_V1.8.0\Projects\STM32F401RENucleo\Examples\UART\UART_Printf\SW4STM32