Thank you so much for your response.
I use exactly the same functions as in wifi station example idf.
I did this:
esp_wifi_stop();
wifi_init_sta();
esp_wifi_start();
But the system reboots with the following info:
I (32410) wifi:state: run -> init (0)
I (32410) wifi:pm stop, total sleep time: 17494143 us / 30438569 us
I (32410) wifi
<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
W (32420) wifi:hmac tx: stop, discard
W (32420) wifi:hmac tx: stop, discard
I (33460) wifi:flush txq
I (33460) wifi:stop sw txq
I (33460) wifi:lmac stop hw txq
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x4002a350
0x4002a350: _esp_error_check_failed at C:/Users/Nasib/Desktop/esp-idf/components
/esp_common/src/esp_err.c:45
file: "../main/gpio_example_main.c" line 533
func: wifi_init_sta
expression: esp_event_loop_create_default()
abort() was called at PC 0x4002a353 on core 0
0x4002a353: _esp_error_check_failed at C:/Users/Nasib/Desktop/esp-idf/components
/esp_common/src/esp_err.c:46
Backtrace:0x4002b493:0x3ffd3f90 0x4002bccd:0x3ffd3fb0 0x40031faa:0x3ffd3fd0 0x40
02a353:0x3ffd4040 0x4008607b:0x3ffd4060 0x400869a7:0x3ffd41c0 0x40084163:0x3ffd4
220 0x4002bcd5:0x3ffd4250
0x4002b493: panic_abort at C:/Users/Nasib/Desktop/esp-idf/components/esp_system/
panic.c:330
0x4002bccd: esp_system_abort at C:/Users/Nasib/Desktop/esp-idf/components/esp_sy
stem/system_api.c:106
0x40031faa: abort at C:/Users/Nasib/Desktop/esp-idf/components/newlib/abort.c:46
0x4002a353: _esp_error_check_failed at C:/Users/Nasib/Desktop/esp-idf/components
/esp_common/src/esp_err.c:46
0x4008607b: wifi_init_sta at C:\Users\Nasib\eclipse-workspace\gpio\build/../main
/gpio_example_main.c:533 (discriminator 1)
0x400869a7: app_main at C:\Users\Nasib\eclipse-workspace\gpio\build/../main/gpio
_example_main.c:1034
0x40084163: main_task at C:/Users/Nasib/Desktop/esp-idf/components/esp32s2/cpu_s
tart.c:453 (discriminator 2)
0x4002bcd5: vPortTaskWrapper at C:/Users/Nasib/Desktop/esp-idf/components/freert
os/xtensa/port.c:143
ELF file SHA256: 04f8503afd36ced3
Rebooting...