I have verified this issue in native esp-idf environment and see @WiFive nailed it down already
It disappears after removing extraneous "extern uint32_t ulp_x = 1;" from the main c program code.
It shows up if I put "extern uint32_t ulp_x = 1;" back.
Complete code that works is below:
ulp:
Code: Select all
.bss
.global x
x: .long 0
.text
.global entry
entry:
move r1, x // Get adress of x
ld r0, r1, 0 // Read x in r0
add r0, r0, 1 // Increment x
st r0, r1, 0 // Save the x in memory
halt
Code: Select all
#include <stdio.h>
#include "soc/rtc_cntl_reg.h"
#include "esp_sleep.h"
#include "esp32/ulp.h"
#include "ulp_main.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");
void app_main()
{
ESP_ERROR_CHECK(ulp_load_binary(0, ulp_main_bin_start,
(ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t)));
ulp_x = 1;
printf("Toggle counter %d\n", ulp_x & UINT16_MAX);
ESP_ERROR_CHECK( ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t)));
printf("Print something to kill some time...\n");
printf("Toggle counter %d\n", ulp_x & UINT16_MAX);
esp_deep_sleep_start();
}
Code: Select all
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x16 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x16 (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:0x3fff0010,len:4
load:0x3fff0014,len:3188
load:0x40078000,len:0
load:0x40078000,len:11056
entry 0x40078c10
Toggle counter 1
Print something to kill some time...
Toggle counter 2