Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32s2 ULP-RISCV ADC in deep sleep the variable is loosing its value after ULP-RISCV sleep (IDFGH-9716) #11052

Closed
3 tasks done
naelNajjar opened this issue Mar 24, 2023 · 1 comment
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@naelNajjar
Copy link

naelNajjar commented Mar 24, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

I am working on a project in which I am using ESP32s2.
The ULP_RISCV is utilized to read ADC data from the light sensor during deep sleep as shown here in ulp_main.c file.

    raw_data = ulp_riscv_adc_read_channel(ADC_UNIT_1, ADC_CHANNEL_1);
/*if the new light_sensor value is greater than threshold A or lower than threshold B*/
if((500 > raw_data) || (2000 < raw_data))
{
	/* set the prev_light_data to the previous reading */
	prev_light_data = light_data;
	light_data = raw_data ;
}

then we compare prev_light_data and light_data with specific threshold to decide whether to rise waking_flag or not.
The ULP will wake the main CPU when light sensor data exceeds a specific threshold.

if((waking_flag == 1))
{
	ulp_riscv_wakeup_main_processor();
}

Also, the ULP is working with the ULP timer.
here is the initiate of ulp in main.c file

ulp_riscv_adc_cfg_t cfg = {
			.adc_n = ADC_UNIT_1,
			.channel = ADC_CHANNEL_1,
			.width = ADC_BITWIDTH_DEFAULT,
			.atten = ADC_ATTEN_DB_11,
	};
	ESP_ERROR_CHECK(ulp_riscv_adc_init(&cfg));
	 esp_err_t err = ulp_riscv_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start));
	 ESP_ERROR_CHECK(err);

	 ulp_set_wakeup_period(0, 20000);

	 err = ulp_riscv_run();
	 ESP_ERROR_CHECK(err);

The problem is when ULP finishes executing its code and goes to sleep (waiting for its next wake-up from the ULP-Timer), all ULP's global variables are re-initialized with different values than before sleeping.
image

So, how can I save the contents of ULP global variables so that when ULP goes to sleep and then wakes up (from the ULP-Timer) its global variables don't lose the contents/values that they were holding before sleep?

@github-actions github-actions bot changed the title ESP32s2 ULP-RISCV ADC in deep sleep the variable is loosing its value after ULP-RISCV sleep ESP32s2 ULP-RISCV ADC in deep sleep the variable is loosing its value after ULP-RISCV sleep (IDFGH-9716) Mar 24, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 24, 2023
@ESP-Marius
Copy link
Collaborator

Hi,

All variables used by the ULP is placed in RTC memory and should keep their value even during sleep. I suspect your issue is actually related to something else.

There is an in-progress issue internally for a known problem with S2 ULP ADC in deep sleep related to some power configurations (it gives the wrong results when reading). I'll remind them that we still have users asking for support with this...

@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Mar 29, 2023
@espressif-bot espressif-bot added Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Selected for Development Issue is selected for development Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable labels Apr 11, 2023
espressif-bot pushed a commit that referenced this issue May 5, 2023
ADC can now be used from the ULP-RISCV on S2 after the RTC power parameters were
fixed in a624d8d

Closes #11052
Closes #11040
espressif-bot pushed a commit that referenced this issue Jun 14, 2023
ADC can now be used from the ULP-RISCV on S2 after the RTC power parameters were
fixed in a624d8d

Closes #11052
Closes #11040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants