-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstm32u5xx_nucleo_usbpd_pwr.c
857 lines (767 loc) · 22.3 KB
/
stm32u5xx_nucleo_usbpd_pwr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
/**
******************************************************************************
* @file stm32u5xx_nucleo_usbpd_pwr.c
* @author MCD Application Team
* @brief This file provides a set of firmware functions to manage
* USB-PD Power on a STM32U5xx-Nucleo Kit:
* - VBUS control
* - VBUS voltage/current measurement
* - VCONN control
* - VBUS presence detection
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32u5xx_nucleo_usbpd_pwr.h"
#include "stm32u5xx_ll_adc.h"
#include "stm32u5xx_ll_bus.h"
#include "stm32u5xx_ll_gpio.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32U5XX_NUCLEO
* @{
*/
/** @addtogroup STM32U5XX_NUCLEO_USBPD_PWR USBPD PWR
* @{
*/
/** @defgroup STM32U5XX_NUCLEO_USBPD_PWR_Private_Typedef USBPD PWR Private Typedef
* @{
*/
/**
* @}
*/
/** @defgroup STM32U5XX_NUCLEO_USBPD_PWR_Private_Constants USBPD PWR Private Constants
* @{
*/
#define VDDA_APPLI 3300U
/**
* @}
*/
/** @defgroup STM32U5XX_NUCLEO_USBPD_PWR_Private_Macros USBPD PWR Private Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32U5XX_NUCLEO_USBPD_PWR_Private_Variables USBPD PWR Private Variables
* @{
*/
/**
* @}
*/
/** @defgroup STM32U5XX_NUCLEO_USBPD_PWR_Private_Functions USBPD PWR Private Functions
* @{
*/
static void MX_ADC1_Init(void);
/**
* @}
*/
/** @addtogroup STM32U5XX_NUCLEO_USBPD_PWR_Exported_Functions USBPD PWR Exported Functions
* @{
*/
/**
* @brief Global initialization of PWR resource used by USB-PD
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_Init(uint32_t PortNum)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Disable DB management on TCPP01 */
GPIO_TCPP01_DB_CLK_ENABLE();
LL_GPIO_SetPinMode(GPIO_TCPP01_DB_PORT, GPIO_TCPP01_DB_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinSpeed(GPIO_TCPP01_DB_PORT, GPIO_TCPP01_DB_PIN, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIO_TCPP01_DB_PORT, GPIO_TCPP01_DB_PIN, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIO_TCPP01_DB_PORT, GPIO_TCPP01_DB_PIN, LL_GPIO_PULL_UP);
LL_GPIO_SetOutputPin(GPIO_TCPP01_DB_PORT, GPIO_TCPP01_DB_PIN);
}
return ret;
}
/**
* @brief Global de-initialization of PWR resource used by USB-PD
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_Deinit(uint32_t PortNum)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Nothing to do */
}
return ret;
}
/**
* @brief Initialize the hardware resources used by the Type-C power delivery (PD)
* controller.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSInit(uint32_t PortNum)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Initialize VBUS sensing ADC */
MX_ADC1_Init();
LL_ADC_REG_StartConversion(VSENSE_ADC_INSTANCE);
}
return ret;
}
/**
* @brief Release the hardware resources used by the Type-C power delivery (PD)
* controller.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSDeInit(uint32_t PortNum)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (LL_ADC_REG_IsConversionOngoing(VSENSE_ADC_INSTANCE) != 0UL)
{
LL_ADC_REG_StopConversion(VSENSE_ADC_INSTANCE);
}
/* Disable ADC */
if (LL_ADC_IsEnabled(VSENSE_ADC_INSTANCE) == 1UL)
{
LL_ADC_Disable(VSENSE_ADC_INSTANCE);
}
/* Reset ADC configuration */
VSENSE_ADC_DISABLE_CLOCK();
}
return ret;
}
/**
* @brief Enable power supply over VBUS.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSOn(uint32_t PortNum)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Disable power supply over VBUS.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSOff(uint32_t PortNum)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Get actual VBUS status.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param pState VBUS status (1: On, 0: Off)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSIsOn(uint32_t PortNum, uint8_t *pState)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
*pState = 0u;
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Set a fixed/variable PDO and manage the power control.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param VbusTargetInmv the vbus Target (in mV)
* @param OperatingCurrent the Operating Current (in mA)
* @param MaxOperatingCurrent the Max Operating Current (in mA)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSSetVoltage_Fixed(uint32_t PortNum,
uint32_t VbusTargetInmv,
uint32_t OperatingCurrent,
uint32_t MaxOperatingCurrent)
{
int32_t ret = BSP_ERROR_NONE;
UNUSED(MaxOperatingCurrent);
UNUSED(OperatingCurrent);
UNUSED(VbusTargetInmv);
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
return ret;
}
/**
* @brief Set a fixed/variable PDO and manage the power control.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param VbusTargetMinInmv the vbus Target min (in mV)
* @param VbusTargetMaxInmv the vbus Target max (in mV)
* @param OperatingCurrent the Operating Current (in mA)
* @param MaxOperatingCurrent the Max Operating Current (in mA)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSSetVoltage_Variable(uint32_t PortNum,
uint32_t VbusTargetMinInmv,
uint32_t VbusTargetMaxInmv,
uint32_t OperatingCurrent,
uint32_t MaxOperatingCurrent)
{
int32_t ret;
UNUSED(MaxOperatingCurrent);
UNUSED(OperatingCurrent);
UNUSED(VbusTargetMaxInmv);
UNUSED(VbusTargetMinInmv);
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Set a Battery PDO and manage the power control.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param VbusTargetMin the vbus Target min (in mV)
* @param VbusTargetMax the vbus Target max (in mV)
* @param OperatingPower the Operating Power (in mW)
* @param MaxOperatingPower the Max Operating Power (in mW)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSSetVoltage_Battery(uint32_t PortNum,
uint32_t VbusTargetMin,
uint32_t VbusTargetMax,
uint32_t OperatingPower,
uint32_t MaxOperatingPower)
{
int32_t ret;
UNUSED(OperatingPower);
UNUSED(VbusTargetMax);
UNUSED(VbusTargetMin);
UNUSED(MaxOperatingPower);
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Set the power, the precision must be at 5% */
/* Set the current limitation */
/* not implemented */
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Set a APDO and manage the power control.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param VbusTargetInmv the vbus Target (in mV)
* @param OperatingCurrent the Operating current (in mA)
* @param Delta Delta between with previous APDO (in mV), 0 means APDO start
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSSetVoltage_APDO(uint32_t PortNum,
uint32_t VbusTargetInmv,
uint32_t OperatingCurrent,
int32_t Delta)
{
int32_t ret;
UNUSED(Delta);
UNUSED(OperatingCurrent);
UNUSED(VbusTargetInmv);
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Set the VBUS disconnection voltage threshold.
* @note Callback function registered through BSP_USBPD_PWR_RegisterVBUSDetectCallback
* function call is invoked when VBUS falls below programmed threshold.
* @note By default VBUS disconnection threshold is set to 3.3V
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param VoltageThreshold VBUS disconnection voltage threshold (in mV)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_SetVBUSDisconnectionThreshold(uint32_t PortNum,
uint32_t VoltageThreshold)
{
UNUSED(VoltageThreshold);
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Register USB Type-C Current callback function.
* @note Callback function invoked when VBUS rises above 4V (VBUS present) or
* when VBUS falls below programmed threshold (VBUS absent).
* @note Callback function is un-registered when callback function pointer
* argument is NULL.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param pfnVBUSDetectCallback callback function pointer
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_RegisterVBUSDetectCallback(uint32_t PortNum,
USBPD_PWR_VBUSDetectCallbackFunc *pfnVBUSDetectCallback)
{
UNUSED(pfnVBUSDetectCallback);
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Get actual voltage level measured on the VBUS line.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param pVoltage Pointer on measured voltage level (in mV)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t PortNum, uint32_t *pVoltage)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if instance is valid */
if ((PortNum >= USBPD_PWR_INSTANCES_NBR) || (NULL == pVoltage))
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
uint32_t val;
LL_ADC_REG_StartConversion(ADC1);
val = (((uint32_t) LL_ADC_REG_ReadConversionData12(VSENSE_ADC_INSTANCE)) * (VDDA_APPLI))
/ (__LL_ADC_DIGITAL_SCALE(VSENSE_ADC_INSTANCE, LL_ADC_RESOLUTION_12B));
/* NUCLEO144_Q (MB1549) board is used */
/* Value is multiplied by 7.61 (Divider R35+R34/R34 (379.9K/49.9K) for VSENSE) */
val *= 761UL;
val /= 100UL;
*pVoltage = val;
}
return ret;
}
/**
* @brief Get actual current level measured on the VBUS line.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param pCurrent Pointer on measured current level (in mA)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t PortNum, int32_t *pCurrent)
{
int32_t ret;
/* Check if instance is valid */
if ((PortNum >= USBPD_PWR_INSTANCES_NBR) || (NULL == pCurrent))
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
*pCurrent = 0;
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Activate discharge on VBUS.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSDischargeOn(uint32_t PortNum)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Deactivate discharge on VBUS.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VBUSDischargeOff(uint32_t PortNum)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Initialize VCONN sourcing.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param CCPinId Type-C CC pin identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_CC1
* @arg @ref USBPD_PWR_TYPE_C_CC2
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNInit(uint32_t PortNum,
uint32_t CCPinId)
{
UNUSED(CCPinId);
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Un-Initialize VCONN sourcing.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param CCPinId Type-C CC pin identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_CC1
* @arg @ref USBPD_PWR_TYPE_C_CC2
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNDeInit(uint32_t PortNum,
uint32_t CCPinId)
{
UNUSED(CCPinId);
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Enable VCONN sourcing.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param CCPinId Type-C CC pin identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_CC1
* @arg @ref USBPD_PWR_TYPE_C_CC2
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNOn(uint32_t PortNum,
uint32_t CCPinId)
{
UNUSED(CCPinId);
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Disable VCONN sourcing.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param CCPinId CC pin identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_CC1
* @arg @ref USBPD_PWR_TYPE_C_CC2
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNOff(uint32_t PortNum,
uint32_t CCPinId)
{
UNUSED(CCPinId);
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Get actual VCONN status.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @param CCPinId Type-C CC pin identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_CC1
* @arg @ref USBPD_PWR_TYPE_C_CC2
* @param pState VCONN status (1: On, 0: Off)
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNIsOn(uint32_t PortNum,
uint32_t CCPinId, uint8_t *pState)
{
UNUSED(CCPinId);
int32_t ret;
/* Check if parameters are valid */
if ((PortNum >= USBPD_PWR_INSTANCES_NBR) || (NULL == pState))
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
*pState = 0;
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Activate discharge on VCONN.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNDischargeOn(uint32_t PortNum)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Deactivate discharge on VCONN.
* @param PortNum Type-C port identifier
* This parameter can be take one of the following values:
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
* @retval BSP status
*/
int32_t BSP_USBPD_PWR_VCONNDischargeOff(uint32_t PortNum)
{
int32_t ret;
/* Check if instance is valid */
if (PortNum >= USBPD_PWR_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @}
*/
/** @addtogroup STM32U5XX_NUCLEO_USBPD_PWR_Private_Functions USBPD PWR Private Functions
* @{
*/
static void MX_ADC1_Init(void)
{
static ADC_HandleTypeDef hadc1;
/* Enable GPIO Clock */
VSENSE_GPIO_ENABLE_CLOCK();
/* Configure GPIO in analog mode to be used as ADC input */
LL_GPIO_SetPinMode(VSENSE_GPIO_PORT, VSENSE_GPIO_PIN, LL_GPIO_MODE_ANALOG);
LL_GPIO_SetPinPull(VSENSE_GPIO_PORT, VSENSE_GPIO_PIN, LL_GPIO_PULL_NO);
/* Enable ADC clock (core clock) */
VSENSE_ADC_ENABLE_CLOCK();
/* Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */
/* The clock source of the ADC is by default HCLCK (see RCC->CCIPR3 ADCDACSEL)*/
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableVddA();
HAL_PWREx_EnableVddIO2();
hadc1.Instance = VSENSE_ADC_INSTANCE;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = ADC_LOW_POWER_NONE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
}
/* Configure Regular Channel */
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = VSENSE_ADC_CHANNEL;
sConfig.Rank = VSENSE_ADC_RANK;
sConfig.SamplingTime = ADC_SAMPLETIME_36CYCLES;
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
sConfig.Offset = 0; /* Parameter discarded because offset correction is disabled */
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
}
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
}
if (HAL_ADC_Start(&hadc1) != HAL_OK)
{
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/