Просмотр исходного кода

Merge branch 'bugfix/esp_err_linux_target' into 'master'

esp_common: make esp_err_to_name and ESP_ERROR_CHECK usable on Linux target

Closes IDF-2693

See merge request espressif/esp-idf!19569
Ivan Grokhotkov 3 лет назад
Родитель
Сommit
ea5fda812b

+ 6 - 4
components/esp_common/CMakeLists.txt

@@ -1,9 +1,11 @@
 idf_build_get_property(target IDF_TARGET)
 
 if(${target} STREQUAL "linux")
-    # Header only library for linux
-    idf_component_register(INCLUDE_DIRS include)
-    return()
+    set(ldfragments)
+    set(srcs "src/esp_err_check_linux.c")
+else()
+    set(ldfragments common.lf soc.lf)
+    set(srcs)
 endif()
 
 list(APPEND srcs "src/esp_err_to_name.c")
@@ -11,7 +13,7 @@ list(APPEND srcs "src/esp_err_to_name.c")
 # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here.
 idf_component_register(SRCS "${srcs}"
                         INCLUDE_DIRS include
-                        LDFRAGMENTS "common.lf" "soc.lf")
+                        LDFRAGMENTS ${ldfragments})
 
 set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 4)
 

+ 11 - 1
components/nvs_flash/test_nvs_host/esp_error_check_stub.cpp → components/esp_common/src/esp_err_check_linux.c

@@ -1,4 +1,14 @@
-#include "catch.hpp"
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * This file provides a simple version of _esp_error_check_failed which is used on Linux target.
+ * For chip targets, esp_system component provides an implementation which uses esp_rom_printf and
+ * takes the possibility of the cache being disabled into account.
+ */
+#include <stdio.h>
+#include <stdlib.h>
 #include "esp_err.h"
 #include "sdkconfig.h"
 

+ 4 - 0
components/esp_common/src/esp_err_to_name.c

@@ -7,6 +7,10 @@
 //Do not edit this file because it is autogenerated by gen_esp_err_to_name.py
 
 #include <string.h>
+#if __has_include(<bsd/string.h>)
+// for strlcpy
+#include <bsd/string.h>
+#endif
 #include "esp_err.h"
 #if __has_include("soc/soc.h")
 #include "soc/soc.h"

+ 4 - 0
components/esp_common/src/esp_err_to_name.c.in

@@ -7,6 +7,10 @@
 @COMMENT@
 
 #include <string.h>
+#if __has_include(<bsd/string.h>)
+// for strlcpy
+#include <bsd/string.h>
+#endif
 #include "esp_err.h"
 #if __has_include("soc/soc.h")
 #include "soc/soc.h"

+ 1 - 2
components/nvs_flash/test_nvs_host/Makefile

@@ -2,7 +2,6 @@ TEST_PROGRAM=test_nvs
 all: $(TEST_PROGRAM)
 
 SOURCE_FILES = \
-	esp_error_check_stub.cpp \
 	$(addprefix ../src/, \
 		nvs_types.cpp \
 		nvs_api.cpp \
@@ -30,7 +29,7 @@ SOURCE_FILES = \
 	test_nvs_initialization.cpp \
 	main.cpp
 
-SOURCE_FILES_C = ../../esp_rom/linux/esp_rom_crc.c
+SOURCE_FILES_C = ../../esp_rom/linux/esp_rom_crc.c ../../esp_common/src/esp_err_check_linux.c
 
 ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
 COMPILER := clang

+ 0 - 8
examples/protocols/sockets/tcp_client/components/esp_stubs/esp_stubs/esp_stubs.c

@@ -9,14 +9,6 @@
 
 extern void app_main(void);
 
-void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
-{
-    ESP_LOGE("ESP_ERROR_CHECK", "Failed with esp_err_t: 0x%x", rc);
-    ESP_LOGE("ESP_ERROR_CHECK", "Expression: %s", expression);
-    ESP_LOGE("ESP_ERROR_CHECK", "Functions: %s %s(%d)", function, file, line);
-    abort();
-}
-
 esp_err_t esp_event_loop_create_default(void)
 {
     return ESP_OK;