From a61706fb2e3eff84deecb4cade048ec695fd2b6f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 4 May 2024 20:19:59 +0200 Subject: [PATCH 1/3] 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 2ae4f65d..53eac105 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 15b8c346..0d4601af 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 */ From fa225130cd736c8857025c244d8d56991fa4589e Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 4 May 2024 20:20:27 +0200 Subject: [PATCH 2/3] Use single banks for CDC --- src/modules/usb_cdc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/usb_cdc.cpp b/src/modules/usb_cdc.cpp index 0d4601af..7e738e1b 100644 --- a/src/modules/usb_cdc.cpp +++ b/src/modules/usb_cdc.cpp @@ -25,13 +25,13 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = { .Address = CDC_TX_EPADDR, .Size = CDC_TXRX_EPSIZE, .Type = EP_TYPE_BULK, - .Banks = 2, + .Banks = 1, }, .DataOUTEndpoint = { .Address = CDC_RX_EPADDR, .Size = CDC_TXRX_EPSIZE, .Type = EP_TYPE_BULK, - .Banks = 2, + .Banks = 1, }, .NotificationEndpoint = { .Address = CDC_NOTIFICATION_EPADDR, From 1f43fa076db5ce6731aee08b3bb06022cc0b1a8f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 4 May 2024 20:20:47 +0200 Subject: [PATCH 3/3] Optimize LUFA config for size --- lib/Descriptors.h | 10 +++++----- lib/lufa_config.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Descriptors.h b/lib/Descriptors.h index b6789d6e..8fd409da 100644 --- a/lib/Descriptors.h +++ b/lib/Descriptors.h @@ -42,14 +42,14 @@ #include "lufa/LUFA/Drivers/USB/USB.h" /* Macros: */ -/** Endpoint address of the CDC device-to-host notification IN endpoint. */ -#define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) - /** Endpoint address of the CDC device-to-host data IN endpoint. */ -#define CDC_TX_EPADDR (ENDPOINT_DIR_IN | 3) +#define CDC_TX_EPADDR (ENDPOINT_DIR_IN | 1) /** Endpoint address of the CDC host-to-device data OUT endpoint. */ -#define CDC_RX_EPADDR (ENDPOINT_DIR_OUT | 4) +#define CDC_RX_EPADDR (ENDPOINT_DIR_OUT | 2) + +/** Endpoint address of the CDC device-to-host notification IN endpoint. */ +#define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 3) /** Size in bytes of the CDC device-to-host notification IN endpoint. */ #define CDC_NOTIFICATION_EPSIZE 8 diff --git a/lib/lufa_config.h b/lib/lufa_config.h index 53eac105..d9e25c72 100644 --- a/lib/lufa_config.h +++ b/lib/lufa_config.h @@ -2,7 +2,7 @@ #define USB_DEVICE_ONLY #define DEVICE_STATE_AS_GPIOR 0 -// #define ORDERED_EP_CONFIG +#define ORDERED_EP_CONFIG #define FIXED_CONTROL_ENDPOINT_SIZE 8 #define FIXED_NUM_CONFIGURATIONS 1 #define INTERRUPT_CONTROL_ENDPOINT @@ -11,7 +11,7 @@ #define NO_INTERNAL_SERIAL #define NO_DEVICE_SELF_POWER #define NO_DEVICE_REMOTE_WAKEUP -// #define NO_SOF_EVENTS +#define NO_SOF_EVENTS #define F_USB F_CPU #define DEVICE_VID 0x2C99 #define DEVICE_PID 0x0004