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
Test & Tools
  • Technologies
  • More
Test & Tools
Blog PST.. Pico SCPI labTool can run multi-core on FreeRTOS SMP
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 20 Nov 2023 6:11 PM Date Created
  • Views 942 views
  • Likes 8 likes
  • Comments 5 comments
  • pico_freertos_smp
  • pico_usbtmc_scpi
  • pico
  • smp
  • USBTMC
  • Pico SCPI labTool
  • freertos
  • scpi
  • labtool
Related
Recommended

PST.. Pico SCPI labTool can run multi-core on FreeRTOS SMP

Jan Cumps
Jan Cumps
20 Nov 2023

The Pico SCPI labTool (PST) allows you to connect your PC to equipment to control and monitor all sorts of things. It runs on a Raspberry Pico.
In this post: you can run it - with multi-core support - on FreeRTOS SMP.

image

What's different, compared to the bare metal version?

The default example runs on one core. It's a very straightforward super loop. The FreeRTOS version uses Symmetric Processing to run tasks on two cores. I've pinned the USB and SCPI related processing to core 0. 

There are currently 3 processes:

  • a task for usb handling and interacting with SCPI lib
  • a task to check the GPIO input pins and manage the instrument specific registers
  • a timer callback to entertain the LED.

int main(void) {
	TaskHandle_t xHandle;

  board_init();
  scpi_instrument_init();

  blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(mainLED_CHECK_FREQUENCY_MS), true, NULL, led_blinky_cb);
  xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &(xHandle));
  vTaskCoreAffinitySet(xHandle, (1 << 0));

  xTaskCreate(maintain_registers_task, "regs", APP_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &(xHandle));
  vTaskCoreAffinitySet(xHandle, (1 << 0));

  xTimerStart(blinky_tm, 0);
  vTaskStartScheduler();
  panic_unsupported(); // should never reach here
  return 0;
}

Each task is simple. Here they are:

static void usb_device_task(void *param) {
  (void) param;
  tud_init(BOARD_TUD_RHPORT);
  // RTOS forever loop
  for( ;; ) {
    tud_task();
    usbtmc_app_task_iter();
  }
}

static void maintain_registers_task(void *param) {
  (void) param;
  TickType_t xNextWakeTime;
  xNextWakeTime = xTaskGetTickCount();
  // RTOS forever loop
  for( ;; ) {
    vTaskDelayUntil( &xNextWakeTime, mainREG_CHECK_FREQUENCY_MS );
    maintainInstrumentRegs();
  }
}

static void led_blinky_cb(TimerHandle_t xTimer) {
  (void) xTimer;
  led_blinking_task();
}

Why?

The extra core allows scenarios, where the second core continuously fetches data from sensors, without being interrupted (e.g.: for handling SCPI communication). Other than that, you get the scheduler and inter-process communication options.

The use of FreeRTOS is not intrusive. You can use it or not use it. There are no changes needed in the labLib or the SCPI setup. It's a choice.

Build from source? You can either clone the repo, or use GITHUB's template options.

  • Template option:

Go to the repo on github, and use the template
image

You now have your own fresh repository. Get at it Slight smile.

  • Use the original repo.

git clone https://github.com/jancumps/pico_scpi_usbtmc_labtool.git --recurse-submodules

For both options, inform the toolchain where your Pico SDK and FreeRTOS sources are. Add these variables to your environment:

PICO_SDK_PATH (e.g.: C:/Users/jancu/Documents/Pico/pico-sdk)
FREERTOS_KERNEL_PATH (e.g.: C:/Users/jancu/Documents/git/git_freertos/FreeRTOS/FreeRTOS/Source)

The source and .uf2 firmware are available from GitHub.

link to all posts

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 1 year ago

    If you want to design a Pico SCPI instrument, with easy access to both ARM cores, 
    getting started is now easier:

    Github supports project templates. 
    You can start your own fresh project by pressing a button. Navigate to the repo, and create your own project by using the Use this template options.

    image

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

    Nice update Jan.

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

     ggabe , example from a previous exercise:

     Guard ADC peripheral access with a MUTEX for the Multi-core FreeRTOS SMP Project with the Raspberry Pi Pico 

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

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

    > how's concurrent access handled over hardware resources - like USB or I2C?

    At this moment: not. I have one task handling USB, and one (not implemented yet) can be used for i2c. There's no battle for a hardware port by several tasks / threads yet.

    When a design will have several tasks using the same hardware (say: two i2c ICs being polled), I'll use semaphores to restrict access to one thread/task at a time. The other tasks will wait until that semaphore is released.

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

    Very nice, it was on my bucket list to learn FreeRTOS!

    For curiosity, how's concurrent access handled over hardware resources - like USB or I2C? What's the optimal way of organizing tasks vs. hw devices?

    • 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