improve cmake warning flags, fix various warnings in examples

This commit is contained in:
hathach 2025-10-14 17:13:28 +07:00
parent 9bf18d080b
commit 47b13f6b10
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
27 changed files with 174 additions and 80 deletions

View File

@ -20,11 +20,11 @@ include(${CMAKE_CURRENT_LIST_DIR}/../cpu/${CMAKE_SYSTEM_CPU}.cmake)
# ----------------------------------------------------------------------------
# Compile flags
# ----------------------------------------------------------------------------
if (TOOLCHAIN STREQUAL "gcc")
if (TOOLCHAIN STREQUAL "gcc" OR TOOLCHAIN STREQUAL "clang")
list(APPEND TOOLCHAIN_COMMON_FLAGS
-fdata-sections
-ffunction-sections
-fsingle-precision-constant
# -fsingle-precision-constant # not supported by clang
-fno-strict-aliasing
)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
@ -34,22 +34,9 @@ if (TOOLCHAIN STREQUAL "gcc")
)
elseif (TOOLCHAIN STREQUAL "iar")
#list(APPEND TOOLCHAIN_COMMON_FLAGS)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
--diag_suppress=Li065
)
elseif (TOOLCHAIN STREQUAL "clang")
list(APPEND TOOLCHAIN_COMMON_FLAGS
-fdata-sections
-ffunction-sections
-fno-strict-aliasing
)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
-Wl,--print-memory-usage
-Wl,--gc-sections
-Wl,--cref
)
endif ()
# join the toolchain flags into a single string

View File

@ -31,4 +31,7 @@ enum
VOLUME_CTRL_SILENCE = 0x8000,
};
void led_blinking_task(void);
void audio_task(void);
#endif

View File

