2020-10-20 07:16 PM
Hi.
I am using stm32cubeide version 1.2.0.
I am using stm32CubeMx version 5.6.1.
The "int _write (int file, char * ptr, int len)" function is not called when the printf ("test") function is called.
What did you do:
1. Added to Properties ---> c / c ++ Build ---> Settings ---> Linker ---> Miscellaneous ---> -u _printf_float and -u _scanf_float.
2. Added to the main () function, printf ("test");
3. Launched the program
4. Did not receive a call to "_write (int file, char * ptr, int len)" to transfer characters "test".
How can I solve my problem?
Thanks for your time.
Solved! Go to Solution.
2020-10-20 10:28 PM
printf (stdout) is line buffered. printf ("test\n") will ultimately call _write.
2020-10-20 10:28 PM
printf (stdout) is line buffered. printf ("test\n") will ultimately call _write.
2020-10-20 11:39 PM
Yes you are right. If you add '\ n' to printf ("test \ n") it works.
Can _write be called without '\ n'?
2020-10-20 11:45 PM
There are standard C methods making stdout unbuffered like
setvbuf(stdout, NULL, _IONBF, 0);
Though I haven't tested that.
2020-10-21 01:02 AM
made:
1. Added setvbuf (stdout, NULL, _IONBF, 0); in
void initialise_monitor_handles ()
{
setvbuf (stdout, NULL, _IONBF, 0);
}
2. Registered in main ()
2.1 extern void initialise_monitor_handles (void);
2.2 In the body of the function main (), initialise_monitor_handles ();
I started it without '\ n' printf ("test") ;. Everything is working.
Are there any pitfalls in the implementation?
2020-10-21 01:16 AM
Perfect.
> Are there any pitfalls in the implementation?
printf implementation uses malloc. You may check that by setting a breakpoint at _sbrk.
The implementation is broken when FreeRTOS is used, see http://www.nadler.com/embedded/newlibAndFreeRTOS.html
Otherwise: good luck
hth
KnarfB