Allow lengthening xosc startup delay with a compile option #457
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!457
Loading…
Reference in a new issue
No description provided.
Delete branch "flexible-xosc-startup-time"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR allows you to specify a multiplier, at compile time to lengthen the default XOSC startup time. The multiplier,
PICO_XOSC_STARTUP_DELAY_MULTIPLIER, is1by default.Motivation: On a few samples of some Adafruit RP2040 boards, the XOSC takes much longer to stabilize than would be expected. This appears to be due to some mismatch between the chosen XOSC crystal and capacitors. Sometimes the problem is intermittent, and may depend on handling the board while restarting, humidity, etc. We are going to fix future boards, but this PR is a software fix that accommodates all boards.
The Adafruit board include files set
PICO_XOSC_STARTUP_DELAY_MULTIPLIERto be 64. This was chosen empirically. 16 can be too low sometimes. 32 seems to work, and so 64 includes a safety margin.This issue has been discussed at length in #401. The default XOSC startup time is used in the boot ROM when using USB, but the XOSC startup problem does not seem to be an issue: the boards all can connect to USB successfully. Also relevant: https://github.com/raspberrypi/pico-feedback/issues/158/.
I've tested this on an Adafruit QT Py RP2040 that exhibits the problem, with the
pico-examplesblinkexample.One minor thing:
xosc.cdid not end in a newline, and my editor fixed that automatically.@ -11,16 +11,25 @@#include "hardware/platform_defs.h"#include "hardware/regs/xosc.h"Can you change this to a
// PICO_CONFIG:so that it shows up in the docs (see other places)@ -11,16 +11,25 @@#include "hardware/platform_defs.h"#include "hardware/regs/xosc.h"Sure. Should I also do some kind of checking on the value to make sure the resultant multiplication doesn't overflow the register field of 14 bits? The
structdefinition for the register does not take that into account.@ -11,16 +11,25 @@#include "hardware/platform_defs.h"#include "hardware/regs/xosc.h"github.com/raspberrypi/pico-sdk@afc10f3599/src/rp2040/hardware_structs/include/hardware/structs/xosc.h (L15-L22)I pushed a
PICO_CONFIG:fix, though I'm a little confused as to where I should see it. I built the doxygen docs andPICO_XOSC_STARTUP_DELAY_MULTIPLIERshows up in thedoxygen/xml/but not thedoxygen/html. However, there are many otherPICO_CONFIG'd definitions that similarly are only in the xml. They don't show up in the search, for instance.The
PICO_CONFIGentries are extracted bytools/extract_configs.pytopico_configs.tsvwhich is then used by e.g. https://github.com/raspberrypi/pico-project-generatorThey're also included into Appendix B of https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-c-sdk.pdf by internal build-tools.
@ -11,16 +11,25 @@#include "hardware/platform_defs.h"#include "hardware/regs/xosc.h"yes makes sense - please follow invalid_params_if() style... (which will require you to add some macros to xosc.h - just copy/paste from somewhere else)
I ended up not using
invalid_params_if(), which seems more meant for run-time checking. Instead I did some cpp-compile-time checking, which is done similarly in other places.Most recent changes:
XOSC_MHZis in range (was done with anassert()).XOSC_MHZinstead of the literal12in the delay calculation.@ -11,16 +11,25 @@#include "hardware/platform_defs.h"#include "hardware/regs/xosc.h"stylistically (going forward, there may be a few stragglers) we are trying to put these defaulted values in the header in case any other code (source files) cares about the actual value. can you move this to xsoc.h
@ -11,16 +11,25 @@#include "hardware/platform_defs.h"#include "hardware/regs/xosc.h"Sure. Moved PICO_CONFIG and default setting to
src/rp2_common/hardware_xosc/include/hardware/xosc.h, and changed#includein xosc.c to accommodate this.@ebenupton this was the clock delay thingy that we thought was crystal-load-cap-related but now we're not so sure