cancel
Showing results for 
Search instead for 
Did you mean: 

Message Rejected for this Port Configuration on the STM32 x-cube-tcpp example

nikolai2111
Associate II

Good afternoon together

I got myself a Nucleo with the STM32G474RE and a shield X-NUCLEO-SNK1M1 to develop a USB-C PD interface (sink), now I cloned the example from Github, built and downloaded it. The cable and the power plug are recognised, but if I select a specific PDO, I get the following message "Message Rejected from this Port Configuration" (see picture). And no PDO is selected. How should I configure the port, if this is not already set in the example?

18 REPLIES 18
FelipeFRL
Associate II

It didn't at the last image, when I requested the 3.3V-5.9V APDO with 3.3V. The last message is "DEBUG 607514 REQUEST not accepted by the stack", which is the response to this last request.

About the VBUSGetCurrent function, I tried copying the code from VBUSGetVoltage, changing variables and the multiplier but can't seem to make it work as I get false current readings (when comparing with multimeter and with current oscilloscope probe too). Where can I find a code exemple that really works?

Here are all the traces in text, even though SRC CAPA can be seen coloured at the first image:

 0 CAD 278616 0 USBPD_CAD_STATE_ATTACHED_WAIT

1 CAD 278740 0 USBPD_CAD_STATE_ATTACHED

2 NOTIF 278740 0 USBSTACK_START

3 DEBUG 278740 0 ADVICE: USBPD_DPM_Notification:104

4 EVENT 278740 0 EVENT_ATTACHED

5 DEBUG 278740 0 ADVICE: USBPD_DPM_Notification:104

6 PE 278740 0 PE_SNK_STARTUP

7 PE 278740 0 PE_SNK_WAIT_FOR_CAPABILITIES

8 IN 278943 0 SOP PD3 s:018  H:0x41A1  (id:0, DR:DFP, PR:SRC) SRC_CAPABILITIES DATA: 2C91010A15D102003C2176C83721DCC8

Option: DRDEPW

[1] Fixed : 5V - 3A /

[2] Fixed : 9V - 2.77A / 

[3] Programmable : [3.3V - 5.9V] - 3A / 

[4] Programmable : [3.3V - 11V] - 2.75A / 

9 OUT 278943 0 SOP s:002  H:0x0041   (id:0, DR:UFP, PR:SNK) GOODCRC

10 PE 278944 0 PE_SNK_EVALUATE_CAPABILITY

11 PE 278946 0 PE_SNK_SEND_REQUEST

12 OUT 278946 0 SOP PD3 REQUEST s:006  H:0x1082  (id:0, DR:UFP, PR:SNK) DATA: 15550420 / ObjectPosition:2 / GiveBack:0 / CapabilityMismatch:0 / USBCommunicationCapable:0 / NoUSBSuspend:0 / UnchunkedExtendedMessagesSupported:0

13 IN 278947 0 SOP s:002  H:0x0161   (id:0, DR:DFP, PR:SRC) GOODCRC

14 PE 278947 0 PE_SNK_SELECT_CAPABILITY

15 IN 278948 0 SOP PD3 ACCEPT s:002  H:0x03A3   (id:1, DR:DFP, PR:SRC) 

16 OUT 278948 0 SOP s:002  H:0x0241   (id:1, DR:UFP, PR:SNK) GOODCRC

17 NOTIF 278948 0 POWER_STATE_CHANGE

18 DEBUG 278948 0 ADVICE: USBPD_DPM_Notification:90

19 NOTIF 278949 0 REQUEST_ACCEPTED

20 PE 278949 0 PE_SNK_TRANSITION_SNK

21 IN 279235 0 SOP PD3 PS_RDY s:002  H:0x05A6   (id:2, DR:DFP, PR:SRC) 

22 OUT 279235 0 SOP s:002  H:0x0441   (id:2, DR:UFP, PR:SNK) GOODCRC

23 NOTIF 279236 0 POWER_STATE_CHANGE

24 DEBUG 279236 0 ADVICE: USBPD_DPM_Notification:90

25 NOTIF 279236 0 POWER_EXPLICIT_CONTRACT

26 DEBUG 279236 0 ADVICE: USBPD_DPM_Notification:16

27 PE 279236 0 PE_STATE_READY

28 NOTIF 279236 0 STATE_SNK_READY

29 DEBUG 279236 0 ADVICE: USBPD_DPM_Notification:32

30 PE 279236 0 PE_STATE_READY_WAIT

31 PE 287267 0 PE_SNK_SEND_REQUEST

