From 728136a91d7c0536201bdc1f40dbfb0e4e0bf15e Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 12 Jul 2024 12:14:32 +0200 Subject: [PATCH 1/5] fix(esp_eth): fix variable declarations inside switch for clang --- components/esp_eth/src/mac/esp_eth_mac_esp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/esp_eth/src/mac/esp_eth_mac_esp.c b/components/esp_eth/src/mac/esp_eth_mac_esp.c index dddf0d24b1..14bfec2f63 100644 --- a/components/esp_eth/src/mac/esp_eth_mac_esp.c +++ b/components/esp_eth/src/mac/esp_eth_mac_esp.c @@ -260,8 +260,7 @@ esp_err_t emac_esp_custom_ioctl(esp_eth_mac_t *mac, int cmd, void *data) { emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent); - switch (cmd) - { + switch (cmd) { case ETH_MAC_ESP_CMD_PTP_ENABLE: return ESP_ERR_NOT_SUPPORTED; case ETH_MAC_ESP_CMD_SET_TDES0_CFG_BITS: @@ -282,7 +281,7 @@ static esp_err_t emac_esp32_transmit(esp_eth_mac_t *mac, uint8_t *buf, uint32_t { emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent); uint32_t sent_len = emac_esp_dma_transmit_frame(emac->emac_dma_hndl, buf, length); - if(sent_len != length) { + if (sent_len != length) { ESP_LOGD(TAG, "insufficient TX buffer size"); return ESP_ERR_NO_MEM; } @@ -583,7 +582,7 @@ static esp_err_t emac_esp_config_data_interface(const eth_esp32_emac_config_t *e { esp_err_t ret = ESP_OK; switch (esp32_emac_config->interface) { - case EMAC_DATA_INTERFACE_MII: + case EMAC_DATA_INTERFACE_MII: { /* MII interface GPIO initialization */ #if SOC_EMAC_MII_USE_GPIO_MATRIX ESP_GOTO_ON_ERROR(emac_esp_gpio_matrix_init_mii(&esp32_emac_config->emac_dataif_gpio.mii), err, TAG, "failed to initialize EMAC MII GPIO Matrix"); @@ -599,7 +598,8 @@ static esp_err_t emac_esp_config_data_interface(const eth_esp32_emac_config_t *e emac_hal_clock_enable_mii(&emac->hal); } break; - case EMAC_DATA_INTERFACE_RMII: + } + case EMAC_DATA_INTERFACE_RMII: { /* RMII interface GPIO initialization */ const eth_mac_rmii_gpio_config_t *rmii_data_gpio = NULL; #if SOC_EMAC_USE_MULTI_IO_MUX @@ -640,6 +640,7 @@ static esp_err_t emac_esp_config_data_interface(const eth_esp32_emac_config_t *e ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "invalid EMAC clock mode"); } break; + } default: ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "invalid EMAC Data Interface:%i", esp32_emac_config->interface); } From c921824230f70baaf686c8dcbcd253f98c1d84f4 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 12 Jul 2024 12:16:07 +0200 Subject: [PATCH 2/5] fix(wifi_provisioning): fix var declarations inside switch for clang --- components/wifi_provisioning/src/scheme_ble.c | 103 +++++++++--------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/components/wifi_provisioning/src/scheme_ble.c b/components/wifi_provisioning/src/scheme_ble.c index 6b594f22c4..16d64a12f2 100644 --- a/components/wifi_provisioning/src/scheme_ble.c +++ b/components/wifi_provisioning/src/scheme_ble.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -41,7 +41,7 @@ static esp_err_t prov_start(protocomm_t *pc, void *config) protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config; #if defined(CONFIG_WIFI_PROV_BLE_BONDING) - ble_config->ble_bonding = 1; + ble_config->ble_bonding = 1; #endif #if defined(CONFIG_WIFI_PROV_BLE_SEC_CONN) || defined(CONFIG_BT_BLUEDROID_ENABLED) @@ -183,7 +183,7 @@ static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, ui } protocomm_ble_name_uuid_t *lookup_table = ( - realloc(ble_config->nu_lookup, (ble_config->nu_lookup_count + 1) * sizeof(protocomm_ble_name_uuid_t))); + realloc(ble_config->nu_lookup, (ble_config->nu_lookup_count + 1) * sizeof(protocomm_ble_name_uuid_t))); if (!lookup_table) { ESP_LOGE(TAG, "Error allocating memory for EP-UUID lookup table"); return ESP_ERR_NO_MEM; @@ -200,35 +200,34 @@ static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, ui void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event_t event, void *event_data) { switch (event) { - case WIFI_PROV_INIT: + case WIFI_PROV_INIT: { #ifdef CONFIG_BT_CONTROLLER_ENABLED - esp_err_t err; - /* Release BT memory, as we need only BLE */ - err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of classic BT failed %d", err); - } else { - ESP_LOGI(TAG, "BT memory released"); - } + /* Release BT memory, as we need only BLE */ + esp_err_t err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); + if (err != ESP_OK) { + ESP_LOGE(TAG, "bt_mem_release of classic BT failed %d", err); + } else { + ESP_LOGI(TAG, "BT memory released"); + } #endif - break; - - case WIFI_PROV_DEINIT: + break; + } + case WIFI_PROV_DEINIT: { #ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV #ifdef CONFIG_BT_CONTROLLER_ENABLED - /* Release memory used by BLE and Bluedroid host stack */ - err = esp_bt_mem_release(ESP_BT_MODE_BTDM); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of BTDM failed %d", err); - } else { - ESP_LOGI(TAG, "BTDM memory released"); - } + /* Release memory used by BLE and Bluedroid host stack */ + esp_err_t err = esp_bt_mem_release(ESP_BT_MODE_BTDM); + if (err != ESP_OK) { + ESP_LOGE(TAG, "bt_mem_release of BTDM failed %d", err); + } else { + ESP_LOGI(TAG, "BTDM memory released"); + } #endif #endif - break; - - default: - break; + break; + } + default: + break; } } @@ -236,21 +235,21 @@ void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event void wifi_prov_scheme_ble_event_cb_free_bt(void *user_data, wifi_prov_cb_event_t event, void *event_data) { switch (event) { - case WIFI_PROV_INIT: + case WIFI_PROV_INIT: { #ifdef CONFIG_BT_CONTROLLER_ENABLED - esp_err_t err; - /* Release BT memory, as we need only BLE */ - err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of classic BT failed %d", err); - } else { - ESP_LOGI(TAG, "BT memory released"); - } + esp_err_t err; + /* Release BT memory, as we need only BLE */ + err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); + if (err != ESP_OK) { + ESP_LOGE(TAG, "bt_mem_release of classic BT failed %d", err); + } else { + ESP_LOGI(TAG, "BT memory released"); + } #endif - break; - - default: - break; + break; + } + default: + break; } } @@ -258,23 +257,23 @@ void wifi_prov_scheme_ble_event_cb_free_bt(void *user_data, wifi_prov_cb_event_t void wifi_prov_scheme_ble_event_cb_free_ble(void *user_data, wifi_prov_cb_event_t event, void *event_data) { switch (event) { - case WIFI_PROV_DEINIT: + case WIFI_PROV_DEINIT: { #ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV #ifdef CONFIG_BT_CONTROLLER_ENABLED - esp_err_t err; - /* Release memory used by BLE stack */ - err = esp_bt_mem_release(ESP_BT_MODE_BLE); - if (err != ESP_OK) { - ESP_LOGE(TAG, "bt_mem_release of BLE failed %d", err); - } else { - ESP_LOGI(TAG, "BLE memory released"); - } + esp_err_t err; + /* Release memory used by BLE stack */ + err = esp_bt_mem_release(ESP_BT_MODE_BLE); + if (err != ESP_OK) { + ESP_LOGE(TAG, "bt_mem_release of BLE failed %d", err); + } else { + ESP_LOGI(TAG, "BLE memory released"); + } #endif #endif - break; - - default: - break; + break; + } + default: + break; } } From df65b3829eb6d406df47a09372b93cb68af26dcc Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 12 Jul 2024 13:57:51 +0200 Subject: [PATCH 3/5] fix(usb): variable declaration after label for clang --- components/usb/hcd_dwc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/usb/hcd_dwc.c b/components/usb/hcd_dwc.c index 9911c62466..345cbe4707 100644 --- a/components/usb/hcd_dwc.c +++ b/components/usb/hcd_dwc.c @@ -1263,6 +1263,7 @@ static esp_err_t _port_cmd_reset(port_t *port) ret = ESP_OK; bailout: // Reinitialize channel registers + (void) 0; // clang doesn't allow variable declarations after labels pipe_t *pipe; TAILQ_FOREACH(pipe, &port->pipes_idle_tailq, tailq_entry) { usb_dwc_hal_chan_set_ep_char(port->hal, pipe->chan_obj, &pipe->ep_char); From 6c2824bdaad77acc8923dfb723cb5f2d50df63e4 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 12 Jul 2024 12:17:01 +0200 Subject: [PATCH 4/5] ci(clang): include all components in clang_build_test --- tools/test_apps/system/clang_build_test/CMakeLists.txt | 4 ++-- tools/test_apps/system/clang_build_test/main/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/test_apps/system/clang_build_test/CMakeLists.txt b/tools/test_apps/system/clang_build_test/CMakeLists.txt index cd85707a09..3d9f414280 100644 --- a/tools/test_apps/system/clang_build_test/CMakeLists.txt +++ b/tools/test_apps/system/clang_build_test/CMakeLists.txt @@ -3,5 +3,5 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(COMPONENTS main) -project(cpp_pthread) +# Note: not setting set(COMPONENTS main) here, this app should build all the components +project(clang_build_test) diff --git a/tools/test_apps/system/clang_build_test/main/CMakeLists.txt b/tools/test_apps/system/clang_build_test/main/CMakeLists.txt index 7f0828d2a3..079bf9c6ab 100644 --- a/tools/test_apps/system/clang_build_test/main/CMakeLists.txt +++ b/tools/test_apps/system/clang_build_test/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "test_main.cpp" - INCLUDE_DIRS "." - PRIV_REQUIRES pthread bt) + INCLUDE_DIRS ".") +# Note: not setting PRIV_REQUIRES, this app should build all the components. From 3d0b50734652fad3ec6dce55070e05eddc2b5147 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 12 Jul 2024 14:18:56 +0200 Subject: [PATCH 5/5] fix(ieee802154): fix linker error due to static function being inlined When the compiler decides to inline a static function, linker script generator will complain about the missing function. --- components/ieee802154/driver/esp_ieee802154_dev.c | 2 +- components/ieee802154/driver/esp_ieee802154_frame.c | 8 ++++---- components/ieee802154/linker.lf | 1 + .../ieee802154/private_include/esp_ieee802154_dev.h | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index c537181479..d7f98198cc 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -136,7 +136,7 @@ static IRAM_ATTR void receive_ack_timeout_timer_start(uint32_t duration) } #endif -static void ieee802154_rx_frame_info_update(void) +static IEEE802154_NOINLINE void ieee802154_rx_frame_info_update(void) { uint8_t len = s_rx_frame[s_rx_index][0]; int8_t rssi = s_rx_frame[s_rx_index][len - 1]; // crc is not written to rx buffer diff --git a/components/ieee802154/driver/esp_ieee802154_frame.c b/components/ieee802154/driver/esp_ieee802154_frame.c index e32e338ae0..9bc2305806 100644 --- a/components/ieee802154/driver/esp_ieee802154_frame.c +++ b/components/ieee802154/driver/esp_ieee802154_frame.c @@ -49,7 +49,7 @@ IEEE802154_STATIC IEEE802154_INLINE bool is_suported_frame_type(uint8_t frame_ty frame_type == IEEE802154_FRAME_TYPE_ACK || frame_type == IEEE802154_FRAME_TYPE_COMMAND); } -IEEE802154_STATIC bool is_dst_panid_present(const uint8_t *frame) +IEEE802154_STATIC IEEE802154_NOINLINE bool is_dst_panid_present(const uint8_t *frame) { uint8_t dst_mode = dst_addr_mode(frame); bool dst_panid_present = false; @@ -79,7 +79,7 @@ IEEE802154_STATIC bool is_dst_panid_present(const uint8_t *frame) return dst_panid_present; } -IEEE802154_STATIC bool is_src_panid_present(const uint8_t *frame) +IEEE802154_STATIC IEEE802154_NOINLINE bool is_src_panid_present(const uint8_t *frame) { uint8_t src_mode = src_addr_mode(frame); bool panid_compression = is_panid_compression(frame); @@ -160,7 +160,7 @@ IEEE802154_STATIC IRAM_ATTR uint8_t ieee802154_frame_address_size(const uint8_t return address_size; } -IEEE802154_STATIC uint8_t ieee802154_frame_security_header_offset(const uint8_t *frame) +IEEE802154_STATIC IEEE802154_NOINLINE uint8_t ieee802154_frame_security_header_offset(const uint8_t *frame) { ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, IEEE802154_TAG, "invalid frame type"); uint8_t offset = ieee802154_frame_address_offset(frame); @@ -174,7 +174,7 @@ IEEE802154_STATIC uint8_t ieee802154_frame_security_header_offset(const uint8_t return offset; } -IEEE802154_STATIC uint8_t ieee802154_frame_get_security_field_len(const uint8_t *frame) +IEEE802154_STATIC IEEE802154_NOINLINE uint8_t ieee802154_frame_get_security_field_len(const uint8_t *frame) { ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_TAG, "invalid frame type"); diff --git a/components/ieee802154/linker.lf b/components/ieee802154/linker.lf index b0a01b70c0..e78d00a5db 100644 --- a/components/ieee802154/linker.lf +++ b/components/ieee802154/linker.lf @@ -2,6 +2,7 @@ archive: libieee802154.a entries: if IEEE802154_ENABLED = y: + # When adding static functions here, add IEEE802154_NOINLINE attribute to them esp_ieee802154_ack: ieee802154_ack_config_pending_bit (noflash) esp_ieee802154_dev: ieee802154_rx_frame_info_update (noflash) esp_ieee802154_dev: ieee802154_isr (noflash) diff --git a/components/ieee802154/private_include/esp_ieee802154_dev.h b/components/ieee802154/private_include/esp_ieee802154_dev.h index ace28cd5f7..76db12a243 100644 --- a/components/ieee802154/private_include/esp_ieee802154_dev.h +++ b/components/ieee802154/private_include/esp_ieee802154_dev.h @@ -245,6 +245,7 @@ extern void esp_ieee802154_timer1_done(void); #define IEEE802154_STATIC static #define IEEE802154_INLINE inline #endif // CONFIG_IEEE802154_TEST +#define IEEE802154_NOINLINE __attribute__((noinline)) #ifdef __cplusplus }