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 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 - Timers in multi-core FreeRTOS SMP ("also a 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: 19 Nov 2023 12:41 PM Date Created
  • Views 886 views
  • Likes 8 likes
  • Comments 3 comments
Related
Recommended
  • raspberry
  • pico_freertos_smp
  • smp
  • freertos

Raspberry Pico - Timers in multi-core FreeRTOS SMP ("also a double blinky")

Jan Cumps
Jan Cumps
19 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, revisit double blinky. One blinky task will now be controlled by a timer.

image

Download and install FreeRTOS

Check  Raspberry Pico - Play with multi-core FreeRTOS SMP ("the double blinky") . You can also get the original code from there. This firmware is based on it.

The Double Blinky With Timer example

In the first posts, I created two tasks, and asked FreeRTOS to schedule them. In this post, I replace one of the "to be scheduled" tasks by a timer controlled one (a timer callback), I then create a FreeRTOS timer, and let the timer call that blinky callback.

For tasks that have to run an a regular base, this is a good option. Timers run tasks at a given interval, while the scheduler will determine who's to run next based on priorities.

This is the timer callback. It toggles LED1.

static void led_blinky_cb(TimerHandle_t xTimer) {
	(void) xTimer;
	gpio_xor_mask(1u << mainTASK_LED1);
}

Here's the part of our startup call that initialises our setup. The commented out code is the part of the previous post that's replaced by the timer one.

	// 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));

    blinky_tm = xTimerCreate("LED1", mainLED_FREQUENCY_MS, true, NULL, led_blinky_cb);
    xTimerStart(blinky_tm, 0);

	vTaskStartScheduler();

Differences compared to the previous blog code:

  • LED2 task is scheduled, but I let the scheduler decide on what core it executes. (commented out the core affinity command)
  • LED1 task is not scheduled (commented out). It's replaced by a timer and a callback that blinks LED1.

Enjoy the FreeRTOS SMP double blinky with timer. The download below includes the .uf2 file, that can be copied directly onto the Pico.

SMP_20231119.zip

Show All Blog Posts

  • Sign in to reply
  • DAB
    DAB over 1 year ago

    Nice update Jan, I really enjoy seeing your projects.

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

    I'm trying out a few scheduling scenarios first.
    Then I'm going to try and move data efficient between the two - if possible keep one core as free as possible to gather (sensor/adc) data, while the other consumes it and deals with user interface.

    First some little setups (like this post and the previous one) to understand better what are good and bad patterns. Understand how things interact multi-core. What things don't work, don't work performant, fail, may block each other ...

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

    Great to see there are lots of options on how to do things!

    It's powerful having the ability to simplify software structures using the variety of features the OS provides and not having to stick to using a megaloop. I'm not of course suggesting the latter is never useful, just that there's a time and a place for it all. I like that even simple real-time tasks can be eye-openers to see how to think when using an OS, and becomes easy to see the benefits!

    • 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