Skip to content

Commit

Permalink
Merge branch 'bugfix/system_examples_print_format_v5.0' into 'release…
Browse files Browse the repository at this point in the history
…/v5.0'

system: fix printf format errors in all system examples (v5.0)

See merge request espressif/esp-idf!21564
  • Loading branch information
ESP-Marius committed Dec 13, 2022
2 parents cc3dd00 + f81cae4 commit fe18c89
Show file tree
Hide file tree
Showing 37 changed files with 64 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ else()
idf_component_get_property(experimental_cpp_component_lib experimental_cpp_component COMPONENT_LIB)
target_link_libraries(${COMPONENT_LIB} PUBLIC ${log_lib} ${mqtt_lib} ${experimental_cpp_component_lib})
endif()
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <algorithm>
#include <stdexcept>
#include <inttypes.h>

#include "mqtt_client.h"
#include "esp_log.h"
Expand Down Expand Up @@ -126,7 +127,7 @@ Client::Client(esp_mqtt_client_config_t const &config) : handler(esp_mqtt_clien

void Client::mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) noexcept
{
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
auto *event = static_cast<esp_mqtt_event_t *>(event_data);
auto &client = *static_cast<Client *>(handler_args);
switch (event->event_id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "mqtt_ssl_example.cpp"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cstdint>
#include <string>
#include <inttypes.h>
#include "esp_mqtt_client_config.hpp"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ namespace mqtt = idf::mqtt;
extern "C" void app_main(void)
{
ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());

esp_log_level_set("*", ESP_LOG_INFO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "mqtt_tcp_example.cpp"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
CONDITIONS OF ANY KIND, either express or implied.
*/

#include <inttypes.h>

#include "nvs_flash.h"
#include "protocol_examples_common.h"

Expand Down Expand Up @@ -44,7 +46,7 @@ class MyClient final : public mqtt::Client {
extern "C" void app_main(void)
{
ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());

esp_log_level_set("*", ESP_LOG_INFO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
idf_component_register(SRCS "cmd_nvs.c"
INCLUDE_DIRS .
REQUIRES console nvs_flash)

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
4 changes: 2 additions & 2 deletions examples/system/console/advanced/components/cmd_nvs/cmd_nvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ static esp_err_t get_value_from_nvs(const char *key, const char *str_type)
} else if (type == NVS_TYPE_I32) {
int32_t value;
if ((err = nvs_get_i32(nvs, key, &value)) == ESP_OK) {
printf("%d\n", value);
printf("%"PRIi32"\n", value);
}
} else if (type == NVS_TYPE_U32) {
uint32_t value;
if ((err = nvs_get_u32(nvs, key, &value)) == ESP_OK) {
printf("%u\n", value);
printf("%"PRIu32"\n", value);
}
} else if (type == NVS_TYPE_I64) {
int64_t value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
idf_component_register(SRCS "cmd_system.c"
INCLUDE_DIRS .
REQUIRES console spi_flash driver)

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <unistd.h>
#include "esp_log.h"
#include "esp_console.h"
Expand Down Expand Up @@ -105,7 +106,7 @@ static int get_version(int argc, char **argv)
printf("Chip info:\r\n");
printf("\tmodel:%s\r\n", model);
printf("\tcores:%d\r\n", info.cores);
printf("\tfeature:%s%s%s%s%d%s\r\n",
printf("\tfeature:%s%s%s%s%"PRIu32"%s\r\n",
info.features & CHIP_FEATURE_WIFI_BGN ? "/802.11bgn" : "",
info.features & CHIP_FEATURE_BLE ? "/BLE" : "",
info.features & CHIP_FEATURE_BT ? "/BT" : "",
Expand Down Expand Up @@ -149,7 +150,7 @@ static void register_restart(void)

static int free_mem(int argc, char **argv)
{
printf("%d\n", esp_get_free_heap_size());
printf("%"PRIu32"\n", esp_get_free_heap_size());
return 0;
}

Expand All @@ -168,7 +169,7 @@ static void register_free(void)
static int heap_size(int argc, char **argv)
{
uint32_t heap_size = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT);
printf("min heap size: %u\n", heap_size);
printf("min heap size: %"PRIu32"\n", heap_size);
return 0;
}

Expand Down
1 change: 0 additions & 1 deletion examples/system/deep_sleep/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "deep_sleep_example_main.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
3 changes: 2 additions & 1 deletion examples/system/deep_sleep/main/deep_sleep_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "soc/soc_caps.h"
#include "freertos/FreeRTOS.h"
Expand Down Expand Up @@ -203,7 +204,7 @@ void app_main(void)
touch_pad_sleep_channel_read_smooth(TOUCH_PAD_NUM9, &touch_value);
wake_threshold = touch_value * 0.1; // wakeup when touch sensor crosses 10% of background level
touch_pad_sleep_set_threshold(TOUCH_PAD_NUM9, wake_threshold);
printf("Touch pad #%d average: %d, wakeup threshold set to %d\n",
printf("Touch pad #%d average: %"PRIu32", wakeup threshold set to %"PRIu32"\n",
TOUCH_PAD_NUM9, touch_value, (uint32_t)(touch_value * 0.1));
#endif
printf("Enabling touch pad wakeup\n");
Expand Down
1 change: 0 additions & 1 deletion examples/system/flash_suspend/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS "")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
3 changes: 2 additions & 1 deletion examples/system/flash_suspend/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_attr.h"
Expand Down Expand Up @@ -92,7 +93,7 @@ void app_main(void)
{
//Get the partition used for SPI1 erase operation
const esp_partition_t *part = s_get_partition();
ESP_LOGI(TAG, "found partition '%s' at offset 0x%x with size 0x%x", part->label, part->address, part->size);
ESP_LOGI(TAG, "found partition '%s' at offset 0x%"PRIx32" with size 0x%"PRIx32, part->label, part->address, part->size);
//Erase whole region
ESP_ERROR_CHECK(esp_flash_erase_region(part->flash_chip, part->address, part->size));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "real_time_stats_example_main.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
Expand Down Expand Up @@ -109,7 +110,7 @@ static esp_err_t print_real_time_stats(TickType_t xTicksToWait)
if (k >= 0) {
uint32_t task_elapsed_time = end_array[k].ulRunTimeCounter - start_array[i].ulRunTimeCounter;
uint32_t percentage_time = (task_elapsed_time * 100UL) / (total_elapsed_time * portNUM_PROCESSORS);
printf("| %s | %d | %d%%\n", start_array[i].pcTaskName, task_elapsed_time, percentage_time);
printf("| %s | %"PRIu32" | %"PRIu32"%%\n", start_array[i].pcTaskName, task_elapsed_time, percentage_time);
}
}

Expand Down Expand Up @@ -155,7 +156,7 @@ static void stats_task(void *arg)

//Print real time stats periodically
while (1) {
printf("\n\nGetting real time stats over %d ticks\n", STATS_TICKS);
printf("\n\nGetting real time stats over %"PRIu32" ticks\n", STATS_TICKS);
if (print_real_time_stats(STATS_TICKS) == ESP_OK) {
printf("Real time stats obtained\n");
} else {
Expand Down
1 change: 0 additions & 1 deletion examples/system/himem/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "himem_example_main.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
3 changes: 2 additions & 1 deletion examples/system/himem/main/himem_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
Expand Down Expand Up @@ -40,7 +41,7 @@ static bool check_mem_seed(int seed, void *mem, int len, int phys_addr)
for (int i = 0; i < len / 4; i++) {
uint32_t ex = rand_r(&rseed);
if (ex != *p) {
printf("check_mem_seed: %x has 0x%08x expected 0x%08x\n", phys_addr+((char*)p-(char*)mem), *p, ex);
printf("check_mem_seed: %x has 0x%08"PRIx32" expected 0x%08"PRIx32"\n", phys_addr+((char*)p-(char*)mem), *p, ex);
return false;
}
p++;
Expand Down
1 change: 0 additions & 1 deletion examples/system/ipc/ipc_isr/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "main.c"
"asm_funcs.S"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
21 changes: 11 additions & 10 deletions examples/system/ipc/ipc_isr/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "esp_timer.h"
#include "esp_log.h"
#include "esp_ipc_isr.h"
Expand Down Expand Up @@ -36,26 +37,26 @@ void app_main(void)
uint32_t ps_other_cpu = 0;
ESP_LOGI(TAG, "call get_ps_other_cpu");
esp_ipc_isr_asm_call_blocking(get_ps_other_cpu, &ps_other_cpu);
ESP_LOGI(TAG, "PS_INTLEVEL = 0x%x", ps_other_cpu & XCHAL_PS_INTLEVEL_MASK);
ESP_LOGI(TAG, "PS_EXCM = 0x%x", (ps_other_cpu & XCHAL_PS_EXCM_MASK) >> XCHAL_PS_EXCM_SHIFT);
ESP_LOGI(TAG, "PS_UM = 0x%x", (ps_other_cpu & XCHAL_PS_UM_MASK) >> XCHAL_PS_UM_SHIFT);
ESP_LOGI(TAG, "PS_INTLEVEL = 0x%"PRIx32, ps_other_cpu & XCHAL_PS_INTLEVEL_MASK);
ESP_LOGI(TAG, "PS_EXCM = 0x%"PRIx32, (ps_other_cpu & XCHAL_PS_EXCM_MASK) >> XCHAL_PS_EXCM_SHIFT);
ESP_LOGI(TAG, "PS_UM = 0x%"PRIx32, (ps_other_cpu & XCHAL_PS_UM_MASK) >> XCHAL_PS_UM_SHIFT);

ESP_LOGI(TAG, "call extended_ipc_isr_asm");
arg_data_t arg = { 0 };
arg.in[0] = 0x01;
arg.in[1] = 0x02;
arg.in[2] = 0x03;
ESP_LOGI(TAG, "in[0] = 0x%x", arg.in[0]);
ESP_LOGI(TAG, "in[1] = 0x%x", arg.in[1]);
ESP_LOGI(TAG, "in[2] = 0x%x", arg.in[2]);
ESP_LOGI(TAG, "in[0] = 0x%"PRIx32, arg.in[0]);
ESP_LOGI(TAG, "in[1] = 0x%"PRIx32, arg.in[1]);
ESP_LOGI(TAG, "in[2] = 0x%"PRIx32, arg.in[2]);
esp_ipc_isr_asm_call_blocking(extended_ipc_isr_asm, (void*)&arg);
ESP_LOGI(TAG, "out[0] = (in[0] | in[1] | in[2]) = 0x%x", arg.out[0]);
ESP_LOGI(TAG, "out[0] = (in[0] | in[1] | in[2]) = 0x%"PRIx32, arg.out[0]);
assert(0x03 == arg.out[0]);
ESP_LOGI(TAG, "out[1] = (in[0] & in[1] & in[2]) = 0x%x", arg.out[1]);
ESP_LOGI(TAG, "out[1] = (in[0] & in[1] & in[2]) = 0x%"PRIx32, arg.out[1]);
assert(0x06 == arg.out[1]);
ESP_LOGI(TAG, "out[2] = in[2] = 0x%x", arg.out[2]);
ESP_LOGI(TAG, "out[2] = in[2] = 0x%"PRIx32, arg.out[2]);
assert(0x03 == arg.out[2]);
ESP_LOGI(TAG, "out[3] = PS of other cpu = 0x%x", arg.out[3]);
ESP_LOGI(TAG, "out[3] = PS of other cpu = 0x%"PRIx32, arg.out[3]);
assert(ps_other_cpu == arg.out[3]);
ESP_LOGI(TAG, "End");
}
1 change: 0 additions & 1 deletion examples/system/ota/advanced_https_ota/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ idf_component_register(SRCS "advanced_https_ota_example.c" "ble_helper/bluedroid
INCLUDE_DIRS "." "./ble_helper/include/"
# Embed the server root certificate into the final binary
EMBED_TXTFILES ${project_dir}/server_certs/ca_cert.pem)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ static esp_err_t validate_image_header(esp_app_desc_t *new_app_info)
*/
const uint32_t hw_sec_version = esp_efuse_read_secure_version();
if (new_app_info->secure_version < hw_sec_version) {
ESP_LOGW(TAG, "New firmware security version is less than eFuse programmed, %d < %d", new_app_info->secure_version, hw_sec_version);
ESP_LOGW(TAG, "New firmware security version is less than eFuse programmed, %"PRIu32" < %"PRIu32, new_app_info->secure_version, hw_sec_version);
return ESP_FAIL;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <inttypes.h>
#include "bluedroid_gatts.h"
#include "esp_log.h"
#include "string.h"
Expand Down Expand Up @@ -170,7 +171,7 @@ void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gat
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_A);
break;
case ESP_GATTS_READ_EVT: {
ESP_LOGI(TAG, "GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", param->read.conn_id, param->read.trans_id, param->read.handle);
ESP_LOGI(TAG, "GATT_READ_EVT, conn_id %d, trans_id %"PRIu32", handle %d\n", param->read.conn_id, param->read.trans_id, param->read.handle);
esp_gatt_rsp_t rsp;
memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
rsp.attr_value.handle = param->read.handle;
Expand All @@ -184,7 +185,7 @@ void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gat
break;
}
case ESP_GATTS_WRITE_EVT: {
ESP_LOGI(TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d", param->write.conn_id, param->write.trans_id, param->write.handle);
ESP_LOGI(TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %"PRIu32", handle %d", param->write.conn_id, param->write.trans_id, param->write.handle);
if (!param->write.is_prep) {
ESP_LOGI(TAG, "GATT_WRITE_EVT, value len %d, value :", param->write.len);
esp_log_buffer_hex(TAG, param->write.value, param->write.len);
Expand Down
1 change: 0 additions & 1 deletion examples/system/ota/native_ota_example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ idf_build_get_property(project_dir PROJECT_DIR)
idf_component_register(SRCS "native_ota_example.c"
INCLUDE_DIRS "."
EMBED_TXTFILES ${project_dir}/server_certs/ca_cert.pem)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
Expand Down Expand Up @@ -87,11 +88,11 @@ static void ota_example_task(void *pvParameter)
const esp_partition_t *running = esp_ota_get_running_partition();

if (configured != running) {
ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x",
ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08"PRIx32", but running from offset 0x%08"PRIx32,
configured->address, running->address);
ESP_LOGW(TAG, "(This can happen if either the OTA boot data or preferred boot image become corrupted somehow.)");
}
ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)",
ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08"PRIx32")",
running->type, running->subtype, running->address);

esp_http_client_config_t config = {
Expand Down Expand Up @@ -134,7 +135,7 @@ static void ota_example_task(void *pvParameter)

update_partition = esp_ota_get_next_update_partition(NULL);
assert(update_partition != NULL);
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%"PRIx32,
update_partition->subtype, update_partition->address);

int binary_file_length = 0;
Expand Down
1 change: 0 additions & 1 deletion examples/system/pthread/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "pthread_example.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Loading

0 comments on commit fe18c89

Please sign in to comment.