on 2026-05-20 5:30 AM
Following the previous article How to build a bare metal USB Power Delivery Sink application using STM32, this article shows how to build a USB Power Delivery source application on STM32. The example is demonstrated using the X-NUCLEO-SRC1M1 shield and the NUCLEO-G0B1RE board, in a bare metal cooperative superloop.
Configure the project as detailed in our ST wiki tutorial:
Generate the project from CubeMX, then add the required user code shown below.
You can use the attached ioc file in this article.
The final project is available in our STM32 hotspot GitHub repository: CKB-STM32-USBPD-Source-Baremetal
When the source application is configured correctly and a compatible USB PD sink is connected, the trace should typically show the following sequence:
The capabilities are sent by the source (OUT message).
The request is sent by the sink (IN message).
After receiving the sink’s Request, the source validates the requested power profile and replies with ACCEPT if it can support it.
Depending on the selected power path and voltage transition type, the output voltage may start changing immediately after ACCEPT. When the output has reached the requested level and is stable, the source sends PS_RDY.
The contract negotiation ends by the POWER_EXPLICIT_CONTRACT.
In bare metal STM32 USB PD applications, the USB PD stack runs in a cooperative superloop.
USBPD_DPM_Run() repeatedly services the Cable Detection module and the Policy Engine using SysTick.
if ((HAL_GetTick() - DPM_Sleep_start[USBPD_PORT_COUNT]) >= DPM_Sleep_time[USBPD_PORT_COUNT])
{
DPM_Sleep_time[USBPD_PORT_COUNT] = USBPD_CAD_Process();
DPM_Sleep_start[USBPD_PORT_COUNT] = HAL_GetTick();
}
uint32_t port = 0;
for (port = 0; port < USBPD_PORT_COUNT; port++)
{
if ((HAL_GetTick() - DPM_Sleep_start[port]) >= DPM_Sleep_time[port])
{
DPM_Sleep_time[port] =
USBPD_PE_StateMachine_SRC(port);
DPM_Sleep_start[port] = HAL_GetTick();
}
}
USBPD_DPM_UserExecute(NULL);
The application must provide correct board support functions, especially VBUS sensing, and CC attach handling, so the sink state machines can progress normally.