From a61706fb2e3eff84deecb4cade048ec695fd2b6f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 4 May 2024 20:19:59 +0200 Subject: [PATCH] USB manual PLL control --- lib/lufa_config.h | 2 +- src/modules/usb_cdc.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/lufa_config.h b/lib/lufa_config.h index 2ae4f65..53eac10 100644 --- a/lib/lufa_config.h +++ b/lib/lufa_config.h @@ -7,7 +7,7 @@ #define FIXED_NUM_CONFIGURATIONS 1 #define INTERRUPT_CONTROL_ENDPOINT #define USE_FLASH_DESCRIPTORS -#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) +#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_MANUAL_PLL) #define NO_INTERNAL_SERIAL #define NO_DEVICE_SELF_POWER #define NO_DEVICE_REMOTE_WAKEUP diff --git a/src/modules/usb_cdc.cpp b/src/modules/usb_cdc.cpp index 15b8c34..0d4601a 100644 --- a/src/modules/usb_cdc.cpp +++ b/src/modules/usb_cdc.cpp @@ -90,6 +90,14 @@ namespace usb { CDC cdc; void CDC::Init() { +#if defined(USE_STATIC_OPTIONS) && (USE_STATIC_OPTIONS & USB_OPT_MANUAL_PLL) +#if defined(USB_SERIES_4_AVR) + PLLFRQ = ((1 << PLLUSB) | (1 << PDIV3) | (1 << PDIV1)); +#endif + USB_PLL_On(); + while (!(USB_PLL_IsReady())); +#endif + USB_Init(); /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */