Skip to content

Commit d55e074

Browse files
committed
improve warnings with rp2040 family
1 parent 8865ec4 commit d55e074

File tree

4 files changed

+54
-80
lines changed

4 files changed

+54
-80
lines changed

hw/bsp/family_support.cmake

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ set(WARN_FLAGS_GNU
6363
-Wunused
6464
-Wunused-function
6565
-Wreturn-type
66-
#-Wredundant-decls
67-
#-Wmissing-prototypes
66+
-Wredundant-decls
67+
-Wmissing-prototypes
68+
# -Wconversion
6869
)
6970
set(WARN_FLAGS_Clang ${WARN_FLAGS_GNU})
7071

@@ -391,56 +392,6 @@ function(family_example_missing_dependency TARGET DEPENDENCY)
391392
message(WARNING "${DEPENDENCY} submodule needed by ${TARGET} not found, please run 'python tools/get_deps.py ${DEPENDENCY}' to fetch it")
392393
endfunction()
393394

394-
#----------------------------------
395-
# RPI specific: refactor later
396-
#----------------------------------
397-
function(family_add_default_example_warnings TARGET)
398-
target_compile_options(${TARGET} PUBLIC
399-
-Wall
400-
-Wextra
401-
-Werror
402-
-Wfatal-errors
403-
-Wdouble-promotion
404-
-Wfloat-equal
405-
# FIXME commented out because of https://github.com/raspberrypi/pico-sdk/issues/1468
406-
#-Wshadow
407-
-Wwrite-strings
408-
-Wsign-compare
409-
-Wmissing-format-attribute
410-
-Wunreachable-code
411-
-Wcast-align
412-
-Wcast-qual
413-
-Wnull-dereference
414-
-Wuninitialized
415-
-Wunused
416-
-Wredundant-decls
417-
#-Wstrict-prototypes
418-
#-Werror-implicit-function-declaration
419-
#-Wundef
420-
)
421-
422-
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
423-
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
424-
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
425-
endif()
426-
427-
# GCC 10
428-
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
429-
target_compile_options(${TARGET} PUBLIC -Wconversion)
430-
endif()
431-
432-
# GCC 8
433-
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
434-
target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow)
435-
endif()
436-
437-
# GCC 6
438-
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
439-
target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing)
440-
endif()
441-
endif()
442-
endfunction()
443-
444395
#----------------------------------
445396
# Flashing target
446397
#----------------------------------

