Hardfault on USBPD_PE_StateMachine_DRP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-06-20 8:44 AM
I am developing a USB power delivery solution involving the STM32G0B1. I have already followed the tutorials for creating a simple DRP application on a Nucleo devkit and they work as expected.
To my understanding there are two paths that we can take; the one is based on FreeRTOS (which comes as a CubeMX software package), while the other is to use a bare-metal flavour of the application with no RTOS.
We have already our own special version of FreeRTOS internally in my company, so, in order to use this, I grabbed the do-while loop from USBPD_DPM_Run() that is executed when no RTOS is in place, and I created a FreeRTOS task that runs it. I ended up with the following snippet:
while(true)
{
// Scheduler stuff
uint8_t port = 0;
uint32_t current_time = HAL_GetTick();
uint32_t next_delay = 0xFF; // Max. delay
for (port = 0; port <= USBPD_PORT_COUNT; port++)
{
if ((current_time - DPM_Sleep_start[port]) < DPM_Sleep_time[port])
{
uint32_t port_delay = DPM_Sleep_time[port] - (current_time - DPM_Sleep_start[port]);
if (port_delay < next_delay)
{
next_delay = port_delay;
}
}
}
vTaskDelay(pdMS_TO_TICKS(next_delay));
// If it has slept for more than sleep time, then run
if ((current_time - 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] = current_time;
}
for (port = 0; port < USBPD_PORT_COUNT; port++)
{
if ((current_time - DPM_Sleep_start[port]) >= DPM_Sleep_time[port])
{
DPM_Sleep_time[port] = USBPD_PE_StateMachine_DRP(port);
DPM_Sleep_start[port] = current_time;
}
}
USBPD_DPM_UserExecute(NULL);
};
The task is called as expected, however USBPD_PE_StateMachine_DRP() gives me a HardFault. I am trying to troubleshoot this, but it is hard since the function comes from a precompiled library. Any ideas on where to look/how to debug this?
- Labels:
-
STM32G0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-07-04 4:37 AM - edited 2025-07-04 6:17 AM
Thank you for the detailed description!
First, did you check UM2552, in the non RTOS case?
Second, while debugging, did you try to recover call stack? Did you try to use UCPD monitor and attach a trace?
You can temporarily disable custom threads to reduce the complexity of the application and to isolate the issue.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
