diff --git a/bootloaders/riotboot_dfu/Makefile b/bootloaders/riotboot_dfu/Makefile index 86995d3119..4a943449c9 100644 --- a/bootloaders/riotboot_dfu/Makefile +++ b/bootloaders/riotboot_dfu/Makefile @@ -5,7 +5,8 @@ APPLICATION = riotboot_dfu USEMODULE += riotboot_usb_dfu # Use xtimer for scheduled reboot -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_auto_init # USB device vendor and product ID # pid.codes test VID/PID, not globally unique diff --git a/bootloaders/riotboot_dfu/main.c b/bootloaders/riotboot_dfu/main.c index ebf876042b..91606817b5 100644 --- a/bootloaders/riotboot_dfu/main.c +++ b/bootloaders/riotboot_dfu/main.c @@ -26,6 +26,7 @@ #include "panic.h" #include "riotboot/slot.h" #include "riotboot/usb_dfu.h" +#include "ztimer.h" #include "bootloader_selection.h" @@ -70,6 +71,9 @@ void kernel_init(void) riotboot_slot_jump(slot); } + /* Init ztimer before starting DFU mode */ + ztimer_init(); + /* Nothing to boot, stay in DFU mode to flash a slot */ riotboot_usb_dfu_init(1); } diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 50112e29f3..a5a10a8e27 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -690,6 +690,7 @@ endif ifneq (,$(filter riotboot_usb_dfu, $(USEMODULE))) USEMODULE += usbus_dfu USEMODULE += riotboot_flashwrite + USEMODULE += ztimer_sec FEATURES_REQUIRED += no_idle_thread FEATURES_REQUIRED += periph_pm endif diff --git a/sys/usb/usbus/dfu/dfu.c b/sys/usb/usbus/dfu/dfu.c index ee1a26409b..37ea5de470 100644 --- a/sys/usb/usbus/dfu/dfu.c +++ b/sys/usb/usbus/dfu/dfu.c @@ -26,7 +26,7 @@ #include "riotboot/magic.h" #include "riotboot/usb_dfu.h" #ifdef MODULE_RIOTBOOT_USB_DFU -#include "xtimer.h" +#include "ztimer.h" #endif #include "periph/pm.h" @@ -48,7 +48,7 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler); #ifdef MODULE_RIOTBOOT_USB_DFU static void _reboot(void *arg); -static xtimer_t scheduled_reboot = { .callback=_reboot }; +static ztimer_t scheduled_reboot = { .callback=_reboot }; #define REBOOT_DELAY 2 #endif @@ -151,9 +151,6 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) /* attached alternate settings to their interface */ usbus_add_interface_alt(&dfu->iface, &dfu->iface_alt_slot1); - - /* Start xtimer for scheduled reboot after firmware upgrade */ - xtimer_init(); #endif /* Add interface to the stack */ usbus_add_interface(usbus, &dfu->iface); @@ -217,7 +214,7 @@ static void _dfu_class_control_req(usbus_t *usbus, usbus_dfu_device_t *dfu, usb_ /* Scheduled reboot, so we can answer back dfu-util before rebooting */ dfu->dfu_state = USB_DFU_STATE_DFU_DL_IDLE; #ifdef MODULE_RIOTBOOT_USB_DFU - xtimer_set(&scheduled_reboot, 1 * US_PER_SEC); + ztimer_set(ZTIMER_SEC, &scheduled_reboot, 1); #endif } memset(&buf, 0, sizeof(buf)); diff --git a/sys/ztimer/auto_init.c b/sys/ztimer/auto_init.c index 7dc2f2de2b..b24fdeb1fe 100644 --- a/sys/ztimer/auto_init.c +++ b/sys/ztimer/auto_init.c @@ -37,7 +37,7 @@ */ #include "kernel_defines.h" -#if IS_USED(MODULE_AUTO_INIT_ZTIMER) +#if IS_USED(MODULE_AUTO_INIT_ZTIMER) || RIOTBOOT #include "board.h" #include "ztimer.h" @@ -302,4 +302,4 @@ void ztimer_init(void) # endif #endif } -#endif /* IS_USED(MODULE_AUTO_INIT_ZTIMER) */ +#endif /* IS_USED(MODULE_AUTO_INIT_ZTIMER) || RIOTBOOT*/