EXAMPLE: S32k144 UART printf/scanf under FreeRTOS - S32DS

cancel
Showing results for 
Search instead for 
Did you mean: 

EXAMPLE: S32k144 UART printf/scanf under FreeRTOS - S32DS

100% helpful (1/1)

EXAMPLE: S32k144 UART printf/scanf under FreeRTOS - S32DS

Application based on FreeRTOS S32DS example performs prinf/scanf functionality
in FreeRTOS. Application runs in two modes - standard run-time mode with two tasks
maintained by scheduler and command mode implementing basic memory monitor.
Application was tested with putty terminal (http://www.putty.org/).

Putty serial terminal settings: 115200 8N1, no HW control.

USAGE:
In run-time mode is green LED blinking and on terminal are shown task
counter values.

To enter into COMMAND MODE - press button (next to LED diode). LED light
switches to red and you can enter commands.

Available commands:
===================

F show free heap memory
A set memory address
V print value on address
M set address to main()
P previous mem page
N next mem page
? help
X Exit from command mode

Putty configuration:

pastedImage_1.png

pastedImage_3.png

Terminal output:

putty_2017-09-21_10-12-40.png

Attachments
Comments

Hi Jiri Kral

Thanks.

But if I try to use printf/scanf exclusive of freeRTOS.

Is there any other way can reach this feature?

Hi, 

sure - you can use and modify in your project console.c and console.h files. That's where printf/scanf callbacks are implemented.

Jiri

Hi Jiri,

Can you tell me how to config the project that I can use printf to print serial port.

I download your attached project and copy the console.c & console.h, also initialize the LPUART1 and then use printf function in my code, but cannot see serial port print log.

But use the download project you provided it works.

Please advice, thanks.

Hi, 

well, it's hard to say what may be wrong. You can copy/paste the LPUART init from rtos.c . Also don't forget set PTC6 as input and PTC7 output and check uart speed. 

pastedImage_1.png

Hope it helps. 

Jiri 

Hi Jiri,

Thanks for relly, I cannot upload attachment file in this thread, can you help on below issue:

https://community.nxp.com/message/1029038 

Hi, 

for some reason your link is not accessible for me. Did you create your thread in https://community.nxp.com/community/s32/s32ds  community space? 

Jiri 

Yes, under S32K, my topic named:

Printf in FreeRTOS

Hi Jiri,

Try your project, printf function is ok, but cannot type in command in command mode?

I don't konow why, I am using the S32K144 EVB and use usb to serial port cable.

Hi, 

what terminal you are using? In RealTerm - RealTerm: Serial/TCP Terminal - Browse /Realterm/2.0.0.70 at SourceForge.net 

is input working okay. 

Jiri 

I use putty:

pastedImage_1.png

If I remember it correctly - in putty you need to setup the end character. So - you can give a chance to RealTerm - this one works out of box. 

Jiri 

Hi, 

I tried fresh Putty install, and for me it also works out of the box: 

pastedImage_1.png

Here is my putty settings: 

pastedImage_2.png

Jiri

Thanks Jiri,

Maybe there are some hardware or connection issue in my side, I will show your the capture of my board and serial line connection.

Hi,

   I can also compile using your project and pringf output is ok.I copied your console.c and.h files into my project. After adding the reference path, you can compile.But printf can't output, the code card dies here.

Hi,

I can also compile using your project and pringf output is ok.I copied your console.c and.h files into my project. After adding the reference path, you can compile.But printf can't output, the code card dies here.

Hi,

I can also compile using your project and pringf output is ok.I copied your console.c and.h files into my project. After adding the reference path, you can compile.But printf can't output, the code card dies here.

Hi Jiri,

Thanks for providing this sample code. With some modification, now I can use printf on S32K118.

I put scanf() in a task, and I found the task have high percentage of run time loading. That's because the __read_console traps in the LPUART_DRV_GetReceiveStatus if there is no input data.

int_t __read_console(__file_handle handleuchar_t * buffersize_t * count)
{
  uint32_t bytesRemain;
  bool MsgDone=false;
  uchar_t new_lin[]={"\n"};
  int i=0;
  while (MsgDone==false)
  {
    LPUART_DRV_ReceiveData(INST_LPUART1, &buffer[i], 1);
    while(LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);

Thus, I add some delay in the while loop or use LPUART_DRV_ReceiveDataBlocking with portMax_DELAY, then the run time loading becomes normal. I was wondering if this a correct method. If so, I think this could be a reference for others. 

int_t __read_console(__file_handle handleuchar_t * buffersize_t * count)
{
  uint32_t bytesRemain;
  bool MsgDone=false;
  uchar_t new_lin[]={"\n"};
  int i=0;
  while (MsgDone==false)
  {
    // LPUART_DRV_ReceiveData(INST_LPUART1, &buffer[i], 1);
    // while(LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS)
    //  {
    //    vTaskDelay(5);
    //  }
    LPUART_DRV_ReceiveDataBlocking(INST_LPUART1, &buffer[i], 1, portMAX_DELAY);

Regards,

Jimmy

bug.JPG

ds.JPG

Hi, I use your console.h and console.c file in my project, but get that problem, How can i do this? thank you very much.

bug2.JPG

if I use another config, still have error,I don't know how to slove this erroe,  Thank you!

Version history
Revision #:
1 of 1
Last update:
‎09-08-2017 04:15 AM
Updated by: