|
|
@@ -0,0 +1,65 @@
|
|
|
+/*
|
|
|
+ * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
|
+ */
|
|
|
+/* ULP riscv uart print example
|
|
|
+
|
|
|
+ This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
+
|
|
|
+ Unless required by applicable law or agreed to in writing, this
|
|
|
+ software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
+ CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+*/
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include "esp_sleep.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)
|
|
|
+{
|
|
|
+ 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");
|
|
|
+ init_ulp_program();
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ULP Risc-V read and detected a change in GPIO_0, prints */
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ /* 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);
|
|
|
+}
|