Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32L152: Added ADC Bank_B functionality #14669

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions targets/TARGET_STM/PinNamesTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ extern "C" {
* [9:6] speed config (as in OSPEEDR)
* [13:10] Alternate Num (as in AFRL/AFRG reg)
* [17:14] Channel (Analog/Timer specific)
* [18] Inverted (Analog/Timer specific)
* [19] Analog ADC control - Only valid for specific families
* [32:21] Reserved
* [19] Inverted (Analog/Timer specific)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch ....

* [20] Analog ADC control - Only valid for specific families
* [21] Analog ADC Channel Bank B - Only valid for specific families
* [32:22] Reserved
*/

#define STM_PIN_FUNCTION_MASK 0x07
Expand Down Expand Up @@ -82,6 +83,10 @@ extern "C" {
#define STM_PIN_AN_CTRL_SHIFT 20
#define STM_PIN_ANALOG_CONTROL_BIT (STM_PIN_AN_CTRL_MASK << STM_PIN_AN_CTRL_SHIFT)

#define STM_PIN_AN_CHAN_BANK_B_MASK 0x01
#define STM_PIN_AN_CHAN_BANK_B_SHIFT 21
#define STM_PIN_ANALOG_CHAN_BANK_B_BIT (STM_PIN_AN_CHAN_BANK_B_MASK << STM_PIN_AN_CHAN_BANK_B_SHIFT)

#define STM_PIN_FUNCTION(X) (((X) >> STM_PIN_FUNCTION_SHIFT) & STM_PIN_FUNCTION_MASK)
#define STM_PIN_OD(X) (((X) >> STM_PIN_OD_SHIFT) & STM_PIN_OD_MASK)
#define STM_PIN_PUPD(X) (((X) >> STM_PIN_PUPD_SHIFT) & STM_PIN_PUPD_MASK)
Expand All @@ -90,6 +95,7 @@ extern "C" {
#define STM_PIN_CHANNEL(X) (((X) >> STM_PIN_CHAN_SHIFT) & STM_PIN_CHAN_MASK)
#define STM_PIN_INVERTED(X) (((X) >> STM_PIN_INV_SHIFT) & STM_PIN_INV_MASK)
#define STM_PIN_ANALOG_CONTROL(X) (((X) >> STM_PIN_AN_CTRL_SHIFT) & STM_PIN_AN_CTRL_MASK)
#define STM_PIN_ANALOG_CHANNEL_BANK_B(X) (((X) >> STM_PIN_AN_CHAN_BANK_B_SHIFT) & STM_PIN_AN_CHAN_BANK_B_MASK)

#define STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM) ((int)(FUNC_OD) |\
((STM_PIN_SPEED_MASK & STM_PIN_SPEED_MASK) << STM_PIN_SPEED_SHIFT) |\
Expand Down Expand Up @@ -141,6 +147,7 @@ typedef enum {
#define STM_MODE_AF_OD (STM_PIN_ALTERNATE | STM_PIN_OD_BITS)
#define STM_MODE_ANALOG (STM_PIN_ANALOG)
#define STM_MODE_ANALOG_ADC_CONTROL (STM_PIN_ANALOG | STM_PIN_ANALOG_CONTROL_BIT)
#define STM_MODE_ANALOG_ADC_CHANNEL_BANK_B (STM_PIN_ANALOG | STM_PIN_ANALOG_CHAN_BANK_B_BIT)

// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
// Low nibble = pin number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ MBED_WEAK const PinMap PinMap_ADC[] = {
{PA_7, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC_IN7
{PB_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC_IN8
{PB_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC_IN9
{PB_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC_IN0b
{PB_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CHANNEL_BANK_B, GPIO_NOPULL, 0, 0, 0)}, // ADC_IN0b
{PB_12, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // ADC_IN18
{PB_13, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 19, 0)}, // ADC_IN19
{PB_14, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 20, 0)}, // ADC_IN20
Expand Down
11 changes: 10 additions & 1 deletion targets/TARGET_STM/TARGET_STM32L1/analogin_device.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void analogin_init(analogin_t *obj, PinName pin)
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).
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.
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).
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
obj->handle.Init.ContinuousConvMode = DISABLE; // Continuous mode disabled to have only 1 conversion at each conversion trig
obj->handle.Init.NbrOfConversion = 1; // Parameter discarded because sequencer is disabled
obj->handle.Init.DiscontinuousConvMode = DISABLE; // Parameter discarded because sequencer is disabled
Expand All @@ -71,6 +70,16 @@ void analogin_init(analogin_t *obj, PinName pin)
obj->handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
obj->handle.Init.DMAContinuousRequests = DISABLE;

#if defined ADC_CHANNELS_BANK_B
if (STM_PIN_ANALOG_CHANNEL_BANK_B(function)) {
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_B;
} else {
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
}
#else
obj->handle.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
#endif

__HAL_RCC_ADC1_CLK_ENABLE();

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