Skip to content

Commit 7b1344f

Browse files
authored
Merge pull request #1467 from kilograham/rp2040_cleanup
Minor cleanup of RP2040 code post addition of Pico-PIO-USB
2 parents c1ae13b + 26c4d4b commit 7b1344f

File tree

10 files changed

+107
-81
lines changed

10 files changed

+107
-81
lines changed

examples/device/net_lwip_webserver/src/lwipopts.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949

5050
#define TCP_MSS (1500 /*mtu*/ - 20 /*iphdr*/ - 20 /*tcphhr*/)
5151
#define TCP_SND_BUF (2 * TCP_MSS)
52+
#ifndef TCP_WND
5253
#define TCP_WND (TCP_MSS)
54+
#endif
5355

5456
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
5557

examples/dual/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/family_support.cmake)
4+
5+
project(tinyusb_dual_examples)
6+
family_initialize_project(tinyusb_dual_examples ${CMAKE_CURRENT_LIST_DIR})
7+
if (FAMILY STREQUAL "rp2040" AND NOT TARGET tinyusb_pico_pio_usb)
8+
message("Skipping dual host/device mode examples as Pico-PIO-USB is not available")
9+
else()
10+
# family_add_subdirectory will filter what to actually add based on selected FAMILY
11+
family_add_subdirectory(host_hid_to_device_cdc)
12+
endif()

