ESP32-S2 Mini, the board often reboots or hang when going into WIFI_AP_STA mode

Please Help

Board: ESP32 S2 Mini Board
IDE: Arduino IDE 2.2.1

I’m working with an ESP32-S2 Mini (WEMOS S2 mini), and I’ve been struggling with an issue for the past couple of weeks. Whenever I try to set the Wi-Fi mode to WIFI_AP_STA, the board either reboots or just gets stuck right after printing the first couple of lines in the Serial Monitor.

Here’s the line that causes the problem:
WiFi.mode(WIFI_AP_STA);

If I comment out this line, the code runs smoothly without any issues.

Also I went through the below post which looks similar to my issue. But it couldn't help.

I would be really grateful if anyone could kindly guide me or suggest what I should check or try. Any help, even small hints, would mean a lot.

Thank you in advance for your time and support.

Code:

#include <WiFi.h>

#if !defined( ESP32 )
  #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif

#define ERROR_LED 15
#define MAX_CONNECTION 8

/* Set these to station Wifi credentials. */    
const char* ap_ssid = "ESP32-S2";      // give Accesspoint SSID, your esp's hotspot name 
const char* ap_password = "PASSWORD";  // password of your esp's hotspot
const char* wifiSSID = "MTS_PARADISE"; // SSID of your Router OR mobile hotspot
const char* wifiPW   = "9988776677";    // PASSWORD of your Router or Mobile hotspot

//=====Define the IP Address of the hotspot======
IPAddress ip (10, 10, 10, 11);
IPAddress gateway (10, 10, 10, 1);
IPAddress subnet (255, 255, 255, 0);

void setup() {
  Serial.begin(9600);//to enable Serial Commmunication with connected esp32 S2 Mini board
  while(!Serial); 
  if(Serial.available()) Serial.readString();
  Serial.flush();
  
  pinMode(ERROR_LED, OUTPUT);

  Serial.println ("Before WIFI_AP_STA ..1");
  Serial.println ("Before WIFI_AP_STA ..2");

 delay(5000);
  WiFi.mode(WIFI_AP_STA);
}

