Changeset 65 for trunk/fw_g473rct/USBPD


Ignore:
Timestamp:
Apr 2, 2026, 3:56:21 PM (5 weeks ago)
Author:
f.jahn
Message:
  • USB-PD function was implemented;
  • HW parity check on RAM was activated;
  • USB Device CDC mode was activated.
Location:
trunk/fw_g473rct/USBPD
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/fw_g473rct/USBPD/App/usbpd_dpm_core.c

    r59 r65  
    9696  static const USBPD_PE_Callbacks dpmCallbacks =
    9797  {
    98     NULL,
     98    USBPD_DPM_SetupNewPower,
    9999    USBPD_DPM_HardReset,
    100100    NULL,
     
    103103    USBPD_DPM_GetDataInfo,
    104104    USBPD_DPM_SetDataInfo,
     105    USBPD_DPM_EvaluateRequest,
    105106    NULL,
    106     USBPD_DPM_SNK_EvaluateCapabilities,
    107107    NULL,
    108108    USBPD_PE_TaskWakeUp,
     
    244244  UTIL_TIMER_Stop(&TimerPE0);
    245245  uint32_t _timing =
    246     USBPD_PE_StateMachine_SNK(USBPD_PORT_0);
     246    USBPD_PE_StateMachine_SRC(USBPD_PORT_0);
    247247  if (_timing != 0xFFFFFFFF)
    248248  {
     
    260260  UTIL_TIMER_Stop(&TimerPE1);
    261261  uint32_t _timing =
    262     USBPD_PE_StateMachine_SNK(USBPD_PORT_1);
     262    USBPD_PE_StateMachine_SRC(USBPD_PORT_1);
    263263  if (_timing != 0xFFFFFFFF)
    264264  {
     
    320320      {
    321321        DPM_Sleep_time[port] =
    322           USBPD_PE_StateMachine_SNK(port);
     322          USBPD_PE_StateMachine_SRC(port);
    323323        DPM_Sleep_start[port] = HAL_GetTick();
    324324      }
     
    327327    USBPD_DPM_UserExecute(NULL);
    328328
    329   } while (1u == 1u);
     329  } while (1u != 1u);
    330330#endif /* USE_STM32_UTILITY_OS */
    331331}
  • trunk/fw_g473rct/USBPD/App/usbpd_pdo_defs.h

    r59 r65  
    3434
    3535/* Define   ------------------------------------------------------------------*/
    36 #define PORT0_NB_SOURCEPDO         0U   /* Number of Source PDOs (applicable for port 0)   */
    37 #define PORT0_NB_SINKPDO           1U   /* Number of Sink PDOs (applicable for port 0)     */
     36#define PORT0_NB_SOURCEPDO         1U   /* Number of Source PDOs (applicable for port 0)   */
     37#define PORT0_NB_SINKPDO           0U   /* Number of Sink PDOs (applicable for port 0)     */
    3838#define PORT1_NB_SOURCEPDO         0U   /* Number of Source PDOs (applicable for port 1)   */
    3939#define PORT1_NB_SINKPDO           0U   /* Number of Sink PDOs (applicable for port 1)     */
     
    8585uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO] =
    8686{
    87   /* PDO 1 */ (0x00000000U),
     87  /* PDO 1 */
     88  (
     89    USBPD_PDO_TYPE_FIXED                 | /* Fixed supply PDO            */
     90
     91    USBPD_PDO_SRC_FIXED_SET_VOLTAGE(5000U)         | /* Voltage in mV               */
     92    USBPD_PDO_SRC_FIXED_SET_MAX_CURRENT(3000U)     | /* Max current in mA           */
     93    USBPD_PDO_SRC_FIXED_PEAKCURRENT_EQUAL          | /* Peak Current info           */
     94
     95    /* Common definitions applicable to all PDOs, defined only in PDO 1 */
     96    USBPD_PDO_SRC_FIXED_UNCHUNK_NOT_SUPPORTED      | /* Unchunked Extended Messages */
     97    USBPD_PDO_SRC_FIXED_DRD_SUPPORTED          | /* Dual-Role Data              */
     98    USBPD_PDO_SRC_FIXED_USBCOMM_SUPPORTED      | /* USB Communications          */
     99    USBPD_PDO_SRC_FIXED_EXT_POWER_NOT_AVAILABLE    | /* External Power              */
     100    USBPD_PDO_SRC_FIXED_USBSUSPEND_NOT_SUPPORTED   | /* USB Suspend Supported            */
     101    USBPD_PDO_SRC_FIXED_DRP_NOT_SUPPORTED            /* Dual-Role Power             */
     102  ),
    88103
    89104  /* PDO 2 */ (0x00000000U),
     
    105120{
    106121
    107   /* PDO 1 */
    108   (
    109     USBPD_PDO_TYPE_FIXED                 | /* Fixed supply PDO            */
    110 
    111     USBPD_PDO_SNK_FIXED_SET_VOLTAGE(5000U)         | /* Voltage in mV               */
    112     USBPD_PDO_SNK_FIXED_SET_OP_CURRENT(500U)     | /* Operating current in  mA            */
    113 
    114     /* Common definitions applicable to all PDOs, defined only in PDO 1 */
    115     USBPD_PDO_SNK_FIXED_FRS_NOT_SUPPORTED          | /* Fast Role Swap                           */
    116     USBPD_PDO_SNK_FIXED_DRD_NOT_SUPPORTED          | /* Dual-Role Data              */
    117     USBPD_PDO_SNK_FIXED_USBCOMM_NOT_SUPPORTED      | /* USB Communications          */
    118     USBPD_PDO_SNK_FIXED_EXT_POWER_NOT_AVAILABLE    | /* External Power              */
    119     USBPD_PDO_SNK_FIXED_HIGHERCAPAB_NOT_SUPPORTED   | /* Higher Capability           */
    120     USBPD_PDO_SNK_FIXED_DRP_NOT_SUPPORTED            /* Dual-Role Power             */
    121   ),
     122  /* PDO 1 */ (0x00000000U),
    122123
    123124  /* PDO 2 */ (0x00000000U),
  • trunk/fw_g473rct/USBPD/App/usbpd_pwr_if.c

    r59 r65  
    121121
    122122/**
     123  * @brief  Sets the required power profile, now it works only with Fixed ones
     124  * @param  PortNum Port number
     125  * @retval USBPD status
     126*/
     127USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum)
     128{
     129/* USER CODE BEGIN USBPD_PWR_IF_SetProfile */
     130  USBPD_StatusTypeDef      _status = USBPD_ERROR;
     131  PWR_IF_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_PWR_IF_SetProfile");
     132  if (BSP_ERROR_NONE == BSP_USBPD_PWR_VBUSSetVoltage_Fixed(PortNum, 5000, 3000, 3000))
     133  {
     134     _status = USBPD_OK;
     135  }
     136 
     137  return _status;
     138/* USER CODE END USBPD_PWR_IF_SetProfile */
     139}
     140
     141/**
    123142  * @brief  Checks if the power on a specified port is ready
    124143  * @param  PortNum Port number
     
    152171  return status;
    153172/* USER CODE END USBPD_PWR_IF_SupplyReady */
     173}
     174
     175/**
     176  * @brief  Enables VBUS power on a specified port
     177  * @param  PortNum Port number
     178  * @retval USBPD status
     179  */
     180USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum)
     181{
     182/* USER CODE BEGIN USBPD_PWR_IF_VBUSEnable */
     183  USBPD_StatusTypeDef _status = (USBPD_StatusTypeDef)HW_IF_PWR_Enable(PortNum, USBPD_ENABLE, CCNONE, USBPD_FALSE, USBPD_PORTPOWERROLE_SRC);
     184  return _status;
     185/* USER CODE END USBPD_PWR_IF_VBUSEnable */
     186}
     187
     188/**
     189  * @brief  Disable VBUS/VCONN the power on a specified port
     190  * @param  PortNum Port number
     191  * @retval USBPD status
     192  */
     193USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum)
     194{
     195/* USER CODE BEGIN USBPD_PWR_IF_VBUSDisable */
     196  USBPD_StatusTypeDef _status = (USBPD_StatusTypeDef)HW_IF_PWR_Enable(PortNum, USBPD_DISABLE, CCNONE, USBPD_FALSE, USBPD_PORTPOWERROLE_SRC);
     197  return _status;
     198/* USER CODE END USBPD_PWR_IF_VBUSDisable */
     199}
     200
     201/**
     202  * @brief  Checks if the power on a specified port is enabled
     203  * @param  PortNum Port number
     204  * @retval USBPD_ENABLE or USBPD_DISABLE
     205  */
     206USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum)
     207{
     208  /* Get the Status of the port */
     209  return USBPD_PORT_IsValid(PortNum) ? (USBPD_FunctionalState)HW_IF_PWR_VBUSIsEnabled(PortNum) : USBPD_DISABLE;
    154210}
    155211
     
    207263void USBPD_PWR_IF_GetPortPDOs(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size)
    208264{
     265    if (DataId == USBPD_CORE_DATATYPE_SRC_PDO)
    209266    {
    210       *Size = PORT0_NB_SINKPDO;
    211       memcpy(Ptr,PORT0_PDO_ListSNK, sizeof(uint32_t) * PORT0_NB_SINKPDO);
     267      *Size = PORT0_NB_SOURCEPDO;
     268      memcpy(Ptr,PORT0_PDO_ListSRC, sizeof(uint32_t) * PORT0_NB_SOURCEPDO);
    212269    }
    213270/* USER CODE BEGIN USBPD_PWR_IF_GetPortPDOs */
     
    269326  switch(PowerTypeStatus)
    270327  {
    271   case USBPD_PWR_BELOWVSAFE0V :
    272     if (_vbus < USBPD_PWR_LOW_VBUS_THRESHOLD) _status = USBPD_TRUE;
    273     break;
    274   case USBPD_PWR_VSAFE5V :
    275     if (_vbus >= USBPD_PWR_HIGH_VBUS_THRESHOLD) _status = USBPD_TRUE;
    276     break;
    277   case USBPD_PWR_SNKDETACH:
    278     if (_vbus < USBPD_PWR_HIGH_VBUS_THRESHOLD) _status = USBPD_TRUE;
    279     break;
    280   default :
    281     break;
     328          case USBPD_PWR_BELOWVSAFE0V :
     329                  // Here we must make sure that voltage on Vbus is lower than 750mV,
     330                  // but we do not monitor Vbus with ADC, so we just assume that voltage is Ok
     331                  _status = USBPD_TRUE;
     332                  break;
     333          case USBPD_PWR_VSAFE5V :
     334                  // Here we must make sure that voltage on Vbus is higher than 2.8V,
     335                  // but we do not monitor Vbus with ADC, so we just assume that voltage is Ok
     336                  _status = USBPD_TRUE;
     337                  break;
     338          case USBPD_PWR_SNKDETACH:
     339                  // Here we must make sure that voltage on Vbus is lower than 2.8V,
     340                  // but we do not monitor Vbus with ADC, so we just assume that voltage is Ok
     341                  _status = USBPD_TRUE;
     342                  break;
     343          default :
     344                  break;
    282345  }
    283346  return _status;
  • trunk/fw_g473rct/USBPD/App/usbpd_pwr_if.h

    r59 r65  
    217217
    218218/**
     219  * @brief  Sets the required power profile
     220  * @param  PortNum Port number
     221  * @retval USBPD status
     222  */
     223USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum);
     224
     225/**
    219226  * @brief  Checks if the power on a specified port is ready
    220227  * @param  PortNum Port number
     
    223230  */
    224231USBPD_StatusTypeDef USBPD_PWR_IF_SupplyReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe);
     232
     233/**
     234  * @brief  Enable VBUS power on a specified port
     235  * @param  PortNum Port number
     236  * @retval USBPD status
     237  */
     238USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum);
     239
     240/**
     241  * @brief  Disable VBUS power on a specified port
     242  * @param  PortNum Port number
     243  * @retval USBPD status
     244  */
     245USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum);
     246
     247/**
     248  * @brief  Checks if the power on a specified port is enabled
     249  * @param  PortNum Port number
     250  * @retval ENABLE or DISABLE
     251  */
     252USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum);
    225253
    226254/**
  • trunk/fw_g473rct/USBPD/Target/usbpd_dpm_conf.h

    r59 r65  
    6464    .PE_SupportedSOP = USBPD_SUPPORTED_SOP_SOP    , /* Supported SOP : SOP, SOP' SOP" SOP'Debug SOP"Debug */
    6565    .PE_SpecRevision = USBPD_SPECIFICATION_REV3,/* spec revision value                                     */
    66     .PE_DefaultRole = USBPD_PORTPOWERROLE_SNK,  /* Default port role                                       */
     66    .PE_DefaultRole = USBPD_PORTPOWERROLE_SRC,  /* Default port role                                       */
    6767    .PE_RoleSwap = USBPD_FALSE,                  /* support port role swap                                  */
    6868    .PE_VDMSupport = USBPD_FALSE,
     
    7272    .PE_CapscounterSupport = USBPD_FALSE,       /* support caps counter                                    */
    7373    .CAD_RoleToggle = USBPD_FALSE,               /* CAD role toggle                                         */
     74    .CAD_DefaultResistor = 0x02u,
    7475    .CAD_TryFeature = 0,              /* CAD try feature                                         */
    7576    .CAD_AccesorySupport = USBPD_FALSE,         /* CAD accessory support                                   */
     
    107108{
    108109  {
    109     .PE_DataSwap = USBPD_FALSE,                  /* support data swap                                       */
     110    .PE_DataSwap = USBPD_TRUE,                  /* support data swap                                       */
    110111    .PE_VconnSwap = USBPD_FALSE,                 /* support VCONN swap                                  */
    111     .PE_DR_Swap_To_DFP = USBPD_FALSE,                  /*  Support of DR Swap to DFP                                  */
    112     .PE_DR_Swap_To_UFP = USBPD_FALSE,                  /*  Support of DR Swap to UFP                                  */
    113      .DPM_SNKExtendedCapa =                        /*!< SNK Extended Capability        */
    114          {
    115            .VID                    = USBPD_VID,  /*!< Vendor ID (assigned by the USB-IF)                      */
    116            .PID                    = USBPD_PID,  /*!< Product ID (assigned by the manufacturer)               */
    117            .XID                    = USBPD_XID,  /*!< Value provided by the USB-IF assigned to the product    */
    118            .FW_revision            = 1,          /*!< Firmware version number                                 */
    119            .HW_revision            = 2,          /*!< Hardware version number                                 */
    120        .SKEDB_Version          = USBPD_SKEDB_VERSION_1P0,  /*!<SKEDV Version (not the specification Version)
    121                                                                based on @ref USBPD_SKEDB_VERSION          */
    122        .LoadStep               = USBPD_SKEDB_LOADSTEP_150MA,/*!< Load Step based on @ref USBPD_SKEDB_LOADSTEP */
    123        .SinkLoadCharac.b       =             /*!< Sink Load Characteristics                               */
    124         {
    125            .PercentOverload    = 0,          /*!< Percent overload in 10% increments Values higher than 25
    126                                                   (11001b) are clipped to 250%. 00000b is the default.    */
    127            .OverloadPeriod     = 0,          /*!< Overload period in 20ms when bits 0-4 non-zero          */
    128            .DutyCycle          = 0,          /*!< Duty Cycle in 5% increments when bits 0-4 are non-zero  */
    129            .VBusVoltageDrop    = 0,          /*!< Can tolerate VBUS Voltage drop                          */
    130         },
    131        .Compliance             = 0,          /*!< Compliance based on combination of @ref USBPD_SKEDB_COMPLIANCE */
    132        .Touchtemp              = USBPD_SKEDB_TOUCHTEMP_NA,  /*< Touch Temp based on @ref USBPD_SKEDB_TOUCHTEMP   */
    133        .BatteryInfo            = 0,          /*!< Battery info                                                   */
    134        .SinkModes              = 0,          /*!< Sink Modes based on combination of @ref USBPD_SKEDB_SINKMODES  */
    135        .SinkMinimumPDP        = 0,          /*!< The Minimum PDP required by the Sink to operate without
    136                                                   consuming any power from its Battery(s) should it have one     */
    137        .SinkOperationalPDP     = 0,          /*!< The PDP the Sink requires to operate normally. For Sinks with
    138                                                   a Battery, it is the PDP rating of the charger supplied with
    139                                                   it or recommended for it.                                      */
    140        .SinkMaximumPDP         = 0,          /*!< The Maximum PDP the Sink can consume to operate and
    141                                                   charge its Battery(s) should it have one                       */
    142       },
     112    .PE_DR_Swap_To_DFP = USBPD_TRUE,                  /*  Support of DR Swap to DFP                                  */
     113    .PE_DR_Swap_To_UFP = USBPD_TRUE,                  /*  Support of DR Swap to UFP                                  */
    143114#if defined(USBPD_REV30_SUPPORT)
    144115#if _MANU_INFO
  • trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.c

    r59 r65  
    3636#endif /* _TRACE */
    3737/* USER CODE BEGIN Includes */
    38 
     38#ifdef DEBUG
     39#include <stdio.h>
     40#endif
    3941/* USER CODE END Includes */
    4042
     
    182184void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State)
    183185{
    184 /* USER CODE BEGIN USBPD_DPM_UserCableDetection */
    185 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_UserCableDetection");
    186   // switch(State)
    187   // {
    188   // case USBPD_CAD_EVENT_ATTACHED:
    189   // case USBPD_CAD_EVENT_ATTEMC:
    190     // {
    191       // if (USBPD_OK != USBPD_PWR_IF_VBUSEnable(PortNum))
    192       // {
    193         // /* Should not occur */
    194         // HAL_Delay(6000);
    195         // NVIC_SystemReset();
    196       // }
    197       // break;
    198     // }
    199   // case USBPD_CAD_EVENT_DETACHED :
    200   // case USBPD_CAD_EVENT_EMC :
    201   // default :
    202     // {
    203       // if (USBPD_OK != USBPD_PWR_IF_VBUSDisable(PortNum))
    204       // {
    205         // /* Should not occur */
    206         // while(1);
    207       // }
    208       // break;
    209     // }
    210   // }
    211 /* USER CODE END USBPD_DPM_UserCableDetection */
     186        /* USER CODE BEGIN USBPD_DPM_UserCableDetection */
     187        DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_UserCableDetection");
     188        switch(State)
     189        {
     190                case USBPD_CAD_EVENT_ATTACHED:
     191                case USBPD_CAD_EVENT_ATTEMC:
     192#ifdef DEBUG
     193                        printf("Cable attached\n");
     194#endif
     195                        if (USBPD_OK != USBPD_PWR_IF_VBUSEnable(PortNum))
     196                        {
     197                                // Should not occur
     198                                while(1)
     199                                {
     200#ifdef DEBUG
     201                                        printf("ERRROR in USBPD_DPM_UserCableDetection!\n");
     202#endif
     203                                        HAL_Delay(2500U);
     204                                }
     205                        }
     206                        break;
     207
     208                case USBPD_CAD_EVENT_DETACHED:
     209                case USBPD_CAD_EVENT_EMC:
     210#ifdef DEBUG
     211                        printf("Cable disconnected\n");
     212#endif
     213                        if (USBPD_OK != USBPD_PWR_IF_VBUSDisable(PortNum))
     214                        {
     215                                // Should not occur
     216                                while(1)
     217                                {
     218#ifdef DEBUG
     219                                        printf("ERRROR!\n");
     220#endif
     221                                        HAL_Delay(2500U);
     222                                }
     223                        }
     224                        break;
     225                default:
     226                        break;
     227        }
     228        /* USER CODE END USBPD_DPM_UserCableDetection */
    212229}
    213230
     
    241258{
    242259/* USER CODE BEGIN USBPD_DPM_Notification */
    243   /* Manage event notified by the stack? */
    244   switch(EventVal)
    245   {
    246 //    case USBPD_NOTIFY_POWER_EXPLICIT_CONTRACT :
    247 //      break;
    248 //    case USBPD_NOTIFY_REQUEST_ACCEPTED:
    249 //      break;
    250 //    case USBPD_NOTIFY_REQUEST_REJECTED:
    251 //    case USBPD_NOTIFY_REQUEST_WAIT:
    252 //      break;
    253 //    case USBPD_NOTIFY_POWER_SWAP_TO_SNK_DONE:
    254 //      break;
    255 //    case USBPD_NOTIFY_STATE_SNK_READY:
    256 //      break;
    257 //    case USBPD_NOTIFY_HARDRESET_RX:
    258 //    case USBPD_NOTIFY_HARDRESET_TX:
    259 //      break;
    260 //    case USBPD_NOTIFY_STATE_SRC_DISABLED:
    261 //      break;
    262 //    case USBPD_NOTIFY_ALERT_RECEIVED :
    263 //      break;
    264 //    case USBPD_NOTIFY_CABLERESET_REQUESTED :
    265 //      break;
    266 //    case USBPD_NOTIFY_MSG_NOT_SUPPORTED :
    267 //      break;
    268 //    case USBPD_NOTIFY_PE_DISABLED :
    269 //      break;
    270 //    case USBPD_NOTIFY_USBSTACK_START:
    271 //      break;
    272 //    case USBPD_NOTIFY_USBSTACK_STOP:
    273 //      break;
    274 //    case USBPD_NOTIFY_DATAROLESWAP_DFP :
    275 //      break;
    276 //    case USBPD_NOTIFY_DATAROLESWAP_UFP :
    277 //      break;
    278     default:
    279       DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: USBPD_DPM_Notification:%d", EventVal);
    280       break;
    281   }
     260        // Manage event notified by the stack?
     261        switch(EventVal)
     262        {
     263                case USBPD_NOTIFY_POWER_EXPLICIT_CONTRACT:      break;
     264                case USBPD_NOTIFY_REQUEST_ACCEPTED:                     break;
     265                case USBPD_NOTIFY_REQUEST_REJECTED:                     break;
     266                case USBPD_NOTIFY_REQUEST_WAIT:                         break;
     267                case USBPD_NOTIFY_POWER_SWAP_TO_SNK_DONE:       break;
     268                case USBPD_NOTIFY_STATE_SNK_READY:                      break;
     269                case USBPD_NOTIFY_HARDRESET_RX:                         break;
     270                case USBPD_NOTIFY_HARDRESET_TX:                         break;
     271                case USBPD_NOTIFY_STATE_SRC_DISABLED:           break;
     272                case USBPD_NOTIFY_ALERT_RECEIVED:                       break;
     273                case USBPD_NOTIFY_CABLERESET_REQUESTED:         break;
     274                case USBPD_NOTIFY_MSG_NOT_SUPPORTED:            break;
     275                case USBPD_NOTIFY_PE_DISABLED:                          break;
     276                case USBPD_NOTIFY_USBSTACK_START:                       break;
     277                case USBPD_NOTIFY_USBSTACK_STOP:                        break;
     278                case USBPD_NOTIFY_DATAROLESWAP_DFP:                     break;
     279                case USBPD_NOTIFY_DATAROLESWAP_UFP:                     break;
     280                default:
     281                        DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: USBPD_DPM_Notification:%d", EventVal);
     282                        break;
     283        }
    282284/* USER CODE END USBPD_DPM_Notification */
    283285}
     
    295297  DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_HardReset");
    296298/* USER CODE END USBPD_DPM_HardReset */
     299}
     300
     301/**
     302  * @brief  Request the DPM to setup the new power level.
     303  * @param  PortNum The current port number
     304  * @retval USBPD status
     305  */
     306USBPD_StatusTypeDef USBPD_DPM_SetupNewPower(uint8_t PortNum)
     307{
     308/* USER CODE BEGIN USBPD_DPM_SetupNewPower */
     309  return USBPD_PWR_IF_SetProfile(PortNum);
     310/* USER CODE END USBPD_DPM_SetupNewPower */
    297311}
    298312
     
    308322{
    309323/* USER CODE BEGIN USBPD_DPM_GetDataInfo */
    310   /* Check type of information targeted by request */
    311   switch(DataId)
    312   {
    313 //  case USBPD_CORE_DATATYPE_REQ_VOLTAGE:       /*!< Get voltage value requested for BIST tests, expect 5V*/
    314 //    *Size = 4;
    315 //    (void)memcpy((uint8_t *)Ptr, (uint8_t *)&DPM_Ports[PortNum].DPM_RequestedVoltage, *Size);
    316     // break;
    317 //  case USBPD_CORE_DATATYPE_SRC_PDO:           /*!< Handling of port Source PDO                         */
    318     // break;
    319 //  case USBPD_CORE_PPS_STATUS:                 /*!< PPS Status message content                          */
    320     // break;
    321 //  case USBPD_CORE_SNK_EXTENDED_CAPA:          /*!< Retrieve of Sink Extended capability message content*/
    322     // break;
    323 //  case USBPD_CORE_INFO_STATUS:                /*!< Information status message content                  */
    324     // break;
    325 //  case USBPD_CORE_MANUFACTURER_INFO:          /*!< Retrieve of Manufacturer info message content       */
    326     // break;
    327 //  case USBPD_CORE_BATTERY_STATUS:             /*!< Retrieve of Battery status message content          */
    328     // break;
    329 //  case USBPD_CORE_BATTERY_CAPABILITY:         /*!< Retrieve of Battery capability message content      */
    330     // break;
    331   default:
    332     DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_GetDataInfo:%d", DataId);
    333     break;
    334   }
     324        // Check type of information targeted by request
     325        switch(DataId)
     326        {
     327                //case USBPD_CORE_DATATYPE_REQ_VOLTAGE:       /*!< Get voltage value requested for BIST tests, expect 5V*/
     328                        //*Size = 4;
     329                        //(void)memcpy((uint8_t *)Ptr, (uint8_t *)&DPM_Ports[PortNum].DPM_RequestedVoltage, *Size);
     330                        //break;
     331                case USBPD_CORE_DATATYPE_SRC_PDO:           /*!< Handling of port Source PDO                         */
     332                        USBPD_PWR_IF_GetPortPDOs(PortNum, DataId, Ptr, Size);
     333                        *Size *= 4;
     334                        break;
     335                //case USBPD_CORE_PPS_STATUS:                 /*!< PPS Status message content                          */
     336                        // break;
     337                //case USBPD_CORE_SNK_EXTENDED_CAPA:          /*!< Retrieve of Sink Extended capability message content*/
     338                        // break;
     339                //case USBPD_CORE_INFO_STATUS:                /*!< Information status message content                  */
     340                        // break;
     341                //case USBPD_CORE_MANUFACTURER_INFO:          /*!< Retrieve of Manufacturer info message content       */
     342                        // break;
     343                //case USBPD_CORE_BATTERY_STATUS:             /*!< Retrieve of Battery status message content          */
     344                        // break;
     345                //case USBPD_CORE_BATTERY_CAPABILITY:         /*!< Retrieve of Battery capability message content      */
     346                        // break;
     347                default:
     348                        DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_GetDataInfo:%d", DataId);
     349                        break;
     350        }
    335351/* USER CODE END USBPD_DPM_GetDataInfo */
    336352}
     
    383399
    384400/**
    385   * @brief  Evaluate received Capabilities Message from Source port and prepare the request message
    386   * @param  PortNum         Port number
    387   * @param  PtrRequestData  Pointer on selected request data object
    388   * @param  PtrPowerObjectType  Pointer on the power data object
    389   * @retval None
    390   */
    391 void USBPD_DPM_SNK_EvaluateCapabilities(uint8_t PortNum, uint32_t *PtrRequestData, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObjectType)
    392 {
    393 /* USER CODE BEGIN USBPD_DPM_SNK_EvaluateCapabilities */
    394   DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_SNK_EvaluateCapabilities");
    395 /* USER CODE END USBPD_DPM_SNK_EvaluateCapabilities */
     401  * @brief  Evaluate received Request Message from Sink port
     402  * @param  PortNum Port number
     403  * @param  PtrPowerObject  Pointer on the power data object
     404  * @retval USBPD status : USBPD_ACCEPT, USBPD_REJECT, USBPD_WAIT, USBPD_GOTOMIN
     405  */
     406USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject)
     407{
     408/* USER CODE BEGIN USBPD_DPM_EvaluateRequest */
     409  /*
     410    Set power data object to initialize value.
     411    This parameter is used by the stack to start or not tPPSTimeout
     412    (in case of USBPD_CORE_PDO_TYPE_APDO, stack will wait for periodic request
     413    from the port partner in PPS mode).
     414  */
     415  *PtrPowerObject = USBPD_CORE_PDO_TYPE_FIXED;
     416
     417  DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_EvaluateRequest");
     418  return USBPD_ACCEPT;
     419/* USER CODE END USBPD_DPM_EvaluateRequest */
    396420}
    397421
     
    827851USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapabilityExt(uint8_t PortNum)
    828852{
    829   USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SNK_CAPEXT, USBPD_SOPTYPE_SOP);
    830   DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SINK_CAPA_EXT not accepted by the stack");
    831   return _status;
     853  DPM_USER_ERROR_TRACE(PortNum, USBPD_ERROR, "GET_SINK_CAPA_EXT not accepted by the stack");
     854  return USBPD_ERROR;
    832855}
    833856
  • trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.h

    r59 r65  
    4747  uint32_t PE_DR_Swap_To_UFP                              : 1U;  /*!< If supported, DR Swap to UFP can be accepted or not by the user else directly rejected */
    4848  uint32_t Reserved1                                      :28U;  /*!< Reserved bits */
    49   USBPD_SNKPowerRequest_TypeDef DPM_SNKRequestedPower;          /*!< Requested Power by the sink board                     */
     49  uint32_t            Reserved_ReqPower[6];                       /*!< Reserved bits to match with Resquested power information            */
    5050  USBPD_MIDB_TypeDef  DPM_ManuInfoPort;                         /*!< Manufacturer information used for the port            */
    51 USBPD_SKEDB_TypeDef DPM_SNKExtendedCapa;                        /*!< SNK Extended Capability           */
    52 uint8_t             ReservedSnkCapa[3];                       /*!< Reserved bits to match with SnkCapaExt information     */
     51uint32_t          ReservedSnkCapa[6];                       /*!< Reserved bits to match with SnkCapaExt information     */
    5352  uint16_t            ReservedManu;                             /*!< Reserved bits to match with Manufacturer information            */
    5453} USBPD_USER_SettingsTypeDef;
     
    105104  */
    106105void                USBPD_DPM_Notification(uint8_t PortNum, USBPD_NotifyEventValue_TypeDef EventVal);
     106USBPD_StatusTypeDef USBPD_DPM_SetupNewPower(uint8_t PortNum);
    107107void                USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status);
    108108void                USBPD_DPM_ExtendedMessageReceived(uint8_t PortNum, USBPD_ExtendedMsg_TypeDef MsgType, uint8_t *ptrData, uint16_t DataSize);
    109109void                USBPD_DPM_GetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t *Size);
    110110void                USBPD_DPM_SetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t Size);
    111 void                USBPD_DPM_SNK_EvaluateCapabilities(uint8_t PortNum, uint32_t *PtrRequestData, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObjectType);
    112 uint32_t            USBPD_DPM_SNK_EvaluateMatchWithSRCPDO(uint8_t PortNum, uint32_t SrcPDO, uint32_t* PtrRequestedVoltage, uint32_t* PtrRequestedPower);
     111USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject);
    113112USBPD_StatusTypeDef USBPD_DPM_EvaluateVconnSwap(uint8_t PortNum);
    114113USBPD_StatusTypeDef USBPD_DPM_PE_VconnPwr(uint8_t PortNum, USBPD_FunctionalState State);
  • trunk/fw_g473rct/USBPD/Target/usbpd_pwr_user.c

    r59 r65  
    2929/* USER CODE BEGIN include */
    3030
     31#include "gpio.h"
     32
    3133/* USER CODE END include */
    3234
     
    266268  else
    267269  {
     270        HAL_GPIO_WritePin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin, GPIO_PIN_RESET);
    268271    PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSInit");
     272        /* Need to keep DISCHARGE ON as soon as not powering VBUS on MB1397 */
     273        //DISCHARGE_SET_ON();
    269274  }
    270275
     
    306311  /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOn */
    307312  /* Check if instance is valid       */
    308   int32_t ret;
    309 
    310   if (Instance >= USBPD_PWR_INSTANCES_NBR)
    311   {
    312     ret = BSP_ERROR_WRONG_PARAM;
    313   }
    314   else
    315   {
    316     ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
     313  int32_t ret = BSP_ERROR_NONE;
     314
     315  if (Instance >= USBPD_PWR_INSTANCES_NBR)
     316  {
     317    ret = BSP_ERROR_WRONG_PARAM;
     318  }
     319  else
     320  {
    317321    PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSOn");
     322        // Turning discharger off;
     323        HAL_GPIO_WritePin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin, GPIO_PIN_SET);          // Turning Power Source on;
    318324  }
    319325  return ret;
     
    332338  /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOff */
    333339  /* Check if instance is valid       */
    334   int32_t ret;
    335 
    336   if (Instance >= USBPD_PWR_INSTANCES_NBR)
    337   {
    338     ret = BSP_ERROR_WRONG_PARAM;
    339   }
    340   else
    341   {
    342     ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
     340  int32_t ret = BSP_ERROR_NONE;
     341
     342  if (Instance >= USBPD_PWR_INSTANCES_NBR)
     343  {
     344    ret = BSP_ERROR_WRONG_PARAM;
     345  }
     346  else
     347  {
    343348    PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSOff");
     349        HAL_GPIO_WritePin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin, GPIO_PIN_RESET);        // Turning Power Source off
     350        // Turning on Discharge and waiting till Vbus voltage is at low level (750mV)
    344351  }
    345352  return ret;
     
    480487  else
    481488  {
    482     ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
    483489    PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSGetVoltage");
     490        val = 5000U;
    484491  }
    485492  *pVoltage = val;
     
    712719  /* USER CODE BEGIN BSP_USBPD_PWR_VBUSIsOn */
    713720  /* Check if instance is valid       */
    714   int32_t ret;
     721  int32_t ret = BSP_ERROR_NONE;
    715722  uint8_t state = 0U;
    716723
     
    721728  else
    722729  {
    723     ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
     730    if (HAL_GPIO_ReadPin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin) == GPIO_PIN_SET)
     731                state = 1U;
    724732    PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSIsOn");
    725733  }
Note: See TracChangeset for help on using the changeset viewer.