Getting Start FreeRTOS

scentoflove wrote on Monday, July 09, 2007:

Dear all!
I’m a newbie with FreeRTOS, I have a project to use RTOS with PIC. I download FreeRTOS demo and compile successful, but I can’t understand demo’s logic, structure . Please tell me where I should begin. I think V1.0 is simplest but I can’t find it in download page so I use V2.4.2.

rtel wrote on Monday, July 09, 2007:

V1.0 does not have a PIC port.  I should stick to the latest version.

Have you read through the demo project and source code organisation sections of the FreeRTOS.org WEB site?  Start there, along with stepping through the code in the MPALB simulator.

Regards.

scentoflove wrote on Wednesday, July 11, 2007:

Thanks Richard. I have read the source code organisation and demo project code, but i can’t find which file contain the function vPortInitialiseBlocks is written.

pdeflandre wrote on Wednesday, July 11, 2007:

I don’t know for the PIC port, but for at91sam7x the vPortInitialiseBlocks is in ./Source/portable/MemMang/heap_1.c

scentoflove wrote on Thursday, July 12, 2007:

I compile with 18F452 is successful, but i compile with 18F458, 4520 is unsuccessful.
If I want to create my project which file is necessary to include in my new project

rtel wrote on Thursday, July 12, 2007:

In what way is it unsuccessful?  The most likely problem is with the linker file.  The demo creates one large RAM block, you would need to do the same for any other device variant used.

Regards.

scentoflove wrote on Friday, July 13, 2007:

Error - section ‘.udata_heap_1.o’ can not fit the section. Section ‘.udata_heap_1.o’ length=0x00000404. I choosed correct linker file with device and 18F452 458 4520 have the same RAM.

Thanks Richard for reply

davedoors wrote on Friday, July 13, 2007:

This is a linker problem.  As Richard implied, you need to edit the linker script to create a block large enough to hold the entire heap.  Look at the linker script in the download to see how it is done, then make the same changes to the linker script you are using.  Alternatively, edit the linker script from the download to be correct for your PIC memory map.

scentoflove wrote on Sunday, July 15, 2007:

Thanks all, I compiled successfull with 458.

scentoflove wrote on Monday, July 16, 2007:

Now I have a problem. I creates task1 flash one led in pin 3 portb, the demo ran successful. If I created task2 flash one led in pin 2 portb, the demo wouldn’t run.

Here is code

In void main ()

    xTaskCreate( vTask1, ( const portCHAR * const ) "Task1", configMINIMAL_STACK_SIZE, NULL, mainTASK1_PRIORITY, NULL );
    xTaskCreate( vTask2, ( const portCHAR * const ) "Task2", configMINIMAL_STACK_SIZE, NULL, mainTASK2_PRIORITY, NULL );

Function task1

static void vTask1( void *pvParameters )
{
    portTickType xDelayTick = 200 ;
    LATBbits.LATB3=0;
    for ( ;; )
    {
        LATBbits.LATB3=!LATBbits.LATB3;
        vTaskDelay( xDelayTick );
    }
}

Function task2

The same with task1, but pin 3 was replaced by pin 2.

embeddedc wrote on Monday, July 16, 2007:

You did not say what it is that does not work.

Both of your tasks are writing to LATBbits which means you will get race conditions unless you use some protection mechanism.  This might make the LED some time not flash as expected but I would not expect this to stop the whole application from working.

scentoflove wrote on Tuesday, July 17, 2007:

In demo have the errorcheck tasks and I created 2 tasks. When I created only task1 (the demo have 2 tasks), the led flashed every 200ms and the demo’s check led flashed every 1s. If I created 2 tasks (the demo have 3 tasks), no led flashed.
I changed the task2 to use the LATDbits but the demo didn’t run. I comment (//xTaskCreate( vErrorChecks, … ) the errorcheck task (the demo have 2 task task 1 & 2) it is running properly.
I think not enough RAM for PIC to run (1426/1533bytes RAM).

scentoflove wrote on Wednesday, July 25, 2007:

No reply for me :(! Now I’m working with dsPIC33FJ256GP710 and Explorer16. I can’t find function config OSC for pic so I use my function to setup OSC at the beginning of main function.

   #define configCPU_CLOCK_HZ    ( ( unsigned portLONG ) 80000000 )  /* Fosc / 2 */

   OSCCON = 0x0180;        // fast rc, pll enable, clock lock
   OSCTUN = 23;           // 7.37MHz + 23 * 0.375% = 8.00 MHz
   //CLKDIV = 0x0;        // N1 = 2, N2 = 2
   _PLLPRE=0;             // N1 = 1
   _PLLPOST=0;             // N2 = 2
   PLLFBD = 38;           // M = 40 -> Fosc = 8*40/(2*2)=80MHz, Fcy=40MIPs
   while(!OSCCONbits.LOCK); // wait untill clock stable

I have trouble with the loop while(!OSCCONbits.LOCK), the demo enter to infinite loop. I used this function in many projects before and working properly. Plz help me

scentoflove wrote on Wednesday, July 25, 2007:

I comment the while loop (//while …), the demo working properly. When I create a new task and have a error.

code
#define mainTASK1_PRIORITY                    ( tskIDLE_PRIORITY + 4 )
#define mainTASK1_STACK_SIZE                ( configMINIMAL_STACK_SIZE * 2 )
static void vCheckTask( void *pvParameters );
static void vTask1 (void *pvParameters);

in main() function

xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", mainCHECK_TASK_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
xTaskCreate( vTask1, ( signed portCHAR * ) "Task1", mainTASK1_STACK_SIZE, NULL, mainTASK1_PRIORITY, NULL );

error

jump_table(.handle+0x4): undefined reference to `vTask1’
jump_table(.handle+0x6): undefined reference to `vTask1’
E:\Dev\FreeRTOS\Demo\dsPIC_MPLAB\main.o(.text+0x50): In function `main’:
E:\Dev\FreeRTOS\Demo\dsPIC_MPLAB\main.c:167: undefined reference to `vTask1’

sotd wrote on Wednesday, July 25, 2007:

Do you need to do this?  Here is some code used outside of main() that sets up a fast clock.  This is for PIC24 but the dsPIC equivalent is probably similar.

_CONFIG2( POSCMOD_HS & OSCIOFNC_OFF & FCKSM_CSDCMD & FNOSC_PRIPLL & IESO_ON );
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & FWDTEN_OFF);

sotd wrote on Wednesday, July 25, 2007:

Is vTask1 defined in main.c too?

scentoflove wrote on Thursday, July 26, 2007:

Thanks sold for reply
_I config dspic’s osc with FRCPLL and the dspic’s FRC have 7.37MHz nominal frequency. II just config _FOSCSEL(FNOSC_FRCPLL);, i don’t know exactly not only frequency but also PLL -> Fcy=?. This code just config the PLL and the FRC frequency.
_vtask1 create and define in main.c.

scentoflove wrote on Friday, July 27, 2007:

Hi all.
I extracted the FreeRTOSv4.3.1 again and I used the demo project to create 3 tasks to flash 3 leds with frequency 2Hz 1Hz 0.5Hz in portD and it’s working. I created my project with the same main.c and didn’t add demo standards files (BlockQ.h, … & commented #include BlockQ.h … in main.c ) it’s not work and suspended in vTaskDelay

Code flash led
void vTask (void *pvParameters )
{
        _TRISD1=0;
    _LATD1=0;
    for ( ;; )
    {
        vTaskDelay(500);
        _LATD1=!_LATD1;
    }
}