Merge pull request #17320 from aabadie/pr/cpu/stm32_ztimer

cpu/stm32: migrate adc and eth periphs to ztimer
This commit is contained in:
Marian Buschsieweke 2021-12-02 20:05:43 +01:00 committed by GitHub
commit ec39b8e3aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 13 deletions

View File

@ -24,7 +24,8 @@ ifneq (,$(filter stm32_eth,$(USEMODULE)))
FEATURES_REQUIRED += periph_eth
USEMODULE += netdev_eth
USEMODULE += iolist
USEMODULE += xtimer
USEMODULE += ztimer
USEMODULE += ztimer_msec
endif
ifneq (,$(filter periph_can,$(FEATURES_USED)))
@ -42,7 +43,7 @@ ifneq (,$(filter periph_rtc_mem,$(USEMODULE)))
endif
ifneq (,$(filter periph_adc,$(FEATURES_USED)))
ifneq (,$(filter $(CPU_FAM),wl))
ifneq (,$(filter f3 l4 wl, $(CPU_FAM)))
USEMODULE += ztimer
USEMODULE += ztimer_msec
endif

View File

@ -31,6 +31,6 @@ config MODULE_PERIPH_CAN
config MODULE_PERIPH_ADC
bool "ADC peripheral driver"
depends on HAS_PERIPH_ADC
select MODULE_ZTIMER if HAS_CPU_STM32WL
select MODULE_ZTIMER_MSEC if HAS_CPU_STM32WL
select MODULE_ZTIMER if HAS_CPU_STM32F3 || HAS_CPU_STM32L4 || HAS_CPU_STM32WL
select MODULE_ZTIMER_MSEC if HAS_CPU_STM32F3 || HAS_CPU_STM32L4 || HAS_CPU_STM32WL
select MODULE_PERIPH_COMMON

View File

@ -23,7 +23,7 @@
#include "mutex.h"
#include "periph/adc.h"
#include "periph_conf.h"
#include "xtimer.h"
#include "ztimer.h"
#define SMP_MIN (0x2) /*< Sampling time for slow channels
(0x2 = 4.5 ADC clock cycles) */
@ -134,7 +134,13 @@ int adc_init(adc_t line)
if (!(dev(line)->CR & ADC_CR_ADEN)) {
/* Enable ADC internal voltage regulator and wait for startup period */
dev(line)->CR |= ADC_CR_ADVREGEN;
xtimer_usleep(ADC_T_ADCVREG_STUP_US);
#if IS_USED(MODULE_ZTIMER_USEC)
ztimer_sleep(ZTIMER_USEC, ADC_T_ADCVREG_STUP_US);
#else
/* to avoid using ZTIMER_USEC unless already included round up the
internal voltage regulator start up to 1ms */
ztimer_sleep(ZTIMER_MSEC, 1);
#endif
if (dev(line)->DIFSEL & (1 << adc_config[line].chan)) {
/* Configure calibration for differential inputs */

View File

@ -25,7 +25,7 @@
#include "mutex.h"
#include "periph/adc.h"
#include "periph_conf.h"
#include "xtimer.h"
#include "ztimer.h"
/**
* @brief map CPU specific register/value names
@ -138,7 +138,13 @@ int adc_init(adc_t line)
/* enable ADC internal voltage regulator and wait for startup period */
dev(line)->ADC_CR_REG |= (ADC_CR_ADVREGEN);
xtimer_usleep(ADC_T_ADCVREG_STUP_US);
#if IS_USED(MODULE_ZTIMER_USEC)
ztimer_sleep(ZTIMER_USEC, ADC_T_ADCVREG_STUP_US);
#else
/* to avoid using ZTIMER_USEC unless already included round up the
internal voltage regulator start up to 1ms */
ztimer_sleep(ZTIMER_MSEC, 1);
#endif
/* configure calibration for single ended input */
dev(line)->ADC_CR_REG &= ~(ADC_CR_ADCALDIF);

View File

@ -38,10 +38,10 @@
#define ENABLE_DEBUG_VERBOSE 0
#include "debug.h"
#include "xtimer.h"
#define STM32_ETH_LINK_UP_TIMEOUT_US (1UL * US_PER_SEC)
#include "ztimer.h"
#define STM32_ETH_LINK_UP_TIMEOUT_MS (1UL * MS_PER_SEC)
static xtimer_t _link_status_timer;
static ztimer_t _link_status_timer;
/* Set the value of the divider with the clock configured */
#if !defined(CLOCK_CORECLOCK) || CLOCK_CORECLOCK < (20000000U)
@ -322,7 +322,7 @@ static void _timer_cb(void *arg)
dev->event_callback(dev, NETDEV_EVENT_ISR);
}
xtimer_set(&_link_status_timer, STM32_ETH_LINK_UP_TIMEOUT_US);
ztimer_set(ZTIMER_MSEC, &_link_status_timer, STM32_ETH_LINK_UP_TIMEOUT_MS);
}
static bool _phy_can_negotiate(void)
@ -411,7 +411,7 @@ static int stm32_eth_init(netdev_t *netdev)
if (IS_USED(MODULE_STM32_ETH_LINK_UP)) {
_link_status_timer.callback = _timer_cb;
_link_status_timer.arg = netdev;
xtimer_set(&_link_status_timer, STM32_ETH_LINK_UP_TIMEOUT_US);
ztimer_set(ZTIMER_MSEC, &_link_status_timer, STM32_ETH_LINK_UP_TIMEOUT_MS);
}
/* The PTP clock is initialized prior to the netdevs and will have already