Skip to content

Commit d75e0d7

Browse files
committed
Fix
1 parent 5c0b130 commit d75e0d7

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

src/current_sense/hardware_specific/stm32/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ This can help reduce the sampling time.
2727
Injected ADC is used for sampling that requires a critical timing (e.g. low side current sensing).<BR>
2828
The driver picks some of the shortest sampling time available on your STM32 chip.<BR>
2929
You can force a specific sampling time with the ADC_SAMPLINGTIME_INJ build flag (e.g. ADC_SAMPLINGTIME_INJ=ADC_SAMPLETIME_1CYCLE_5).<BR>
30+
Up to 4 injected channels can be sampled per ADC, you will get an error message beyond that.<BR>
3031

3132
### Regular ADC
3233
Regular ADC is used for less critical sampling.<BR>
3334
It uses DMA to copy ADC samples to a buffer.<BR>
3435
If not triggered by a timer, it will sample in continuous mode.<BR>
3536
You can force a specific sampling time with the ADC_SAMPLINGTIME build flag (e.g. ADC_SAMPLINGTIME=ADC_SAMPLETIME_8CYCLES_5).<BR>
37+
Up to 16 inected channels can be sampled per ADC, you will get an error message beyond that.<BR>
38+
If many ADCs are available, this can lead to a lot of RAM usage. You can use the MAX_REG_ADC_CHANNELS build flag to reduce this. (e.g. MAX_REG_ADC_CHANNELS=4).<BR>
3639

3740
### Internal channels
3841
You can now sample internal channels (VREF,VBAT,TEMP).<BR>
@@ -43,5 +46,3 @@ You can force a specific sampling time with the ADC_SAMPLINGTIME_INTERNAL build
4346
An interrupt is used with low side current sensing if the timer used to trigger the ADC has no repetition counter, which is used to make sure the low side mosfets are ON.<BR>
4447
You can force the use of an interrupt if needed with the SIMPLEFOC_STM32_ADC_INTERRUPT build flag.
4548

46-
47-

src/current_sense/hardware_specific/stm32/stm32_adc.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,18 @@ ADC_HandleTypeDef *interrupt_adc = NP;
2525

2626
ADC_HandleTypeDef *_get_ADC_handle(ADC_TypeDef* Instance){
2727

28-
#ifdef ADC
29-
// Some families have a single ADC without a number
30-
if (Instance == ADC) return &hadc1;
31-
#else
32-
if (Instance == ADC1) return &hadc1;
33-
#ifdef ADC2
34-
else if (Instance == ADC2) return &hadc2;
35-
#endif
36-
#ifdef ADC3
37-
else if (Instance == ADC3) return &hadc3;
38-
#endif
39-
#ifdef ADC4
40-
else if (Instance == ADC4) return &hadc4;
41-
#endif
42-
#ifdef ADC5
43-
else if (Instance == ADC5) return &hadc5;
44-
#endif
28+
if (Instance == ADC1) return &hadc1;
29+
#ifdef ADC2
30+
else if (Instance == ADC2) return &hadc2;
31+
#endif
32+
#ifdef ADC3
33+
else if (Instance == ADC3) return &hadc3;
34+
#endif
35+
#ifdef ADC4
36+
else if (Instance == ADC4) return &hadc4;
37+
#endif
38+
#ifdef ADC5
39+
else if (Instance == ADC5) return &hadc5;
4540
#endif
4641
else return nullptr;
4742
}
@@ -223,7 +218,7 @@ int _init_ADC(Stm32ADCSample sample)
223218
sample.handle->Init.DataAlign = ADC_DATAALIGN_RIGHT;
224219
#endif
225220
#if !defined(STM32F0xx) && !defined(STM32L0xx)
226-
sample.handle->Init.NbrOfConversion = max(1,ADCEngine.reg_channel_count[sample.adc_index]); // Minimum 1 for analogread to work
221+
sample.handle->Init.NbrOfConversion = ADCEngine.reg_channel_count[sample.adc_index]; // Minimum 1 for analogread to work
227222
#endif
228223
#if !defined(STM32F1xx) && !defined(STM32H7xx) && !defined(STM32MP1xx) && \
229224
!defined(ADC1_V2_5)

src/current_sense/hardware_specific/stm32/stm32_adc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242

4343
#define ADC_COUNT (ADC1_COUNT + ADC2_COUNT + ADC3_COUNT + ADC4_COUNT + ADC5_COUNT)
4444

45+
#ifndef MAX_REG_ADC_CHANNELS
4546
#define MAX_REG_ADC_CHANNELS 16 // Maximum number of samples for Regular ADC
47+
#endif
4648
#define MAX_INJ_ADC_CHANNELS 4 // Maximum number of samples for Injected ADC
4749

4850
#ifndef ADC_SAMPLINGTIME_INJ

src/current_sense/hardware_specific/stm32/stm32_dma.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,19 @@ extern Stm32ADCEngine ADCEngine;
1818
uint16_t adc_dma_buf[ADC_COUNT][MAX_REG_ADC_CHANNELS]={0};
1919

2020
DMA_HandleTypeDef *_get_DMA_handle(ADC_TypeDef* Instance){
21-
#ifdef ADC
22-
// Some families have a single ADC without a number
23-
if (Instance == ADC) return &hdma_adc1;
24-
#else
25-
if (Instance == ADC1) return &hdma_adc1;
26-
#ifdef ADC2
27-
else if (Instance == ADC2) return &hdma_adc2;
28-
#endif
29-
#ifdef ADC3
30-
else if (Instance == ADC3) return &hdma_adc3;
31-
#endif
32-
#ifdef ADC4
33-
else if (Instance == ADC4) return &hdma_adc4;
34-
#endif
35-
#ifdef ADC5
36-
else if (Instance == ADC5) return &hdma_adc5;
37-
#endif
21+
22+
if (Instance == ADC1) return &hdma_adc1;
23+
#ifdef ADC2
24+
else if (Instance == ADC2) return &hdma_adc2;
25+
#endif
26+
#ifdef ADC3
27+
else if (Instance == ADC3) return &hdma_adc3;
28+
#endif
29+
#ifdef ADC4
30+
else if (Instance == ADC4) return &hdma_adc4;
31+
#endif
32+
#ifdef ADC5
33+
else if (Instance == ADC5) return &hdma_adc5;
3834
#endif
3935
else return nullptr;
4036
}

0 commit comments

Comments
 (0)