Changing max_cpu_freq will 100% couse wifi: bcn_timout,ap_probe_send_start
Posted: Fri Oct 26, 2018 3:10 pm
by ZHDX227
Hi,
When switch the max_cpu_freq between RTC_CPU_FREQ_80M and RTC_CPU_FREQ_240M ,
The wifi will 100% reset , all TCP connections lost.
[0;32mI (9085) pm_esp32: Frequency switching config: CPU_MAX: 80, APB_MAX: 80, APB_MIN: 80, Light sleep: DISABLED[0m
cfg.max_cpu_freq changed to 1 , result 0
I (15041) wifi: bcn_timout,ap_probe_send_start
I (17544) wifi: ap_probe_send over, resett wifi status to disassoc
I (17545) wifi: state: run -> init (100)
I (17546) wifi: pm stop, total sleep time: 5687366 us / 15097450 us
I (17550) wifi: n:2 0, o:2 1, ap:2 1, sta:2 1, prof:2
I (17982) wifi: n:2 1, o:2 0, ap:2 1, sta:2 1, prof:2
I (17983) wifi: state: init -> auth (b0)
I (17986) wifi: state: auth -> assoc (0)
I (17991) wifi: state: assoc -> run (10)
I (18006) wifi: connected with NC-BGN, channel 2
I (18007) wifi: pm start, type: 1
[0;32mI (18721) event: sta ip: 192.168.1.2, mask: 255.255.255.0, gw: 192.168.1.1[0m
The code like this
extern "C"{
#include "esp_pm.h"
esp_pm_config_esp32_t cfg;
void _cpu_cfg()
{
cfg.min_cpu_freq = cfg.max_cpu_freq; //RTC_CPU_FREQ_XTAL;
esp_err_t err=esp_pm_configure(&cfg);
printf("cfg.max_cpu_freq changed to %d , result %d\r\n",(int)cfg.max_cpu_freq,(int)err);
}
extern void _cpu_min()
{
cfg.max_cpu_freq = RTC_CPU_FREQ_80M;
//cfg.light_sleep_enable=true; //result 262 ESP_ERR_NOT_SUPPORTED
_cpu_cfg();
}
extern void _cpu_max()
{
cfg.max_cpu_freq = RTC_CPU_FREQ_240M;
//cfg.light_sleep_enable=false;
_cpu_cfg();
}
}
_cpu_min() or _cpu_max() are called in cpu core 1
Regards,
Thanks.
Re: Changing max_cpu_freq will 100% couse wifi: bcn_timout,ap_probe_send_start
Posted: Mon Nov 05, 2018 1:52 pm
by liuzhifu
HI @ZHDX227,
Sorry for late response.
I just can't reproduce this issue for 10 hours test with a Mercury soft-AP. My reproduce method:
1. Configure ESP32 as STA mode
2. Connects ESP32 to a Mercury AP
3. Change CPU core#1 frequency between 80M and 240M every 5 seconds
Need you help to provide following information:
1. The AP type to which ESP32 STA is connected
2. How much time is needed in order to reproduce this issue
3. Does this issue happen on a specific ESP32 device or every ESP32 devices you have
Re: Changing max_cpu_freq will 100% couse wifi: bcn_timout,ap_probe_send_start
Posted: Mon Nov 05, 2018 3:25 pm
by ZHDX227
Hi,
I just do some tests.
It's ONLY happend when use
esp_wifi_set_mode(WIFI_MODE_APSTA)
Environment :
Board : DevKitC v4, ESP-WROVER-B
CONFIG - Default , and turn's on the Power Management
Code :
Code: Select all
/* WiFi station Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sys.h"
/* The examples use WiFi configuration that you can set via 'make menuconfig'.
If you'd rather not, just change the below entries to strings with
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
*/
#define EXAMPLE_ESP_WIFI_SSID "SSID"
#define EXAMPLE_ESP_WIFI_PASS "12345678"
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
/* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group;
/* The event group allows multiple bits for each event, but we only care about one event
* - are we connected to the AP with an IP? */
const int WIFI_CONNECTED_BIT = BIT0;
static const char *TAG = "wifi station";
static int s_retry_num = 0;
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
case SYSTEM_EVENT_STA_START:
esp_wifi_connect();
break;
case SYSTEM_EVENT_STA_GOT_IP:
ESP_LOGI(TAG, "got ip:%s",
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
{
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
esp_wifi_connect();
xEventGroupClearBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
s_retry_num++;
ESP_LOGI(TAG,"retry to connect to the AP");
}
ESP_LOGI(TAG,"connect to the AP fail\n");
break;
}
default:
break;
}
return ESP_OK;
}
void wifi_init_sta()
{
s_wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
.sta = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.password = EXAMPLE_ESP_WIFI_PASS
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA) );
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
wifi_config_t wifi_ap_config = {
.ap = {
.ssid = "ESP_SSID",
.ssid_len = strlen("ESP_SSID"),
.password = EXAMPLE_ESP_WIFI_PASS,
.max_connection = 8,
.authmode = WIFI_AUTH_WPA_WPA2_PSK
},
};
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_ap_config));
ESP_ERROR_CHECK(esp_wifi_start() );
ESP_LOGI(TAG, "wifi_init_sta finished.");
ESP_LOGI(TAG, "connect to ap SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
//extern "C"{
#include "esp_pm.h"
esp_pm_config_esp32_t cfg;
void _cpu_cfg()
{
cfg.min_cpu_freq = cfg.max_cpu_freq; //RTC_CPU_FREQ_XTAL;
esp_err_t err=esp_pm_configure(&cfg);
printf("cfg.max_cpu_freq changed to %d , result %d\r\n",(int)cfg.max_cpu_freq,(int)err);
}
extern void _cpu_min()
{
cfg.max_cpu_freq = RTC_CPU_FREQ_80M;
//cfg.light_sleep_enable=true; //result 262 ESP_ERR_NOT_SUPPORTED
_cpu_cfg();
}
extern void _cpu_max()
{
cfg.max_cpu_freq = RTC_CPU_FREQ_240M;
//cfg.light_sleep_enable=false;
_cpu_cfg();
}
//}
void app_main()
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
wifi_init_sta();
for(;;)
{
_cpu_max();
vTaskDelay(5000 / portTICK_PERIOD_MS);
_cpu_min();
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
Re: Changing max_cpu_freq will 100% couse wifi: bcn_timout,ap_probe_send_start
Posted: Sat Nov 24, 2018 1:37 am
by liuzhifu
OK, I will try to reproduce it again