cancel
Showing results for 
Search instead for 
Did you mean: 

UCPD sink on STM32G4

RMas
Associate II

Is it possible to implement UCPD sink on a stm32G4 without RTOS. What all does that entail? What are the pros and cons?

1 REPLY 1
FBL
ST Employee

Hi @RMas 

The following wiki application is based on FreeRTOS STM32StepByStep:Getting started with USB-Power Delivery Sink - stm32mcu and here is the associated example using G4 x-cube-tcpp/Projects/NUCLEO-G474RE/Applications/USB_PD/SNK1M1_Sink at main · STMicroelectronics/x-cube-tcpp (github.com)

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

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);
}

Caution: LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY may need to be adjusted as it may causes the code execution to get stuck in the vPortValidateInterruptPriority function due to overlapping interrupt priorities with kernel operations.

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.