FreeRTOSV7.1.0 on PIC18F25k80 Queue - Uart

voloviq wrote on Friday, February 10, 2012:


I ported example number 2 for pic18f452 to pic18f25k80. Porting sucesful everything compile etc.

When I create one task just only one task which receive some data from queue UART1 system restar in some period (period is different all the times).

Below my configuration:

Linker script:

// File: 18f25k80_g.lkr
// Generic linker script for the PIC18F25K80 processor



    FILES c018i_e.o
    FILES clib_e.lib
    FILES p18F25K80_e.lib

    FILES c018i.o
    FILES clib.lib
    FILES p18F25K80.lib


  CODEPAGE   NAME=page       START=0x0               END=_CODEEND
  CODEPAGE   NAME=page       START=0x0               END=0x7FFF

CODEPAGE   NAME=userid     START=0x200000          END=0x200007       PROTECTED
CODEPAGE   NAME=cfgmem     START=0x300000          END=0x30000D       PROTECTED
CODEPAGE   NAME=devid      START=0x3FFFFE          END=0x3FFFFF       PROTECTED
CODEPAGE   NAME=eedata     START=0xF00000          END=0xF003FF       PROTECTED

  DATABANK   NAME=gpre       START=0x0               END=0x5F
  ACCESSBANK NAME=accessram  START=0x0               END=0x5F

//DATABANK   NAME=gpr0       START=0x60              END=0xFF
//DATABANK   NAME=gpr1       START=0x100             END=0x1FF
//DATABANK   NAME=gpr2       START=0x200             END=0x2FF
//DATABANK   NAME=gpr3       START=0x300             END=0x3FF
//DATABANK   NAME=gpr4       START=0x400             END=0x4FF
//DATABANK   NAME=gpr5       START=0x500             END=0x5FF
//DATABANK   NAME=gpr6       START=0x600             END=0x6FF
//DATABANK   NAME=gpr7       START=0x700             END=0x7FF
//DATABANK   NAME=gpr8       START=0x800             END=0x8FF
//DATABANK   NAME=gpr9       START=0x900             END=0x9FF
//DATABANK   NAME=gpr10      START=0xA00             END=0xAFF
//DATABANK   NAME=gpr11      START=0xB00             END=0xBFF
//DATABANK   NAME=gpr12      START=0xC00             END=0xCFF
DATABANK   NAME=gpr12      START=0xB00             END=0xCFF            PROTECTED

  DATABANK   NAME=gpr13      START=0xD00             END=_DATAEND
#ELSE //no debug
  DATABANK   NAME=gpr13      START=0xD00             END=0xDFF

DATABANK   NAME=gpr14      START=0xE00             END=0xE40
DATABANK   NAME=sfr14      START=0xE41             END=0xEFF          PROTECTED
DATABANK   NAME=sfr15      START=0xF00             END=0xF5F          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60             END=0xFFF          PROTECTED

    STACK SIZE=0x1FF RAM=gpr12
    STACK SIZE=0x1FF RAM=gpr12

Task creation

xTaskCreate( Receiver_Tmp, ( const char * const ) “Urt_Rx”, 250, NULL, 1, NULL );

Task definition

static void Receiver_Tmp( void *pvParameters )
    unsigned char i;
    char bt;
    portTickType xUart1Rate, xLastUart1Time;

    /* The parameters are not used. */
    ( void ) pvParameters;

    /* Calculate the LED and flash rate. */
        i = 0;
        bt = 0;
        xUart1Rate = 10;

        /* We need to initialise xLastFlashTime prior to the first call to
        vTaskDelayUntil(). */
        xLastUart1Time = xTaskGetTickCount();

        for(i = 0; i < inputRECEIVER_BUFFER; i++)
            str_1_ = 0x00;

        i = 0;

    for( ;; )
        while(xSerial1GetChar( NULL, &bt, mainNO_BLOCK ))
            str_1 = bt;

            if(bt == 0x03)
                PORTBbits.RB5 = !PORTBbits.RB5;
                //Emar_Frame_Analyze( str_1, &cfr );
                bt = 0;
                i = 0;
                i %= inputRECEIVER_BUFFER;
        vTaskDelayUntil( &xLastUart1Time, xUart1Rate );

Queue definition:

        xRx1edChars = xQueueCreate( 150, ( unsigned portBASE_TYPE ) sizeof( unsigned char ) );
xCharsForTx1 = xQueueCreate( 50, ( unsigned portBASE_TYPE ) sizeof( unsigned char ) );

Frames which incoming to uart receive come with 38400 bd usualy 20 bytes with gap between consecutive frames 200

Can anyone help me to resolve this problem because my idea was finished now ;(


rtel wrote on Saturday, February 11, 2012:

PIC18 is not an ideal target in this scenario.  That said…

If the code is linking then your linker script is probably ok, at least it is defining a block large enough to hold a heap.  Did you also check the math and temp data section sizes, which can vary with builds?
Does your system work as you expect for a while, then reset, or not work at all before resetting?


voloviq wrote on Tuesday, February 14, 2012:


first of all thanks for reply.

I discover that in generic example number 2 in flash led section at the end was invoke function named xTaskResumeAll( void ) as I good remember. When I remove this function system seems to be work as shoud be but sometimes also hung up. This hung up is probably caused be me probably some array but I must it check very careful.

One question concerning to this function xTaskResumeAll( void );.

What this function do indeed?

Where is located math and temp data section sizes definitions ?

Thanks for any answers
BR Voloviq

voloviq wrote on Tuesday, February 14, 2012:

Sorry I forgotten one thing,

all system start and work well for 10minutes, 20minuts sometimes 60minutes and hung up. Hung up all tasks. Do exist some procedure to quickly find leakage because stack protect doesn’t as should be.

Regards Voloviq

voloviq wrote on Wednesday, February 15, 2012:

After careful reading of documentation seems to function xTaskSuspendAll( void );.
xTaskResumeAll( void );. has completly no influence. One thing from my site need to be clarify. I use in this project 2 UARTS one only receive frames and second one transmit data with new data (something like converter). Unfortunately I use for both UARTS interrupt, one receive interrupt and second one transmit interrupt. I saw that if I block one of them system work without any hung up. Due this one question appear what happen if 2 interrupt request come in same time and if this process is cause hung up. Both interrupt are on the same priority. Today I try remove transmit interrupt and do it in polling I hope this help. If anyone has an idea how to resolve this problem it will be great.

Thanks in advanced

davedoors wrote on Wednesday, February 15, 2012:

vTaskSuspendScheduler() does not disable interrupts, if that is what you expect it to do. All it does is prevent anything causing a task switch. It definitely does that so does have an effect.

voloviq wrote on Saturday, February 18, 2012:

Hello All,

I resolve all my problem and want to sharing my results.

Befor I strat rework my code I look on this forum similar threads and some I found. Tha main my problem was related with OERR bit of UART. I try to think why I have a problem with this bit. This bit is set when Uart receiver is in receive interrupt routine and come next byte and it’s not possible to proper service it. The problem of this was very simple to low speed. When I perform my first experiency my PIC18F25K80 work with 16 main clock and UART work with 38400 Baudrate. I try to estimate how much time processor need to proper service push byte to queue and if become much data OERR bit was set. Resolution for this is very simple speed up microcontroller Main Clock and I do this. Increase speed from 16MHz to 64MHz resolve complete problem with OERR bit and hung up. That’s all. In my opinion this thread may be colose due to find solution.

Thanks any one for help

Regards Voloviq