USBPD-Stack
Cross-platform distribution of the NXP USB Power Delivery stack for the PTN5110.
Code on GitHub ↗USBPD-Stack is an open-source distribution of the NXP MCUXpresso USB Power Delivery stack (derived from MCUXpresso middleware 25.06.00): it keeps the PTN5110 TCPC driver and adds a modern build system, a portable HAL layer and multi-platform ports. The ST-LINE value-add is portability: the same PD policy engine runs on ESP32-S3, STM32 and Arduino by swapping only the adapters. Reference source: the GitHub repository.
Origin and value-add
The PD core (policy engine and PTN5110 driver) comes from NXP MCUXpresso middleware. ST-LINE separates inherited code (third_party/nxp_pd/) from the portable adapters. The Ellisys captures distributed in the repository concern the original NXP stack: they document that provenance and those tests, without establishing USB-IF certification on the new platforms.
The original contribution is the portability layer: header-only HAL adapters for GPIO, I²C and OS primitives, scheduling ports per platform, a PlatformIO-ready layout and compile-time target selection. Dual-licensed: BSD-3-Clause for the NXP sources, MIT for the ST-LINE parts.
What it does
USB Power Delivery 2.0 / 3.0 policy engine with PTN5110 Type-C Port Controller support. It handles Source, Sink and DRP roles, capability discovery, PDO/RDO contract negotiation and power transitions.
Optional features enabled by configuration: DisplayPort alt mode, PD 3.0 Programmable Power Supply (PPS) and Fast Role Swap (opt-in).
USB Power Delivery concepts in brief
USB Power Delivery (PD) is the protocol that lets two devices over Type-C negotiate voltage and current well beyond the 5 V / 3 A of the classic USB bus — up to 240 W with the Extended Power Range. A handful of terms recur throughout the documentation:
- Source / Sink — who supplies and who draws power. A DRP (Dual-Role Power) can do both and swap roles at runtime.
- PDO / RDO — the Source advertises its capabilities as a list of Power Data Objects (e.g. “5 V 3 A”, “9 V 3 A”, “20 V 5 A”); the Sink picks one and answers with a Request Data Object that fixes the power contract.
- TCPC — Type-C Port Controller, the chip (here the PTN5110) that implements the PD PHY and the cable’s physical interface; the software policy engine, running on the MCU, decides roles, capabilities and transitions by talking to the TCPC over I²C per the TCPCI interface.
- PPS — PD 3.0 Programmable Power Supply: voltage adjustable in fine steps (20 mV) for direct battery charging.
The USBPD-Stack policy engine is exactly the state machine that orchestrates this dialogue; the PTN5110 driver interfaces it to the TCPC.
Supported targets
ESP32-S3 (ESP-IDF) — FreeRTOS + HAL, Stable: 1 kHz tick via a shared FreeRTOS software timer.
STM32 F3/F4/H7 — FreeRTOS + Cube HAL, Stable: EXTI-based ALERT handling, configurable I²C timeout.
Arduino (AVR/ESP/NXP) — cooperative loop, Beta: uses TwoWire for I²C; PD_PortArduino_TaskTick() must be called from the main loop.
Exactly one PD_CONFIG_TARGET_* macro is selected before compiling; each platform has its own pd_phy_<platform>_config_t structure describing the required MCU resources.
Architecture
include/ — core public headers (policy engine, configs, types). src/ — core C sources: Policy Engine (usb_pd_policy.c, the PD state machine), Device Policy Manager (usb_pd_interface.c, creates PD instances and dispatches events), protocol timers (usb_pd_timer.c) and alt mode.
third_party/nxp_pd/ — PTN5110 driver and inherited NXP code (TCPC register access, ALERT interrupts, bus recovery). support/ — HAL abstraction (GPIO, I²C, OS primitives) and its per-platform implementations. port/ — scheduler glue that periodically invokes PD_TimerIsrFunction.
Porting the stack to a new MCU essentially means implementing only the support/ layer (plus the scheduling port): the core and the PTN5110 driver remain unchanged.

