Skip to content

Commit b0b0598

Browse files
committed
core: analog: add STM32U5xx support
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 526d548 commit b0b0598

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

libraries/SrcWrapper/src/stm32/analog.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static PinName g_current_pin = NC;
3333
#ifndef ADC_SAMPLINGTIME
3434
#if defined(ADC_SAMPLETIME_8CYCLES_5)
3535
#define ADC_SAMPLINGTIME ADC_SAMPLETIME_8CYCLES_5;
36+
#elif defined(ADC_SAMPLETIME_12CYCLES)
37+
#define ADC_SAMPLINGTIME ADC_SAMPLETIME_12CYCLES;
3638
#elif defined(ADC_SAMPLETIME_12CYCLES_5)
3739
#define ADC_SAMPLINGTIME ADC_SAMPLETIME_12CYCLES_5;
3840
#elif defined(ADC_SAMPLETIME_13CYCLES_5)
@@ -50,6 +52,10 @@ static PinName g_current_pin = NC;
5052
#define ADC3_SAMPLINGTIME ADC3_SAMPLETIME_24CYCLES_5;
5153
#endif
5254

55+
#if defined(ADC4_SAMPLETIME_19CYCLES_5) && !defined(ADC4_SAMPLINGTIME)
56+
#define ADC4_SAMPLINGTIME ADC4_SAMPLETIME_19CYCLES_5;
57+
#endif
58+
5359
/*
5460
* Minimum ADC sampling time is required when reading
5561
* internal channels so set it to max possible value.
@@ -64,6 +70,8 @@ static PinName g_current_pin = NC;
6470
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_384CYCLES
6571
#elif defined(ADC_SAMPLETIME_810CYCLES_5)
6672
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_810CYCLES_5
73+
#elif defined(ADC_SAMPLETIME_814CYCLES)
74+
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_814CYCLES
6775
#elif defined(ADC_SAMPLETIME_640CYCLES_5)
6876
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_640CYCLES_5
6977
#elif defined(ADC_SAMPLETIME_601CYCLES_5)
@@ -84,8 +92,8 @@ static PinName g_current_pin = NC;
8492
#define ADC_CLOCK_DIV ADC_CLOCK_SYNC_PCLK_DIV4
8593
#elif ADC_CLOCK_SYNC_PCLK_DIV2
8694
#define ADC_CLOCK_DIV ADC_CLOCK_SYNC_PCLK_DIV2
87-
#elif defined(ADC_CLOCK_ASYNC_DIV1)
88-
#define ADC_CLOCK_DIV ADC_CLOCK_ASYNC_DIV1
95+
#elif defined(ADC_CLOCK_ASYNC_DIV4)
96+
#define ADC_CLOCK_DIV ADC_CLOCK_ASYNC_DIV4
8997
#endif
9098
#endif /* !ADC_CLOCK_DIV */
9199

