Skip to content

Commit 80f1d97

Browse files
committed
STM32F4xx - Add support of ADC channels 16, 17, 18
1 parent cc3a382 commit 80f1d97

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

hal/targets/hal/TARGET_STM/TARGET_STM32F4/analogin_api.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2015, STMicroelectronics
2+
* Copyright (c) 2016, STMicroelectronics
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -58,8 +58,10 @@ void analogin_init(analogin_t *obj, PinName pin)
5858
MBED_ASSERT(function != (uint32_t)NC);
5959
obj->channel = STM_PIN_CHANNEL(function);
6060

61-
// Configure GPIO
62-
pinmap_pinout(pin, PinMap_ADC);
61+
// Configure GPIO excepted for internal channels (Temperature, Vref, Vbat)
62+
if ((obj->channel != 16) && (obj->channel != 17) && (obj->channel != 18)) {
63+
pinmap_pinout(pin, PinMap_ADC);
64+
}
6365

6466
// Save pin number for the read function
6567
obj->pin = pin;
@@ -101,6 +103,7 @@ void analogin_init(analogin_t *obj, PinName pin)
101103
AdcHandle.Init.NbrOfConversion = 1;
102104
AdcHandle.Init.DMAContinuousRequests = DISABLE;
103105
AdcHandle.Init.EOCSelection = DISABLE;
106+
104107
if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {
105108
error("Cannot initialize ADC\n");
106109
}
@@ -114,7 +117,7 @@ static inline uint16_t adc_read(analogin_t *obj)
114117

115118
// Configure ADC channel
116119
sConfig.Rank = 1;
117-
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
120+
sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;
118121
sConfig.Offset = 0;
119122

120123
switch (obj->channel) {
@@ -166,6 +169,15 @@ static inline uint16_t adc_read(analogin_t *obj)
166169
case 15:
167170
sConfig.Channel = ADC_CHANNEL_15;
168171
break;
172+
case 16:
173+
sConfig.Channel = ADC_CHANNEL_16;
174+
break;
175+
case 17:
176+
sConfig.Channel = ADC_CHANNEL_17;
177+
break;
178+
case 18:
179+
sConfig.Channel = ADC_CHANNEL_18;
180+
break;
169181
default:
170182
return 0;
171183
}

0 commit comments

Comments
 (0)