Internal pulldown resistors on esp32 c6

Hi,
I wanted to use the deep sleep example demo1 from Getting Started with Seeed Studio XIAO ESP32C6 | Seeed Studio Wiki, but instead of using an external 10k pull down resistor I wanted to use the internal one.

So I tried both
pinMode(2, INPUT_PULLDOWN);
and
rtc_gpio_pulldown_en(2);
rtc_gpio_pullup_dis(2);
But they don’t seem to have any effect, as it still wakes up from automatically wakes up from
deep sleep without pushing the button attached to gpio2.

Of course I could use an external resistor, but this has to fit in a watch, so every component skipped is a win. (actually it will be a watched-sized planetarium/orrery)

Does the esp32c6 even have internal pull down functionality?? if yes how to activate that so it can be used in deep sleep.

First, you will need to read the following documentation.
https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/system/sleep_modes.html
Try the following slightly modified sketch from “File–>Examples–>ESP32–>DeepSleep–>ExternalWakeUp–>ExternalWakeUp.ino”.
Sleep current is about 14uA.

//----------------------------------------------------------------------------------------------
//Board Library : esp32 by Espressif 3.0.7
//Board Select  : XIAO_ESP32C6
//----------------------------------------------------------------------------------------------
// 2025/01/23
/*
  NOTE:
  ======
  Only RTC IO can be used as a source for external wake
  source. They are pins: 0,2,4,12-15,25-27,32-39.
  XIAO ESP32C6 RTC IO pins : D0(0), D2(2)
  XIAO ESP32C3 RTC IO pins : D0(2), D2(4)
  XIAO ESP32S3 RTC IO pins : D1(2), D3(4)
*/

#include "driver/rtc_io.h"

#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)  // 2 ^ GPIO_NUMBER in hex
#define USE_EXT0_WAKEUP          0               // 1 = EXT0 wakeup, 0 = EXT1 wakeup, NOTE:EXT0 compiler error
#define WAKEUP_GPIO              GPIO_NUM_2     // Only RTC IO are allowed - XIAO ESP32C6 Pin example
RTC_DATA_ATTR int bootCount = 0;

void setup() {
  Serial.begin(115200);
  delay(1000);  //Take some time to open up the Serial Monitor

  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

#if USE_EXT0_WAKEUP
  esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);  //1 = High, 0 = Low
  rtc_gpio_pullup_dis(WAKEUP_GPIO);
  rtc_gpio_pulldown_en(WAKEUP_GPIO);
#else  // EXT1 WAKEUP
  esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  rtc_gpio_pulldown_en(WAKEUP_GPIO);  // GPIO 2 is tie to GND in order to wake up in HIGH
  rtc_gpio_pullup_dis(WAKEUP_GPIO);   // Disable PULL_UP in order to allow it to wakeup on HIGH
#endif

  Serial.println("Going to sleep now");
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop() {
}

(post deleted by author)

unfortunately it doesn’t work. it still immediately wakes up.
Note that I have to switch to EXT1 wakeup as otherwise I get
Compilation error: ‘esp_sleep_enable_ext0_wakeup’ was not declared in this scope; did you mean ‘esp_sleep_enable_ext1_wakeup’?

for testing I have temporarily added an external 10k pull down resistor to gpio 2. When I use that, it works fine, but when I set the program to use gpio 5 or 7 it fails and immediately wakes up when I run the program.

The only wake-up pins available on XIAO_ESP32C6 are D0 (gpio0) and D2 (gpio2).

Only RTC IO can be used as a source for external wake
source. They are pins: 0,2,4,12-15,25-27,32-39.
XIAO ESP32C6 RTC IO pins : D0(0), D2(2)
XIAO ESP32C3 RTC IO pins : D0(2), D2(4)
XIAO ESP32S3 RTC IO pins : D1(2), D3(4)

Please read the comments carefully.

#define USE_EXT0_WAKEUP  0  // 1:EXT0, 0:EXT1 , NOTE:EXT0 compiler error

I have confirmed that the example sketch I posted works.

that’s confusing, because in the example code given it reads:

Bit mask of GPIO numbers which will cause wakeup.
Only GPIOswhich have RTC functionality can be used in this bit map.
For different SoCs, the related GPIOs are:
ESP32: 0, 2, 4, 12-15, 25-27, 32-39- 
ESP32-S2: 0-21 
ESP32-S3: 0-21 
ESP32-C6: 0-7 
ESP32-H2: 7-14
So I was using pins 0-7 .

It is indeed confusing, but not all pins 0-7 of the C6 chip are assigned to XIAO pins. See “XIAO ESP32C6 Pin List” in Wiki.

GPIO 7 is on the back of the seeed studio c6, not on the usual pins. (I was using GPIO 5 at first, but on the schematic it tells me to avoid that one)

What is sample code? Where can I find it?

According to “ESP32-C6 Technical Reference Manual 7.13 LO IO MUX Functions List”, GOIO 0-7 can be used as a wake-up source. I have checked pins 0, 1, and 2 assigned to XIAO and they wake up without any problem.
I have not checked the pads on the back as I do not have access to them.

I used a fresh esp32C6 (as the other one had things connected to D2, including an external pulldown) and added a line that calls esp_sleep_is_valid_wakeup_gpio() in order to check the validity of a port. To my surprise in now works with gpio 2, 5 and 7. All report to be valid GPIO, Back to the other board and gpio7 is waking up automatically without a button press. Running the exact same code! All though I find it very, very hard to believe myself, it looks like the other board is broken, but only slightly, as it works fine with external pulldown resistors. Very, very strange.

@msfujino now I’m a bit afraid to attach a button to gpio_7 and possibly damage this fresh esp32c6 as well. gpio 7 is labeled as MTDO, which looks like an output to me. That might conflict with the input button. Do I need to configure this in someway before pressing the button? will it go back to MTDO output when it wakes up. I’m scared…

I think it is safer not to use gpio 4-7 because it has another function assigned to it. Equally, BoardSupportPackage may initialized gpio4-7 to some function.

Are the wires soldered to the pads on the back? Or are they soldered directly to the board?

Does it work with D0?