I'm facing a lot of Emulation Trap while debugging with gdbstub.
It happens when I try to change the wifi operation mode/config.
User Case: Start wifi mode as STATIONAP_MODE, with ap_hidden = true, after 10 not_found_ap_count, creates a task that will disable wifi_station_reconnect_policy and set ap_hidden = false. When trying to change any mode/config of wifi STATIONAP_MODE (it also happens for STATION and SOFTAP modes), it results on an Emulation Trap.
Code: Select all
bool wifi_set_mode(WIFI_MODE mode){
if(!mode){
bool s = wifi_set_opmode(mode);
wifi_fpm_open();
wifi_fpm_set_sleep_type(MODEM_SLEEP_T);
wifi_fpm_do_sleep(0xFFFFFFFF);
wifi_fpm_close();
return s;
}
return wifi_set_opmode(mode);
}
bool wifi_ap_set_visible(bool value) {
struct softap_config config;
if(!wifi_softap_get_config(&config)) {
IOT_ERROR("Failed to get softAP config");
return false;
}
//check value
if(value) {
config.ssid_hidden = false;
} else {
config.ssid_hidden = true;
}
if(!wifi_softap_set_config(&config)) {
IOT_ERROR("Failed to set softAP config");
return false;
}
return true;
}
void wifi_event_handler_cb(System_Event_t *event)
{
static bool station_was_connected = false;
if (event == NULL) {
return;
}
switch (event->event_id) {
case EVENT_STAMODE_DISCONNECTED:
wifi_station_is_connected = false;
Event_StaMode_Disconnected_t *ev = (Event_StaMode_Disconnected_t *)&event->event_info;
if(ev != NULL) {
//notify callback
if(on_station_disconnect){
on_station_disconnect(ev->reason);
}
//check ap not found count
if(ev->reason == REASON_NO_AP_FOUND) {
++wifi_ap_not_found_count;
if(wifi_ap_not_found_count >= 10) {
//call smart config
init_smart_config();
//reset ap not found count
wifi_ap_not_found_count = 0;
}
}
//check auth fail count
if(ev->reason == REASON_AUTH_FAIL) {
++wifi_auth_fail_count;
if(wifi_auth_fail_count >= 10) {
//call smart config
init_smart_config();
//reset count
wifi_auth_fail_count = 0;
}
}
} else {
IOT_ERROR("Event_StaMode_Disconnected_t is NULL");
}
break;
case EVENT_STAMODE_CONNECTED:
if(wifi_station_static_ip){
wifi_station_is_connected = true;
if(!station_was_connected){
station_was_connected = true;
//notify first connection callback
if(on_station_first_connect){
on_station_first_connect();
}
}
//notify callback
if(on_station_connect){
on_station_connect();
}
}
break;
case EVENT_STAMODE_DHCP_TIMEOUT:
if(wifi_station_is_connected){
wifi_station_is_connected = false;
if(on_station_disconnect){
on_station_disconnect(REASON_UNSPECIFIED);
}
}
break;
case EVENT_STAMODE_GOT_IP:
wifi_station_is_connected = true;
if(!station_was_connected){
station_was_connected = true;
if(on_station_first_connect){
on_station_first_connect();
}
}
if(on_station_connect){
on_station_connect();
}
break;
case EVENT_SOFTAPMODE_STACONNECTED:
if(on_client_connect){
on_client_connect();
}
break;
case EVENT_SOFTAPMODE_STADISCONNECTED:
if(on_client_disconnect){
on_client_disconnect();
}
break;
default:
break;
}
}
void init_wifi_controller(){
wifi_set_event_handler_cb(wifi_event_handler_cb);
//initial config for wifi ap and station
wifi_station_set_reconnect_policy(true);
wifi_station_set_auto_connect(true);
wifi_ap_set_visible(false);
if(!wifi_set_mode(STATIONAP_MODE)) {
IOT_ERROR("Failed to set STATIONAP_MODE mode");
}
if(!wifi_station_dhcpc_status()){
IOT_DEBUG("DHCP client is not started, starting it...");
if(!wifi_station_dhcpc_start()){
IOT_ERROR("DHCP client start failed");
}
}
wifi_station_connect();
}
LOCAL void smart_config_task(void *pvParameter) {
wifi_station_set_reconnect_policy(false);
wifi_station_disconnect();
//EMULATION TRAP HAPPENS HERE INTERNALLY..
wifi_ap_set_visible(true);
portTickType xLastWakeTime = xTaskGetTickCount();
for(;;) {
//vTaskDelay(5000 / portTICK_RATE_MS);
vTaskDelayUntil(&xLastWakeTime, 5000 / portTICK_RATE_MS);
}
}
void init_smart_config() {
if(smartConfigTaskControllerHandle == NULL) {
//create smart config task
portBASE_TYPE xReturned;
xReturned = xTaskCreate(smart_config_task, (const signed char * const )"smart_config_task", 256, NULL, tskIDLE_PRIORITY + 1, &smartConfigTaskControllerHandle);
if( xReturned != pdPASS ) {
IOT_ERROR("Could not create smart_config task: %d", (int32)xReturned);
}
}
}
void user_init(void) {
uart_init();
#ifdef DEBUG
gdbstub_init();
initiMemoryDump();
#endif
init_wifi_controller();
}
Please let me know if you need more information.
Thanks
Regards