Skip to content

Commit 305489f

Browse files
Add a picow_blink_fast_clock example (#511)
* Add a picow_blink_fast_clock example We have picow_blink_slow_clock, so we probably need an example of running it faster?
1 parent 70222a8 commit 305489f

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ App|Description
171171
---|---
172172
[picow_access_point](pico_w/wifi/access_point) | Starts a WiFi access point, and fields DHCP requests.
173173
[picow_blink](pico_w/wifi/blink) | Blinks the on-board LED (which is connected via the WiFi chip).
174-
[picow_blink_slow_clock](pico_w/wifi/blink_slow_clock) | Blinks the on-board LED (which is connected via the WiFi chip) with a slower system clock to show how to reconfigure communication with the WiFi chip under those circumstances
174+
[picow_blink_slow_clock](pico_w/wifi/blink) | Blinks the on-board LED (which is connected via the WiFi chip) with a slower system clock to show how to reconfigure communication with the WiFi chip at run time under those circumstances
175+
[picow_blink_fast_clock](pico_w/wifi/blink) | Blinks the on-board LED (which is connected via the WiFi chip) with a faster system clock to show how to reconfigure communication with the WiFi chip at build time under those circumstances
175176
[picow_iperf_server](pico_w/wifi/iperf) | Runs an "iperf" server for WiFi speed testing.
176177
[picow_ntp_client](pico_w/wifi/ntp_client) | Connects to an NTP server to fetch and display the current time.
177178
[picow_tcp_client](pico_w/wifi/tcp_client) | A simple TCP client. You can run [python_test_tcp_server.py](pico_w/wifi/python_test_tcp/python_test_tcp_server.py) for it to connect to.

pico_w/wifi/blink/CMakeLists.txt

+22-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pico_add_extra_outputs(picow_blink)
1212
# add url via pico_set_program_url
1313
example_auto_set_url(picow_blink)
1414

15-
# This version should behave exactly the same, but it runs the sys clock slowly.
15+
# This version should behave exactly the same, but it runs the sys clock slower and changes the pio pio clock divisor for the cyw43 driver at run time.
1616
add_executable(picow_blink_slow_clock
1717
picow_blink_slow_clock.c
1818
)
@@ -31,3 +31,24 @@ pico_add_extra_outputs(picow_blink_slow_clock)
3131

3232
# add url via pico_set_program_url
3333
example_auto_set_url(picow_blink_slow_clock)
34+
35+
# This version should behave exactly the same, but it runs the sys clock faster and changes the pio pio clock divisor for the cyw43 driver at build time.
36+
add_executable(picow_blink_fast_clock
37+
picow_blink_fast_clock.c
38+
)
39+
target_link_libraries(picow_blink_fast_clock
40+
pico_stdlib # for core functionality
41+
pico_cyw43_arch_none # we need Wifi to access the GPIO, but we don't need anything else
42+
hardware_clocks
43+
)
44+
# This requires us to modify the pio divisor to successfully communicate with the cyw43 chip
45+
target_compile_definitions(picow_blink_fast_clock PRIVATE
46+
CYW43_PIO_CLOCK_DIV_INT=4
47+
CYW43_PIO_CLOCK_DIV_FRAC8=0
48+
)
49+
50+
# create map/bin/hex file etc.
51+
pico_add_extra_outputs(picow_blink_fast_clock)
52+
53+
# add url via pico_set_program_url
54+
example_auto_set_url(picow_blink_fast_clock)
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include "pico/stdlib.h"
8+
#include "pico/cyw43_arch.h"
9+
#include "pico/cyw43_driver.h"
10+
#include "hardware/clocks.h"
11+
12+
int main() {
13+
// Increase sys clock. We have slowed down the cyw43 pio to compensate using CYW43_PIO_CLOCK_DIV_INT=4 CYW43_PIO_CLOCK_DIV_FRAC=0 in the cmake file
14+
// By default the pio used to communicate with cyw43 runs with a clock divisor of 2
15+
// if you modify the clock you will have to compensate for this
16+
// As an alternative you could specify CYW43_PIO_CLOCK_DIV_DYNAMIC=1 in your cmake file and call cyw43_set_pio_clock_divisor(4, 0)
17+
set_sys_clock_khz(266000, true);
18+
19+
stdio_init_all();
20+
if (cyw43_arch_init()) {
21+
printf("Wi-Fi init failed");
22+
return -1;
23+
}
24+
while (true) {
25+
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
26+
sleep_ms(250);
27+
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
28+
sleep_ms(250);
29+
}
30+
}

0 commit comments

Comments
 (0)