Skip to content

Commit df044f4

Browse files
committed
cpu/stm32/periph/usbdev_fs: avoid using ztimer when not needed
Signed-off-by: Dylan Laduranty <[email protected]>
1 parent db51ad7 commit df044f4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

cpu/stm32/Makefile.dep

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ ifneq (,$(filter periph_usbdev,$(FEATURES_USED)))
77
ifneq (,$(filter f2 f4 f7 h7 u5,$(CPU_FAM)))
88
# Whole STM32 families F2, F4, F7, H7 and U5 use the Synopsys DWC2 USB OTG core
99
USEMODULE += usbdev_synopsys_dwc2
10+
USEMODULE += ztimer
11+
USEMODULE += ztimer_msec
1012
else ifneq (,$(filter stm32f105% stm32f107%,$(CPU_MODEL)))
1113
# STM32F105xx and STM32F107xx also use the Synopsys DWC2 USB OTG core
1214
USEMODULE += usbdev_synopsys_dwc2
15+
USEMODULE += ztimer
16+
USEMODULE += ztimer_msec
1317
else ifneq (,$(filter stm32l47% stm32l48% stm32l49%,$(CPU_MODEL)))
1418
# STM32L475xx, STM32L476xx, STM32L485xx, STM32L486xx and STM32L496xx
1519
# also use the Synopsys DWC2 USB OTG core
1620
USEMODULE += usbdev_synopsys_dwc2
21+
USEMODULE += ztimer
22+
USEMODULE += ztimer_msec
1723
else ifneq (,$(filter stm32l4a% stm32l4p% stm32l4q% stm32l4r% stm32l4s%,$(CPU_MODEL)))
1824
# STM32L4Axxx, STM32L4Pxxx, STM32L4Qxxx, STM32L4Rxxx and STM32L4Sxxx
1925
# also use the Synopsys DWC2 USB OTG core
2026
USEMODULE += usbdev_synopsys_dwc2
27+
USEMODULE += ztimer
28+
USEMODULE += ztimer_msec
2129
endif
22-
USEMODULE += ztimer
23-
USEMODULE += ztimer_msec
2430
endif
2531

2632
ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE)))

cpu/stm32/periph/usbdev_fs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "usbdev_stm32.h"
3333
#include "pm_layered.h"
3434
#include "ztimer.h"
35+
#include "busy_wait.h"
3536

3637
#include <string.h>
3738
/**
@@ -218,7 +219,15 @@ static void _enable_gpio(const stm32_usbdev_fs_config_t *conf)
218219
gpio_init(conf->dp, GPIO_OUT);
219220
gpio_clear(conf->dp);
220221
/* wait a 1 ms */
221-
ztimer_sleep(ZTIMER_MSEC, 1);
222+
if (IS_USED(MODULE_ZTIMER_MSEC)) {
223+
ztimer_sleep(ZTIMER_MSEC, 1);
224+
}
225+
else if(IS_USED(MODULE_ZTIMER_USEC)) {
226+
ztimer_sleep(ZTIMER_USEC, 1 * US_PER_MS);
227+
}
228+
else {
229+
busy_wait_us(1 * US_PER_MS);
230+
}
222231
gpio_init(conf->dp, GPIO_IN);
223232
}
224233
if (conf->af != GPIO_AF_UNDEF) {

0 commit comments

Comments
 (0)