Raspberry Pi Microcontrollers: Difference between revisions
Line 38: | Line 38: | ||
The following articles by Hunter Adams offer a detailed analysis of how BTstack works on the Pico: | The following articles by Hunter Adams offer a detailed analysis of how BTstack works on the Pico: | ||
# [https://vanhunteradams.com/Pico/BLE/BTStack_HCI.html BTstack and RP2040: HCI (Host Controller Interface)].<br />This article delves, among other things, into how the BTstack runloop is executed inside a Pico [[#Async_Context | async_context]].<br /><blockquote>[...] we have just one ''when_pending_worker'' in our async_context. This worker is called ''cyw43_poll_worker'', and its ''do_work'' function points to ''cyw43_poll_func()'', listed above. This function ends up calling ''btstack_run_loop_poll_data_sources_from_irq()'', about which we'll learn more shortly. This worker gets marked as pending in a GPIO interrupt. So, this provides a mechanism by which the CYW43 can tell the RP2040 to run ''btstack_run_loop_poll_data_sources_from_irq()'' which, as we're going to learn, goes and gets data from the device.</blockquote> | # [https://vanhunteradams.com/Pico/BLE/BTStack_HCI.html BTstack and RP2040: HCI (Host Controller Interface)].<br />This article delves, among other things, into how the BTstack runloop is executed inside a Pico [[#Async_Context | async_context]].<br /><blockquote>[...] we have just one ''when_pending_worker'' in our async_context. This worker is called ''cyw43_poll_worker'', and its ''do_work'' function points to ''cyw43_poll_func()'', listed above. This function ends up calling ''btstack_run_loop_poll_data_sources_from_irq()'', about which we'll learn more shortly. This worker gets marked as pending in a GPIO interrupt. So, this provides a mechanism by which the CYW43 can tell the RP2040 to run ''btstack_run_loop_poll_data_sources_from_irq()'' which, as we're going to learn, goes and gets data from the device.</blockquote> | ||
# [https://vanhunteradams.com/Pico/BLE/GATT_Server.html Building a Bluetooth GATT Server on the Pi Pico W] | # [https://vanhunteradams.com/Pico/BLE/GATT_Server.html Building a Bluetooth GATT Server on the Pi Pico W] |
Revision as of 2025-05-06T07:36:44
Pico Series
- Raspberry Pi Pico and Pico W
- Dual Arm Cortex-M0+ with Armv6-M programming model, up to 133 MHz
- Raspberry Pi Pico 2 and Pico 2 W
- Dual Arm Cortex-M33 with Armv8-M programming model, up to 150 MHz
Development Setup
Using the Raspberry Pi Debug Probe
The Debug Probe is a RP2040 based USB-to-UART/SWD board for connecting the USB slot of a development machine to the SWD or UART pins of a target device.
Using A Pico To Debug Another Pico
A Pico can be used to debug another Pico (a.k.a. target device) by flashing it with the debugprobe binary and wiring to the target Pico as shown below.
From the debugger Pico to the target Pico,
- pin #4 (GP2) connects to pin SWCLK,
- pin #5 (GP3) connects to SWDIO,
- pin #6 (GP4, UART1 TX) connects to pin #2 (GP1, UART0 RX),
- pin #7 (GP5, UART1 RX) connects to pin #1 (GP0, UART0, TX).
The debugger Pico serves both as a USB-to-SWD and USB-to-UART bridge to the target device. The development machine, therefore, needs to be connected via USB only to the debugger Pico. Console output on the target Pico is relayed through the debugger. It is possible, though, to connect a second USB cable from the development machine to the target device for (simultaneous) direct access to the console output. This debugger setup works not just with Pico targets but with any microcontroller that supports the CMSIS-DAP protocol over SWD.
Software Tools for Debugging
Whether we use the Raspberry Pi Debug Probe or a spare Pico as debug probe, the software tools used for debugging are the same:
- openocd
Notes on Programming with the C SDK
Async Context
In the C SDK, an async_context is used in concurrent programming to make sure that functions are executed on the same thread and in the order they were submitted, similar to dispatch queues in Apple's Dispatch framework. The async_context data structure is a container of linked lists of worker functions that are executed within a single thread of a single processor core.
Bluetooth
The C SDK integrates the third-party BTstack framework as its Bluetooth API that interfaces with the Infineon CYW43 wireless communication module (on Pico W models) via the Host-Controller Interface (HCI) protocol.
The following articles by Hunter Adams offer a detailed analysis of how BTstack works on the Pico:
- BTstack and RP2040: HCI (Host Controller Interface).
This article delves, among other things, into how the BTstack runloop is executed inside a Pico async_context.[...] we have just one when_pending_worker in our async_context. This worker is called cyw43_poll_worker, and its do_work function points to cyw43_poll_func(), listed above. This function ends up calling btstack_run_loop_poll_data_sources_from_irq(), about which we'll learn more shortly. This worker gets marked as pending in a GPIO interrupt. So, this provides a mechanism by which the CYW43 can tell the RP2040 to run btstack_run_loop_poll_data_sources_from_irq() which, as we're going to learn, goes and gets data from the device.
- Building a Bluetooth GATT Server on the Pi Pico W