I was testing the existing ulp riscv interrupt sample for the esp32s2, i just added to it a led blink code to see a blink from ulp riscv before going to halt mode. it works 1 or 3 times ,then freezes.;
here is the code (Board is esp32 s2 Mini ) ESP IDF rel 5.0
https://www.wemos.cc/en/latest/_static/ ... v1.0.0.pdf
ulp
Code: Select all
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "ulp_riscv.h"
#include "ulp_riscv_utils.h"
#include "ulp_riscv_gpio.h"
int main (void)
{
ulp_riscv_gpio_init(15);
ulp_riscv_gpio_set_output_mode(15,RTCIO_MODE_OUTPUT);
ulp_riscv_gpio_output_enable(15);
ulp_riscv_gpio_output_level(15,1);
/* Wakeup interrupt is a level interrupt, wait 1 sec to
allow user to release button to avoid waking up the ULP multiple times */
ulp_riscv_delay_cycles(1000*1000 * ULP_RISCV_CYCLES_PER_US);
ulp_riscv_gpio_output_level(15,0);
ulp_riscv_gpio_wakeup_clear();
ulp_riscv_delay_cycles(100 * ULP_RISCV_CYCLES_PER_US);
ulp_riscv_wakeup_main_processor();
/* ulp_riscv_halt() is called automatically when main exits */
return 0;
}
ESP32S2 Code
Code: Select all
#include <stdio.h>
#include "esp_sleep.h"
#include "soc/sens_reg.h"
#include "driver/gpio.h"
#include "ulp_riscv.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define WAKEUP_PIN 0
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);
static void wakeup_gpio_init(void)
{
/* Configure the button GPIO as input, enable wakeup */
gpio_config_t config = {
.pin_bit_mask = BIT64(WAKEUP_PIN),
.mode = GPIO_MODE_INPUT,
.pull_up_en = 1
};
ESP_ERROR_CHECK(gpio_config(&config));
gpio_wakeup_enable(WAKEUP_PIN, GPIO_INTR_LOW_LEVEL);
gpio_hold_en(WAKEUP_PIN);
}
void app_main(void)
{
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
wakeup_gpio_init();
init_ulp_program();
}
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP-RISC-V woke up the main CPU! \n");
}
/* Go back to sleep, only the ULP Risc-V will run */
printf("Entering in deep sleep\n\n");
/* Small delay to ensure the messages are printed */
vTaskDelay(100);
/* RTC peripheral power domain needs to be kept on to detect
the GPIO state change */
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup());
esp_deep_sleep_start();
}
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);
/* Start the program */
ulp_riscv_cfg_t cfg = {
.wakeup_source = ULP_RISCV_WAKEUP_SOURCE_GPIO,
};
err = ulp_riscv_config_and_run(&cfg);
ESP_ERROR_CHECK(err);
}
Code: Select all
ulp_riscv_delay_cycles(100 * ULP_RISCV_CYCLES_PER_US);
i really dont see a reason why it freezes.
any help welcome.