32 OUT 287267 0 SOP PD3 REQUEST s:006  H:0x1282  (id:1, DR:UFP, PR:SNK) DATA: 2CB10410 / ObjectPosition:1 / GiveBack:0 / CapabilityMismatch:0 / USBCommunicationCapable:0 / NoUSBSuspend:0 / UnchunkedExtendedMessagesSupported:0

33 IN 287269 0 SOP s:002  H:0x0361   (id:1, DR:DFP, PR:SRC) GOODCRC

34 PE 287269 0 PE_SNK_SELECT_CAPABILITY

35 IN 287269 0 SOP PD3 ACCEPT s:002  H:0x07A3   (id:3, DR:DFP, PR:SRC) 

36 OUT 287269 0 SOP s:002  H:0x0641   (id:3, DR:UFP, PR:SNK) GOODCRC

37 NOTIF 287270 0 POWER_STATE_CHANGE

38 DEBUG 287270 0 ADVICE: USBPD_DPM_Notification:90

39 NOTIF 287270 0 REQUEST_ACCEPTED

40 PE 287270 0 PE_SNK_TRANSITION_SNK

41 IN 287556 0 SOP PD3 PS_RDY s:002  H:0x09A6   (id:4, DR:DFP, PR:SRC) 

42 OUT 287556 0 SOP s:002  H:0x0841   (id:4, DR:UFP, PR:SNK) GOODCRC

43 NOTIF 287556 0 POWER_STATE_CHANGE

44 DEBUG 287557 0 ADVICE: USBPD_DPM_Notification:90

45 NOTIF 287557 0 POWER_EXPLICIT_CONTRACT

46 DEBUG 287557 0 ADVICE: USBPD_DPM_Notification:16

47 PE 287557 0 PE_STATE_READY

48 NOTIF 287557 0 STATE_SNK_READY

49 DEBUG 287557 0 ADVICE: USBPD_DPM_Notification:32

50 PE 287557 0 PE_STATE_READY_WAIT

51 PE 294467 0 PE_SNK_SEND_REQUEST

52 OUT 294467 0 SOP PD3 REQUEST s:006  H:0x1482  (id:2, DR:UFP, PR:SNK) DATA: 15550420 / ObjectPosition:2 / GiveBack:0 / CapabilityMismatch:0 / USBCommunicationCapable:0 / NoUSBSuspend:0 / UnchunkedExtendedMessagesSupported:0

53 IN 294469 0 SOP s:002  H:0x0561   (id:2, DR:DFP, PR:SRC) GOODCRC

54 PE 294469 0 PE_SNK_SELECT_CAPABILITY

55 IN 294469 0 SOP PD3 ACCEPT s:002  H:0x0BA3   (id:5, DR:DFP, PR:SRC) 

56 OUT 294469 0 SOP s:002  H:0x0A41   (id:5, DR:UFP, PR:SNK) GOODCRC

57 NOTIF 294470 0 POWER_STATE_CHANGE

58 DEBUG 294470 0 ADVICE: USBPD_DPM_Notification:90

59 NOTIF 294470 0 REQUEST_ACCEPTED

60 PE 294470 0 PE_SNK_TRANSITION_SNK

61 IN 294756 0 SOP PD3 PS_RDY s:002  H:0x0DA6   (id:6, DR:DFP, PR:SRC) 

62 OUT 294756 0 SOP s:002  H:0x0C41   (id:6, DR:UFP, PR:SNK) GOODCRC

63 NOTIF 294756 0 POWER_STATE_CHANGE

64 DEBUG 294756 0 ADVICE: USBPD_DPM_Notification:90

65 NOTIF 294756 0 POWER_EXPLICIT_CONTRACT

66 DEBUG 294757 0 ADVICE: USBPD_DPM_Notification:16

67 PE 294757 0 PE_STATE_READY

68 NOTIF 294757 0 STATE_SNK_READY

69 DEBUG 294757 0 ADVICE: USBPD_DPM_Notification:32

70 PE 294757 0 PE_STATE_READY_WAIT

71 DEBUG 298422 0 REQUEST not accepted by the stack

72 DEBUG 306386 0 REQUEST not accepted by the stack

73 PE 601467 0 PE_SNK_SEND_REQUEST

74 OUT 601467 0 SOP PD3 REQUEST s:006  H:0x1682  (id:3, DR:UFP, PR:SNK) DATA: 2CB10410 / ObjectPosition:1 / GiveBack:0 / CapabilityMismatch:0 / USBCommunicationCapable:0 / NoUSBSuspend:0 / UnchunkedExtendedMessagesSupported:0

75 IN 601468 0 SOP s:002  H:0x0761   (id:3, DR:DFP, PR:SRC) GOODCRC

76 PE 601468 0 PE_SNK_SELECT_CAPABILITY

