Skip to content

Commit 6d393c2

Browse files
Modified analogin_init function to take correct value for ChannelsBank depends on ADC pin.
This commit adds ADC Bank_B feature to STm32L152RE. With this commit PB_2 pin can also work as ADC. Summary of changes: Impact of changes Migration actions required Pull request type [x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor) [] Feature update (New feature / Functionality change / New API) [] Major update (Breaking change E.g. Return code change / API behaviour change) Test results [] No Tests required for this change (E.g docs only update) [x] Covered by existing mbed-os tests (Greentea or Unittest) [] Tests / results supplied as part of this PR Signed-off-by: Affrin Pinhero <[email protected]>
1 parent a3be10c commit 6d393c2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

targets/TARGET_STM/PinNamesTypes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ extern "C" {
8282
#define STM_PIN_AN_CTRL_SHIFT 20
8383
#define STM_PIN_ANALOG_CONTROL_BIT (STM_PIN_AN_CTRL_MASK << STM_PIN_AN_CTRL_SHIFT)
8484

85+
#define STM_PIN_AN_CHAN_BANK_B_MASK 0x01
86+
#define STM_PIN_AN_CHAN_BANK_B_SHIFT 22
87+
#define STM_PIN_ANALOG_CHAN_BANK_B_BIT (STM_PIN_AN_CHAN_BANK_B_MASK << STM_PIN_AN_CHAN_BANK_B_SHIFT)
88+
8589
#define STM_PIN_FUNCTION(X) (((X) >> STM_PIN_FUNCTION_SHIFT) & STM_PIN_FUNCTION_MASK)
8690
#define STM_PIN_OD(X) (((X) >> STM_PIN_OD_SHIFT) & STM_PIN_OD_MASK)
8791
#define STM_PIN_PUPD(X) (((X) >> STM_PIN_PUPD_SHIFT) & STM_PIN_PUPD_MASK)
@@ -90,6 +94,7 @@ extern "C" {
9094
#define STM_PIN_CHANNEL(X) (((X) >> STM_PIN_CHAN_SHIFT) & STM_PIN_CHAN_MASK)
9195
#define STM_PIN_INVERTED(X) (((X) >> STM_PIN_INV_SHIFT) & STM_PIN_INV_MASK)
9296
#define STM_PIN_ANALOG_CONTROL(X) (((X) >> STM_PIN_AN_CTRL_SHIFT) & STM_PIN_AN_CTRL_MASK)
97+
#define STM_PIN_ANALOG_CHANNEL_BANK_B(X) (((X) >> STM_PIN_AN_CHAN_BANK_B_SHIFT) & STM_PIN_AN_CHAN_BANK_B_MASK)
9398

9499
#define STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM) ((int)(FUNC_OD) |\
95100
((STM_PIN_SPEED_MASK & STM_PIN_SPEED_MASK) << STM_PIN_SPEED_SHIFT) |\
@@ -141,6 +146,7 @@ typedef enum {
141146
#define STM_MODE_AF_OD (STM_PIN_ALTERNATE | STM_PIN_OD_BITS)
142147
#define STM_MODE_ANALOG (STM_PIN_ANALOG)
143148
#define STM_MODE_ANALOG_ADC_CONTROL (STM_PIN_ANALOG | STM_PIN_ANALOG_CONTROL_BIT)
149+
#define STM_MODE_ANALOG_ADC_CHANNEL_BANK_B (STM_PIN_ANALOG | STM_PIN_ANALOG_CHAN_BANK_B_BIT)
144150

145151
// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
146152
// Low nibble = pin number

targets/TARGET_STM/TARGET_STM32L1/TARGET_STM32L152xE/TARGET_NUCLEO_L152RE/PeripheralPins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ MBED_WEAK const PinMap PinMap_ADC[] = {
6363
{PA_7, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC_IN7
6464
{PB_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC_IN8
6565
{PB_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC_IN9
66-
{PB_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC_IN0b
66+
{PB_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CHANNEL_BANK_B, GPIO_NOPULL, 0, 0, 0)}, // ADC_IN0b
6767
{PB_12, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // ADC_IN18
6868
{PB_13, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 19, 0)}, // ADC_IN19
6969
{PB_14, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 20, 0)}, // ADC_IN20

targets/TARGET_STM/TARGET_STM32L1/analogin_device.c

100644100755
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ void analogin_init(analogin_t *obj, PinName pin)
6262
obj->handle.Init.EOCSelection = EOC_SINGLE_CONV; // On STM32L1xx ADC, overrun detection is enabled only if EOC selection is set to each conversion (or transfer by DMA enabled, this is not the case in this example).
6363
obj->handle.Init.LowPowerAutoWait = ADC_AUTOWAIT_UNTIL_DATA_READ; // Enable the dynamic low power Auto Delay: new conversion start only when the previous conversion (for regular group) or previous sequence (for injected group) has been treated by user software.
6464
obj->handle.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_IDLE_PHASE; // Enable the auto-off mode: the ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered (with startup time between trigger and start of sampling).
65-
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
6665
obj->handle.Init.ContinuousConvMode = DISABLE; // Continuous mode disabled to have only 1 conversion at each conversion trig
6766
obj->handle.Init.NbrOfConversion = 1; // Parameter discarded because sequencer is disabled
6867
obj->handle.Init.DiscontinuousConvMode = DISABLE; // Parameter discarded because sequencer is disabled
@@ -71,6 +70,16 @@ void analogin_init(analogin_t *obj, PinName pin)
7170
obj->handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
7271
obj->handle.Init.DMAContinuousRequests = DISABLE;
7372

73+
#if defined ADC_CHANNELS_BANK_B
74+
if (STM_PIN_ANALOG_CHANNEL_BANK_B(function)) {
75+
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_B;
76+
} else {
77+
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
78+
}
79+
#else
80+
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
81+
#endif
82+
7483
__HAL_RCC_ADC1_CLK_ENABLE();
7584

7685
if (HAL_ADC_Init(&obj->handle) != HAL_OK) {

0 commit comments

Comments
 (0)