ULP RISC-V Blink application help.
Posted: Fri Nov 17, 2023 3:23 pm
I put together this simple blink application from many different examples I found for the ULP RISC-V on the ESP32-S2. I don't think I'm missing a step from the ULP RISC-V programming guide. If it is missing here it is because I had it there and it did not seem to do anything.
I would like to run this code in an infinite loop while the main CPU is running and not in sleep mode. I'm using the ESP32-S2-Saola-1 module and PlatformIO. I tried many fixes I found here and have had no luck. I'm probably not implementing the fixes properly. I'm fairly certain I have to POKE some ULP register bits. This code builds and loads. The main core runs as I see "Loop" printing out once a second, but no output pin toggling from the copro. If I put the main CPU to sleep, I see one single 10ms pulse.
I appreciate your help.
ESP32 app_main:
ULP RISC-V main:
I would like to run this code in an infinite loop while the main CPU is running and not in sleep mode. I'm using the ESP32-S2-Saola-1 module and PlatformIO. I tried many fixes I found here and have had no luck. I'm probably not implementing the fixes properly. I'm fairly certain I have to POKE some ULP register bits. This code builds and loads. The main core runs as I see "Loop" printing out once a second, but no output pin toggling from the copro. If I put the main CPU to sleep, I see one single 10ms pulse.
I appreciate your help.
ESP32 app_main:
Code: Select all
#include <stdio.h>
#include "esp_sleep.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "soc/rtc_periph.h"
#include "driver/gpio.h"
#include "driver/rtc_io.h"
#include "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)
{
vTaskDelay(100);
printf("Initializing ULP-RISC-V program! \n");
init_ulp_program();
vTaskDelay(100);
printf("Entering main loop.\n\n");
for (;;)
{
vTaskDelay(100);
printf("Loop\n");
}
}
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 */
err = ulp_riscv_run();
ESP_ERROR_CHECK(err);
printf("Done initializing ULP-RISC-V program! \n");
}
Code: Select all
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "ulp_riscv.h"
#include "../../ulp_core/include/ulp_riscv_utils.h"
#include "../../ulp_core/include/ulp_riscv_gpio.h"
#define SAMPLE_IO GPIO_NUM_4
int main(void)
{
ulp_riscv_gpio_init(SAMPLE_IO);
ulp_riscv_gpio_output_enable(SAMPLE_IO);
ulp_riscv_gpio_set_output_mode(SAMPLE_IO, RTCIO_MODE_OUTPUT);
ulp_riscv_gpio_pullup(SAMPLE_IO);
ulp_riscv_gpio_pulldown_disable(SAMPLE_IO);
ulp_riscv_gpio_output_level(SAMPLE_IO, 1);
for (;;)
{
ulp_riscv_delay_cycles(10 * ULP_RISCV_CYCLES_PER_MS);
ulp_riscv_gpio_output_level(SAMPLE_IO, 0);
ulp_riscv_delay_cycles(10 * ULP_RISCV_CYCLES_PER_MS);
ulp_riscv_gpio_output_level(SAMPLE_IO, 1);
}
/* ulp_riscv_halt() is called automatically when main exits */
return 0;
}