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


Redirecting printf() does not work

I have enabled USART1 and I’m able to send data using HAL_UART_Transmit() function. I want printf() to put its data on this port using following code :

#include stdio.h

#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

And at the bottom of the code I have defined PUTCHAR_PROTOTYPE like this:

PUTCHAR_PROTOTYPE
{
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
  return ch;
}

But after initializing the USART1 in the main function I don’t see any data coming from something simple like printf(“Hello!\n”)
What wonders me is that I did all this in Keil and it worked like a charm!

I suspect there is a compile option or something like that in GCC. I’m not sure. Could you guys help me?

(By the way I don’t know why all # marks have been changed into line numbers in above code)

France

Hi,

Regarding the ‘#’ characters, its because a sharp as first character of a line is introducing a numbered list item (like a star will introduce an unnumbered, dot, lost); two sharps (or two stars) introduce sublist items and so on...

To avoid that just include your code between {CODE()} and {CODE}, as I’ve done in your message above. (by the way to display special characters or syntax, surround them between ~np~ and ~/np~). You have a quite exhaustive presentation of the Wiki syntax used on this site (which is based on tiki-wiki) at https://doc.tiki.org/Wiki-Syntax+TextQuestion

To come back to your original problem, what you have done should work; are you sure the file in which you define the PUTCHAR_PROTOTYPE function was effectively included in your executable? If it is in a file that is only needed for this function, it may be omitted; try putting this function in your main program for example.

Bernard (Ac6)

Thank you
The PUTCHAR_PROTOTYPE function is in my main.c file. In fact all the code is in main.c
I was thinking about compiler options cause in this part :

#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__ */


it says: With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to ‘Yes’) calls __io_putchar()
Which I’m not sure what it’s talking about ...
And the fact that this all worked in Keil that first time.


Hi,

I am new to STM32. After playing with the code generation from STM32cubeMX for SW4STM32, I am facing the same problem with printf. I am using a STM32F0 discovery board and the function HAL_UART_Transmit works perfectly. I added the following code to the main project and included the stdio.h header in order to use the printf function:

#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

PUTCHAR_PROTOTYPE
{
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);

  return ch;
}


Without success. However, when I call the function io_putchar directly, my terminal receives the string just fine.
I generated the same code to use in keil and it surprises me that the printf function works there without problems.

So I think there are some compiler options that I need to configure within SW4STM32. It would be very helpful if somebody can help me finding the solution.

Thanks in advance,

Hendrik

Tunisia

Hello Hendrik,

You are just missing the syscalls.c, see atached file
look at _write function which calls the _io_putchar function, this _write function is called by printf, puts, putc ...

Regards,
Tarek

Great!! This is what I needed. I thought that printf was calling io_putchar directly.
Now it works fine :-).

Thank you very much, I am a happy man :-).

Could you possible show me how you got it to work? I’ve been trying everything I came across and I’ve had no luck. I have a nucleo-F767ZI and I’ve downloaded the example UART printf() and that works fine but when I try implementing it on my own project I can’t get it to transmit anything. If you could help me that would be great!

The solution is :copy _write function in syscalls.c to place under __io_putchar ,if a multi declare error occure while compiling,recover _write function to previouse place.

For example ,i used touchgfx,compiled in linux,and encounted the same issue,and found a file named gccstubs.cpp in touchgfx/config/gcc/gccstubs.cpp,_write function in it is blank,then i replace the _write function,and printf is working to uart.

Hi guys,

I know it’s an old thread, but one of the few that comes up on top of Google’s hitlist.

I just want to make it a bit more clear, how to get it working:

Simply move the CubeM-generated syscalls.c to your src-Folder, put the PUTCHAR_PROTOTYPE define in your main.h (in a USER CODE section) and then your PUTCHAR_PROTOTYPE function will be called correctly.

If you have no syscall.c, just implement the _write function.

Hope this makes it more clear.


Hi Moha1993, if you are using floats there is a way to enable float support in printf :
By default “nano” version of the standard input-output (stdio) library is selected.
This helps to keep code size low but does not allow use float numbers in printf
In order to change it, disable “nano” library option within project settings :
Remove this option : -spec=nano.specs in C/C++ Build -> Settings -> MCU GCC Linker -> Miscellaneous


I’ve done everything mentioned here and in many other pages I Googled.... but I still cannot get printf to work.
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); works.
I have syscalls.c

I get this warning :
”./Core/Src/main.c:152:31: warning: ‘__io_putchar’ defined but not used -Wunused-function
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

../Core/Src/main.c:158:3: note: in expansion of macro ‘PUTCHAR_PROTOTYPE’
PUTCHAR_PROTOTYPE
~~~~~~~~~~~~~~~~
Finished building: ../Core/Src/main.c ”

I guess the fact that __io_putchar not being used is the root of the problem ?

Any ideas what I’m doing wrong here ?