Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow much more time for xosc to start #4

Merged
merged 1 commit into from
May 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
}
}