77 IN 601469 0 SOP PD3 ACCEPT s:002  H:0x0FA3   (id:7, DR:DFP, PR:SRC) 

78 OUT 601469 0 SOP s:002  H:0x0E41   (id:7, DR:UFP, PR:SNK) GOODCRC

79 NOTIF 601469 0 POWER_STATE_CHANGE

80 DEBUG 601469 0 ADVICE: USBPD_DPM_Notification:90

81 NOTIF 601469 0 REQUEST_ACCEPTED

82 PE 601469 0 PE_SNK_TRANSITION_SNK

83 IN 601756 0 SOP PD3 PS_RDY s:002  H:0x01A6   (id:0, DR:DFP, PR:SRC) 

84 OUT 601756 0 SOP s:002  H:0x0041   (id:0, DR:UFP, PR:SNK) GOODCRC

85 NOTIF 601757 0 POWER_STATE_CHANGE

86 DEBUG 601757 0 ADVICE: USBPD_DPM_Notification:90

87 NOTIF 601757 0 POWER_EXPLICIT_CONTRACT

88 DEBUG 601757 0 ADVICE: USBPD_DPM_Notification:16

89 PE 601757 0 PE_STATE_READY

90 NOTIF 601757 0 STATE_SNK_READY

91 DEBUG 601757 0 ADVICE: USBPD_DPM_Notification:32

92 PE 601757 0 PE_STATE_READY_WAIT

93 DEBUG 607514 0 REQUEST not accepted by the stack

Regards,

Felipe

The traces in .cpd format can be seen at this link.

FelipeFRL
Associate II

Dear @HFISTM​ ,

I'm debbuging the hell out of this aplication, and the problem seems to be within line 432 of usbpd_user_services.c file. The USER_SERV_SNK_EvaluateMatchWithSRCPDO function passes only the max possible voltage to the RequestedVoltage variable used in ResquestMessageRequest function, then causing its if condition of equality between voltage and RequestedVoltage to be False, which then traces the Debug message "REQUEST not accepted by the stack". I just don't know what value to use on line 432 for it to proceed in the right way.

After commenting out this line, the application seems to be out of control, as it won't establish a contract. The hardware it keeps unstoppably requesting for the APDO to be instated, rejecting the request and then resetting, over and over.

Here you can see one iteration of this unending cycle of madness:


_legacyfs_online_stmicro_images_0693W00000bi1qjQAA.png 

Regards,

Felipe

FelipeFRL
Associate II

Any help? @HFISTM​ 

HFISTM
ST Employee

Hello @FelipeFRL​ ,

Thanks, I've understood the issue.

Could you please try the following fix ?

