Hardfault on USBPD_PE_StateMachine_DRP
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?