void loop() {
  digitalWrite(ERROR_LED, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                    // wait for a second
  digitalWrite(ERROR_LED, LOW);   // turn the LED off by making the voltage LOW
  delay(500);                     // wait for half a second

  Serial.println ("Hello Wifi.");
}

Just a wild hunch, but comment out the 3 lines after Serial.begin(9600); and replace with delay(3000);

Still Rebooting

Try changing to this

  WiFi.STA.begin();       // required for ESP32 core 3 to get MAC address ??
  WiFi.mode(WIFI_AP_STA);

OR change esp32 boards back to 2.0.17.
I don't have problems but my codse looks nothing like yours, where did you get an example that tells you that is how to code it?

Sorry, I just tried your code and it works as it should so your board must be damaged. Here is screen shot.

Solution is there is NO problem.

Hi @sonofcy
The same code works fine on my ESP32-WROOM-32 (38-pin).
I have two ESP32-S2 Mini boards, and the Wi-Fi part of the code doesn’t work on either of them, though non-Wi-Fi functions run fine. I’m connecting the board to my laptop with a Type-C cable, so I believe the hardware is okay.

I’m just wondering—are you also using the same board, the ESP32-S2 Mini (picture attached below)?

Output Log:

Sketch uses 876818 bytes (66%) of program storage space. Maximum is 1310720 bytes.
Global variables use 58016 bytes (17%) of dynamic memory, leaving 269664 bytes for local variables. Maximum is 327680 bytes.
"C:\Users\sahoo\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\5.1.0/esptool.exe" --chip esp32s2 --port "COM3" --baud 921600  --before default-reset --after hard-reset write-flash  -z --flash-mode keep --flash-freq keep --flash-size keep 0x1000 "C:\Users\sahoo\AppData\Local\Temp\arduino\sketches\606239953CDC063229AC330A56971643/ESP32-S2-Mini_Wifi_AP-STA_Test.ino.bootloader.bin" 0x8000 "C:\Users\sahoo\AppData\Local\Temp\arduino\sketches\606239953CDC063229AC330A56971643/ESP32-S2-Mini_Wifi_AP-STA_Test.ino.partitions.bin" 0xe000 "C:\Users\sahoo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.1/tools/partitions/boot_app0.bin" 0x10000 "C:\Users\sahoo\AppData\Local\Temp\arduino\sketches\606239953CDC063229AC330A56971643/ESP32-S2-Mini_Wifi_AP-STA_Test.ino.bin" 
esptool v5.1.0
Serial port COM3:
Connecting...
Connected to ESP32-S2 on COM3:
Chip type:          ESP32-S2FNR2 (revision v0.0)
Features:           Wi-Fi, Single Core, 240MHz, Embedded Flash 4MB, Embedded PSRAM 2MB, ADC and temperature sensor calibration in BLK2 of eFuse V1
Crystal frequency:  40MHz
USB mode:           USB-OTG
MAC:                84:f7:03:f2:d9:68

Uploading stub flasher...
Running stub flasher...
Stub flasher running.
Changing baud rate to 921600...
Changed.

Configuring flash size...
Flash will be erased from 0x00001000 to 0x00006fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x000e6fff...
Compressed 21152 bytes to 13549...

Writing at 0x00001000 [                              ]   0.0% 0/13549 bytes... 

Writing at 0x000022a3 [===>                          ]  15.1% 2048/13549 bytes... 

Writing at 0x00002df9 [========>                     ]  30.2% 4096/13549 bytes... 

Writing at 0x00003a44 [============>                 ]  45.3% 6144/13549 bytes... 

Writing at 0x000044c5 [=================>            ]  60.5% 8192/13549 bytes... 

Writing at 0x00004ead [=====================>        ]  75.6% 10240/13549 bytes... 

Writing at 0x00005ac4 [==========================>   ]  90.7% 12288/13549 bytes... 

Writing at 0x000062a0 [==============================] 100.0% 13549/13549 bytes... 
Wrote 21152 bytes (13549 compressed) at 0x00001000 in 0.4 seconds (421.0 kbit/s).
Hash of data verified.
Compressed 3072 bytes to 146...

Writing at 0x00008000 [                              ]   0.0% 0/146 bytes... 

Writing at 0x00008c00 [==============================] 100.0% 146/146 bytes... 
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (340.8 kbit/s).
Hash of data verified.
Compressed 8192 bytes to 47...

Writing at 0x0000e000 [                              ]   0.0% 0/47 bytes... 

Writing at 0x00010000 [==============================] 100.0% 47/47 bytes... 
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (560.1 kbit/s).
Hash of data verified.
Compressed 876960 bytes to 568127...

Writing at 0x00010000 [                              ]   0.0% 0/568127 bytes... 

Writing at 0x000110a3 [                              ]   0.4% 2048/568127 bytes... 

Writing at 0x00012518 [                              ]   0.7% 4096/568127 bytes... 

Writing at 0x0001413c [                              ]   1.1% 6144/568127 bytes... 

Writing at 0x000159ac [                              ]   1.4% 8192/568127 bytes... 

Writing at 0x00017461 [                              ]   1.8% 10240/568127 bytes... 

Writing at 0x00018dae [                              ]   2.2% 12288/568127 bytes... 

Writing at 0x0001a779 [                              ]   2.5% 14336/568127 bytes... 

Writing at 0x0001c767 [                              ]   2.9% 16384/568127 bytes... 

Writing at 0x0001e000 [                              ]   3.2% 18432/568127 bytes... 

Writing at 0x0001f6b1 [>                             ]   3.6% 20480/568127 bytes... 

Writing at 0x0002083c [>                             ]   4.0% 22528/568127 bytes... 

Writing at 0x000219ee [>                             ]   4.3% 24576/568127 bytes... 

Writing at 0x00023068 [>                             ]   4.7% 26624/568127 bytes... 

Writing at 0x00024106 [>                             ]   5.0% 28672/568127 bytes... 

Writing at 0x000255b4 [>                             ]   5.4% 30720/568127 bytes... 

Writing at 0x000262b7 [>                             ]   5.8% 32768/568127 bytes... 

Writing at 0x00026edb [>                             ]   6.1% 34816/568127 bytes... 

Writing at 0x00027695 [>                             ]   6.5% 36864/568127 bytes... 

Writing at 0x00028631 [=>                            ]   6.8% 38912/568127 bytes... 

Writing at 0x00029d29 [=>                            ]   7.2% 40960/568127 bytes... 

Writing at 0x0002b36d [=>                            ]   7.6% 43008/568127 bytes... 

Writing at 0x0002e2cc [=>                            ]   7.9% 45056/568127 bytes... 

Writing at 0x00031149 [=>                            ]   8.3% 47104/568127 bytes... 

Writing at 0x00033aac [=>                            ]   8.7% 49152/568127 bytes... 

Writing at 0x00035550 [=>                            ]   9.0% 51200/568127 bytes... 

Writing at 0x00036a52 [=>                            ]   9.4% 53248/568127 bytes... 

Writing at 0x000375e0 [=>                            ]   9.7% 55296/568127 bytes... 

Writing at 0x0003814e [==>                           ]  10.1% 57344/568127 bytes... 

Writing at 0x00038b67 [==>                           ]  10.5% 59392/568127 bytes... 

Writing at 0x00039747 [==>                           ]  10.8% 61440/568127 bytes... 

Writing at 0x0003a23a [==>                           ]  11.2% 63488/568127 bytes... 

Writing at 0x0003aefb [==>                           ]  11.5% 65536/568127 bytes... 

Writing at 0x0003baa1 [==>                           ]  11.9% 67584/568127 bytes... 

Writing at 0x0003c632 [==>                           ]  12.3% 69632/568127 bytes... 

Writing at 0x0003d163 [==>                           ]  12.6% 71680/568127 bytes... 

Writing at 0x0003dddf [==>                           ]  13.0% 73728/568127 bytes... 

Writing at 0x0003e834 [===>                          ]  13.3% 75776/568127 bytes... 

Writing at 0x0003f2bf [===>                          ]  13.7% 77824/568127 bytes... 

Writing at 0x0003fe3f [===>                          ]  14.1% 79872/568127 bytes... 

Writing at 0x00040a89 [===>                          ]  14.4% 81920/568127 bytes... 

Writing at 0x00041744 [===>                          ]  14.8% 83968/568127 bytes... 

Writing at 0x00042323 [===>                          ]  15.1% 86016/568127 bytes... 

Writing at 0x00042e6b [===>                          ]  15.5% 88064/568127 bytes... 

Writing at 0x000438ce [===>                          ]  15.9% 90112/568127 bytes... 

Writing at 0x0004430d [===>                          ]  16.2% 92160/568127 bytes... 

Writing at 0x00044dad [===>                          ]  16.6% 94208/568127 bytes... 

Writing at 0x0004597f [====>                         ]  16.9% 96256/568127 bytes... 

Writing at 0x00046459 [====>                         ]  17.3% 98304/568127 bytes... 

Writing at 0x00046ef9 [====>                         ]  17.7% 100352/568127 bytes... 

Writing at 0x00047944 [====>                         ]  18.0% 102400/568127 bytes... 

Writing at 0x000484d7 [====>                         ]  18.4% 104448/568127 bytes... 

Writing at 0x00048e9c [====>                         ]  18.7% 106496/568127 bytes... 

Writing at 0x00049acf [====>                         ]  19.1% 108544/568127 bytes... 

Writing at 0x0004a50a [====>                         ]  19.5% 110592/568127 bytes... 

Writing at 0x0004af02 [====>                         ]  19.8% 112640/568127 bytes... 

Writing at 0x0004b94c [=====>                        ]  20.2% 114688/568127 bytes... 

Writing at 0x0004c453 [=====>                        ]  20.5% 116736/568127 bytes... 

Writing at 0x0004ce31 [=====>                        ]  20.9% 118784/568127 bytes... 

Writing at 0x0004d802 [=====>                        ]  21.3% 120832/568127 bytes... 

Writing at 0x0004e24b [=====>                        ]  21.6% 122880/568127 bytes... 

Writing at 0x0004ecef [=====>                        ]  22.0% 124928/568127 bytes... 

Writing at 0x0004f763 [=====>                        ]  22.3% 126976/568127 bytes... 

Writing at 0x0005029a [=====>                        ]  22.7% 129024/568127 bytes... 

Writing at 0x00050dc9 [=====>                        ]  23.1% 131072/568127 bytes... 

Writing at 0x00051808 [======>                       ]  23.4% 133120/568127 bytes... 

Writing at 0x000522a5 [======>                       ]  23.8% 135168/568127 bytes... 

Writing at 0x00052e08 [======>                       ]  24.2% 137216/568127 bytes... 

Writing at 0x00053853 [======>                       ]  24.5% 139264/568127 bytes... 

Writing at 0x00054346 [======>                       ]  24.9% 141312/568127 bytes... 

Writing at 0x00054ecd [======>                       ]  25.2% 143360/568127 bytes... 

Writing at 0x00055888 [======>                       ]  25.6% 145408/568127 bytes... 

Writing at 0x000562cf [======>                       ]  26.0% 147456/568127 bytes... 

Writing at 0x00056d09 [======>                       ]  26.3% 149504/568127 bytes... 

Writing at 0x000576e3 [=======>                      ]  26.7% 151552/568127 bytes... 

Writing at 0x000580d2 [=======>                      ]  27.0% 153600/568127 bytes... 

Writing at 0x00058af3 [=======>                      ]  27.4% 155648/568127 bytes... 

Writing at 0x000595a6 [=======>                      ]  27.8% 157696/568127 bytes... 

Writing at 0x00059f9e [=======>                      ]  28.1% 159744/568127 bytes... 

Writing at 0x0005aaca [=======>                      ]  28.5% 161792/568127 bytes... 

Writing at 0x0005b40a [=======>                      ]  28.8% 163840/568127 bytes... 

Writing at 0x0005be26 [=======>                      ]  29.2% 165888/568127 bytes... 

Writing at 0x0005c9fa [=======>                      ]  29.6% 167936/568127 bytes... 

Writing at 0x0005d3db [=======>                      ]  29.9% 169984/568127 bytes... 

Writing at 0x0005dedc [========>                     ]  30.3% 172032/568127 bytes... 

Writing at 0x0005e9c6 [========>                     ]  30.6% 174080/568127 bytes... 

Writing at 0x0005f3cb [========>                     ]  31.0% 176128/568127 bytes... 

Writing at 0x0005fe62 [========>                     ]  31.4% 178176/568127 bytes... 

Writing at 0x000607e9 [========>                     ]  31.7% 180224/568127 bytes... 

Writing at 0x000613cc [========>                     ]  32.1% 182272/568127 bytes... 

Writing at 0x00061de0 [========>                     ]  32.4% 184320/568127 bytes... 

Writing at 0x00062849 [========>                     ]  32.8% 186368/568127 bytes... 

Writing at 0x0006332d [========>                     ]  33.2% 188416/568127 bytes... 

Writing at 0x00063d6e [=========>                    ]  33.5% 190464/568127 bytes... 

Writing at 0x0006477f [=========>                    ]  33.9% 192512/568127 bytes... 

Writing at 0x000651af [=========>                    ]  34.2% 194560/568127 bytes... 

Writing at 0x00065cda [=========>                    ]  34.6% 196608/568127 bytes... 

Writing at 0x0006679b [=========>                    ]  35.0% 198656/568127 bytes... 

Writing at 0x00067118 [=========>                    ]  35.3% 200704/568127 bytes... 

Writing at 0x00067b25 [=========>                    ]  35.7% 202752/568127 bytes... 

Writing at 0x0006863d [=========>                    ]  36.0% 204800/568127 bytes... 

Writing at 0x000691f6 [=========>                    ]  36.4% 206848/568127 bytes... 

Writing at 0x00069d76 [==========>                   ]  36.8% 208896/568127 bytes... 

Writing at 0x0006a853 [==========>                   ]  37.1% 210944/568127 bytes... 

Writing at 0x0006b366 [==========>                   ]  37.5% 212992/568127 bytes... 

Writing at 0x0006bdf0 [==========>                   ]  37.9% 215040/568127 bytes... 

Writing at 0x0006c98d [==========>                   ]  38.2% 217088/568127 bytes... 

Writing at 0x0006d3c3 [==========>                   ]  38.6% 219136/568127 bytes... 

Writing at 0x0006ddef [==========>                   ]  38.9% 221184/568127 bytes... 

Writing at 0x0006e946 [==========>                   ]  39.3% 223232/568127 bytes... 

Writing at 0x0006f402 [==========>                   ]  39.7% 225280/568127 bytes... 

Writing at 0x0006fe82 [===========>                  ]  40.0% 227328/568127 bytes... 

Writing at 0x00070873 [===========>                  ]  40.4% 229376/568127 bytes... 

Writing at 0x00071276 [===========>                  ]  40.7% 231424/568127 bytes... 

Writing at 0x00071c72 [===========>                  ]  41.1% 233472/568127 bytes... 

Writing at 0x00072622 [===========>                  ]  41.5% 235520/568127 bytes... 

Writing at 0x00073008 [===========>                  ]  41.8% 237568/568127 bytes... 

Writing at 0x00073ac2 [===========>                  ]  42.2% 239616/568127 bytes... 

Writing at 0x0007452e [===========>                  ]  42.5% 241664/568127 bytes... 

Writing at 0x00074f7a [===========>                  ]  42.9% 243712/568127 bytes... 

Writing at 0x000759ed [===========>                  ]  43.3% 245760/568127 bytes... 

Writing at 0x000764b3 [============>                 ]  43.6% 247808/568127 bytes... 

Writing at 0x00076e9b [============>                 ]  44.0% 249856/568127 bytes... 

Writing at 0x00077889 [============>                 ]  44.3% 251904/568127 bytes... 

Writing at 0x0007828e [============>                 ]  44.7% 253952/568127 bytes... 

Writing at 0x00078cd9 [============>                 ]  45.1% 256000/568127 bytes... 

Writing at 0x000796d5 [============>                 ]  45.4% 258048/568127 bytes... 

Writing at 0x0007a169 [============>                 ]  45.8% 260096/568127 bytes... 

Writing at 0x0007ad6f [============>                 ]  46.1% 262144/568127 bytes... 

Writing at 0x0007b84a [============>                 ]  46.5% 264192/568127 bytes... 

Writing at 0x0007c30d [=============>                ]  46.9% 266240/568127 bytes... 

Writing at 0x0007cd73 [=============>                ]  47.2% 268288/568127 bytes... 

Writing at 0x0007d91b [=============>                ]  47.6% 270336/568127 bytes... 

Writing at 0x0007e4de [=============>                ]  47.9% 272384/568127 bytes... 

Writing at 0x0007eefd [=============>                ]  48.3% 274432/568127 bytes... 

Writing at 0x0007f9b1 [=============>                ]  48.7% 276480/568127 bytes... 

Writing at 0x00080547 [=============>                ]  49.0% 278528/568127 bytes... 

Writing at 0x00080fa1 [=============>                ]  49.4% 280576/568127 bytes... 

Writing at 0x00081b22 [=============>                ]  49.7% 282624/568127 bytes... 

Writing at 0x00082580 [==============>               ]  50.1% 284672/568127 bytes... 

Writing at 0x00082fec [==============>               ]  50.5% 286720/568127 bytes... 

Writing at 0x00083ac9 [==============>               ]  50.8% 288768/568127 bytes... 

Writing at 0x00084551 [==============>               ]  51.2% 290816/568127 bytes... 

Writing at 0x00084f95 [==============>               ]  51.5% 292864/568127 bytes... 

Writing at 0x00085a6f [==============>               ]  51.9% 294912/568127 bytes... 

Writing at 0x00086447 [==============>               ]  52.3% 296960/568127 bytes... 

Writing at 0x00086f5f [==============>               ]  52.6% 299008/568127 bytes... 

Writing at 0x00087994 [==============>               ]  53.0% 301056/568127 bytes... 

Writing at 0x000885f3 [===============>              ]  53.4% 303104/568127 bytes... 

Writing at 0x0008904e [===============>              ]  53.7% 305152/568127 bytes... 

Writing at 0x00089b5f [===============>              ]  54.1% 307200/568127 bytes... 

Writing at 0x0008a607 [===============>              ]  54.4% 309248/568127 bytes... 

Writing at 0x0008b089 [===============>              ]  54.8% 311296/568127 bytes... 

Writing at 0x0008ba1d [===============>              ]  55.2% 313344/568127 bytes... 

Writing at 0x0008c474 [===============>              ]  55.5% 315392/568127 bytes... 

Writing at 0x0008cf6d [===============>              ]  55.9% 317440/568127 bytes... 

Writing at 0x0008da03 [===============>              ]  56.2% 319488/568127 bytes... 

Writing at 0x0008e418 [===============>              ]  56.6% 321536/568127 bytes... 

Writing at 0x0008ef64 [================>             ]  57.0% 323584/568127 bytes... 

Writing at 0x0008f9e7 [================>             ]  57.3% 325632/568127 bytes... 

Writing at 0x0009052f [================>             ]  57.7% 327680/568127 bytes... 

Writing at 0x00091090 [================>             ]  58.0% 329728/568127 bytes... 

Writing at 0x00091c6a [================>             ]  58.4% 331776/568127 bytes... 

Writing at 0x00092668 [================>             ]  58.8% 333824/568127 bytes... 

Writing at 0x00093080 [================>             ]  59.1% 335872/568127 bytes... 

Writing at 0x00093ae4 [================>             ]  59.5% 337920/568127 bytes... 

Writing at 0x000944b2 [================>             ]  59.8% 339968/568127 bytes... 

Writing at 0x00094ed7 [=================>            ]  60.2% 342016/568127 bytes... 

Writing at 0x0009594b [=================>            ]  60.6% 344064/568127 bytes... 

Writing at 0x00096487 [=================>            ]  60.9% 346112/568127 bytes... 

Writing at 0x00096ecc [=================>            ]  61.3% 348160/568127 bytes... 

Writing at 0x00097953 [=================>            ]  61.6% 350208/568127 bytes... 

Writing at 0x000982d5 [=================>            ]  62.0% 352256/568127 bytes... 

Writing at 0x00098d1f [=================>            ]  62.4% 354304/568127 bytes... 

Writing at 0x000996e1 [=================>            ]  62.7% 356352/568127 bytes... 

Writing at 0x0009a14a [=================>            ]  63.1% 358400/568127 bytes... 

Writing at 0x0009ab3e [==================>           ]  63.4% 360448/568127 bytes... 

Writing at 0x0009b53f [==================>           ]  63.8% 362496/568127 bytes... 

Writing at 0x0009bf4a [==================>           ]  64.2% 364544/568127 bytes... 

Writing at 0x0009c975 [==================>           ]  64.5% 366592/568127 bytes... 

Writing at 0x0009d379 [==================>           ]  64.9% 368640/568127 bytes... 

Writing at 0x0009ddda [==================>           ]  65.2% 370688/568127 bytes... 

Writing at 0x0009eac2 [==================>           ]  65.6% 372736/568127 bytes... 

Writing at 0x0009f665 [==================>           ]  66.0% 374784/568127 bytes... 

Writing at 0x000a01e9 [==================>           ]  66.3% 376832/568127 bytes... 

Writing at 0x000a0cbe [===================>          ]  66.7% 378880/568127 bytes... 

Writing at 0x000a175e [===================>          ]  67.0% 380928/568127 bytes... 

Writing at 0x000a2243 [===================>          ]  67.4% 382976/568127 bytes... 

Writing at 0x000a2ca0 [===================>          ]  67.8% 385024/568127 bytes... 

Writing at 0x000a369a [===================>          ]  68.1% 387072/568127 bytes... 

Writing at 0x000a4405 [===================>          ]  68.5% 389120/568127 bytes... 

Writing at 0x000a4d7d [===================>          ]  68.9% 391168/568127 bytes... 

Writing at 0x000a5783 [===================>          ]  69.2% 393216/568127 bytes... 

Writing at 0x000a6243 [===================>          ]  69.6% 395264/568127 bytes... 

Writing at 0x000a6d39 [===================>          ]  69.9% 397312/568127 bytes... 

Writing at 0x000a7942 [====================>         ]  70.3% 399360/568127 bytes... 

Writing at 0x000a83fe [====================>         ]  70.7% 401408/568127 bytes... 

Writing at 0x000a8e88 [====================>         ]  71.0% 403456/568127 bytes... 

Writing at 0x000a999a [====================>         ]  71.4% 405504/568127 bytes... 

Writing at 0x000aa3f5 [====================>         ]  71.7% 407552/568127 bytes... 

Writing at 0x000aaddb [====================>         ]  72.1% 409600/568127 bytes... 

Writing at 0x000ab859 [====================>         ]  72.5% 411648/568127 bytes... 

Writing at 0x000ac3b1 [====================>         ]  72.8% 413696/568127 bytes... 

Writing at 0x000acf05 [====================>         ]  73.2% 415744/568127 bytes... 

Writing at 0x000ad917 [=====================>        ]  73.5% 417792/568127 bytes... 

Writing at 0x000ae386 [=====================>        ]  73.9% 419840/568127 bytes... 

Writing at 0x000aeed9 [=====================>        ]  74.3% 421888/568127 bytes... 

Writing at 0x000af8e7 [=====================>        ]  74.6% 423936/568127 bytes... 

Writing at 0x000b03d6 [=====================>        ]  75.0% 425984/568127 bytes... 

Writing at 0x000b0d89 [=====================>        ]  75.3% 428032/568127 bytes... 

Writing at 0x000b17c0 [=====================>        ]  75.7% 430080/568127 bytes... 

Writing at 0x000b2237 [=====================>        ]  76.1% 432128/568127 bytes... 

Writing at 0x000b2d4e [=====================>        ]  76.4% 434176/568127 bytes... 

Writing at 0x000b379d [======================>       ]  76.8% 436224/568127 bytes... 

Writing at 0x000b426e [======================>       ]  77.1% 438272/568127 bytes... 

Writing at 0x000b4dfe [======================>       ]  77.5% 440320/568127 bytes... 

Writing at 0x000b59bc [======================>       ]  77.9% 442368/568127 bytes... 

Writing at 0x000b648a [======================>       ]  78.2% 444416/568127 bytes... 

Writing at 0x000b6fe0 [======================>       ]  78.6% 446464/568127 bytes... 

Writing at 0x000b79d6 [======================>       ]  78.9% 448512/568127 bytes... 

Writing at 0x000b846e [======================>       ]  79.3% 450560/568127 bytes... 

Writing at 0x000b8f14 [======================>       ]  79.7% 452608/568127 bytes... 

Writing at 0x000b9c03 [=======================>      ]  80.0% 454656/568127 bytes... 

Writing at 0x000ba95e [=======================>      ]  80.4% 456704/568127 bytes... 

Writing at 0x000bb6cc [=======================>      ]  80.7% 458752/568127 bytes... 

Writing at 0x000bc32a [=======================>      ]  81.1% 460800/568127 bytes... 

Writing at 0x000bcfd9 [=======================>      ]  81.5% 462848/568127 bytes... 

Writing at 0x000bdb74 [=======================>      ]  81.8% 464896/568127 bytes... 

Writing at 0x000be8d2 [=======================>      ]  82.2% 466944/568127 bytes... 

Writing at 0x000bf24e [=======================>      ]  82.6% 468992/568127 bytes... 

Writing at 0x000bfcb3 [=======================>      ]  82.9% 471040/568127 bytes... 

Writing at 0x000c0709 [=======================>      ]  83.3% 473088/568127 bytes... 

Writing at 0x000c11da [========================>     ]  83.6% 475136/568127 bytes... 

Writing at 0x000c1c53 [========================>     ]  84.0% 477184/568127 bytes... 

Writing at 0x000c266b [========================>     ]  84.4% 479232/568127 bytes... 

Writing at 0x000c3153 [========================>     ]  84.7% 481280/568127 bytes... 

Writing at 0x000c3d6f [========================>     ]  85.1% 483328/568127 bytes... 

Writing at 0x000c487d [========================>     ]  85.4% 485376/568127 bytes... 

Writing at 0x000c5230 [========================>     ]  85.8% 487424/568127 bytes... 

Writing at 0x000c5cf2 [========================>     ]  86.2% 489472/568127 bytes... 

Writing at 0x000c72fc [========================>     ]  86.5% 491520/568127 bytes... 

Writing at 0x000c8548 [=========================>    ]  86.9% 493568/568127 bytes... 

Writing at 0x000c97c7 [=========================>    ]  87.2% 495616/568127 bytes... 

Writing at 0x000ca6d7 [=========================>    ]  87.6% 497664/568127 bytes... 

Writing at 0x000cd8a2 [=========================>    ]  88.0% 499712/568127 bytes... 

Writing at 0x000cf52a [=========================>    ]  88.3% 501760/568127 bytes... 

Writing at 0x000d0084 [=========================>    ]  88.7% 503808/568127 bytes... 

Writing at 0x000d0b4e [=========================>    ]  89.0% 505856/568127 bytes... 

Writing at 0x000d1804 [=========================>    ]  89.4% 507904/568127 bytes... 

Writing at 0x000d24ce [=========================>    ]  89.8% 509952/568127 bytes... 

Writing at 0x000d305f [==========================>   ]  90.1% 512000/568127 bytes... 

Writing at 0x000d3c99 [==========================>   ]  90.5% 514048/568127 bytes... 

Writing at 0x000d45f3 [==========================>   ]  90.8% 516096/568127 bytes... 

Writing at 0x000d500c [==========================>   ]  91.2% 518144/568127 bytes... 

Writing at 0x000d5a77 [==========================>   ]  91.6% 520192/568127 bytes... 

Writing at 0x000d64da [==========================>   ]  91.9% 522240/568127 bytes... 

Writing at 0x000d6f43 [==========================>   ]  92.3% 524288/568127 bytes... 

Writing at 0x000d78b6 [==========================>   ]  92.6% 526336/568127 bytes... 

Writing at 0x000d8281 [==========================>   ]  93.0% 528384/568127 bytes... 

Writing at 0x000d8c46 [===========================>  ]  93.4% 530432/568127 bytes... 

Writing at 0x000d96b2 [===========================>  ]  93.7% 532480/568127 bytes... 

Writing at 0x000da112 [===========================>  ]  94.1% 534528/568127 bytes... 

Writing at 0x000dab6a [===========================>  ]  94.4% 536576/568127 bytes... 

Writing at 0x000db63e [===========================>  ]  94.8% 538624/568127 bytes... 

Writing at 0x000dc272 [===========================>  ]  95.2% 540672/568127 bytes... 

Writing at 0x000dcdb2 [===========================>  ]  95.5% 542720/568127 bytes... 

Writing at 0x000dd749 [===========================>  ]  95.9% 544768/568127 bytes... 

Writing at 0x000de3ba [===========================>  ]  96.2% 546816/568127 bytes... 

Writing at 0x000dee7b [===========================>  ]  96.6% 548864/568127 bytes... 

Writing at 0x000df9d3 [============================> ]  97.0% 550912/568127 bytes... 

Writing at 0x000e07c3 [============================> ]  97.3% 552960/568127 bytes... 

Writing at 0x000e12c2 [============================> ]  97.7% 555008/568127 bytes... 

Writing at 0x000e21e7 [============================> ]  98.1% 557056/568127 bytes... 

Writing at 0x000e2e92 [============================> ]  98.4% 559104/568127 bytes... 

Writing at 0x000e38de [============================> ]  98.8% 561152/568127 bytes... 

Writing at 0x000e4425 [============================> ]  99.1% 563200/568127 bytes... 

Writing at 0x000e4ea1 [============================> ]  99.5% 565248/568127 bytes... 

Writing at 0x000e5cbe [============================> ]  99.9% 567296/568127 bytes... 

Writing at 0x000e61a0 [==============================] 100.0% 568127/568127 bytes... 

A serial exception error occurred: Cannot configure port, something went wrong. Original message: PermissionError(13, 'A device attached to the system is not functioning.', None, 31)
Note: This error originates from pySerial. It is likely not a problem with esptool, but with the hardware connection or drivers.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
Wrote 876960 bytes (568127 compressed) at 0x00010000 in 11.7 seconds (602.0 kbit/s).
Hash of data verified.

Hard resetting with a watchdog...
Failed uploading: uploading error: exit status 1

No, I am not, never heard of that board. The fact is, the sketch is correct. When a sketch works on one board and not another, it is because you are using the wrong library OR the hardware is bad. What board are you selecting? Once you pick a board try the BOARD examples. I just did and it worked fine. I used

Here is the AP code for that specific board. Try it.

/*
  WiFiAccessPoint.ino creates a WiFi access point and provides a web server on it.

  Steps:
  1. Connect to the access point "yourAp"
  2. Point your web browser to http://192.168.4.1/H to turn the LED on or http://192.168.4.1/L to turn it off
     OR
     Run raw TCP "GET /H" and "GET /L" on PuTTY terminal with 192.168.4.1 as IP address and 80 as port

  Created for arduino-esp32 on 04 July, 2018
  by Elochukwu Ifediora (fedy0)
*/

#include <WiFi.h>
#include <NetworkClient.h>
#include <WiFiAP.h>

#ifndef LED_BUILTIN
#define LED_BUILTIN 2  // Set the GPIO pin where you connected your test LED or comment this line out if your dev board has a built-in LED
#endif

// Set these to your desired credentials.
const char *ssid = "yourAP";
const char *password = "yourPassword";

NetworkServer server(80);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");

  // You can remove the password parameter if you want the AP to be open.
  // a valid password must have more than 7 characters
  if (!WiFi.softAP(ssid, password)) {
    log_e("Soft AP creation failed.");
    while (1);
  }
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();

  Serial.println("Server started");
}

