Skip to content

Commit 5cf1048

Browse files
authored
Merge pull request #737 from fpistm/Nucleo-G071RB_Analog
Fix Nucleo G071RB analog pin issue
2 parents fd40374 + 856da01 commit 5cf1048

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

cores/arduino/stm32/analog.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,11 @@ uint16_t adc_read_value(PinName pin)
797797
#ifdef ADC_DATAALIGN_RIGHT
798798
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */
799799
#endif
800+
#ifdef ADC_SCAN_SEQ_FIXED
801+
AdcHandle.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
802+
#else
800803
AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
804+
#endif
801805
#ifdef ADC_EOC_SINGLE_CONV
802806
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
803807
#endif
@@ -845,7 +849,6 @@ uint16_t adc_read_value(PinName pin)
845849
#if defined(STM32G0xx)
846850
AdcHandle.Init.SamplingTimeCommon1 = samplingTime; /* Set sampling time common to a group of channels. */
847851
AdcHandle.Init.SamplingTimeCommon2 = samplingTime; /* Set sampling time common to a group of channels, second common setting possible.*/
848-
AdcHandle.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
849852
#endif
850853
#if defined(STM32L0xx)
851854
AdcHandle.Init.LowPowerFrequencyMode = DISABLE; /* To be enabled only if ADC clock < 2.8 MHz */
@@ -887,7 +890,11 @@ uint16_t adc_read_value(PinName pin)
887890
#endif /* STM32L4xx || STM32WBxx */
888891
return 0;
889892
}
893+
#ifdef ADC_SCAN_SEQ_FIXED
894+
AdcChannelConf.Rank = ADC_RANK_CHANNEL_NUMBER; /* Enable the rank of the selected channels when not fully configurable */
895+
#else
890896
AdcChannelConf.Rank = ADC_REGULAR_RANK_1; /* Specifies the rank in the regular group sequencer */
897+
#endif
891898
#if !defined(STM32L0xx)
892899
#if !defined(STM32G0xx)
893900
AdcChannelConf.SamplingTime = samplingTime; /* Sampling time value to be set for the selected channel */

variants/NUCLEO_G071RB/PeripheralPins.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ WEAK const PinMap PinMap_ADC[] = {
3232
//{PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5
3333
{PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6
3434
{PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7
35-
{PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8
35+
//{PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8
3636
{PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9
3737
{PB_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10
3838
{PB_10, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11

variants/NUCLEO_G071RB/variant.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ const PinName digitalPin[] = {
3434
PA_8, //D7
3535
PA_9, //D8
3636
PC_7, //D9
37-
PB_0, //D10/A8
38-
PA_7, //D11/A7
39-
PA_6, //D12/A6
37+
PB_0, //D10
38+
PA_7, //D11/A6
39+
PA_6, //D12/A7
4040
PA_5, //D13/LED
4141
PB_9, //D14
4242
PB_8, //D15
@@ -74,10 +74,10 @@ const PinName digitalPin[] = {
7474
PA_12, //D42
7575
PC_1, //D43
7676
PC_0, //D44
77-
PB_2, //D45/A9
77+
PB_2, //D45/A8
7878
PB_6, //D46
7979
PB_15, //D47
80-
PB_10, //D48/A10
80+
PB_10, //D48/A9
8181
PB_13, //D49
8282
PA_2, //D50
8383
PD_8, //D51
@@ -89,11 +89,10 @@ const PinName digitalPin[] = {
8989
PB_11, //D57/A4
9090
PB_12, //D58/A5
9191
// Duplicated pins in order to be aligned with PinMap_ADC
92-
PB_0, //D59/A6 = D10
93-
PA_7, //D60/A7 = D11
94-
PA_6, //D61/A8 = D12
95-
PB_2, //D62/A9 = D45
96-
PB_10 //D63/A10 = D48
92+
PA_7, //D59/A6 = D11
93+
PA_6, //D60/A7 = D12
94+
PB_2, //D61/A8 = D45
95+
PB_10 //D62/A9 = D48
9796
};
9897

9998
#ifdef __cplusplus

variants/NUCLEO_G071RB/variant.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ extern "C" {
3737
#define PA8 7
3838
#define PA9 8
3939
#define PC7 9
40-
#define PB0 10 // A6
41-
#define PA7 11 // A7
42-
#define PA6 12 // A8
40+
#define PB0 10
41+
#define PA7 11 // A6
42+
#define PA6 12 // A7
4343
#define PA5 13 // LED
4444
#define PB9 14
4545
#define PB8 15
@@ -77,10 +77,10 @@ extern "C" {
7777
#define PA12 42
7878
#define PC1 43
7979
#define PC0 44
80-
#define PB2 45 // A9
80+
#define PB2 45 // A8
8181
#define PB6 46
8282
#define PB15 47
83-
#define PB10 48 // A10
83+
#define PB10 48 // A9
8484
#define PB13 49
8585
#define PA2 50
8686
#define PD8 51
@@ -93,9 +93,9 @@ extern "C" {
9393
#define PB12 58 // A5
9494

9595
// This must be a literal
96-
#define NUM_DIGITAL_PINS 64
96+
#define NUM_DIGITAL_PINS 63
9797
// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
98-
#define NUM_ANALOG_INPUTS 11
98+
#define NUM_ANALOG_INPUTS 10
9999
#define NUM_ANALOG_FIRST 53
100100

101101
// On-board LED pin number

0 commit comments

Comments
 (0)