Thank you! This is a step forward. It now wakes from sleep once, but fails to do so on subsequent sleeps. This is the output:
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5108
load:0x40078000,len:9780
ho 0 tail 12 room 4
load:0x40080400,len:6288
entry 0x4008070c
start
Entering light sleep...
2
Woke from light sleep!
Entering light sleep...
I used provided for loop but I replaced the vTaskDelay(), which was giving me errors (even with freeRTOS included) with a for loop delay. I attempted to move esp_sleep_enable_ulp_wakeup() into the loop, but it made no difference.
#include <stdio.h>
#include "esp_sleep.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/sens_reg.h"
#include "soc/rtc_periph.h"
#include "soc/soc.h"
#include "driver/gpio.h"
#include "driver/rtc_io.h"
//#include "sdkconfig.h"
#include "esp32/ulp.h"
#include "ulp_main.h"
//#include "freertos/FreeRTOS.h"
extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start");
extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end");
static void init_ulp_program();
static void init_ulp_program()
{
esp_err_t err = ulp_load_binary(0, ulp_main_bin_start,
(ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t));
ESP_ERROR_CHECK(err);
// Init Values
ulp_testval = 0;
//esp_deep_sleep_disable_rom_logging(); // suppress boot messages
/* Set ULP wake up period to 20ms */
ulp_set_wakeup_period(0, 20000);
ESP_ERROR_CHECK( ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t)));
}
void app_main()
{
//testNoSleep();
printf("start\n");
//esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
init_ulp_program();
/*if (cause != ESP_SLEEP_WAKEUP_ULP)
{
printf("Not ULP wakeup, initializing ULP\n");
init_ulp_program();
}
else
{
printf("ULP Wakeup\n");
ESP_ERROR_CHECK( ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t)));
printf("%u\n", ulp_testval& 0x0000FFFF);
printf("\n");
}*/
//ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup() );
//esp_light_sleep_start();
//esp_deep_sleep_start();
for(;;)
{
ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup() );
printf("Entering light sleep...\n");
//vTaskDelay(500 / portTICK_PERIOD_MS);
int k = 0;
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 100; j++)
{
k+=i+j;
}
}
esp_light_sleep_start();
printf("%u\n", ulp_testval& 0x0000FFFF);
printf("Woke from light sleep!\n");
}
}
/* idf.py menuconfig was used to adjust
* Component config -> ESP32 specific -> select 'Enable Ultra Low Power Coprocessor'
* to 4096 to get this to work
*/
/* ULP assembly files are passed through C preprocessor first, so include directives
and C macros may be used in these files
*/
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/soc_ulp.h"
/* Define variables, which go into .bss section (zero-initialized data) */
.bss
.global testval
testval: .long 0
/* Code goes into .text section */
.text
.global entry
entry:
move r0, testval
ld r1, r0, 0
add r1, r1, 2
st r1, r0, 0
STAGE_RST
wait100ms:
wait 8000
STAGE_INC 1
jumps wake_up, 2000, GE
jump wait100ms
// wake up at the end
wake_up:
// Check if the system can be woken up
READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP)
and r0, r0, 1
jump wake_up, eq
// Wake up the SoC, end program
wake
REG_WR 0x006, 24, 24, 0 // Stop ULP timer (clear RTC_CNTL_ULP_CP_SLP_TIMER_EN)
halt
Thank you!