very simple Freertos hello world

Dependencies:   mbed freertos_test FreeRTOS

Dependents:   freertos_test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // N.C. Freertos mbed minimal example based on below:
00002 // https://developer.mbed.org/users/rgrover1/code/FreeRTOS/
00003 // http://www.radekdostal.com/content/freertos-610-minimal-example
00004 // 20/04/2017 update: Compiled for  and NUCLEO-F104RB, without errors
00005 // Complile without errors: LPC1768,NUCLEO-F104RB,F401RE,L152RE
00006 // Compilation Errors for: EA LPC11U35, TG-LPC11U35-501 nRF51822, FRDM-K25Z,
00007 //                         nRF52-DK,BBC micro:bit,LPC1114FN28, NUCLEO-F030R8
00008 //                         NUCLEO-F746ZG, LPC800-MAX
00009 
00010 
00011 
00012 // Nikos 07/09/2019: Is using Cortex M3 version FreeRTOS, confirmed to to be compiled with cotexM3 CPUs
00013 // LPC1768, L152, F401, F103, Teensy3.1
00014 
00015 #include "mbed.h"
00016 #include "FreeRTOS.h"
00017 #include "task.h"
00018 
00019 DigitalOut led1(LED1);
00020 DigitalOut led2(LED2);
00021 
00022 void Task1 (void* pvParameters)
00023 {       
00024     (void) pvParameters;                    // Just to stop compiler warnings.   
00025     for (;;) {
00026         led1 = !led1;
00027         printf("Task1\n");
00028         vTaskDelay(500);
00029     }
00030 }
00031 
00032 void Task2 (void* pvParameters)
00033 {
00034     (void) pvParameters;                    // Just to stop compiler warnings.
00035     for (;;) {
00036         led2= !led2;
00037         printf("Task2\n");
00038         vTaskDelay(5000);
00039     }
00040 }
00041 
00042 int main (void)
00043 {
00044     xTaskCreate( Task1, ( signed char * ) "Task1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
00045     xTaskCreate( Task2, ( signed char * ) "Task2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
00046     vTaskStartScheduler();
00047    //should never get here
00048    printf("ERORR: vTaskStartScheduler returned!");
00049    for (;;);
00050 }