@ -38,9 +38,6 @@ extern uint32_t blink_interval_ms;
#include "pico/stdlib.h"
#endif
void led_blinking_task(void);
void audio_task(void);
/*------------- MAIN -------------*/
int main(void)
{

View File

@ -58,6 +58,7 @@ try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00
#include "lwip/ethip6.h"
#include "lwip/init.h"
#include "lwip/timeouts.h"
#include "lwip/sys.h"
#ifdef INCLUDE_IPERF
#include "lwip/apps/lwiperf.h"
@ -172,7 +173,7 @@ static void init_lwip(void) {
}
/* handle any DNS requests from dns-server */
bool dns_query_proc(const char *name, ip4_addr_t *addr) {
static bool dns_query_proc(const char *name, ip4_addr_t *addr) {
if (0 == strcmp(name, "tiny.usb")) {
*addr = ipaddr;
return true;

View File

@ -29,6 +29,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "main.h"
#include "usbtmc_app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES

View File

@ -28,6 +28,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
#include "main.h"
#include "usbtmc_app.h"
#if (CFG_TUD_USBTMC_ENABLE_488)
static usbtmc_response_capabilities_488_t const

View File

@ -180,7 +180,7 @@ static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
}
#endif
size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
static size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
uint32_t idx = ctl_idx + stm_idx;
if (idx == 0) {
@ -205,8 +205,7 @@ size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, voi
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
void video_send_frame(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
static void video_send_frame(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
static unsigned start_ms[CFG_TUD_VIDEO_STREAMING] = {0, };
static unsigned already_sent = 0;

View File

@ -107,7 +107,7 @@ int main(void) {
}
// send characters to both CDC and WebUSB
void echo_all(const uint8_t buf[], uint32_t count) {
static void echo_all(const uint8_t buf[], uint32_t count) {
// echo to web serial
if (web_serial_connected) {
tud_vendor_write(buf, count);

View File

@ -0,0 +1,32 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2025 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
#define TUSB_TINYUSB_EXAMPLES_APP_H
void cdc_app_task(void);
void hid_app_task(void);
#endif

View File

@ -26,6 +26,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
#include "app.h"
static size_t get_console_inputs(uint8_t* buf, size_t bufsize) {
size_t count = 0;

View File

@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "app.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION

View File

@ -29,13 +29,12 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTOTYPES
//--------------------------------------------------------------------+
void led_blinking_task(void);
extern void cdc_app_task(void);
extern void hid_app_task(void);
/*------------- MAIN -------------*/
int main(void) {

View File

@ -0,0 +1,33 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2025 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
#define TUSB_TINYUSB_EXAMPLES_APP_H
void cdc_app_init(void);
void hid_app_init(void);
void msc_app_init(void);
#endif

View File

@ -26,6 +26,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
#include "app.h"
#ifdef ESP_PLATFORM
#define CDC_STACK_SZIE 2048

View File

@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "app.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
@ -160,7 +161,7 @@ static void process_kbd_report(hid_keyboard_report_t const *report) {
// Mouse
//--------------------------------------------------------------------+
void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
static void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
#if USE_ANSI_ESCAPE
// Move X using ansi escape
if ( x < 0) {

View File

@ -29,6 +29,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "app.h"
#ifdef ESP_PLATFORM
#define USBH_STACK_SIZE 4096
@ -65,9 +66,6 @@ TimerHandle_t blinky_tm;
static void led_blinky_cb(TimerHandle_t xTimer);
static void usb_host_task(void* param);
extern void cdc_app_init(void);
extern void hid_app_init(void);
extern void msc_app_init(void);
/*------------- MAIN -------------*/
int main(void) {

View File

@ -24,6 +24,7 @@
*/
#include "tusb.h"
#include "app.h"
// define the buffer to be place in USB/DMA memory with correct alignment/cache line size
CFG_TUH_MEM_SECTION static struct {

View File

@ -0,0 +1,31 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2025 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
#define TUSB_TINYUSB_EXAMPLES_APP_H
void hid_app_task(void);
#endif

View File

@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "app.h"
/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
____________________________ __

View File

@ -34,18 +34,15 @@
#include "bsp/board_api.h"
#include "tusb.h"
#include "app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
void led_blinking_task(void);
extern void cdc_task(void);
extern void hid_app_task(void);
/*------------- MAIN -------------*/
int main(void)
{
int main(void) {
board_init();
printf("TinyUSB Host HID Controller Example\r\n");
@ -60,19 +57,11 @@ int main(void)
board_init_after_tusb();
while (1)
{
while (1) {
// tinyusb host task
tuh_task();
led_blinking_task();
#if CFG_TUH_CDC
cdc_task();
#endif
#if CFG_TUH_HID
hid_app_task();
#endif
}
}
@ -83,8 +72,7 @@ int main(void)
//--------------------------------------------------------------------+
// Blinking Task
//--------------------------------------------------------------------+
void led_blinking_task(void)
{
void led_blinking_task(void) {
const uint32_t interval_ms = 1000;
static uint32_t start_ms = 0;

View File

@ -180,9 +180,11 @@ uint32_t tusb_time_millis_api(void) {
// FreeRTOS hooks
//--------------------------------------------------------------------
#if CFG_TUSB_OS == OPT_OS_FREERTOS && !defined(ESP_PLATFORM)
#include "FreeRTOS.h"
#include "task.h"
void vApplicationMallocFailedHook(void); // missing prototype
void vApplicationMallocFailedHook(void) {
taskDISABLE_INTERRUPTS();
TU_ASSERT(false, );
@ -199,7 +201,7 @@ void vApplicationStackOverflowHook(xTaskHandle pxTask, char *pcTaskName) {
/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
* used by the Idle task. */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) {
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
/* If the buffers to be provided to the Idle task are declared inside this
* function then they must be declared static - otherwise they will be allocated on
* the stack and so not exists after this function exits. */
@ -243,6 +245,8 @@ void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, Stack
}
#if CFG_TUSB_MCU == OPT_MCU_RX63X || CFG_TUSB_MCU == OPT_MCU_RX65X
void vApplicationSetupTimerInterrupt(void);
#include "iodefine.h"
void vApplicationSetupTimerInterrupt(void) {
/* Enable CMT0 */

View File

@ -38,6 +38,35 @@ if (NOT DEFINED TOOLCHAIN)
set(TOOLCHAIN gcc)
endif ()
set(WARN_FLAGS_GNU
-Wall
-Wextra
-Werror
-Wfatal-errors
-Wdouble-promotion
-Wstrict-prototypes
-Wstrict-overflow
-Werror-implicit-function-declaration
-Wfloat-equal
-Wundef
-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-function-type
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wunused-function
-Wreturn-type
-Wredundant-decls
-Wmissing-prototypes
)
set(WARN_FLAGS_Clang ${WARN_FLAGS_GNU})
# Optimization
if (NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Build type" FORCE)
@ -48,8 +77,8 @@ endif ()
#-------------------------------------------------------------
if (NOT DEFINED FAMILY)
if (NOT DEFINED BOARD)
message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, espressif).
You can do this via -DFAMILY=xxx on the cmake command line")
message(FATAL_ERROR "You must set a BOARD variable for the build (e.g. metro_m4_express, raspberry_pi_pico).
You can do this via -DBOARD=xxx on the cmake command line")
endif ()
# Find path contains BOARD
@ -226,33 +255,7 @@ function(family_configure_common TARGET RTOS)
endif ()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE
-Wall
-Wextra
#-Werror
-Wfatal-errors
-Wdouble-promotion
-Wstrict-prototypes
-Wstrict-overflow
-Werror-implicit-function-declaration
-Wfloat-equal
-Wundef
-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-function-type
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wunused-function
-Wreturn-type
-Wredundant-decls
-Wmissing-prototypes
)
target_compile_options(${TARGET} PRIVATE ${WARN_FLAGS_${CMAKE_C_COMPILER_ID}})
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0
AND NO_WARN_RWX_SEGMENTS_SUPPORTED AND (NOT RTOS STREQUAL zephyr))

View File

@ -145,7 +145,7 @@ static __inline void free_entry(dhcp_entry_t *entry)
memset(entry->mac, 0, 6);
}
uint8_t *find_dhcp_option(uint8_t *attrs, int size, uint8_t attr)
static uint8_t *find_dhcp_option(uint8_t *attrs, int size, uint8_t attr)
{
int i = 0;
while ((i + 1) < size)
@ -159,7 +159,7 @@ uint8_t *find_dhcp_option(uint8_t *attrs, int size, uint8_t attr)
return NULL;
}
int fill_options(void *dest,
static int fill_options(void *dest,
uint8_t msg_type,
const char *domain,
ip4_addr_t dns,

View File

@ -29,7 +29,10 @@
#include <stdalign.h>
#include <string.h>
#include "class/net/net_device.h"
#include "tusb.h"
#if CFG_TUD_ECM_RNDIS
#include "rndis_protocol.h"
#include "netif/ethernet.h"
@ -299,3 +302,5 @@ void rndis_class_set_handler(uint8_t *data, int size)
break;
}
}
#endif

View File

@ -360,6 +360,7 @@ bool tud_audio_feedback_format_correction_cb(uint8_t func_id);
#if CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP
void tud_audio_int_done_cb(uint8_t rhport);
void tud_audio_int_xfer_cb(uint8_t rhport);
#endif
// Invoked when audio set interface request received

View File

@ -35,8 +35,6 @@
#include "net_device.h"
#include "rndis_protocol.h"
extern void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networking/rndis_reports.c */
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0

View File

@ -55,6 +55,13 @@ typedef enum
extern "C" {
#endif
//--------------------------------------------------------------------+
// Implemented by Application
//--------------------------------------------------------------------+
#if CFG_TUD_ECM_RNDIS
extern void rndis_class_set_handler(uint8_t *data, int size);
#endif
//--------------------------------------------------------------------+
// Application API
//--------------------------------------------------------------------+