Skip to main content
Associate
August 18, 2026
Question

Details on how to implement a USB PD Battery Status request from a sink to a battery source with STM32Cube_FW_G0_V1.6.3

  • August 18, 2026
  • 5 replies
  • 49 views

I am using a STM32G071CB MCU on a device that connects to a battery that supports USB PD and I would like to get a battery status periodically. Code generated by STM32CubeMX that includes trace and GUI code works as expected when using STM32CubeMonitor-UCPD. However, the return path of a battery status reply message does not go through usbpd_dpm_user.c, but through GUI code instead. I would like my application to use usbpd_dpm_user.c as the interface using STM32Cube_FW_G0_V1.6.3, but information on how to do that is incomplete and examples are outdated. There seems to be more required than just selecting appropriate usbpd PE options and adding code to USBPD_DPM_SetDataInfo().

Currently, USBPD_DPM_RequestGetBatteryStatus() returns USBPD_ERROR, but a request is send to the battery anyway. However, the battery status reply message does not trigger a call to USBPD_DPM_SetDataInfo() or USBPD_DPM_ExtendedMessageReceived(). What am I missing? Is there any documentation other than usbpd basics?

5 replies

ST Technical Moderator
August 18, 2026

Hi ​@BluntDog 

Did you configure .Is_GetBattery_Supported   in DPM_Settings?

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
BluntDogAuthor
Associate
August 18, 2026

Yes, that has been set to true by my STM32CubeMX support setting for Battery Status.

ST Technical Moderator
August 19, 2026

Would you attach your usbpd_dpm_conf.h and usbpd_dpm_user.c?

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
BluntDogAuthor
Associate
August 19, 2026

I get the following errors when I try to upload the requested files:

“usbpd_dpm_conf.h: Sorry, we couldn't upload your file because we don't support that file type.”

“usbpd_dpm_user.c: Sorry, we couldn't upload your file because we don't support that file type.”

 

Anyway, in USBPD_DPM_SetDataInfo() I added:

 

case USBPD_CORE_BATTERY_STATUS:

DPM_Ports[PortNum].DPM_BatteryStatus.d32 = *Ptr;

osMessagePut(USBPDOutQueueHandle, (uint32_t)*Ptr, QUEUE_PUT_TIMEOUT);

break;

case USBPD_CORE_GET_BATTERY_STATUS:

{

DPM_Ports[PortNum].DPM_GetBatteryStatus.BatteryStatusRef = *(uint8_t*)Ptr;

}

break;

 

The configuration in usbpd_dpm_conf.h is:

 

.PE_SupportedSOP = USBPD_SUPPORTED_SOP_SOP , /* Supported SOP : SOP, SOP' SOP" SOP'Debug SOP"Debug */

.PE_SpecRevision = USBPD_SPECIFICATION_REV3,/* spec revision value */

.PE_DefaultRole = USBPD_PORTPOWERROLE_SNK, /* Default port role */

.PE_RoleSwap = USBPD_FALSE, /* support port role swap */

.PE_VDMSupport = USBPD_FALSE,

.PE_RespondsToDiscovSOP = USBPD_FALSE, /*!< Can respond successfully to a Discover Identity */

.PE_AttemptsDiscovSOP = USBPD_FALSE, /*!< Can send a Discover Identity */

.PE_PingSupport = USBPD_FALSE, /* support Ping (only for PD3.0) */

.PE_CapscounterSupport = USBPD_FALSE, /* support caps counter */

.CAD_RoleToggle = USBPD_FALSE, /* CAD role toggle */

.CAD_TryFeature = 0, /* CAD try feature */

.CAD_AccesorySupport = USBPD_FALSE, /* CAD accessory support */

.PE_PD3_Support.d = /*!< PD3 SUPPORT FEATURE */

{

.PE_UnchunkSupport = USBPD_FALSE, /* support Unchunked mode (valid only spec revision 3.0) */

.PE_FastRoleSwapSupport = USBPD_FALSE, /* support fast role swap only spec revision 3.0 */

.Is_GetPPSStatus_Supported = USBPD_FALSE, /*!< PPS message NOT supported by PE stack */

.Is_SrcCapaExt_Supported = USBPD_TRUE, /*!< Source_Capabilities_Extended message supported or not by DPM */

.Is_Alert_Supported = USBPD_TRUE, /*!< Alert message supported or not by DPM */

.Is_GetStatus_Supported = USBPD_TRUE, /*!< Status message supported or not by DPM (Is_Alert_Supported should be enabled) */

.Is_GetManufacturerInfo_Supported = USBPD_FALSE, /*!< Manufacturer_Info message supported or not by DPM */

.Is_GetCountryCodes_Supported = USBPD_FALSE, /*!< Country_Codes message supported or not by DPM */

.Is_GetCountryInfo_Supported = USBPD_FALSE, /*!< Country_Info message supported or not by DPM */

.Is_SecurityRequest_Supported = USBPD_FALSE, /*!< Security_Response message supported or not by DPM */

.Is_FirmUpdateRequest_Supported = USBPD_FALSE, /*!< Firmware update response message supported by PE */

.Is_GetBattery_Supported = USBPD_TRUE, /*!< Get Battery Capabitity and Status messages supported by PE */

},

 

.CAD_SRCToggleTime = 0, /* uint8_t CAD_SRCToggleTime; */

.CAD_SNKToggleTime = 0, /* uint8_t CAD_SNKToggleTime; */

 

Everything else is as generated by STM32CubeMX. As I mentioned before, when TRACER_EMB and GUI_INTERFACE are included everything works fine including a call to USBPD_DPM_SetDataInfo() after a battery status request reply. I suspect some additional code is required as done in gui_api.c.

BluntDogAuthor
Associate
August 21, 2026

I decided to create test USB PD sink software from scratch for a NUCLEO_G071RB and X-NUCLEO-SNK1M1 following “Getting started with the STMicroelectronics X-CUBE-TCPP software package for STM32CubeMX” but leaving out TRACER_EMB and GUI_INTERFACE.

The root cause of the issue I am having is the system timebase source. Firmware can send and process a reply battery status response only if the timebase source is SysTick. It doesn’t work with any timer source. It’s not good to have FreeRTOS and HAL use the same timebase source. How can I work around this?