diff --git a/CMakeLists.txt b/CMakeLists.txt index a0ef70d15..4dae14c8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,16 @@ unset(compile_definitions) # Add the following build specifications here, since these seem to be dependent # on config values on the root Kconfig. -if(CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE) +if(CONFIG_COMPILER_OPTIMIZATION_SIZE) list(APPEND compile_options "-Os") list(APPEND compile_options "-freorder-blocks") -else() +elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT) list(APPEND compile_options "-Og") +elseif(CONFIG_COMPILER_OPTIMIZATION_NONE) + list(APPEND compile_options "-O0") +elseif(CONFIG_COMPILER_OPTIMIZATION_PERF) + list(APPEND compile_options "-O2") + endif() if(CONFIG_COMPILER_CXX_EXCEPTIONS) diff --git a/Kconfig b/Kconfig index 0fcb5e1e5..2f1d8e76d 100644 --- a/Kconfig +++ b/Kconfig @@ -40,6 +40,13 @@ mainmenu "Espressif IoT Development Framework Configuration" default "n" select FREERTOS_UNICORE + config IDF_FIRMWARE_CHIP_ID + hex + default 0x0000 if IDF_TARGET_ESP32 + # note: S2 beta uses Chip ID 0 still, S2 will use 0x0002 + default 0x0000 if IDF_TARGET_ESP32S2BETA + default 0xFFFF + menu "SDK tool configuration" config SDK_TOOLPREFIX string "Compiler toolchain path/prefix" @@ -81,24 +88,35 @@ mainmenu "Espressif IoT Development Framework Configuration" choice COMPILER_OPTIMIZATION prompt "Optimization Level" - default COMPILER_OPTIMIZATION_LEVEL_DEBUG + default COMPILER_OPTIMIZATION_DEFAULT help This option sets compiler optimization level (gcc -O argument). - - for "Release" setting, -Os flag is added to CFLAGS. - - for "Debug" setting, -Og flag is added to CFLAGS. + - The "Default" setting will add the -0g flag to CFLAGS. + - The "Size" setting will add the -0s flag to CFLAGS. + - The "Performance" setting will add the -O2 flag to CFLAGS. + - The "None" setting will add the -O0 flag to CFLAGS. - "Release" with -Os produces smaller & faster compiled code but it - may be harder to correlated code addresses to source files when debugging. + The "Size" setting cause the compiled code to be smaller and faster, but + may lead to difficulties of correlating code addresses to source file + lines when debugging. - To add custom optimization settings, set CFLAGS and/or CPPFLAGS - in project makefile, before including $(IDF_PATH)/make/project.mk. Note that - custom optimization levels may be unsupported. + The "Performance" setting causes the compiled code to be larger and faster, + but will be easier to correlated code addresses to source file lines. - config COMPILER_OPTIMIZATION_LEVEL_DEBUG + "None" with -O0 produces compiled code without optimization. + + Note that custom optimization levels may be unsupported. + + config COMPILER_OPTIMIZATION_DEFAULT bool "Debug (-Og)" - config COMPILER_OPTIMIZATION_LEVEL_RELEASE - bool "Release (-Os)" + config COMPILER_OPTIMIZATION_SIZE + bool "Optimize for size (-Os)" + config COMPILER_OPTIMIZATION_PERF + bool "Optimize for performance (-O2)" + config COMPILER_OPTIMIZATION_NONE + bool "Debug without optimization (-O0)" + endchoice choice COMPILER_OPTIMIZATION_ASSERTION_LEVEL diff --git a/components/app_update/Makefile.projbuild b/components/app_update/Makefile.projbuild index 4081aab97..886ca569a 100644 --- a/components/app_update/Makefile.projbuild +++ b/components/app_update/Makefile.projbuild @@ -40,9 +40,6 @@ read_otadata: $(PARTITION_TABLE_CSV_PATH) partition_table_get_info | check_pytho --partition-table-offset $(partition_table_offset) \ read_otadata -erase_ota: erase_otadata - @echo "WARNING: erase_ota is deprecated. Use erase_otadata instead." - all: blank_ota_data flash: blank_ota_data ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index baf4c3b86..eb2bddebb 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -202,7 +202,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size) // must erase the partition before writing to it assert(it->erased_size > 0 && "must erase the partition before writing to it"); if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) { - ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x", data_bytes[0]); + ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x)", data_bytes[0]); return ESP_ERR_OTA_VALIDATE_FAILED; } diff --git a/components/bootloader_support/include/bootloader_common.h b/components/bootloader_support/include/bootloader_common.h index 504285df0..b3f818bea 100644 --- a/components/bootloader_support/include/bootloader_common.h +++ b/components/bootloader_support/include/bootloader_common.h @@ -15,6 +15,7 @@ #pragma once #include "esp_flash_partitions.h" #include "esp_image_format.h" +#include "esp_app_format.h" #ifdef __cplusplus extern "C" { @@ -148,6 +149,16 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata, */ esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t *partition, esp_app_desc_t *app_desc); +/** + * @brief Check if the image (bootloader and application) has valid chip ID and revision + * + * @param img_hdr: image header + * @return + * - ESP_OK: image and chip are matched well + * - ESP_FAIL: image doesn't match to the chip + */ +esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr); + /** * @brief Configure VDDSDIO, call this API to rise VDDSDIO to 1.9V when VDDSDIO regulator is enabled as 1.8V mode. */ diff --git a/components/bootloader_support/include/esp_app_format.h b/components/bootloader_support/include/esp_app_format.h index 4917dd0f7..c7edaebd2 100644 --- a/components/bootloader_support/include/esp_app_format.h +++ b/components/bootloader_support/include/esp_app_format.h @@ -13,6 +13,19 @@ // limitations under the License. #pragma once +/** + * @brief ESP chip ID + * + */ +typedef enum { + ESP_CHIP_ID_ESP32 = 0x0000, /*!< chip ID: ESP32 */ + ESP_CHIP_ID_INVALID = 0xFFFF /*!< Invalid chip ID (we defined it to make sure the esp_chip_id_t is 2 bytes size) */ +} __attribute__((packed)) esp_chip_id_t; + +/** @cond */ +_Static_assert(sizeof(esp_chip_id_t) == 2, "esp_chip_id_t should be 16 bit"); +/** @endcond */ + /** * @brief SPI flash mode, used in esp_image_header_t */ @@ -63,7 +76,9 @@ typedef struct { * the IDF bootloader uses software to configure the WP * pin and sets this field to 0xEE=disabled) */ uint8_t spi_pin_drv[3]; /*!< Drive settings for the SPI flash pins (read by ROM bootloader) */ - uint8_t reserved[11]; /*!< Reserved bytes in ESP32 additional header space, currently unused */ + esp_chip_id_t chip_id; /*!< Chip identification number */ + uint8_t min_chip_rev; /*!< Minimum chip revision supported by image */ + uint8_t reserved[8]; /*!< Reserved bytes in additional header space, currently unused */ uint8_t hash_appended; /*!< If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum. * Included in image length. This digest * is separate to secure boot and only used for detecting corruption. diff --git a/components/bootloader_support/include/esp_flash_partitions.h b/components/bootloader_support/include/esp_flash_partitions.h index e652cc300..004bbeb23 100644 --- a/components/bootloader_support/include/esp_flash_partitions.h +++ b/components/bootloader_support/include/esp_flash_partitions.h @@ -98,12 +98,6 @@ typedef struct { esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions); -/* This function is included for compatibility with the ESP-IDF v3.x API */ -inline static __attribute__((deprecated)) esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions) -{ - return esp_partition_table_verify(partition_table, log_errors, num_partitions); -} - /** * Check whether the region on the main flash is safe to write. * diff --git a/components/bootloader_support/include/esp_image_format.h b/components/bootloader_support/include/esp_image_format.h index 4e656a17b..928a29adf 100644 --- a/components/bootloader_support/include/esp_image_format.h +++ b/components/bootloader_support/include/esp_image_format.h @@ -79,36 +79,6 @@ _Static_assert(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE % 4 == 0, "CONFIG_BOOTLOADER_R _Static_assert(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reserved RTC area must exceed size of rtc_retain_mem_t"); #endif -/** - * @brief Verify and (optionally, in bootloader mode) load an app image. - * - * This name is deprecated and is included for compatibility with the ESP-IDF v3.x API. - * It will be removed in V4.0 version. - * Function has been renamed to esp_image_verify(). - * Use function esp_image_verify() to verify a image. And use function bootloader_load_image() to load image from a bootloader space. - * - * If encryption is enabled, data will be transparently decrypted. - * - * @param mode Mode of operation (verify, silent verify, or load). - * @param part Partition to load the app from. - * @param[inout] data Pointer to the image metadata structure which is be filled in by this function. 'start_addr' member should be set (to the start address of the image.) Other fields will all be initialised by this function. - * - * Image validation checks: - * - Magic byte. - * - Partition smaller than 16MB. - * - All segments & image fit in partition. - * - 8 bit image checksum is valid. - * - SHA-256 of image is valid (if image has this appended). - * - (Signature) if signature verification is enabled. - * - * @return - * - ESP_OK if verify or load was successful - * - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs - * - ESP_ERR_IMAGE_INVALID if the image appears invalid. - * - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid. - */ -esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) __attribute__((deprecated)); - /** * @brief Verify an app image. * diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index 0e41dc326..3b0e7c4c5 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -35,6 +35,7 @@ #include "esp_image_format.h" #include "bootloader_sha.h" #include "sys/param.h" +#include "esp_efuse.h" #define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */ @@ -278,6 +279,25 @@ void bootloader_common_vddsdio_configure(void) #endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST } +esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr) +{ + esp_err_t err = ESP_OK; + esp_chip_id_t chip_id = CONFIG_IDF_FIRMWARE_CHIP_ID; + if (chip_id != img_hdr->chip_id) { + ESP_LOGE(TAG, "image has invalid chip ID, expected at least %d, found %d", chip_id, img_hdr->chip_id); + err = ESP_FAIL; + } + uint8_t revision = esp_efuse_get_chip_ver(); + if (revision < img_hdr->min_chip_rev) { + ESP_LOGE(TAG, "image has invalid chip revision, expected at least %d, found %d", revision, img_hdr->min_chip_rev); + err = ESP_FAIL; + } else if (revision != img_hdr->min_chip_rev) { + ESP_LOGI(TAG, "This chip is revision %d but project was configured for minimum revision %d. "\ + "Suggest setting project minimum revision to %d if safe to do so.", + revision, img_hdr->min_chip_rev, revision); + } + return err; +} #if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC ) @@ -339,4 +359,4 @@ rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void) { return rtc_retain_mem; } -#endif \ No newline at end of file +#endif diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index 59941ad78..76258a696 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -60,6 +60,7 @@ #endif #include "sdkconfig.h" +#include "esp_efuse.h" #include "esp_image_format.h" #include "esp_secure_boot.h" #include "esp_flash_encrypt.h" @@ -168,6 +169,14 @@ static esp_err_t bootloader_main(void) ESP_LOGE(TAG, "failed to load bootloader header!"); return ESP_FAIL; } + + /* Check chip ID and minimum chip revision that supported by this image */ + uint8_t revision = esp_efuse_get_chip_ver(); + ESP_LOGI(TAG, "Chip Revision: %d", revision); + if (bootloader_common_check_chip_validity(&fhdr) != ESP_OK) { + return ESP_FAIL; + } + bootloader_init_flash_configure(&fhdr); #ifdef CONFIG_IDF_TARGET_ESP32 diff --git a/components/bootloader_support/src/esp_image_format.c b/components/bootloader_support/src/esp_image_format.c index 03647ae05..1511f0efe 100644 --- a/components/bootloader_support/src/esp_image_format.c +++ b/components/bootloader_support/src/esp_image_format.c @@ -22,7 +22,7 @@ #include #include #include "bootloader_util.h" -#include "bootloader_utility.h" +#include "bootloader_common.h" #if CONFIG_IDF_TARGET_ESP32 #include #include @@ -300,8 +300,6 @@ esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t return image_load(mode, part, data); } -esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) __attribute__((alias("esp_image_verify"))); - static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t *image, bool silent) { esp_err_t err = ESP_OK; @@ -312,6 +310,9 @@ static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t } err = ESP_ERR_IMAGE_INVALID; } + if (bootloader_common_check_chip_validity(image) != ESP_OK) { + err = ESP_ERR_IMAGE_INVALID; + } if (!silent) { if (image->spi_mode > ESP_IMAGE_SPI_MODE_SLOW_READ) { ESP_LOGW(TAG, "image at 0x%x has invalid SPI mode %d", src_addr, image->spi_mode); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index a60fa6c0f..c0a155bed 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -315,6 +315,8 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model, return; } + bt_mesh_client_model_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false); if (node == NULL) { msg.act = ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT; @@ -334,12 +336,21 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model, msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_MODEL; - if (msg.act != ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) { - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&data->queue, node); + if (msg.act == ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) { + ret = btc_transfer_context(&msg, &mesh_param, + sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + } else { + if (!k_delayed_work_free(&node->timer)) { + ret = btc_transfer_context(&msg, &mesh_param, + sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&data->queue, node); + } else { + ret = BT_STATUS_SUCCESS; + } } - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + + bt_mesh_client_model_unlock(); if (ret != BT_STATUS_SUCCESS) { LOG_ERROR("%s, btc_transfer_context failed", __func__); @@ -611,21 +622,29 @@ static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work) return; } - mesh_param.client_send_timeout.opcode = node->opcode; - mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model; - mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx; + bt_mesh_client_model_lock(); - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + if (!k_delayed_work_free(&node->timer)) { + mesh_param.client_send_timeout.opcode = node->opcode; + mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model; + mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx; - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_MODEL; + msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT; + + ret = btc_transfer_context(&msg, &mesh_param, + sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("%s btc_transfer_context failed", __func__); + } + + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&data->queue, node); } - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&data->queue, node); + + bt_mesh_client_model_unlock(); + return; } diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index 94374d98e..55a6d25c3 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -505,17 +505,21 @@ static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem, struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr) { - int i; + u16_t index; - for (i = 0; i < dev_comp->elem_count; i++) { - struct bt_mesh_elem *elem = &dev_comp->elem[i]; + if (BLE_MESH_ADDR_IS_UNICAST(addr)) { + index = (addr - dev_comp->elem[0].addr); + if (index < dev_comp->elem_count) { + return &dev_comp->elem[index]; + } else { + return NULL; + } + } - if (BLE_MESH_ADDR_IS_GROUP(addr) || - BLE_MESH_ADDR_IS_VIRTUAL(addr)) { - if (bt_mesh_elem_find_group(elem, addr)) { - return elem; - } - } else if (elem->addr == addr) { + for (index = 0; index < dev_comp->elem_count; index++) { + struct bt_mesh_elem *elem = &dev_comp->elem[index]; + + if (bt_mesh_elem_find_group(elem, addr)) { return elem; } } diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 3165ccb3f..2eb843e35 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -12,6 +12,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "sdkconfig.h" #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) @@ -82,6 +83,28 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = { { OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS }, }; +static osi_mutex_t cfg_client_mutex; + +static void bt_mesh_cfg_client_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&cfg_client_mutex); + init = true; + } +} + +static void bt_mesh_cfg_client_lock(void) +{ + osi_mutex_lock(&cfg_client_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +static void bt_mesh_cfg_client_unlock(void) +{ + osi_mutex_unlock(&cfg_client_mutex); +} + static void timeout_handler(struct k_work *work) { config_internal_data_t *internal = NULL; @@ -108,10 +131,16 @@ static void timeout_handler(struct k_work *work) return; } - bt_mesh_config_client_cb_evt_to_btc(node->opcode, - BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + bt_mesh_cfg_client_lock(); - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_config_client_cb_evt_to_btc(node->opcode, + BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } + + bt_mesh_cfg_client_unlock(); return; } @@ -139,6 +168,9 @@ static void cfg_client_cancel(struct bt_mesh_model *model, /* If it is a publish message, sent to the user directly. */ buf.data = (u8_t *)status; buf.len = (u16_t)len; + + bt_mesh_cfg_client_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true); if (!node) { BT_DBG("Unexpected config status message 0x%x", ctx->recv_op); @@ -199,12 +231,16 @@ static void cfg_client_cancel(struct bt_mesh_model *model, break; } - bt_mesh_config_client_cb_evt_to_btc( - node->opcode, evt_type, model, ctx, (const u8_t *)status, len); - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&data->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_config_client_cb_evt_to_btc( + node->opcode, evt_type, model, ctx, (const u8_t *)status, len); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&data->queue, node); + } } + bt_mesh_cfg_client_unlock(); + switch (ctx->recv_op) { case OP_DEV_COMP_DATA_STATUS: { struct bt_mesh_cfg_comp_data_status *val; @@ -1653,5 +1689,7 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) /* Configuration Model security is device-key based */ model->keys[0] = BLE_MESH_KEY_DEV; + bt_mesh_cfg_client_mutex_new(); + return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 1e13befc6..e652bdda5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -12,6 +12,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "sdkconfig.h" #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) @@ -38,6 +39,28 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = { { OP_ATTENTION_SET, OP_ATTENTION_STATUS }, }; +static osi_mutex_t health_client_mutex; + +static void bt_mesh_health_client_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&health_client_mutex); + init = true; + } +} + +static void bt_mesh_health_client_lock(void) +{ + osi_mutex_lock(&health_client_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +static void bt_mesh_health_client_unlock(void) +{ + osi_mutex_unlock(&health_client_mutex); +} + static void timeout_handler(struct k_work *work) { health_internal_data_t *internal = NULL; @@ -64,10 +87,16 @@ static void timeout_handler(struct k_work *work) return; } - bt_mesh_health_client_cb_evt_to_btc(node->opcode, - BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + bt_mesh_health_client_lock(); - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_health_client_cb_evt_to_btc(node->opcode, + BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } + + bt_mesh_health_client_unlock(); return; } @@ -95,6 +124,9 @@ static void health_client_cancel(struct bt_mesh_model *model, /* If it is a publish message, sent to the user directly. */ buf.data = (u8_t *)status; buf.len = (u16_t)len; + + bt_mesh_health_client_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true); if (!node) { BT_DBG("Unexpected health status message 0x%x", ctx->recv_op); @@ -115,12 +147,16 @@ static void health_client_cancel(struct bt_mesh_model *model, break; } - bt_mesh_health_client_cb_evt_to_btc( - node->opcode, evt_type, model, ctx, (const u8_t *)status, len); - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&data->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_health_client_cb_evt_to_btc( + node->opcode, evt_type, model, ctx, (const u8_t *)status, len); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&data->queue, node); + } } + bt_mesh_health_client_unlock(); + switch (ctx->recv_op) { case OP_HEALTH_FAULT_STATUS: { struct bt_mesh_health_fault_status *val; @@ -453,6 +489,8 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) client->op_pair = health_op_pair; client->internal_data = internal; + bt_mesh_health_client_mutex_new(); + /* Set the default health client pointer */ if (!health_cli) { health_cli = client; diff --git a/components/bt/esp_ble_mesh/mesh_core/mesh_kernel.c b/components/bt/esp_ble_mesh/mesh_core/mesh_kernel.c index d1d1ca667..7ff4f75b8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/mesh_kernel.c +++ b/components/bt/esp_ble_mesh/mesh_core/mesh_kernel.c @@ -38,14 +38,6 @@ typedef struct alarm_t { int64_t deadline_us; } osi_alarm_t; -static void bt_mesh_alarm_cb(void *data) -{ - assert(data != NULL); - struct k_delayed_work *work = (struct k_delayed_work *)data; - work->work.handler(&work->work); - return; -} - unsigned int bt_mesh_irq_lock(void) { #if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK @@ -111,7 +103,7 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) { - alarm = osi_alarm_new("bt_mesh", bt_mesh_alarm_cb, (void *)work, 0); + alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)work, 0); if (alarm == NULL) { BT_ERR("%s, Unable to create alarm", __func__); return; @@ -189,17 +181,5 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work) return 0; } - if (!alarm->deadline_us) { - return 0; - } - - s32_t remain_time = 0; - int64_t now = esp_timer_get_time(); - if ((alarm->deadline_us - now) < 0x1FFFFFFFFFF) { - remain_time = (alarm->deadline_us - now) / 1000; - } else { - return 0; - } - - return remain_time; + return osi_alarm_get_remaining_ms(alarm); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index c2590935b..037dd98d0 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -16,6 +16,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "mesh_access.h" #include "mesh_buf.h" @@ -222,6 +223,28 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return err; } +static osi_mutex_t client_model_mutex; + +static void bt_mesh_client_model_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&client_model_mutex); + init = true; + } +} + +void bt_mesh_client_model_lock(void) +{ + osi_mutex_lock(&client_model_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +void bt_mesh_client_model_unlock(void) +{ + osi_mutex_unlock(&client_model_mutex); +} + int bt_mesh_client_init(struct bt_mesh_model *model) { bt_mesh_client_internal_data_t *data = NULL; @@ -256,17 +279,18 @@ int bt_mesh_client_init(struct bt_mesh_model *model) cli->model = model; cli->internal_data = data; + bt_mesh_client_model_mutex_new(); + return 0; } int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node) { if (!queue || !node) { + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - // Free the node timer - k_delayed_work_free(&node->timer); // Release the client node from the queue sys_slist_find_and_remove(queue, &node->client_node); // Free the node diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index f821fb3d9..617083cbd 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -17,6 +17,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "sdkconfig.h" #include "mesh_types.h" @@ -119,6 +120,28 @@ static const bt_mesh_client_op_pair_t gen_op_pair[] = { { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS }, }; +static osi_mutex_t generic_client_mutex; + +static void bt_mesh_generic_client_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&generic_client_mutex); + init = true; + } +} + +static void bt_mesh_generic_client_lock(void) +{ + osi_mutex_lock(&generic_client_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +static void bt_mesh_generic_client_unlock(void) +{ + osi_mutex_unlock(&generic_client_mutex); +} + static void timeout_handler(struct k_work *work) { generic_internal_data_t *internal = NULL; @@ -145,10 +168,16 @@ static void timeout_handler(struct k_work *work) return; } - bt_mesh_generic_client_cb_evt_to_btc(node->opcode, - BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + bt_mesh_generic_client_lock(); - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_generic_client_cb_evt_to_btc(node->opcode, + BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } + + bt_mesh_generic_client_unlock(); return; } @@ -535,6 +564,9 @@ static void generic_status(struct bt_mesh_model *model, buf->data = val; buf->len = len; + + bt_mesh_generic_client_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { BT_DBG("Unexpected generic status message 0x%x", rsp); @@ -580,11 +612,15 @@ static void generic_status(struct bt_mesh_model *model, break; } - bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } } + bt_mesh_generic_client_unlock(); + switch (rsp) { case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { struct bt_mesh_gen_user_properties_status *status; @@ -1181,6 +1217,8 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary) client->op_pair = gen_op_pair; client->internal_data = internal; + bt_mesh_generic_client_mutex_new(); + return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h index 384d08a05..d2b05e0c1 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h @@ -78,6 +78,10 @@ typedef struct { void *cb_data; /* User defined callback value */ } bt_mesh_client_common_param_t; +void bt_mesh_client_model_lock(void); + +void bt_mesh_client_model_unlock(void); + int bt_mesh_client_init(struct bt_mesh_model *model); /** diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index b7b9a0413..c52f35e00 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -17,6 +17,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "sdkconfig.h" #include "mesh_types.h" @@ -128,6 +129,28 @@ static const bt_mesh_client_op_pair_t light_op_pair[] = { { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, }; +static osi_mutex_t light_client_mutex; + +static void bt_mesh_light_client_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&light_client_mutex); + init = true; + } +} + +static void bt_mesh_light_client_lock(void) +{ + osi_mutex_lock(&light_client_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +static void bt_mesh_light_client_unlock(void) +{ + osi_mutex_unlock(&light_client_mutex); +} + static void timeout_handler(struct k_work *work) { light_internal_data_t *internal = NULL; @@ -154,10 +177,16 @@ static void timeout_handler(struct k_work *work) return; } - bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, - BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + bt_mesh_light_client_lock(); - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, + BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } + + bt_mesh_light_client_unlock(); return; } @@ -650,6 +679,9 @@ static void light_status(struct bt_mesh_model *model, buf->data = val; buf->len = len; + + bt_mesh_light_client_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { BT_DBG("Unexpected light status message 0x%x", rsp); @@ -706,11 +738,15 @@ static void light_status(struct bt_mesh_model *model, break; } - bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } } + bt_mesh_light_client_unlock(); + switch (rsp) { case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { struct bt_mesh_light_lc_property_status *status; @@ -1371,6 +1407,8 @@ static int light_client_init(struct bt_mesh_model *model, bool primary) client->op_pair = light_op_pair; client->internal_data = internal; + bt_mesh_light_client_mutex_new(); + return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index 3f95168c3..3626a38dc 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -17,6 +17,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "sdkconfig.h" #include "mesh_types.h" @@ -57,6 +58,28 @@ static const bt_mesh_client_op_pair_t sensor_op_pair[] = { { BLE_MESH_MODEL_OP_SENSOR_SERIES_GET, BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS }, }; +static osi_mutex_t sensor_client_mutex; + +static void bt_mesh_sensor_client_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&sensor_client_mutex); + init = true; + } +} + +static void bt_mesh_sensor_client_lock(void) +{ + osi_mutex_lock(&sensor_client_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +static void bt_mesh_sensor_client_unlock(void) +{ + osi_mutex_unlock(&sensor_client_mutex); +} + static void timeout_handler(struct k_work *work) { sensor_internal_data_t *internal = NULL; @@ -83,10 +106,16 @@ static void timeout_handler(struct k_work *work) return; } - bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, - BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + bt_mesh_sensor_client_lock(); - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, + BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } + + bt_mesh_sensor_client_unlock(); return; } @@ -262,6 +291,9 @@ static void sensor_status(struct bt_mesh_model *model, buf->data = val; buf->len = len; + + bt_mesh_sensor_client_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { BT_DBG("Unexpected sensor status message 0x%x", rsp); @@ -284,11 +316,15 @@ static void sensor_status(struct bt_mesh_model *model, break; } - bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } } + bt_mesh_sensor_client_unlock(); + switch (rsp) { case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { struct bt_mesh_sensor_descriptor_status *status; @@ -612,5 +648,7 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary) client->op_pair = sensor_op_pair; client->internal_data = internal; + bt_mesh_sensor_client_mutex_new(); + return 0; } \ No newline at end of file diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index 275b29cc6..01f563994 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -17,6 +17,7 @@ #include #include "osi/allocator.h" +#include "osi/mutex.h" #include "sdkconfig.h" #include "mesh_types.h" @@ -73,6 +74,28 @@ static const bt_mesh_client_op_pair_t time_scene_op_pair[] = { { BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, }; +static osi_mutex_t time_scene_client_mutex; + +static void bt_mesh_time_scene_client_mutex_new(void) +{ + static bool init; + + if (!init) { + osi_mutex_new(&time_scene_client_mutex); + init = true; + } +} + +static void bt_mesh_time_scene_client_lock(void) +{ + osi_mutex_lock(&time_scene_client_mutex, OSI_MUTEX_MAX_TIMEOUT); +} + +static void bt_mesh_time_scene_client_unlock(void) +{ + osi_mutex_unlock(&time_scene_client_mutex); +} + static void timeout_handler(struct k_work *work) { time_scene_internal_data_t *internal = NULL; @@ -99,10 +122,16 @@ static void timeout_handler(struct k_work *work) return; } - bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, - BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + bt_mesh_time_scene_client_lock(); - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, + BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } + + bt_mesh_time_scene_client_unlock(); return; } @@ -299,6 +328,9 @@ static void time_scene_status(struct bt_mesh_model *model, buf->data = val; buf->len = len; + + bt_mesh_time_scene_client_lock(); + node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { BT_DBG("Unexpected time scene status message 0x%x", rsp); @@ -328,11 +360,15 @@ static void time_scene_status(struct bt_mesh_model *model, break; } - bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); - // Don't forget to release the node at the end. - bt_mesh_client_free_node(&internal->queue, node); + if (!k_delayed_work_free(&node->timer)) { + bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(&internal->queue, node); + } } + bt_mesh_time_scene_client_unlock(); + switch (rsp) { case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { struct bt_mesh_scene_register_status *status; @@ -675,6 +711,8 @@ static int time_scene_client_init(struct bt_mesh_model *model, bool primary) client->op_pair = time_scene_op_pair; client->internal_data = internal; + bt_mesh_time_scene_client_mutex_new(); + return 0; } diff --git a/components/bt/include/bt.h b/components/bt/include/bt.h deleted file mode 100644 index a957698fb..000000000 --- a/components/bt/include/bt.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#warning "This header is deprecated, please use functions defined in esp_bt.h instead." -#include "esp_bt.h" diff --git a/components/driver/i2s.c b/components/driver/i2s.c index c4cecebbb..2cb466344 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -1180,18 +1180,6 @@ esp_err_t i2s_driver_uninstall(i2s_port_t i2s_num) return ESP_OK; } -int i2s_write_bytes(i2s_port_t i2s_num, const void *src, size_t size, TickType_t ticks_to_wait) -{ - size_t bytes_written = 0; - int res = 0; - res = i2s_write(i2s_num, src, size, &bytes_written, ticks_to_wait); - if (res != ESP_OK) { - return ESP_FAIL; - } else { - return bytes_written; - } -} - esp_err_t i2s_write(i2s_port_t i2s_num, const void *src, size_t size, size_t *bytes_written, TickType_t ticks_to_wait) { char *data_ptr, *src_byte; @@ -1317,18 +1305,6 @@ esp_err_t i2s_write_expand(i2s_port_t i2s_num, const void *src, size_t size, siz return ESP_OK; } -int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks_to_wait) -{ - size_t bytes_read = 0; - int res = 0; - res = i2s_read(i2s_num, dest, size, &bytes_read, ticks_to_wait); - if (res != ESP_OK) { - return ESP_FAIL; - } else { - return bytes_read; - } -} - esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait) { char *data_ptr, *dest_byte; @@ -1367,29 +1343,3 @@ esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_re xSemaphoreGive(p_i2s_obj[i2s_num]->rx->mux); return ESP_OK; } - -int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait) -{ - size_t bytes_push = 0; - int res = 0; - I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_FAIL); - res = i2s_write(i2s_num, sample, p_i2s_obj[i2s_num]->bytes_per_sample, &bytes_push, ticks_to_wait); - if (res != ESP_OK) { - return ESP_FAIL; - } else { - return bytes_push; - } -} - -int i2s_pop_sample(i2s_port_t i2s_num, void *sample, TickType_t ticks_to_wait) -{ - size_t bytes_pop = 0; - int res = 0; - I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_FAIL); - res = i2s_read(i2s_num, sample, p_i2s_obj[i2s_num]->bytes_per_sample, &bytes_pop, ticks_to_wait); - if (res != ESP_OK) { - return ESP_FAIL; - } else { - return bytes_pop; - } -} diff --git a/components/driver/include/driver/adc.h b/components/driver/include/driver/adc.h index e3b1ac74a..ad9021c4e 100644 --- a/components/driver/include/driver/adc.h +++ b/components/driver/include/driver/adc.h @@ -218,20 +218,6 @@ esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten); */ int adc1_get_raw(adc1_channel_t channel); -/** @cond */ //Doxygen command to hide deprecated function from API Reference -/* - * @note When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, - * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. - * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. - * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. - * - * @deprecated This function returns an ADC1 reading but is deprecated due to - * a misleading name and has been changed to directly call the new function. - * Use the new function adc1_get_raw() instead - */ -int adc1_get_voltage(adc1_channel_t channel) __attribute__((deprecated)); -/** @endcond */ - /** * @brief Enable ADC power */ diff --git a/components/driver/include/driver/dac.h b/components/driver/include/driver/dac.h index 820b913a8..fe375190c 100644 --- a/components/driver/include/driver/dac.h +++ b/components/driver/include/driver/dac.h @@ -42,25 +42,6 @@ typedef enum { */ esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num); -/** @cond */ -/** - * @brief Set DAC output voltage. - * - * @note Function has been deprecated, please use dac_output_voltage instead. - * This name will be removed in a future release. - * The difference is that before calling dac_output_voltage, we need to initialize the dac pad by dac_output_enable - * - * - * @param channel DAC channel - * @param dac_value DAC output value - * - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value) __attribute__ ((deprecated)); -/** @endcond */ - /** * @brief Set DAC output voltage. * diff --git a/components/driver/include/driver/i2s.h b/components/driver/include/driver/i2s.h index b1b767cab..3ccd55135 100644 --- a/components/driver/include/driver/i2s.h +++ b/components/driver/include/driver/i2s.h @@ -294,18 +294,6 @@ esp_err_t i2s_driver_install(i2s_port_t i2s_num, const i2s_config_t *i2s_config, */ esp_err_t i2s_driver_uninstall(i2s_port_t i2s_num); -/** - * @brief Write data to I2S DMA transmit buffer. - * - * This function is deprecated. Use 'i2s_write' instead. - * This definition will be removed in a future release. - * - * @return - * - The amount of bytes written, if timeout, the result will be less than the size passed in. - * - ESP_FAIL Parameter error - */ -int i2s_write_bytes(i2s_port_t i2s_num, const void *src, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated)); - /** * @brief Write data to I2S DMA transmit buffer. * @@ -361,18 +349,6 @@ esp_err_t i2s_write(i2s_port_t i2s_num, const void *src, size_t size, size_t *by */ esp_err_t i2s_write_expand(i2s_port_t i2s_num, const void *src, size_t size, size_t src_bits, size_t aim_bits, size_t *bytes_written, TickType_t ticks_to_wait); -/** - * @brief Read data from I2S DMA receive buffer - * - * This function is deprecated. Use 'i2s_read' instead. - * This definition will be removed in a future release. - * - * @return - * - The amount of bytes read, if timeout, bytes read will be less than the size passed in - * - ESP_FAIL Parameter error - */ -int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated)); - /** * @brief Read data from I2S DMA receive buffer * @@ -395,42 +371,6 @@ int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks */ esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait); -/** - * @brief Write a single sample to the I2S DMA TX buffer. - * - * This function is deprecated. Use 'i2s_write' instead. - * This definition will be removed in a future release. - * - * @param i2s_num I2S_NUM_0, I2S_NUM_1 - * - * @param sample Buffer to read data. Size of buffer (in bytes) = bits_per_sample / 8. - * - * @param ticks_to_wait Timeout in RTOS ticks. If a sample is not available in the DMA buffer within this period, no data is read and function returns zero. - * - * @return - * - Number of bytes successfully pushed to DMA buffer, will be either zero or the size of configured sample buffer (in bytes). - * - ESP_FAIL Parameter error - */ -int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated)); - -/** - * @brief Read a single sample from the I2S DMA RX buffer. - * - * This function is deprecated. Use 'i2s_read' instead. - * This definition will be removed in a future release. - * - * @param i2s_num I2S_NUM_0, I2S_NUM_1 - * - * @param sample Buffer to write data. Size of buffer (in bytes) = bits_per_sample / 8. - * - * @param ticks_to_wait Timeout in RTOS ticks. If a sample is not available in the DMA buffer within this period, no data is read and function returns zero. - * - * @return - * - Number of bytes successfully read from DMA buffer, will be either zero or the size of configured sample buffer (in bytes). - * - ESP_FAIL Parameter error - */ -int i2s_pop_sample(i2s_port_t i2s_num, void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated)); - /** * @brief Set sample rate used for I2S RX and TX. * diff --git a/components/driver/include/driver/ledc.h b/components/driver/include/driver/ledc.h index c801b8cc9..82ab7a1f8 100644 --- a/components/driver/include/driver/ledc.h +++ b/components/driver/include/driver/ledc.h @@ -130,10 +130,7 @@ typedef struct { */ typedef struct { ledc_mode_t speed_mode; /*!< LEDC speed speed_mode, high-speed mode or low-speed mode */ - union { - ledc_timer_bit_t duty_resolution; /*!< LEDC channel duty resolution */ - ledc_timer_bit_t bit_num __attribute__((deprecated)); /*!< Deprecated in ESP-IDF 3.0. This is an alias to 'duty_resolution' for backward compatibility with ESP-IDF 2.1 */ - }; + ledc_timer_bit_t duty_resolution; /*!< LEDC channel duty resolution */ ledc_timer_t timer_num; /*!< The timer source of channel (0 - 3) */ uint32_t freq_hz; /*!< LEDC timer frequency (Hz) */ ledc_clk_cfg_t clk_cfg; /*!< Configure LEDC source clock. diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index e94de2a29..92f2c6e8a 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -430,21 +430,6 @@ typedef void (* filter_cb_t)(uint16_t *raw_value, uint16_t *filtered_value); */ esp_err_t touch_pad_set_filter_read_cb(filter_cb_t read_cb); -/** - * @brief Register touch-pad ISR, - * @note Deprecated function, users should replace this with touch_pad_isr_register, - * because RTC modules share a same interrupt index. - * @param fn Pointer to ISR handler - * @param arg Parameter for ISR - * @param unused Reserved, not used - * @param handle_unused Reserved, not used - * @return - * - ESP_OK Success ; - * - ESP_ERR_INVALID_ARG GPIO error - * - ESP_ERR_NO_MEM No memory - */ -esp_err_t touch_pad_isr_handler_register(void(*fn)(void *), void *arg, int unused, intr_handle_t *handle_unused) __attribute__ ((deprecated)); - /** * @brief Register touch-pad ISR. * The handler will be attached to the same CPU core that this function is running on. diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 1035e164c..3c76e7304 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -1901,11 +1901,6 @@ int adc1_get_raw(adc1_channel_t channel) return adc_value; } -int adc1_get_voltage(adc1_channel_t channel) //Deprecated. Use adc1_get_raw(void) instead -{ - return adc1_get_raw(channel); -} - void adc1_ulp_enable(void) { adc_power_on(); @@ -2223,35 +2218,6 @@ esp_err_t dac_output_voltage(dac_channel_t channel, uint8_t dac_value) return ESP_OK; } -esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value) -{ - RTC_MODULE_CHECK((channel >= DAC_CHANNEL_1) && (channel < DAC_CHANNEL_MAX), DAC_ERR_STR_CHANNEL_ERROR, ESP_ERR_INVALID_ARG); - portENTER_CRITICAL(&rtc_spinlock); - //Disable Tone - CLEAR_PERI_REG_MASK(SENS_SAR_DAC_CTRL1_REG, SENS_SW_TONE_EN); - - //Disable Channel Tone - if (channel == DAC_CHANNEL_1) { - CLEAR_PERI_REG_MASK(SENS_SAR_DAC_CTRL2_REG, SENS_DAC_CW_EN1_M); - } else if (channel == DAC_CHANNEL_2) { - CLEAR_PERI_REG_MASK(SENS_SAR_DAC_CTRL2_REG, SENS_DAC_CW_EN2_M); - } - - //Set the Dac value - if (channel == DAC_CHANNEL_1) { - SET_PERI_REG_BITS(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_DAC, dac_value, RTC_IO_PDAC1_DAC_S); //dac_output - } else if (channel == DAC_CHANNEL_2) { - SET_PERI_REG_BITS(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_DAC, dac_value, RTC_IO_PDAC2_DAC_S); //dac_output - } - - portEXIT_CRITICAL(&rtc_spinlock); - //dac pad init - dac_rtc_pad_init(channel); - dac_output_enable(channel); - - return ESP_OK; -} - esp_err_t dac_i2s_enable(void) { portENTER_CRITICAL(&rtc_spinlock); diff --git a/components/driver/test/esp32/test_ledc.c b/components/driver/test/esp32/test_ledc.c index 60135ec3d..b5e9441e0 100644 --- a/components/driver/test/esp32/test_ledc.c +++ b/components/driver/test/esp32/test_ledc.c @@ -82,7 +82,7 @@ static void timer_frequency_test(ledc_channel_t channel, ledc_timer_bit_t timer_ }; ledc_timer_config_t ledc_time_config = { .speed_mode = speed_mode, - .bit_num = timer_bit, + .duty_resolution = timer_bit, .timer_num = timer, .freq_hz = 5000, .clk_cfg = LEDC_AUTO_CLK, @@ -123,7 +123,7 @@ static void timer_duty_test(ledc_channel_t channel, ledc_timer_bit_t timer_bit, }; ledc_timer_config_t ledc_time_config = { .speed_mode = speed_mode, - .bit_num = timer_bit, + .duty_resolution = timer_bit, .timer_num = timer, .freq_hz = 5000, .clk_cfg = LEDC_AUTO_CLK, @@ -227,7 +227,7 @@ TEST_CASE("LEDC normal channel and timer config", "[ledc][test_env=UT_T1_LEDC]") ledc_timer_config_t ledc_time_config = { .speed_mode = LEDC_HIGH_SPEED_MODE, - .bit_num = LEDC_TIMER_13_BIT, + .duty_resolution = LEDC_TIMER_13_BIT, .timer_num = LEDC_TIMER_0, .freq_hz = 5000, .clk_cfg = LEDC_AUTO_CLK, @@ -297,7 +297,7 @@ TEST_CASE("LEDC timer set", "[ledc][test_env=UT_T1_LEDC]") ledc_timer_config_t ledc_time_config = { .speed_mode = LEDC_HIGH_SPEED_MODE, - .bit_num = 13, + .duty_resolution = 13, .timer_num = LEDC_TIMER_0, .freq_hz = 5000, .clk_cfg = LEDC_AUTO_CLK, diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 5bff4c199..3d7346351 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -385,7 +385,7 @@ menu "ESP32-specific" config ESP32_DEBUG_STUBS_ENABLE bool "OpenOCD debug stubs" - default COMPILER_OPTIMIZATION_LEVEL_DEBUG + default COMPILER_OPTIMIZATION_DEFAULT depends on !ESP32_TRAX help Debug stubs are used by OpenOCD to execute pre-compiled onboard code which does some useful debugging, diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index c5f252881..e3a4bc11e 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -43,7 +43,7 @@ #include "sdkconfig.h" #include "esp_system.h" #include "esp_spi_flash.h" -#include "esp_flash.h" +#include "esp_flash_internal.h" #include "nvs_flash.h" #include "esp_event.h" #include "esp_spi_flash.h" @@ -395,20 +395,9 @@ void start_cpu0_default(void) /* init default OS-aware flash access critical section */ spi_flash_guard_set(&g_flash_guard_default_ops); -#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL esp_flash_app_init(); esp_err_t flash_ret = esp_flash_init_default_chip(); assert(flash_ret == ESP_OK); -#endif - - uint8_t revision = esp_efuse_get_chip_ver(); - ESP_LOGI(TAG, "Chip Revision: %d", revision); - if (revision > CONFIG_ESP32_REV_MIN) { - ESP_LOGW(TAG, "Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it."); - } else if(revision != CONFIG_ESP32_REV_MIN) { - ESP_LOGE(TAG, "ESP-IDF can't support this chip revision. Modify minimum supported revision in menuconfig"); - abort(); - } #ifdef CONFIG_PM_ENABLE esp_pm_impl_init(); diff --git a/components/esp32/include/esp32/pm.h b/components/esp32/include/esp32/pm.h index f64045fb3..8c3682cc7 100644 --- a/components/esp32/include/esp32/pm.h +++ b/components/esp32/include/esp32/pm.h @@ -31,9 +31,7 @@ extern "C" { * Pass a pointer to this structure as an argument to esp_pm_configure function. */ typedef struct { - rtc_cpu_freq_t max_cpu_freq __attribute__((deprecated)); /*!< Maximum CPU frequency to use. Deprecated, use max_freq_mhz instead. */ int max_freq_mhz; /*!< Maximum CPU frequency, in MHz */ - rtc_cpu_freq_t min_cpu_freq __attribute__((deprecated)); /*!< Minimum CPU frequency to use when no frequency locks are taken. Deprecated, use min_freq_mhz instead. */ int min_freq_mhz; /*!< Minimum CPU frequency to use when no locks are taken, in MHz */ bool light_sleep_enable; /*!< Enter light sleep when no locks are taken */ } esp_pm_config_esp32_t; diff --git a/components/esp32/include/esp_sleep.h b/components/esp32/include/esp_sleep.h index 7101bda07..b70667327 100644 --- a/components/esp32/include/esp_sleep.h +++ b/components/esp32/include/esp_sleep.h @@ -295,16 +295,6 @@ esp_err_t esp_light_sleep_start(void); */ void esp_deep_sleep(uint64_t time_in_us) __attribute__((noreturn)); -/** - * @brief Enter deep-sleep mode - * - * Function has been renamed to esp_deep_sleep. - * This name is deprecated and will be removed in a future version. - * - * @param time_in_us deep-sleep time, unit: microsecond - */ -void system_deep_sleep(uint64_t time_in_us) __attribute__((noreturn, deprecated)); - /** * @brief Get the wakeup source which caused wakeup from sleep diff --git a/components/esp32/pm_esp32.c b/components/esp32/pm_esp32.c index f1b29189a..80008b745 100644 --- a/components/esp32/pm_esp32.c +++ b/components/esp32/pm_esp32.c @@ -182,15 +182,6 @@ esp_err_t esp_pm_configure(const void* vconfig) int min_freq_mhz = config->min_freq_mhz; int max_freq_mhz = config->max_freq_mhz; - if (min_freq_mhz == 0 && max_freq_mhz == 0) { - /* For compatibility, handle deprecated fields, min_cpu_freq and max_cpu_freq. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - min_freq_mhz = rtc_clk_cpu_freq_value(config->min_cpu_freq) / MHZ; - max_freq_mhz = rtc_clk_cpu_freq_value(config->max_cpu_freq) / MHZ; -#pragma GCC diagnostic pop - } - if (min_freq_mhz > max_freq_mhz) { return ESP_ERR_INVALID_ARG; } diff --git a/components/esp32/sleep_modes.c b/components/esp32/sleep_modes.c index 052b816a4..86c209162 100644 --- a/components/esp32/sleep_modes.c +++ b/components/esp32/sleep_modes.c @@ -360,8 +360,6 @@ esp_err_t esp_light_sleep_start(void) return err; } -void system_deep_sleep(uint64_t) __attribute__((alias("esp_deep_sleep"))); - esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source) { // For most of sources it is enough to set trigger mask in local diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index f017a0f65..c3d77c01d 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -47,10 +47,6 @@ static uint8_t base_mac_addr[6] = { 0 }; #define SHUTDOWN_HANDLERS_NO 2 static shutdown_handler_t shutdown_handlers[SHUTDOWN_HANDLERS_NO]; -void system_init(void) -{ -} - esp_err_t esp_base_mac_addr_set(uint8_t *mac) { if (mac == NULL) { @@ -122,9 +118,6 @@ esp_err_t esp_efuse_mac_get_default(uint8_t* mac) return ESP_OK; } -esp_err_t system_efuse_read_mac(uint8_t *mac) __attribute__((alias("esp_efuse_mac_get_default"))); -esp_err_t esp_efuse_read_mac(uint8_t *mac) __attribute__((alias("esp_efuse_mac_get_default"))); - esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac) { uint8_t idx; @@ -344,8 +337,6 @@ void IRAM_ATTR esp_restart_noos(void) } } -void system_restart(void) __attribute__((alias("esp_restart"))); - uint32_t esp_get_free_heap_size( void ) { return heap_caps_get_free_size( MALLOC_CAP_DEFAULT ); @@ -356,13 +347,6 @@ uint32_t esp_get_minimum_free_heap_size( void ) return heap_caps_get_minimum_free_size( MALLOC_CAP_DEFAULT ); } -uint32_t system_get_free_heap_size(void) __attribute__((alias("esp_get_free_heap_size"))); - -const char* system_get_sdk_version(void) -{ - return "master"; -} - const char* esp_get_idf_version(void) { return IDF_VER; diff --git a/components/esp32/task_wdt.c b/components/esp32/task_wdt.c index c1aa4e976..37c5b8726 100644 --- a/components/esp32/task_wdt.c +++ b/components/esp32/task_wdt.c @@ -387,46 +387,3 @@ esp_err_t esp_task_wdt_status(TaskHandle_t handle) portEXIT_CRITICAL(&twdt_spinlock); return ESP_ERR_NOT_FOUND; } - -void esp_task_wdt_feed(void) -{ - portENTER_CRITICAL(&twdt_spinlock); - //Return immediately if TWDT has not been initialized - ASSERT_EXIT_CRIT_RETURN((twdt_config != NULL), VOID_RETURN); - - //Check if task is on list - TaskHandle_t handle = xTaskGetCurrentTaskHandle(); - bool all_reset; - twdt_task_t *target_task = find_task_in_twdt_list(handle, &all_reset); - - //reset the task if it's on the list, then return - if(target_task != NULL){ - target_task->has_reset = true; - if(all_reset){ - reset_hw_timer(); //Reset hardware timer if all other tasks have reset - } - portEXIT_CRITICAL(&twdt_spinlock); - return; - } - - //Add task if it's has not on list - target_task = calloc(1, sizeof(twdt_task_t)); - ASSERT_EXIT_CRIT_RETURN((target_task != NULL), VOID_RETURN); //If calloc failed - target_task->task_handle = handle; - target_task->has_reset = true; - target_task->next = NULL; - - if (twdt_config->list == NULL) { //Adding to empty list - twdt_config->list = target_task; - } else { //Adding to tail of list - twdt_task_t *task; - for (task = twdt_config->list; task->next != NULL; task = task->next){ - ; //point task to current tail of wdt task list - } - task->next = target_task; - } - - portEXIT_CRITICAL(&twdt_spinlock); -} - - diff --git a/components/esp32/test/test_pm.c b/components/esp32/test/test_pm.c index e74a214d7..2f17202f1 100644 --- a/components/esp32/test/test_pm.c +++ b/components/esp32/test/test_pm.c @@ -15,6 +15,8 @@ #include "esp32/ulp.h" #include "soc/rtc_periph.h" +#define MHZ 1000000 + TEST_CASE("Can dump power management lock stats", "[pm]") { esp_pm_dump_locks(stdout); @@ -31,15 +33,15 @@ static void switch_freq(int mhz) }; ESP_ERROR_CHECK( esp_pm_configure(&pm_config) ); printf("Waiting for frequency to be set to %d MHz...\n", mhz); - while (esp_clk_cpu_freq() / 1000000 != mhz) { + while (esp_clk_cpu_freq() / MHZ != mhz) { vTaskDelay(pdMS_TO_TICKS(200)); - printf("Frequency is %d MHz\n", esp_clk_cpu_freq() / 1000000); + printf("Frequency is %d MHz\n", esp_clk_cpu_freq() / MHZ); } } TEST_CASE("Can switch frequency using esp_pm_configure", "[pm]") { - int orig_freq_mhz = esp_clk_cpu_freq() / 1000000; + int orig_freq_mhz = esp_clk_cpu_freq() / MHZ; switch_freq(240); switch_freq(40); switch_freq(160); @@ -60,9 +62,12 @@ TEST_CASE("Can switch frequency using esp_pm_configure", "[pm]") static void light_sleep_enable(void) { + int cur_freq_mhz = esp_clk_cpu_freq() / MHZ; + int xtal_freq = (int) rtc_clk_xtal_freq_get(); + const esp_pm_config_esp32_t pm_config = { - .max_cpu_freq = rtc_clk_cpu_freq_get(), - .min_cpu_freq = RTC_CPU_FREQ_XTAL, + .max_freq_mhz = cur_freq_mhz, + .min_freq_mhz = xtal_freq, .light_sleep_enable = true }; ESP_ERROR_CHECK( esp_pm_configure(&pm_config) ); @@ -70,9 +75,11 @@ static void light_sleep_enable(void) static void light_sleep_disable(void) { + int cur_freq_mhz = esp_clk_cpu_freq() / MHZ; + const esp_pm_config_esp32_t pm_config = { - .max_cpu_freq = rtc_clk_cpu_freq_get(), - .min_cpu_freq = rtc_clk_cpu_freq_get(), + .max_freq_mhz = cur_freq_mhz, + .min_freq_mhz = cur_freq_mhz, }; ESP_ERROR_CHECK( esp_pm_configure(&pm_config) ); } diff --git a/components/esp_adc_cal/esp_adc_cal.c b/components/esp_adc_cal/esp_adc_cal.c index 75146b37c..43b08c146 100644 --- a/components/esp_adc_cal/esp_adc_cal.c +++ b/components/esp_adc_cal/esp_adc_cal.c @@ -390,23 +390,3 @@ esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel, *voltage = esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, chars); return ESP_OK; } - -/* ------------------------ Deprecated API --------------------------------- */ -void esp_adc_cal_get_characteristics(uint32_t vref, - adc_atten_t atten, - adc_bits_width_t bit_width, - esp_adc_cal_characteristics_t *chars) -{ - assert(chars != NULL); - esp_adc_cal_characterize(ADC_UNIT_1, atten, bit_width, vref, chars); -} - -uint32_t adc1_to_voltage(adc1_channel_t channel, const esp_adc_cal_characteristics_t *chars) -{ - assert(chars != NULL); - uint32_t voltage = 0; - esp_adc_cal_get_voltage((adc_channel_t)channel, chars, &voltage); - return voltage; -} - - diff --git a/components/esp_adc_cal/include/esp_adc_cal.h b/components/esp_adc_cal/include/esp_adc_cal.h index af611357b..b1798847b 100644 --- a/components/esp_adc_cal/include/esp_adc_cal.h +++ b/components/esp_adc_cal/include/esp_adc_cal.h @@ -127,24 +127,6 @@ uint32_t esp_adc_cal_raw_to_voltage(uint32_t adc_reading, const esp_adc_cal_char */ esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel, const esp_adc_cal_characteristics_t *chars, uint32_t *voltage); -/* -------------------------- Deprecated API ------------------------------- */ - -/** @cond */ //Doxygen command to hide deprecated function from API Reference -/** - * @deprecated ADC1 characterization function. Deprecated in order to accommodate - * ADC2 and eFuse functionality. Use esp_adc_cal_characterize() instead - */ -void esp_adc_cal_get_characteristics(uint32_t vref, adc_atten_t atten, adc_bits_width_t bit_width, esp_adc_cal_characteristics_t *chars) __attribute__((deprecated)); - -/* - * @deprecated This function reads ADC1 and returns the corrected voltage. This - * has been deprecated in order to accommodate ADC2 support. Use the - * new function esp_adc_cal_get_voltage() instead. - */ -uint32_t adc1_to_voltage(adc1_channel_t channel, const esp_adc_cal_characteristics_t *chars) __attribute__((deprecated)); - -/** @endcond */ - #ifdef __cplusplus } #endif diff --git a/components/esp_common/include/esp_system.h b/components/esp_common/include/esp_system.h index 9aca3b83f..7d161f721 100644 --- a/components/esp_common/include/esp_system.h +++ b/components/esp_common/include/esp_system.h @@ -62,22 +62,6 @@ typedef enum { ESP_RST_SDIO, //!< Reset over SDIO } esp_reset_reason_t; -/** @cond */ -/** - * @attention Applications don't need to call this function anymore. It does nothing and will - * be removed in future version. - */ -void system_init(void) __attribute__ ((deprecated)); - -/** - * @brief Reset to default settings. - * - * Function has been deprecated, please use esp_wifi_restore instead. - * This name will be removed in a future release. - */ -void system_restore(void) __attribute__ ((deprecated)); -/** @endcond */ - /** * Shutdown handler type */ @@ -117,32 +101,12 @@ esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handle); */ void esp_restart(void) __attribute__ ((noreturn)); -/** @cond */ -/** - * @brief Restart system. - * - * Function has been renamed to esp_restart. - * This name will be removed in a future release. - */ -void system_restart(void) __attribute__ ((deprecated, noreturn)); -/** @endcond */ - /** * @brief Get reason of last reset * @return See description of esp_reset_reason_t for explanation of each value. */ esp_reset_reason_t esp_reset_reason(void); -/** @cond */ -/** - * @brief Get system time, unit: microsecond. - * - * This function is deprecated. Use 'gettimeofday' function for 64-bit precision. - * This definition will be removed in a future release. - */ -uint32_t system_get_time(void) __attribute__ ((deprecated)); -/** @endcond */ - /** * @brief Get the size of available heap. * @@ -153,18 +117,6 @@ uint32_t system_get_time(void) __attribute__ ((deprecated)); */ uint32_t esp_get_free_heap_size(void); -/** @cond */ -/** - * @brief Get the size of available heap. - * - * Function has been renamed to esp_get_free_heap_size. - * This name will be removed in a future release. - * - * @return Available heap size, in bytes. - */ -uint32_t system_get_free_heap_size(void) __attribute__ ((deprecated)); -/** @endcond */ - /** * @brief Get the minimum heap that has ever been available * @@ -250,31 +202,6 @@ esp_err_t esp_efuse_mac_get_custom(uint8_t *mac); */ esp_err_t esp_efuse_mac_get_default(uint8_t *mac); -/** @cond */ -/** - * @brief Read hardware MAC address from efuse. - * - * Function has been renamed to esp_efuse_mac_get_default. - * This name will be removed in a future release. - * - * @param mac hardware MAC address, length: 6 bytes. - * - * @return ESP_OK on success - */ -esp_err_t esp_efuse_read_mac(uint8_t *mac) __attribute__ ((deprecated)); - -/** - * @brief Read hardware MAC address. - * - * Function has been renamed to esp_efuse_mac_get_default. - * This name will be removed in a future release. - * - * @param mac hardware MAC address, length: 6 bytes. - * @return ESP_OK on success - */ -esp_err_t system_efuse_read_mac(uint8_t *mac) __attribute__ ((deprecated)); -/** @endcond */ - /** * @brief Read base MAC address and set MAC address of the interface. * @@ -305,17 +232,6 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type); */ esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac); -/** @cond */ -/** - * Get SDK version - * - * This function is deprecated and will be removed in a future release. - * - * @return constant string "master" - */ -const char* system_get_sdk_version(void) __attribute__ ((deprecated)); -/** @endcond */ - /** * @brief Chip models */ diff --git a/components/esp_common/include/esp_task_wdt.h b/components/esp_common/include/esp_task_wdt.h index 554aa3497..cf64cfc14 100644 --- a/components/esp_common/include/esp_task_wdt.h +++ b/components/esp_common/include/esp_task_wdt.h @@ -141,22 +141,6 @@ esp_err_t esp_task_wdt_delete(TaskHandle_t handle); */ esp_err_t esp_task_wdt_status(TaskHandle_t handle); -/** - * @brief Reset the TWDT on behalf of the current running task, or - * subscribe the TWDT to if it has not done so already - * - * @warning This function is deprecated, use esp_task_wdt_add() and - * esp_task_wdt_reset() instead - * - * This function is similar to esp_task_wdt_reset() and will reset the TWDT on - * behalf of the current running task. However if this task has not subscribed - * to the TWDT, this function will automatically subscribe the task. Therefore, - * an unsubscribed task will subscribe to the TWDT on its first call to this - * function, then proceed to reset the TWDT on subsequent calls of this - * function. - */ -void esp_task_wdt_feed(void) __attribute__ ((deprecated)); - #ifdef __cplusplus } diff --git a/components/esp_eth/src/esp_eth_mac_dm9051.c b/components/esp_eth/src/esp_eth_mac_dm9051.c index b2878cb13..c2c4c1095 100644 --- a/components/esp_eth/src/esp_eth_mac_dm9051.c +++ b/components/esp_eth/src/esp_eth_mac_dm9051.c @@ -390,10 +390,10 @@ static esp_err_t dm9051_verify_id(emac_dm9051_t *emac) uint8_t id[2]; MAC_CHECK(dm9051_register_read(emac, DM9051_VIDL, &id[0]) == ESP_OK, "read VIDL failed", err, ESP_FAIL); MAC_CHECK(dm9051_register_read(emac, DM9051_VIDH, &id[1]) == ESP_OK, "read VIDH failed", err, ESP_FAIL); - MAC_CHECK(0x0A46 == *(uint16_t *)id, "wrong Vendor ID", err, ESP_ERR_INVALID_VERSION); + MAC_CHECK(0x0A == id[1] && 0x46 == id[0], "wrong Vendor ID", err, ESP_ERR_INVALID_VERSION); MAC_CHECK(dm9051_register_read(emac, DM9051_PIDL, &id[0]) == ESP_OK, "read PIDL failed", err, ESP_FAIL); MAC_CHECK(dm9051_register_read(emac, DM9051_PIDH, &id[1]) == ESP_OK, "read PIDH failed", err, ESP_FAIL); - MAC_CHECK(0x9051 == *(uint16_t *)id, "wrong Product ID", err, ESP_ERR_INVALID_VERSION); + MAC_CHECK(0x90 == id[1] && 0x51 == id[0], "wrong Product ID", err, ESP_ERR_INVALID_VERSION); return ESP_OK; err: return ret; diff --git a/components/esp_ringbuf/include/freertos/ringbuf.h b/components/esp_ringbuf/include/freertos/ringbuf.h index 338fa3eae..1312723ad 100644 --- a/components/esp_ringbuf/include/freertos/ringbuf.h +++ b/components/esp_ringbuf/include/freertos/ringbuf.h @@ -514,10 +514,6 @@ void vRingbufferGetInfo(RingbufHandle_t xRingbuffer, */ void xRingbufferPrintInfo(RingbufHandle_t xRingbuffer); -/* ------------------------------- Deprecated ------------------------------- */ - -typedef RingbufferType_t ringbuf_type_t __attribute__((deprecated)); - #ifdef __cplusplus } #endif diff --git a/components/esp_wifi/CMakeLists.txt b/components/esp_wifi/CMakeLists.txt index 1bc1341ad..f4a53e693 100644 --- a/components/esp_wifi/CMakeLists.txt +++ b/components/esp_wifi/CMakeLists.txt @@ -12,7 +12,6 @@ idf_component_register(SRCS "src/coexist.c" "src/lib_printf.c" "src/mesh_event.c" "src/phy_init.c" - "src/restore.c" "src/smartconfig.c" "src/smartconfig_ack.c" "src/wifi_init.c" diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index ad13bd6c7..82fa00bfc 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -813,32 +813,6 @@ esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta); */ esp_err_t esp_wifi_set_storage(wifi_storage_t storage); -/** - * @brief Set auto connect - * The default value is true - * - * @param en : true - enable auto connect / false - disable auto connect - * - * @return - * - ESP_OK: succeed - * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init - * - ESP_ERR_WIFI_MODE: WiFi internal error, the station/soft-AP control block is invalid - * - others: refer to error code in esp_err.h - */ -esp_err_t esp_wifi_set_auto_connect(bool en) __attribute__ ((deprecated)); - -/** - * @brief Get the auto connect flag - * - * @param[out] en store current auto connect configuration - * - * @return - * - ESP_OK: succeed - * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init - * - ESP_ERR_INVALID_ARG: invalid argument - */ -esp_err_t esp_wifi_get_auto_connect(bool *en) __attribute__ ((deprecated)); - /** * @brief Function signature for received Vendor-Specific Information Element callback. * @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback. diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index 817c442bb..ad29f93bd 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -181,9 +181,7 @@ typedef enum { typedef struct { int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */ wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode */ -}wifi_fast_scan_threshold_t; - -typedef wifi_fast_scan_threshold_t wifi_scan_threshold_t; /**< wifi_fast_scan_threshold_t only used in fast scan mode once, now it enabled in all channel scan, the wifi_fast_scan_threshold_t will be remove in version 4.0 */ +}wifi_scan_threshold_t; typedef enum { WIFI_PS_NONE, /**< No power save */ @@ -191,8 +189,6 @@ typedef enum { WIFI_PS_MAX_MODEM, /**< Maximum modem power saving. In this mode, interval to receive beacons is determined by the listen_interval parameter in wifi_sta_config_t */ } wifi_ps_type_t; -#define WIFI_PS_MODEM WIFI_PS_MIN_MODEM /**< @deprecated Use WIFI_PS_MIN_MODEM or WIFI_PS_MAX_MODEM instead */ - #define WIFI_PROTOCOL_11B 1 #define WIFI_PROTOCOL_11G 2 #define WIFI_PROTOCOL_11N 4 diff --git a/components/esp_wifi/lib_esp32 b/components/esp_wifi/lib_esp32 index 7d93cbf05..3ea3a8f30 160000 --- a/components/esp_wifi/lib_esp32 +++ b/components/esp_wifi/lib_esp32 @@ -1 +1 @@ -Subproject commit 7d93cbf05bb521520700b2cbcc8e104d9cb9efec +Subproject commit 3ea3a8f30c6cd5b29ccfb8b9b74d3e6741bdc1c2 diff --git a/components/esp_wifi/src/restore.c b/components/esp_wifi/src/restore.c deleted file mode 100644 index e17f1ab77..000000000 --- a/components/esp_wifi/src/restore.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2013-2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "esp_system.h" -#include "esp_wifi.h" - -/* This function is in a separate file from the reset of system APIs because - * it causes link time dependency on WiFi stack. - */ -void system_restore(void) -{ - esp_wifi_restore(); -} diff --git a/components/espcoredump/Kconfig b/components/espcoredump/Kconfig index fe8b6e455..991bf18f7 100644 --- a/components/espcoredump/Kconfig +++ b/components/espcoredump/Kconfig @@ -13,7 +13,6 @@ menu "Core dump" config ESP32_ENABLE_COREDUMP_TO_FLASH bool "Flash" select ESP32_ENABLE_COREDUMP - select SPI_FLASH_USE_LEGACY_IMPL config ESP32_ENABLE_COREDUMP_TO_UART bool "UART" select ESP32_ENABLE_COREDUMP diff --git a/components/espcoredump/linker.lf b/components/espcoredump/linker.lf index 8a79b1a36..96a6dd259 100644 --- a/components/espcoredump/linker.lf +++ b/components/espcoredump/linker.lf @@ -8,3 +8,12 @@ entries: core_dump_port (noflash_text) else: * (default) + +[mapping:spi_flash_override] +archive: libspi_flash.a +entries: + if ESP_PANIC_HANDLER_IRAM = y && ESP32_ENABLE_COREDUMP_TO_FLASH = y: + esp_flash_api (noflash_text) + esp_flash_spi_init (noflash_text) + else: + * (default) diff --git a/components/espcoredump/src/core_dump_flash.c b/components/espcoredump/src/core_dump_flash.c index 21e85731e..569852536 100644 --- a/components/espcoredump/src/core_dump_flash.c +++ b/components/espcoredump/src/core_dump_flash.c @@ -15,6 +15,9 @@ #include "esp32/rom/crc.h" #include "esp_partition.h" #include "esp_core_dump_priv.h" +#include "esp_flash_internal.h" + +#include "sdkconfig.h" const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_flash"; @@ -50,7 +53,7 @@ static inline core_dump_crc_t esp_core_dump_calc_flash_config_crc(void) return crc32_le(0, (uint8_t const *)&s_core_flash_config.partition, sizeof(s_core_flash_config.partition)); } -void esp_core_dump_flash_init(void) +void esp_core_dump_flash_init(void) { const esp_partition_t *core_part; @@ -82,7 +85,11 @@ static uint32_t esp_core_dump_write_flash_padded(size_t off, uint8_t *data, uint assert((off + data_len + (data_size % sizeof(uint32_t) ? sizeof(uint32_t) : 0)) <= s_core_flash_config.partition.start + s_core_flash_config.partition.size); +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_write(off, data, data_len); +#else + err = esp_flash_write(esp_flash_default_chip, data, off, data_len); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to write data to flash (%d)!", err); return 0; @@ -95,7 +102,11 @@ static uint32_t esp_core_dump_write_flash_padded(size_t off, uint8_t *data, uint for (k = 0; k < len; k++) { rom_data.data8[k] = *(data + data_len + k); } +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_write(off + data_len, &rom_data, sizeof(uint32_t)); +#else + err = esp_flash_write(esp_flash_default_chip, &rom_data, off + data_len, sizeof(uint32_t)); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to finish write data to flash (%d)!", err); return 0; @@ -127,7 +138,11 @@ static esp_err_t esp_core_dump_flash_write_prepare(void *priv, uint32_t *data_le sec_num++; } assert(sec_num * SPI_FLASH_SEC_SIZE <= s_core_flash_config.partition.size); +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_erase_range(s_core_flash_config.partition.start + 0, sec_num * SPI_FLASH_SEC_SIZE); +#else + err = esp_flash_erase_region(esp_flash_default_chip, s_core_flash_config.partition.start + 0, sec_num * SPI_FLASH_SEC_SIZE); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to erase flash (%d)!", err); return err; @@ -141,7 +156,11 @@ static esp_err_t esp_core_dump_flash_write_word(core_dump_write_flash_data_t *wr uint32_t data32 = word; assert(wr_data->off + sizeof(uint32_t) <= s_core_flash_config.partition.size); +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_write(s_core_flash_config.partition.start + wr_data->off, &data32, sizeof(uint32_t)); +#else + err = esp_flash_write(esp_flash_default_chip, &data32, s_core_flash_config.partition.start + wr_data->off, sizeof(uint32_t)); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to write to flash (%d)!", err); return err; @@ -166,7 +185,11 @@ static esp_err_t esp_core_dump_flash_write_end(void *priv) uint32_t data32[4]; } rom_data; +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL esp_err_t err = spi_flash_read(s_core_flash_config.partition.start + 0, &rom_data, sizeof(rom_data)); +#else + esp_err_t err = esp_flash_read(esp_flash_default_chip, &rom_data, s_core_flash_config.partition.start + 0, sizeof(rom_data)); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to read flash (%d)!", err); return err; @@ -214,10 +237,9 @@ void esp_core_dump_to_flash(XtExcFrame *frame) return; } -#if CONFIG_SPI_FLASH_USE_LEGACY_IMPL // init non-OS flash access critical section spi_flash_guard_set(&g_flash_guard_no_os_ops); -#endif + esp_flash_app_disable_protect(true); memset(&wr_cfg, 0, sizeof(wr_cfg)); wr_cfg.prepare = esp_core_dump_flash_write_prepare; diff --git a/components/esptool_py/Makefile.projbuild b/components/esptool_py/Makefile.projbuild index 8292c06ec..a351e8282 100644 --- a/components/esptool_py/Makefile.projbuild +++ b/components/esptool_py/Makefile.projbuild @@ -31,6 +31,10 @@ endif ESPTOOL_ELF2IMAGE_OPTIONS := +ifdef CONFIG_ESP32_REV_MIN +ESPTOOL_ELF2IMAGE_OPTIONS += --min-rev $(CONFIG_ESP32_REV_MIN) +endif + ifdef CONFIG_SECURE_BOOT_ENABLED ifndef CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION ifndef IS_BOOTLOADER_BUILD diff --git a/components/esptool_py/esptool b/components/esptool_py/esptool index 9c41a5795..ecc72c540 160000 --- a/components/esptool_py/esptool +++ b/components/esptool_py/esptool @@ -1 +1 @@ -Subproject commit 9c41a57955b3c4b3873d653ac0d87c0900b135ff +Subproject commit ecc72c54037eeae9b95e442246b8a92696518a3b diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index af78f4583..edf91b0f3 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -52,6 +52,10 @@ if(CONFIG_SECURE_BOOT_ENABLED AND set(ESPTOOLPY_ELF2IMAGE_OPTIONS ${ESPTOOLPY_ELF2IMAGE_OPTIONS} --secure-pad) endif() +if(CONFIG_ESP32_REV_MIN) + set(ESPTOOLPY_ELF2IMAGE_OPTIONS ${ESPTOOLPY_ELF2IMAGE_OPTIONS} --min-rev ${CONFIG_ESP32_REV_MIN}) +endif() + if(CONFIG_ESPTOOLPY_FLASHSIZE_DETECT) # Set ESPFLASHSIZE to 'detect' *after* elf2image options are generated, # as elf2image can't have 'detect' as an option... diff --git a/components/fatfs/vfs/esp_vfs_fat.h b/components/fatfs/vfs/esp_vfs_fat.h index b7b2ee78b..01a4c70d1 100644 --- a/components/fatfs/vfs/esp_vfs_fat.h +++ b/components/fatfs/vfs/esp_vfs_fat.h @@ -50,20 +50,6 @@ extern "C" { esp_err_t esp_vfs_fat_register(const char* base_path, const char* fat_drive, size_t max_files, FATFS** out_fs); -/** - * @brief Un-register FATFS from VFS - * - * @note FATFS structure returned by esp_vfs_fat_register is destroyed after - * this call. Make sure to call f_mount function to unmount it before - * calling esp_vfs_fat_unregister. - * This function is left for compatibility and will be changed in - * future versions to accept base_path and replace the method below - * @return - * - ESP_OK on success - * - ESP_ERR_INVALID_STATE if FATFS is not registered in VFS - */ -esp_err_t esp_vfs_fat_unregister(void) __attribute__((deprecated)); - /** * @brief Un-register FATFS from VFS * diff --git a/components/fatfs/vfs/vfs_fat.c b/components/fatfs/vfs/vfs_fat.c index e4be41516..bb0a666e4 100644 --- a/components/fatfs/vfs/vfs_fat.c +++ b/components/fatfs/vfs/vfs_fat.c @@ -205,19 +205,6 @@ esp_err_t esp_vfs_fat_unregister_path(const char* base_path) return ESP_OK; } -esp_err_t esp_vfs_fat_unregister(void) -{ - if (s_fat_ctx == NULL) { - return ESP_ERR_INVALID_STATE; - } - esp_err_t err = esp_vfs_fat_unregister_path(s_fat_ctx->base_path); - if (err != ESP_OK) { - return err; - } - s_fat_ctx = NULL; - return ESP_OK; -} - static int get_next_fd(vfs_fat_ctx_t* fat_ctx) { for (size_t i = 0; i < fat_ctx->max_files; ++i) { diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index c6a4d36b3..e1331f812 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -411,7 +411,7 @@ menu "FreeRTOS" config FREERTOS_TASK_FUNCTION_WRAPPER bool "Enclose all task functions in a wrapper function" - depends on COMPILER_OPTIMIZATION_LEVEL_DEBUG + depends on COMPILER_OPTIMIZATION_DEFAULT default y help If enabled, all FreeRTOS task functions will be enclosed in a wrapper function. diff --git a/components/heap/include/esp_heap_alloc_caps.h b/components/heap/include/esp_heap_alloc_caps.h deleted file mode 100644 index 7e6e25d6a..000000000 --- a/components/heap/include/esp_heap_alloc_caps.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#warning "This header is deprecated, please use functions defined in esp_heap_caps.h instead." -#include "esp_heap_caps.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Deprecated FreeRTOS-style esp_heap_alloc_caps.h functions follow */ - -/* Please use heap_caps_malloc() instead of this function */ -void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps) asm("heap_caps_malloc") __attribute__((deprecated)); - -/* Please use heap_caps_get_minimum_free_size() instead of this function */ -size_t xPortGetMinimumEverFreeHeapSizeCaps( uint32_t caps ) asm("heap_caps_get_minimum_free_size") __attribute__((deprecated)); - -/* Please use heap_caps_get_free_size() instead of this function */ -size_t xPortGetFreeHeapSizeCaps( uint32_t caps ) asm("heap_caps_get_free_size") __attribute__((deprecated)); - -#ifdef __cplusplus -} -#endif diff --git a/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml b/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml index 7195a32cc..6906252fc 100644 --- a/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml +++ b/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml @@ -464,7 +464,6 @@ test cases: SDK: |- 8266_NonOS 8266_RTOS - ESP32_IDF Test App: SSC allow fail: '' auto test: 'Yes' @@ -1069,35 +1068,6 @@ test cases: test point 1: basic function test point 2: use WiFi API after WiFi stop version: v1 (2016-12-31) -- CI ready: 'Yes' - ID: WIFI_CONN_1202 - SDK: ESP32_IDF - Test App: SSC - allow fail: '' - auto test: 'Yes' - category: Function - cmd set: - - '' - - - SSC SSC1 sta -R -a 1 - - - R SSC1 C +AUTORECONN:OK - - - SSC SSC1 sta -Q - - - R SSC1 C +JAP:DISCONNECTED - execution time: 0 - expected result: | - 1. OK - 2. DISCONNECTED - initial condition: WIFISTO - level: Integration - module: WIFI MAC - steps: | - 1. sta reconnect start - 2. query sta state - sub module: WIFI Connect - summary: sta reconnect start and connect fail after WiFi stop - test environment: SSC_T1_5 - test point 1: basic function - test point 2: use WiFi API after WiFi stop - version: v1 (2016-12-31) - CI ready: 'Yes' ID: WIFI_CONN_1203 SDK: ESP32_IDF diff --git a/components/mbedtls/port/esp32/aes.c b/components/mbedtls/port/esp32/aes.c index db8f1bf57..edf2e2f08 100644 --- a/components/mbedtls/port/esp32/aes.c +++ b/components/mbedtls/port/esp32/aes.c @@ -208,13 +208,6 @@ int esp_internal_aes_encrypt( esp_aes_context *ctx, return r; } -void esp_aes_encrypt( esp_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16] ) -{ - esp_internal_aes_encrypt(ctx, input, output); -} - /* * AES-ECB block decryption */ @@ -237,13 +230,6 @@ int esp_internal_aes_decrypt( esp_aes_context *ctx, return r; } -void esp_aes_decrypt( esp_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16] ) -{ - esp_internal_aes_decrypt(ctx, input, output); -} - /* * AES-ECB block encryption/decryption */ diff --git a/components/mbedtls/port/include/esp32/aes.h b/components/mbedtls/port/include/esp32/aes.h index 107193015..f423b8a7f 100644 --- a/components/mbedtls/port/include/esp32/aes.h +++ b/components/mbedtls/port/include/esp32/aes.h @@ -332,9 +332,6 @@ int esp_aes_xts_setkey_dec( esp_aes_xts_context *ctx, */ int esp_internal_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ); -/** Deprecated, see esp_aes_internal_encrypt */ -void esp_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ) __attribute__((deprecated)); - /** * \brief Internal AES block decryption function * (Only exposed to allow overriding it, @@ -346,9 +343,6 @@ void esp_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsig */ int esp_internal_aes_decrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ); -/** Deprecated, see esp_aes_internal_decrypt */ -void esp_aes_decrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ) __attribute__((deprecated)); - /** AES-XTS buffer encryption/decryption */ int esp_aes_crypt_xts( esp_aes_xts_context *ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char *input, unsigned char *output ); diff --git a/components/nvs_flash/src/nvs_storage.cpp b/components/nvs_flash/src/nvs_storage.cpp index 1786f7316..4926df54b 100644 --- a/components/nvs_flash/src/nvs_storage.cpp +++ b/components/nvs_flash/src/nvs_storage.cpp @@ -45,7 +45,7 @@ void Storage::populateBlobIndices(TBlobIndexList& blobIdxList) while (p.findItem(Page::NS_ANY, ItemType::BLOB_IDX, nullptr, itemIndex, item) == ESP_OK) { BlobIndexNode* entry = new BlobIndexNode; - item.getKey(entry->key, sizeof(entry->key) - 1); + item.getKey(entry->key, sizeof(entry->key)); entry->nsIndex = item.nsIndex; entry->chunkStart = item.blobIndex.chunkStart; entry->chunkCount = item.blobIndex.chunkCount; @@ -101,7 +101,7 @@ esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount) Item item; while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) { NamespaceEntry* entry = new NamespaceEntry; - item.getKey(entry->mName, sizeof(entry->mName) - 1); + item.getKey(entry->mName, sizeof(entry->mName)); item.getValue(entry->mIndex); mNamespaces.push_back(entry); mNamespaceUsage.set(entry->mIndex, true); @@ -182,7 +182,7 @@ esp_err_t Storage::writeMultiPageBlob(uint8_t nsIndex, const char* key, const vo return err; } else if(getCurrentPage().getVarDataTailroom() == tailroom) { /* We got the same page or we are not improving.*/ - return ESP_ERR_NVS_NOT_ENOUGH_SPACE; + return ESP_ERR_NVS_NOT_ENOUGH_SPACE; } else { continue; } @@ -308,9 +308,9 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key if (err != ESP_OK) { return err; } - + findPage = nullptr; - } else { + } else { /* Support for earlier versions where BLOBS were stored without index */ err = findItem(nsIndex, datatype, key, findPage, item); if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) { @@ -512,14 +512,14 @@ esp_err_t Storage::readItem(uint8_t nsIndex, ItemType datatype, const char* key, if (err != ESP_ERR_NVS_NOT_FOUND) { return err; } // else check if the blob is stored with earlier version format without index - } + } auto err = findItem(nsIndex, datatype, key, findPage, item); if (err != ESP_OK) { return err; } return findPage->readItem(nsIndex, datatype, key, data, dataSize); - + } esp_err_t Storage::eraseMultiPageBlob(uint8_t nsIndex, const char* key, VerOffset chunkStart) diff --git a/components/nvs_flash/src/nvs_types.hpp b/components/nvs_flash/src/nvs_types.hpp index c4b7f51e9..74f34b5b6 100644 --- a/components/nvs_flash/src/nvs_types.hpp +++ b/components/nvs_flash/src/nvs_types.hpp @@ -21,7 +21,9 @@ #include #include "nvs.h" #include "compressed_enum_table.hpp" +#include "string.h" +using namespace std; namespace nvs { @@ -125,7 +127,8 @@ public: void getKey(char* dst, size_t dstSize) { - strncpy(dst, key, (dstSize @@ -138,6 +141,4 @@ public: } // namespace nvs - - #endif /* nvs_types_h */ diff --git a/components/soc/esp32/include/soc/io_mux_reg.h b/components/soc/esp32/include/soc/io_mux_reg.h index bf7d59e52..22ea25b91 100644 --- a/components/soc/esp32/include/soc/io_mux_reg.h +++ b/components/soc/esp32/include/soc/io_mux_reg.h @@ -77,40 +77,6 @@ #define PIN_INPUT_DISABLE(PIN_NAME) CLEAR_PERI_REG_MASK(PIN_NAME,FUN_IE) #define PIN_SET_DRV(PIN_NAME, drv) REG_SET_FIELD(PIN_NAME, FUN_DRV, (drv)); -/* - * @attention - * The PIN_PULL[UP|DWN]_[EN|DIS]() functions used to exist as macros in previous SDK versions. - * Unfortunately, however, they do not work for some GPIOs on the ESP32 chip, which needs pullups - * and -downs turned on and off through RTC registers. The functions still exist for compatibility - * with older code, but are marked as deprecated in order to generate a warning. - * Please replace them in this fashion: (make sure to include driver/gpio.h as well) - * PIN_PULLUP_EN(GPIO_PIN_MUX_REG[x]) -> gpio_pullup_en(x) - * PIN_PULLUP_DIS(GPIO_PIN_MUX_REG[x]) -> gpio_pullup_dis(x) - * PIN_PULLDWN_EN(GPIO_PIN_MUX_REG[x]) -> gpio_pulldown_en(x) - * PIN_PULLDWN_DIS(GPIO_PIN_MUX_REG[x]) -> gpio_pulldown_dis(x) - * -*/ -static inline void __attribute__ ((deprecated)) PIN_PULLUP_DIS(uint32_t PIN_NAME) -{ - REG_CLR_BIT(PIN_NAME, FUN_PU); -} - -static inline void __attribute__ ((deprecated)) PIN_PULLUP_EN(uint32_t PIN_NAME) -{ - REG_SET_BIT(PIN_NAME, FUN_PU); -} - -static inline void __attribute__ ((deprecated)) PIN_PULLDWN_DIS(uint32_t PIN_NAME) -{ - REG_CLR_BIT(PIN_NAME, FUN_PD); -} - -static inline void __attribute__ ((deprecated)) PIN_PULLDWN_EN(uint32_t PIN_NAME) -{ - REG_SET_BIT(PIN_NAME, FUN_PD); -} - - #define PIN_FUNC_SELECT(PIN_NAME, FUNC) REG_SET_FIELD(PIN_NAME, MCU_SEL, FUNC) #define PIN_FUNC_GPIO 2 diff --git a/components/soc/esp32/include/soc/ledc_struct.h b/components/soc/esp32/include/soc/ledc_struct.h index a9f505b8f..36c8303f8 100644 --- a/components/soc/esp32/include/soc/ledc_struct.h +++ b/components/soc/esp32/include/soc/ledc_struct.h @@ -79,11 +79,6 @@ typedef volatile struct ledc_dev_s { uint32_t low_speed_update: 1; /*This bit is only useful for low speed timer channels, reserved for high speed timers*/ uint32_t reserved26: 5; }; - struct { - uint32_t bit_num: 5 __attribute__((deprecated)); /*Deprecated in ESP-IDF 3.0. This is an alias to 'duty_resolution' for backward compatibility with ESP-IDF 2.1.*/ - uint32_t div_num: 18 __attribute__((deprecated)); /*Deprecated in ESP-IDF 3.0. This is an alias to 'clock_divider' for backward compatibility with ESP-IDF 2.1.*/ - uint32_t place_holder: 9 __attribute__((deprecated)); /*A place holder to accommodate deprecated members*/ - }; uint32_t val; } conf; union { diff --git a/components/soc/esp32/include/soc/rtc.h b/components/soc/esp32/include/soc/rtc.h index 22d3601d3..cb999ae1c 100644 --- a/components/soc/esp32/include/soc/rtc.h +++ b/components/soc/esp32/include/soc/rtc.h @@ -304,82 +304,6 @@ void rtc_clk_fast_freq_set(rtc_fast_freq_t fast_freq); */ rtc_fast_freq_t rtc_clk_fast_freq_get(void); -/** - * @brief Switch CPU frequency - * - * @note This function is deprecated and will be removed. - * See rtc_clk_cpu_freq_config_set instead. - * - * If a PLL-derived frequency is requested (80, 160, 240 MHz), this function - * will enable the PLL. Otherwise, PLL will be disabled. - * Note: this function is not optimized for switching speed. It may take several - * hundred microseconds to perform frequency switch. - * - * @param cpu_freq new CPU frequency - */ -void rtc_clk_cpu_freq_set(rtc_cpu_freq_t cpu_freq) __attribute__((deprecated)); - -/** - * @brief Switch CPU frequency - * - * @note This function is deprecated and will be removed. - * See rtc_clk_cpu_freq_set_config_fast instead. - * - * This is a faster version of rtc_clk_cpu_freq_set, which can handle some of - * the frequency switch paths (XTAL -> PLL, PLL -> XTAL). - * When switching from PLL to XTAL, PLL is not disabled (unlike rtc_clk_cpu_freq_set). - * When switching back from XTAL to PLL, only the same PLL can be used. - * Therefore it is not possible to switch 240 -> XTAL -> (80 or 160) using this - * function. - * - * For unsupported cases, this function falls back to rtc_clk_cpu_freq_set. - * - * Unlike rtc_clk_cpu_freq_set, this function relies on static data, so it is - * less safe to use it e.g. from a panic handler (when memory might be corrupted). - * - * @param cpu_freq new CPU frequency - */ -void rtc_clk_cpu_freq_set_fast(rtc_cpu_freq_t cpu_freq) __attribute__((deprecated)); - -/** - * @brief Get the currently selected CPU frequency - * - * @note This function is deprecated and will be removed. - * See rtc_clk_cpu_freq_get_config instead. - * - * Although CPU can be clocked by APLL and RTC 8M sources, such support is not - * exposed through this library. As such, this function will not return - * meaningful values when these clock sources are configured (e.g. using direct - * access to clock selection registers). In debug builds, it will assert; in - * release builds, it will return RTC_CPU_FREQ_XTAL. - * - * @return CPU frequency (one of rtc_cpu_freq_t values) - */ -rtc_cpu_freq_t rtc_clk_cpu_freq_get(void) __attribute__((deprecated)); - -/** - * @brief Get corresponding frequency value for rtc_cpu_freq_t enum value - * - * @note This function is deprecated and will be removed. - * See rtc_clk_cpu_freq_get/set_config instead. - * - * @param cpu_freq CPU frequency, on of rtc_cpu_freq_t values - * @return CPU frequency, in HZ - */ -uint32_t rtc_clk_cpu_freq_value(rtc_cpu_freq_t cpu_freq) __attribute__((deprecated)); - -/** - * @brief Get rtc_cpu_freq_t enum value for given CPU frequency - * - * @note This function is deprecated and will be removed. - * See rtc_clk_cpu_freq_mhz_to_config instead. - * - * @param cpu_freq_mhz CPU frequency, one of 80, 160, 240, 2, and XTAL frequency - * @param[out] out_val output, rtc_cpu_freq_t value corresponding to the frequency - * @return true if the given frequency value matches one of enum values - */ - bool rtc_clk_cpu_freq_from_mhz(int cpu_freq_mhz, rtc_cpu_freq_t* out_val) __attribute__((deprecated)); - /** * @brief Get CPU frequency config corresponding to a rtc_cpu_freq_t value * @param cpu_freq CPU frequency enumeration value diff --git a/components/soc/esp32/rtc_clk.c b/components/soc/esp32/rtc_clk.c index 42640b32f..e0c74ec72 100644 --- a/components/soc/esp32/rtc_clk.c +++ b/components/soc/esp32/rtc_clk.c @@ -104,7 +104,6 @@ static void rtc_clk_cpu_freq_to_8m(void); static void rtc_clk_bbpll_disable(void); static void rtc_clk_bbpll_enable(void); static void rtc_clk_cpu_freq_to_pll_mhz(int cpu_freq_mhz); -static bool rtc_clk_cpu_freq_from_mhz_internal(int mhz, rtc_cpu_freq_t* out_val); // Current PLL frequency, in MHZ (320 or 480). Zero if PLL is not enabled. static int s_cur_pll_freq; @@ -501,21 +500,6 @@ static void rtc_clk_cpu_freq_to_pll_mhz(int cpu_freq_mhz) rtc_clk_wait_for_slow_cycle(); } - -void rtc_clk_cpu_freq_set(rtc_cpu_freq_t cpu_freq) -{ - rtc_cpu_freq_config_t config; - rtc_clk_cpu_freq_to_config(cpu_freq, &config); - rtc_clk_cpu_freq_set_config(&config); -} - -void rtc_clk_cpu_freq_set_fast(rtc_cpu_freq_t cpu_freq) -{ - rtc_cpu_freq_config_t config; - rtc_clk_cpu_freq_to_config(cpu_freq, &config); - rtc_clk_cpu_freq_set_config_fast(&config); -} - void rtc_clk_cpu_freq_set_xtal(void) { int freq_mhz = (int) rtc_clk_xtal_freq_get(); @@ -525,57 +509,6 @@ void rtc_clk_cpu_freq_set_xtal(void) rtc_clk_bbpll_disable(); } -rtc_cpu_freq_t rtc_clk_cpu_freq_get(void) -{ - rtc_cpu_freq_config_t config; - rtc_clk_cpu_freq_get_config(&config); - rtc_cpu_freq_t freq = RTC_CPU_FREQ_XTAL; - rtc_clk_cpu_freq_from_mhz_internal(config.freq_mhz, &freq); - return freq; -} - -uint32_t rtc_clk_cpu_freq_value(rtc_cpu_freq_t cpu_freq) -{ - switch (cpu_freq) { - case RTC_CPU_FREQ_XTAL: - return ((uint32_t) rtc_clk_xtal_freq_get()) * MHZ; - case RTC_CPU_FREQ_2M: - return 2 * MHZ; - case RTC_CPU_FREQ_80M: - return 80 * MHZ; - case RTC_CPU_FREQ_160M: - return 160 * MHZ; - case RTC_CPU_FREQ_240M: - return 240 * MHZ; - default: - SOC_LOGE(TAG, "invalid rtc_cpu_freq_t value"); - return 0; - } -} - -static bool rtc_clk_cpu_freq_from_mhz_internal(int mhz, rtc_cpu_freq_t* out_val) -{ - if (mhz == 240) { - *out_val = RTC_CPU_FREQ_240M; - } else if (mhz == 160) { - *out_val = RTC_CPU_FREQ_160M; - } else if (mhz == 80) { - *out_val = RTC_CPU_FREQ_80M; - } else if (mhz == (int) rtc_clk_xtal_freq_get()) { - *out_val = RTC_CPU_FREQ_XTAL; - } else if (mhz == 2) { - *out_val = RTC_CPU_FREQ_2M; - } else { - return false; - } - return true; -} - -bool rtc_clk_cpu_freq_from_mhz(int mhz, rtc_cpu_freq_t* out_val) -{ - return rtc_clk_cpu_freq_from_mhz_internal(mhz, out_val); -} - void rtc_clk_cpu_freq_to_config(rtc_cpu_freq_t cpu_freq, rtc_cpu_freq_config_t* out_config) { uint32_t source_freq_mhz; diff --git a/components/soc/include/hal/spi_flash_types.h b/components/soc/include/hal/spi_flash_types.h index 7babeee0c..c19eee1ed 100644 --- a/components/soc/include/hal/spi_flash_types.h +++ b/components/soc/include/hal/spi_flash_types.h @@ -142,11 +142,6 @@ struct spi_flash_host_driver_t { * modified, the cache needs to be flushed. Left NULL if not supported. */ esp_err_t (*flush_cache)(spi_flash_host_driver_t* driver, uint32_t addr, uint32_t size); - /** - * Check if the given region is protected (e.g. is the bootloader). Left - * NULL if current host doesn't need protection. - */ - bool (*region_protected)(spi_flash_host_driver_t* driver, uint32_t addr, uint32_t size); }; #ifdef __cplusplus diff --git a/components/spi_flash/CMakeLists.txt b/components/spi_flash/CMakeLists.txt index 756ef6767..547ef167d 100644 --- a/components/spi_flash/CMakeLists.txt +++ b/components/spi_flash/CMakeLists.txt @@ -12,18 +12,19 @@ else() "spi_flash_chip_drivers.c" "spi_flash_chip_generic.c" "spi_flash_chip_issi.c" + "spi_flash_rom_patch.c" ) if (NOT CONFIG_IDF_TARGET_ESP32S2BETA) # TODO: workaround until ESP32-S2 supports new API, can be always included list(APPEND srcs "esp_flash_spi_init.c" "memspi_host_driver.c" "spi_flash_os_func_app.c" - "spi_flash_os_func_noos.c") + "spi_flash_os_func_noos.c" + "memspi_host_driver.c" + "esp_flash_api.c" + ) endif() - if(NOT CONFIG_SPI_FLASH_USE_LEGACY_IMPL) - list(APPEND srcs "esp_flash_api.c") - endif() set(priv_requires bootloader_support app_update soc) endif() diff --git a/components/spi_flash/esp_flash_api.c b/components/spi_flash/esp_flash_api.c index e45f906ab..b062619dc 100644 --- a/components/spi_flash/esp_flash_api.c +++ b/components/spi_flash/esp_flash_api.c @@ -22,6 +22,7 @@ #include "esp_log.h" #include "sdkconfig.h" #include "esp_heap_caps.h" +#include "esp_flash_internal.h" static const char TAG[] = "spi_flash"; @@ -42,7 +43,7 @@ static const char TAG[] = "spi_flash"; #define CHECK_WRITE_ADDRESS(CHIP, ADDR, SIZE) #else /* FAILS or ABORTS */ #define CHECK_WRITE_ADDRESS(CHIP, ADDR, SIZE) do { \ - if (CHIP && CHIP->host->region_protected && CHIP->host->region_protected(CHIP->host, ADDR, SIZE)) { \ + if (CHIP && CHIP->os_func->region_protected && CHIP->os_func->region_protected(CHIP->os_func_data, ADDR, SIZE)) { \ UNSAFE_WRITE_ADDRESS; \ } \ } while(0) @@ -294,14 +295,15 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui return ESP_ERR_INVALID_ARG; } - esp_err_t err = spiflash_start(chip); - if (err != ESP_OK) { - return err; - } - + esp_err_t err = ESP_OK; // Check for write protected regions overlapping the erase region if (chip->chip_drv->get_protected_regions != NULL && chip->chip_drv->num_protectable_regions > 0) { + + err = spiflash_start(chip); + if (err != ESP_OK) { + return err; + } uint64_t protected = 0; err = chip->chip_drv->get_protected_regions(chip, &protected); if (err == ESP_OK && protected != 0) { @@ -313,10 +315,10 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui } } } + // Don't lock the SPI flash for the entire erase, as this may be very long + err = spiflash_end(chip, err); } - // Don't lock the SPI flash for the entire erase, as this may be very long - err = spiflash_end(chip, err); while (err == ESP_OK && len >= sector_size) { err = spiflash_start(chip); @@ -615,6 +617,17 @@ esp_err_t IRAM_ATTR esp_flash_read_encrypted(esp_flash_t *chip, uint32_t address return spi_flash_read_encrypted(address, out_buffer, length); } +#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL +esp_err_t esp_flash_app_disable_protect(bool disable) +{ + if (disable) { + return esp_flash_app_disable_os_functions(esp_flash_default_chip); + } else { + return esp_flash_app_init_os_functions(esp_flash_default_chip); + } +} +#endif + /*------------------------------------------------------------------------------ Adapter layer to original api before IDF v4.0 ------------------------------------------------------------------------------*/ diff --git a/components/spi_flash/esp_flash_spi_init.c b/components/spi_flash/esp_flash_spi_init.c index c554f4a29..9938ab3fb 100644 --- a/components/spi_flash/esp_flash_spi_init.c +++ b/components/spi_flash/esp_flash_spi_init.c @@ -22,8 +22,9 @@ #include "esp_heap_caps.h" #include "hal/spi_types.h" #include "driver/spi_common.h" +#include "esp_flash_internal.h" -static const char TAG[] = "spi_flash"; +__attribute__((unused)) static const char TAG[] = "spi_flash"; #ifdef CONFIG_ESPTOOLPY_FLASHFREQ_80M #define DEFAULT_FLASH_SPEED ESP_FLASH_80MHZ @@ -49,6 +50,18 @@ static const char TAG[] = "spi_flash"; #define DEFAULT_FLASH_MODE SPI_FLASH_FASTRD #endif +#define ESP_FLASH_HOST_CONFIG_DEFAULT() (memspi_host_config_t){ \ + .host_id = SPI_HOST,\ + .speed = DEFAULT_FLASH_SPEED, \ + .cs_num = 0, \ + .iomux = false, \ + .input_delay_ns = 0,\ +} + + +esp_flash_t *esp_flash_default_chip = NULL; + + static IRAM_ATTR void cs_initialize(esp_flash_t *chip, const esp_flash_spi_device_config_t *config, bool use_iomux) { //Not using spicommon_cs_initialize since we don't want to put the whole @@ -151,29 +164,22 @@ esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip) return ESP_OK; } -#define ESP_FLASH_HOST_CONFIG_DEFAULT() (memspi_host_config_t){ \ - .host_id = SPI_HOST,\ - .speed = DEFAULT_FLASH_SPEED, \ - .cs_num = 0, \ - .iomux = false, \ - .input_delay_ns = 0,\ -} - -static DRAM_ATTR spi_flash_host_driver_t esp_flash_default_host_drv = ESP_FLASH_DEFAULT_HOST_DRIVER(); - -static DRAM_ATTR memspi_host_data_t default_driver_data; /* The default (ie initial boot) no-OS ROM esp_flash_os_functions_t */ extern const esp_flash_os_functions_t esp_flash_noos_functions; +#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL + +static DRAM_ATTR memspi_host_data_t default_driver_data; +static DRAM_ATTR spi_flash_host_driver_t esp_flash_default_host_drv = ESP_FLASH_DEFAULT_HOST_DRIVER(); + + static DRAM_ATTR esp_flash_t default_chip = { .read_mode = DEFAULT_FLASH_MODE, .host = &esp_flash_default_host_drv, .os_func = &esp_flash_noos_functions, }; -esp_flash_t *esp_flash_default_chip = NULL; - esp_err_t esp_flash_init_default_chip(void) { memspi_host_config_t cfg = ESP_FLASH_HOST_CONFIG_DEFAULT(); @@ -202,5 +208,7 @@ esp_err_t esp_flash_init_default_chip(void) esp_err_t esp_flash_app_init(void) { - return esp_flash_init_os_functions(&default_chip, 0); + return esp_flash_app_init_os_functions(&default_chip); } + +#endif diff --git a/components/spi_flash/include/esp_flash.h b/components/spi_flash/include/esp_flash.h index 0de03e121..caca07596 100644 --- a/components/spi_flash/include/esp_flash.h +++ b/components/spi_flash/include/esp_flash.h @@ -45,6 +45,9 @@ typedef struct { /** Called after completing any flash operation. */ esp_err_t (*end)(void *arg); + /** Called before any erase/write operations to check whether the region is limited by the OS */ + esp_err_t (*region_protected)(void* arg, size_t start_addr, size_t size); + /** Delay for at least 'ms' milliseconds. Called in between 'start' and 'end'. */ esp_err_t (*delay_ms)(void *arg, unsigned ms); } esp_flash_os_functions_t; @@ -282,33 +285,6 @@ esp_err_t esp_flash_read_encrypted(esp_flash_t *chip, uint32_t address, void *ou */ extern esp_flash_t *esp_flash_default_chip; -/** @brief Initialise the default SPI flash chip - * - * Called by OS startup code. You do not need to call this in your own applications. - */ -esp_err_t esp_flash_init_default_chip(void); - -/** - * Enable OS-level SPI flash protections in IDF - * - * Called by OS startup code. You do not need to call this in your own applications. - * - * @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``. - */ -esp_err_t esp_flash_app_init(void); - -/** - * Enable OS-level SPI flash for a specific chip. - * - * @param chip The chip to init os functions. - * @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI) - * - * @return - * - ESP_OK if success - * - ESP_ERR_INVALID_ARG if host_id is invalid - */ -esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id); - #ifdef __cplusplus } diff --git a/components/spi_flash/include/esp_flash_internal.h b/components/spi_flash/include/esp_flash_internal.h new file mode 100644 index 000000000..0496f5649 --- /dev/null +++ b/components/spi_flash/include/esp_flash_internal.h @@ -0,0 +1,100 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#include "esp_err.h" +#include +#include +#include "sdkconfig.h" + +#include "esp_flash.h" + +/** Internal API, don't use in the applications */ + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @brief Initialise the default SPI flash chip + * + * Called by OS startup code. You do not need to call this in your own applications. + */ +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL +#define esp_flash_init_default_chip(...) ({ESP_OK;}) +#else +esp_err_t esp_flash_init_default_chip(void); +#endif + +/** + * Enable OS-level SPI flash protections in IDF + * + * Called by OS startup code. You do not need to call this in your own applications. + * + * @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``. + */ +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL +#define esp_flash_app_init(...) ({ESP_OK;}) +#else +esp_err_t esp_flash_app_init(void); +#endif + +/** + * Disable OS-level SPI flash protections in IDF + * + * Called by the IDF internal code (e.g. coredump). You do not need to call this in your own applications. + * + * @return always ESP_OK. + */ +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL +#define esp_flash_app_disable_protect(...) ({ESP_OK;}) +#else +esp_err_t esp_flash_app_disable_protect(bool disable); +#endif + +/** + * Initialize OS-level functions for a specific chip. + * + * @param chip The chip to init os functions. + * @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI) + * + * @return + * - ESP_OK if success + * - ESP_ERR_INVALID_ARG if host_id is invalid + */ +esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id); + +/** + * Initialize OS-level functions for the main flash chip. + * + * @param chip The chip to init os functions. Only pointer to the default chip is supported now. + * + * @return always ESP_OK + */ +esp_err_t esp_flash_app_init_os_functions(esp_flash_t* chip); + +/** + * Disable OS-level functions for the main flash chip during special phases (e.g. coredump) + * + * @param chip The chip to init os functions. Only "esp_flash_default_chip" is supported now. + * + * @return always ESP_OK + */ +esp_err_t esp_flash_app_disable_os_functions(esp_flash_t* chip); + + + +#ifdef __cplusplus +} +#endif diff --git a/components/spi_flash/include/memspi_host_driver.h b/components/spi_flash/include/memspi_host_driver.h index 434361d97..cb0f3e9d9 100644 --- a/components/spi_flash/include/memspi_host_driver.h +++ b/components/spi_flash/include/memspi_host_driver.h @@ -35,7 +35,6 @@ .configure_host_read_mode = spi_flash_hal_configure_host_read_mode, \ .poll_cmd_done = spi_flash_hal_poll_cmd_done, \ .flush_cache = memspi_host_flush_cache, \ - .region_protected = memspi_region_protected, \ } /// configuration for the memspi host @@ -100,14 +99,3 @@ esp_err_t memspi_host_read_status_hs(spi_flash_host_driver_t *driver, uint8_t *o * @return always ESP_OK. */ esp_err_t memspi_host_flush_cache(spi_flash_host_driver_t* driver, uint32_t addr, uint32_t size); - -/** - * Check if the given region is protected. - * - * @param driver The driver context. - * @param addr Start address of the region. - * @param size Size of the region to check. - * - * @return true if protected, otherwise false. - */ -bool memspi_region_protected(spi_flash_host_driver_t* driver, uint32_t addr, uint32_t size); \ No newline at end of file diff --git a/components/spi_flash/memspi_host_driver.c b/components/spi_flash/memspi_host_driver.c index 871616386..85b31998a 100644 --- a/components/spi_flash/memspi_host_driver.c +++ b/components/spi_flash/memspi_host_driver.c @@ -34,7 +34,6 @@ esp_err_t memspi_host_init_pointers(spi_flash_host_driver_t *host, memspi_host_d //some functions are not required if not SPI1 if (data->spi != &SPI1) { host->flush_cache = NULL; - host->region_protected = NULL; } return ESP_OK; } @@ -87,15 +86,4 @@ esp_err_t memspi_host_flush_cache(spi_flash_host_driver_t* driver, uint32_t addr spi_flash_check_and_flush_cache(addr, size); } return ESP_OK; -} - -bool memspi_region_protected(spi_flash_host_driver_t* driver, uint32_t addr, uint32_t size) -{ - if (((memspi_host_data_t*)(driver->driver_data))->spi != &SPI1) { - return false; - } - if (!esp_partition_main_flash_region_safe(addr, size)) { - return true; - } - return false; } \ No newline at end of file diff --git a/components/spi_flash/partition.c b/components/spi_flash/partition.c index a6b33a138..14de32c9f 100644 --- a/components/spi_flash/partition.c +++ b/components/spi_flash/partition.c @@ -172,9 +172,7 @@ static esp_err_t load_partitions(void) err = ESP_ERR_NO_MEM; break; } -#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL item->info.flash_chip = esp_flash_default_chip; -#endif item->info.address = it->pos.offset; item->info.size = it->pos.size; item->info.type = it->type; @@ -336,11 +334,10 @@ esp_err_t esp_partition_read(const esp_partition_t* partition, #endif // CONFIG_SPI_FLASH_USE_LEGACY_IMPL } else { #if CONFIG_SECURE_FLASH_ENC_ENABLED -#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL if (partition->flash_chip != esp_flash_default_chip) { return ESP_ERR_NOT_SUPPORTED; } -#endif + /* Encrypted partitions need to be read via a cache mapping */ const void *buf; spi_flash_mmap_handle_t handle; @@ -379,11 +376,9 @@ esp_err_t esp_partition_write(const esp_partition_t* partition, #endif // CONFIG_SPI_FLASH_USE_LEGACY_IMPL } else { #if CONFIG_SECURE_FLASH_ENC_ENABLED -#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL if (partition->flash_chip != esp_flash_default_chip) { return ESP_ERR_NOT_SUPPORTED; } -#endif return spi_flash_write_encrypted(dst_offset, src, size); #else return ESP_ERR_NOT_SUPPORTED; @@ -433,11 +428,9 @@ esp_err_t esp_partition_mmap(const esp_partition_t* partition, size_t offset, si if (offset + size > partition->size) { return ESP_ERR_INVALID_SIZE; } -#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL if (partition->flash_chip != esp_flash_default_chip) { return ESP_ERR_NOT_SUPPORTED; } -#endif size_t phys_addr = partition->address + offset; // offset within 64kB block size_t region_offset = phys_addr & 0xffff; diff --git a/components/spi_flash/spi_flash_os_func_app.c b/components/spi_flash/spi_flash_os_func_app.c index 7328250eb..655d12940 100644 --- a/components/spi_flash/spi_flash_os_func_app.c +++ b/components/spi_flash/spi_flash_os_func_app.c @@ -16,6 +16,8 @@ #include "esp_attr.h" #include "esp_spi_flash.h" //for ``g_flash_guard_default_ops`` #include "esp_flash.h" +#include "esp_flash_partitions.h" + #ifdef CONFIG_IDF_TARGET_ESP32 #include "esp32/rom/ets_sys.h" @@ -34,6 +36,11 @@ typedef struct { int host_id; } app_func_arg_t; +typedef struct { + int host_id; + bool no_protect; //to decide whether to check protected region (for the main chip) or not. +} spi1_app_func_arg_t; + // in the future we will have arbitration among devices, including flash on the same flash bus static IRAM_ATTR esp_err_t spi_bus_acquire(int host_id) { @@ -50,7 +57,7 @@ static IRAM_ATTR esp_err_t spi1_start(void *arg) { g_flash_guard_default_ops.start(); - spi_bus_acquire(((app_func_arg_t *)arg)->host_id); + spi_bus_acquire(((spi1_app_func_arg_t *)arg)->host_id); return ESP_OK; } @@ -58,7 +65,7 @@ static IRAM_ATTR esp_err_t spi1_end(void *arg) { g_flash_guard_default_ops.end(); - spi_bus_release(((app_func_arg_t *)arg)->host_id); + spi_bus_release(((spi1_app_func_arg_t *)arg)->host_id); return ESP_OK; } @@ -81,8 +88,24 @@ static IRAM_ATTR esp_err_t delay_ms(void *arg, unsigned ms) return ESP_OK; } -static DRAM_ATTR app_func_arg_t spi1_arg = { +static IRAM_ATTR esp_err_t main_flash_region_protected(void* arg, size_t start_addr, size_t size) +{ + if (((spi1_app_func_arg_t*)arg)->no_protect || esp_partition_main_flash_region_safe(start_addr, size)) { + //ESP_OK = 0, also means protected==0 + return ESP_OK; + } else { + return ESP_ERR_NOT_SUPPORTED; + } +} + +static DRAM_ATTR spi1_app_func_arg_t spi1_arg = { .host_id = 0, //for SPI1, + .no_protect = true, +}; + +static DRAM_ATTR spi1_app_func_arg_t main_flash_arg = { + .host_id = 0, //for SPI1, + .no_protect = false, }; static app_func_arg_t spi2_arg = { @@ -98,6 +121,7 @@ const DRAM_ATTR esp_flash_os_functions_t esp_flash_spi1_default_os_functions = { .start = spi1_start, .end = spi1_end, .delay_ms = delay_ms, + .region_protected = main_flash_region_protected, }; const esp_flash_os_functions_t esp_flash_spi23_default_os_functions = { @@ -122,4 +146,11 @@ esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id) return ESP_OK; } +esp_err_t esp_flash_app_init_os_functions(esp_flash_t* chip) +{ + chip->os_func = &esp_flash_spi1_default_os_functions; + chip->os_func_data = &main_flash_arg; + return ESP_OK; +} + diff --git a/components/spi_flash/spi_flash_os_func_noos.c b/components/spi_flash/spi_flash_os_func_noos.c index 0e4cc34a8..6595a4781 100644 --- a/components/spi_flash/spi_flash_os_func_noos.c +++ b/components/spi_flash/spi_flash_os_func_noos.c @@ -25,13 +25,15 @@ #include "esp32s2beta/rom/cache.h" #endif -static esp_err_t start(void *arg) + +static IRAM_ATTR esp_err_t start(void *arg) { Cache_Read_Disable(0); Cache_Read_Disable(1); return ESP_OK; } -static esp_err_t end(void *arg) + +static IRAM_ATTR esp_err_t end(void *arg) { Cache_Flush(0); Cache_Flush(1); @@ -40,14 +42,21 @@ static esp_err_t end(void *arg) return ESP_OK; } -static esp_err_t delay_ms(void *arg, unsigned ms) +static IRAM_ATTR esp_err_t delay_ms(void *arg, unsigned ms) { ets_delay_us(1000 * ms); return ESP_OK; } -const esp_flash_os_functions_t esp_flash_noos_functions = { +const DRAM_ATTR esp_flash_os_functions_t esp_flash_noos_functions = { .start = start, .end = end, .delay_ms = delay_ms, + .region_protected = NULL, }; + +esp_err_t IRAM_ATTR esp_flash_app_disable_os_functions(esp_flash_t* chip) +{ + chip->os_func = &esp_flash_noos_functions; + return ESP_OK; +} diff --git a/components/spiffs/component.mk b/components/spiffs/component.mk index f245a57e1..804b02bd3 100644 --- a/components/spiffs/component.mk +++ b/components/spiffs/component.mk @@ -2,4 +2,7 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := . spiffs/src COMPONENT_SRCDIRS := . spiffs/src +# To avoid warning for strncpy in "spiffs_nucleus.c" +CPPFLAGS += -Wno-stringop-truncation + COMPONENT_SUBMODULES := spiffs diff --git a/components/wifi_provisioning/CMakeLists.txt b/components/wifi_provisioning/CMakeLists.txt index 41e09b17f..fd8128fda 100644 --- a/components/wifi_provisioning/CMakeLists.txt +++ b/components/wifi_provisioning/CMakeLists.txt @@ -20,3 +20,9 @@ idf_component_register(SRCS "${srcs}" PRIV_INCLUDE_DIRS src proto-c ../protocomm/proto-c REQUIRES lwip protocomm PRIV_REQUIRES protobuf-c bt mdns json) + +# To avoid warning for strncpy +set_source_files_properties(src/handlers.c src/scheme_softap.c + PROPERTIES COMPILE_FLAGS + -Wno-stringop-truncation +) diff --git a/components/wifi_provisioning/component.mk b/components/wifi_provisioning/component.mk index 66a43c3f2..1d3fc7474 100644 --- a/components/wifi_provisioning/component.mk +++ b/components/wifi_provisioning/component.mk @@ -2,6 +2,9 @@ COMPONENT_SRCDIRS := src proto-c COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := src proto-c ../protocomm/proto-c/ +# To avoid warning for strncpy in "handlers.c" and "scheme_softap.c" +CPPFLAGS += -Wno-stringop-truncation + ifndef CONFIG_BT_BLUEDROID_ENABLED ifndef CONFIG_BT_NIMBLE_ENABLED COMPONENT_OBJEXCLUDE := src/scheme_ble.o diff --git a/components/wpa_supplicant/src/tls/tlsv1_cred.c b/components/wpa_supplicant/src/tls/tlsv1_cred.c index ed7577617..67970f9f5 100644 --- a/components/wpa_supplicant/src/tls/tlsv1_cred.c +++ b/components/wpa_supplicant/src/tls/tlsv1_cred.c @@ -157,7 +157,7 @@ static int tlsv1_set_cert_chain(struct x509_certificate **chain, if (cert) { u8 *buf = NULL; - size_t len; + size_t len = 0; int ret; if (buf == NULL) { @@ -328,7 +328,7 @@ int tlsv1_set_private_key(struct tlsv1_credentials *cred, if (private_key) { u8 *buf = NULL; - size_t len; + size_t len = 0; int ret; if (buf == NULL) { @@ -484,7 +484,7 @@ int tlsv1_set_dhparams(struct tlsv1_credentials *cred, const char *dh_file, if (dh_file) { u8 *buf = NULL; - size_t len; + size_t len = 0; int ret; if (buf == NULL) { diff --git a/docs/en/api-guides/build-system-legacy.rst b/docs/en/api-guides/build-system-legacy.rst index 52ca8642c..19c1ad3ee 100644 --- a/docs/en/api-guides/build-system-legacy.rst +++ b/docs/en/api-guides/build-system-legacy.rst @@ -360,7 +360,7 @@ Advanced Make Targets --------------------- - ``make app``, ``make bootloader``, ``make partition table`` can be used to build only the app, bootloader, or partition table from the project as applicable. -- ``make erase_flash`` and ``make erase_ota`` will use esptool.py to erase the entire flash chip and the OTA selection setting from the flash chip, respectively. +- ``make erase_flash`` and ``make erase_otadata`` will use esptool.py to erase the entire flash chip and the OTA selection setting from the flash chip, respectively. - ``make size`` prints some size information about the app. ``make size-components`` and ``make size-files`` are similar targets which print more detailed per-component or per-source-file information, respectively. diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index 97eb3d3f3..7a4f7f822 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -1130,7 +1130,8 @@ For example, to get the Python interpreter used for the build: message(STATUS "The Python intepreter is: ${python}") - BUILD_DIR - build directory; set from ``idf_build_process`` BUILD_DIR argument - - BUILD_COMPONENTS - list of components (more specifically, component aliases) included in the build; set by ``idf_build_process`` + - BUILD_COMPONENTS - list of components included in the build; set by ``idf_build_process`` + - BUILD_COMPONENT_ALIASES - list of library alias of components included in the build; set by ``idf_build_process`` - C_COMPILE_OPTIONS - compile options applied to all components' C source files - COMPILE_OPTIONS - compile options applied to all components' source files, regardless of it being C or C++ - COMPILE_DEFINITIONS - compile definitions applied to all component source files diff --git a/docs/en/api-reference/peripherals/touch_pad.rst b/docs/en/api-reference/peripherals/touch_pad.rst index 6d4c2f8ac..7da4b4d05 100644 --- a/docs/en/api-reference/peripherals/touch_pad.rst +++ b/docs/en/api-reference/peripherals/touch_pad.rst @@ -1,6 +1,8 @@ Touch Sensor ============ +:link_to_translation:`zh_CN:[中文]` + Introduction ------------ diff --git a/docs/en/api-reference/storage/sdmmc.rst b/docs/en/api-reference/storage/sdmmc.rst index 2b7490ddb..d650ccdaf 100644 --- a/docs/en/api-reference/storage/sdmmc.rst +++ b/docs/en/api-reference/storage/sdmmc.rst @@ -1,6 +1,8 @@ SD/SDIO/MMC Driver ================== +:link_to_translation:`zh_CN:[中文]` + Overview -------- diff --git a/docs/en/get-started/eclipse-setup.rst b/docs/en/get-started/eclipse-setup.rst index 08b46fcf6..f6a499561 100644 --- a/docs/en/get-started/eclipse-setup.rst +++ b/docs/en/get-started/eclipse-setup.rst @@ -3,10 +3,8 @@ Build and Flash with Eclipse IDE ******************************** :link_to_translation:`zh_CN:[中文]` -ESP-IDF V4.0 will be released with a new CMake-based build system as the default build system. +ESP-IDF V4.0 has a new CMake-based build system as the default build system. -Eclipse CDT IDE support for CMake-based build system will be available before the ESP-IDF V4.0 release but -is not available yet. We apologise for the inconvenience. - -If you require Eclipse IDE support for this pre-release version of ESP-IDF, you can follow the :doc:`legacy GNU Make build system Getting Started guide ` which has steps for :doc:`Building and Flashing with Eclipse IDE `. +There is a new ESP-IDF Eclipse Plugin that works with the CMake-based build system. Please refer to https://github.com/espressif/idf-eclipse-plugin/blob/master/README.md for further instructions. +If you require Eclipse IDE support for legacy ESP_IDF Make build system, you can follow the :doc:`legacy GNU Make build system Getting Started guide ` which has steps for :doc:`Building and Flashing with Eclipse IDE `. diff --git a/docs/en/versions.rst b/docs/en/versions.rst index a1cd3ece6..70048064d 100644 --- a/docs/en/versions.rst +++ b/docs/en/versions.rst @@ -59,10 +59,9 @@ ESP-IDF uses `Semantic Versioning `_. This means that: Checking the Current Version ---------------------------- -The local ESP-IDF version can be checked by using git:: +The local ESP-IDF version can be checked by using idf.py:: - cd $IDF_PATH - git describe --tags --dirty + idf.py --version The ESP-IDF version is also compiled into the firmware and can be accessed (as a string) via the macro ``IDF_VER``. The default ESP-IDF bootloader will print the version on boot (the version information is not always updated in code, it only changes if that particular source file is recompiled). diff --git a/docs/zh_CN/api-guides/build-system-legacy.rst b/docs/zh_CN/api-guides/build-system-legacy.rst index cc7241005..3ae2cdda4 100644 --- a/docs/zh_CN/api-guides/build-system-legacy.rst +++ b/docs/zh_CN/api-guides/build-system-legacy.rst @@ -289,7 +289,7 @@ ESP-IDF 构建系统会在命令行中添加以下 C 预处理定义: ~~~~~~~~~~~~~~~~~~ - ``make app``,``make bootloader``,``make partition table`` 可以根据需要为项目单独构建生成应用程序文件、启动引导文件和分区表文件。 -- ``make erase_flash`` 和 ``make erase_ota`` 会调用 esptool.py 脚本分别擦除整块闪存芯片或者其中 OTA 分区的内容。 +- ``make erase_flash`` 和 ``make erase_otadata`` 会调用 esptool.py 脚本分别擦除整块闪存芯片或者其中 OTA 分区的内容。 - ``make size`` 会打印应用程序的大小信息。``make size-components`` 和 ``make size-files`` 两者功能相似,分别打印每个组件或者每个源文件大小的详细信息。 调试 Make 的过程 diff --git a/docs/zh_CN/api-reference/peripherals/touch_pad.rst b/docs/zh_CN/api-reference/peripherals/touch_pad.rst index 15df578a7..2aafd02ba 100644 --- a/docs/zh_CN/api-reference/peripherals/touch_pad.rst +++ b/docs/zh_CN/api-reference/peripherals/touch_pad.rst @@ -1 +1,168 @@ -.. include:: ../../../en/api-reference/peripherals/touch_pad.rst \ No newline at end of file +触摸传感器 +============ + +:link_to_translation:`en:[English]` + +概述 +------------ + +触摸传感器系统由保护覆盖层、触摸电极、绝缘基板和走线组成,保护覆盖层位于最上层,绝缘基板上设有电极及走线。用户触摸覆盖层将产生电容变化,根据电容变化判断此次触摸是否为有效触摸行为。 + +ESP32 可支持最多 10 个电容式触摸板/GPIO,触摸板可以以矩阵或滑条等方式组合使用,从而覆盖更大触感区域及更多触感点。触摸传感由有限状态机 (FSM) 硬件控制,由软件或专用硬件计时器发起。 + +如需了解触摸传感器设计、操作及其控制寄存器等相关信息,请参考《`ESP32 技术参考手册 `_》(PDF),您也可以在《ESP32 技术参考手册》中查看这一子系统是如何运行的。 + +请参考 `触摸传感器应用方案简介 `_,查看触摸传感器设计详情和固件开发指南。如果不想亲自在多种配置环境下测试触摸传感器,请查看 `ESP32 触摸功能开发套件 `_。 + +功能介绍 +---------------------- + +下面将 API 分解成几个函数组进行介绍,帮助您快速了解以下功能: + +- 初始化触摸板驱动程序 +- 配置触摸板 GPIO 管脚 +- 触摸状态测量 +- 调整测量参数(优化测量) +- 过滤触摸测量 +- 触摸监测方式 +- 设置中断信号监测触碰动作 +- 中断触发 + +请前往 :ref:`touch_pad-api-reference` 章节,查看某一函数的具体描述。:ref:`touch_pad-api-examples` 章节则介绍了此 API 的具体实现。 + + +初始化触摸板驱动程序 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +使用触摸板之前,需要先调用 :cpp:func:`touch_pad_init` 函数初始化触摸板驱动程序。此函数设置了 :ref:`touch_pad-api-reference` 项下的 *Macros* 中列出的几项 ``.._DEFAULT`` 驱动程序参数,同时删除之前设置过的触摸板信息(如有),并禁用中断。 + +如果不再需要该驱动程序,可以调用 :cpp:func:`touch_pad_deinit` 释放已初始化的驱动程序。 + +配置触摸板 GPIO 管脚 +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +调用 :cpp:func:`touch_pad_config` 使能某一 GPIO 的触感功能。 + +使用 :cpp:func:`touch_pad_set_fsm_mode` 选择触摸板测量(由 FSM 操作)是由硬件计时器自动启动,还是由软件自动启动。如果选择软件模式,请使用 :cpp:func:`touch_pad_sw_start` 启动 FSM。 + +触摸状态测量 +^^^^^^^^^^^^^^^^^^^^^^^^ + +借助以下两个函数从传感器读取原始数据或过滤后的数据: + +* :cpp:func:`touch_pad_read` +* :cpp:func:`touch_pad_read_filtered` + +这两个函数也可以用于检查触碰和释放触摸板时传感器读数变化范围,来评估触摸板设计,然后根据这些信息设定触摸阈值。 + +.. note:: + + 使用 :cpp:func:`touch_pad_read_filtered` 之前,需要先调用 `过滤触摸测量`_ 中特定的滤波器函数初始化并配置该滤波器。 + +请参考应用示例 :example:`peripherals/touch_pad_read`,查看如何使用这两个读值函数。 + +优化测量 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +触摸传感器设有数个可配置参数,以适应触摸板设计特点。例如,如果需要感知较细微的电容变化,则可以缩小触摸板充放电的参考电压范围。您可以使用 :cpp:func:`touch_pad_set_voltage` 函数设置电压参考低值和参考高值。 + +优化测量除了可以识别细微的电容变化之外,还可以降低应用程序功耗,但可能会增加测量噪声干扰。如果得到的动态读数范围结果比较理想,则可以调用 :cpp:func:`touch_pad_set_meas_time` 函数来减少测量时间,从而进一步降低功耗。 + +可用的测量参数及相应的 'set' 函数总结如下: + +* 触摸板充放电参数: + + * 电压门限::cpp:func:`touch_pad_set_voltage` + * 速率(斜率) :cpp:func:`touch_pad_set_cnt_mode` + +* 测量时间::cpp:func:`touch_pad_set_meas_time` + +电压门限(参考低值/参考高值)、速率(斜率)与测量时间的关系如下图所示: + +.. figure:: ../../../_static/touch_pad-measurement-parameters.jpg + :align: center + :alt: Touch Pad - relationship between measurement parameters + :figclass: align-center + + 触摸板 - 测量参数之间的关系 + +上图中的 *Output* 代表触摸传感器读值,即一个测量周期内测得的脉冲计数值。 + +所有函数均成对出现,用于设定某一特定参数,并获取当前参数值。例如::cpp:func:`touch_pad_set_voltage` 和 :cpp:func:`touch_pad_get_voltage`。 + +.. _touch_pad-api-filtering-of-measurements: + +过滤触摸测量 +^^^^^^^^^^^^^^^^^^^^^^^^^ + +如果测量中存在噪声,可以使用提供的 API 函数对测量进行过滤。使用滤波器之前,请先调用 :cpp:func:`touch_pad_filter_start` 启动该滤波器。 + +滤波器类型为 IIR(无限脉冲响应滤波器),您可以调用 :cpp:func:`touch_pad_set_filter_period` 配置此类滤波器的采样周期。 + +如需停止滤波器,请调用 :cpp:func:`touch_pad_filter_stop` 函数。如果不再使用该滤波器,请调用 :cpp:func:`touch_pad_filter_delete` 删除此滤波器。 + +触摸监测 +^^^^^^^^^^^^^^^ + +触摸监测基于用户配置的阈值和 FSM 执行的原始测量,并由 ESP32 硬件实现。你可以调用 :cpp:func:`touch_pad_get_status` 查看被触碰的触摸板,或调用 :cpp:func:`touch_pad_clear_status` 清除触摸状态信息。 + +您也可以将硬件触摸监测连接至中断,详细介绍见下一章节。 + +如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议您在自己的应用程序中采用测量过滤,并执行触摸监测。请参考 :example:`peripherals/touch_pad_interrupt`,查看以上两种触摸监测的实现方式。 + +中断触发 +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +在对触摸监测启用中断之前,请先设置一个触摸监测阈值。然后使用 `触摸状态测量`_ 中所述的函数读取并显示触摸和释放触摸板时测得的结果。如果测量中存在噪声且相对电容变化较小,请使用滤波器。您也可以根据应用程序和环境条件,测试温度和电源电压变化对测量值的影响。 + +确定监测阈值后就可以在初始化时调用 :cpp:func:`touch_pad_config` 设置此阈值,或在运行时调用 :cpp:func:`touch_pad_set_thresh` 设置此阈值。 + +下一步就是设置如何触发中断。您可以设置在阈值以下或以上触发中断,具体触发模式由函数 :cpp:func:`touch_pad_set_trigger_mode` 设置。 + +最后您可以使用以下函数配置和管理中断调用: + +* :cpp:func:`touch_pad_isr_register` / :cpp:func:`touch_pad_isr_deregister` +* :cpp:func:`touch_pad_intr_enable` / :cpp:func:`touch_pad_intr_disable` + +中断配置完成后,您可以调用 :cpp:func:`touch_pad_get_status` 查看中断信号来自哪个触摸板,也可以调用 :cpp:func:`touch_pad_clear_status` 清除触摸板状态信息。 + +.. note:: + + 触摸监测中的中断信号基于原始/未经过滤的测量值(对比用户设置的阈值),并在硬件中实现。启用软件滤波 API 并不会影响这一过程,见 :ref:`touch_pad-api-filtering-of-measurements`。 + + + +从睡眠模式唤醒 +^^^^^^^^^^^^^^^^^^^^^^ + +如果使用触摸板中断将芯片从睡眠模式唤醒,您可以选择配置一些触摸板,例如 SET1 或 SET1 和 SET2,触摸这些触摸板将触发中断并唤醒芯片。请调用 :cpp:func:`touch_pad_set_trigger_source` 实现上述操作。 + +您可以使用以下函数管理 'SET' 中触摸板所需的位模式配置: + +* :cpp:func:`touch_pad_set_group_mask` / :cpp:func:`touch_pad_get_group_mask` +* :cpp:func:`touch_pad_clear_group_mask` + + +.. _touch_pad-api-examples: + +应用示例 +-------------------- + +- 触摸传感器读值示例::example:`peripherals/touch_pad_read` +- 触摸传感器中断示例::example:`peripherals/touch_pad_interrupt` + +.. _touch_pad-api-reference: + +API 参考 +------------- + +.. include:: /_build/inc/touch_pad.inc + +GPIO 宏查找表 +^^^^^^^^^^^^^^^^^^ +您可以使用宏定义某一触摸板通道的 GPIO,或定义某一 GPIO 的通道。例如: + +1. ``TOUCH_PAD_NUM5_GPIO_NUM`` 定义了通道 5 的 GPIO(即 GPIO 12); +2. ``TOUCH_PAD_GPIO4_CHANNEL`` 定义了 GPIO 4 的通道(即通道 0)。 + +.. include:: /_build/inc/touch_channel.inc diff --git a/docs/zh_CN/api-reference/storage/sdmmc.rst b/docs/zh_CN/api-reference/storage/sdmmc.rst index b2db3d718..a6d4348a0 100644 --- a/docs/zh_CN/api-reference/storage/sdmmc.rst +++ b/docs/zh_CN/api-reference/storage/sdmmc.rst @@ -1 +1,97 @@ -.. include:: ../../../en/api-reference/storage/sdmmc.rst \ No newline at end of file +SD/SDIO/MMC 驱动程序 +========================= + +:link_to_translation:`en:[English]` + +概述 +-------- + +SD/SDIO/MMC 驱动是一种基于 SDMMC 和 SD SPI 主机驱动的协议级驱动程序,目前已支持 SD 存储器、SDIO 卡和 eMMC 芯片。 + +SDMMC 主机驱动和 SD SPI 主机驱动(:component:`driver/include/driver/sdmmc_host.h`)为以下功能提供 API: + +- 发送命令至从设备 +- 接收和发送数据 +- 处理总线错误 + +初始化函数及配置函数: + +- 如需初始化和配置 SDMMC 主机,请参阅 :doc:`SDMMC 主机 API <../peripherals/sdmmc_host>` +- 如需初始化和配置 SD SPI 主机,请参阅 :doc:`SD SPI 主机 API <../peripherals/sdspi_host>` + +本文档中所述的 SDMMC 协议层仅处理 SD 协议相关事项,例如卡初始化和数据传输命令。 + +协议层通过 :cpp:class:`sdmmc_host_t` 结构体和主机协同工作,该结构体包含指向主机各类函数的指针。 + +应用示例 +------------------- + +ESP-IDF :example:`storage/sd_card` 目录下提供了 SDMMC 驱动与 FatFs 库组合使用的示例,演示了先初始化卡,然后使用 POSIX 和 C 库 API 向卡读写数据。请参考示例目录下 README.md 文件,查看更多详细信息。 + +协议层 API +------------------ + +协议层具备 :cpp:class:`sdmmc_host_t` 结构体,此结构体描述了 SD/MMC 主机驱动,列出了其功能,并提供指向驱动程序函数的指针。协议层将卡信息储存于 :cpp:class:`sdmmc_card_t` 结构体中。向 SD/MMC 主机发送命令时,协议层调用时需要一个 :cpp:class:`sdmmc_command_t` 结构体来描述命令、参数、预期返回值和需传输的数据(如有)。 + +用于 SD 存储卡的 API +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +1. 初始化主机,请调用主机驱动函数,例如 :cpp:func:`sdmmc_host_init` 和 :cpp:func:`sdmmc_host_init_slot`; +2. 初始化卡,请调用 :cpp:func:`sdmmc_card_init`,并将参数 ``host`` (即主机驱动信息)和参数 ``card`` (指向 :cpp:class:`sdmmc_card_t` 结构体的指针)传递给此函数。函数运行结束后,将会向 :cpp:class:`sdmmc_card_t` 结构体填充该卡的信息; +3. 读取或写入卡的扇区,请分别调用 :cpp:func:`sdmmc_read_sectors` 和 :cpp:func:`sdmmc_write_sectors`,并将参数 ``card`` (指向卡信息结构的指针)传递给函数; +4. 如果不再使用该卡,请调用主机驱动函数,例如 :cpp:func:`sdmmc_host_deinit`,以禁用主机外设,并释放驱动程序分配的资源。 + +用于 eMMC 芯片的 API +^^^^^^^^^^^^^^^^^^^^^^^^^ + +从协议层的角度而言,eMMC 存储芯片与 SD 存储卡相同。尽管 eMMC 是芯片,不具备卡的外形,但由于协议相似 (`sdmmc_card_t`, `sdmmc_card_init`),用于 SD 卡的一些概念同样适用于 eMMC 芯片。注意,eMMC 芯片不可通过 SPI 使用,因此它与 SD API 主机驱动不兼容。 + +如需初始化 eMMC 内存并执行读/写操作,请参照上一章节 SD 卡操作步骤。 + +用于 SDIO 卡的 API +^^^^^^^^^^^^^^^^^^^^^^^^^ + +SDIO 卡初始化和检测过程与 SD 存储卡相同,唯一的区别是 SDIO 模式下数据传输命令不同。 + +在卡初始化和卡检测(通过运行 :cpp:func:`sdmmc_card_init`)期间,驱动仅配置 SDIO 卡如下寄存器: + +1. I/O 中止 (0x06) 寄存器:在该寄存器中设置 RES 位可重置卡的 I/O 部分; +2. 总线接口控制 (0x07) 寄存器:如果主机和插槽配置中启用 4 线模式,则驱动程序会尝试在该寄存器中设置总线宽度字段。如果字段设置成功,则从机支持 4 线模式,主机也切换至 4 线模式; +3. 高速(0x13)寄存器:如果主机配置中启用高速模式,则会在该寄存器中设置 SHS 位。 + +注意,驱动程序不会在 (1) I/O 使能寄存器和 Int 使能寄存器,及 (2) I/O 块大小中,设置任何位。应用程序可通过调用 :cpp:func:`sdmmc_io_write_byte` 来设置相关位。 + +如需设置卡配置或传输数据,请根据您的具体情况选择下表中的函数: + +========================================================================= ================================= ================================= +操作 读函数 写函数 +========================================================================= ================================= ================================= +使用 IO_RW_DIRECT (CMD52) 读写单个字节。 :cpp:func:`sdmmc_io_read_byte` :cpp:func:`sdmmc_io_write_byte` +使用 IO_RW_EXTENDED (CMD53) 的字节模式读写多个字节。 :cpp:func:`sdmmc_io_read_bytes` :cpp:func:`sdmmc_io_write_bytes` +块模式下,使用 IO_RW_EXTENDED (CMD53) 读写数据块。 :cpp:func:`sdmmc_io_read_blocks` :cpp:func:`sdmmc_io_write_blocks` +========================================================================= ================================= ================================= + +使用 :cpp:func:`sdmmc_io_enable_int` 函数,应用程序可启用 SDIO 中断。 + +在单线模式下使用 SDIO 时,还需要连接 D1 线来启用 SDIO 中断。 + +如果您需要应用程序保持等待直至发生 SDIO 中断,请使用 :cpp:func:`sdmmc_io_wait_int` 函数。 + + +复合卡(存储 + SDIO) +^^^^^^^^^^^^^^^^^^^^^^^^^ + +该驱动程序不支持 SDIO 复合卡,复合卡会被视为 SDIO 卡。 + + +线程安全 +^^^^^^^^^^^^^ + +多数应用程序仅需在一个任务中使用协议层。因此,协议层在 :cpp:class:`sdmmc_card_t` 结构体或在访问 SDMMC 或 SD SPI 主机驱动程序时不使用任何类型的锁。这种锁通常在较高层级实现,例如文件系统驱动程序。 + +API 参考 +------------- + +.. include:: /_build/inc/sdmmc_cmd.inc + +.. include:: /_build/inc/sdmmc_types.inc \ No newline at end of file diff --git a/docs/zh_CN/versions.rst b/docs/zh_CN/versions.rst index 31ba158ea..457235342 100644 --- a/docs/zh_CN/versions.rst +++ b/docs/zh_CN/versions.rst @@ -57,10 +57,9 @@ ESP-IDF 采用了 `语义版本管理方法 `_,即您可 查看当前版本 ---------------------------- -查看 ESP-IDF 本地副本的版本,请使用 git 命令:: +查看 ESP-IDF 本地副本的版本,请使用 idf.py 命令:: - cd $IDF_PATH - git describe --tags --dirty + idf.py --version 此外,由于 ESP-IDF 的版本也已编译至固件中,因此您也可以使用宏 ``IDF_VER`` 查看 ESP-IDF 的版本(以字符串的格式)。ESP-IDF 默认引导程序可以在设备启动时打印 ESP-IDF 的版本,但注意代码中的版本信息仅会在源代码重新编译时才会更新,因此打印出来的版本可能并不是最新的。 diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_client_model/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_client_model/sdkconfig.defaults index 0be67101d..de589ddff 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_client_model/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_client_model/sdkconfig.defaults @@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_BLE_MESH=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults index 1a9c02e1b..2ccd3d921 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults @@ -15,7 +15,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_BLE_MESH=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults index cf11fdcc8..12861bdab 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults @@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_BLE_MESH=y CONFIG_BLE_MESH_HCI_5_0=y CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults index 22854582c..c0df56a4f 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults @@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_BLE_MESH=y CONFIG_BLE_MESH_HCI_5_0=y CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults index 5118ab757..d32424124 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults @@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_BLE_MESH=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/sdkconfig.defaults index 292c41a32..3932dab57 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/sdkconfig.defaults @@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_BLE_MESH=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/sdkconfig.defaults index ae512edd8..ac2cefedb 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/sdkconfig.defaults @@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_BLE_MESH=y CONFIG_BLE_MESH_HCI_5_0=y CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults index 214f15eb6..20e18a588 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults @@ -16,7 +16,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n +CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_BLE_MESH=y diff --git a/examples/bluetooth/nimble/blecent/blecent_test_noci.py b/examples/bluetooth/nimble/blecent/blecent_test.py similarity index 98% rename from examples/bluetooth/nimble/blecent/blecent_test_noci.py rename to examples/bluetooth/nimble/blecent/blecent_test.py index a30579735..eabe8df26 100644 --- a/examples/bluetooth/nimble/blecent/blecent_test_noci.py +++ b/examples/bluetooth/nimble/blecent/blecent_test.py @@ -65,6 +65,8 @@ def test_example_app_ble_central(env, extra_data): adv_type = 'peripheral' adv_uuid = '1811' + subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*']) + subprocess.check_output(['hciconfig','hci0','reset']) # Acquire DUT dut = env.get_dut("blecent", "examples/bluetooth/nimble/blecent", dut_class=ESP32DUT) @@ -76,8 +78,8 @@ def test_example_app_ble_central(env, extra_data): # Upload binary and start testing Utility.console_log("Starting blecent example test app") dut.start_app() + dut.reset() - subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*']) device_addr = ':'.join(re.findall('..', '%012x' % uuid.getnode())) # Get BLE client module diff --git a/examples/bluetooth/nimble/blehr/blehr_test_noci.py b/examples/bluetooth/nimble/blehr/blehr_test.py similarity index 59% rename from examples/bluetooth/nimble/blehr/blehr_test_noci.py rename to examples/bluetooth/nimble/blehr/blehr_test.py index 76cf2d402..7ba871a73 100644 --- a/examples/bluetooth/nimble/blehr/blehr_test_noci.py +++ b/examples/bluetooth/nimble/blehr/blehr_test.py @@ -18,7 +18,9 @@ from __future__ import print_function import os import sys import re -from threading import Thread +import threading +import traceback +import Queue import subprocess try: @@ -52,7 +54,7 @@ import Utility # > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw -def blehr_client_task(dut_addr, dut): +def blehr_client_task(hr_obj, dut_addr): interface = 'hci0' ble_devname = 'blehr_sensor_1.0' hr_srv_uuid = '180d' @@ -71,20 +73,18 @@ def blehr_client_task(dut_addr, dut): # Connect BLE Device is_connected = ble_client_obj.connect() if not is_connected: - Utility.console_log("Connection to device ", ble_devname, "failed !!") # Call disconnect to perform cleanup operations before exiting application ble_client_obj.disconnect() - return + raise RuntimeError("Connection to device " + str(ble_devname) + " failed !!") # Read Services services_ret = ble_client_obj.get_services() if services_ret: - print("\nServices\n") - print(services_ret) + Utility.console_log("\nServices\n") + Utility.console_log(str(services_ret)) else: - print("Failure: Read Services failed") ble_client_obj.disconnect() - return + raise RuntimeError("Failure: Read Services failed") ''' Blehr application run: @@ -94,14 +94,27 @@ def blehr_client_task(dut_addr, dut): ''' blehr_ret = ble_client_obj.hr_update_simulation(hr_srv_uuid, hr_char_uuid) if blehr_ret: - print("Success: blehr example test passed") + Utility.console_log("Success: blehr example test passed") else: - print("Failure: blehr example test failed") + raise RuntimeError("Failure: blehr example test failed") # Call disconnect to perform cleanup operations before exiting application ble_client_obj.disconnect() +class BleHRThread(threading.Thread): + def __init__(self, dut_addr, exceptions_queue): + threading.Thread.__init__(self) + self.dut_addr = dut_addr + self.exceptions_queue = exceptions_queue + + def run(self): + try: + blehr_client_task(self, self.dut_addr) + except Exception: + self.exceptions_queue.put(traceback.format_exc(), block=False) + + @IDF.idf_example_test(env_tag="Example_WIFI_BT") def test_example_app_ble_hr(env, extra_data): """ @@ -112,38 +125,47 @@ def test_example_app_ble_hr(env, extra_data): 4. Updated value is retrieved 5. Stop Notifications """ - try: - # Acquire DUT - dut = env.get_dut("blehr", "examples/bluetooth/nimble/blehr", dut_class=ESP32DUT) + subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*']) + subprocess.check_output(['hciconfig','hci0','reset']) - # Get binary file - binary_file = os.path.join(dut.app.binary_path, "blehr.bin") - bin_size = os.path.getsize(binary_file) - IDF.log_performance("blehr_bin_size", "{}KB".format(bin_size // 1024)) - IDF.check_performance("blehr_bin_size", bin_size // 1024) + # Acquire DUT + dut = env.get_dut("blehr", "examples/bluetooth/nimble/blehr") - # Upload binary and start testing - Utility.console_log("Starting blehr simple example test app") - dut.start_app() + # Get binary file + binary_file = os.path.join(dut.app.binary_path, "blehr.bin") + bin_size = os.path.getsize(binary_file) + IDF.log_performance("blehr_bin_size", "{}KB".format(bin_size // 1024)) + IDF.check_performance("blehr_bin_size", bin_size // 1024) - subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*']) + # Upload binary and start testing + Utility.console_log("Starting blehr simple example test app") + dut.start_app() + dut.reset() - # Get device address from dut - dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0] + # Get device address from dut + dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0] + exceptions_queue = Queue.Queue() + # Starting a py-client in a separate thread + blehr_thread_obj = BleHRThread(dut_addr, exceptions_queue) + blehr_thread_obj.start() + blehr_thread_obj.join() - # Starting a py-client in a separate thread - thread1 = Thread(target=blehr_client_task, args=(dut_addr,dut,)) - thread1.start() - thread1.join() + exception_msg = None + while True: + try: + exception_msg = exceptions_queue.get(block=False) + except Queue.Empty: + break + else: + Utility.console_log("\n" + exception_msg) - # Check dut responses - dut.expect("subscribe event; cur_notify=1", timeout=30) - dut.expect("GATT procedure initiated: notify;", timeout=30) - dut.expect("subscribe event; cur_notify=0", timeout=30) - dut.expect("disconnect;", timeout=30) + if exception_msg: + raise Exception("Thread did not run successfully") - except Exception as e: - sys.exit(e) + # Check dut responses + dut.expect("subscribe event; cur_notify=1", timeout=30) + dut.expect("subscribe event; cur_notify=0", timeout=30) + dut.expect("disconnect;", timeout=30) if __name__ == '__main__': diff --git a/examples/bluetooth/nimble/bleprph/bleprph_test_noci.py b/examples/bluetooth/nimble/bleprph/bleprph_test.py similarity index 57% rename from examples/bluetooth/nimble/bleprph/bleprph_test_noci.py rename to examples/bluetooth/nimble/bleprph/bleprph_test.py index 0a1a1aa62..b4ea5aca8 100644 --- a/examples/bluetooth/nimble/bleprph/bleprph_test_noci.py +++ b/examples/bluetooth/nimble/bleprph/bleprph_test.py @@ -18,7 +18,9 @@ from __future__ import print_function import os import sys import re -from threading import Thread +import Queue +import traceback +import threading import subprocess try: @@ -51,7 +53,7 @@ import Utility # > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw -def bleprph_client_task(dut_addr, dut): +def bleprph_client_task(prph_obj, dut, dut_addr): interface = 'hci0' ble_devname = 'nimble-bleprph' srv_uuid = '2f12' @@ -69,10 +71,9 @@ def bleprph_client_task(dut_addr, dut): # Connect BLE Device is_connected = ble_client_obj.connect() if not is_connected: - Utility.console_log("Connection to device ", ble_devname, "failed !!") # Call disconnect to perform cleanup operations before exiting application ble_client_obj.disconnect() - return + raise RuntimeError("Connection to device " + ble_devname + " failed !!") # Check dut responses dut.expect("GAP procedure initiated: advertise;", timeout=30) @@ -80,12 +81,11 @@ def bleprph_client_task(dut_addr, dut): # Read Services services_ret = ble_client_obj.get_services(srv_uuid) if services_ret: - print("\nServices\n") - print(services_ret) + Utility.console_log("\nServices\n") + Utility.console_log(str(services_ret)) else: - print("Failure: Read Services failed") ble_client_obj.disconnect() - return + raise RuntimeError("Failure: Read Services failed") # Read Characteristics chars_ret = {} @@ -93,14 +93,13 @@ def bleprph_client_task(dut_addr, dut): if chars_ret: Utility.console_log("\nCharacteristics retrieved") for path, props in chars_ret.items(): - print("\n\tCharacteristic: ", path) - print("\tCharacteristic UUID: ", props[2]) - print("\tValue: ", props[0]) - print("\tProperties: : ", props[1]) + Utility.console_log("\n\tCharacteristic: " + str(path)) + Utility.console_log("\tCharacteristic UUID: " + str(props[2])) + Utility.console_log("\tValue: " + str(props[0])) + Utility.console_log("\tProperties: : " + str(props[1])) else: - print("Failure: Read Characteristics failed") ble_client_obj.disconnect() - return + raise RuntimeError("Failure: Read Characteristics failed") ''' Write Characteristics @@ -111,19 +110,32 @@ def bleprph_client_task(dut_addr, dut): if chars_ret_on_write: Utility.console_log("\nCharacteristics after write operation") for path, props in chars_ret_on_write.items(): - print("\n\tCharacteristic:", path) - print("\tCharacteristic UUID: ", props[2]) - print("\tValue:", props[0]) - print("\tProperties: : ", props[1]) + Utility.console_log("\n\tCharacteristic:" + str(path)) + Utility.console_log("\tCharacteristic UUID: " + str(props[2])) + Utility.console_log("\tValue:" + str(props[0])) + Utility.console_log("\tProperties: : " + str(props[1])) else: - print("Failure: Write Characteristics failed") ble_client_obj.disconnect() - return + raise RuntimeError("Failure: Write Characteristics failed") # Call disconnect to perform cleanup operations before exiting application ble_client_obj.disconnect() +class BlePrphThread(threading.Thread): + def __init__(self, dut, dut_addr, exceptions_queue): + threading.Thread.__init__(self) + self.dut = dut + self.dut_addr = dut_addr + self.exceptions_queue = exceptions_queue + + def run(self): + try: + bleprph_client_task(self, self.dut, self.dut_addr) + except Exception: + self.exceptions_queue.put(traceback.format_exc(), block=False) + + @IDF.idf_example_test(env_tag="Example_WIFI_BT") def test_example_app_ble_peripheral(env, extra_data): """ @@ -134,36 +146,47 @@ def test_example_app_ble_peripheral(env, extra_data): 4. Read Characteristics 5. Write Characteristics """ - try: + subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*']) + subprocess.check_output(['hciconfig','hci0','reset']) - # Acquire DUT - dut = env.get_dut("bleprph", "examples/bluetooth/nimble/bleprph", dut_class=ESP32DUT) + # Acquire DUT + dut = env.get_dut("bleprph", "examples/bluetooth/nimble/bleprph") - # Get binary file - binary_file = os.path.join(dut.app.binary_path, "bleprph.bin") - bin_size = os.path.getsize(binary_file) - IDF.log_performance("bleprph_bin_size", "{}KB".format(bin_size // 1024)) - IDF.check_performance("bleprph_bin_size", bin_size // 1024) + # Get binary file + binary_file = os.path.join(dut.app.binary_path, "bleprph.bin") + bin_size = os.path.getsize(binary_file) + IDF.log_performance("bleprph_bin_size", "{}KB".format(bin_size // 1024)) + IDF.check_performance("bleprph_bin_size", bin_size // 1024) - # Upload binary and start testing - Utility.console_log("Starting bleprph simple example test app") - dut.start_app() + # Upload binary and start testing + Utility.console_log("Starting bleprph simple example test app") + dut.start_app() + dut.reset() - subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*']) + # Get device address from dut + dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0] - # Get device address from dut - dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0] + exceptions_queue = Queue.Queue() + # Starting a py-client in a separate thread + bleprph_thread_obj = BlePrphThread(dut, dut_addr, exceptions_queue) + bleprph_thread_obj.start() + bleprph_thread_obj.join() - # Starting a py-client in a separate thread - thread1 = Thread(target=bleprph_client_task, args=(dut_addr,dut,)) - thread1.start() - thread1.join() + exception_msg = None + while True: + try: + exception_msg = exceptions_queue.get(block=False) + except Queue.Empty: + break + else: + Utility.console_log("\n" + exception_msg) - # Check dut responses - dut.expect("connection established; status=0", timeout=30) - dut.expect("disconnect;", timeout=30) - except Exception as e: - sys.exit(e) + if exception_msg: + raise Exception("Thread did not run successfully") + + # Check dut responses + dut.expect("connection established; status=0", timeout=30) + dut.expect("disconnect;", timeout=30) if __name__ == '__main__': diff --git a/examples/mesh/internal_communication/main/mesh_light.c b/examples/mesh/internal_communication/main/mesh_light.c index b64c01fb9..7c0e94386 100644 --- a/examples/mesh/internal_communication/main/mesh_light.c +++ b/examples/mesh/internal_communication/main/mesh_light.c @@ -39,7 +39,7 @@ esp_err_t mesh_light_init(void) s_light_inited = true; ledc_timer_config_t ledc_timer = { - .bit_num = LEDC_TIMER_13_BIT, + .duty_resolution = LEDC_TIMER_13_BIT, .freq_hz = 5000, .speed_mode = LEDC_LOW_SPEED_MODE, .timer_num = LEDC_TIMER_0, diff --git a/examples/mesh/manual_networking/main/mesh_light.c b/examples/mesh/manual_networking/main/mesh_light.c index 2ebed91a5..c9bbfc59b 100644 --- a/examples/mesh/manual_networking/main/mesh_light.c +++ b/examples/mesh/manual_networking/main/mesh_light.c @@ -39,7 +39,7 @@ esp_err_t mesh_light_init(void) s_light_inited = true; ledc_timer_config_t ledc_timer = { - .bit_num = LEDC_TIMER_13_BIT, + .duty_resolution = LEDC_TIMER_13_BIT, .freq_hz = 5000, .speed_mode = LEDC_LOW_SPEED_MODE, .timer_num = LEDC_TIMER_0, diff --git a/examples/protocols/http_request/main/http_request_example_main.c b/examples/protocols/http_request/main/http_request_example_main.c index 5626ae796..12621e06a 100644 --- a/examples/protocols/http_request/main/http_request_example_main.c +++ b/examples/protocols/http_request/main/http_request_example_main.c @@ -24,13 +24,13 @@ /* Constants that aren't configurable in menuconfig */ #define WEB_SERVER "example.com" -#define WEB_PORT 80 -#define WEB_URL "http://example.com/" +#define WEB_PORT "80" +#define WEB_PATH "/" static const char *TAG = "example"; -static const char *REQUEST = "GET " WEB_URL " HTTP/1.0\r\n" - "Host: "WEB_SERVER"\r\n" +static const char *REQUEST = "GET " WEB_PATH " HTTP/1.0\r\n" + "Host: "WEB_SERVER":"WEB_PORT"\r\n" "User-Agent: esp-idf/1.0 esp32\r\n" "\r\n"; @@ -46,7 +46,7 @@ static void http_get_task(void *pvParameters) char recv_buf[64]; while(1) { - int err = getaddrinfo(WEB_SERVER, "80", &hints, &res); + int err = getaddrinfo(WEB_SERVER, WEB_PORT, &hints, &res); if(err != 0 || res == NULL) { ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res); diff --git a/make/project.mk b/make/project.mk index e146acc42..4c5935b07 100644 --- a/make/project.mk +++ b/make/project.mk @@ -417,12 +417,22 @@ endif endif # Optimization flags are set based on menuconfig choice -ifdef CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE +ifdef CONFIG_COMPILER_OPTIMIZATION_SIZE OPTIMIZATION_FLAGS = -Os -freorder-blocks -else +endif + +ifdef CONFIG_COMPILER_OPTIMIZATION_DEFAULT OPTIMIZATION_FLAGS = -Og endif +ifdef CONFIG_COMPILER_OPTIMIZATION_NONE +OPTIMIZATION_FLAGS = -O0 +endif + +ifdef CONFIG_COMPILER_OPTIMIZATION_PERF +OPTIMIZATION_FLAGS = -O2 +endif + ifdef CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE CPPFLAGS += -DNDEBUG endif diff --git a/sdkconfig.rename b/sdkconfig.rename index 6ff0f5747..1440ae6e6 100644 --- a/sdkconfig.rename +++ b/sdkconfig.rename @@ -7,20 +7,22 @@ CONFIG_PYTHON CONFIG_SDK_PYTHON CONFIG_MAKE_WARN_UNDEFINED_VARIABLES CONFIG_SDK_MAKE_WARN_UNDEFINED_VARIABLES # Compiler options -CONFIG_OPTIMIZATION_COMPILER CONFIG_COMPILER_OPTIMIZATION -CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG -CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE -CONFIG_OPTIMIZATION_ASSERTION_LEVEL CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL -CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE -CONFIG_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT -CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE -CONFIG_CXX_EXCEPTIONS CONFIG_COMPILER_CXX_EXCEPTIONS -CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE -CONFIG_STACK_CHECK_MODE CONFIG_COMPILER_STACK_CHECK_MODE -CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE -CONFIG_STACK_CHECK_NORM CONFIG_COMPILER_STACK_CHECK_MODE_NORM -CONFIG_STACK_CHECK_STRONG CONFIG_COMPILER_STACK_CHECK_MODE_STRONG -CONFIG_STACK_CHECK_ALL CONFIG_COMPILER_STACK_CHECK_MODE_ALL -CONFIG_STACK_CHECK CONFIG_COMPILER_STACK_CHECK -CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS -CONFIG_DISABLE_GCC8_WARNINGS CONFIG_COMPILER_DISABLE_GCC8_WARNINGS +CONFIG_OPTIMIZATION_COMPILER CONFIG_COMPILER_OPTIMIZATION +CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT +CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE +CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT +CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE +CONFIG_OPTIMIZATION_ASSERTION_LEVEL CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL +CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE +CONFIG_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT +CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE +CONFIG_CXX_EXCEPTIONS CONFIG_COMPILER_CXX_EXCEPTIONS +CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE +CONFIG_STACK_CHECK_MODE CONFIG_COMPILER_STACK_CHECK_MODE +CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE +CONFIG_STACK_CHECK_NORM CONFIG_COMPILER_STACK_CHECK_MODE_NORM +CONFIG_STACK_CHECK_STRONG CONFIG_COMPILER_STACK_CHECK_MODE_STRONG +CONFIG_STACK_CHECK_ALL CONFIG_COMPILER_STACK_CHECK_MODE_ALL +CONFIG_STACK_CHECK CONFIG_COMPILER_STACK_CHECK +CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS +CONFIG_DISABLE_GCC8_WARNINGS CONFIG_COMPILER_DISABLE_GCC8_WARNINGS \ No newline at end of file diff --git a/tools/ble/lib_ble_client.py b/tools/ble/lib_ble_client.py index 3cbec0370..6fda14288 100644 --- a/tools/ble/lib_ble_client.py +++ b/tools/ble/lib_ble_client.py @@ -20,6 +20,7 @@ from __future__ import print_function import sys import time +import traceback try: from future.moves.itertools import zip_longest @@ -39,11 +40,11 @@ import lib_gap srv_added_old_cnt = 0 srv_added_new_cnt = 0 +verify_signal_check = 0 blecent_retry_check_cnt = 0 verify_service_cnt = 0 verify_readchars_cnt = 0 blecent_adv_uuid = '1811' -iface_added = False gatt_app_obj_check = False gatt_app_reg_check = False adv_data_check = False @@ -54,6 +55,7 @@ subscribe_req_check = False ble_hr_chrc = False DISCOVERY_START = False +SIGNAL_CAUGHT = False TEST_CHECKS_PASS = False ADV_STOP = False @@ -89,26 +91,42 @@ dbus.mainloop.glib.threads_init() event_loop = GLib.MainLoop() +def verify_signal_is_caught(): + global verify_signal_check + verify_signal_check += 1 + + if (not SIGNAL_CAUGHT and verify_signal_check == 15) or (SIGNAL_CAUGHT): + if event_loop.is_running(): + event_loop.quit() + return False # polling for checks will stop + + return True # polling will continue + + def set_props_status(props): """ Set Adapter status if it is powered on or off """ global ADAPTER_ON, SERVICES_RESOLVED, GATT_OBJ_REMOVED, GATT_APP_REGISTERED, \ - ADV_REGISTERED, ADV_ACTIVE_INSTANCE, DEVICE_CONNECTED, CHRC_VALUE, CHRC_VALUE_CNT + ADV_REGISTERED, ADV_ACTIVE_INSTANCE, DEVICE_CONNECTED, CHRC_VALUE, CHRC_VALUE_CNT, \ + SIGNAL_CAUGHT is_service_uuid = False # Signal caught for change in Adapter Powered property if 'Powered' in props: if props['Powered'] == 1: + SIGNAL_CAUGHT = True ADAPTER_ON = True else: + SIGNAL_CAUGHT = True ADAPTER_ON = False - event_loop.quit() - elif 'ServicesResolved' in props: + if 'ServicesResolved' in props: if props['ServicesResolved'] == 1: + SIGNAL_CAUGHT = True SERVICES_RESOLVED = True else: + SIGNAL_CAUGHT = True SERVICES_RESOLVED = False - elif 'UUIDs' in props: + if 'UUIDs' in props: # Signal caught for add/remove GATT data having service uuid for uuid in props['UUIDs']: if blecent_adv_uuid in uuid: @@ -118,7 +136,7 @@ def set_props_status(props): # and for unregistering GATT application GATT_APP_REGISTERED = False lib_gatt.GATT_APP_OBJ = False - elif 'ActiveInstances' in props: + if 'ActiveInstances' in props: # Signal caught for Advertising - add/remove Instances property if props['ActiveInstances'] == 1: ADV_ACTIVE_INSTANCE = True @@ -126,20 +144,24 @@ def set_props_status(props): ADV_ACTIVE_INSTANCE = False ADV_REGISTERED = False lib_gap.ADV_OBJ = False - elif 'Connected' in props: + if 'Connected' in props: # Signal caught for device connect/disconnect - if props['Connected'] is True: + if props['Connected'] == 1: + SIGNAL_CAUGHT = True DEVICE_CONNECTED = True - event_loop.quit() else: + SIGNAL_CAUGHT = True DEVICE_CONNECTED = False - elif 'Value' in props: + if 'Value' in props: # Signal caught for change in chars value if ble_hr_chrc: CHRC_VALUE_CNT += 1 print(props['Value']) if CHRC_VALUE_CNT == 10: - event_loop.quit() + SIGNAL_CAUGHT = True + return False + + return False def props_change_handler(iface, changed_props, invalidated): @@ -194,6 +216,9 @@ class BLE_Bluez_Client: Discover Bluetooth Adapter Power On Bluetooth Adapter ''' + global verify_signal_check, SIGNAL_CAUGHT, ADAPTER_ON + verify_signal_check = 0 + ADAPTER_ON = False try: print("discovering adapter...") for path, interfaces in self.ble_objs.items(): @@ -209,45 +234,45 @@ class BLE_Bluez_Client: break if self.adapter is None: - raise RuntimeError("\nError: bluetooth adapter not found") + raise Exception("Bluetooth adapter not found") if self.props_iface_obj is None: - raise RuntimeError("\nError: properties interface not found") + raise Exception("Properties interface not found") print("bluetooth adapter discovered") - self.props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) - # Check if adapter is already powered on if ADAPTER_ON: - print("bluetooth adapter is already on") + print("Adapter already powered on") return True # Power On Adapter print("powering on adapter...") + self.props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) self.props_iface_obj.Set(ADAPTER_IFACE, "Powered", dbus.Boolean(1)) + SIGNAL_CAUGHT = False + GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() if ADAPTER_ON: print("bluetooth adapter powered on") return True else: - print("Failure: bluetooth adapter not powered on") - return False + raise Exception("Failure: bluetooth adapter not powered on") - except Exception as e: - print(e) - sys.exit(1) + except Exception: + print(traceback.format_exc()) + return False def connect(self): ''' Connect to the device discovered Retry 10 times to discover and connect to device ''' - global DISCOVERY_START - + global DISCOVERY_START, SIGNAL_CAUGHT, DEVICE_CONNECTED, verify_signal_check device_found = False + DEVICE_CONNECTED = False try: self.adapter.StartDiscovery() print("\nStarted Discovery") @@ -255,6 +280,7 @@ class BLE_Bluez_Client: DISCOVERY_START = True for retry_cnt in range(10,0,-1): + verify_signal_check = 0 try: if self.device is None: print("\nConnecting to device...") @@ -263,9 +289,15 @@ class BLE_Bluez_Client: device_found = self.get_device() if device_found: self.device.Connect(dbus_interface=DEVICE_IFACE) - event_loop.quit() - print("\nConnected to device") - return True + time.sleep(15) + SIGNAL_CAUGHT = False + GLib.timeout_add_seconds(5, verify_signal_is_caught) + event_loop.run() + if DEVICE_CONNECTED: + print("\nConnected to device") + return True + else: + raise Exception except Exception as e: print(e) print("\nRetries left", retry_cnt - 1) @@ -274,8 +306,8 @@ class BLE_Bluez_Client: # Device not found return False - except Exception as e: - print(e) + except Exception: + print(traceback.format_exc()) self.device = None return False @@ -299,8 +331,7 @@ class BLE_Bluez_Client: break if dev_path is None: - print("\nBLE device not found") - return False + raise Exception("\nBLE device not found") device_props_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, dev_path), DBUS_PROP_IFACE) device_props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) @@ -321,16 +352,7 @@ class BLE_Bluez_Client: if path not in self.services: self.services.append(path) - def verify_get_services(self): - global SERVICE_SCAN_FAIL, verify_service_cnt - verify_service_cnt += 1 - if iface_added and self.services and SERVICES_RESOLVED: - event_loop.quit() - - if verify_service_cnt == 10: - event_loop.quit() - - def verify_service_uuid_found(self): + def verify_service_uuid_found(self, service_uuid): ''' Verify service uuid found ''' @@ -340,40 +362,45 @@ class BLE_Bluez_Client: if srv_uuid_found: SERVICE_UUID_FOUND = True - def get_services(self, srv_uuid=None): + def get_services(self, service_uuid=None): ''' Retrieve Services found in the device connected ''' - global service_uuid, iface_added, SERVICE_UUID_FOUND - service_uuid = srv_uuid - iface_added = False + global SIGNAL_CAUGHT, SERVICE_UUID_FOUND, SERVICES_RESOLVED, verify_signal_check + verify_signal_check = 0 SERVICE_UUID_FOUND = False + SERVICES_RESOLVED = False + SIGNAL_CAUGHT = False + try: om_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, "/"), DBUS_OM_IFACE) self.ble_objs = om_iface_obj.GetManagedObjects() - for path, interfaces in self.ble_objs.items(): self.srvc_iface_added_handler(path, interfaces) # If services not found, then they may not have been added yet on dbus if not self.services: - iface_added = True - GLib.timeout_add_seconds(2, self.verify_get_services) + GLib.timeout_add_seconds(5, verify_signal_is_caught) om_iface_obj.connect_to_signal('InterfacesAdded', self.srvc_iface_added_handler) event_loop.run() + if not SERVICES_RESOLVED: + raise Exception("Services not found...") + if service_uuid: - self.verify_service_uuid_found() + self.verify_service_uuid_found(service_uuid) if not SERVICE_UUID_FOUND: - raise Exception("Service with uuid: %s not found !!!" % service_uuid) + raise Exception("Service with uuid: %s not found..." % service_uuid) + + # Services found return self.srv_uuid - except Exception as e: - print("Error: ", e) + except Exception: + print(traceback.format_exc()) return False def chrc_iface_added_handler(self, path, interfaces): ''' Add services found as lib_ble_client obj ''' - global chrc, chrc_discovered + global chrc, chrc_discovered, SIGNAL_CAUGHT chrc_val = None if self.device and path.startswith(self.device.object_path): @@ -386,22 +413,17 @@ class BLE_Bluez_Client: chrc_val = chrc.ReadValue({}, dbus_interface=GATT_CHRC_IFACE) uuid = chrc_props['UUID'] self.chars[path] = chrc_val, chrc_flags, uuid - - def verify_get_chars(self): - global verify_readchars_cnt - verify_readchars_cnt += 1 - if iface_added and self.chars: - event_loop.quit() - if verify_readchars_cnt == 10: - event_loop.quit() + SIGNAL_CAUGHT = True def read_chars(self): ''' Read characteristics found in the device connected ''' - global iface_added, chrc_discovered + global iface_added, chrc_discovered, SIGNAL_CAUGHT, verify_signal_check + verify_signal_check = 0 chrc_discovered = False iface_added = False + SIGNAL_CAUGHT = False try: om_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, "/"), DBUS_OM_IFACE) @@ -410,14 +432,15 @@ class BLE_Bluez_Client: self.chrc_iface_added_handler(path, interfaces) # If chars not found, then they have not been added yet to interface + time.sleep(15) if not self.chars: iface_added = True - GLib.timeout_add_seconds(2, self.verify_get_chars) + GLib.timeout_add_seconds(5, verify_signal_is_caught) om_iface_obj.connect_to_signal('InterfacesAdded', self.chars_iface_added_handler) event_loop.run() return self.chars - except Exception as e: - print("Error: ", e) + except Exception: + print(traceback.format_exc()) return False def write_chars(self, write_val): @@ -443,12 +466,11 @@ class BLE_Bluez_Client: return False self.chars[path] = chrc_val, props[1], props[2] # update value if not char_write_props: - print("Failure: Cannot perform write operation. Characteristic does not have write permission.") - return False + raise Exception("Failure: Cannot perform write operation. Characteristic does not have write permission.") return self.chars - except Exception as e: - print(e) + except Exception: + print(traceback.format_exc()) return False def hr_update_simulation(self, hr_srv_uuid, hr_char_uuid): @@ -457,7 +479,7 @@ class BLE_Bluez_Client: Retrieve updated value Stop Notifications ''' - global ble_hr_chrc + global ble_hr_chrc, verify_signal_check, SIGNAL_CAUGHT, CHRC_VALUE_CNT srv_path = None chrc = None @@ -465,6 +487,7 @@ class BLE_Bluez_Client: chrc_path = None chars_ret = None ble_hr_chrc = True + CHRC_VALUE_CNT = 0 try: # Get HR Measurement characteristic @@ -475,8 +498,7 @@ class BLE_Bluez_Client: break if srv_path is None: - print("Failure: HR UUID:", hr_srv_uuid, "not found") - return False + raise Exception("Failure: HR UUID:", hr_srv_uuid, "not found") chars_ret = self.read_chars() @@ -487,8 +509,8 @@ class BLE_Bluez_Client: if hr_char_uuid in props[2]: # uuid break if chrc is None: - print("Failure: Characteristics for service: ", srv_path, "not found") - return False + raise Exception("Failure: Characteristics for service: ", srv_path, "not found") + # Subscribe to notifications print("\nSubscribe to notifications: On") chrc.StartNotify(dbus_interface=GATT_CHRC_IFACE) @@ -496,6 +518,9 @@ class BLE_Bluez_Client: chrc_props_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, chrc_path), DBUS_PROP_IFACE) chrc_props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) + SIGNAL_CAUGHT = False + verify_signal_check = 0 + GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() chrc.StopNotify(dbus_interface=GATT_CHRC_IFACE) time.sleep(2) @@ -504,8 +529,8 @@ class BLE_Bluez_Client: ble_hr_chrc = False return True - except Exception as e: - print(e) + except Exception: + print(traceback.format_exc()) return False def create_gatt_app(self): @@ -513,10 +538,12 @@ class BLE_Bluez_Client: Create GATT data Register GATT Application ''' - global gatt_app_obj, gatt_manager_iface_obj + global gatt_app_obj, gatt_manager_iface_obj, GATT_APP_REGISTERED gatt_app_obj = None gatt_manager_iface_obj = None + GATT_APP_REGISTERED = False + lib_gatt.GATT_APP_OBJ = False try: gatt_app_obj = lib_gatt.Application(self.bus, self.adapter_path[0]) @@ -526,8 +553,8 @@ class BLE_Bluez_Client: reply_handler=self.gatt_app_handler, error_handler=self.gatt_app_error_handler) return True - except Exception as e: - print(e) + except Exception: + print(traceback.format_exc()) return False def gatt_app_handler(self): @@ -550,25 +577,28 @@ class BLE_Bluez_Client: Register Advertisement Start Advertising ''' - global le_adv_obj, le_adv_manager_iface_obj + global le_adv_obj, le_adv_manager_iface_obj, ADV_ACTIVE_INSTANCE, ADV_REGISTERED + le_adv_obj = None le_adv_manager_iface_obj = None le_adv_iface_path = None + ADV_ACTIVE_INSTANCE = False + ADV_REGISTERED = False + lib_gap.ADV_OBJ = False try: print("Advertising started") gatt_app_ret = self.create_gatt_app() if not gatt_app_ret: - return False + raise Exception for path,interface in self.ble_objs.items(): if LE_ADVERTISING_MANAGER_IFACE in interface: le_adv_iface_path = path if le_adv_iface_path is None: - print('\n Cannot start advertising. LEAdvertisingManager1 Interface not found') - return False + raise Exception('\n Cannot start advertising. LEAdvertisingManager1 Interface not found') le_adv_obj = lib_gap.Advertisement(self.bus, adv_iface_index, adv_type, adv_uuid, adv_host_name) le_adv_manager_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, le_adv_iface_path), LE_ADVERTISING_MANAGER_IFACE) @@ -583,11 +613,10 @@ class BLE_Bluez_Client: if TEST_CHECKS_PASS: return True else: - return False + raise Exception - except Exception as e: - print("in Exception") - print(e) + except Exception: + print(traceback.format_exc()) return False def adv_handler(self): @@ -646,39 +675,41 @@ class BLE_Bluez_Client: TEST_CHECKS_PASS = False if subscribe_req_check: lib_gatt.alert_status_char_obj.StopNotify() - event_loop.quit() - return False # polling for checks will stop + else: + # Check for success + if not gatt_app_obj_check and lib_gatt.GATT_APP_OBJ: + print("GATT Data created") + gatt_app_obj_check = True + if not gatt_app_reg_check and GATT_APP_REGISTERED: + print("GATT Application registered") + gatt_app_reg_check = True + if not adv_data_check and lib_gap.ADV_OBJ: + print("Advertising data created") + adv_data_check = True + if not adv_reg_check and ADV_REGISTERED and ADV_ACTIVE_INSTANCE: + print("Advertisement registered") + adv_reg_check = True + if not read_req_check and lib_gatt.CHAR_READ: + read_req_check = True + if not write_req_check and lib_gatt.CHAR_WRITE: + write_req_check = True + if not subscribe_req_check and lib_gatt.CHAR_SUBSCRIBE: + subscribe_req_check = True - # Check for success - if not gatt_app_obj_check and lib_gatt.GATT_APP_OBJ: - print("GATT Data created") - gatt_app_obj_check = True - if not gatt_app_reg_check and GATT_APP_REGISTERED: - print("GATT Application registered") - gatt_app_reg_check = True - if not adv_data_check and lib_gap.ADV_OBJ: - print("Advertising data created") - adv_data_check = True - if not adv_reg_check and ADV_REGISTERED and ADV_ACTIVE_INSTANCE: - print("Advertisement registered") - adv_reg_check = True - if not read_req_check and lib_gatt.CHAR_READ: - read_req_check = True - if not write_req_check and lib_gatt.CHAR_WRITE: - write_req_check = True - if not subscribe_req_check and lib_gatt.CHAR_SUBSCRIBE: - subscribe_req_check = True - - # Increment retry count - blecent_retry_check_cnt += 1 if read_req_check and write_req_check and subscribe_req_check: # all checks passed # Blecent Test passed TEST_CHECKS_PASS = True lib_gatt.alert_status_char_obj.StopNotify() - event_loop.quit() + + if (blecent_retry_check_cnt == 10 or TEST_CHECKS_PASS): + if event_loop.is_running(): + event_loop.quit() return False # polling for checks will stop + # Increment retry count + blecent_retry_check_cnt += 1 + # Default return True - polling for checks will continue return True @@ -709,29 +740,29 @@ class BLE_Bluez_Client: # Blecent Test failed ADV_STOP = False - event_loop.quit() - return False # polling for checks will stop + else: + # Check for success + if not gatt_app_obj_check and not lib_gatt.GATT_APP_OBJ: + print("GATT Data removed") + gatt_app_obj_check = True + if not gatt_app_reg_check and not GATT_APP_REGISTERED: + print("GATT Application unregistered") + gatt_app_reg_check = True + if not adv_data_check and not adv_reg_check and not (ADV_REGISTERED or ADV_ACTIVE_INSTANCE or lib_gap.ADV_OBJ): + print("Advertising data removed") + print("Advertisement unregistered") + adv_data_check = True + adv_reg_check = True + # all checks passed + ADV_STOP = True - # Check for success - if not gatt_app_obj_check and not lib_gatt.GATT_APP_OBJ: - print("GATT Data removed") - gatt_app_obj_check = True - if not gatt_app_reg_check and not GATT_APP_REGISTERED: - print("GATT Application unregistered") - gatt_app_reg_check = True - if not adv_data_check and not adv_reg_check and not (ADV_REGISTERED or ADV_ACTIVE_INSTANCE or lib_gap.ADV_OBJ): - print("Advertising data removed") - print("Advertisement unregistered") - adv_data_check = True - adv_reg_check = True + if (blecent_retry_check_cnt == 10 or ADV_STOP): + if event_loop.is_running(): + event_loop.quit() + return False # polling for checks will stop # Increment retry count blecent_retry_check_cnt += 1 - if adv_reg_check: - # all checks passed - ADV_STOP = True - event_loop.quit() - return False # polling for checks will stop # Default return True - polling for checks will continue return True @@ -747,11 +778,14 @@ class BLE_Bluez_Client: Adapter is powered off ''' try: - global blecent_retry_check_cnt, DISCOVERY_START + global blecent_retry_check_cnt, DISCOVERY_START, verify_signal_check, SIGNAL_CAUGHT blecent_retry_check_cnt = 0 + verify_signal_check = 0 print("\nexiting from test...") + self.props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) + if ADV_REGISTERED: # Unregister Advertisement le_adv_manager_iface_obj.UnregisterAdvertisement(le_adv_obj.get_path()) @@ -766,7 +800,7 @@ class BLE_Bluez_Client: # Remove GATT data dbus.service.Object.remove_from_connection(gatt_app_obj) - GLib.timeout_add_seconds(2, self.verify_blecent_disconnect) + GLib.timeout_add_seconds(5, self.verify_blecent_disconnect) event_loop.run() if ADV_STOP: @@ -784,9 +818,10 @@ class BLE_Bluez_Client: if DISCOVERY_START: self.adapter.StopDiscovery() DISCOVERY_START = False + time.sleep(15) - # Power off Adapter - self.props_iface_obj.Set(ADAPTER_IFACE, "Powered", dbus.Boolean(0)) + SIGNAL_CAUGHT = False + GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() if not DEVICE_CONNECTED: @@ -794,12 +829,6 @@ class BLE_Bluez_Client: else: print("Warning: device could not be disconnected") - print("powering off adapter...") - if not ADAPTER_ON: - print("bluetooth adapter powered off") - else: - print("\nWarning: Bluetooth adapter not powered off") - - except Exception as e: - print(e) + except Exception: + print(traceback.format_exc()) return False diff --git a/tools/ci/check_artifacts_expire_time.py b/tools/ci/check_artifacts_expire_time.py index 3eb06c177..ae7942dae 100644 --- a/tools/ci/check_artifacts_expire_time.py +++ b/tools/ci/check_artifacts_expire_time.py @@ -7,6 +7,11 @@ import os import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + IDF_PATH = os.getenv("IDF_PATH") if not IDF_PATH: print("Please set IDF_PATH before running this script") @@ -17,7 +22,7 @@ GITLAB_CONFIG_FILE = os.path.join(os.getenv("IDF_PATH"), ".gitlab-ci.yml") def check_artifacts_expire_time(): with open(GITLAB_CONFIG_FILE, "r") as f: - config = yaml.load(f) + config = yaml.load(f, Loader=Loader) errors = [] diff --git a/tools/ci/config/build.yml b/tools/ci/config/build.yml index b2bb84b55..dfb277a14 100644 --- a/tools/ci/config/build.yml +++ b/tools/ci/config/build.yml @@ -45,13 +45,31 @@ build_template_app: - export PATH="$IDF_PATH/tools:$PATH" - export EXTRA_CFLAGS=${PEDANTIC_CFLAGS} - export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS} + + # CONFIG_COMPILER_OPTIMIZATION_DEFAULT with flag -Og + - echo "CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y" >> sdkconfig - make defconfig - # Test debug build (default) - make all V=1 - # Now test release build - make clean - - sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig + + # CONFIG_COMPILER_OPTIMIZATION_SIZE with flag -Os + - echo "CONFIG_COMPILER_OPTIMIZATION_SIZE=y" >> sdkconfig + - make defconfig - make all V=1 + - make clean + + # CONFIG_COMPILER_OPTIMIZATION_PERF with flag -O2 + - echo "CONFIG_COMPILER_OPTIMIZATION_PERF=y" >> sdkconfig + - make defconfig + - make all V=1 + - make clean + + # CONFIG_COMPILER_OPTIMIZATION_NONE with flag -O0 + - echo "CONFIG_COMPILER_OPTIMIZATION_NONE=y" >> sdkconfig + - make defconfig + - make all V=1 + - make clean + # Check if there are any stray printf/ets_printf references in WiFi libs - pushd ../components/esp_wifi/lib_esp32 - test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0 diff --git a/tools/ci/config/host-test.yml b/tools/ci/config/host-test.yml index 4fcab23b8..aeeac4541 100644 --- a/tools/ci/config/host-test.yml +++ b/tools/ci/config/host-test.yml @@ -187,6 +187,14 @@ test_idf_size: - cd ${IDF_PATH}/tools/test_idf_size - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh ./test.sh +test_idf_py: + extends: .host_test_template + variables: + LC_ALL: C.UTF-8 + script: + - cd ${IDF_PATH}/tools/test_idf_py + - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh ./test_idf_py.py + test_idf_tools: extends: .host_test_template script: diff --git a/tools/ci/executable-list.txt b/tools/ci/executable-list.txt index 6c259a10d..b7c30f565 100644 --- a/tools/ci/executable-list.txt +++ b/tools/ci/executable-list.txt @@ -77,6 +77,7 @@ tools/mass_mfg/mfg_gen.py tools/set-submodules-to-github.sh tools/test_check_kconfigs.py tools/test_idf_monitor/run_test_idf_monitor.py +tools/test_idf_py/test_idf_py.py tools/test_idf_size/test.sh tools/test_idf_tools/test_idf_tools.py tools/unit-test-app/tools/get_available_configs.sh diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 5b758c814..1f7b215a4 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -490,16 +490,6 @@ endmenu\n" >> ${IDF_PATH}/Kconfig; rm -rf esp32 rm -rf mycomponents - # idf.py global and subcommand parameters - print_status "Cannot set -D twice: for command and subcommand of idf.py (with different values)" - idf.py -DAAA=BBB build -DAAA=BBB -DCCC=EEE - if [ $? -eq 0 ]; then - failure "It shouldn't be allowed to set -D twice (globally and for subcommand) with different set of options" - fi - - print_status "Can set -D twice: globally and for subcommand, only if values are the same" - idf.py -DAAA=BBB -DCCC=EEE build -DAAA=BBB -DCCC=EEE || failure "It should be allowed to set -D twice (globally and for subcommand) if values are the same" - # idf.py subcommand options, (using monitor with as example) print_status "Can set options to subcommands: print_filter for monitor" mv ${IDF_PATH}/tools/idf_monitor.py ${IDF_PATH}/tools/idf_monitor.py.tmp diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 0440677b7..8c695ec53 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -220,6 +220,24 @@ function(__build_expand_requirements component_target) idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS) if(NOT component_target IN_LIST build_component_targets) idf_build_set_property(__BUILD_COMPONENT_TARGETS ${component_target} APPEND) + + __component_get_property(component_lib ${component_target} COMPONENT_LIB) + idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND) + + idf_build_get_property(prefix __PREFIX) + __component_get_property(component_prefix ${component_target} __PREFIX) + + __component_get_property(component_alias ${component_target} COMPONENT_ALIAS) + + idf_build_set_property(BUILD_COMPONENT_ALIASES ${component_alias} APPEND) + + # Only put in the prefix in the name if it is not the default one + if(component_prefix STREQUAL prefix) + __component_get_property(component_name ${component_target} COMPONENT_NAME) + idf_build_set_property(BUILD_COMPONENTS ${component_name} APPEND) + else() + idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND) + endif() endif() endfunction() diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 8eb2f3f97..5591ad44f 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -56,13 +56,8 @@ function(__component_get_target var name_or_alias) foreach(component_target ${component_targets}) __component_get_property(_component_name ${component_target} COMPONENT_NAME) if(name_or_alias STREQUAL _component_name) - # There should only be one component of the same name - if(NOT target) - set(target ${component_target}) - else() - message(FATAL_ERROR "Multiple components with name '${name_or_alias}' found.") - return() - endif() + set(target ${component_target}) + break() endif() endforeach() set(${var} ${target} PARENT_SCOPE) @@ -191,6 +186,7 @@ function(__component_add component_dir prefix) __component_set_property(${component_target} COMPONENT_NAME ${component_name}) __component_set_property(${component_target} COMPONENT_DIR ${component_dir}) __component_set_property(${component_target} COMPONENT_ALIAS ${component_alias}) + __component_set_property(${component_target} __PREFIX ${prefix}) # Set Kconfig related properties on the component @@ -482,10 +478,6 @@ function(idf_component_register) # Set dependencies __component_set_all_dependencies() - # Add the component to built components - idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND) - idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND) - # Make the COMPONENT_LIB variable available in the component CMakeLists.txt set(COMPONENT_LIB ${component_lib} PARENT_SCOPE) # COMPONENT_TARGET is deprecated but is made available with same function diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 0208f3e9e..7608268f7 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -353,13 +353,16 @@ macro(project project_name) # so that it treats components equally. # # This behavior should only be when user did not set REQUIRES/PRIV_REQUIRES manually. - idf_build_get_property(build_components BUILD_COMPONENTS) + idf_build_get_property(build_components BUILD_COMPONENT_ALIASES) if(idf::main IN_LIST build_components) __component_get_target(main_target idf::main) __component_get_property(reqs ${main_target} REQUIRES) __component_get_property(priv_reqs ${main_target} PRIV_REQUIRES) idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON) if(reqs STREQUAL common_reqs AND NOT priv_reqs) #if user has not set any requirements + if(test_components) + list(REMOVE_ITEM build_components ${test_components}) + endif() list(REMOVE_ITEM build_components idf::main) __component_get_property(lib ${main_target} COMPONENT_LIB) set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${build_components}") @@ -392,7 +395,7 @@ macro(project project_name) target_link_libraries(${project_elf} "-Wl,--no-whole-archive") endif() - idf_build_get_property(build_components BUILD_COMPONENTS) + idf_build_get_property(build_components BUILD_COMPONENT_ALIASES) if(test_components) list(REMOVE_ITEM build_components ${test_components}) endif() diff --git a/tools/idf.py b/tools/idf.py index 8b700d0cc..6e1109537 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -32,11 +32,12 @@ import locale import multiprocessing import os import os.path +import platform import re import shutil import subprocess import sys -import platform +from collections import Counter, OrderedDict class FatalError(RuntimeError): @@ -121,8 +122,13 @@ def check_environment(): (cmake will check a lot of other things) """ + checks_output = [] + if not executable_exists(["cmake", "--version"]): + print_idf_version() raise FatalError("'cmake' must be available on the PATH to use %s" % PROG) + + # verify that IDF_PATH env variable is set # find the directory idf.py is in, then the parent directory of this, and assume this is IDF_PATH detected_idf_path = _realpath(os.path.join(os.path.dirname(__file__), "..")) if "IDF_PATH" in os.environ: @@ -138,9 +144,9 @@ def check_environment(): os.environ["IDF_PATH"] = detected_idf_path # check Python dependencies - print("Checking Python dependencies...") + checks_output.append("Checking Python dependencies...") try: - subprocess.check_call( + out = subprocess.check_output( [ os.environ["PYTHON"], os.path.join( @@ -149,9 +155,15 @@ def check_environment(): ], env=os.environ, ) - except subprocess.CalledProcessError: + + checks_output.append(out.decode('utf-8','ignore').strip()) + except subprocess.CalledProcessError as e: + print(e.output.decode('utf-8','ignore')) + print_idf_version() raise SystemExit(1) + return checks_output + def executable_exists(args): try: @@ -413,6 +425,7 @@ def set_target(action, ctx, args, idf_target): if os.path.exists(sdkconfig_path): os.rename(sdkconfig_path, sdkconfig_old) print("Set Target to: %s, new sdkconfig created. Existing sdkconfig renamed to sdkconfig.old." % idf_target) + _ensure_build_directory(args, True) def reconfigure(action, ctx, args): @@ -496,6 +509,71 @@ def _safe_relpath(path, start=None): return os.path.abspath(path) +def _idf_version_from_cmake(): + version_path = os.path.join(os.environ["IDF_PATH"], "tools/cmake/version.cmake") + regex = re.compile(r"^\s*set\s*\(\s*IDF_VERSION_([A-Z]{5})\s+(\d+)") + ver = {} + try: + with open(version_path) as f: + for line in f: + m = regex.match(line) + + if m: + ver[m.group(1)] = m.group(2) + + return "v%s.%s.%s" % (ver["MAJOR"], ver["MINOR"], ver["PATCH"]) + except (KeyError, OSError): + sys.stderr.write("WARNING: Cannot find ESP-IDF version in version.cmake\n") + return None + + +def idf_version(): + """Print version of ESP-IDF""" + + # Try to get version from git: + try: + version = subprocess.check_output([ + "git", + "--git-dir=%s" % os.path.join(os.environ["IDF_PATH"], '.git'), + "--work-tree=%s" % os.environ["IDF_PATH"], "describe", "--tags", "--dirty" + ]).decode('utf-8', 'ignore').strip() + except (subprocess.CalledProcessError, UnicodeError): + # if failed, then try to parse cmake.version file + sys.stderr.write("WARNING: Git version unavailable, reading from source\n") + version = _idf_version_from_cmake() + + return version + + +def print_idf_version(): + version = idf_version() + if version: + print("ESP-IDF %s" % version) + else: + print("ESP-IDF version unknown") + + +def idf_version_callback(ctx, param, value): + if not value or ctx.resilient_parsing: + return + + version = idf_version() + + if not version: + raise FatalError("ESP-IDF version cannot be determined") + + print("ESP-IDF %s" % version) + sys.exit(0) + + +def verbose_callback(ctx, param, value): + if not value or ctx.resilient_parsing: + return + + for line in ctx.command.verbose_output: + print(line) + + def get_commandline_options(ctx): """ Return all the command line options up to first action """ # This approach ignores argument parsing done Click @@ -549,7 +627,7 @@ class PropertyDict(dict): raise AttributeError("'PropertyDict' object has no attribute '%s'" % name) -def init_cli(): +def init_cli(verbose_output=None): # Click is imported here to run it after check_environment() import click @@ -724,7 +802,7 @@ def init_cli(): class Option(click.Option): """Option that knows whether it should be global""" - def __init__(self, scope=None, deprecated=False, **kwargs): + def __init__(self, scope=None, deprecated=False, hidden=False, **kwargs): """ Keyword arguments additional to Click's Option class: @@ -741,6 +819,7 @@ def init_cli(): self.deprecated = deprecated self.scope = Scope(scope) + self.hidden = hidden if deprecated: deprecation = DeprecationMessage(deprecated) @@ -749,10 +828,17 @@ def init_cli(): if self.scope.is_global: self.help += " This option can be used at most once either globally, or for one subcommand." + def get_help_record(self, ctx): + # Backport "hidden" parameter to click 5.0 + if self.hidden: + return + + return super(Option, self).get_help_record(ctx) + class CLI(click.MultiCommand): """Action list contains all actions with options available for CLI""" - def __init__(self, action_lists=None, help=None): + def __init__(self, action_lists=None, verbose_output=None, help=None): super(CLI, self).__init__( chain=True, invoke_without_command=True, @@ -764,6 +850,11 @@ def init_cli(): self.global_action_callbacks = [] self.commands_with_aliases = {} + if verbose_output is None: + verbose_output = [] + + self.verbose_output = verbose_output + if action_lists is None: action_lists = [] @@ -901,9 +992,18 @@ def init_cli(): def execute_tasks(self, tasks, **kwargs): ctx = click.get_current_context() - global_args = PropertyDict(ctx.params) + global_args = PropertyDict(kwargs) - # Set propagated global options + # Show warning if some tasks are present several times in the list + dupplicated_tasks = sorted([item for item, count in Counter(task.name for task in tasks).items() if count > 1]) + if dupplicated_tasks: + dupes = ", ".join('"%s"' % t for t in dupplicated_tasks) + print("WARNING: Command%s found in the list of commands more than once. " + % ("s %s are" % dupes if len(dupplicated_tasks) > 1 else " %s is" % dupes) + + "Only first occurence will be executed.") + + # Set propagated global options. + # These options may be set on one subcommand, but available in the list of global arguments for task in tasks: for key in list(task.action_args): option = next((o for o in ctx.command.params if o.name == key), None) @@ -924,72 +1024,78 @@ def init_cli(): # Show warnings about global arguments print_deprecation_warning(ctx) - # Validate global arguments + # Make sure that define_cache_entry is mutable list and can be modified in callbacks + global_args.define_cache_entry = list(global_args.define_cache_entry) + + # Execute all global action callback - first from idf.py itself, then from extensions for action_callback in ctx.command.global_action_callbacks: action_callback(ctx, global_args, tasks) + # Always show help when command is not provided if not tasks: print(ctx.get_help()) ctx.exit() - # Make sure that define_cache_entry is list - global_args.define_cache_entry = list(global_args.define_cache_entry) - - # Go through the task and create depended but missing tasks - all_tasks = [t.name for t in tasks] - tasks, tasks_to_handle = [], tasks - while tasks_to_handle: - task = tasks_to_handle.pop() - tasks.append(task) - for dep in task.dependencies: - if dep not in all_tasks: - print( - 'Adding %s\'s dependency "%s" to list of actions' - % (task.name, dep) - ) - dep_task = ctx.invoke(ctx.command.get_command(ctx, dep)) - - # Remove global options from dependent tasks - for key in list(dep_task.action_args): - option = next((o for o in ctx.command.params if o.name == key), None) - if option and (option.scope.is_global or option.scope.is_shared): - dep_task.action_args.pop(key) - - tasks_to_handle.append(dep_task) - all_tasks.append(dep_task.name) - - # very simple dependency management - completed_tasks = set() + # Build full list of tasks to and deal with dependencies and order dependencies + tasks_to_run = OrderedDict() while tasks: task = tasks[0] tasks_dict = dict([(t.name, t) for t in tasks]) - name_with_aliases = task.name - if task.aliases: - name_with_aliases += " (aliases: %s)" % ", ".join(task.aliases) + dependecies_processed = True - ready_to_run = True + # If task have some dependecies they have to be executed before the task. + for dep in task.dependencies: + if dep not in tasks_to_run.keys(): + # If dependent task is in the list of unprocessed tasks move to the front of the list + if dep in tasks_dict.keys(): + dep_task = tasks.pop(tasks.index(tasks_dict[dep])) + # Otherwise invoke it with default set of options + # and put to the front of the list of unprocessed tasks + else: + print( + 'Adding "%s"\'s dependency "%s" to list of commands with default set of options.' + % (task.name, dep) + ) + dep_task = ctx.invoke(ctx.command.get_command(ctx, dep)) + # Remove options with global scope from invoke tasks because they are alread in global_args + for key in list(dep_task.action_args): + option = next((o for o in ctx.command.params if o.name == key), None) + if option and (option.scope.is_global or option.scope.is_shared): + dep_task.action_args.pop(key) + + tasks.insert(0, dep_task) + dependecies_processed = False + + # Order only dependencies are moved to the front of the queue if they present in command list for dep in task.order_dependencies: - if dep in tasks_dict.keys() and dep not in completed_tasks: + if dep in tasks_dict.keys() and dep not in tasks_to_run.keys(): tasks.insert(0, tasks.pop(tasks.index(tasks_dict[dep]))) - ready_to_run = False + dependecies_processed = False - if ready_to_run: + if dependecies_processed: + # Remove task from list of unprocessed tasks tasks.pop(0) - if task.name in completed_tasks: - print( - "Skipping action that is already done: %s" - % name_with_aliases - ) - else: - print("Executing action: %s" % name_with_aliases) - task.run(ctx, global_args, task.action_args) + # And add to the queue + if task.name not in tasks_to_run.keys(): + tasks_to_run.update([(task.name, task)]) - completed_tasks.add(task.name) + # Run all tasks in the queue + # when global_args.no_run is true idf.py works in idle mode and skips actual task execution + if not global_args.no_run: + for task in tasks_to_run.values(): + name_with_aliases = task.name + if task.aliases: + name_with_aliases += " (aliases: %s)" % ", ".join(task.aliases) - self._print_closing_message(global_args, completed_tasks) + print("Executing action: %s" % name_with_aliases) + task.run(ctx, global_args, task.action_args) + + self._print_closing_message(global_args, tasks_to_run.keys()) + + return tasks_to_run @staticmethod def merge_action_lists(*action_lists): @@ -1044,6 +1150,12 @@ def init_cli(): root_options = { "global_options": [ + { + "names": ["--version"], + "help": "Show IDF version and exit.", + "is_flag": True, + "callback": idf_version_callback + }, { "names": ["-C", "--project-dir"], "help": "Project directory.", @@ -1066,7 +1178,9 @@ def init_cli(): "names": ["-v", "--verbose"], "help": "Verbose build output.", "is_flag": True, + "is_eager": True, "default": False, + "callback": verbose_callback }, { "names": ["--ccache/--no-ccache"], @@ -1079,6 +1193,13 @@ def init_cli(): "help": "CMake generator.", "type": click.Choice(GENERATOR_CMDS.keys()), }, + { + "names": ["--no-run"], + "help": "Only process arguments, but don't execute actions.", + "is_flag": True, + "hidden": True, + "default": False + }, ], "global_action_callbacks": [validate_root_options], } @@ -1189,7 +1310,7 @@ def init_cli(): + "For example, \"idf.py -DNAME='VALUE' reconfigure\" " + 'can be used to set variable "NAME" in CMake cache to value "VALUE".', "options": global_options, - "order_dependencies": ["menuconfig", "set-target", "fullclean"], + "order_dependencies": ["menuconfig", "fullclean"], }, "set-target": { "callback": set_target, @@ -1204,7 +1325,7 @@ def init_cli(): "nargs": 1, "type": click.Choice(SUPPORTED_TARGETS), }], - "dependencies": ["fullclean", "reconfigure"], + "dependencies": ["fullclean"], }, "clean": { "callback": clean, @@ -1339,12 +1460,12 @@ def init_cli(): except NameError: pass - return CLI(help="ESP-IDF build management", action_lists=all_actions) + return CLI(help="ESP-IDF build management", verbose_output=verbose_output, action_lists=all_actions) def main(): - check_environment() - cli = init_cli() + checks_output = check_environment() + cli = init_cli(verbose_output=checks_output) cli(prog_name=PROG) diff --git a/tools/ldgen/samples/sdkconfig b/tools/ldgen/samples/sdkconfig index 43c81dd18..112abbec6 100644 --- a/tools/ldgen/samples/sdkconfig +++ b/tools/ldgen/samples/sdkconfig @@ -82,8 +82,10 @@ CONFIG_PARTITION_TABLE_MD5=y # # Compiler options # -CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y -CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE= +CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y +CONFIG_COMPILER_OPTIMIZATION_SIZE= +CONFIG_COMPILER_OPTIMIZATION_NONE= +CONFIG_COMPILER_OPTIMIZATION_PERF= CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT= CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE= diff --git a/tools/test_idf_py/test_idf_py.py b/tools/test_idf_py/test_idf_py.py new file mode 100755 index 000000000..1a9f8a073 --- /dev/null +++ b/tools/test_idf_py/test_idf_py.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# +# Copyright 2019 Espressif Systems (Shanghai) CO LTD +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import unittest + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + +try: + import idf +except ImportError: + sys.path.append('..') + import idf + + +class TestDependencyManagement(unittest.TestCase): + def test_dependencies(self): + result = idf.init_cli()( + args=['--no-run', 'flash'], + standalone_mode=False, + ) + self.assertEqual(['all', 'flash'], list(result.keys())) + + def test_order_only_dependencies(self): + result = idf.init_cli()( + args=['--no-run', 'build', 'fullclean', 'all'], + standalone_mode=False, + ) + self.assertEqual(['fullclean', 'all'], list(result.keys())) + + def test_repeated_dependencies(self): + result = idf.init_cli()( + args=['--no-run', 'fullclean', 'app', 'fullclean', 'fullclean'], + standalone_mode=False, + ) + self.assertEqual(['fullclean', 'app'], list(result.keys())) + + def test_complex_case(self): + result = idf.init_cli()( + args=['--no-run', 'clean', 'monitor', 'clean', 'fullclean', 'flash'], + standalone_mode=False, + ) + self.assertEqual(['fullclean', 'clean', 'all', 'flash', 'monitor'], list(result.keys())) + + def test_dupplicated_commands_warning(self): + capturedOutput = StringIO() + sys.stdout = capturedOutput + idf.init_cli()( + args=['--no-run', 'clean', 'monitor', 'build', 'clean', 'fullclean', 'all'], + standalone_mode=False, + ) + sys.stdout = sys.__stdout__ + self.assertIn('WARNING: Commands "all", "clean" are found in the list of commands more than once.', + capturedOutput.getvalue()) + + sys.stdout = capturedOutput + idf.init_cli()( + args=['--no-run', 'clean', 'clean'], + standalone_mode=False, + ) + sys.stdout = sys.__stdout__ + self.assertIn('WARNING: Command "clean" is found in the list of commands more than once.', + capturedOutput.getvalue()) + + +class TestGlobalAndSubcommandParameters(unittest.TestCase): + def test_set_twice_same_value(self): + """Can set -D twice: globally and for subcommand if values are the same""" + + idf.init_cli()( + args=['--no-run', '-DAAA=BBB', '-DCCC=EEE', 'build', '-DAAA=BBB', '-DCCC=EEE'], + standalone_mode=False, + ) + + def test_set_twice_different_values(self): + """Cannot set -D twice: for command and subcommand of idf.py (with different values)""" + + with self.assertRaises(idf.FatalError): + idf.init_cli()( + args=['--no-run', '-DAAA=BBB', 'build', '-DAAA=EEE', '-DCCC=EEE'], + standalone_mode=False, + ) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tiny-test-fw/CIAssignUnitTest.py b/tools/tiny-test-fw/CIAssignUnitTest.py index c6ec2a0ad..b95cd8903 100644 --- a/tools/tiny-test-fw/CIAssignUnitTest.py +++ b/tools/tiny-test-fw/CIAssignUnitTest.py @@ -9,6 +9,11 @@ import argparse import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + try: from Utility import CIAssignTest except ImportError: @@ -128,7 +133,7 @@ class UnitTestAssignTest(CIAssignTest.AssignTest): try: with open(test_case_path, "r") as f: - raw_data = yaml.load(f) + raw_data = yaml.load(f, Loader=Loader) test_cases = raw_data["test cases"] except IOError: print("Test case path is invalid. Should only happen when use @bot to skip unit test.") diff --git a/tools/tiny-test-fw/EnvConfig.py b/tools/tiny-test-fw/EnvConfig.py index 9e6c35551..1f7a75511 100644 --- a/tools/tiny-test-fw/EnvConfig.py +++ b/tools/tiny-test-fw/EnvConfig.py @@ -34,6 +34,11 @@ This will prevent test cases from getting configs from other env when there're c import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + class Config(object): """ Test Env Config """ @@ -52,7 +57,7 @@ class Config(object): """ try: with open(config_file) as f: - configs = yaml.load(f)[env_name] + configs = yaml.load(f, Loader=Loader)[env_name] except (OSError, TypeError, IOError): configs = dict() return configs diff --git a/tools/tiny-test-fw/TestCase.py b/tools/tiny-test-fw/TestCase.py index 80b548530..dd3ca2f22 100644 --- a/tools/tiny-test-fw/TestCase.py +++ b/tools/tiny-test-fw/TestCase.py @@ -14,6 +14,11 @@ import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + class TestCase(object): """ @@ -45,7 +50,7 @@ class TestCase(object): """ doc_string = self.test_method.__doc__ try: - doc = yaml.load(doc_string) + doc = yaml.load(doc_string, Loader=Loader) except (AttributeError, OSError, UnicodeDecodeError): doc = self.DEFAULT_CASE_DOC doc.update(self.test_method.env_args) diff --git a/tools/tiny-test-fw/Utility/CIAssignTest.py b/tools/tiny-test-fw/Utility/CIAssignTest.py index a936428cb..0931b6997 100644 --- a/tools/tiny-test-fw/Utility/CIAssignTest.py +++ b/tools/tiny-test-fw/Utility/CIAssignTest.py @@ -47,6 +47,11 @@ import yaml from Utility import (CaseConfig, SearchCases, GitlabCIJob, console_log) +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + class Group(object): @@ -150,7 +155,7 @@ class AssignTest(object): def _parse_gitlab_ci_config(self, ci_config_file): with open(ci_config_file, "r") as f: - ci_config = yaml.load(f) + ci_config = yaml.load(f, Loader=Loader) job_list = list() for job_name in ci_config: diff --git a/tools/tiny-test-fw/Utility/CaseConfig.py b/tools/tiny-test-fw/Utility/CaseConfig.py index ee6234da8..8f9736f5b 100644 --- a/tools/tiny-test-fw/Utility/CaseConfig.py +++ b/tools/tiny-test-fw/Utility/CaseConfig.py @@ -49,6 +49,11 @@ import TestCase from Utility import load_source +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + def _convert_to_lower_case_bytes(item): """ @@ -154,7 +159,7 @@ class Parser(object): configs = cls.DEFAULT_CONFIG.copy() if config_file: with open(config_file, "r") as f: - configs.update(yaml.load(f)) + configs.update(yaml.load(f), Loader=Loader) return configs @classmethod diff --git a/tools/unit-test-app/tools/UnitTestParser.py b/tools/unit-test-app/tools/UnitTestParser.py index f82715768..574df3e0a 100644 --- a/tools/unit-test-app/tools/UnitTestParser.py +++ b/tools/unit-test-app/tools/UnitTestParser.py @@ -8,6 +8,11 @@ import subprocess from copy import deepcopy import CreateSectionTable +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader + TEST_CASE_PATTERN = { "initial condition": "UTINIT1", "chip_target": "esp32", @@ -50,9 +55,10 @@ class Parser(object): self.unit_jobs = {} self.file_name_cache = {} self.idf_path = idf_path - self.tag_def = yaml.load(open(os.path.join(idf_path, self.TAG_DEF_FILE), "r")) - self.module_map = yaml.load(open(os.path.join(idf_path, self.MODULE_DEF_FILE), "r")) - self.config_dependencies = yaml.load(open(os.path.join(idf_path, self.CONFIG_DEPENDENCY_FILE), "r")) + self.tag_def = yaml.load(open(os.path.join(idf_path, self.TAG_DEF_FILE), "r"), Loader=Loader) + self.module_map = yaml.load(open(os.path.join(idf_path, self.MODULE_DEF_FILE), "r"), Loader=Loader) + self.config_dependencies = yaml.load(open(os.path.join(idf_path, self.CONFIG_DEPENDENCY_FILE), "r"), + Loader=Loader) # used to check if duplicated test case names self.test_case_names = set() self.parsing_errors = []