Have been worked a few projects with KDS and MCUXprosso, and currently using MCUXpresso 11.1.1 and Kinetis SDK 2.7, I found myself still having problems on how to use printf() to send data to a UART console.
There are three ways to configure a project regarding printf() to UART console
It is convenient to have multi-places for some key configurations, but it is confusing as well. For instance, you could have identical Preprocessor settings but projects behave in different ways.
Here is the procedure to create a project with printf() which I have had problem with. And I cannot find any solid information on how to use standard IO library printf for uart console in MCUXpresso configuration.
Step 1 – Create a new project from MCUXpresso Quick Panel
Step 2 - Choose right SDK software components
case 1:
case 2:
In my case, since I just use UART for connecting to Tera Term VT100 screen, so I simply do:
1. Select FreeRTOS
2. Select all Drivers
3. Select all CMSIS Drivers
4. On Utilities, I have done two ways:
(1). Select none
(2). Select Serial manager shown above
Step 3 - Advanced configurations (tried multi cases, got the same result)
case 1: use Redlib (nohost)
case 2: use NewlibNano (nohost)
Step 4 - Check the configurations from Project Property
It is confusing that the UART is not selected as I have done so in Step 2, but it can be reconfigured.
I checked the configuration from Quicksettings, and it is correct here.
Step 5 - Run the project and see the result
Result: printf() did not send anything to the UART (without set SERIAL_PORT_TYPE_UART=1).
"MCUXpresso & Kinetis K64 MCU" shown in the console captured in the screenshot below is done by UART_WriteBlocking() for checking UART configuration.
Step 6 - Modify Preprocessor by adding SERIAL_PORT_TYPE_UART=1, and run the project and see the same result
Result is the same.
The UART can be read or written properly with other functions, but printf() cannot route information to the UART, and I have tried with different configurations and I am unable to make it work.
The way I have made printf() work properly on UART/TeraTerm is via semihosting, which I not sure why I have to do that.
A project working properly should look like:
What did I miss here?
Thanks.
Solved! Go to Solution.
I have been using printf for UART console in a few projects with KDS and MCUXPresso IDE and SDK 2.6/2.7, but I did not document the procedure on how I did that and I could not replicate it recently in creating a new Kinetis project. After downloading MCUXpresso 11.2.0 and updated to the SDK 2.8, I decided to give it another try(I need to use printf/sprintf and other stdio functions instead of using PRINTF). This time I figured out how to do so and here are the steps.
To create a new project for a device in MCUXpresso:
1. Select FreeRTOS
2. Select all Drivers
3. Select all CMSIS Drivers
4. Instead of selecting proper Utilities, I went to next: Advanced project settings first:
As can been from screenshot below, you are able to check without checking , I checked as well since I need to use floating point version of printf (this can be done later in Quick Settings).
After that I go back to select Utilities:
Then, click Finish to create the new project.
In Settings ->Preprocessor, you should see the settings as below (If you see CR_INTEGER_PRINTF, remove it for floating point)
Then, you should be able to use all standard library functions in your application.
Hope this helps.
Regards.
I have been using printf for UART console in a few projects with KDS and MCUXPresso IDE and SDK 2.6/2.7, but I did not document the procedure on how I did that and I could not replicate it recently in creating a new Kinetis project. After downloading MCUXpresso 11.2.0 and updated to the SDK 2.8, I decided to give it another try(I need to use printf/sprintf and other stdio functions instead of using PRINTF). This time I figured out how to do so and here are the steps.
To create a new project for a device in MCUXpresso:
1. Select FreeRTOS
2. Select all Drivers
3. Select all CMSIS Drivers
4. Instead of selecting proper Utilities, I went to next: Advanced project settings first:
As can been from screenshot below, you are able to check without checking , I checked as well since I need to use floating point version of printf (this can be done later in Quick Settings).
After that I go back to select Utilities:
Then, click Finish to create the new project.
In Settings ->Preprocessor, you should see the settings as below (If you see CR_INTEGER_PRINTF, remove it for floating point)
Then, you should be able to use all standard library functions in your application.
Hope this helps.
Regards.
Hello zhiqunhu,
I'm trying to do the same initialization but I stuck at "Advanced project settings". I use MCUXpresso IDE v11.5.0 with 2.11.0 SDK Version (MK64FN1M0xxx12). I can't select 'Redirect print/scanf to UART' (it's not active) without checking 'Redirect SDK "PRINTF" to C library "printf"'. It would be nice to have possibility to use standard printf. I tried to set different library types and hosting variants but it didn't help.
Do you have some idea? Did I miss come setting?
Best regards!
The way to make PRINTF() work is to follow configurations below:
1. Step 1 is the same as that in previous post.
2. Step 2 Configure the project:
(1). Select RTOS, Drivers and CMSIS Drivers the same way as previous post.
(2). Select Utilities as the screenshot below:
Please note to select uart_adapter, otherwise you will get the error like this of missing uart.h file:
Step 3 - Advanced project settings
To check on Redirect printf/scanf to UART, you have to check at Redirect SDK "PRINTF" to C library "printf"
If you check SDK Debug Console from QuickSettings, you will see UART is not selected. And if you take a look at the Preprocessor, you will see SDK_DEBUGCONSOLE=0.
I ran the project and got:
From assemble code, you can see PRINTF() is still using printf(), so that is why there is nothing to UART.
So you need to modify SDK_DEBUGCONSOLE=1, then build/run again and as can be seen from assembly code, right now PRINTF calls DbgConsole_Print(), so the string "Kinetis uProject: Ver" come to Tera Term console via UART.
Regards.