From 84a11e746f5a445e80eb9b6a21c9768a9e06bc6c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 5 Nov 2020 12:49:07 -0700 Subject: [PATCH] Reduce AVR clock to 8MHz --- keyboards/system76/launch_beta_1/rules.mk | 6 ++++-- tmk_core/protocol/lufa/lufa.c | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/keyboards/system76/launch_beta_1/rules.mk b/keyboards/system76/launch_beta_1/rules.mk index bc8d6fe734a..85774a90d48 100644 --- a/keyboards/system76/launch_beta_1/rules.mk +++ b/keyboards/system76/launch_beta_1/rules.mk @@ -4,8 +4,10 @@ MCU = atmega32u4 # Allow flashing with usbasp AVRDUDE_MCU = $(MCU) -# Processor frequency -F_CPU = 16000000 +# CPU frequency divided by two since AVR is at 3.3V +F_CPU = 8000000 +# External oscillator is 16Mhz +F_USB = 16000000 # Bootloader selection # Teensy halfkay diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 8319b34e94d..46a65c27aae 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -917,8 +917,14 @@ static void setup_mcu(void) { MCUSR &= ~_BV(WDRF); wdt_disable(); +// HACK for System76 boards with AVR at 3.3V and crystal at 16 MHz +#if (F_CPU == 8000000 && F_USB == 16000000) + /* Divide clock by 2 */ + clock_prescale_set(clock_div_2); +#else /* Disable clock division */ clock_prescale_set(clock_div_1); +#endif } /** \brief Setup USB