From ea19838d3a9e4dc100a90209fa4e4084577521d0 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 16 Jan 2017 11:52:15 +1100 Subject: [PATCH] Build: Handle WiFi & BT enabled/disabled combos gracefully as possible If using WIFI_INIT_CONFIG_DEFAULT, error message will point out lack of WiFi. Otherwise linker errors on WiFi symbols should help give a clue as to what is broken. Piggy-backs on changes in !420, ref github #230 #237 --- components/esp32/component.mk | 9 ++++++++- components/esp32/include/esp_wifi.h | 6 +++++- components/esp32/system_api.c | 3 +++ examples/02_blink/sdkconfig.defaults | 2 ++ examples/14_gatt_server/sdkconfig.defaults | 7 ++----- examples/15_gatt_client/sdkconfig.defaults | 7 ++----- 6 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 examples/02_blink/sdkconfig.defaults diff --git a/components/esp32/component.mk b/components/esp32/component.mk index 4ceb13e83..e1cd2c652 100644 --- a/components/esp32/component.mk +++ b/components/esp32/component.mk @@ -3,8 +3,15 @@ # COMPONENT_SRCDIRS := . hwcrypto +LIBS := core rtc phy +ifdef CONFIG_BT_ENABLED +LIBS += coexist +endif +ifdef CONFIG_WIFI_ENABLED +LIBS += net80211 pp wpa smartconfig coexist wps wpa2 +endif -LIBS := core net80211 phy rtc pp wpa smartconfig coexist wps wpa2 +LIBS := $(sort $(LIBS)) # de-duplicate, we can handle different orders here LINKER_SCRIPTS += esp32.common.ld esp32.rom.ld esp32.peripherals.ld diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index 197a04fd3..8d4fa17bb 100755 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -62,6 +62,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "rom/queue.h" +#include "sdkconfig.h" #include "esp_err.h" #include "esp_wifi_types.h" #include "esp_event.h" @@ -97,11 +98,14 @@ typedef struct { uint32_t rx_buf_num; /**< WiFi RX buffer number */ } wifi_init_config_t; - +#ifdef CONFIG_WIFI_ENABLED #define WIFI_INIT_CONFIG_DEFAULT() { \ .event_handler = &esp_event_send, \ .rx_buf_num = CONFIG_ESP32_WIFI_RX_BUFFER_NUM, \ }; +#else +#define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work +#endif /** * @brief Init WiFi diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 60fa1796c..bfc0f0752 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -17,6 +17,7 @@ #include "esp_wifi.h" #include "esp_wifi_internal.h" #include "esp_log.h" +#include "sdkconfig.h" #include "rom/efuse.h" #include "rom/cache.h" #include "rom/uart.h" @@ -74,7 +75,9 @@ esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__((alias("esp_efuse_ void IRAM_ATTR esp_restart(void) { +#ifdef CONFIG_WIFI_ENABLED esp_wifi_stop(); +#endif // Disable scheduler on this core. vTaskSuspendAll(); diff --git a/examples/02_blink/sdkconfig.defaults b/examples/02_blink/sdkconfig.defaults new file mode 100644 index 000000000..8c618fb9b --- /dev/null +++ b/examples/02_blink/sdkconfig.defaults @@ -0,0 +1,2 @@ +# Disable WiFi stack by default +CONFIG_WIFI_ENABLED=n diff --git a/examples/14_gatt_server/sdkconfig.defaults b/examples/14_gatt_server/sdkconfig.defaults index dcf4ad2c2..9d51df5ee 100644 --- a/examples/14_gatt_server/sdkconfig.defaults +++ b/examples/14_gatt_server/sdkconfig.defaults @@ -1,7 +1,4 @@ # Override some defaults so BT stack is enabled -# in this example - -# -# BT config -# +# and WiFi disabled by default in this example CONFIG_BT_ENABLED=y +CONFIG_WIFI_ENABLED=n diff --git a/examples/15_gatt_client/sdkconfig.defaults b/examples/15_gatt_client/sdkconfig.defaults index dcf4ad2c2..9d51df5ee 100644 --- a/examples/15_gatt_client/sdkconfig.defaults +++ b/examples/15_gatt_client/sdkconfig.defaults @@ -1,7 +1,4 @@ # Override some defaults so BT stack is enabled -# in this example - -# -# BT config -# +# and WiFi disabled by default in this example CONFIG_BT_ENABLED=y +CONFIG_WIFI_ENABLED=n