3
3
*
4
4
* SPDX-License-Identifier: Unlicense OR CC0-1.0
5
5
*/
6
- /* LP core gpio example
6
+ /* ULP LP-Core GPIO wake-up example
7
7
8
8
This example code is in the Public Domain (or CC0 licensed, at your option.)
9
9
13
13
*/
14
14
15
15
#include <stdio.h>
16
- #include <inttypes.h>
17
16
#include "esp_sleep.h"
18
- #include "driver/gpio.h"
19
17
#include "driver/rtc_io.h"
20
- #include "freertos/FreeRTOS.h"
21
- #include "freertos/task.h"
22
18
#include "ulp_lp_core.h"
23
19
#include "ulp_main.h"
24
- #include "lp_core_uart.h"
20
+ #include "freertos/FreeRTOS.h"
21
+ #include "freertos/task.h"
22
+
23
+ #define WAKEUP_PIN 2
25
24
26
25
extern const uint8_t ulp_main_bin_start [] asm("_binary_ulp_main_bin_start" );
27
26
extern const uint8_t ulp_main_bin_end [] asm("_binary_ulp_main_bin_end" );
28
27
29
-
30
28
static void init_ulp_program (void );
31
29
30
+ static void wakeup_gpio_init (void )
31
+ {
32
+ /* Configure the button GPIO as input, enable wakeup */
33
+ rtc_gpio_init (WAKEUP_PIN );
34
+ rtc_gpio_set_direction (WAKEUP_PIN , RTC_GPIO_MODE_INPUT_ONLY );
35
+ rtc_gpio_pulldown_dis (WAKEUP_PIN );
36
+ rtc_gpio_pullup_en (WAKEUP_PIN );
37
+ rtc_gpio_wakeup_enable (WAKEUP_PIN , GPIO_INTR_NEGEDGE );
38
+ }
39
+
32
40
void app_main (void )
33
41
{
34
42
/* If user is using USB-serial-jtag then idf monitor needs some time to
@@ -38,46 +46,39 @@ void app_main(void)
38
46
*/
39
47
vTaskDelay (pdMS_TO_TICKS (1000 ));
40
48
41
- /* Initialize selected GPIO as RTC IO, enable input/output, disable pullup and pulldown */
42
- printf ("Using pin %d as pulse counter input\n" , CONFIG_EXAMPLE_PULSE_COUNT_PIN );
43
- rtc_gpio_init (CONFIG_EXAMPLE_PULSE_COUNT_PIN );
44
- rtc_gpio_set_direction (CONFIG_EXAMPLE_PULSE_COUNT_PIN , RTC_GPIO_MODE_INPUT_OUTPUT );
45
- rtc_gpio_pulldown_dis (CONFIG_EXAMPLE_PULSE_COUNT_PIN );
46
- rtc_gpio_pullup_dis (CONFIG_EXAMPLE_PULSE_COUNT_PIN );
47
-
48
- printf ("ULP will wake up processor after every %d pulses\n" , CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT );
49
+ wakeup_gpio_init ();
49
50
50
51
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause ();
51
52
/* not a wakeup from ULP, load the firmware */
52
53
if (cause != ESP_SLEEP_WAKEUP_ULP ) {
53
54
printf ("Not a ULP wakeup, initializing it! \n" );
54
55
init_ulp_program ();
55
- } else {
56
- printf ("ULP woke up the main CPU!\n" );
57
- printf ("Pulse count: %" PRIu32 "\n" , ulp_pulse_count );
56
+ }
57
+
58
+ /* ULP read and detected a change in WAKEUP_PIN, prints */
59
+ if (cause == ESP_SLEEP_WAKEUP_ULP ) {
60
+ printf ("ULP woke up the main CPU! \n" );
58
61
}
59
62
60
63
/* Go back to sleep, only the ULP will run */
61
- printf ("Entering in deep sleep\n\n" );
64
+ printf ("Entering deep sleep\n\n" );
62
65
63
66
/* Small delay to ensure the messages are printed */
67
+ vTaskDelay (100 / portTICK_PERIOD_MS );
68
+
64
69
ESP_ERROR_CHECK ( esp_sleep_enable_ulp_wakeup ());
65
70
66
71
esp_deep_sleep_start ();
67
72
}
68
73
69
74
static void init_ulp_program (void )
70
75
{
71
- lp_core_uart_cfg_t uart_cfg = LP_CORE_UART_DEFAULT_CONFIG ();
72
-
73
- ESP_ERROR_CHECK (lp_core_uart_init (& uart_cfg ));
74
-
75
76
esp_err_t err = ulp_lp_core_load_binary (ulp_main_bin_start , (ulp_main_bin_end - ulp_main_bin_start ));
76
77
ESP_ERROR_CHECK (err );
77
78
78
79
/* Start the program */
79
80
ulp_lp_core_cfg_t cfg = {
80
- .wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU ,
81
+ .wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_LP_IO ,
81
82
};
82
83
83
84
err = ulp_lp_core_run (& cfg );
0 commit comments