Allow lengthening xosc startup delay with a compile option (#457)

This commit is contained in:
Dan Halbert 2021-06-01 15:24:40 -04:00 committed by GitHub
parent 42cbdcb13a
commit d026118499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 6 deletions

View File

@ -15,6 +15,11 @@
// For board detection // For board detection
#define ADAFRUIT_FEATHER_RP2040 #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 -------------// //------------- UART -------------//
#ifndef PICO_DEFAULT_UART #ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0 #define PICO_DEFAULT_UART 0

View File

@ -15,6 +15,11 @@
// For board detection // For board detection
#define ADAFRUIT_ITSYBITSY_RP2040 #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 -------------// //------------- UART -------------//
#ifndef PICO_DEFAULT_UART #ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0 #define PICO_DEFAULT_UART 0

View File

@ -15,6 +15,11 @@
// For board detection // For board detection
#define ADAFRUIT_QTPY_RP2040 #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 -------------// //------------- UART -------------//
#ifndef PICO_DEFAULT_UART #ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 1 #define PICO_DEFAULT_UART 1

View File

@ -10,6 +10,15 @@
#include "pico.h" #include "pico.h"
#include "hardware/structs/xosc.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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -11,16 +11,25 @@
#include "hardware/platform_defs.h" #include "hardware/platform_defs.h"
#include "hardware/regs/xosc.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) { void xosc_init(void) {
// Assumes 1-15 MHz input // Assumes 1-15 MHz input, checked above.
assert(XOSC_MHZ <= 15);
xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ; xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ;
// Set xosc startup delay // 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 // 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); 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; xosc_hw->dormant = XOSC_DORMANT_VALUE_DORMANT;
// Wait for it to become stable once woken up // Wait for it to become stable once woken up
while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)); while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS));
} }