|
36 | 36 | #include "mbed_error.h" |
37 | 37 | #include "PeripheralPins.h" |
38 | 38 |
|
| 39 | + |
| 40 | +void analogin_pll_configuration(void) |
| 41 | +{ |
| 42 | +#if defined(DUAL_CORE) |
| 43 | + while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) { |
| 44 | + } |
| 45 | +#endif /* DUAL_CORE */ |
| 46 | + |
| 47 | + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
| 48 | + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
| 49 | + PeriphClkInitStruct.PLL2.PLL2M = 4; |
| 50 | + PeriphClkInitStruct.PLL2.PLL2N = 240; |
| 51 | + PeriphClkInitStruct.PLL2.PLL2P = 2; |
| 52 | + PeriphClkInitStruct.PLL2.PLL2Q = 2; |
| 53 | + PeriphClkInitStruct.PLL2.PLL2R = 2; |
| 54 | + PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_1; |
| 55 | + PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE; |
| 56 | + PeriphClkInitStruct.PLL2.PLL2FRACN = 0; |
| 57 | + PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2; |
| 58 | + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { |
| 59 | + error("analogin_init HAL_RCCEx_PeriphCLKConfig"); |
| 60 | + } |
| 61 | + |
| 62 | +#if defined(DUAL_CORE) |
| 63 | + LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT); |
| 64 | +#endif /* DUAL_CORE */ |
| 65 | + |
| 66 | +} |
| 67 | + |
39 | 68 | void analogin_init(analogin_t *obj, PinName pin) |
40 | 69 | { |
41 | 70 | uint32_t function = (uint32_t)NC; |
@@ -99,29 +128,7 @@ void analogin_init(analogin_t *obj, PinName pin) |
99 | 128 | obj->handle.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; |
100 | 129 | obj->handle.Init.OversamplingMode = DISABLE; |
101 | 130 |
|
102 | | -#if defined(DUAL_CORE) |
103 | | - while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) { |
104 | | - } |
105 | | -#endif /* DUAL_CORE */ |
106 | | - |
107 | | - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
108 | | - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
109 | | - PeriphClkInitStruct.PLL2.PLL2M = 4; |
110 | | - PeriphClkInitStruct.PLL2.PLL2N = 240; |
111 | | - PeriphClkInitStruct.PLL2.PLL2P = 2; |
112 | | - PeriphClkInitStruct.PLL2.PLL2Q = 2; |
113 | | - PeriphClkInitStruct.PLL2.PLL2R = 2; |
114 | | - PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_1; |
115 | | - PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE; |
116 | | - PeriphClkInitStruct.PLL2.PLL2FRACN = 0; |
117 | | - PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2; |
118 | | - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { |
119 | | - error("analogin_init HAL_RCCEx_PeriphCLKConfig"); |
120 | | - } |
121 | | - |
122 | | -#if defined(DUAL_CORE) |
123 | | - LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT); |
124 | | -#endif /* DUAL_CORE */ |
| 131 | + analogin_pll_configuration(); |
125 | 132 |
|
126 | 133 | #if defined(ADC1) |
127 | 134 | if ((ADCName)obj->handle.Instance == ADC_1) { |
@@ -163,6 +170,9 @@ uint16_t adc_read(analogin_t *obj) |
163 | 170 | { |
164 | 171 | ADC_ChannelConfTypeDef sConfig = {0}; |
165 | 172 |
|
| 173 | + /* Reconfigure PLL as it could be lost during deepsleep */ |
| 174 | + analogin_pll_configuration(); |
| 175 | + |
166 | 176 | // Configure ADC channel |
167 | 177 | sConfig.Rank = ADC_REGULAR_RANK_1; |
168 | 178 | sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_5; |
|
0 commit comments