element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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 Raspberry Pico - Play with multi-core FreeRTOS SMP ("the double blinky")
  • 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: 17 Nov 2023 11:49 AM Date Created
  • Views 3468 views
  • Likes 14 likes
  • Comments 6 comments
Related
Recommended
  • raspberry
  • pico_freertos_smp
  • smp
  • freertos

Raspberry Pico - Play with multi-core FreeRTOS SMP ("the double blinky")

Jan Cumps
Jan Cumps
17 Nov 2023

FreeRTOS Symmetric Multiprocessing (SMP) is a version of the RTOS that can schedule tasks across multiple controller cores.
It has just been promoted to the main release, and supports the RP2040. In this blog post, I design a double blinky. Both cores will run a task to blink a LED.

image

It's a very simple example - on purpose. With a few lines of code, we can make jobs run on either Pico ARM core.

Download and install FreeRTOS

Clone FreeRTOS if you don't have it yet. The SMP part is recently added to FreeRTOS proper. The version that comes with Pico C SDK 1.5 doesn't have it yet.

git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules

We'll tell our project later where it can find the RTOS.

The Double Blinky example

Goal: run two FreeRTOS tasks. Both on a different core.

The base for my code is the CORTEX_M0+_RP2040 SMP blinky demo code. You can find it in the FreeRTOS\FreeRTOS\Demo\ThirdParty\Community-Supported-Demos\CORTEX_M0+_RP2040\Standard_smp folder.
I added support for controlling what core to run a task on (instead of letting the scheduler decide).

FreeRTOSConfig.h is set up to use 2 cores, and to allow "core affinity"

#define configNUMBER_OF_CORES                   2
#define configTICK_CORE                         0
#define configRUN_MULTIPLE_PRIORITIES           0

// ...

/* RP2040 specific */
#define configSUPPORT_PICO_SYNC_INTEROP         1
#define configSUPPORT_PICO_TIME_INTEROP         1

// ...

/* SMP Related config. */
#define configUSE_PASSIVE_IDLE_HOOK             0
#define portSUPPORT_SMP                         1
#define configUSE_CORE_AFFINITY                 1


The LED blink task is virtually the same as the one from the demo. I used the parameter to tell which LED to blink

static void prvLedTask(void *pvParameters) {
  TickType_t xNextWakeTime;
  xNextWakeTime = xTaskGetTickCount();

  for( ;; ) {
    vTaskDelayUntil( &xNextWakeTime, mainLED_FREQUENCY_MS );
    gpio_xor_mask(1u << (uint32_t)pvParameters);
  }
}

The main code schedules two of those tasks. Tells each of them to blink a different LED, and run on a different core:

	TaskHandle_t xHandle;
	
	xTaskCreate(prvLedTask, "LED", configMINIMAL_STACK_SIZE, (void *)mainTASK_LED1, mainLED_TASK_PRIORITY, &(xHandle) );
	// Define the core affinity mask such that this task can only run on core 0
    vTaskCoreAffinitySet(xHandle, (1 << 0));

	xTaskCreate(prvLedTask, "LED2", configMINIMAL_STACK_SIZE, (void *)mainTASK_LED2, mainLED_TASK_PRIORITY, &(xHandle) );
	// Define the core affinity mask such that this task can only run on core 1
    vTaskCoreAffinitySet(xHandle, (1 << 1));

	vTaskStartScheduler();

Result:

image

"Hey, my code can't find (the right) FreeRTOS on my disk?"
The project includes a file in the CMake script that 'll help you to find the RTOS: FreeRTOS_Kernel_import.cmake.
Define a variable FREERTOS_KERNEL_PATH that points to the install (in my case, C:/Users/jancu/Documents/git/git_freertos/FreeRTOS/FreeRTOS/Source).

You can set it as an OS variable, or use the functionality of your IDE. Here's how I did that in VSCode:

image

Enjoy the FreeRTOS SMP double blinky. The download below includes the .uf2 file, that can be copied directly onto the Pico. LEDs will flash after you flash the firmware.

SMP_20231117.zip

Show All Blog Posts

  • Sign in to reply

Top Comments

  • Fred27
    Fred27 over 1 year ago +2
    Your post has got me thinking that a "double blinky" should just be called blinky. We should rename the standard "single blinky" to winky.
  • shabaz
    shabaz over 1 year ago in reply to Fred27

    This makes a lot of sense!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 1 year ago

    Your post has got me thinking that a "double blinky" should just be called blinky. We should rename the standard "single blinky" to winky. Wink

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    A similar exercise, doing things in a different way:  Raspberry Pico - Timers in multi-core FreeRTOS SMP ("also a double blinky") 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 1 year ago

    Nice post Jan, good work.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    Great to see that the experiment is repeatable. And that it "just" works with different toolchains.

    Blinking one LED per core may not be good resource use. But it's the gateway to double the calculation power.
    Or to have one processor deal with time critical duties, while the other one deals with interruptible and non-time-critical activities.

    Thanks for trying it out Slight smile

    • 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