<SOLVED> IDF esp_wifi_stop() interfering with LEDC operation

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

<SOLVED> IDF esp_wifi_stop() interfering with LEDC operation

Postby felixcollins » Mon Jan 30, 2023 4:03 am

Hi, I've got a weird problem whereby when I turn wifi off (not that this is off not on) my leds under control of ledc start flickering. When I re-enable wifi they go back to normal. I suspect this is something to do with the wifi turn off code doing something to the clock supplying the ledc module but I really have no clue. My wifi stop code is below. Some of if it non-idf obviously.

Does anyone have any ideas as to where to start looking?

Code: Select all

void wifi_stop()
{
	
	telemetry_notify_wifi_disconnected();
	webserver_stop();
	AP_state = AP_STATE_Off;
	STA_state = STA_STATE_Idle;

	deinit_mini_dns();
	
	esp_netif_deinit();

	esp_wifi_stop();

	if (reconnect_timer) 
	{
		xTimerStop(reconnect_timer, (TickType_t)1000 / portTICK_PERIOD_MS);
		xTimerReset(reconnect_timer, 1);
	}
	if (ap_stop_timer) 
	{
		xTimerStop(ap_stop_timer, (TickType_t)1000 / portTICK_PERIOD_MS);
		xTimerReset(ap_stop_timer, 1);

	}	
	
	wifi_state = WIFI_STATE_STOPPED;
	led_change_pattern(LED_WIFI_OFF, true);
}
Last edited by felixcollins on Mon Jan 30, 2023 10:56 pm, edited 1 time in total.

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: IDF esp_wifi_stop() interfering with LEDC operation

Postby felixcollins » Mon Jan 30, 2023 8:23 pm

I've narrowed down the source of the issue to the esp_wifi_stop() function. If all I do is call that function it causes my LEDC controlled leds to start flickering erratically. Unfortunately esp_wifi_stop() is bundled as a library so there is no source code to see where the issue is. Could an Espressif person with access to the code please take a look? Perhaps I should just log a bug.

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: IDF esp_wifi_stop() interfering with LEDC operation

Postby felixcollins » Mon Jan 30, 2023 8:59 pm

Just in case it matters... I'm running on a WROOM32E. Custom board.

Code: Select all

	ledc_timer_config_t ledc_timer =
	{
		.duty_resolution = LEDC_TIMER_13_BIT,
		.freq_hz = 5000,
		.speed_mode = LEDC_HIGH_SPEED_MODE,
		.timer_num = LEDC_TIMER_0,
		.clk_cfg = LEDC_USE_APB_CLK,
	};
	ledc_timer_config(&ledc_timer);
LEDS on channels 0,1,2,3,4. GPIOs 26,25,27,2,4

All on High Speed Mode.

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: IDF esp_wifi_stop() interfering with LEDC operation

Postby felixcollins » Mon Jan 30, 2023 10:55 pm

This does seem to be a bug. I worked around it by changing the clock source for the LEDC module. LEDC_USE_RTC8M_CLK is not used by wifi.

Code: Select all

	ledc_timer_config_t ledc_timer =
	{
		.duty_resolution = LED_PWM_RESOLUTION_SELECTED,
		.freq_hz = LED_PWM_FREQ_SELECTED,
		.speed_mode = LED_SPEED_MODE_SELECTED,
		.timer_num = LED_TIMER_SELECTED,
		.clk_cfg = LEDC_USE_RTC8M_CLK,
	};
	ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));

felixcollins
Posts: 123
Joined: Fri May 24, 2019 2:02 am

Re: <SOLVED> IDF esp_wifi_stop() interfering with LEDC operation

Postby felixcollins » Thu Feb 02, 2023 12:36 am

Light sleep must also be disabled.


Who is online

Users browsing this forum: No registered users and 132 guests