hw/bsp/rp2040/family.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static uart_inst_t *uart_inst;
9292
//
9393
// This doesn't work if others are trying to access flash at the same time,
9494
// e.g. XIP streamer, or the other core.
95-
bool __no_inline_not_in_flash_func(get_bootsel_button)(void) {
95+
static bool __no_inline_not_in_flash_func(get_bootsel_button)(void) {
9696
const uint CS_PIN_INDEX = 1;
9797

9898
// Must disable interrupts, as interrupt handlers may be in flash, and we

hw/bsp/rp2040/family.cmake

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,43 @@ endif()
184184
#------------------------------------
185185
# Functions
186186
#------------------------------------
187+
function(family_add_default_example_warnings TARGET)
188+
# Apply warnings to all TinyUSB interface library sources as well as examples sources
189+
# we cannot set compile options for target since it will not propagate to INTERFACE sources then picosdk files
190+
foreach(TINYUSB_TARGET IN ITEMS tinyusb_common_base tinyusb_device_base tinyusb_host_base tinyusb_host_max3421 tinyusb_bsp)
191+
get_target_property(TINYUSB_SOURCES ${TINYUSB_TARGET} INTERFACE_SOURCES)
192+
set_source_files_properties(${TINYUSB_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}")
193+
endforeach()
194+
195+
# Also apply to example sources, but filter out any source files from lib/ (e.g. fatfs)
196+
get_target_property(EXAMPLE_SOURCES ${TARGET} SOURCES)
197+
set(FILTERED_SOURCES "")
198+
foreach(SOURCE_FILE IN LISTS EXAMPLE_SOURCES)
199+
string(FIND "${SOURCE_FILE}" "${TOP}/lib" FOUND_POS)
200+
if(FOUND_POS EQUAL -1)
201+
list(APPEND FILTERED_SOURCES ${SOURCE_FILE})
202+
endif()
203+
endforeach()
204+
set_source_files_properties(${FILTERED_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}")
205+
206+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
207+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
208+
target_link_options(${TARGET} PRIVATE "LINKER:--no-warn-rwx-segments")
209+
endif()
210+
211+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
212+
target_compile_options(${TARGET} PRIVATE -Wconversion)
213+
endif()
214+
215+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
216+
target_compile_options(${TARGET} PRIVATE -Wcast-function-type -Wstrict-overflow)
217+
endif()
218+
219+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
220+
target_compile_options(${TARGET} PRIVATE -Wno-strict-aliasing)
221+
endif()
222+
endif()
223+
endfunction()
187224

188225
function(family_configure_target TARGET RTOS)
189226
if (RTOS STREQUAL noos OR RTOS STREQUAL "")
@@ -204,7 +241,7 @@ function(family_configure_target TARGET RTOS)
204241
pico_enable_stdio_uart(${TARGET} 1)
205242
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_board${RTOS_SUFFIX} tinyusb_additions)
206243

207-
family_flash_openocd(${TARGET})
244+
family_flash_openocd(${TARGET})
208245
family_flash_jlink(${TARGET})
209246
endfunction()
210247

@@ -359,34 +396,9 @@ function(suppress_tinyusb_warnings)
359396
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/hcd_rp2040.c
360397
)
361398
foreach(SOURCE_FILE IN LISTS CONVERSION_WARNING_FILES)
362-
set_source_files_properties(
363-
${SOURCE_FILE}
364-
PROPERTIES
365-
COMPILE_FLAGS "-Wno-conversion")
399+
set_source_files_properties(${SOURCE_FILE} PROPERTIES COMPILE_FLAGS "-Wno-conversion")
366400
endforeach()
367401
endif()
368-
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
369-
set_source_files_properties(
370-
${PICO_TINYUSB_PATH}/lib/fatfs/source/ff.c
371-
COMPILE_FLAGS "-Wno-stringop-overflow -Wno-array-bounds")
372-
endif()
373-
set_source_files_properties(
374-
${PICO_TINYUSB_PATH}/lib/fatfs/source/ff.c
375-
PROPERTIES
376-
COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual")
377-
378-
set_source_files_properties(
379-
${PICO_TINYUSB_PATH}/lib/lwip/src/core/tcp_in.c
380-
${PICO_TINYUSB_PATH}/lib/lwip/src/core/tcp_out.c
381-
PROPERTIES
382-
COMPILE_FLAGS "-Wno-conversion")
383-
384-
set_source_files_properties(
385-
${PICO_TINYUSB_PATH}/lib/networking/dnserver.c
386-
${PICO_TINYUSB_PATH}/lib/networking/dhserver.c
387-
${PICO_TINYUSB_PATH}/lib/networking/rndis_reports.c
388-
PROPERTIES
389-
COMPILE_FLAGS "-Wno-conversion -Wno-sign-conversion")
390402

391403
if (TARGET tinyusb_pico_pio_usb)
392404
set_source_files_properties(

src/portable/raspberrypi/pio_usb/hcd_pio_usb.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,20 @@
2929
#if CFG_TUH_ENABLED && (CFG_TUSB_MCU == OPT_MCU_RP2040) && CFG_TUH_RPI_PIO_USB
3030

3131
#include "pico.h"
32+
3233
#include "pio_usb.h"
34+
35+
#ifdef __GNUC__
36+
#pragma GCC diagnostic push
37+
#pragma GCC diagnostic ignored "-Wsign-conversion"
38+
#endif
39+
3340
#include "pio_usb_ll.h"
3441

42+
#ifdef __GNUC__
43+
#pragma GCC diagnostic pop
44+
#endif
45+
3546
//--------------------------------------------------------------------+
3647
// INCLUDE
3748
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)