Skip to content

Commit

Permalink
Merge branch 'develop' into uart_pio_dma
Browse files Browse the repository at this point in the history
  • Loading branch information
kilograham authored Nov 19, 2024
2 parents 67e3171 + da4e50d commit 4e3dc9e
Show file tree
Hide file tree
Showing 218 changed files with 27,545 additions and 947 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ jobs:

- name: Build Project
working-directory: ${{github.workspace}}/pico-examples
# bash required otherwise this mysteriously (no error) fails at "Generating cyw43_bus_pio_spi.pio.h"
shell: bash
shell: pwsh
run: |
mkdir build
cd build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
_deps
cmake-*
build
build-*
.DS_Store
*.pdf
41 changes: 36 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,52 @@ cmake_minimum_required(VERSION 3.12)

# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)

include(pico_extras_import_optional.cmake)

project(pico_examples C CXX ASM)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
if (PICO_SDK_VERSION_STRING VERSION_LESS "2.0.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 2.0.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})

# If you want debug output from USB (pass -DPICO_STDIO_USB=1) this ensures you don't lose any debug output while USB is set up
if (NOT DEFINED PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS)
set(PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS 3000)
endif()

# Initialize the SDK
pico_sdk_init()

include(example_auto_set_url.cmake)

function(add_subdirectory_exclude_platforms NAME)
if (ARGN)
if (PICO_PLATFORM IN_LIST ARGN)
message("Skipping ${NAME} example which is unsupported on this platform")
return()
endif()
foreach(PATTERN IN LISTS ARGN)
string(REGEX MATCH "${PATTERN}" MATCHED "${PICO_PLATFORM}")
if (MATCHED)
message("Skipping ${NAME} example which is unsupported on this platform")
return()
endif()
endforeach()
endif()
add_subdirectory(${NAME})
endfunction()

# Add blink example
add_subdirectory(blink)
add_subdirectory_exclude_platforms(blink)
add_subdirectory_exclude_platforms(blink_simple)

# Add hello world example
add_subdirectory(hello_world)
add_subdirectory_exclude_platforms(hello_world)

add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
Expand All @@ -35,15 +59,19 @@ endif()

# Hardware-specific examples in subdirectories:
add_subdirectory(adc)
add_subdirectory(bootloaders)
add_subdirectory(clocks)
add_subdirectory(cmake)
add_subdirectory(dcp)
add_subdirectory(divider)
add_subdirectory(dma)
add_subdirectory(flash)
add_subdirectory(gpio)
add_subdirectory(hstx)
add_subdirectory(i2c)
add_subdirectory(interp)
add_subdirectory(multicore)
add_subdirectory(otp)
add_subdirectory(picoboard)
add_subdirectory(pico_w)
add_subdirectory(pio)
Expand All @@ -54,5 +82,8 @@ add_subdirectory(spi)
add_subdirectory(system)
add_subdirectory(timer)
add_subdirectory(uart)
add_subdirectory(universal)
add_subdirectory(usb)
add_subdirectory(watchdog)
add_subdirectory(sha)
add_subdirectory(freertos)
93 changes: 85 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# Raspberry Pi Pico SDK Examples
# Raspberry Pi RP2350 Pico SDK Examples - Early Access

## RP2350 Instructions

Everything below this section is from the stock pico-examples, so ignore URLs etc., but generally instructions are the same.

The Pico SDK default continues to be to build for RP2040 (PICO_PLATFORM=rp2040), so to build for RP2350, you need to pass
`-DPICO_PLATFORM=rp2350` to CMake (or `-DPICO_PLATFORM=rp2350-riscv` for RISC-V).

Most, but not all examples, currently work on RP2350 however you should be able to do a full build with any of the above platforms (PICO_PLATFORM=host however currently fails on some examples)

For RISC-V compilation, you should take a compiler from here: https://www.embecosm.com/resources/tool-chain-downloads/#riscv-stable

# Original pico-examples docs

## Getting started

See [Getting Started with the Raspberry Pi Pico](https://rptl.io/pico-get-started) and the README in the [pico-sdk](https://github.com/raspberrypi/pico-sdk) for information
on getting up and running.

### First Examples
### First Examples

App|Description | Link to prebuilt UF2
---|---|---
[hello_serial](hello_world/serial) | The obligatory Hello World program for Pico (Output over serial version) |
[hello_usb](hello_world/usb) | The obligatory Hello World program for Pico (Output over USB version) | https://rptl.io/pico-hello-usb
[blink](blink) | Blink an LED on and off. | https://rptl.io/pico-blink
App| Description | Link to prebuilt UF2
---|----------------------------------------------------------------------------|---
[hello_serial](hello_world/serial) | The obligatory Hello World program for Pico (Output over serial version) |
[hello_usb](hello_world/usb) | The obligatory Hello World program for Pico (Output over USB version) | https://rptl.io/pico-hello-usb
[blink](blink) | Blink an LED on and off. Works on both boards with regular LEDs and Pico W | https://rptl.io/pico-blink
[blink_simple](blink_simple) | Blink an LED on and off. Does not work on Pico W. | https://rptl.io/pico-blink
[picow_blink](pico_w/wifi/blink) | Blinks the Pico W on-board LED (which is connected via the WiFi chip). | http://rptl.io/pico-w-blink

### ADC

Expand All @@ -25,6 +40,11 @@ App|Description
[dma_capture](adc/dma_capture) | Use the DMA to capture many samples from the ADC.
[read_vsys](adc/read_vsys) | Demonstrates how to read VSYS to get the voltage of the power supply.

### Bootloaders (RP2350 Only)
App|Description
---|---
[enc_bootloader](bootloaders/encrypted) | A bootloader which decrypts binaries from flash into SRAM. See the separate [README](bootloaders/encrypted/README.md) for more information

### Clocks

App|Description
Expand All @@ -40,6 +60,12 @@ App|Description
---|---
[build_variants](cmake/build_variants) | Builds two version of the same app with different configurations

### DCP

App|Description
---|---
[hello_dcp](dcp/hello_dcp) | Use the double-precision coprocessor directly in assembler.

### DMA

App|Description
Expand All @@ -49,6 +75,12 @@ App|Description
[channel_irq](dma/channel_irq) | Use an IRQ handler to reconfigure a DMA channel, in order to continuously drive data through a PIO state machine.
[sniff_crc](dma/sniff_crc) | Use the DMA engine's 'sniff' capability to calculate a CRC32 on a data buffer.

### HSTX

App|Description
---|---
[dvi_out_hstx_encoder](dvi_out_hstx_encoder) `RP2350`| Use the HSTX to output a DVI signal with 3:3:2 RGB

### Flash

App|Description
Expand All @@ -58,6 +90,15 @@ App|Description
[program](flash/program) | Erase a flash sector, program one flash page, and read back the data.
[xip_stream](flash/xip_stream) | Stream data using the XIP stream hardware, which allows data to be DMA'd in the background whilst executing code from flash.
[ssi_dma](flash/ssi_dma) | DMA directly from the flash interface (continuous SCK clocking) for maximum bulk read performance.
[runtime_flash_permissions](flash/runtime_flash_permissions) | Demonstrates adding partitions at runtime to change the flash permissions

### FreeRTOS

These examples require you to set the `FREERTOS_KERNEL_PATH` to point to the FreeRTOS Kernel. See https://github.com/FreeRTOS/FreeRTOS-Kernel

App|Description
---|---
[hello_freertos](freertos/hello_freertos) | Examples that demonstrate how run FreeRTOS and tasks on 1 or 2 cores.

### GPIO

Expand Down Expand Up @@ -106,6 +147,13 @@ App|Description
[hello_multicore](multicore/hello_multicore) | Launch a function on the second core, printf some messages on each core, and pass data back and forth through the mailbox FIFOs.
[multicore_fifo_irqs](multicore/multicore_fifo_irqs) | On each core, register and interrupt handler for the mailbox FIFOs. Show how the interrupt fires when that core receives a message.
[multicore_runner](multicore/multicore_runner) | Set up the second core to accept, and run, any function pointer pushed into its mailbox FIFO. Push in a few pieces of code and get answers back.
[multicore_doorbell](multicore/multicore_doorbell) | Claims two doorbells for signaling between the cores. Counts how many doorbell IRQs occur on the second core and uses doorbells to coordinate exit.

### OTP

App|Description
---|---
[hello_otp](otp/hello_otp) | Demonstrate reading and writing from the OTP on RP2350, along with some of the features of OTP (error correction and page locking).

### Pico Board

Expand All @@ -122,6 +170,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_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.
Expand All @@ -130,18 +179,22 @@ App|Description
[picow_tls_verify](pico_w/wifi/tls_client) | Demonstrates how to make a HTTPS request using TLS with certificate verification.
[picow_wifi_scan](pico_w/wifi/wifi_scan) | Scans for WiFi networks and prints the results.
[picow_udp_beacon](pico_w/wifi/udp_beacon) | A simple UDP transmitter.
[picow_httpd](pico_w/wifi/httpd) | Runs a LWIP HTTP server test app

#### FreeRTOS examples

These are examples of integrating Pico W networking under FreeRTOS, and require you to set the `FREERTOS_KERNEL_PATH`
to point to the FreeRTOS Kernel.
to point to the FreeRTOS Kernel. See https://github.com/FreeRTOS/FreeRTOS-Kernel

App|Description
---|---
[picow_freertos_iperf_server_nosys](pico_w/wifi/freertos/iperf) | Runs an "iperf" server for WiFi speed testing under FreeRTOS in NO_SYS=1 mode. The LED is blinked in another task
[picow_freertos_iperf_server_sys](pico_w/wifi/freertos/iperf) | Runs an "iperf" server for WiFi speed testing under FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode. The LED is blinked in another task
[picow_freertos_ping_nosys](pico_w/wifi/freertos/ping) | Runs the lwip-contrib/apps/ping test app under FreeRTOS in NO_SYS=1 mode.
[picow_freertos_ping_sys](pico_w/wifi/freertos/ping) | Runs the lwip-contrib/apps/ping test app under FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode. The test app uses the lwIP _socket_ API in this case.
[picow_freertos_ntp_client_socket](pico_w/wifi/freertos/ntp_client_socket) | Connects to an NTP server using the LwIP Socket API with FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode.
[pico_freertos_httpd_nosys](pico_w/wifi/freertos/httpd) | Runs a LWIP HTTP server test app under FreeRTOS in NO_SYS=1 mode.
[pico_freertos_httpd_sys](pico_w/wifi/freertos/httpd) | Runs a LWIP HTTP server test app under FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode.

### Pico W Bluetooth

Expand All @@ -153,6 +206,8 @@ default being *background*. This can be changed by passing `-DBTSTACK_EXAMPLE_TY
examples can be built (which may be slow) by passing `-DBTSTACK_EXAMPLE_TYPE=all`
Freertos versions can only be built if `FREERTOS_KERNEL_PATH` is defined.

The Bluetooth examples that use audio require code in [pico-extras](https://github.com/raspberrypi/pico-extras). Pass `-DPICO_EXTRAS_PATH=${HOME}/pico-extras` on the cmake command line or define `PICO_EXTRAS_PATH=${HOME}/pico-extras` in your environment and re-run cmake to include them in the build.

App|Description
---|---
[picow_bt_example_a2dp_sink_demo](https://github.com/bluekitchen/btstack/tree/master/example/a2dp_sink_demo.c) | A2DP Sink - Receive Audio Stream and Control Playback.
Expand Down Expand Up @@ -230,8 +285,10 @@ App|Description
[pwm](pio/pwm) | Pulse width modulation on PIO. Use it to gradually fade the brightness of an LED.
[spi](pio/spi) | Use PIO to erase, program and read an external SPI flash chip. A second example runs a loopback test with all four CPHA/CPOL combinations.
[squarewave](pio/squarewave) | Drive a fast square wave onto a GPIO. This example accesses low-level PIO registers directly, instead of using the SDK functions.
[squarewave_div_sync](pio/squarewave) | Generates a square wave on three GPIOs and synchronises the divider on all the state machines
[st7789_lcd](pio/st7789_lcd) | Set up PIO for 62.5 Mbps serial output, and use this to display a spinning image on a ST7789 serial LCD.
[quadrature_encoder](pio/quadrature_encoder) | A quadrature encoder using PIO to maintain counts independent of the CPU.
[quadrature_encoder_substep](pio/quadrature_encoder_substep) | High resolution speed measurement using a standard quadrature encoder
[uart_rx](pio/uart_rx) | Implement the receive component of a UART serial port. Attach it to the spare Arm UART to see it receive characters.
[uart_tx](pio/uart_tx) | Implement the transmit component of a UART serial port, and print hello world.
[ws2812](pio/ws2812) | Examples of driving WS2812 addressable RGB LEDs.
Expand Down Expand Up @@ -260,6 +317,13 @@ App|Description
[rtc_alarm](rtc/rtc_alarm) | Set an alarm on the RTC to trigger an interrupt at a date/time 5 seconds into the future.
[rtc_alarm_repeat](rtc/rtc_alarm_repeat) | Trigger an RTC interrupt once per minute.

### SHA-256

App|Description
---|---
[hello_sha256](sha/sha256) | Demonstrates how to use the pico_sha256 library to calculate a checksum using the hardware in rp2350
[mbedtls_sha256](sha/mbedtls_sha256) | Demonstrates using the SHA-256 hardware acceleration in mbedtls

### SPI

App|Description
Expand All @@ -276,7 +340,9 @@ App|Description

App|Description
---|---
[boot_info](system/boot_info) | Demonstrate how to read and interpret sys info boot info.
[hello_double_tap](system/hello_double_tap) | An LED blink with the `pico_bootsel_via_double_reset` library linked. This enters the USB bootloader when it detects the system being reset twice in quick succession, which is useful for boards with a reset button but no BOOTSEL button.
[rand](system/rand) | Demonstrate how to use the pico random number functions.
[narrow_io_write](system/narrow_io_write) | Demonstrate the effects of 8-bit and 16-bit writes on a 32-bit IO register.
[unique_board_id](system/unique_board_id) | Read the 64 bit unique ID from external flash, which serves as a unique identifier for the board.

Expand All @@ -296,6 +362,17 @@ App|Description
[lcd_uart](uart/lcd_uart) | Display text and symbols on a 16x02 RGB LCD display via UART
[uart_advanced](uart/uart_advanced) | Use some other UART features like RX interrupts, hardware control flow, and data formats other than 8n1.

### Universal

These are examples of how to build universal binaries which run on RP2040, and RP2350 Arm & RISC-V.
These require you to set `PICO_ARM_TOOLCHAIN_PATH` and `PICO_RISCV_TOOLCHAIN_PATH` to appropriate paths, to ensure you have compilers for both architectures.

App|Description
---|---
[blink](universal/CMakeLists.txt#L126) | Same as the [blink](blink) example, but universal.
[hello_universal](universal/hello_universal) | The obligatory Hello World program for Pico (USB and serial output). On RP2350 it will reboot to the other architecture after every 10 prints.
[nuke_universal](universal/CMakeLists.txt#L132) | Same as the [nuke](flash/nuke) example, but universal. On RP2350 runs as a packaged SRAM binary, so is written to flash and copied to SRAM by the bootloader

### USB Device

#### TinyUSB Examples
Expand Down
20 changes: 11 additions & 9 deletions adc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
if (NOT PICO_NO_HARDWARE)
add_subdirectory(adc_console)
add_subdirectory(dma_capture)
add_subdirectory(hello_adc)
add_subdirectory(joystick_display)
add_subdirectory(onboard_temperature)
add_subdirectory(microphone_adc)
add_subdirectory(read_vsys)
endif ()
if (TARGET hardware_adc)
add_subdirectory_exclude_platforms(adc_console)
add_subdirectory_exclude_platforms(dma_capture)
add_subdirectory_exclude_platforms(hello_adc)
add_subdirectory_exclude_platforms(joystick_display)
add_subdirectory_exclude_platforms(onboard_temperature)
add_subdirectory_exclude_platforms(microphone_adc)
add_subdirectory_exclude_platforms(read_vsys)
else()
message("Skipping ADC examples as hardware_adc is unavailable on this platform")
endif()
2 changes: 1 addition & 1 deletion adc/adc_console/adc_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void printhelp() {
void __not_in_flash_func(adc_capture)(uint16_t *buf, size_t count) {
adc_fifo_setup(true, false, 0, false, false);
adc_run(true);
for (int i = 0; i < count; i = i + 1)
for (size_t i = 0; i < count; i = i + 1)
buf[i] = adc_fifo_get_blocking();
adc_run(false);
adc_fifo_drain();
Expand Down
4 changes: 2 additions & 2 deletions adc/joystick_display/joystick_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ int main() {
uint bar_x_pos = adc_x_raw * bar_width / adc_max;
uint bar_y_pos = adc_y_raw * bar_width / adc_max;
printf("\rX: [");
for (int i = 0; i < bar_width; ++i)
for (uint i = 0; i < bar_width; ++i)
putchar( i == bar_x_pos ? 'o' : ' ');
printf("] Y: [");
for (int i = 0; i < bar_width; ++i)
for (uint i = 0; i < bar_width; ++i)
putchar( i == bar_y_pos ? 'o' : ' ');
printf("]");
sleep_ms(50);
Expand Down
6 changes: 3 additions & 3 deletions adc/read_vsys/read_vsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ int main() {
}
#endif

bool old_battery_status;
float old_voltage;
bool old_battery_status = false;
bool battery_status = true;
float old_voltage = -1;
char *power_str = "UNKNOWN";

while(true) {
Expand All @@ -50,7 +50,7 @@ int main() {
if (battery_status && voltage_return == PICO_OK) {
const float min_battery_volts = 3.0f;
const float max_battery_volts = 4.2f;
int percent_val = ((voltage - min_battery_volts) / (max_battery_volts - min_battery_volts)) * 100;
int percent_val = (int) (((voltage - min_battery_volts) / (max_battery_volts - min_battery_volts)) * 100);
snprintf(percent_buf, sizeof(percent_buf), " (%d%%)", percent_val);
}

Expand Down
8 changes: 6 additions & 2 deletions blink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
add_executable(blink
blink.c
)
blink.c
)

# pull in common dependencies
target_link_libraries(blink pico_stdlib)

if (PICO_CYW43_SUPPORTED)
target_link_libraries(blink pico_cyw43_arch_none)
endif()

# create map/bin/hex file etc.
pico_add_extra_outputs(blink)

Expand Down
Loading

0 comments on commit 4e3dc9e

Please sign in to comment.