mirror of https://github.com/MLXXXp/Arduboy2.git
Fix setting CPU clock to 8MHz
A dedicated #define is used. The PLL prescaler for USB is readjusted.
This commit is contained in:
parent
f6e7ee40e7
commit
ded48cef81
|
@ -93,8 +93,9 @@ ArduboyCore::ArduboyCore() {}
|
|||
|
||||
void ArduboyCore::boot()
|
||||
{
|
||||
#if F_CPU == 8000000L
|
||||
bootCPUSpeed();
|
||||
#ifdef ARDUBOY_SET_CPU_8MHZ
|
||||
// ARDUBOY_SET_CPU_8MHZ will be set by the IDE using boards.txt
|
||||
setCPUSpeed8MHz();
|
||||
#endif
|
||||
|
||||
SPI.begin();
|
||||
|
@ -109,15 +110,19 @@ void ArduboyCore::boot()
|
|||
bootPowerSaving();
|
||||
}
|
||||
|
||||
#if F_CPU == 8000000L
|
||||
// if we're compiling for 8Mhz we need to slow the CPU down because the
|
||||
// hardware clock on the Arduboy is 16MHz
|
||||
void ArduboyCore::bootCPUSpeed()
|
||||
#ifdef ARDUBOY_SET_CPU_8MHZ
|
||||
// If we're compiling for 8MHz we need to slow the CPU down because the
|
||||
// hardware clock on the Arduboy is 16MHz.
|
||||
// We also need to readjust the PLL prescaler because the Arduino USB code
|
||||
// likely will have incorrectly set it for an 8MHz hardware clock.
|
||||
void ArduboyCore::setCPUSpeed8MHz()
|
||||
{
|
||||
uint8_t oldSREG = SREG;
|
||||
cli(); // suspend interrupts
|
||||
PLLCSR = _BV(PINDIV); // dissable the PLL and set prescale for 16MHz)
|
||||
CLKPR = _BV(CLKPCE); // allow reprogramming clock
|
||||
CLKPR = 1; // set clock divisor to 2 (0b0001)
|
||||
PLLCSR = _BV(PLLE) | _BV(PINDIV); // enable the PLL (with 16MHz prescale)
|
||||
SREG = oldSREG; // restore interrupts
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -283,9 +283,9 @@ protected:
|
|||
void static inline safeMode() __attribute__((always_inline));
|
||||
|
||||
// internals
|
||||
void static inline setCPUSpeed8MHz() __attribute__((always_inline));
|
||||
void static inline bootOLED() __attribute__((always_inline));
|
||||
void static inline bootPins() __attribute__((always_inline));
|
||||
void static inline bootCPUSpeed() __attribute__((always_inline));
|
||||
void static inline bootPowerSaving() __attribute__((always_inline));
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue