@@ -33,11 +33,13 @@ static const char *TAG = "cp wifi";
3333
3434#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
3535
36+ #include "esp-idf/components/heap/include/esp_heap_caps.h"
37+
3638wifi_radio_obj_t common_hal_wifi_radio_obj ;
3739
3840static void event_handler (void * arg , esp_event_base_t event_base ,
3941 int32_t event_id , void * event_data ) {
40- ESP_LOGI (TAG , "event" );
42+ ESP_LOGI (TAG , "event %x" , event_id );
4143 wifi_radio_obj_t * radio = arg ;
4244 if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE ) {
4345 xEventGroupSetBits (radio -> event_group_handle , WIFI_SCAN_DONE_BIT );
@@ -65,16 +67,20 @@ static void event_handler(void* arg, esp_event_base_t event_base,
6567static bool wifi_inited ;
6668
6769void common_hal_wifi_init (void ) {
68- ESP_LOGI (TAG , "init" );
70+ ESP_EARLY_LOGI (TAG , "init" );
71+ heap_caps_print_heap_info (MALLOC_CAP_8BIT );
6972 wifi_inited = true;
7073 common_hal_wifi_radio_obj .base .type = & wifi_radio_type ;
7174
7275 ESP_ERROR_CHECK (esp_netif_init ());
7376
77+ ESP_EARLY_LOGI (TAG , "create event loop" );
7478 ESP_ERROR_CHECK (esp_event_loop_create_default ());
75- esp_netif_create_default_wifi_sta ();
7679
80+ ESP_EARLY_LOGI (TAG , "create wifi sta" );
7781 wifi_radio_obj_t * self = & common_hal_wifi_radio_obj ;
82+ self -> netif = esp_netif_create_default_wifi_sta ();
83+
7884 self -> event_group_handle = xEventGroupCreateStatic (& self -> event_group );
7985 ESP_ERROR_CHECK (esp_event_handler_instance_register (WIFI_EVENT ,
8086 ESP_EVENT_ANY_ID ,
@@ -88,13 +94,15 @@ void common_hal_wifi_init(void) {
8894 self -> handler_instance_got_ip ));
8995
9096
97+ ESP_EARLY_LOGI (TAG , "wifi init" );
9198 wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT ();
9299 esp_err_t result = esp_wifi_init (& config );
93100 if (result == ESP_ERR_NO_MEM ) {
94101 mp_raise_msg (& mp_type_MemoryError , translate ("Failed to allocate Wifi memory" ));
95102 } else if (result != ESP_OK ) {
96103 // handle this
97104 }
105+ ESP_EARLY_LOGI (TAG , "enable radio" );
98106 common_hal_wifi_radio_set_enabled (self , true);
99107}
100108
@@ -111,5 +119,8 @@ void wifi_reset(void) {
111119 ESP_ERROR_CHECK (esp_event_handler_instance_unregister (IP_EVENT ,
112120 IP_EVENT_STA_GOT_IP ,
113121 radio -> handler_instance_got_ip ));
114- esp_wifi_deinit ();
122+ ESP_ERROR_CHECK (esp_wifi_deinit ());
123+ esp_netif_destroy (radio -> netif );
124+ radio -> netif = NULL ;
125+ ESP_ERROR_CHECK (esp_netif_deinit ());
115126}
0 commit comments