Configuration
All options live in include/usb_pd_config.h. Beyond target selection (PD_CONFIG_TARGET_ESP32S3 / _STM32 / _ARDUINO; defaults to ESP32-S3 if none is set) the main flags are: PD_CONFIG_MAX_PORT (simultaneous PD ports), PD_CONFIG_ALT_MODE_SUPPORT / _DP_SUPPORT (DisplayPort alt mode), PD_CONFIG_PD3_PPS_ENABLE (PPS), PD_CONFIG_SOURCE_ROLE_ENABLE / _SINK_ROLE_ENABLE (restrict advertised roles), PD_CONFIG_PD3_FAST_ROLE_SWAP_ENABLE.
Macros are set from the build system (build_flags in PlatformIO, add_compile_definitions in CMake). Include paths to add: include/, port/include, support/include, third_party/nxp_pd/include; sources to compile: src/, port/src, support/src, third_party/nxp_pd/src.
Integration
Prerequisites: a PTN5110 connected over I²C with the ALERT pin on an edge-interrupt-capable GPIO, correct SDA/SCL pull-ups and a C toolchain for the target (ESP-IDF, STM32Cube, Arduino, PlatformIO).
Typical flow: (1) describe the hardware in pd_phy_<platform>_config_t (SDA/SCL GPIOs and priorities for ESP32-S3; I2C_HandleTypeDef*, ALERT pin and IRQ for STM32; TwoWire* and pull-ups for Arduino); (2) fill pd_instance_config_t with roles and PDO tables and phyType = kPD_PhyPTN5110; (3) implement the pd_stack_callback_t and pd_power_handle_callback_t callbacks; (4) call PD_InstanceInit; (5) run PD_InstanceTask in a FreeRTOS task or the Arduino loop, keeping the shared 1 ms tick active.
Why the tick is 1 ms, and not 10
This integration requires one call to PD_TimerIsrFunction every 1 ms for each instance: the code decrements counters expressed in milliseconds by one. Calling it every 10 ms without adapting the timer system changes its time base. This is an implementation requirement, not a deduction from a universal protocol window.
In USB PD 2.0, version 1.0, §6.5.3 and Table 6-30, tSenderResponse (24–30 ms) is the sender’s timeout while waiting for a response; the separate tReceiverResponse has a maximum of 15 ms. Responding before 24 ms is not prohibited. These historical values must not be applied automatically to other revisions.
Timer resolution, service latency and jitter are separate issues: a 1 ms tick alone does not demonstrate port compliance. Task scheduling, I²C access and ALERT handling must also be checked. Each instance needs one tick sequence, avoiding duplicate decrements. When using a 1 ms FreeRTOS software timer, the system tick configuration must support that period and actual callback delays must be checked.
Sources: timer implementation and USB PD 2.0 v1.0, §6.5.3.
Requirements of the support/ layer for a new port
The support/ layer must provide four things; the suitability of the platform depends on them:
What the support/ layer must provide |
Why the stack needs it |
|---|---|
| I²C: blocking 8-bit register read and write, with timeout | it is the only channel to the TCPC: every state-machine transition becomes a register access |
| GPIO: one input with falling-edge interrupt (ALERT) | the TCPC cannot be polled without losing events: it signals and must be serviced |
A 1 ms periodic tick calling PD_TimerIsrFunction |
it provides the millisecond time base for the implemented timers |
| OS primitives: a task or a loop, and mutual exclusion on the I²C | the bus is shared with the rest of the application; the ALERT ISR and the task must not access it together |
A port requires checks of I²C, ALERT handling, the time base and bus concurrency. A GPIO and timer alone do not guarantee operation: test latencies under load on the chosen platform. The Arduino target remains Beta.
The CC resistors: why they never appear in software
The 3 A to advertise is not set in the stack’s software. Before PD comes into play, Type-C declares its intentions with resistors on the CC lines, and the one reading them is the TCPC:
| Resistor | Value | Who fits it | What it declares |
|---|---|---|---|
| Rp | 56 kΩ | Source | default USB only (500/900 mA) |
| Rp | 22 kΩ | Source | 1.5 A at 5 V |
| Rp | 10 kΩ | Source | 3 A at 5 V |
| Rd | 5.1 kΩ | Sink | “I am a sink” |
| Ra | ≈ 1 kΩ | active cable | “I am a cable, not a device” |
This level — called Type-C, not Power Delivery — works with no PD at all: it is why a Type-C charger with no PD delivers 3 A to a phone without exchanging a single message. PD comes in above it, to go beyond 5 V. In the PTN5110 the Rp and Rd are internal and switched by register, so the stack governs them indirectly through the role it declares: there is nothing to fit on the PCB beyond the Rd if the device is a sink-only design without a TCPC.
Diagnostics and platform notes
Diagnostics: enable the debug macros in usb_pd_config.h to trace the message exchange; PD_Control(..., PD_CONTROL_GET_PD_STATE, ...) returns the current state-machine node; the PTN5110 driver exposes helpers to read fault status and regulate VBUS.
ESP32-S3: the adapter installs a 1 ms timer and uses the i2c_instance I²C driver instance from pd_phy_esp32s3_config_t; PD_InstanceTask runs in a dedicated task and the timer callback is registered as soon as an instance exists.
STM32 (F3/F4/H7): requires Cube HAL handles and FreeRTOS; supply the HAL I²C pointer, ALERT GPIO info and IRQ priorities in pd_phy_stm32_config_t, and the adapter handles EXTI dispatch via PD_PortStm32_DispatchExti. Arduino: cooperative design, call PD_PortArduino_TaskTick() and PD_InstanceTask() inside loop(), I²C over TwoWire.
Compliance, status and roadmap
docs/library_usage.md holds the integration guide; docs/compliance_test_report/ contains Ellisys captures from the original NXP stack. The porting article describes internal PD 2.0/3.0 message-exchange tests, source and sink, for ESP32-S3 and STM32, and the timing limit of the beta Arduino port. These reported functional checks are distinct from USB-IF certification of the ports, for which no certificates are available here. Initial release 0.1.0 (2025-11-06); development on the develop branch.
Stated roadmap: a FUSB302B TCPC port layer with ALERT-handling helpers, refreshed Ellisys compliance reports on the new platforms and ready-to-build example projects for each target. References: PTN5110 product page (NXP) and the USB Type-C Port Controller Interface Specification (UM11056).