void loop() {
  NetworkClient client = server.accept();  // listen for incoming clients

  if (client) {                     // if you get a client,
    Serial.println("New Client.");  // print a message out the serial port
    String currentLine = "";        // make a String to hold incoming data from the client
    while (client.connected()) {    // loop while the client's connected
      if (client.available()) {     // if there's bytes to read from the client,
        char c = client.read();     // read a byte, then
        Serial.write(c);            // print it out the serial monitor
        if (c == '\n') {            // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> to turn ON the LED.<br>");
            client.print("Click <a href=\"/L\">here</a> to turn OFF the LED.<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {  // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(LED_BUILTIN, HIGH);  // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(LED_BUILTIN, LOW);  // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

Your board is ESP32, while my board is ESP32 S2 (Wemos S2 Mini).

The sketch works perfectly on the ESP32 board, but unfortunately, it does not work on the ESP32 S2.

Over the past few days, I have revisited this issue and searched extensively online.
It seems that many users have faced the same problem with this board,
and so far, I could not find any reliable solution.

I will still try a few more approaches. If that does not help, I may have to shift to another board, as continuing with this one may not be practical.

Thank you @sonofcy for your time and guidance.

I heard from a friend that if you short pin EN and 3.3v with a 10k ohm rezistor or a coin it could solve the problem but use it as last ditch efort (it could do iversible damage and i have never tried it) also i would check connections on the board, but keep in mind that im no expert.

Wish you luck