0%
0%

T76 Instrument Core: Pro instruments on Pi Pico 2

A C++ framework for building real-time, pro-grade digital instruments on the RP2350 / Pi Pico 2 platform.

marco-tabiniMarco Tabini

Become a Hackaday.io member

Not a member? You should Sign up.

Already have an account? Log in.

Just one more thing

To make the experience fit your profile, pick a username and tell us what interests you.

Pick an awesome username
hackaday.io/
Your profile's URL: hackaday.io/username. Max 25 alphanumeric characters.
Pick a few interests
Projects that share your interests
People that share your interests
Similar projects worth following
0 followers
0 likes
View Gallery
I've grown quite fond of Raspberry Pi's Pico product and the microprocessors that power them. The RP2350, in particular, has all the makings of a great foundation on which to build measurement instrumentation that provides "prosumer" features and is accessible to a broad audience of professionals and enthusiasts. In this project, I want to develop a template project that can be used to build high-quality realtime applications on a stock Pi Pico 2.

Features

The IC will support these features:

  • C++ code written to modern standards using the Pi Pico SDK
    • Support for the RP2350 only
    • No support for Arduino; use the Pico SDK only
    • No support for displays, as plenty of alternatives exist already
    • Fallback to plain C for critical tasks where warranted
    • Use of CMake for configuration through and through
  • Full use of multicore:
    • Bare-metal critical tasks running on one core
    • FreeRTOS running on the other for housekeeping/communication tasks
    • Reliance on FreeRTOS for all memory management
  • Support for industry-standard communications
    • SCPI over USBTMC for instrument management
    • USB Serial for debug / status management
  • Safety features
    • Last-ditch exception manager that puts the instrument in safe mode on crash and halt

  • Enabling FreeRTOS on the RP2350

    Marco Tabini a day ago 0 comments

    Adding FreeRTOS support to IC is relatively simple. First, we add RPi's own branch of FreeRTOS as an external submodule to the repository:

    git submodule add https://github.com/raspberrypi/FreeRTOS-Kernel.git

    Next, we copy a few files from the FreeRTOS source into the project's main directory; these include a CMake config file, a C include file that provides the actual configuration for FreeRTOS, and a couple small C source files that provide some functionality required by FreeRTOS to run.

    We must also define a vApplicationStackOverflowHook() function that is called by FreeRTOS when a task overflows its stack. Right now, our implementation (in freertos/rp2350.c) simply asserts and crashes the core, but in a future iteration we will use it to call our exception handler to give the code an opportunity to place our device in a safe mode before resetting or halting.

    FreeRTOS configuration

    The stock configuration that comes in the FreeRTOS source sets up the operating system with multi-core support and allows all tasks to run on either core. We, however, want FreeRTOS to only run on core 0 while reserving core 1 for our critical tasks. Therefore, we change the configuration so that FreeRTOS runs in single-core mode:

    #define configNUMBER_OF_CORES 1
    #define configNUM_CORES configNUMBER_OF_CORES
    #define configTICK_CORE 0
    #define configRUN_MULTIPLE_PRIORITIES 1
    /* SMP Related config. */
    #define configUSE_CORE_AFFINITY 0
    #define configUSE_PASSIVE_IDLE_HOOK 0
    #define portSUPPORT_SMP 0

    Making TinyUSB work

    Interestingly, this configuration causes TinyUSB to stop working; I haven't really figured out why this is the case, but my bet is that, by default, the SDK attempts to run the TinyUSB task on core 1 if it detects FreeRTOS; since we do not support SMP, this approach fails.

    The fix to this problem is pretty simple: We just provide our own TinyUSB task and call tud_task() directly. Eventually, when we add more substantial USB support, we'll move this code into its own class, but for now it's just a simple function inside main.cpp.

    Putting it all together

    The new version of the source demonstrates that everything works by spawning three tasks:

    • A core 1 task that outputs some text; this demonstrates that code is running on both cores.
    • A core 0 task that calls TinyUSB.
    • A second core 0 task that does the same, interlacing with the core 1 task; this demonstrates that FreeRTOS is multitasking successfully.

View project log

Enjoy this project?

Share

Discussions

Log In/Sign up to comment

Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.

Similar Projects

Project Owner Contributor

jupyosys

martinMartin

Project Owner Contributor

Pi Pico, PicoProbe and VS Code

nickNick

Does this project spark your interest?

to follow this project and never miss any updates

Cancel

AltStyle によって変換されたページ (->オリジナル) /