examples/dual/host_hid_to_device_cdc/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ target_include_directories(${PROJECT} PUBLIC
2525

2626
# Configure compilation flags and libraries for the example... see the corresponding function
2727
# in hw/bsp/FAMILY/family.cmake for details.
28-
family_configure_device_example(${PROJECT})
29-
family_configure_host_example(${PROJECT})
30-
family_configure_pico_pio_usb_example(${PROJECT})
28+
family_configure_dual_usb_example(${PROJECT})

examples/host/bare_api/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ target_include_directories(${PROJECT} PUBLIC
2727
family_configure_host_example(${PROJECT})
2828

2929
# For rp2040, un-comment to enable pico-pio-usb
30-
# family_configure_pico_pio_usb_example(${PROJECT})
30+
# family_add_pico_pio_usb(${PROJECT})

examples/host/cdc_msc_hid/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ target_include_directories(${PROJECT} PUBLIC
2929
family_configure_host_example(${PROJECT})
3030

3131
# For rp2040, un-comment to enable pico-pio-usb
32-
# family_configure_pico_pio_usb_example(${PROJECT})
32+
# family_add_pico_pio_usb(${PROJECT})

examples/host/hid_controller/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ target_include_directories(${PROJECT} PUBLIC
2828
family_configure_host_example(${PROJECT})
2929

3030
# For rp2040, un-comment to enable pico-pio-usb
31-
# family_configure_pico_pio_usb_example(${PROJECT})
31+
# family_add_pico_pio_usb(${PROJECT})

hw/bsp/rp2040/family.c

+2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ void board_init(void)
127127
#ifndef BUTTON_BOOTSEL
128128
#endif
129129

130+
#if CFG_TUH_RPI_PIO_USB || CFG_TUD_RPI_PIO_USB
130131
// Set the system clock to a multiple of 120mhz for bitbanging USB with pico-usb
131132
set_sys_clock_khz(120000, true);
133+
#endif
132134

133135
#if defined(UART_DEV) && defined(LIB_PICO_STDIO_UART)
134136
bi_decl(bi_2pins_with_func(UART_TX_PIN, UART_TX_PIN, GPIO_FUNC_UART));

hw/bsp/rp2040/family.cmake

+82-74
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
2323
set(PICO_TINYUSB_PATH ${TOP})
2424
endif()
2525

26-
#------------------------------------
26+
#------------------------------------
2727
# Base config for both device and host; wrapped by SDK's tinyusb_common
2828
#------------------------------------
2929
add_library(tinyusb_common_base INTERFACE)
@@ -50,52 +50,21 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
5050
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
5151
message("Compiling TinyUSB with CFG_TUSB_DEBUG=1")
5252
set(TINYUSB_DEBUG_LEVEL 1)
53-
endif ()
53+
endif()
5454

5555
target_compile_definitions(tinyusb_common_base INTERFACE
5656
CFG_TUSB_MCU=OPT_MCU_RP2040
5757
CFG_TUSB_OS=OPT_OS_PICO
5858
CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL}
5959
)
6060

61-
#------------------------------------
62-
# PIO USB for both host and device
63-
#------------------------------------
64-
add_library(pico_pio_usb INTERFACE)
65-
66-
if (NOT DEFINED PICO_PIO_USB_PATH)
67-
set(PICO_PIO_USB_PATH "${TOP}/hw/mcu/raspberry_pi/Pico-PIO-USB")
68-
endif()
69-
70-
target_sources(pico_pio_usb INTERFACE
71-
${PICO_PIO_USB_PATH}/src/pio_usb.c
72-
${PICO_PIO_USB_PATH}/src/pio_usb_host.c
73-
${PICO_PIO_USB_PATH}/src/pio_usb_device.c
74-
${PICO_PIO_USB_PATH}/src/usb_crc.c
75-
)
76-
77-
target_include_directories(pico_pio_usb INTERFACE
78-
${PICO_PIO_USB_PATH}/src
79-
)
80-
81-
target_link_libraries(pico_pio_usb INTERFACE
82-
hardware_dma
83-
hardware_pio
84-
pico_multicore
85-
)
86-
87-
target_compile_definitions(pico_pio_usb INTERFACE
88-
PIO_USB_USE_TINYUSB
89-
)
90-
91-
#------------------------------------
61+
#------------------------------------
9262
# Base config for device mode; wrapped by SDK's tinyusb_device
9363
#------------------------------------
9464
add_library(tinyusb_device_base INTERFACE)
9565
target_sources(tinyusb_device_base INTERFACE
9666
${TOP}/src/portable/raspberrypi/rp2040/dcd_rp2040.c
9767
${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c
98-
${TOP}/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
9968
${TOP}/src/device/usbd.c
10069
${TOP}/src/device/usbd_control.c
10170
${TOP}/src/class/audio/audio_device.c
@@ -119,7 +88,6 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
11988
target_sources(tinyusb_host_base INTERFACE
12089
${TOP}/src/portable/raspberrypi/rp2040/hcd_rp2040.c
12190
${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c
122-
${TOP}/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
12391
${TOP}/src/host/usbh.c
12492
${TOP}/src/host/hub.c
12593
${TOP}/src/class/cdc/cdc_host.c
@@ -140,8 +108,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
140108
target_sources(tinyusb_bsp INTERFACE
141109
${TOP}/hw/bsp/rp2040/family.c
142110
)
143-
# target_include_directories(tinyusb_bsp INTERFACE
144-
# ${TOP}/hw/bsp/rp2040)
111+
# target_include_directories(tinyusb_bsp INTERFACE
112+
# ${TOP}/hw/bsp/rp2040)
145113

146114
# tinyusb_additions will hold our extra settings for examples
147115
add_library(tinyusb_additions INTERFACE)
@@ -151,22 +119,22 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
151119
)
152120

153121
if(DEFINED LOG)
154-
target_compile_definitions(tinyusb_additions INTERFACE CFG_TUSB_DEBUG=${LOG} )
122+
target_compile_definitions(tinyusb_additions INTERFACE CFG_TUSB_DEBUG=${LOG})
155123
endif()
156124

157125
if(LOGGER STREQUAL "rtt")
158-
target_compile_definitions(tinyusb_additions INTERFACE
159-
LOGGER_RTT
160-
SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
161-
)
162-
163-
target_sources(tinyusb_additions INTERFACE
164-
${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c
165-
)
166-
167-
target_include_directories(tinyusb_additions INTERFACE
168-
${TOP}/lib/SEGGER_RTT/RTT
169-
)
126+
target_compile_definitions(tinyusb_additions INTERFACE
127+
LOGGER_RTT
128+
SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
129+
)
130+
131+
target_sources(tinyusb_additions INTERFACE
132+
${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c
133+
)
134+
135+
target_include_directories(tinyusb_additions INTERFACE
136+
${TOP}/lib/SEGGER_RTT/RTT
137+
)
170138
endif()
171139

172140
#------------------------------------
@@ -189,41 +157,81 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
189157
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_host)
190158
endfunction()
191159

192-
function(family_configure_pico_pio_usb_example TARGET)
160+
function(family_add_pico_pio_usb TARGET)
161+
target_link_libraries(${TARGET} PUBLIC tinyusb_pico_pio_usb)
162+
endfunction()
163+
164+
function(family_configure_dual_usb_example TARGET)
193165
family_configure_target(${TARGET})
194-
target_link_libraries(${TARGET} PUBLIC pico_stdlib pico_pio_usb)
195-
pico_generate_pio_header(tinyusb_common_base ${PICO_PIO_USB_PATH}/src/usb_tx.pio)
196-
pico_generate_pio_header(tinyusb_common_base ${PICO_PIO_USB_PATH}/src/usb_rx.pio)
166+
# require tinyusb_pico_pio_usb
167+
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb )
197168
endfunction()
198169

170+
function(check_and_add_pico_pio_usb_support)
171+
# check for pico_generate_pio_header (as depending on environment we may be called before SDK is
172+
# initialized in which case it isn't available yet), and only do the initialization once
173+
if (COMMAND pico_generate_pio_header AND NOT TARGET tinyusb_pico_pio_usb)
174+
#------------------------------------
175+
# PIO USB for both host and device
176+
#------------------------------------
177+
178+
if (NOT DEFINED PICO_PIO_USB_PATH)
179+
set(PICO_PIO_USB_PATH "${TOP}/hw/mcu/raspberry_pi/Pico-PIO-USB")
180+
endif()
181+
182+
if (EXISTS ${PICO_PIO_USB_PATH}/src/pio_usb.c)
183+
add_library(tinyusb_pico_pio_usb INTERFACE)
184+
target_sources(tinyusb_device_base INTERFACE
185+
${TOP}/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
186+
)
187+
target_sources(tinyusb_host_base INTERFACE
188+
${TOP}/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
189+
)
190+
191+
target_sources(tinyusb_pico_pio_usb INTERFACE
192+
${PICO_PIO_USB_PATH}/src/pio_usb.c
193+
${PICO_PIO_USB_PATH}/src/pio_usb_host.c
194+
${PICO_PIO_USB_PATH}/src/pio_usb_device.c
195+
${PICO_PIO_USB_PATH}/src/usb_crc.c
196+
)
197+
198+
target_include_directories(tinyusb_pico_pio_usb INTERFACE
199+
${PICO_PIO_USB_PATH}/src
200+
)
201+
202+
target_link_libraries(tinyusb_pico_pio_usb INTERFACE
203+
hardware_dma
204+
hardware_pio
205+
pico_multicore
206+
)
207+
208+
target_compile_definitions(tinyusb_pico_pio_usb INTERFACE
209+
PIO_USB_USE_TINYUSB
210+
)
211+
212+
pico_generate_pio_header(tinyusb_pico_pio_usb ${PICO_PIO_USB_PATH}/src/usb_tx.pio)
213+
pico_generate_pio_header(tinyusb_pico_pio_usb ${PICO_PIO_USB_PATH}/src/usb_rx.pio)
214+
endif()
215+
endif()
216+
endfunction()
217+
218+
# Try to add Pico-PIO_USB support now for the case where this file is included directly
219+
# after Pico SDK initialization, but without using the family_ functions (as is the case
220+
# when included by the SDK itself)
221+
check_and_add_pico_pio_usb_support()
222+
199223
function(family_initialize_project PROJECT DIR)
200224
# call the original version of this function from family_common.cmake
201225
_family_initialize_project(${PROJECT} ${DIR})
202226
enable_language(C CXX ASM)
203227
pico_sdk_init()
228+
229+
# now re-check for adding Pico-PIO_USB support now SDK is definitely available
230+
check_and_add_pico_pio_usb_support()
204231
endfunction()
205232

206233
# This method must be called from the project scope to suppress known warnings in TinyUSB source files
207234
function(suppress_tinyusb_warnings)
208-
set_source_files_properties(
209-
${PICO_TINYUSB_PATH}/src/tusb.c
210-
PROPERTIES
211-
COMPILE_FLAGS "-Wno-conversion")
212-
set_source_files_properties(
213-
${PICO_TINYUSB_PATH}/src/common/tusb_fifo.c
214-
PROPERTIES
215-
COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual")
216-
set_source_files_properties(
217-
${PICO_TINYUSB_PATH}/src/device/usbd.c
218-
PROPERTIES
219-
COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual -Wno-null-dereference")
220-
set_source_files_properties(
221-
${PICO_TINYUSB_PATH}/src/device/usbd_control.c
222-
PROPERTIES
223-
COMPILE_FLAGS "-Wno-conversion")
224-
set_source_files_properties(
225-
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c
226-
PROPERTIES
227-
COMPILE_FLAGS "-Wno-conversion")
235+
# there are currently no warnings to suppress, however this function must still exist
228236
endfunction()
229237
endif()

src/portable/raspberrypi/rp2040/hcd_rp2040.c

+4
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,11 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
537537
(void) rhport;
538538

539539
// Copy data into setup packet buffer
540+
#pragma GCC diagnostic push
541+
#pragma GCC diagnostic ignored "-Warray-bounds"
542+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
540543
memcpy((void*)&usbh_dpram->setup_packet[0], setup_packet, 8);
544+
#pragma GCC diagnostic pop
541545

542546
// Configure EP0 struct with setup info for the trans complete
543547
struct hw_endpoint *ep = _hw_endpoint_allocate(0);

src/portable/raspberrypi/rp2040/rp2040_usb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ void rp2040_usb_init(void)
5858
unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
5959

6060
// Clear any previous state just in case
61-
// TODO Suppress warning array-bounds with gcc11
6261
#pragma GCC diagnostic push
6362
#pragma GCC diagnostic ignored "-Warray-bounds"
63+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
6464
memset(usb_hw, 0, sizeof(*usb_hw));
6565
memset(usb_dpram, 0, sizeof(*usb_dpram));
6666
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)