UART driver with FreeRTOS on K66

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART driver with FreeRTOS on K66

3,005 Views
mmoncigoli
Contributor III

Hello community,

I need to implement a UART driver for a project with K66 micro-controller which uses FreeRTOS. Looking at KSDK_2.0.0, I saw there is a UART driver code examples among FreeRTOS ones ("freertos_uart"). I do not want to use KSDK library to implement this UART driver because I want to have it very simple and easy to be debugged.

 

In my project I have 2 UARTs which are handled by two different tasks. These tasks won't communicate directly.

So my question is: what kind of advantage I can have in implementing a UART driver like the one in "freertos_uart" code example? Wouldn't my UART driver code be easier to debug if I just developed it without using KSDK library functions and just using FreeRTOS "...FromISR"API functions inside the ISRs?

 

Thanks so much to anyone who can provide me with some help

Labels (1)
0 Kudos
3 Replies

1,301 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Drugo,

Regarding your question, it seems that you want to use FreeRTOS and do not want to use the uart driver in SDK2.0, of course, it is okay. For the example code located at:

C:\Freescale\SDK2.0_K64F\boards\frdmk64f\rtos_examples\freertos_uart\kds

The freertos_uart examples is based on the example without OS located at:

C:\Freescale\SDK2.0_K64F\boards\frdmk64f\driver_examples\uart\interrupt_ring_buffer_transfer\kds

This is the mechanism of interrupt_ring_buffer_transfer example, first of all, the uart is initialized, a callback functioin is installed, then call the sender() or receiver() function. The example uses interrupt mechanism to transfer data, in other words, in the ISR of uart, the UARTx_D is read or written in ISR of the uart, in the ISR, we check if the predefined number of data has received or sent, if the predefined number of data has been received or sent, the callback function is called. In   the main(), user should create the callback function himself, in the callback(), update a bool flag. in the main(), user should poll the flag to know if the redefined number of datas has been received or sent.

The rtos_examples is based on the interrupt_ring_buffer_transfer example, because the FreeRTOS is used, in the above callback() function, the xEventGroupSetBitsFromISR() is called. While in the UART_RTOS_Send()  or UART_RTOS_Receive() function, the mcu is blocked at the function xEventGroupWaitBits(), the FreeRTOS can switch the task automatically based on the event triggering mechanism. But If you use FreeRTOS, it is difficult to debug.

From your description, it seems that you want to write the uart code yourself withour calling the SDK driver based on interrupt, it is okay, but if you call the xEventGroupSetBitsFromISR() in ISR of uart, the efficiency of code is very very low, because sending/receiving EACH byte, the xEventGroupSetBitsFromISR() is called and OS have to swich task. If you use the mechanism that after a bunch of bytes has been transferred, an event happens, and the OS switch task, it is the same as the rtos_examples, why do not you use it?

Hope it can help you.

BR

Xiangjun Rong

0 Kudos

1,301 Views
mmoncigoli
Contributor III

Hello Xiangjun, thanks a lot for your answer! And I am sorry for my late answer, but I was on vacation...

I think that what you said about calling xEventGroupSetBitsFromISR() in UART ISR makes lot of sense.

The main reason of my original post is that, as I did when I was recently working with Microchip platforms, I would like to write my UART driver (ISR and the relevant TX and RX UART interface functions) WITHOUT using KSDK library functions.

Why this?

Because, in my opinion, UART driver is pretty "simple". I mean, it is not easy, but neither complicated. So I would like to keep it simple (simple for a firmware engineer who wants to access to the register fields directly from his code). I will then manage FreeRTOS interface with the related ISR-APIs they provide.

In Microchip, for example, I wrote my ISR following their naming/parameters convention and, inside, I checked if the flag of RX data was high. In that case my code read the register to get incoming data, cleared a UART register flag to enable again the reception through ISR and so on.

The big advantage I personally see in this approach is simplicity in debugging the code.

Yesterday I started to read the good document written by Jorge Gonzalez (for KSDK v1.2 and KDS v3.0.0)

https://community.nxp.com/docs/DOC-104352

Is there an updated version of this document for KSDK v2.0? I didn't find it in the website.

Thanks so much for your precious help

Drugo

0 Kudos

1,301 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Drugo,

The SDK2.0 is different from SDK1.3, there is one SDK for each processor in Kinetis family. For example, if you use K64, pls download the SDK2.0 for only K64. After you download SDK2.0, you can check the doc in the directory:

C:\Freescale\SDK2.0_K64F\docs

Hope it can help you.

BR

Xiangjun Rong

0 Kudos