Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Strange problem using printf in C with STM32F407VE

Not open for further replies.


Full Member level 5
Sep 16, 2003
Reaction score
Trophy points
Activity points

I've used printf function in many of my older projects without any problem, i.e stm32f103 or stm32L071 MCUs and ... (all Keil compiler).
but just got a strange problem running a simple code on STM32F407VET6.
The problem is that when I program the code on the MCU, after restart, it doesn't run the code at all.
I tried online debugger (ST-Link) to check what happens exactly, after starting the debug session, and clicking on F5 (Run) it pauses fast, then I need to click F5 3 times more and then the code runs without any problem !!!

I simplified the code to find the problem point and found it's because of just using printf command !
The problem is just using it in the code (and the complier complies it's library and adds code size) makes the problem at start up ! although the printf works correctly in the code !

here is the simplified code:

just removing the printf function solves the startup problem !
please note that the problem is just at startup (not when it reaches printf function) !

I'm confused what can be the reason ... any settings in Keil ? or ...
I tried changing complier version in Keil settings, but no result.
I tried sprintf function and didn't face that problem. seems it just happens when I use printf function in code and which makes me more confused is that the problem is only at startup of the code as described above not even reaching the printf function ... and if the codes starts anyway, it will work fine ! (printf works correctly).

Maybe it needs a format string or destination for the output but I would have thought the compiler would warn you.
Something like "printf("%c","S");


The printf function works well, the only problem is when I use it in code, startup problem occurs as I described.

I just tried different settings in compiler and found when I check "Use MicroLIB" the startup problem doesn't occur ! and code size also decreases ...

here is a screenshot:

I don't know what does that setting do exactly, but I reviewed my older projects (which didn't have the startup problem) and saw in all of them that this setting is checked (and I know I didn't check it manually).
I guess STMcubeMX doesn't check it in it's newer version (I recently updated it to the last version - V6.8.0). I even made a project for STM32L071 which I had worked without any problem before and saw when I open project in Keil, that setting is not checked by default ... (probably by STMcubeMX default project file ).


I would have thought the compiler would warn you.
The compiler output shows "1 warning", but the OP does not show...

Compiler warnings are rather useful ... especially in case of problems, it´s the first place to read them.

Last edited:
How is standard output assigned in your design?
--- Updated ---

See respective discussion for ST GCC tool chain. Probably different solution for Keil.
Thanks for your reply, as I wrote in my last post, I found the problem, In the last version of STMCubeMX (which I recently updated to) it doesn't check "Use MicroLIB" in the output project by default and it makes the problem, when I manually check it, code size decreases and works fine.
I searched about "Use MicroLIB" in keil and found they say when we check it, libraries like STDIO and ... can be used on non OS systems (like my project).
Seems when it's not checked in Keil, it adds and runs some functions which need OS to work fine so it stops MCU working at start point (when calling those functions).

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to