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,9 +93,10 @@ ArduboyCore::ArduboyCore() {}
|
||||||
|
|
||||||
void ArduboyCore::boot()
|
void ArduboyCore::boot()
|
||||||
{
|
{
|
||||||
#if F_CPU == 8000000L
|
#ifdef ARDUBOY_SET_CPU_8MHZ
|
||||||
bootCPUSpeed();
|
// ARDUBOY_SET_CPU_8MHZ will be set by the IDE using boards.txt
|
||||||
#endif
|
setCPUSpeed8MHz();
|
||||||
|
#endif
|
||||||
|
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
bootPins();
|
bootPins();
|
||||||
|
@ -109,15 +110,19 @@ void ArduboyCore::boot()
|
||||||
bootPowerSaving();
|
bootPowerSaving();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if F_CPU == 8000000L
|
#ifdef ARDUBOY_SET_CPU_8MHZ
|
||||||
// if we're compiling for 8Mhz we need to slow the CPU down because the
|
// If we're compiling for 8MHz we need to slow the CPU down because the
|
||||||
// hardware clock on the Arduboy is 16MHz
|
// hardware clock on the Arduboy is 16MHz.
|
||||||
void ArduboyCore::bootCPUSpeed()
|
// 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;
|
uint8_t oldSREG = SREG;
|
||||||
cli(); // suspend interrupts
|
cli(); // suspend interrupts
|
||||||
|
PLLCSR = _BV(PINDIV); // dissable the PLL and set prescale for 16MHz)
|
||||||
CLKPR = _BV(CLKPCE); // allow reprogramming clock
|
CLKPR = _BV(CLKPCE); // allow reprogramming clock
|
||||||
CLKPR = 1; // set clock divisor to 2 (0b0001)
|
CLKPR = 1; // set clock divisor to 2 (0b0001)
|
||||||
|
PLLCSR = _BV(PLLE) | _BV(PINDIV); // enable the PLL (with 16MHz prescale)
|
||||||
SREG = oldSREG; // restore interrupts
|
SREG = oldSREG; // restore interrupts
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -283,9 +283,9 @@ protected:
|
||||||
void static inline safeMode() __attribute__((always_inline));
|
void static inline safeMode() __attribute__((always_inline));
|
||||||
|
|
||||||
// internals
|
// internals
|
||||||
|
void static inline setCPUSpeed8MHz() __attribute__((always_inline));
|
||||||
void static inline bootOLED() __attribute__((always_inline));
|
void static inline bootOLED() __attribute__((always_inline));
|
||||||
void static inline bootPins() __attribute__((always_inline));
|
void static inline bootPins() __attribute__((always_inline));
|
||||||
void static inline bootCPUSpeed() __attribute__((always_inline));
|
|
||||||
void static inline bootPowerSaving() __attribute__((always_inline));
|
void static inline bootPowerSaving() __attribute__((always_inline));
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue