STMicroelectronics / x-cube-tcpp

STM32 expansion package providing an integrated solution for a robust protection of MCU-based USB Type-C applications
https://www.st.com/content/st_com/en/stm32-usb-c.html
Other
25 stars 9 forks source link

Cannot run 2x USB PD contracts at once. #9

Closed davedesro closed 4 months ago

davedesro commented 6 months ago

Describe the bug There's only one queue for 2x PE threads. Each PE thread needs its own queue. Here's the diff explaining the issue, and the fix.

diff --git a/app/src/usbpd/STM32_USBPD_Library/Core/src/usbpd_dpm_core.c b/app/src/usbpd/STM32_USBPD_Library/Core/src/usbpd_dpm_core.c
index 616dd53d..20f78dc1 100644
--- a/app/src/usbpd/STM32_USBPD_Library/Core/src/usbpd_dpm_core.c
+++ b/app/src/usbpd/STM32_USBPD_Library/Core/src/usbpd_dpm_core.c
@@ -433,10 +433,10 @@ USBPD_StatusTypeDef USBPD_DPM_InitOS(void)
   /* Create the queue corresponding to PE task */
   for (uint32_t index = 0; index < USBPD_PORT_COUNT; index++)
   {
-    OS_CREATE_QUEUE(PEQueueId[index], QPE, 1, OS_ELEMENT_SIZE);

     if (index == USBPD_PORT_0)
     {
+      OS_CREATE_QUEUE(PEQueueId[index], QPE_0, 1, OS_ELEMENT_SIZE);
       /* Tasks definition */
       OS_DEFINE_TASK(PE_0, USBPD_PE_Task, OS_PE_PRIORITY,  OS_PE_STACK_SIZE,  USBPD_PORT_0);
       OS_CREATE_TASK(DPM_PEThreadId_Table[USBPD_PORT_0], PE_0, USBPD_PE_Task,
@@ -445,6 +445,7 @@ USBPD_StatusTypeDef USBPD_DPM_InitOS(void)
 #if USBPD_PORT_COUNT > 1
     if (index == USBPD_PORT_1)
     {
+      OS_CREATE_QUEUE(PEQueueId[index], QPE_1, 1, OS_ELEMENT_SIZE);
       /* Tasks definition */
       OS_DEFINE_TASK(PE_1, USBPD_PE_Task, OS_PE_PRIORITY,  OS_PE_STACK_SIZE,  USBPD_PORT_1);
       OS_CREATE_TASK(DPM_PEThreadId_Table[USBPD_PORT_1], PE_1, USBPD_PE_Task,

How To Reproduce

  1. Enable both UCPD / USB PD ports
  2. Plug one USB PD partner in port1
  3. Plug another USB PD partner in port2
  4. Port1 will start to send HARD_RESETs

The modules that you suspect to be the cause of the problem (Driver, BSP, MW ...) STM32_USBPD_Library/Core

The use case that generates the problem. Using 2x ports

HFISTM commented 6 months ago

ST Internal Reference: 175518

LLECSTM commented 4 months ago

Fixed in commit 97ed40c9cdbb9dc18377ea4533833be2844532b2