element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Add a first Task to the Multi-core FreeRTOS SMP Project with the Raspberry Pi Pico
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 28 Sep 2022 10:24 PM Date Created
  • Views 1483 views
  • Likes 6 likes
  • Comments 1 comment
Related
Recommended
  • pico_freertos_smp
  • pico
  • smp
  • freertos

Add a first Task to the Multi-core FreeRTOS SMP Project with the Raspberry Pi Pico

Jan Cumps
Jan Cumps
28 Sep 2022
Add a first Task to the Multi-core FreeRTOS SMP Project with the Raspberry Pi Pico

FreeRTOS Symmetric Multiprocessing (SMP) is a recent version of the RTOS that can schedule tasks across multiple controller cores. It's currently in test phase, and they have a version for the RP2040. In this blog post, I add a first blinky task to my own little SMP project in VSCode. 
image
Prerequisite is that you are able to run the empty project from the previous post.

Create a Blinky task

Our first attempt to write a custom task is a very simple blinky. It's  a simplification of the RP2040 FreeRTOS Blinky example. First a few constants that will be used by the task:

#define mainTASK_LED (PICO_DEFAULT_LED_PIN)
#define mainBLINK_TASK_PRIORITY (tskIDLE_PRIORITY +1)
#define mainBLINK_TASK_FREQUENCY_MS (1000 / portTICK_PERIOD_MS)

The first one defines the LED. he second line the priority (lowest, just above the idle priority. The third definition is the frequency for toggling the LED (1 second). I'm trying to stay close to the FreeRTOS naming and formatting conventions.

To make the task a little bit interesting, I used a mechanism that wakes up the task on a certain interval - not after a time delay. This is mimicking what real-time designs do.

static void prvBlinkTask(void *pvParameters)
{
    (void)pvParameters;
    TickType_t xNextWakeTime;

    /* Initialise xNextWakeTime - this only needs to be done once. */
    xNextWakeTime = xTaskGetTickCount();

    for (;;)
    {
        gpio_xor_mask(1u << mainTASK_LED);
        xTaskDelayUntil(&xNextWakeTime, mainBLINK_TASK_FREQUENCY_MS);
    }
}

Before entering the task loop, we initialise the tick counter. The loop first toggles the LED. Then it tells the scheduler to deactivate the task and wake it up again when 1 second expired since the stored tick count. The OS will update that tick count when the focus returns. On the image below, you can see that the count is 2000 after 2 sleep sessions.

image

Register the task

An API function is called to register the task in the scheduler. This has to be done before the scheduler is started. Creating the task does not start it. The scheduler will do that as soon as it is kicked off, and there's a slot for the task to run in.

    prvSetupHardware();

    xTaskCreate(prvBlinkTask, "blink", configMINIMAL_STACK_SIZE, NULL, mainBLINK_TASK_PRIORITY, NULL);

    /* Start the tasks and timer running. */
    vTaskStartScheduler();

You can now build and run the project. The result is that the LED will toggle every second.

Show All Blog Posts

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 3 years ago

    For the next post, I'm adding a task that reads the onboard temperature.

    Here's a capture of the blinky task running on core 0, temperature task on core 1.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube