No support for crystals other than 12MHz #1024
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#1024
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
The current runtime_init() invokes clocks_init() which is entirely hard-wired for crystal oscillator at 12MHz (and sets up PLLs assuming 12MHz base frequency), such that any board with a higher frequency crystal/external oscillator to XIN will fail before the user application gets a chance to reconfigure it.
Issue #748 requests support to heavily customise this startup behaviour (for example, if there is no crystal at all or it is undersirable to use it for power reasons). However, there is another class of applications that do want all the standard initialisation but simply have a crystal of different frequency (or an external clock wired to XIN). This could usefully be supported by allowing the board file to specify the crystal frequency.
There is already a symbol XOSC_MHZ defined in platform_defs.h, but this is almost entirely ignored in the setup code in clocks_init().
If the code in clocks_init() were updated to respect XOSC_MHZ, it could be overridden in the board file for boards with non-standard crystals.
One question is what setup is expected in respect of the PLLs. The minimum requirement is that the PLLs are not set up to out-of-range frequencies, causing a crash before the user program has a chance to do further setup. The ideal would be to set the desired PLL output frequencies for any crystal, but the PLL configuration tool is currently in the form of a python program not readily invoked during the build process. A compromise would be to allow the board file to define the PLL parameters, and for the code in clocks_init() to set the PLLs to x1 as a fallback if XOSC_MHZ != 12 and custom PLL parameters have not been defined.
Is the ideal solution to this to run vcocalc.py during the build to get the PLL configuration given the crystal frequency?
I might need this explaining to me...
Ideal in one sense, but making Python a dependency of the build system may not be considered justified for just this feature.
I simply meant that if the init code doesn't have access to sensible PLL parameters (by calculating them, or having them passed in through defines in the board file) then it can simply use the crystal frequency as clk_sys as that's always safe, and the application can sort things out later. Probably that's more sensibly done by bypassing the PLLs rather than literally setting them to a x1 configuration.
@andygpz11 I might need your advice on this
Sure @peterharperuk
Actually I'll assign it to me.
note i think the scope of this is to respect XOSC_MHZ. i would prefer not to use vcocalc during the build, but perhaps as suggested use new #defines. See if this looks neat/tidy without building a bunch of infrastructure, because we do have a separate issue for configurable startup.
@kilograham Having looked at the code I completely agree: Running from ROSC etc. is beyond scope of this ticket.
For this, we could & should do a better job and respect XOSC_MHZ. I think that can be done relatively easily, at least for common/standard integer type frequencies.
Perhaps we should add some static_asserts and/or warnings where the math(s) won't allow us to get an exact 48 MHz clock for the USB operations?
Not everyone will need USB connectivity but it needs to be flagged.
My thinking was:
#1272 is merged into develop; this allows customization of PLLs and Clock frequencies