Initial Release
This commit is contained in:
5
clocks/CMakeLists.txt
Normal file
5
clocks/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
if (NOT PICO_NO_HARDWARE)
|
||||
add_subdirectory(hello_48MHz)
|
||||
add_subdirectory(hello_gpout)
|
||||
add_subdirectory(hello_resus)
|
||||
endif ()
|
||||
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;
|
||||
}
|
||||
12
clocks/hello_gpout/CMakeLists.txt
Normal file
12
clocks/hello_gpout/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(hello_gpout
|
||||
hello_gpout.c
|
||||
)
|
||||
|
||||
# Pull in our pico_stdlib which pulls in commonly used features
|
||||
target_link_libraries(hello_gpout pico_stdlib)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(hello_gpout)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(hello_gpout)
|
||||
23
clocks/hello_gpout/hello_gpout.c
Normal file
23
clocks/hello_gpout/hello_gpout.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
printf("Hello gpout\n");
|
||||
|
||||
// Output clk_sys / 10 to gpio 21, etc...
|
||||
clock_gpio_init(21, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_SYS, 10);
|
||||
clock_gpio_init(23, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_USB, 10);
|
||||
clock_gpio_init(24, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_ADC, 10);
|
||||
clock_gpio_init(26, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_RTC, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
12
clocks/hello_resus/CMakeLists.txt
Normal file
12
clocks/hello_resus/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(hello_resus
|
||||
hello_resus.c
|
||||
)
|
||||
|
||||
# Pull in our pico_stdlib which pulls in commonly used features
|
||||
target_link_libraries(hello_resus pico_stdlib)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(hello_resus)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(hello_resus)
|
||||
48
clocks/hello_resus/hello_resus.c
Normal file
48
clocks/hello_resus/hello_resus.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "hardware/pll.h"
|
||||
|
||||
volatile bool seen_resus;
|
||||
|
||||
void resus_callback(void) {
|
||||
// Reconfigure PLL sys back to the default state of 1500 / 6 / 2 = 125MHz
|
||||
pll_init(pll_sys, 1, 1500 * MHZ, 6, 2);
|
||||
|
||||
// CLK SYS = PLL SYS (125MHz) / 1 = 125MHz
|
||||
clock_configure(clk_sys,
|
||||
CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX,
|
||||
CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
|
||||
125 * MHZ,
|
||||
125 * MHZ);
|
||||
|
||||
// Reconfigure uart as clocks have changed
|
||||
stdio_init_all();
|
||||
printf("Resus event fired\n");
|
||||
|
||||
// Wait for uart output to finish
|
||||
uart_default_tx_wait_blocking();
|
||||
|
||||
seen_resus = true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
printf("Hello resus\n");
|
||||
|
||||
seen_resus = false;
|
||||
|
||||
clocks_enable_resus(&resus_callback);
|
||||
// Break PLL sys
|
||||
pll_deinit(pll_sys);
|
||||
|
||||
while(!seen_resus);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user