@@ -180,6 +188,7 @@ static uint32_t get_adc_channel(PinName pin, uint32_t *bank)
180188
case 23:
181189
channel = ADC_CHANNEL_23;
182190
break;
191+
#ifdef ADC_CHANNEL_24
183192
case 24:
184193
channel = ADC_CHANNEL_24;
185194
break;
@@ -206,6 +215,7 @@ static uint32_t get_adc_channel(PinName pin, uint32_t *bank)
206215
channel = ADC_CHANNEL_31;
207216
break;
208217
#endif
218+
#endif
209219
#endif
210220
default:
211221
channel = 0;
@@ -592,6 +602,9 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
592602
#endif
593603
#ifdef ADC4
594604
else if (hadc->Instance == ADC4) {
605+
#ifdef __HAL_RCC_ADC4_CLK_ENABLE
606+
__HAL_RCC_ADC4_CLK_ENABLE();
607+
#endif
595608
#ifdef __HAL_RCC_ADC34_CLK_ENABLE
596609
__HAL_RCC_ADC34_CLK_ENABLE();
597610
#endif
@@ -711,6 +724,15 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc)
711724
#endif
712725
#ifdef ADC4
713726
else if (hadc->Instance == ADC4) {
727+
#ifdef __HAL_RCC_ADC4_FORCE_RESET
728+
__HAL_RCC_ADC4_FORCE_RESET();
729+
#endif
730+
#ifdef __HAL_RCC_ADC4_RELEASE_RESET
731+
__HAL_RCC_ADC4_RELEASE_RESET();
732+
#endif
733+
#ifdef __HAL_RCC_ADC4_CLK_DISABLE
734+
__HAL_RCC_ADC4_CLK_DISABLE();
735+
#endif
714736
#ifdef __HAL_RCC_ADC34_FORCE_RESET
715737
__HAL_RCC_ADC34_FORCE_RESET();
716738
#endif
@@ -778,6 +800,11 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
778800
if (AdcHandle.Instance == ADC3) {
779801
samplingTime = ADC3_SAMPLINGTIME;
780802
}
803+
#endif
804+
#if defined(ADC4_SAMPLINGTIME)
805+
if (AdcHandle.Instance == ADC4) {
806+
samplingTime = ADC4_SAMPLINGTIME;
807+
}
781808
#endif
782809
}
783810

@@ -896,6 +923,9 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
896923
#ifdef ADC_TRIGGER_FREQ_HIGH
897924
AdcHandle.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
898925
#endif
926+
#ifdef ADC_VREF_PPROT_NONE
927+
AdcHandle.Init.VrefProtection = ADC_VREF_PPROT_NONE;
928+
#endif
899929

900930
AdcHandle.State = HAL_ADC_STATE_RESET;
901931
AdcHandle.DMA_Handle = NULL;
@@ -918,7 +948,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
918948
#endif
919949
return 0;
920950
}
921-
#ifdef ADC_SCAN_SEQ_FIXED
951+
#if defined(ADC_SCAN_SEQ_FIXED) && defined(ADC_RANK_CHANNEL_NUMBER)
922952
AdcChannelConf.Rank = ADC_RANK_CHANNEL_NUMBER; /* Enable the rank of the selected channels when not fully configurable */
923953
#else
924954
AdcChannelConf.Rank = ADC_REGULAR_RANK_1; /* Specifies the rank in the regular group sequencer */
@@ -968,7 +998,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
968998

969999
/*##-3- Start the conversion process ####################*/
9701000
if (HAL_ADC_Start(&AdcHandle) != HAL_OK) {
971-
/* Start Conversation Error */
1001+
/* Start Conversion Error */
9721002
return 0;
9731003
}
9741004

libraries/SrcWrapper/src/stm32/hw_config.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ void hw_config_init(void)
2828
{
2929
configIPClock();
3030

31-
#if defined(PWR_CR3_UCPD_DBDIS) || defined(STM32L5xx)
31+
#if defined(PWR_CR3_UCPD_DBDIS) || defined(PWR_UCPDR_UCPD_DBDIS)
3232
/* Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral */
3333
HAL_PWREx_DisableUCPDDeadBattery();
3434
#endif
35-
#if defined (SYSCFG_CFGR1_UCPD1_STROBE) || defined (SYSCFG_CFGR1_UCPD2_STROBE)
35+
#if defined(SYSCFG_CFGR1_UCPD1_STROBE) || defined(SYSCFG_CFGR1_UCPD2_STROBE)
3636
/* Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral */
3737
HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);
3838
#endif /* SYSCFG_CFGR1_UCPD1_STROBE || SYSCFG_CFGR1_UCPD2_STROBE */
3939

40+
#if defined(PWR_SVMCR_ASV)
41+
HAL_PWREx_EnableVddA();
42+
#endif
4043
/* Init DWT if present */
4144
#ifdef DWT_BASE
4245
dwt_init();

0 commit comments

Comments
 (0)