Kinetis FreeRToS interrupt based GETCHAR() PUTCHAR()

cancel
Showing results for 
Search instead for 
Did you mean: 

Kinetis FreeRToS interrupt based GETCHAR() PUTCHAR()

Jump to solution
1,016 Views
carlnormansuret
Contributor V

Hi Guys,

 

Short Version; is there interrupt based DEBUG_CONSOLE_DEVICE_TYPE_UART code so I can have GETCHAR() block properly and let my other tasks run? Currently it sits in a while loop waiting for the RX data flag to be set.

 

Longer version; Ive come from MQX and thought I would give FreeRToS a run on the new Kinetis KL27Z that I have. normally in MQX i use itty to achieve blocking UART commands that will allow the rest of my tasks to run normally while waiting for data to come in.

 

I had to move my debug console to UART (no longer on LPUART), which works fine, I can PRINTF and GETCHAR fine.

 

uartClkSrcFreq = CLOCK_GetFreq(UART2_CLK_SRC);

DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);

 

FreeRToS does not appear to support GETCHAR() that is interrupt based so it literally runs s_debugConsole.ops.rx_union.UART_GetChar = UART_ReadBlocking; which sits in a while(wait for data); loop. I need the rest of my application running, not sitting in a while loop. I do not want to have horribly inefficient context switching and use delays to poll non blocking reads, its 115200 data, its fast, this is not a nice way to do things.

 

Is there examples of how to use an interrupt based version of the debug consol? I need to be able to printf / getchar while running other tasks.

Labels (1)
0 Kudos
1 Solution
238 Views
carlnormansuret
Contributor V

Hi Guys, I had no choice but to get this working... I made a huge mistake and used FreeRToS as the UART so you cant use getchar/putchar (which is EVERYTHING like scanf and printf) until AFTER the scheduler is started (you'll get a lock up condition)

If someone can be bothered to write and post a version that does not use FreeRToS this will allow PRINTF to work BEFORE running the scheduler i.e. to use my code you have to create a new task, and start the scheduler, the new task can call the PRINTF function

Here is what you do (i didnt double check or read this so use at your own risk, and fault find at your own risk, dont have time to make it right. 

Attached is the consol code i quickly made to get me out of trouble. if you fix it or do it better, please sure, I was nice enough to share :smileyhappy:

This is using UART2, so if you need another you'll have to hand code it, i dont have time to do this properly, i just needed a result. Not here for support, just sharing because
this 100% should be standard code, waiting in a while loop in a multithreaded RToS is nothing short of pathetic

I did it using the RToS functions, you could have dont it with standard UART which would no doubt be less overheads

Add this to fsl_common.h
#define DEBUG_CONSOLE_DEVICE_TYPE_FREERTOS_UART 6U

//Change the call to configure consol to this
DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, DEBUG_CONSOLE_DEVICE_TYPE_FREERTOS_UART, uartClkSrcFreq);

DO NOT CALL ANYTHING CONSOLE FUNCTIONS UNTIL AFTER FreeRToS is running!

example:


xTaskCreate(ModemTask, "ModemTask", ModemTask_STACKSIZE, NULL, ModemTask_PRIORITY, NULL);
vTaskStartScheduler();

then inside ModemTask you can use printf, if you do it before, you're dead in the water.

View solution in original post

0 Kudos
4 Replies
239 Views
carlnormansuret
Contributor V

Hi Guys, I had no choice but to get this working... I made a huge mistake and used FreeRToS as the UART so you cant use getchar/putchar (which is EVERYTHING like scanf and printf) until AFTER the scheduler is started (you'll get a lock up condition)

If someone can be bothered to write and post a version that does not use FreeRToS this will allow PRINTF to work BEFORE running the scheduler i.e. to use my code you have to create a new task, and start the scheduler, the new task can call the PRINTF function

Here is what you do (i didnt double check or read this so use at your own risk, and fault find at your own risk, dont have time to make it right. 

Attached is the consol code i quickly made to get me out of trouble. if you fix it or do it better, please sure, I was nice enough to share :smileyhappy:

This is using UART2, so if you need another you'll have to hand code it, i dont have time to do this properly, i just needed a result. Not here for support, just sharing because
this 100% should be standard code, waiting in a while loop in a multithreaded RToS is nothing short of pathetic

I did it using the RToS functions, you could have dont it with standard UART which would no doubt be less overheads

Add this to fsl_common.h
#define DEBUG_CONSOLE_DEVICE_TYPE_FREERTOS_UART 6U

//Change the call to configure consol to this
DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, DEBUG_CONSOLE_DEVICE_TYPE_FREERTOS_UART, uartClkSrcFreq);

DO NOT CALL ANYTHING CONSOLE FUNCTIONS UNTIL AFTER FreeRToS is running!

example:


xTaskCreate(ModemTask, "ModemTask", ModemTask_STACKSIZE, NULL, ModemTask_PRIORITY, NULL);
vTaskStartScheduler();

then inside ModemTask you can use printf, if you do it before, you're dead in the water.

View solution in original post

0 Kudos
238 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Carl,

As you know that only a task can be blocked instead of an api function.

We have the UART example with FreeRTOS which enable a task be blocked, once a char or string has been received, an semphore or event can be triggered, and the blocked task can be ready to be run.

Pls refer to the example:

If you have installed SDK2.0 based on KL27, pls refer to the example:

C:\Freescale\KSDK2.0_KL27\boards\frdmkl27z\rtos_examples\freertos_uart

Hope it can help you

BR

Xiangjun Rong

0 Kudos
238 Views
carlnormansuret
Contributor V

I guess what I was asking for is some examples. I am aware there is an example of LPUART and UART, but they have nothing to do with being integrated into PUTCHAR GETCHAR so that you can use printf etc... MQX has it, but MQX's overheads are a little bit to much.

If anyone has spent the time to integrate the UART / LPUART stuff into the debug consol init and feel like sharing, that'd be handy... I would have thought this would be a default option because people will use GETCHAR / PUTCHAR and PRINTF for that matter with the requirement of not stopping the entire processor from being able to function...

I am in the process of making my own wrappers to do all this, but I am really surprised its not set up..

0 Kudos
238 Views
priya_dwivedula
Contributor III

Please let me know if you had any luck with the debug console. I am running into same problem, where my entire application is waiting because of UART blocking function calls and I want to be able to run other tasks while waiting for data from the console.

0 Kudos