Skip to content

Commit 74c2273

Browse files
jeromecoutantadbridge
authored andcommitted
STM32F2 Internal ADC channels rework
Internal ADC pin are now out of PinMap_ADC array
1 parent c23fea7 commit 74c2273

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/PeripheralPins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const PinMap PinMap_ADC[] = {
8787
{PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6
8888
{PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7
8989
{PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8
90+
{NC, NC, 0}
91+
};
92+
93+
const PinMap PinMap_ADC_Internal[] = {
9094
{ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // See in analogin_api.c the correct ADC channel used
9195
{ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, // See in analogin_api.c the correct ADC channel used
9296
{ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // See in analogin_api.c the correct ADC channel used

targets/TARGET_STM/TARGET_STM32F2/analogin_api.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ ADC_HandleTypeDef AdcHandle;
4040

4141
void analogin_init(analogin_t *obj, PinName pin)
4242
{
43+
uint32_t function = (uint32_t)NC;
44+
obj->adc = (ADCName)NC;
45+
4346
#if defined(ADC1)
4447
static int adc1_inited = 0;
4548
#endif
@@ -49,20 +52,27 @@ void analogin_init(analogin_t *obj, PinName pin)
4952
#if defined(ADC3)
5053
static int adc3_inited = 0;
5154
#endif
52-
// Get the peripheral name from the pin and assign it to the object
53-
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
55+
// ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
56+
// are described in PinNames.h and PeripheralPins.c
57+
// Pin value must be between 0xF0 and 0xFF
58+
if ((pin < 0xF0) || (pin >= 0x100)) {
59+
// Normal channels
60+
// Get the peripheral name from the pin and assign it to the object
61+
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
62+
// Get the functions (adc channel) from the pin and assign it to the object
63+
function = pinmap_function(pin, PinMap_ADC);
64+
// Configure GPIO
65+
pinmap_pinout(pin, PinMap_ADC);
66+
} else {
67+
// Internal channels
68+
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC_Internal);
69+
function = pinmap_function(pin, PinMap_ADC_Internal);
70+
// No GPIO configuration for internal channels
71+
}
5472
MBED_ASSERT(obj->adc != (ADCName)NC);
55-
56-
// Get the functions (adc channel) from the pin and assign it to the object
57-
uint32_t function = pinmap_function(pin, PinMap_ADC);
5873
MBED_ASSERT(function != (uint32_t)NC);
59-
obj->channel = STM_PIN_CHANNEL(function);
6074

61-
// Configure GPIO excepted for internal channels (Temperature, Vref, Vbat, ...)
62-
// ADC Internal Channels "pins" are described in PinNames.h and must have a value >= 0xF0
63-
if (pin < 0xF0) {
64-
pinmap_pinout(pin, PinMap_ADC);
65-
}
75+
obj->channel = STM_PIN_CHANNEL(function);
6676

6777
// Save pin number for the read function
6878
obj->pin = pin;

0 commit comments

Comments
 (0)