Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Timer and Uart usage in FreeRTOS with Keil

Posted by Mehmet Ali YARIM on June 19, 2009
Im using LPC2138, FreeRTOS and Keil combination.
1) I can use the "vSerialPutString" successfuly to print text only mesages on UART0. But it doesn't support parameter (e.g. %d, %x, %s ).

--> tried to assemble the full masage with "sscanf" (in Keil lib) and then call the "vSerialPutString". Faced some difficulties.

--> than decided to use the Keil's "printf". so retraged the "putchar" and "getchar" functions in "retarget.c" to "xSerialPutChar" and "xSerialGetChar". This time text is printed successfuly but parameters such as %d, %c failed and system hangs on first print of string.

--> than I gave up insisting to use functions "xSerialPutChar" and "xSerialGetChar" funtions because it is communation with UART_ISR with the help of Queues etc after I spend much time investigating the issue, although I found a solution which is not so neat. If a delay accorind to baudrate is added in the "xSerialPutChar" it is working fine.

--> than I retarget the "putchar" and "getchar" functions in "retarget.c" to
Keil's own implementation of them. So putchar waits TX buff to be empty and sends the new char. This time it is working nice, can print pramaters embedded within text. But calling "printf" from multiple tasks fails, so I protected printf with binay semaphore.

Anybode faced such issues, any comments ?

2) What system resources FreeRTOS uses? Can anyone please list it ?
Becase I want to use timer and notices that systemtick is using timer0 module (in "port.c"). on API it is suggested to use now I am considering to use "vTaskDelayUntil" and "vTaskDelay" system function of FreeRTOS. for exact timing "vTaskDelayUntil" is recommended I think ?

I could not managed to implement my own tick rates on timer1 ISR, I though I am sure about initialization steps and ISR implementations. Any idea ?

any comment on using "printf" in ISR considering the binary semaphore guarding and xportYIELD/ xportYIELDfromISR usage ?

all the best

RE: Timer and Uart usage in FreeRTOS with Kei

Posted by Richard on June 19, 2009
The xSerialPutChar() function is intended to demonstrate using queues to communicate between tasks and interrupts and to test the port. It is not intended to be an efficient example of a UART driver, especially on the LPC parts. A much more efficient and practical method would be to turn on all the UART FIFOs/Buffers/DMA [whatever is available] and use those to feed the peripheral with characters. The UART should only then generate interrupts when transmission has ended, or a buffer is full - rather than on every character. Ideally drivers would not poll UART registers, but be completely event driven.

You have to be careful with using printf() etc because some implementations can use massive stacks, and hence cause problems. You can use the stack checking features of FreeRTOS to trap these. I normally use the cut down and very stack light printf-stdarg.c implementation (search for it in the FreeRTOS download) for its sprintf() functionality, which admittedly is somewhat limited but can be extended. I don't use other functions defined in the same file however as at least one contains a bug that I am aware of.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.


FreeRTOS and other embedded software careers at AWS.

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner