UART send and receive integration with freeRTOS

cancel
Showing results for 
Search instead for 
Did you mean: 

UART send and receive integration with freeRTOS

5,533 Views
Contributor V

Hi,

Can someone please post me the source code of UART driver(sample send and receive feature) integrated with freeRTOS.

Thanks

Mohan

27 Replies

318 Views
NXP Employee
NXP Employee

Hi Mohan, 

here is example using LPUART under FreeRTOS. In the example is also implemented printf/scanf functionality. 

Jiri 

318 Views
Contributor V

Hi Jiri,

Do you have this same source code ported for S32K144 platform.

I am not able to compile this source. I am ending with compilation errors. Also there are too many dependencies while importing the source code.

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

Hi Mohan, 

did you generate Processor Expert code  build? 

pastedImage_1.png

The example is for latest S32DS ARM 2.0 version and SDK v0.8.4. If you are using old S32DS ARM 1.3 - you have to change paths and so on. 

Jiri

0 Kudos

318 Views
Contributor V

Hi Jiri,

I have a question about this example.

In this sample scanf and printf are used. Is these functions are equivalent to reading and writing to UART ?.

Whether these functions are directly mapped to UART interrupt ?

Please guide.

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

Hi Mohan, 

scanf/printf in this example are using LPUART - but aren't equivalent to send/receive data. For UART receive/send data you can use SDK functions LPUART_DRV_SendData() and LPUART_DRV_ReceiveData(). 

Jiri

0 Kudos

318 Views
Contributor V

Hi Jiri,

In my product there is communication between Snapdragon processor and S32K144 MCU over UART.

Basically it will be request and response kind of requirement over UART.

Then, can I use these scanf and printf to read request and send response respectively on S32K144 MCU side ?

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

Well, you can use printf/scanf - but these functions are designated more to interaction with human than with the other machine. Also implementation of printf/scanf consumes quite big portion of memory.  

Best way how to communicate with other MCU via UART is using functions mentioned above - LPUART_DRV_SendData() and LPUART_DRV_ReceiveData().  

Jiri

318 Views
Contributor V

Hi Jiri,

With default code you shared, binary size is 70 KB.

I customized the code as per my requirement.

For your information:

I am not using printf/scanf, instead I am using LPUART_DRV_SendData() and LPUART_DRV_ReceiveData().

Customized code has only below files.

      pastedImage_1.png

Customized rtos.c has simple implementation(below snippet),  uARTTask task will receive and send data from UART using above functions.

*******************************************************************************************

void rtos_start( void )
{
   prvSetupHardware();
   xTaskCreate( uARTTask, "TX", configMINIMAL_STACK_SIZE, NULL, TASK_PRIORITY, NULL );
   vTaskStartScheduler();
   for( ;; );
}

*******************************************************************************************

Now the question is why binary of this simple implementation is 45KB ? Any suggestions please. 

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

Hi Mohan,

You probably aren't using printf in your code - and printf function was removed by linker (this why binary size was shrank to 45k). FreeRTOS itself consumes also big portion of memory. 

Jiri

318 Views
Contributor V

Hi Jiri,

Ok, then I understand it is because of freeRTOS, memory is consuming 45KB .

Then can you please share me the steps which you followed while creating project for freeRTOS integration with LPUART support. So with this knowledge I will check whether I can customize if possible. 

The reason is I still have lot of stuff's to implement with the available 64KB memory :smileysad:

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

I just grabbed freertos example from S32DS and added lpuart in the processor expert. That's all. If you need FreeRTOS and LPUART in your project - the easiest way is exactly what you did - remove from the example console and memmon functionality. 

If you are focusing to save RAM usage  - consider if you really need FreeRTOS.

Jiri 

318 Views
Contributor V

Hi Jiri,

When I just run the project you had shared, it works fine !

However when I create project from scratch and add freeRTOS,lpuart and other stuffs, it is not working.

I mean receiving is not working.

Should I do any specific settings in the project, please guide.

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

Hi Mohan, 

can you share your project? There is no specific settings - just some standard one like init UART and set correctly IO pins. 

Jiri 

0 Kudos

318 Views
Contributor V

Hi Jiri,

How shall I share my project ?

Thanks

Mohan

0 Kudos

318 Views
NXP Employee
NXP Employee

Just attach zip file with your project (zipped folder from your workspace) in this thread - as a part of comment. You can attach files by clicking on Use advanced editor and on the bottom of dialog is Attach icon. 

pastedImage_1.png

Jiri

0 Kudos

307 Views
Contributor V

Hi Jiri,

advanced editor option is available in IE.

I am attaching the project file.

To test the application, please type GVER on putty(baud rate is 115200). MCU should send these characters back to putty console.

Thanks

Mohan

0 Kudos

307 Views
NXP Employee
NXP Employee

Hi, 

so - it looks like that optimization level -O2  causes the issue in your project. For some reason - IO pins can't be initialized and MCU ends in exception. I'll do more investigation. So - quick workaround is disable optimization.

Jiri

307 Views
Contributor V

Hi Jiri,

Yes after removing the optimization, it is working. Thanks.

But optimization is must for me due to RAM memory constraint in my project.

Thanks

Mohan 

0 Kudos

307 Views
NXP Employee
NXP Employee

I understand. Anyway - thanks for report. It looks like that the issue is inside the SDK in PINS_DRV_Init() fucntion. I'll create JIRA ticket for SDK team. I think that you are okay with RAM. Your project now consumes abot 14kB of RAM - including freeRTOS 8kB heap memory. 

Jiri

307 Views
Contributor V

Hi Jiri,

Strange thing is with other optimization options, my application is working. Problem is seen only with -O2 option.

I used optimization option as -Os and below is the output.

text       data       bss       dec          hex    filename
15956    2320    11784    30060    756c    Test_AP_MCU.elf

With above data can you rephrase your statement "Your project now consumes abot 14kB of RAM - including freeRTOS 8kB heap memory" with little more explanation.

Thanks

Mohan

0 Kudos