drivers: esp32: wifi/bt: modify init call return error

Update both Wi-FI and BLE init codes to return proper
error code and logging when it is missing heap.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
This commit is contained in:
Sylvio Alves 2024-10-07 17:22:58 -03:00 committed by Carles Cufí
parent 5e225e0c8b
commit 882ac1d088
2 changed files with 15 additions and 6 deletions

View file

@ -289,15 +289,19 @@ static int bt_esp32_ble_init(void)
#endif #endif
ret = esp_bt_controller_init(&bt_cfg); ret = esp_bt_controller_init(&bt_cfg);
if (ret) { if (ret == ESP_ERR_NO_MEM) {
LOG_ERR("Bluetooth controller init failed %d", ret); LOG_ERR("Not enough memory to initialize Bluetooth.");
return ret; LOG_ERR("Consider increasing CONFIG_HEAP_MEM_POOL_SIZE value.");
return -ENOMEM;
} else if (ret != ESP_OK) {
LOG_ERR("Unable to initialize the Bluetooth: %d", ret);
return -EIO;
} }
ret = esp_bt_controller_enable(mode); ret = esp_bt_controller_enable(mode);
if (ret) { if (ret) {
LOG_ERR("Bluetooth controller enable failed: %d", ret); LOG_ERR("Bluetooth controller enable failed: %d", ret);
return ret; return -EIO;
} }
esp_vhci_host_register_callback(&vhci_host_cb); esp_vhci_host_register_callback(&vhci_host_cb);

View file

@ -874,8 +874,13 @@ static int esp32_wifi_dev_init(const struct device *dev)
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT(); wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
esp_err_t ret = esp_wifi_init(&config); esp_err_t ret = esp_wifi_init(&config);
if (ret != ESP_OK) { if (ret == ESP_ERR_NO_MEM) {
LOG_ERR("Unable to initialize the wifi"); LOG_ERR("Not enough memory to initialize Wi-Fi.");
LOG_ERR("Consider increasing CONFIG_HEAP_MEM_POOL_SIZE value.");
return -ENOMEM;
} else if (ret != ESP_OK) {
LOG_ERR("Unable to initialize the Wi-Fi: %d", ret);
return -EIO;
} }
if (IS_ENABLED(CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4)) { if (IS_ENABLED(CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4)) {