Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

LPC17xx Serial example

Posted by Ron B on February 25, 2010
Hello, I am trying to make a serial driver for the LCP1768, which I tried to derive from the serial driver that was included with STM32 examples. My example is close, but crashes "after some time." Does anyone have a good example that works with the LPC17xx series?

Thanks

RE: LPC17xx Serial example

Posted by Ron B on February 27, 2010
Well I haven't seen a follow up yet, so let me expand my issue.

The main problem that I am having with the LPC1768 is that you cannot have a fully interrupt driven serial driver because the Transmit ISR only triggers on a FIFO transition to empty instead of generating interrupts while empty. So while IDEALLY I would like to do this:

My code would call this function to place characters into the serial buffer:

signed portBASE_TYPE serial_putChar(signed portCHAR ch, portTickType xBlockTime )){
signed portBASE_TYPE xReturn = pdFAIL;
xReturn = xQueueSend( TxQueue, &ch, xBlockTime );
UART1->IER |= UART_IER_THREINT_EN;
return xReturn;
}


And this would be the serial interrupt handler:

void serialISR(){
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
portCHAR cChar;

if(UART1->IIR & UART_IIR_INTID_THRE){
if( xQueueReceiveFromISR( TxQueue, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE ){
UART1->THR = cChar;
}
else{
UART1->IER &= ~UART_IER_THREINT_EN;
}
}
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}

This part doesn't work like that.

So I am working to have a task load the THR transmit register for me. This is what I have so far (rough outline):

My main function call would be

signed portBASE_TYPE serial_putChar(signed portCHAR cOutChar, portTickType xBlockTime )
{
signed portBASE_TYPE xReturn = pdFAIL;
if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS ){
xReturn = pdPASS;
}
return xReturn;
}


The interrupt handler:

void serialISR(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
portCHAR cChar;


if(UART1->IIR & UART_IIR_INTID_THRE){
{
xSemaphoreGiveFromISR(xSendSemaphore, &xHigherPriorityTaskWoken);
}
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}


And my task to load characters into the THR register would be

void xUARTsendTask(void *pvParameter)
{
uint8_t sendChar;
vSemaphoreCreateBinary(xSendSemaphore);
xSemaphoreTake(xSendSemaphore, 0);

for( ;; ){
xQueueReceive(xCharsForTx, &sendChar, portMAX_DELAY);
UART1->THR = sendChar;
xSemaphoreTake(xSendSemaphore, portMAX_DELAY);
}
}


The problem I have with this is that it halts have transmitting 2 characters. So what I am looking for is some ideas on making this work.

RE: LPC17xx Serial example

Posted by Richard Damon on February 27, 2010
While I am not familiar with this processor, here is what I tend to use a the pseudo code for the transmit character routine:

Place character into software queue
if that worked and serial transmit buffer is empty, force transmit buffer empty serial interrupt.

The key here is finding a way to force the interrupt. On many processors you can write to the interrupt request flag to set it, or have some other way to trigger the interrupt.

RE: LPC17xx Serial example

Posted by tgarner on February 27, 2010

What I usually do is use the Tx interrupt enable as a busy flag.

Putchar(c)
{
if( Tx IE flag )
put c in Queue
else
{
Set Tx IE flag
Write C directly to hardware
}
}


ISR
if char in Queue
transmit it
else
turn off Tx IE flag

RE: LPC17xx Serial example

Posted by Richard Damon on February 27, 2010
That has a race condition. If the interrupt for the last character going out occurs between the test of the IE flag and the insertion into the queue, then you end up with a character in the queue that will get output out of order, as the next character sent out will go directly to the transmit buffer, and then the queued character. One fix, if it is available, is to disable interrupts around the code.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists