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. |
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
You now have your own fresh repository. Get at it .
- 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.