Skip to content

Commit

Permalink
Add Pico W and lwIP support
Browse files Browse the repository at this point in the history
  • Loading branch information
kilograham committed Jun 30, 2022
1 parent 77c04e4 commit 5e9a5e8
Show file tree
Hide file tree
Showing 36 changed files with 2,915 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "tinyusb"]
path = lib/tinyusb
url = https://github.com/hathach/tinyusb.git
[submodule "lib/cyw43-driver"]
path = lib/cyw43-driver
url = https://github.com/georgerobotics/cyw43-driver.git
[submodule "lib/lwip"]
path = lib/lwip
url = https://github.com/lwip-tcpip/lwip.git
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ instructions for other platforms, and just in general, we recommend you see [Ras
```

* Or by cloning the SDK locally, but without copying `pico_sdk_import.cmake`:
1. `git clone` this Raspberry Pi Pico SDK repository
2. Setup a `CMakeLists.txt` like:

```cmake
cmake_minimum_required(VERSION 3.13)
# initialize the SDK directly
include(/path/to/pico-sdk/pico_sdk_init.cmake)
project(my_project)
# initialize the Raspberry Pi Pico SDK
pico_sdk_init()
# rest of your project
```
1. Write your code (see [pico-examples](https://github.com/raspberrypi/pico-examples) or the [Raspberry Pi Pico C/C++ SDK](https://rptl.io/pico-c-sdk) documentation for more information)

About the simplest you can do is a single source file (e.g. hello_world.c)
Expand Down
3 changes: 2 additions & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ PREDEFINED = __not_in_flash_func(x) \
__time_critical_func(x) \
__not_in_flash(x)= \
__no_inline_not_in_flash(x)= \
__attribute__(x)=
__attribute__(x)= \
DOXYGEN_GENERATION=
7 changes: 7 additions & 0 deletions docs/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
* \defgroup tinyusb_host tinyusb_host
* @}
*
* \defgroup networking Networking Libraries
* Functions for implementing networking
* @{
* \defgroup pico_lwip pico_lwip
* \defgroup pico_cyw43_arch pico_cyw43_arch
* @}
*
* \defgroup runtime Runtime Infrastructure
* Libraries that are used to provide efficient implementation of certain
* language level and C library functions, as well as CMake INTERFACE libraries
Expand Down
1 change: 1 addition & 0 deletions lib/cyw43-driver
Submodule cyw43-driver added at 195dfc
1 change: 1 addition & 0 deletions lib/lwip
Submodule lwip added at 239918
102 changes: 102 additions & 0 deletions src/boards/include/boards/pico_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------

// This header may be included by other board headers as "boards/pico.h"

#ifndef _BOARDS_PICO_W_H
#define _BOARDS_PICO_W_H

// For board detection
#define RASPBERRYPI_PICO_W

// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif

// --- LED ---
// no PICO_DEFAULT_LED_PIN - LED is on Wireless chip
// no PICO_DEFAULT_WS2812_PIN

// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C 0
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN 4
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN 5
#endif

// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI 0
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN 18
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN 19
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN 16
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 17
#endif

// --- FLASH ---

#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1

#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2
#endif

#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
#endif

// note the SMSP mode pin is on WL_GPIO1
// #define PICO_SMPS_MODE_PIN

#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 0
#endif

#ifndef PICO_RP2040_B1_SUPPORTED
#define PICO_RP2040_B1_SUPPORTED 0
#endif

#ifndef CYW43_PIN_WL_HOST_WAKE
#define CYW43_PIN_WL_HOST_WAKE 24
#endif

#ifndef CYW43_PIN_WL_REG_ON
#define CYW43_PIN_WL_REG_ON 23
#endif

#ifndef CYW43_WL_GPIO_COUNT
#define CYW43_WL_GPIO_COUNT 3
#endif

#ifndef CYW43_WL_GPIO_LED_PIN
#define CYW43_WL_GPIO_LED_PIN 0
#endif

#endif
2 changes: 2 additions & 0 deletions src/boards/pico_w.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(PICO_CYW43_SUPPORTED "1" CACHE INTERNAL "Try to add support for PICO_CYW43")
include(${CMAKE_CURRENT_LIST_DIR}/generic_board.cmake)
8 changes: 6 additions & 2 deletions src/common/pico_base/include/pico/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
#ifndef __ASSEMBLER__

/*!
* Common return codes from pico_sdk methods that return a status
* \brief Common return codes from pico_sdk methods that return a status
* \ingroup pico_base
*/
enum {
enum pico_error_codes {
PICO_OK = 0,
PICO_ERROR_NONE = 0,
PICO_ERROR_TIMEOUT = -1,
PICO_ERROR_GENERIC = -2,
PICO_ERROR_NO_DATA = -3,
PICO_ERROR_NOT_PERMITTED = -4,
PICO_ERROR_INVALID_ARG = -5,
PICO_ERROR_IO = -6,
};

#endif // !__ASSEMBLER__
Expand Down
4 changes: 4 additions & 0 deletions src/rp2_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ if (NOT PICO_BARE_METAL)
pico_add_subdirectory(tinyusb)
pico_add_subdirectory(pico_stdio_usb)

pico_add_subdirectory(cyw43_driver)
pico_add_subdirectory(pico_lwip)
pico_add_subdirectory(pico_cyw43_arch)

pico_add_subdirectory(pico_stdlib)

pico_add_subdirectory(pico_cxx_options)
Expand Down
81 changes: 81 additions & 0 deletions src/rp2_common/cyw43_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
if (DEFINED ENV{PICO_CYW43_DRIVER_PATH} AND (NOT PICO_CYW43_DRIVER_PATH))
set(PICO_CYW43_DRIVER_PATH $ENV{PICO_CYW43_DRIVER_PATH})
message("Using PICO_CYW43_DRIVER_PATH from environment ('${PICO_CYW43_DRIVER_PATH}')")
endif()

set(CYW43_DRIVER_TEST_FILE "src/cyw43.h")

if (NOT PICO_CYW43_DRIVER_PATH)
set(PICO_CYW43_DRIVER_PATH ${PICO_SDK_PATH}/lib/cyw43-driver)
if (PICO_CYW43_SUPPORTED AND NOT EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE})
message(WARNING "cyw43-driver submodule has not been initialized; Pico W wireless support will be unavailable
hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).")
endif()
elseif (NOT EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE})
message(WARNING "PICO_CYW43_DRIVER_PATH specified but content not present.")
endif()

if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE})
message("cyw43-driver available at ${PICO_CYW43_DRIVER_PATH}")

pico_register_common_scope_var(PICO_CYW43_DRIVER_PATH)

# base driver without our bus
add_library(cyw43_driver_base INTERFACE)
target_sources(cyw43_driver_base INTERFACE
${PICO_CYW43_DRIVER_PATH}/src/cyw43_ll.c
${PICO_CYW43_DRIVER_PATH}/src/cyw43_stats.c
${PICO_CYW43_DRIVER_PATH}/src/cyw43_lwip.c
${PICO_CYW43_DRIVER_PATH}/src/cyw43_ctrl.c
)
target_include_directories(cyw43_driver_base INTERFACE
${PICO_CYW43_DRIVER_PATH}/src
${PICO_CYW43_DRIVER_PATH}/firmware
)

# Build the driver for cyw43 for pico w

# Firmware stuff
set(CYW43_FIRMWARE_BIN 43439A0-7.95.49.00.combined)
string(REGEX REPLACE [\\\.\-] _ CYW43_FIRMWARE_BIN_ ${CYW43_FIRMWARE_BIN})
string(REGEX MATCH [^_]+_?[^_]*_?[^_]*_?[^_]*_?[^_]* CYW43_FIRMWARE_PRETTY ${CYW43_FIRMWARE_BIN_})
set(CYW43_FIRMWARE_PRETTY fw_${CYW43_FIRMWARE_PRETTY})
set(RESOURCE_SECNAME .big_const)
set(RESOURCE_SECFLAGS contents,alloc,load,readonly,data)
set(CYW43_FIRMWARE_OBJ ${CMAKE_CURRENT_BINARY_DIR}/cyw43_resource.o)

add_custom_target(cyw43_firmware_package DEPENDS ${CYW43_FIRMWARE_OBJ})

# cyw43_resource.o contains the WiFi and BT firmware as a binary blob
add_custom_command(
OUTPUT ${CYW43_FIRMWARE_OBJ}
DEPENDS ${PICO_CYW43_DRIVER_PATH}/firmware/${CYW43_FIRMWARE_BIN}
WORKING_DIRECTORY ${PICO_CYW43_DRIVER_PATH}/firmware
COMMAND ${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm
--readonly-text
--rename-section .data=${RESOURCE_SECNAME},${RESOURCE_SECFLAGS}
--redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_start=${CYW43_FIRMWARE_PRETTY}_start
--redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_end=${CYW43_FIRMWARE_PRETTY}_end
--redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_size=${CYW43_FIRMWARE_PRETTY}_size
${CYW43_FIRMWARE_BIN} ${CYW43_FIRMWARE_OBJ}
)

add_library(cyw43_driver_picow INTERFACE)
target_sources(cyw43_driver_picow INTERFACE
${CMAKE_CURRENT_LIST_DIR}/cyw43_bus_pio_spi.c
)
pico_generate_pio_header(cyw43_driver_picow ${CMAKE_CURRENT_LIST_DIR}/cyw43_bus_pio_spi.pio)
add_dependencies(cyw43_driver_picow INTERFACE cyw43_firmware_package)
target_link_libraries(cyw43_driver_picow INTERFACE
${CYW43_FIRMWARE_OBJ}
)
target_link_libraries(cyw43_driver_picow INTERFACE
cyw43_driver_base
pico_stdlib
hardware_pio
hardware_dma
hardware_exception
)

pico_promote_common_scope_vars()
endif()
Loading

0 comments on commit 5e9a5e8

Please sign in to comment.