Page 1 of 1

Is GPIO9 special in ESP32-PICO-D4 ?

Posted: Wed Sep 25, 2019 6:44 pm
by kuhatovuk
Hello ! GPIO9 is connected to flash on other hardware but is it special on ESP32-PICO-D4 ? I configure it with LEDC, go to light sleep and then the pin stops outputting. If I change to similar non-RTC pins like IO5 or IO19, everything is fine. Thank you !

Re: Is GPIO9 special in ESP32-PICO-D4 ?

Posted: Wed Sep 25, 2019 7:00 pm
by kuhatovuk
Thanks to this topic : viewtopic.php?t=6452

I noticed the problem goes away if I remove :

esp_sleep_enable_timer_wakeup(10000000);

and only keep :

esp_sleep_enable_gpio_wakeup();

Any idea ?? Thank you

Re: Is GPIO9 special in ESP32-PICO-D4 ?

Posted: Wed Sep 25, 2019 7:28 pm
by kuhatovuk
Some reduced code sample to test the issue on ESP32-PICO-D4 :
- comment esp_sleep_enable_timer_wakeup(5000000); to test it,
- without it all is expected, pin 9 stays correctly HIGH/LOW in light sleep,
- with it, pin 9 stops outputting when light sleep is entered :

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_sleep.h"
#include "esp_log.h"
#include "rom/uart.h"
#include "driver/rtc_io.h"

#define BUTTON_GPIO_NUM_DEFAULT         36
#define BUTTON_WAKEUP_LEVEL_DEFAULT     0

void test_sleep() {
        esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);

        /* 
         * 
         * REMOVE OR ADD THIS LINE TO CHECK BUG
         * 
         *
         */
        esp_sleep_enable_timer_wakeup(5000000);

        esp_sleep_enable_gpio_wakeup();

        /* Wait until GPIO goes high */
        if (rtc_gpio_get_level(BUTTON_GPIO_NUM_DEFAULT) == BUTTON_WAKEUP_LEVEL_DEFAULT) {
            printf("Waiting for GPIO%d to go high...\n", BUTTON_GPIO_NUM_DEFAULT);
            do {
                vTaskDelay(pdMS_TO_TICKS(10));
            } while (rtc_gpio_get_level(BUTTON_GPIO_NUM_DEFAULT) == BUTTON_WAKEUP_LEVEL_DEFAULT);
        }

        printf("Entering light sleep, press button to continue\n");
        /* To make sure the complete line is printed before entering sleep mode,
         * need to wait until UART TX FIFO is empty:
         */
        uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM);

        /* Get timestamp before entering sleep */
        int64_t t_before_us = esp_timer_get_time();
        
        /* Enter sleep mode */
        esp_light_sleep_start();
        printf("Exiting light sleep\n");
        vTaskDelay(pdMS_TO_TICKS(10));
        uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM);
        vTaskDelay(pdMS_TO_TICKS(10));
        /* Execution continues here after wakeup */

        /* Get timestamp after waking up from sleep */
        int64_t t_after_us = esp_timer_get_time();

        /* Determine wake up reason */
        const char* wakeup_reason;
        switch (esp_sleep_get_wakeup_cause()) {
            case ESP_SLEEP_WAKEUP_TIMER:
                wakeup_reason = "timer";
                break;
            case ESP_SLEEP_WAKEUP_GPIO:
                wakeup_reason = "pin";
                break;
            default:
                wakeup_reason = "other";
                break;
        }

        printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n",
                wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
};

void app_main(void)
{
    /* Configure the button GPIO as input, enable wakeup */
    const int button_gpio_num = BUTTON_GPIO_NUM_DEFAULT;
    const int wakeup_level = BUTTON_WAKEUP_LEVEL_DEFAULT;
    gpio_config_t config = {
            .pin_bit_mask = BIT64(button_gpio_num),
            .mode = GPIO_MODE_INPUT
    };
    ESP_ERROR_CHECK(gpio_config(&config));
    gpio_wakeup_enable(button_gpio_num,
            wakeup_level == 0 ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL);

    while (1) {
        printf("Pin 9 is now HIGH and should stay HIGH after 2s delay\n");
        gpio_pad_select_gpio(9);
        gpio_set_direction(9, GPIO_MODE_OUTPUT);
        gpio_set_level(9, 1);
        vTaskDelay(2000 / portTICK_RATE_MS);
        test_sleep();

        printf("Pin 9 is now LOW and should stay LOW after 2s delay\n");
        gpio_pad_select_gpio(9);
        gpio_set_direction(9, GPIO_MODE_OUTPUT);
        gpio_set_level(9, 0);
        vTaskDelay(2000 / portTICK_RATE_MS);
        test_sleep();
    }
}

Re: Is GPIO9 special in ESP32-PICO-D4 ?

Posted: Wed Sep 25, 2019 8:33 pm
by WiFive

Re: Is GPIO9 special in ESP32-PICO-D4 ?

Posted: Wed Sep 25, 2019 8:46 pm
by kuhatovuk
Ho wow thank you very much ! I just wasted a complete day because I removed SPIRAM support to make my test-case smaller. :oops:

Re: Is GPIO9 special in ESP32-PICO-D4 ?

Posted: Thu Sep 26, 2019 12:49 am
by WiFive
You should be able to force vddsio to stay powered up, so I think it would be appropriate to open a GitHub issue about it. It should also check whether spiram is actually enabled and whether any vddsdio gpios are configured for wakeup when deciding whether or not to power it off.