Created
December 12, 2025 10:21
-
-
Save WhiteGrouse/406f302d324d2309c2c0b896ef703d0b to your computer and use it in GitHub Desktop.
ESP32-S3のULP RISC-VでGPIOのホールドを設定、解除する方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <esp_log.h> | |
| #include <esp_sleep.h> | |
| #include <ulp_riscv.h> | |
| #include <driver/rtc_io.h> | |
| #include <driver/gpio.h> | |
| #include <soc/rtc_periph.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 const char *TAG = "example"; | |
| static gpio_num_t led_pin = GPIO_NUM_1; | |
| int app_main(void) { | |
| rtc_gpio_force_hold_dis_all(); | |
| ESP_ERROR_CHECK(rtc_gpio_init(led_pin)); | |
| ESP_ERROR_CHECK(rtc_gpio_set_direction(led_pin, RTC_GPIO_MODE_OUTPUT_ONLY)); | |
| ESP_ERROR_CHECK(rtc_gpio_set_direction_in_sleep(led_pin, RTC_GPIO_MODE_OUTPUT_ONLY)); | |
| ESP_ERROR_CHECK(rtc_gpio_hold_en(led_pin)); | |
| ESP_ERROR_CHECK(ulp_riscv_load_binary(ulp_main_bin_start, ulp_main_bin_end - ulp_main_bin_start)); | |
| ESP_ERROR_CHECK(ulp_set_wakeup_period(0, 1000 * 1000)); // 1sec | |
| ESP_ERROR_CHECK(ulp_riscv_run()); | |
| esp_sleep_enable_ulp_wakeup(); | |
| esp_deep_sleep_start(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| #include <ulp_riscv.h> | |
| #include <ulp_riscv_utils.h> | |
| #include <ulp_riscv_gpio.h> | |
| static gpio_num_t led_pin = GPIO_NUM_1; | |
| int main(void) { | |
| CLEAR_PERI_REG_MASK(RTC_CNTL_PAD_HOLD_REG, BIT(led_pin)); | |
| ulp_riscv_gpio_init(led_pin); | |
| ulp_riscv_gpio_output_enable(led_pin); | |
| for (int i = 0; i < 5; i++) { | |
| ulp_riscv_gpio_output_level(led_pin, 1); | |
| ulp_riscv_delay_cycles(50 * ULP_RISCV_CYCLES_PER_MS); | |
| ulp_riscv_gpio_output_level(led_pin, 0); | |
| ulp_riscv_delay_cycles(50 * ULP_RISCV_CYCLES_PER_MS); | |
| } | |
| SET_PERI_REG_MASK(RTC_CNTL_PAD_HOLD_REG, BIT(led_pin)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment