RP2040 USB-PD Sniffer and Sink
This project provides two firmwares for a Raspberry Pi Pico or any other RP2040-based board to interact with the USB Power Delivery (USB-PD) protocol.
- Sniffer: A passive USB-PD sniffer that listens to the communication on a USB-C CC (Configuration Channel) line, decodes the messages in real-time, and prints them to the USB serial console.
- Sink: An active device that can negotiate a specific power profile from a USB-PD power adapter. This example is configured to request a 15V / 3A profile.
Features
- Shared USB-PD Library: All the common logic for decoding and encoding USB-PD messages is contained in a shared library.
- PIO-Based Sampling and Transmission: Uses the RP2040’s Programmable I/O (PIO) for both an 8x oversampled receiver (sniffer and sink) and a BMC transmitter (sink).
- Real-Time Decoding: Performs full, real-time decoding of the physical layer protocol.
- Self-Contained Build: The project is configured with a modern CMake build system and includes the Raspberry Pi Pico SDK as a submodule.
- Automated Builds: A GitHub Actions workflow automatically builds both firmware targets on every push to the
main branch.
Building the Firmware
This project uses CMake and requires the ARM GCC toolchain.
Prerequisites
git
cmake
gcc-arm-none-eabi
On a Debian-based system (like Ubuntu), you can install these with:
sudo apt-get update
sudo apt-get install -y git cmake gcc-arm-none-eabi
Build Steps
- Clone the repository:
git clone https://github.com/your-username/rp2040-pd-sniffer.git
cd rp2040-pd-sniffer
- Initialize the Submodules:
git submodule update --init --recursive
- Run the Build:
cmake -B build -S .
cmake --build build --parallel
- Find the Firmware:
If the build is successful, you will find the flashable
.uf2 files inside the build directory:
build/sniffer.uf2
build/sink.uf2
Flashing and Usage
Sniffer
- Flash the Firmware: Flash
sniffer.uf2 to your Pico.
- Monitor the Output: Open a serial monitor and connect to the Pico’s virtual COM port. You will see the decoded USB-PD messages.
Sink
- Flash the Firmware: Flash
sink.uf2 to your Pico.
- Connect to Power Adapter: Connect the CC line of your circuit to a USB-PD power adapter.
- Monitor the Output: Open a serial monitor. The application will print a message if it finds and requests the 15V/3A profile.