Initial Release
This commit is contained in:
12
clocks/hello_48MHz/CMakeLists.txt
Normal file
12
clocks/hello_48MHz/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(hello_48MHz
|
||||
hello_48MHz.c
|
||||
)
|
||||
|
||||
# Pull in our pico_stdlib which pulls in commonly used features
|
||||
target_link_libraries(hello_48MHz pico_stdlib hardware_clocks)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(hello_48MHz)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(hello_48MHz)
|
||||
68
clocks/hello_48MHz/hello_48MHz.c
Normal file
68
clocks/hello_48MHz/hello_48MHz.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/pll.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "hardware/structs/pll.h"
|
||||
#include "hardware/structs/clocks.h"
|
||||
|
||||
void measure_freqs(void) {
|
||||
uint f_pll_sys = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY);
|
||||
uint f_pll_usb = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_PLL_USB_CLKSRC_PRIMARY);
|
||||
uint f_rosc = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_ROSC_CLKSRC);
|
||||
uint f_clk_sys = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_CLK_SYS);
|
||||
uint f_clk_peri = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_CLK_PERI);
|
||||
uint f_clk_usb = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_CLK_USB);
|
||||
uint f_clk_adc = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_CLK_ADC);
|
||||
uint f_clk_rtc = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_CLK_RTC);
|
||||
|
||||
printf("pll_sys = %dkHz\n", f_pll_sys);
|
||||
printf("pll_usb = %dkHz\n", f_pll_usb);
|
||||
printf("rosc = %dkHz\n", f_rosc);
|
||||
printf("clk_sys = %dkHz\n", f_clk_sys);
|
||||
printf("clk_peri = %dkHz\n", f_clk_peri);
|
||||
printf("clk_usb = %dkHz\n", f_clk_usb);
|
||||
printf("clk_adc = %dkHz\n", f_clk_adc);
|
||||
printf("clk_rtc = %dkHz\n", f_clk_rtc);
|
||||
|
||||
// Can't measure clk_ref / xosc as it is the ref
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
|
||||
printf("Hello, world!\n");
|
||||
|
||||
measure_freqs();
|
||||
|
||||
// Change clk_sys to be 48MHz. The simplest way is to take this from PLL_USB
|
||||
// which has a source frequency of 48MHz
|
||||
clock_configure(clk_sys,
|
||||
CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX,
|
||||
CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_USB,
|
||||
48 * MHZ,
|
||||
48 * MHZ);
|
||||
|
||||
// Turn off PLL sys for good measure
|
||||
pll_deinit(pll_sys);
|
||||
|
||||
// CLK peri is clocked from clk_sys so need to change clk_peri's freq
|
||||
clock_configure(clk_peri,
|
||||
0,
|
||||
CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS,
|
||||
48 * MHZ,
|
||||
48 * MHZ);
|
||||
|
||||
// Re init uart now that clk_peri has changed
|
||||
stdio_init_all();
|
||||
|
||||
measure_freqs();
|
||||
printf("Hello, 48MHz");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user