Skip to main content
Graduate II
March 5, 2025
Question

STM32G0B1 USB-PD

  • March 5, 2025
  • 2 replies
  • 740 views

Hi, 

I am using the STM32G0B1CBTX with STM32CubeMX ver 6.13.0 to produce a USB-PD DRP application. So far, I managed to implement a USB 2.0 Host as this is also needed. When trying to add the USB-PD DRP following ST-s tutorial BUT omitting the inclusion of the OS, I get a hard fault immediately after running the firmware. Moreover, I need to use the USB-PD library without the OS.

1. I tried to check what is causing the hard fault but I cannot find any documentation on how to view the hard fault status or any reference to hard fault registers. Can someone point me to any documentation. 

2. Are there any references on how to implement the USB-PD with out the use of an OS?

 

Thanks

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    March 10, 2025

    Hi @DDeba.1 

    First, we do not recommend building applications without RTOS in case full compliance with USB PD and Type-C specifications is required.

    Without an RTOS, you would typically have a main loop that continuously polls various functions and manages state transitions manually. Check page 16 in UM2552

    void USBPD_DPM_Run(void)
    {
     // The following code is executed in an infinite loop
     do {
     // Call the Type-C and USB PD stack to handle any CAD (Cable Attachment Detection) events
     (void)USBPD_CAD_Process();
    
     // Check if the time elapsed since the last Policy Engine (PE) process run is greater than the defined sleep time
     if ((HAL_GetTick() - DPM_Sleep_start[USB_PD_PORT_0]) > DPM_Sleep_time[USB_PD_PORT_0]) {
     // Depending on the role of the device (DRP, Source, or Sink), run the appropriate PE state machine
    
     USBPD_PE_StateMachine_SNK(USB_PD_PORT_0);
    
     // Update the start time for the next PE process run
     DPM_Sleep_start[USB_PD_PORT_0] = HAL_GetTick();
     }
    
     // Execute user-defined code, which could include handling application-specific logic
     USBPD_DPM_UserExecute(NULL);
    
     // Process any pending USB PD trace data for transmission
     (void)USBPD_TRACE_TX_Process();
    
     // Continue looping indefinitely
     } while (1u == 1u);
    }

     

    DDeba.1Author
    Graduate II
    March 11, 2025

    Hi @FBL ,

    Thanks for your reply. I have found the main issues and basically;

    1. The hard fault was coming from not setting the CAD role toggle to supported in CubeMX. This was causing the CAD_PtrStateMachine function pointer in usbpd_cad_hw_if.c to point to NULL. 

    2. So far, I implemented the USB-PD SINK using RTOS and the GUI Interface for debugging and managed to find the necessary functions to request a change in power profile. 

    As a side note, my application is for a testing equipment to test products which incorporates a USB-PD source and  part of the test would be to switch power profiles. Thus I don't need full compliance with USB-PD. 

    Thanks

    Technical Moderator
    March 11, 2025

    Hi @DDeba.1 

    Would you attach IOC file to report the issue of not setting role toggle? 
    Thanks

    Technical Moderator
    March 11, 2025

    Hi @DDeba.1 

    Thank you again! An internal ticket is submitted to dedicated team 205086  about CAD_PtrStateMachine pointing to NULL.

    The other issue should be fixed in internal ticket 203408.