Connecting to a WPA2 network with an ESP8266 module

Hello community
I have been connecting to a WPA2 network with an ESP8266 module and I found the code that works.
But...
When I connect and spend 20 seconds. This overflows and restarts.
Looking for I found that it could be memory or voltage
but from memory there is only that and if it is well connected
HELP ME :frowning:

#include <ESP8266WiFi.h>
#include <WebSocketsServer.h>
#include <WiFiClient.h>

extern "C" {
#include "user_interface.h"
#include "wpa2_enterprise.h"
}

// SSID to connect to
static const char* ssid = "*********";
// Username for authentification
static const char* username = "********";
// Password for authentication
static const char* password = "*********";


void setup() {
    lcd.begin (16,2);
  // put your setup code here, to run once:
  Serial.begin(9200);

  // WPA2 Connection starts here
  // Setting ESP into STATION mode only (no AP mode or dual mode)
    wifi_set_opmode(STATION_MODE);
    struct station_config wifi_config;
    memset(&wifi_config, 0, sizeof(wifi_config));
    strcpy((char*)wifi_config.ssid, ssid);
    wifi_station_set_config(&wifi_config);
    wifi_station_clear_cert_key();
    wifi_station_clear_enterprise_ca_cert();
    wifi_station_set_wpa2_enterprise_auth(1);
    wifi_station_set_enterprise_identity((uint8*)username, strlen(username));
    wifi_station_set_enterprise_username((uint8*)username, strlen(username));
    wifi_station_set_enterprise_password((uint8*)password, strlen(password));
    wifi_station_connect();
  // WPA2 Connection ends here

  
  // Wait for connection AND IP address from DHCP
  Serial.println();
  Serial.println("Waiting for connection and IP Address from DHCP");
  while (WiFi.status() != WL_CONNECTED) {
    delay(2000);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  IPAddress myAddr = WiFi.localIP();
}


void loop() {
delay(2000);
}

Error

Exception (3):
epc1=0x40204e81 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40070151 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffec80 end: 3fffffb0 offset: 01a0
3fffee20:  00000002 40100ddc 000000a0 3ffe8004  
3fffee30:  40100e10 0000049c 000003fe 40204fab  
3fffee40:  0000049c 00001000 000003fe 40100e10  
............

Look here to see how to interpret the stack trace. It may help to isolate the problem:

https://arduino-esp8266.readthedocs.io/en/latest/faq/a02-my-esp-crashes.html