cancel
Showing results for 
Search instead for 
Did you mean: 

How to use two ucpd port in stm32g0?

Gbang
Associate III

I generated my code by stm32cubemx, and use ucpd1 as sink&dead battery, use ucpd2 as drp. But got USBPD_ERROR in USBPD_DPM_InitCore after execute " CHECK_PE_FUNCTION_CALL(USBPD_PE_Init(USBPD_PORT_0, (USBPD_SettingsTypeDef *)&DPM_Settings[USBPD_PORT_0], &DPM_Params[USBPD_PORT_0], &dpmCallbacks));

"

and USBPD_PE_Init success when just use ucpd1, ​why the added ucpd2 caused the ucpd1 USBPD_PE_Init error?

thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Yohann M.
ST Employee

This issue is linked to heap size used your project. You have to increase the 'Minimum heap size' in the "Project Manager[Project]" panel.

I advise you 0x800 instead of 0x400.

Useful debug function is the following one:

  /* to get how much memory are dynamically allocated by the stack
     the memory return is corresponding to 2 ports so if the application
     managed only one port divide the value return by 2                   */
  stack_dynamemsize = USBPD_PE_GetMemoryConsumption();

(same problem as this thread)

View solution in original post

5 REPLIES 5
Yohann M.
ST Employee

This issue is linked to heap size used your project. You have to increase the 'Minimum heap size' in the "Project Manager[Project]" panel.

I advise you 0x800 instead of 0x400.

Useful debug function is the following one:

  /* to get how much memory are dynamically allocated by the stack
     the memory return is corresponding to 2 ports so if the application
     managed only one port divide the value return by 2                   */
  stack_dynamemsize = USBPD_PE_GetMemoryConsumption();

(same problem as this thread)

Gbang
Associate III

thanks and it works.

Hello,

And I got another problem, when I set the breakpoint in USBPD_DPM_SNK_EvaluateCapabilities, and set USBPD_PORT_COUNT=1, and then I connect my pd power adapter with ucpd1 by typec line, it will trigger the breakpoint, and I can get the source capabilities from power adapter.

however, if I set USBPD_PORT_COUNT=2, after connect with ucpd1, this breakpoint will not trigger.

Defined symbols,

USE_FULL_LL_DRIVER
USBPD_PORT_COUNT=2
USBPDCORE_LIB_PD3_FULL
_RTOS
_DRP
USE_HAL_DRIVER
STM32G071xx

Hello,

I reproduced an issue with the following configuration:

  • Port0 (UCPD1) configured as source
  • Port1 (UCPD2) configured as sink

Then CubeMX will generate a project with _DRP switch to cover both configurations.

We found an issue with this configuration. I suggest to apply the following patch in the file '.\Middlewares\ST\STM32_USBPD_Library\Devices\STM32G0XX\src\usbpd_cad_hw_if.c'

static uint32_t ManageStateAttached_SRC(uint8_t PortNum, USBPD_CAD_EVENT *pEvent, CCxPin_TypeDef *pCCXX)
{
(...)
      /* evaluate CAD_tDebounce */
      uint32_t CAD_tDebounce = HAL_GetTick() - _handle->CAD_tDebounce_start;
      if (CAD_tDebounce > CAD_TSRCDISCONNECT_THRESHOLD)
      {
        HW_SignalDetachment(PortNum);
#ifdef _DRP
        if (USBPD_TRUE == Ports[PortNum].settings->CAD_RoleToggle)
        {
          USBPDM1_AssertRd(PortNum);
        }
#endif 

Do not forget to add the handle for Port1 in 'UCPD1_2_IRQHandler' function:

/**
  * @brief This function handles UCPD1 and UCPD2 interrupts / UCPD1 and UCPD2 wake-up interrupts through EXTI lines 32 and 33.
  */
void UCPD1_2_IRQHandler(void)
{
  /* USER CODE BEGIN UCPD1_2_IRQn 0 */
  extern void USBPD_PORT0_IRQHandler(void);
  USBPD_PORT0_IRQHandler();
#if USBPD_PORT_COUNT == 2
  extern void USBPD_PORT1_IRQHandler(void);
  USBPD_PORT1_IRQHandler();
#endif

Sorry for the problem. We will fix it in the next G0 release.

Gbang
Associate III

It works for me, thank you very much.:beaming_face_with_smiling_eyes: ​