source: trunk/fw_g473rct/USBPD/Target/usbpd_pwr_user.c@ 65

Last change on this file since 65 was 65, checked in by f.jahn, 5 weeks ago
  • USB-PD function was implemented;
  • HW parity check on RAM was activated;
  • USB Device CDC mode was activated.
File size: 24.6 KB
Line 
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file usbpd_pwr_user.c
5 * @author MCD Application Team
6 * @brief USBPD PWR user code
7 ******************************************************************************
8 * @attention
9 *
10 * Copyright (c) 2026 STMicroelectronics.
11 * All rights reserved.
12 *
13 * This software is licensed under terms that can be found in the LICENSE file
14 * in the root directory of this software component.
15 * If no LICENSE file comes with this software, it is provided AS-IS.
16 *
17 ******************************************************************************
18 */
19/* USER CODE END Header */
20
21/* Includes ------------------------------------------------------------------*/
22#include "usbpd_pwr_user.h"
23#include "stm32g4xx_hal.h"
24#if defined(_TRACE)
25#include "usbpd_core.h"
26#include "usbpd_trace.h"
27#endif /* _TRACE */
28
29/* USER CODE BEGIN include */
30
31#include "gpio.h"
32
33/* USER CODE END include */
34
35/** @addtogroup BSP
36 * @{
37 */
38
39/** @addtogroup POWER
40 * @{
41 */
42/** @defgroup POWER_Private_Typedef Private Typedef
43 * @{
44 */
45/* USER CODE BEGIN POWER_Private_Typedef */
46
47/* USER CODE END POWER_Private_Typedef */
48/**
49 * @}
50 */
51
52/** @defgroup POWER_Private_Constants Private Constants
53* @{
54*/
55/* USER CODE BEGIN POWER_Private_Constants */
56
57/* USER CODE END POWER_Private_Constants */
58/**
59 * @}
60 */
61
62/** @defgroup POWER_Private_Macros Private Macros
63 * @{
64 */
65#if defined(_TRACE)
66#define PWR_DEBUG_TRACE(_PORT_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (_PORT_), 0u, (uint8_t*)(__MESSAGE__), sizeof(__MESSAGE__) - 1u)
67#else
68#define PWR_DEBUG_TRACE(_PORT_, __MESSAGE__)
69#endif /* _TRACE */
70/* USER CODE BEGIN POWER_Private_Macros */
71
72/* USER CODE END POWER_Private_Macros */
73/**
74 * @}
75 */
76
77/** @defgroup POWER_Private_Variables Private Variables
78 * @{
79 */
80/* USER CODE BEGIN POWER_Private_Variables */
81
82/* USER CODE END POWER_Private_Variables */
83/**
84 * @}
85 */
86
87/** @defgroup POWER_Private_Functions Private Functions
88 * @{
89 */
90/* USER CODE BEGIN POWER_Private_Prototypes */
91
92/* USER CODE END POWER_Private_Prototypes */
93/**
94 * @}
95 */
96
97/** @defgroup POWER_Exported_Variables Exported Variables
98 * @{
99 */
100/* USER CODE BEGIN POWER_Exported_Variables */
101
102/* USER CODE END POWER_Exported_Variables */
103/**
104 * @}
105 */
106
107/** @addtogroup POWER_Exported_Functions
108 * @{
109 */
110/**
111 * @brief Global initialization of PWR resource used by USB-PD
112 * @param Instance Type-C port identifier
113 * This parameter can be take one of the following values:
114 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
115 * @retval BSP status
116 */
117__weak int32_t BSP_USBPD_PWR_Init(uint32_t Instance)
118{
119 /* USER CODE BEGIN BSP_USBPD_PWR_Init */
120 /* Check if instance is valid */
121 int32_t ret = BSP_ERROR_NONE;
122
123 if (Instance >= USBPD_PWR_INSTANCES_NBR)
124 {
125 ret = BSP_ERROR_WRONG_PARAM;
126 }
127 return ret;
128 /* USER CODE END BSP_USBPD_PWR_Init */
129}
130
131/**
132 * @brief Global de-initialization of PWR resource used by USB-PD
133 * @param Instance Type-C port identifier
134 * This parameter can be take one of the following values:
135 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
136 * @retval BSP status
137 */
138__weak int32_t BSP_USBPD_PWR_Deinit(uint32_t Instance)
139{
140 /* USER CODE BEGIN BSP_USBPD_PWR_Deinit */
141 /* Check if instance is valid */
142 int32_t ret = BSP_ERROR_NONE;
143
144 if (Instance >= USBPD_PWR_INSTANCES_NBR)
145 {
146 ret = BSP_ERROR_WRONG_PARAM;
147 }
148 else
149 {
150 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_Deinit");
151 }
152
153 return ret;
154 /* USER CODE END BSP_USBPD_PWR_Deinit */
155}
156
157/**
158 * @brief Assign Power role for current Port (Source or Sink)
159 * @param Instance Type-C port identifier
160 * This parameter can be take one of the following values:
161 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
162 * @param Role Type-C port role
163 * This parameter can be take one of the following values:
164 * @arg @ref POWER_ROLE_SOURCE
165 * @arg @ref POWER_ROLE_SINK
166 * @retval BSP status
167 */
168__weak int32_t BSP_USBPD_PWR_SetRole(uint32_t Instance, USBPD_PWR_PowerRoleTypeDef Role)
169{
170 /* USER CODE BEGIN BSP_USBPD_PWR_SetRole */
171 /* Check if instance is valid */
172 int32_t ret = BSP_ERROR_NONE;
173
174 if (Instance >= USBPD_PWR_INSTANCES_NBR)
175 {
176 ret = BSP_ERROR_WRONG_PARAM;
177 }
178 else
179 {
180 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_SetRole");
181 }
182
183 return ret;
184 /* USER CODE END BSP_USBPD_PWR_SetRole */
185}
186
187/**
188 * @brief Set operating mode of Port regarding power saving constraints
189 * @param Instance Type-C port identifier
190 * This parameter can be take one of the following values:
191 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
192 * @param PwrMode Type-C port power saving mode
193 * This parameter can be take one of the following values:
194 * @arg @ref USBPD_PWR_MODE_OFF
195 * @arg @ref USBPD_PWR_MODE_HIBERNATE
196 * @arg @ref USBPD_PWR_MODE_LOWPOWER
197 * @arg @ref USBPD_PWR_MODE_NORMAL
198 * @retval BSP status
199 */
200__weak int32_t BSP_USBPD_PWR_SetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef PwrMode)
201{
202 /* USER CODE BEGIN BSP_USBPD_PWR_SetPowerMode */
203 /* Check if instance is valid */
204 int32_t ret = BSP_ERROR_NONE;
205
206 if (Instance >= USBPD_PWR_INSTANCES_NBR)
207 {
208 ret = BSP_ERROR_WRONG_PARAM;
209 }
210 else
211 {
212 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_SetPowerMode");
213 }
214
215 return ret;
216 /* USER CODE END BSP_USBPD_PWR_SetPowerMode */
217}
218
219/**
220 * @brief Get operating mode of Port regarding power saving constraints
221 * @param Instance Type-C port identifier
222 * This parameter can be take one of the following values:
223 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
224 * @param PwrMode Pointer on current Type-C port power saving mode value
225 * Following values are available :
226 * @arg @ref USBPD_PWR_MODE_OFF
227 * @arg @ref USBPD_PWR_MODE_HIBERNATE
228 * @arg @ref USBPD_PWR_MODE_LOWPOWER
229 * @arg @ref USBPD_PWR_MODE_NORMAL
230 * @retval BSP status
231 */
232__weak int32_t BSP_USBPD_PWR_GetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef *PwrMode)
233{
234 /* USER CODE BEGIN BSP_USBPD_PWR_GetPowerMode */
235 /* Check if instance is valid */
236 int32_t ret = BSP_ERROR_NONE;
237
238 if (Instance >= USBPD_PWR_INSTANCES_NBR)
239 {
240 ret = BSP_ERROR_WRONG_PARAM;
241 }
242 else
243 {
244 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_GetPowerMode");
245 }
246 return ret;
247 /* USER CODE END BSP_USBPD_PWR_GetPowerMode */
248}
249
250/**
251 * @brief Initialize the hardware resources used by the Type-C power delivery (PD)
252 * controller.
253 * @param Instance Type-C port identifier
254 * This parameter can be take one of the following values:
255 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
256 * @retval BSP status
257 */
258__weak int32_t BSP_USBPD_PWR_VBUSInit(uint32_t Instance)
259{
260 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSInit */
261 /* Check if instance is valid */
262 int32_t ret = BSP_ERROR_NONE;
263
264 if (Instance >= USBPD_PWR_INSTANCES_NBR)
265 {
266 ret = BSP_ERROR_WRONG_PARAM;
267 }
268 else
269 {
270 HAL_GPIO_WritePin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin, GPIO_PIN_RESET);
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();
274 }
275
276 return ret;
277 /* USER CODE END BSP_USBPD_PWR_VBUSInit */
278}
279
280/**
281 * @brief Release the hardware resources used by the Type-C power delivery (PD)
282 * controller.
283 * @param Instance Type-C port identifier
284 * This parameter can be take one of the following values:
285 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
286 * @retval BSP status
287 */
288__weak int32_t BSP_USBPD_PWR_VBUSDeInit(uint32_t Instance)
289{
290 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSDeInit */
291 /* Check if instance is valid */
292 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
293
294 if (Instance >= USBPD_PWR_INSTANCES_NBR)
295 {
296 ret = BSP_ERROR_WRONG_PARAM;
297 }
298 return ret;
299 /* USER CODE END BSP_USBPD_PWR_VBUSDeInit */
300}
301
302/**
303 * @brief Enable power supply over VBUS.
304 * @param Instance Type-C port identifier
305 * This parameter can be take one of the following values:
306 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
307 * @retval BSP status
308 */
309__weak int32_t BSP_USBPD_PWR_VBUSOn(uint32_t Instance)
310{
311 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOn */
312 /* Check if instance is valid */
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 {
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;
324 }
325 return ret;
326 /* USER CODE END BSP_USBPD_PWR_VBUSOn */
327}
328
329/**
330 * @brief Disable power supply over VBUS.
331 * @param Instance Type-C port identifier
332 * This parameter can be take one of the following values:
333 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
334 * @retval BSP status
335 */
336__weak int32_t BSP_USBPD_PWR_VBUSOff(uint32_t Instance)
337{
338 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOff */
339 /* Check if instance is valid */
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 {
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)
351 }
352 return ret;
353 /* USER CODE END BSP_USBPD_PWR_VBUSOff */
354}
355
356/**
357 * @brief Set a fixed/variable PDO and manage the power control.
358 * @param Instance Type-C port identifier
359 * This parameter can be take one of the following values:
360 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
361 * @param VbusTargetInmv the vbus Target (in mV)
362 * @param OperatingCurrent the Operating Current (in mA)
363 * @param MaxOperatingCurrent the Max Operating Current (in mA)
364 * @retval BSP status
365 */
366__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Fixed(uint32_t Instance,
367 uint32_t VbusTargetInmv,
368 uint32_t OperatingCurrent,
369 uint32_t MaxOperatingCurrent)
370{
371 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Fixed */
372 /* Check if instance is valid */
373 int32_t ret = BSP_ERROR_NONE;
374
375 if (Instance >= USBPD_PWR_INSTANCES_NBR)
376 {
377 ret = BSP_ERROR_WRONG_PARAM;
378 }
379 return ret;
380 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Fixed */
381}
382
383/**
384 * @brief Set a fixed/variable PDO and manage the power control.
385 * @param Instance Type-C port identifier
386 * This parameter can be take one of the following values:
387 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
388 * @param VbusTargetMinInmv the vbus Target min (in mV)
389 * @param VbusTargetMaxInmv the vbus Target max (in mV)
390 * @param OperatingCurrent the Operating Current (in mA)
391 * @param MaxOperatingCurrent the Max Operating Current (in mA)
392 * @retval BSP status
393 */
394__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Variable(uint32_t Instance,
395 uint32_t VbusTargetMinInmv,
396 uint32_t VbusTargetMaxInmv,
397 uint32_t OperatingCurrent,
398 uint32_t MaxOperatingCurrent)
399{
400 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Variable */
401 /* Check if instance is valid */
402 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
403
404 if (Instance >= USBPD_PWR_INSTANCES_NBR)
405 {
406 ret = BSP_ERROR_WRONG_PARAM;
407 }
408 return ret;
409 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Variable */
410}
411
412/**
413 * @brief Set a Battery PDO and manage the power control.
414 * @param Instance Type-C port identifier
415 * This parameter can be take one of the following values:
416 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
417 * @param VbusTargetMin the vbus Target min (in mV)
418 * @param VbusTargetMax the vbus Target max (in mV)
419 * @param OperatingPower the Operating Power (in mW)
420 * @param MaxOperatingPower the Max Operating Power (in mW)
421 * @retval BSP status
422 */
423__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Battery(uint32_t Instance,
424 uint32_t VbusTargetMin,
425 uint32_t VbusTargetMax,
426 uint32_t OperatingPower,
427 uint32_t MaxOperatingPower)
428{
429 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Battery */
430 /* Check if instance is valid */
431 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
432
433 if (Instance >= USBPD_PWR_INSTANCES_NBR)
434 {
435 ret = BSP_ERROR_WRONG_PARAM;
436 }
437 return ret;
438 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Battery */
439}
440
441/**
442 * @brief Set a APDO and manage the power control.
443 * @param Instance Type-C port identifier
444 * This parameter can be take one of the following values:
445 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
446 * @param VbusTargetInmv the vbus Target (in mV)
447 * @param OperatingCurrent the Operating current (in mA)
448 * @param Delta Delta between with previous APDO (in mV), 0 means APDO start
449 * @retval BSP status
450 */
451__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_APDO(uint32_t Instance,
452 uint32_t VbusTargetInmv,
453 uint32_t OperatingCurrent,
454 int32_t Delta)
455{
456 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_APDO */
457 /* Check if instance is valid */
458 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
459
460 if (Instance >= USBPD_PWR_INSTANCES_NBR)
461 {
462 ret = BSP_ERROR_WRONG_PARAM;
463 }
464 return ret;
465 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_APDO */
466}
467
468/**
469 * @brief Get actual voltage level measured on the VBUS line.
470 * @param Instance Type-C port identifier
471 * This parameter can be take one of the following values:
472 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
473 * @param pVoltage Pointer on measured voltage level (in mV)
474 * @retval BSP status
475 */
476__weak int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t Instance, uint32_t *pVoltage)
477{
478 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetVoltage */
479 /* Check if instance is valid */
480 int32_t ret;
481 uint32_t val = 0U;
482
483 if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pVoltage))
484 {
485 ret = BSP_ERROR_WRONG_PARAM;
486 }
487 else
488 {
489 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSGetVoltage");
490 val = 5000U;
491 }
492 *pVoltage = val;
493 return ret;
494 /* USER CODE END BSP_USBPD_PWR_VBUSGetVoltage */
495}
496
497/**
498 * @brief Get actual current level measured on the VBUS line.
499 * @param Instance Type-C port identifier
500 * This parameter can be take one of the following values:
501 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
502 * @param pCurrent Pointer on measured current level (in mA)
503 * @retval BSP status
504 */
505__weak int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t Instance, int32_t *pCurrent)
506{
507 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetCurrent */
508 /* Check if instance is valid */
509 int32_t ret;
510
511 if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pCurrent))
512 {
513 ret = BSP_ERROR_WRONG_PARAM;
514 }
515 else
516 {
517 *pCurrent = 0;
518 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
519 }
520 return ret;
521 /* USER CODE END BSP_USBPD_PWR_VBUSGetCurrent */
522}
523
524/**
525 * @brief Initialize VCONN sourcing.
526 * @param Instance Type-C port identifier
527 * This parameter can be take one of the following values:
528 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
529 * @param CCPinId Type-C CC pin identifier
530 * This parameter can be take one of the following values:
531 * @arg @ref USBPD_PWR_TYPE_C_CC1
532 * @arg @ref USBPD_PWR_TYPE_C_CC2
533 * @retval BSP status
534 */
535__weak int32_t BSP_USBPD_PWR_VCONNInit(uint32_t Instance,
536 uint32_t CCPinId)
537{
538 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNInit */
539 /* Check if instance is valid */
540 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
541
542 if (Instance >= USBPD_PWR_INSTANCES_NBR)
543 {
544 ret = BSP_ERROR_WRONG_PARAM;
545 }
546 return ret;
547 /* USER CODE END BSP_USBPD_PWR_VCONNInit */
548}
549
550/**
551 * @brief Un-Initialize VCONN sourcing.
552 * @param Instance Type-C port identifier
553 * This parameter can be take one of the following values:
554 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
555 * @param CCPinId Type-C CC pin identifier
556 * This parameter can be take one of the following values:
557 * @arg @ref USBPD_PWR_TYPE_C_CC1
558 * @arg @ref USBPD_PWR_TYPE_C_CC2
559 * @retval BSP status
560 */
561__weak int32_t BSP_USBPD_PWR_VCONNDeInit(uint32_t Instance,
562 uint32_t CCPinId)
563{
564 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNDeInit */
565 /* Check if instance is valid */
566 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
567
568 if (Instance >= USBPD_PWR_INSTANCES_NBR)
569 {
570 ret = BSP_ERROR_WRONG_PARAM;
571 }
572 return ret;
573 /* USER CODE END BSP_USBPD_PWR_VCONNDeInit */
574}
575
576/**
577 * @brief Enable VCONN sourcing.
578 * @param Instance Type-C port identifier
579 * This parameter can be take one of the following values:
580 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
581 * @param CCPinId Type-C CC pin identifier
582 * This parameter can be take one of the following values:
583 * @arg @ref USBPD_PWR_TYPE_C_CC1
584 * @arg @ref USBPD_PWR_TYPE_C_CC2
585 * @retval BSP status
586 */
587__weak int32_t BSP_USBPD_PWR_VCONNOn(uint32_t Instance,
588 uint32_t CCPinId)
589{
590 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNOn */
591 /* Check if instance is valid */
592 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
593
594 if (Instance >= USBPD_PWR_INSTANCES_NBR)
595 {
596 ret = BSP_ERROR_WRONG_PARAM;
597 }
598 return ret;
599 /* USER CODE END BSP_USBPD_PWR_VCONNOn */
600}
601
602/**
603 * @brief Disable VCONN sourcing.
604 * @param Instance Type-C port identifier
605 * This parameter can be take one of the following values:
606 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
607 * @param CCPinId CC pin identifier
608 * This parameter can be take one of the following values:
609 * @arg @ref USBPD_PWR_TYPE_C_CC1
610 * @arg @ref USBPD_PWR_TYPE_C_CC2
611 * @retval BSP status
612 */
613__weak int32_t BSP_USBPD_PWR_VCONNOff(uint32_t Instance,
614 uint32_t CCPinId)
615{
616 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNOff */
617 /* Check if instance is valid */
618 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
619
620 if (Instance >= USBPD_PWR_INSTANCES_NBR)
621 {
622 ret = BSP_ERROR_WRONG_PARAM;
623 }
624 return ret;
625 /* USER CODE END BSP_USBPD_PWR_VCONNOff */
626}
627
628/**
629 * @brief Get actual VCONN status.
630 * @param Instance Type-C port identifier
631 * This parameter can be take one of the following values:
632 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
633 * @param CCPinId Type-C CC pin identifier
634 * This parameter can be take one of the following values:
635 * @arg @ref USBPD_PWR_TYPE_C_CC1
636 * @arg @ref USBPD_PWR_TYPE_C_CC2
637 * @param pState VCONN status (1: On, 0: Off)
638 * @retval BSP status
639 */
640__weak int32_t BSP_USBPD_PWR_VCONNIsOn(uint32_t Instance,
641 uint32_t CCPinId, uint8_t *pState)
642{
643 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNIsOn */
644 /* Check if instance is valid */
645 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
646
647 if (Instance >= USBPD_PWR_INSTANCES_NBR)
648 {
649 ret = BSP_ERROR_WRONG_PARAM;
650 }
651 *pState = 0u;
652 return ret;
653 /* USER CODE END BSP_USBPD_PWR_VCONNIsOn */
654}
655
656/**
657 * @brief Set the VBUS disconnection voltage threshold.
658 * @note Callback function registered through BSP_USBPD_PWR_RegisterVBUSDetectCallback
659 * function call is invoked when VBUS falls below programmed threshold.
660 * @note By default VBUS disconnection threshold is set to 3.3V
661 * @param Instance Type-C port identifier
662 * This parameter can be take one of the following values:
663 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
664 * @param VoltageThreshold VBUS disconnection voltage threshold (in mV)
665 * @retval BSP status
666 */
667__weak int32_t BSP_USBPD_PWR_SetVBUSDisconnectionThreshold(uint32_t Instance,
668 uint32_t VoltageThreshold)
669{
670 /* USER CODE BEGIN BSP_USBPD_PWR_SetVBUSDisconnectionThreshold */
671 /* Check if instance is valid */
672 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
673
674 if (Instance >= USBPD_PWR_INSTANCES_NBR)
675 {
676 ret = BSP_ERROR_WRONG_PARAM;
677 }
678 return ret;
679 /* USER CODE END BSP_USBPD_PWR_SetVBUSDisconnectionThreshold */
680}
681
682/**
683 * @brief Register USB Type-C Current callback function.
684 * @note Callback function invoked when VBUS rises above 4V (VBUS present) or
685 * when VBUS falls below programmed threshold (VBUS absent).
686 * @note Callback function is un-registered when callback function pointer
687 * argument is NULL.
688 * @param Instance Type-C port identifier
689 * This parameter can be take one of the following values:
690 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
691 * @param pfnVBUSDetectCallback callback function pointer
692 * @retval BSP status
693 */
694__weak int32_t BSP_USBPD_PWR_RegisterVBUSDetectCallback(uint32_t Instance,
695 USBPD_PWR_VBUSDetectCallbackFunc *pfnVBUSDetectCallback)
696{
697 /* USER CODE BEGIN BSP_USBPD_PWR_RegisterVBUSDetectCallback */
698 /* Check if instance is valid */
699 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
700
701 if (Instance >= USBPD_PWR_INSTANCES_NBR)
702 {
703 ret = BSP_ERROR_WRONG_PARAM;
704 }
705 return ret;
706 /* USER CODE END BSP_USBPD_PWR_RegisterVBUSDetectCallback */
707}
708
709/**
710 * @brief Get actual VBUS status.
711 * @param Instance Type-C port identifier
712 * This parameter can be take one of the following values:
713 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
714 * @param pState VBUS status (1: On, 0: Off)
715 * @retval BSP status
716 */
717__weak int32_t BSP_USBPD_PWR_VBUSIsOn(uint32_t Instance, uint8_t *pState)
718{
719 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSIsOn */
720 /* Check if instance is valid */
721 int32_t ret = BSP_ERROR_NONE;
722 uint8_t state = 0U;
723
724 if (Instance >= USBPD_PWR_INSTANCES_NBR)
725 {
726 ret = BSP_ERROR_WRONG_PARAM;
727 }
728 else
729 {
730 if (HAL_GPIO_ReadPin(UCPD1_VBUS_GPIO_Port, UCPD1_VBUS_Pin) == GPIO_PIN_SET)
731 state = 1U;
732 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSIsOn");
733 }
734 *pState = state;
735 return ret;
736 /* USER CODE END BSP_USBPD_PWR_VBUSIsOn */
737}
738
739/**
740 * @brief Set state of VCC (specific functions)
741 * @param Instance Type-C port identifier
742 * This parameter can be take one of the following values:
743 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
744 * @param State VCC state
745 * @retval BSP status
746 */
747__weak int32_t BSP_USBPD_PWR_VCCSetState(uint32_t Instance, uint32_t State)
748{
749 /* USER CODE BEGIN BSP_USBPD_PWR_VCCSetState */
750 /* Check if instance is valid */
751 int32_t ret = BSP_ERROR_NONE;
752
753 if (Instance >= USBPD_PWR_INSTANCES_NBR)
754 {
755 ret = BSP_ERROR_WRONG_PARAM;
756 }
757 else
758 {
759 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
760 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VCCSetState");
761 }
762 return ret;
763 /* USER CODE END BSP_USBPD_PWR_VCCSetState */
764}
765
766/**
767 * @brief USBPD PWR callback used to notify a asynchronous PWR event.
768 * (This callback caould be called fromp an IT routine, associated to
769 * any PWR related event detection mechanism)
770 * @param Instance Type-C port identifier
771 * This parameter can be take one of the following values:
772 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
773 * @retval None
774 */
775__weak void BSP_USBPD_PWR_EventCallback(uint32_t Instance)
776{
777 /* USER CODE BEGIN BSP_USBPD_PWR_EventCallback */
778 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_EventCallback");
779 /* USER CODE END BSP_USBPD_PWR_EventCallback */
780}
781
782/**
783 * @}
784 */
785
786/** @addtogroup POWER_Private_Functions
787 * @{
788 */
789
790/* USER CODE BEGIN POWER_Private_Functions */
791
792/* USER CODE END POWER_Private_Functions */
793
794/**
795 * @}
796 */
797
798/**
799 * @}
800 */
801
802/**
803 * @}
804 */
805
806/**
807 * @}
808 */
809
Note: See TracBrowser for help on using the repository browser.