Wifi station example and ESP32-S2

timokett
Posts: 7
Joined: Thu Jun 17, 2021 11:19 am

Wifi station example and ESP32-S2

Postby timokett » Thu Jun 17, 2021 12:23 pm

I have been going through the ESP32 sample codes in examples folder.
I have ESP32-S2 WROVER and I am using internal USB CDC instead of serial converter.
When I build and run the sample examples/wifi/getting_started/station, I get no console output.
The device seems to reboot in a loop idf.py monitor saying:

device reports readiness to read but returned no data (device disconnected or multiple access on port?)
Waiting for the device to reconnect..
device reports readiness to read but returned no data (device disconnected or multiple access on port?)
Waiting for the device to reconnect.


The app has following code (printf by me):
  1. void app_main(void)
  2. {
  3.     printf("** started\n");
  4.     //Initialize NVS
  5.     esp_err_t ret = nvs_flash_init();
  6.     printf("** initialized\n");
  7.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  8.       ESP_ERROR_CHECK(nvs_flash_erase());
  9.       ret = nvs_flash_init();
  10.     }
  11.     ESP_ERROR_CHECK(ret);
  12.     ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
  13.     wifi_init_sta();
  14. }
This outputs nothing.

If I comment the nvs_flash_init and related error checks away, I get the printf outputs but the app fails later, of course.
Should this station sample work with ESP32-S2? Any ideas?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Wifi station example and ESP32-S2

Postby ESP_Sprite » Fri Jun 18, 2021 12:28 am

Could be a brownout. What's the power supply to the S2 look like? If you're using a devboard, perhaps try a different USB cable?

timokett
Posts: 7
Joined: Thu Jun 17, 2021 11:19 am

Re: Wifi station example and ESP32-S2

Postby timokett » Tue Jun 22, 2021 3:25 pm

Brownout is not likely since the dev board supports lipo battery and I have it also connected.

bbinet
Posts: 6
Joined: Tue Jun 22, 2021 10:36 pm

Re: Wifi station example and ESP32-S2

Postby bbinet » Tue Jun 22, 2021 10:46 pm

I have the exact same issue.
I've tried with multiple USB cables but the issue remains.
If I make a basic example which only make the ESP32S2 led to blink, but does not use the NVS nor call nvs_flash_init(); then the device led blinks as expected and the usb console works perfectly.
So there must be an issue with the NVS stuff.
I tried to erase_flash the device, but it does not help: same issue after the flash has been erased.

timokett
Posts: 7
Joined: Thu Jun 17, 2021 11:19 am

Re: Wifi station example and ESP32-S2

Postby timokett » Wed Jun 23, 2021 6:09 pm

I now found out that when I loop a while before going into nv_init, it works.
I merged the led blink example with station example to add few blinks at the beginning:
  1. void app_main(void)
  2. {
  3.     ESP_LOGI(TAG, "Started");
  4.    
  5.     #if 1
  6.     /* Configure the peripheral according to the LED type */
  7.     configure_led();
  8.     int times = 5;
  9.     while (--times > 0) {
  10.         ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
  11.         blink_led();
  12.         /* Toggle the LED state */
  13.         s_led_state = !s_led_state;
  14.         vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
  15.     }
  16.     #endif
  17.  
  18.     printf("** started\n");
  19.     //Initialize NVS
  20.     esp_err_t ret = nvs_flash_init();
  21. ....
When blinking is included, the code works fine. When it is not (#if 0), it behaves as before.
I will experiment more later, now I will be five days away...

ESP32-S2-WROVER-DevKit-LiPo-USB

bbinet
Posts: 6
Joined: Tue Jun 22, 2021 10:36 pm

Re: Wifi station example and ESP32-S2

Postby bbinet » Thu Jun 24, 2021 7:28 am

Waiting a few sec before initializing NVS indeed fix the issue.
This is an easy workaround, thank you @timokett.

timokett
Posts: 7
Joined: Thu Jun 17, 2021 11:19 am

Re: Wifi station example and ESP32-S2

Postby timokett » Wed Jul 07, 2021 6:38 am

I found out that 500 ms is enough, 100 ms was not.
So I added this in the beginning and it works fine:

Code: Select all

vTaskDelay(500 / portTICK_PERIOD_MS);

Who is online

Users browsing this forum: No registered users and 203 guests