Skip to main content
Visitor II
November 21, 2022
Question

About UM2552 sample code

  • November 21, 2022
  • 11 replies
  • 4647 views

I am building a USBPD sink with reference to the UM2552, but in the sample code on page 16, it seems that the ")" corresponding to the IF on the 9th line has disappeared, is this a typo? Also, is there a correct example somewhere?

    This topic has been closed for replies.

    11 replies

    ST Employee
    November 21, 2022
    Sodag.1Author
    Visitor II
    November 21, 2022

    I have checked the package you gave me. It seems that the content is slightly different from UM2552, but is it this one?

    0693W00000WIzM7QAL.png

    ST Employee
    November 21, 2022

    Hi @Sodag.1​ ,

    The USBPD_DPM_Run function differs depending on whether you are in RTOS or bare metal system.

    In case of RTOS, the USBPD_DPM_Run function is used to start the OS and USBPD_DPM_UserExecute is the user application function called inside a dedicated task.

    void USBPD_DPM_Run(void)
    {
     OS_KERNEL_START();
    }

    In the case of bare metal, the USBPD_DPM_Run function is an infinite loop that calls the various entry points of the USBPD stack + USBPD_DPM_Users (for the user application)

    void USBPD_DPM_Run(void)
    {
     uint32_t port = 0;
     
     do
     {
     USBPD_CAD_Process();
     
     for (port = 0; port < USBPD_PORT_COUNT; port++)
     {
     if ((HAL_GetTick() - DPM_Sleep_start[port]) >= DPM_Sleep_time[port])
     {
     DPM_Sleep_time[port] =
    #ifdef _DRP
     USBPD_PE_StateMachine_DRP(port);
    #elif _SRC
     USBPD_PE_StateMachine_SRC(port);
    #elif _SNK
     USBPD_PE_StateMachine_SNK(port);
    #endif /* _DRP */
     DPM_Sleep_start[port] = HAL_GetTick();
     }
     }
     
     USBPD_DPM_UserExecute(NULL);
     } while (1u == 1u);
    }

    A standard USBPD sytem must handle different activities

    • state machine detection in charge to detect cable event (function USBPD_CAD_Process)
    • policy engine in charge manage PD exchange ( USBPD_PE_StateMachine_*** depending the port capabilities)

    Please could you provide us more detail about your issue ? and the type of application you want to generate ?

    BR

    Sodag.1Author
    Visitor II
    November 22, 2022

    thank you for your answer. I'm trying to build a USBPD on bare metal without RTOS. So I was trying to refer to the "do~while" of the USBPD_DPM_Run function

    I'm trying to build a USBPD_SINK to pick up an arbitrary voltage. I think that the necessary description should be written in the USBPD_PE_StateMachine_SNK function in the USBPD_DPM_Run function function, but is it wrong?

    Best regards,

    ST Employee
    November 23, 2022

    Hi Sodag,

    Bare metal brings some constraints unlike RTOS we don't have preemption management. So you must avoid blocking the system inside a task. The main constraint is on the management of USB-PD message exchanges, the standard requires responding to a message within a maximum of 30ms. So user tasks must not block the scheduling for more than 28ms to have a margin.

    in your case the function void USBPD_DPM_Run(void) manages the task schedule and USBPD_DPM_UserExecute can be used to call application code

    yes a sink port must use USBPD_PE_StateMachine_SNK(port);

    BR

    Dominique

    Sodag.1Author
    Visitor II
    November 24, 2022

    thank you for your answer. I have one more question. I am thinking about USBPD_SINK referring to the following Wiki. In this sample,

    https://wiki.st.com/stm32mcu/wiki/STM32StepByStep:Getting_started_with_USB-Power_Delivery_Sink

    I think that PD is managed by two tasks, "USBPD_CAD_Task" and "USBPD_PE_task", but where is the function actually executed in the task defined?

    Best regards,​

    ST Employee
    November 24, 2022

    Hi @Sodag.1​ 

    In your case, the scheduler is the while(1) instruction which will sequentially call the different functions: USBPD_CAD_Process, USBPD_PE_StateMachine_SNK and USBPD_DPM_UserExecute.

    Present inside the delivered stack, there is a file which could help you better understand the difference between OS and bare metal system : Middlewares\ST\STM32_USBPD_Library\Core\src\usbpd_dpm_core.c

    What is important for you is to see the correspondence

    the call to USBDP_CAD_Process is made inside USBPD_CAD_Task

    the call to USBPD_PE_StateMachine_SNK is made inside USBPD_PE_task

    BR

    Dominique

    Sodag.1Author
    Visitor II
    November 25, 2022

    thank you for your answer.

    As a first step I'm trying to recreate the selected PDO retrieval system running on the Wiki without an RTOS.

    In the sample, I think that the following two tasks are executed within the RTOS

    ・USBPD_CAD_Task (cable detection: USBPD_CAD_Process)

    ・USBPD_PE_Task (voltage adjustment, etc.: USBPD_PE_StateMachine_SNK)

    So, if I don't use RTOS, I think that the basic operation will work if the above function in () is executed in While(1), but is that correct?

    Also, looking at the explanations in the USBPD_CORE_RELEASE_User_Manual and UM2552, I didn't really understand the actual contents of the functions such as USBPD_CAD_Process.Is there a detailed explanation manual?

    Best regards,

    ST Employee
    December 1, 2022

    Hello Sodag,

    The USB-PD standard defines some rules for the cable detection (information available there https://www.usb.org/document-library/usb-type-cr-cable-and-connector-specification-release-22 ), the CAD process manages these rules through a state machine detection.

    BR

    Dominique

    Sodag.1Author
    Visitor II
    December 8, 2022

    Hello @Dominique​ 

    As a result of reviewing the code based on the materials you provided, I was able to extract an arbitrary voltage without using an RTOS.

    Thank you for your cooperation.

    BR