diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-12-02 13:40:04 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-12-02 13:40:04 +0100 |
commit | e1526bb2c84b315c72a089dbb50447183d4b1685 (patch) | |
tree | f16d8fec3726dcfccf8640c1ce23ecf71213da0c /src/arch/msp430fr5994lp/arch.cc | |
parent | 0dbd065d0d0756a8645cdfb71f6572abfa0d013e (diff) |
msp430fr5994lp: add 16MHz HFXT clock source support
Diffstat (limited to 'src/arch/msp430fr5994lp/arch.cc')
-rw-r--r-- | src/arch/msp430fr5994lp/arch.cc | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/arch/msp430fr5994lp/arch.cc b/src/arch/msp430fr5994lp/arch.cc index 4edab89..b247da3 100644 --- a/src/arch/msp430fr5994lp/arch.cc +++ b/src/arch/msp430fr5994lp/arch.cc @@ -56,15 +56,53 @@ void Arch::setup(void) // enable LXFT for RTC CSCTL0_H = CSKEY >> 8; CSCTL4 &= ~LFXTOFF; - while (SFRIFG1 & OFIFG) { + while (CSCTL5 & LFXTOFFG) { CSCTL5 &= ~LFXTOFFG; - SFRIFG1 &= ~OFIFG; } + SFRIFG1 &= ~OFIFG; CSCTL0_H = 0; __delay_cycles(1000000); #endif +#ifdef WITH_HFXT_16MHZ + PJSEL0 |= BIT6 | BIT7; + CSCTL0_H = CSKEY >> 8; + + // set HFFREQ to 8-16 MHz (HFFREQ=10) + CSCTL4 = HFXTDRIVE_0 | HFFREQ_2 | (CSCTL4 & 0x0f); + + // enable HFXT for SMCLK + while (CSCTL5 & HFXTOFFG) { + CSCTL5 &= ~HFXTOFFG; + } + SFRIFG1 &= ~OFIFG; + CSCTL0_H = 0; + + // wait for it to stabilize + __delay_cycles(1000000); + + // set MCLK and SMCLK to HFXT + CSCTL0_H = CSKEY >> 8; +#if F_CPU == 16000000UL + CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; +#elif F_CPU == 8000000UL + CSCTL3 = DIVA__1 | DIVS__2 | DIVM__2; +#elif F_CPU == 4000000UL + CSCTL3 = DIVA__1 | DIVS__4 | DIVM__4; +#elif F_CPU == 1000000UL + CSCTL3 = DIVA__1 | DIVS__16 | DIVM__16; +#endif + // SELA__LFXTCLK falls back to VLOCLK if LFXT is not available, but set + // LFXT_FAULT (LFXTOFFG) in the process. We don't want that. +#if defined(WITH_LOOP) || F_CPU == 32768UL + CSCTL2 = SELA__LFXTCLK | SELS__HFXTCLK | SELM__HFXTCLK; +#else + CSCTL2 = SELA__VLOCLK | SELS__HFXTCLK | SELM__HFXTCLK; +#endif + CSCTL0_H = 0; +#endif + #ifdef TIMER_US #if F_CPU == 16000000UL TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; // /8 |