Please replace line 427 to 439 (the whole block if (((srcminvoltage100mv <= snkmaxvolta ...) by:

            /* Match if SNK APDO voltage overlaps with the SRC APDO voltage range */
            if (((srcminvoltage100mv <= snkmaxvoltage100mv) && (srcminvoltage100mv >= snkminvoltage100mv)) ||
                ((snkminvoltage100mv <= srcmaxvoltage100mv) && (snkminvoltage100mv >= srcminvoltage100mv)))
            {
              if (snkmaxcurrent50ma <= srcmaxcurrent50ma)
              {
                if (0U != *PtrRequestedPower)
                {
                  /* A specific voltage was requested, verify it */
                  if ((PWR_DECODE_100MV(snkminvoltage100mv) <= (*PtrRequestedVoltage)) && 
                     ((*PtrRequestedVoltage) <= PWR_DECODE_100MV(snkmaxvoltage100mv)))
                  {
                    currentrequestedpower = (*PtrRequestedVoltage * PWR_DECODE_50MA(snkmaxcurrent50ma))
                                            / 1000U; /* mW */
                    currentrequestedvoltage = (*PtrRequestedVoltage / 50U);
                  }
                }
                else
                {
                  /* No specific voltage was requested, take the maximum possible voltage:
                     min between the source max and Sink max */
                  *PtrRequestedVoltage = MIN(PWR_DECODE_100MV(srcmaxvoltage100mv),
                                             PWR_DECODE_100MV(snkmaxvoltage100mv));
 
                  currentrequestedpower = (*PtrRequestedVoltage * PWR_DECODE_50MA(snkmaxcurrent50ma))
                                          / 1000U; /* mW */
                  currentrequestedvoltage = (*PtrRequestedVoltage / 50U);  
                }
              }
            }

Thank you for your feedback regarding this bug, we will update the x-cube-tcpp package to fix it shortly.

Best regards

FelipeFRL
Associate II

Thanks for the response!!

It didn't work, I can't even request the PDOs now. I made a sketchy but honest solution, but it can't be passed to the tcpp example as it won't work with other Source devices. It seems like your solution is way smarter and the right one to be passed to the tcpp example, it just needs to work.

HFISTM
ST Employee

Hello @FelipeFRL​ ,

Please try with the original code from x-cube-tcpp without any modifications but the one in this thread. (USBPD_DPM_RequestMessageRequest modification + the code I just sent above).

It worked on our side so ensuring that we are aligned on the same code would help.

Thanks

FelipeFRL
Associate II

It seems to have worked, that fixed the original problem, but I have other problems now. It won't finalize the request made even though it has recognized the request correctly. Every subsequent request I make (even get_status, or requestHardReset), it gets status USBPD_BUSY and then traces REQUEST not accepted by the stack.

Any clue?

Its not relevant yet for you but I hope someone will find this answer useful. The VBUS_Get_Current() function example can be found in CubeMX examples for G0 boards: STM32G081B-EVAL. You need to open the DemoUCPD project in CubeIDE, for me the path is:

C:\ST\STM32CubeMX\Repository\STM32Cube_FW_G0_V1.6.2\Projects\STM32G081B-EVAL\Demonstrations\DemoUCPD

Now in DemoUCPD\Src\demo_application.c you can find the BSP_USBPD_PWR_VBUSGetCurrent() call which can lead you to the example when looking for its declaration.

/**
  * @brief  Get actual current level measured on the VBUS line.
  * @PAram  Instance Type-C port identifier
  *         This parameter can be take one of the following values:
  *         @arg @ref USBPD_PWR_TYPE_C_PORT_1
  *         @arg @ref USBPD_PWR_TYPE_C_PORT_2
  * @PAram  pCurrent Pointer on measured current level (in mA)
  * @retval BSP status
  */
int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t Instance, int32_t *pCurrent)
{
  /* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetCurrent */
  /* Check if instance is valid       */
  int32_t ret = BSP_ERROR_NONE;

  if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pCurrent))
  {
    ret = BSP_ERROR_WRONG_PARAM;
  }
  else
  {
    int32_t current = 0;

    if (Instance == USBPD_PWR_TYPE_C_PORT_1)
    {
      current = PWR_ConvertADCDataToCurrent(aADCxConvertedValues[2u]);
    }
    else
    {
      if (Instance == USBPD_PWR_TYPE_C_PORT_2)
      {
        current = PWR_ConvertADCDataToCurrent(aADCxConvertedValues[3u]);
      }
    }

    *pCurrent = current;
  }
  return ret;
  /* USER CODE END BSP_USBPD_PWR_VBUSGetCurrent */
/**
  * @brief  Calculate the VBUS current level corresponding to ADC raw converted data.
  * @note   Current level is measured though INA199x1 output voltage level.
  * @note   INA199x1 measures currents through a resistive shunt (0.005 Ohms) in
  *         two directions.
  * @note   VDD corresponds to the zero-input level state. The Vout responds
  *         by increasing above VDD for positive differential signals (relative
  *         to the IN� pin) and responds by decreasing below VDD for negative
  *        differential signals.
  *
  *   VBUS -----. Rs .-....
  *             |    |  .------------.
  *             |    |  |  INA199x1  |
  *             |    |  |            |
  *             |    '--> IN+        > Vout (GAIN * Vs)
  *             |  Vs ^ |            | 0 <= Vout < VDD   -  negative current
  *             |     | |            | Vout = VDD        -  zero-input
  *             '-------> IN-        | Vout > VDD        -  positive current
  *                     |            |
  *              Vref   >            |
  *             (Vdd/2) |            |
  *                     '------------'
  *
  * Is = Vout/(GAIN * Rs) = (Vout - 2*Vref)/(Gain * Rs)
  *    where Vout = ADCData * (VDD/ADC_FULL_SCALE)
  * Is = (ADCData * Vdd)/(ADC_FULL_SCALE * Gain * Rs) - Vdd/(Gain * Rs)
  *   Vdd = 3300 mV, ADC_FULL_SCALE = 4095, Gain = 50, Rs = 5/1000
  * @PAram  ADCData  ADC raw converted data (resolution 12 bits)
  * @retval VBUS analog current (unit: mA)
  */
static int32_t PWR_ConvertADCDataToCurrent(uint32_t ADCData)
{
  int32_t current;

  current = ((ADCData * VDD) >> 10u) - 6600u;

  return current;
}

Note that the Current measurement on STM32G081B-EVAL is provided by UCPD daughterboard USB PD and its INA199C1DCKR (see Figure 50. in UM2403).

Isense measurement is also native for TCPP02 and TCPP03 with using small R (as in Figure 14. of UM2891), but not for TCPP01 (which is on SNK1M1).

Untitled.png