FreeRTOS on the RP2040 Part 3 – Source Code

New CMakeLists.txt file

add_executable(blink
        main.c
)

pico_enable_stdio_usb(blink 1)
pico_enable_stdio_uart(blink 0)

target_link_libraries(blink pico_stdlib freertos)
pico_add_extra_outputs(blink)

New main.c file

Comment and uncomment the delays as required.

#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>
#include "pico/stdlib.h"


void task1(void *pvParameters)
{   
    while (true) {
        printf("Task 1 is currently running\n");
        for(int i = 0; i<20000000; i++){};
        //vTaskDelay(100);
    }
}

void task2(void *pvParameters)
{   
    while (true) {
        printf("Task 2 is currently running\n");
        for(int i = 0; i<20000000; i++){};
        //vTaskDelay(100);
    }
}

int main()
{
    stdio_init_all();

    xTaskCreate(task1, "Task 1", 256, NULL, 1, NULL);
    xTaskCreate(task2, "Task 2", 256, NULL, 2, NULL);
    vTaskStartScheduler();

    while(1){};
}

Leave a comment

Your email address will not be published.