Allow lengthening xosc startup delay with a compile option (#457)
This commit is contained in:
parent
42cbdcb13a
commit
d026118499
@ -15,6 +15,11 @@
|
||||
// For board detection
|
||||
#define ADAFRUIT_FEATHER_RP2040
|
||||
|
||||
// On some samples, the xosc can take longer to stabilize than is usual
|
||||
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
|
||||
#endif
|
||||
|
||||
//------------- UART -------------//
|
||||
#ifndef PICO_DEFAULT_UART
|
||||
#define PICO_DEFAULT_UART 0
|
||||
|
@ -15,6 +15,11 @@
|
||||
// For board detection
|
||||
#define ADAFRUIT_ITSYBITSY_RP2040
|
||||
|
||||
// On some samples, the xosc can take longer to stabilize than is usual
|
||||
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
|
||||
#endif
|
||||
|
||||
//------------- UART -------------//
|
||||
#ifndef PICO_DEFAULT_UART
|
||||
#define PICO_DEFAULT_UART 0
|
||||
|
@ -15,6 +15,11 @@
|
||||
// For board detection
|
||||
#define ADAFRUIT_QTPY_RP2040
|
||||
|
||||
// On some samples, the xosc can take longer to stabilize than is usual
|
||||
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
|
||||
#endif
|
||||
|
||||
//------------- UART -------------//
|
||||
#ifndef PICO_DEFAULT_UART
|
||||
#define PICO_DEFAULT_UART 1
|
||||
|
@ -10,6 +10,15 @@
|
||||
#include "pico.h"
|
||||
#include "hardware/structs/xosc.h"
|
||||
|
||||
|
||||
// Allow lengthening startup delay to accommodate slow-starting oscillators
|
||||
|
||||
// PICO_CONFIG: PICO_XOSC_STARTUP_DELAY_MULTIPLIER, Multiplier to lengthen xosc startup delay to accommodate slow-starting oscillators, type=int, min=1, default=1, group=hardware_xosc
|
||||
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -11,16 +11,25 @@
|
||||
|
||||
#include "hardware/platform_defs.h"
|
||||
#include "hardware/regs/xosc.h"
|
||||
#include "hardware/structs/xosc.h"
|
||||
#include "hardware/xosc.h"
|
||||
|
||||
#if XOSC_MHZ < 1 || XOSC_MHZ > 15
|
||||
#error XOSC_MHZ must be in the range 1-15
|
||||
#endif
|
||||
|
||||
#define STARTUP_DELAY (((((XOSC_MHZ * MHZ) / 1000) + 128) / 256) * PICO_XOSC_STARTUP_DELAY_MULTIPLIER)
|
||||
|
||||
// The DELAY field in xosc_hw->startup is 14 bits wide.
|
||||
#if STARTUP_DELAY >= (1 << 13)
|
||||
#error PICO_XOSC_STARTUP_DELAY_MULTIPLIER is too large: XOSC STARTUP.DELAY must be < 8192
|
||||
#endif
|
||||
|
||||
void xosc_init(void) {
|
||||
// Assumes 1-15 MHz input
|
||||
assert(XOSC_MHZ <= 15);
|
||||
// Assumes 1-15 MHz input, checked above.
|
||||
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;
|
||||
xosc_hw->startup = STARTUP_DELAY;
|
||||
|
||||
// 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);
|
||||
@ -43,4 +52,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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user