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/App
Files:
4 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/**
Note: See TracChangeset for help on using the changeset viewer.