For reference, I am using ESP-IDF master at commit 178b122c145c19e94ac896197a3a4a9d379cd618.
My understanding of how this is supposed to work is that after the ulp main exits, start.S calls ulp_riscv_shutdown, which sets the power off delay then sets the two registers in order to shutdown and reset the ULP. After that timer expires, the ULP should start again and run main(). However, what I am seeing is that main() only runs once, and never wakes up again.
For reference, her is the trivial example I put together to demonstrate the problem:
Here's the main code for the main CPU:
Code: Select all
#include <stdio.h>
#include "soc/rtc_cntl_reg.h"
#include "esp32s2/ulp.h"
#include "esp32s2/ulp_riscv.h"
#include "ulp_main.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.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(void);
void app_main(void)
{
init_ulp_program();
while(1) {
printf("ulp_testval=%d\n", ulp_testval);
vTaskDelay(100 / portTICK_RATE_MS);
}
}
static void init_ulp_program(void)
{
esp_err_t err = ulp_riscv_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start));
ESP_ERROR_CHECK(err);
/* The first argument is the period index, which is not used by the ULP-RISC-V timer
* The second argument is the period in microseconds, which gives a wakeup time period of: 20ms
*/
ulp_set_wakeup_period(0, 20000);
/* Start the program */
err = ulp_riscv_run();
ESP_ERROR_CHECK(err);
}
Code: Select all
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "ulp_riscv/ulp_riscv.h"
#include "ulp_riscv/ulp_riscv_utils.h"
int testval = 8;
int main (void)
{
testval++;
/* ulp_riscv_shutdown() is called automatically when main exits */
return 0;
}
Code: Select all
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x8
load:0x3ffe6108,len:0x12a8
load:0x4004c000,len:0x8c4
load:0x40050000,len:0x2c34
entry 0x4004c1a8
W (138) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
ulp_testval=8
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
ulp_testval=9
When I decoded the value of RTC_CNTL_COCPU_CTRL_REG=0x24FC810 (I was printing it in the loop from the main CPU), I get the following:
Code: Select all
RTC_CNTL_COCPU_CLK_FO 0
RTC_CNTL_COCPU_START_2_RESET_DIS 001000
RTC_CNTL_COCPU_START_2_INTR_EN 010000
RTC_CNTL_COCPU_SHUT 0
RTC_CNTL_COCPU_SHUT_2_CLK_DIS 00111111 = 3F
RTC_CNTL_COCPU_SHUT_RESET_EN 1
RTC_CNTL_COCPU_SEL 0 = RISCV
RTC_CNTL_COCPU_DONE_FORCE 0
RTC_CNTL_COCPU_DONE 0
RTC_CNTL_COCPU_SW_INT_TRIGGER 1
RTC_CNTL_COCPU_CLKGATE_EN 0
(I can send a zip of the whole repro example. I didn't see a way to attach the file.)
Any ideas? What am I doing wrong?
Thanks,
- Scott