EXAMPLE: S32k144 UART printf/scanf under FreeRTOS - S32DS

cancel
Showing results for 
Show  only  | 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!

i creat three task in this demo, but it doesn't work, seems all hold on, can you check it ?

@jiri_kral 

static void prvQueueTestTask( void *pvParameters )
{
unsigned long ulReceivedValue;
 
/* Casting pvParameters to void because it is unused */
(void)pvParameters;
int i = 0;
printf("first prvQueueTestTask=%d\n",i);
for( ;; )
{
/* Wait until something arrives in the queue - this task will block
indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
FreeRTOSConfig.h. */
//xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
printf("prvQueueTestTask=%d\n",i);
/*  To get here something must have been received from the queue, but
is it the expected value?  If it is, toggle the LED. */
vTaskDelay(pdMS_TO_TICKS(10));
 
}
}
/*-----------------------------------------------------------*/
 
void rtos_start( void )
{
/* Configure the NVIC, LED outputs and button inputs. */
prvSetupHardware();
 
/* Create the queue. */
xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
 
if( xQueue != NULL )
{
/* Start the two tasks as described in the comments at the top of this
file. */
 
xTaskCreate( prvQueueReceiveTask, "RX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );
xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
xTaskCreate( prvQueueTestTask, "TEST", configMINIMAL_STACK_SIZE, NULL, 3, NULL );
 
/* Create the software timer that is responsible for turning off the LED
if the button is not pushed within 5000ms, as described at the top of
this file. */
xButtonLEDTimer = xTimerCreate( "ButtonLEDTimer", /* A text name, purely to help debugging. */
mainBUTTON_LED_TIMER_PERIOD_MS, /* The timer period, in this case 5000ms (5s). */
pdFALSE, /* This is a one shot timer, so xAutoReload is set to pdFALSE. */
( void * ) 0, /* The ID is not used, so can be set to anything. */
prvButtonLEDTimerCallback /* The callback function that switches the LED off. */
);
 
/* Start the tasks and timer running. */
vTaskStartScheduler();
}
 
/* If all is well, the scheduler will now be running, and the following line
will never be reached.  If the following line does execute, then there was
insufficient FreeRTOS heap memory available for the idle and/or timer tasks
to be created.  See the memory management section on the FreeRTOS web site
for more details. */
for( ;; );
}

i resolved it, thanks

Version history
Last update:
‎09-08-2017 04:15 AM
Updated by: