Skip to content

Commit ad8af3e

Browse files
committed
fixup! cpu/stm32{f4,l4,wb,wl}: replace ztimer w/ busy_wait for uncrit. delay
1 parent 76a6143 commit ad8af3e

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

cpu/stm32/Makefile.dep

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ ifneq (,$(filter periph_rtc_mem,$(USEMODULE)))
7878
FEATURES_REQUIRED += periph_rtc
7979
endif
8080

81-
ifneq (,$(filter periph_adc,$(FEATURES_USED)))
82-
ifneq (,$(filter f3 l4 wb wl, $(CPU_FAM)))
83-
USEMODULE += ztimer
84-
USEMODULE += ztimer_msec
85-
endif
86-
endif
87-
8881
ifneq (,$(filter periph_can,$(FEATURES_USED)))
8982
ifneq (,$(filter g4,$(CPU_FAM)))
9083
USEMODULE += fdcan

cpu/stm32/periph/adc_f3.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@
1919
* @}
2020
*/
2121

22+
#include "busy_wait.h"
2223
#include "cpu.h"
2324
#include "mutex.h"
2425
#include "periph/adc.h"
2526
#include "periph_conf.h"
26-
#include "ztimer.h"
2727
#include "periph/vbat.h"
2828

29-
#define SMP_MIN (0x2) /*< Sampling time for slow channels
29+
#if IS_USED(MODULE_PERIPH_VBAT)
30+
# define SMP_MIN (0x5) /*< Sampling time when the VBat channel
31+
is read (0x5 = 61.5 ADC clock cycles) */
32+
#else
33+
# define SMP_MIN (0x2) /*< Sampling time for slow channels
3034
(0x2 = 4.5 ADC clock cycles) */
35+
#endif
36+
3137
#ifdef ADC1_COMMON
3238
#define ADC_INSTANCE ADC1_COMMON
3339
#else
@@ -143,13 +149,7 @@ int adc_init(adc_t line)
143149
if (!(dev(line)->CR & ADC_CR_ADEN)) {
144150
/* Enable ADC internal voltage regulator and wait for startup period */
145151
dev(line)->CR |= ADC_CR_ADVREGEN;
146-
#if IS_USED(MODULE_ZTIMER_USEC)
147-
ztimer_sleep(ZTIMER_USEC, ADC_T_ADCVREG_STUP_US);
148-
#else
149-
/* to avoid using ZTIMER_USEC unless already included round up the
150-
internal voltage regulator start up to 1ms */
151-
ztimer_sleep(ZTIMER_MSEC, 1);
152-
#endif
152+
busy_wait_us(ADC_T_ADCVREG_STUP_US * 2);
153153

154154
if (dev(line)->DIFSEL & (1 << adc_config[line].chan)) {
155155
/* Configure calibration for differential inputs */

cpu/stm32/periph/adc_l4_wb.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
* @}
2222
*/
2323

24+
#include "busy_wait.h"
2425
#include "cpu.h"
2526
#include "mutex.h"
2627
#include "periph/adc.h"
2728
#include "periph_conf.h"
2829
#include "periph/vbat.h"
29-
#include "ztimer.h"
3030

3131
/**
3232
* @brief Not all STM32 L4 boards have 3 ADC devices
@@ -54,8 +54,14 @@
5454
works on all channels.
5555
TCONV = Sampling time + 12.5 ADC clock cycles (RM section 18.4.12)
5656
At 80MHz this means we need to set SMP to 001 (6.5 ADC clock cycles) to
57-
stay within specs. (80000000/(6.5+12.5)) = 4210526 */
58-
#define ADC_SMP_MIN_VAL (0x1)
57+
stay within specs. (80000000/(6.5+12.5)) = 4210526.
58+
Reading the battery voltage V_BAT is much slower and requires 92.5
59+
ADC clock cycles. */
60+
#if IS_USED(MODULE_PERIPH_VBAT)
61+
# define ADC_SMP_MIN_VAL (0x5)
62+
#else
63+
# define ADC_SMP_MIN_VAL (0x2)
64+
#endif
5965

6066
/* The sampling time width is 3 bit */
6167
#define ADC_SMP_BIT_WIDTH (3)
@@ -171,13 +177,7 @@ int adc_init(adc_t line)
171177

172178
/* enable ADC internal voltage regulator and wait for startup period */
173179
dev(line)->ADC_CR_REG |= (ADC_CR_ADVREGEN);
174-
#if IS_USED(MODULE_ZTIMER_USEC)
175-
ztimer_sleep(ZTIMER_USEC, ADC_T_ADCVREG_STUP_US);
176-
#else
177-
/* to avoid using ZTIMER_USEC unless already included round up the
178-
internal voltage regulator start up to 1ms */
179-
ztimer_sleep(ZTIMER_MSEC, 1);
180-
#endif
180+
busy_wait_us(ADC_T_ADCVREG_STUP_US * 2);
181181

182182
/* configure calibration for single ended input */
183183
dev(line)->ADC_CR_REG &= ~(ADC_CR_ADCALDIF);

0 commit comments

Comments
 (0)