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
|
// 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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user