From e53235c2462dd2d3b20c7481ed3afd7053d9531c Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Fri, 9 Aug 2024 11:38:35 +0100 Subject: [PATCH] Add a picow_blink_fast_clock example We have picow_blink_slow_clock, so we probably need an example of running it faster? --- README.md | 1 + pico_w/wifi/blink/CMakeLists.txt | 21 +++++++++++++++ pico_w/wifi/blink/picow_blink_fast_clock.c | 30 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 pico_w/wifi/blink/picow_blink_fast_clock.c diff --git a/README.md b/README.md index 7170139fe..514801f38 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ App|Description [picow_access_point](pico_w/wifi/access_point) | Starts a WiFi access point, and fields DHCP requests. [picow_blink](pico_w/wifi/blink) | Blinks the on-board LED (which is connected via the WiFi chip). [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 +[picow_blink_fast_clock](pico_w/wifi/blink_slow_clock) | 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 under those circumstances [picow_iperf_server](pico_w/wifi/iperf) | Runs an "iperf" server for WiFi speed testing. [picow_ntp_client](pico_w/wifi/ntp_client) | Connects to an NTP server to fetch and display the current time. [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. diff --git a/pico_w/wifi/blink/CMakeLists.txt b/pico_w/wifi/blink/CMakeLists.txt index 1fd548391..b4444a3f0 100644 --- a/pico_w/wifi/blink/CMakeLists.txt +++ b/pico_w/wifi/blink/CMakeLists.txt @@ -31,3 +31,24 @@ pico_add_extra_outputs(picow_blink_slow_clock) # add url via pico_set_program_url example_auto_set_url(picow_blink_slow_clock) + +# This version should behave exactly the same, but it runs the sys clock slowly. +add_executable(picow_blink_fast_clock + picow_blink_fast_clock.c + ) +target_link_libraries(picow_blink_fast_clock + pico_stdlib # for core functionality + pico_cyw43_arch_none # we need Wifi to access the GPIO, but we don't need anything else + hardware_clocks + ) +# This requires us to modify the pio divisor to successfully communicate with the cyw43 chip +target_compile_definitions(picow_blink_fast_clock PRIVATE + CYW43_PIO_CLOCK_DIV_INT=4 + CYW43_PIO_CLOCK_DIV_FRAC=0 + ) + +# create map/bin/hex file etc. +pico_add_extra_outputs(picow_blink_fast_clock) + +# add url via pico_set_program_url +example_auto_set_url(picow_blink_fast_clock) diff --git a/pico_w/wifi/blink/picow_blink_fast_clock.c b/pico_w/wifi/blink/picow_blink_fast_clock.c new file mode 100644 index 000000000..68d1153e3 --- /dev/null +++ b/pico_w/wifi/blink/picow_blink_fast_clock.c @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/stdlib.h" +#include "pico/cyw43_arch.h" +#include "pico/cyw43_driver.h" +#include "hardware/clocks.h" + +int main() { + // 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 + // By default the pio used to communicate with cyw43 runs with a clock divisor of 2 + // if you modify the clock you will have to compensate for this + // 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) + set_sys_clock_khz(266000, true); + + stdio_init_all(); + if (cyw43_arch_init()) { + printf("Wi-Fi init failed"); + return -1; + } + while (true) { + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); + sleep_ms(250); + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); + sleep_ms(250); + } +}