Skip to content

Commit e9f9d43

Browse files
authored
Merge pull request #2723 from liamfraser/rp2040_tweaks
RP2040 tweaks
2 parents 9a41831 + 31a979a commit e9f9d43

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

examples/device/net_lwip_webserver/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ include(${CMAKE_CURRENT_LIST_DIR}/../../../hw/bsp/family_support.cmake)
55
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
66
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
77

8+
# Prefer the tinyusb lwip
89
set(LWIP ${TOP}/lib/lwip)
10+
11+
# If we can't find one from tinyusb then check cmake var before giving up
12+
if (NOT EXISTS ${LWIP}/src)
13+
set(LWIP ${TINYUSB_LWIP_PATH})
14+
endif()
15+
916
if (NOT EXISTS ${LWIP}/src)
1017
family_example_missing_dependency(${PROJECT} "lib/lwip")
1118
return()

examples/host/cdc_msc_hid/src/hid_app.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ static void process_mouse_report(hid_mouse_report_t const * report)
235235
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len)
236236
{
237237
(void) dev_addr;
238+
(void) len;
238239

239240
uint8_t const rpt_count = hid_info[instance].report_count;
240241
tuh_hid_report_info_t* rpt_info_arr = hid_info[instance].report_info;

examples/host/hid_controller/src/hid_app.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ bool diff_report(sony_ds4_report_t const* rpt1, sony_ds4_report_t const* rpt2)
253253

254254
void process_sony_ds4(uint8_t const* report, uint16_t len)
255255
{
256+
(void)len;
256257
const char* dpad_str[] = { "N", "NE", "E", "SE", "S", "SW", "W", "NW", "none" };
257258

258259
// previous report used to compare for changes

hw/bsp/family_support.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ if (NOT FAMILY STREQUAL rp2040)
6969
endif()
7070
endif()
7171

72+
if (NOT NO_WARN_RWX_SEGMENTS_SUPPORTED)
73+
set(NO_WARN_RWX_SEGMENTS_SUPPORTED 1)
74+
endif()
75+
7276
set(WARNING_FLAGS_GNU
7377
-Wall
7478
-Wextra
@@ -210,7 +214,7 @@ function(family_configure_common TARGET RTOS)
210214
# Generate linker map file
211215
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
212216
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
213-
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
217+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
214218
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
215219
endif ()
216220
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
@@ -360,7 +364,7 @@ function(family_add_default_example_warnings TARGET)
360364
)
361365

362366
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
363-
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
367+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
364368
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
365369
endif()
366370

src/class/hid/hid_host.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,9 @@ uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* report_info_arr,
657657
uint8_t const data8 = desc_report[0];
658658

659659
TU_LOG(3, "tag = %d, type = %d, size = %d, data = ", tag, type, size);
660-
for (uint32_t i = 0; i < size; i++) TU_LOG(3, "%02X ", desc_report[i]);
660+
for (uint32_t i = 0; i < size; i++) {
661+
TU_LOG(3, "%02X ", desc_report[i]);
662+
}
661663
TU_LOG(3, "\r\n");
662664

663665
switch (type) {

src/portable/raspberrypi/rp2040/rp2040_usb.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_host_mode(void) {
5353
//--------------------------------------------------------------------+
5454
// Implementation
5555
//--------------------------------------------------------------------+
56+
// Provide own byte by byte memcpy as not all copies are aligned
57+
static void unaligned_memcpy(void *dst, const void *src, size_t n) {
58+
uint8_t *dst_byte = (uint8_t*)dst;
59+
const uint8_t *src_byte = (const uint8_t*)src;
60+
while (n--) {
61+
*dst_byte++ = *src_byte++;
62+
}
63+
}
5664

5765
void rp2040_usb_init(void) {
5866
// Reset usb controller
@@ -67,7 +75,6 @@ void rp2040_usb_init(void) {
6775
#pragma GCC diagnostic ignored "-Wstringop-overflow"
6876
#endif
6977
#endif
70-
memset(usb_hw, 0, sizeof(*usb_hw));
7178
memset(usb_dpram, 0, sizeof(*usb_dpram));
7279
#ifdef __GNUC__
7380
#pragma GCC diagnostic pop
@@ -125,7 +132,7 @@ static uint32_t __tusb_irq_path_func(prepare_ep_buffer)(struct hw_endpoint* ep,
125132

126133
if (!ep->rx) {
127134
// Copy data from user buffer to hw buffer
128-
memcpy(ep->hw_data_buf + buf_id * 64, ep->user_buf, buflen);
135+
unaligned_memcpy(ep->hw_data_buf + buf_id * 64, ep->user_buf, buflen);
129136
ep->user_buf += buflen;
130137

131138
// Mark as full
@@ -230,7 +237,7 @@ static uint16_t __tusb_irq_path_func(sync_ep_buffer)(struct hw_endpoint* ep, uin
230237
// we have received AFTER we have copied it to the user buffer at the appropriate offset
231238
assert(buf_ctrl & USB_BUF_CTRL_FULL);
232239

233-
memcpy(ep->user_buf, ep->hw_data_buf + buf_id * 64, xferred_bytes);
240+
unaligned_memcpy(ep->user_buf, ep->hw_data_buf + buf_id * 64, xferred_bytes);
234241
ep->xferred_len = (uint16_t) (ep->xferred_len + xferred_bytes);
235242
ep->user_buf += xferred_bytes;
236243
}

src/tusb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ static void dump_str_line(uint8_t const* buf, uint16_t count) {
398398
tu_printf(" |");
399399
// each line is 16 bytes
400400
for (uint16_t i = 0; i < count; i++) {
401-
const char ch = buf[i];
401+
int ch = buf[i];
402402
tu_printf("%c", isprint(ch) ? ch : '.');
403403
}
404404
tu_printf("|\r\n");

0 commit comments

Comments
 (0)