Skip to content

Commit 1c77628

Browse files
authored
Merge pull request #4153 from jeromecoutant/PR_AF2_LEVEL0
STM32F2: Internal ADC channels rework
2 parents 47b1a9e + 43ab881 commit 1c77628

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/PeripheralPins.c

Lines changed: 5 additions & 1 deletion
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
@@ -107,7 +111,7 @@ const PinMap PinMap_I2C_SDA[] = {
107111
// {PB_7, I2C_1 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, // LED2
108112
{PB_9, I2C_1 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
109113
{PB_11, I2C_2 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
110-
{PC_9, I2C_3 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
114+
// {PC_9, I2C_3 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, // no I2C_3 SCL available
111115
{PF_0, I2C_2 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
112116
{NC, NC, 0}
113117
};

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)