Changeset 65 for trunk/fw_g473rct/USBPD/Target
- Timestamp:
- Apr 2, 2026, 3:56:21 PM (5 weeks ago)
- Location:
- trunk/fw_g473rct/USBPD/Target
- Files:
-
- 4 edited
-
usbpd_dpm_conf.h (modified) (3 diffs)
-
usbpd_dpm_user.c (modified) (7 diffs)
-
usbpd_dpm_user.h (modified) (2 diffs)
-
usbpd_pwr_user.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/USBPD/Target/usbpd_dpm_conf.h
r59 r65 64 64 .PE_SupportedSOP = USBPD_SUPPORTED_SOP_SOP , /* Supported SOP : SOP, SOP' SOP" SOP'Debug SOP"Debug */ 65 65 .PE_SpecRevision = USBPD_SPECIFICATION_REV3,/* spec revision value */ 66 .PE_DefaultRole = USBPD_PORTPOWERROLE_S NK, /* Default port role */66 .PE_DefaultRole = USBPD_PORTPOWERROLE_SRC, /* Default port role */ 67 67 .PE_RoleSwap = USBPD_FALSE, /* support port role swap */ 68 68 .PE_VDMSupport = USBPD_FALSE, … … 72 72 .PE_CapscounterSupport = USBPD_FALSE, /* support caps counter */ 73 73 .CAD_RoleToggle = USBPD_FALSE, /* CAD role toggle */ 74 .CAD_DefaultResistor = 0x02u, 74 75 .CAD_TryFeature = 0, /* CAD try feature */ 75 76 .CAD_AccesorySupport = USBPD_FALSE, /* CAD accessory support */ … … 107 108 { 108 109 { 109 .PE_DataSwap = USBPD_ FALSE, /* support data swap */110 .PE_DataSwap = USBPD_TRUE, /* support data swap */ 110 111 .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 */ 143 114 #if defined(USBPD_REV30_SUPPORT) 144 115 #if _MANU_INFO -
trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.c
r59 r65 36 36 #endif /* _TRACE */ 37 37 /* USER CODE BEGIN Includes */ 38 38 #ifdef DEBUG 39 #include <stdio.h> 40 #endif 39 41 /* USER CODE END Includes */ 40 42 … … 182 184 void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State) 183 185 { 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 */ 212 229 } 213 230 … … 241 258 { 242 259 /* 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 } 282 284 /* USER CODE END USBPD_DPM_Notification */ 283 285 } … … 295 297 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_HardReset"); 296 298 /* 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 */ 306 USBPD_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 */ 297 311 } 298 312 … … 308 322 { 309 323 /* 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 } 335 351 /* USER CODE END USBPD_DPM_GetDataInfo */ 336 352 } … … 383 399 384 400 /** 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 */ 406 USBPD_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 */ 396 420 } 397 421 … … 827 851 USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapabilityExt(uint8_t PortNum) 828 852 { 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; 832 855 } 833 856 -
trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.h
r59 r65 47 47 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 */ 48 48 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 */ 50 50 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 */ 51 uint32_t ReservedSnkCapa[6]; /*!< Reserved bits to match with SnkCapaExt information */ 53 52 uint16_t ReservedManu; /*!< Reserved bits to match with Manufacturer information */ 54 53 } USBPD_USER_SettingsTypeDef; … … 105 104 */ 106 105 void USBPD_DPM_Notification(uint8_t PortNum, USBPD_NotifyEventValue_TypeDef EventVal); 106 USBPD_StatusTypeDef USBPD_DPM_SetupNewPower(uint8_t PortNum); 107 107 void USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status); 108 108 void USBPD_DPM_ExtendedMessageReceived(uint8_t PortNum, USBPD_ExtendedMsg_TypeDef MsgType, uint8_t *ptrData, uint16_t DataSize); 109 109 void USBPD_DPM_GetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t *Size); 110 110 void 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); 111 USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject); 113 112 USBPD_StatusTypeDef USBPD_DPM_EvaluateVconnSwap(uint8_t PortNum); 114 113 USBPD_StatusTypeDef USBPD_DPM_PE_VconnPwr(uint8_t PortNum, USBPD_FunctionalState State); -
trunk/fw_g473rct/USBPD/Target/usbpd_pwr_user.c
r59 r65 29 29 /* USER CODE BEGIN include */ 30 30 31 #include "gpio.h" 32 31 33 /* USER CODE END include */ 32 34 … … 266 268 else 267 269 { 270 HAL_GPIO_WritePin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin, GPIO_PIN_RESET); 268 271 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(); 269 274 } 270 275 … … 306 311 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOn */ 307 312 /* 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 { 317 321 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; 318 324 } 319 325 return ret; … … 332 338 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOff */ 333 339 /* 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 { 343 348 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) 344 351 } 345 352 return ret; … … 480 487 else 481 488 { 482 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;483 489 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSGetVoltage"); 490 val = 5000U; 484 491 } 485 492 *pVoltage = val; … … 712 719 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSIsOn */ 713 720 /* Check if instance is valid */ 714 int32_t ret ;721 int32_t ret = BSP_ERROR_NONE; 715 722 uint8_t state = 0U; 716 723 … … 721 728 else 722 729 { 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; 724 732 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSIsOn"); 725 733 }
Note:
See TracChangeset
for help on using the changeset viewer.
