Skip to content

Commit

Permalink
Merge pull request #4 from dhalbert/lengthen-xosc-startup
Browse files Browse the repository at this point in the history
Allow much more time for xosc to start
  • Loading branch information
tannewt committed May 25, 2021
2 parents 7a66601 + 218b382 commit 49c0c16
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/rp2_common/hardware_xosc/xosc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
#include "hardware/regs/xosc.h"
#include "hardware/structs/xosc.h"

#define XOSC_STARTUP_DELAY_MULTIPLIER (64)

void xosc_init(void) {
// Assumes 1-15 MHz input
assert(XOSC_MHZ <= 15);
xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ;

// Set xosc startup delay
uint32_t startup_delay = (((12 * MHZ) / 1000) + 128) / 256;
xosc_hw->startup = startup_delay;
// Lengthen startup delay to accomodate slow-starting oscillators
xosc_hw->startup = startup_delay * XOSC_STARTUP_DELAY_MULTIPLIER;

// Set the enable bit now that we have set freq range and startup delay
hw_set_bits(&xosc_hw->ctrl, XOSC_CTRL_ENABLE_VALUE_ENABLE << XOSC_CTRL_ENABLE_LSB);
Expand All @@ -43,4 +46,4 @@ void xosc_dormant(void) {
xosc_hw->dormant = XOSC_DORMANT_VALUE_DORMANT;
// Wait for it to become stable once woken up
while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS));
}
}

0 comments on commit 49c0c16

Please sign in to comment.