Page 1 of 1

ESP32-S3-WROOM-1 GPIO stays high for an extended period

Posted: Fri Jan 13, 2023 4:17 am
by mikedawes
Seeing odd behavior when rapidly toggling a GPIO on the ESP32-S3-WROOM-1. There appears to be a very repeatable period where the GPIO is high for an extended period of time. The scope is configured to trigger on any pulse longer than 1uS. The code is based on the Hello World example with no changes to sdkconfig and just spins a tight loop.
Has anyone else experienced this?
SDS00006.png
SDS00006.png (22.3 KiB) Viewed 793 times
  1. /* Hello World Example
  2.  
  3.    This example code is in the Public Domain (or CC0 licensed, at your option.)
  4.  
  5.    Unless required by applicable law or agreed to in writing, this
  6.    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  7.    CONDITIONS OF ANY KIND, either express or implied.
  8. */
  9. #include <stdio.h>
  10. #include "sdkconfig.h"
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/task.h"
  13. #include "esp_system.h"
  14. #include "esp_spi_flash.h"
  15. #include <driver/gpio.h>
  16.  
  17. /* Private defines -----------------------------------------------------------*/
  18. #define CNVST_PIN             14      /* Conversion start control. */
  19.  
  20. /* Function Definitions ------------------------------------------------------*/
  21. void IRAM_ATTR hw_gpio_toggle(void)
  22. {
  23.     uint32_t reg_val = (1ULL << CNVST_PIN);
  24.  
  25.     do {
  26.  
  27.         REG_WRITE(GPIO_OUT_W1TS_REG, reg_val);
  28.  
  29.         REG_WRITE(GPIO_OUT_W1TC_REG, reg_val);
  30.  
  31.     } while (1);
  32. }
  33.  
  34. static void hw_gpio_init(void)
  35. {
  36.     gpio_config_t io_conf = {};
  37.     uint32_t reg_val;
  38.  
  39.     /* Configure GPIO pin output level - LOW */
  40.     reg_val = (1ULL << CNVST_PIN);
  41.     REG_WRITE(GPIO_OUT_W1TC_REG, reg_val);
  42.  
  43.     io_conf.intr_type = GPIO_INTR_DISABLE;
  44.     io_conf.mode = GPIO_MODE_OUTPUT;
  45.     io_conf.pin_bit_mask = (1ULL << CNVST_PIN);
  46.     io_conf.pull_down_en = 1;
  47.     io_conf.pull_up_en = 0;
  48.     ESP_ERROR_CHECK(gpio_config(&io_conf));
  49. }
  50.  
  51. void app_main(void)
  52. {
  53.     uint16_t recvbuf;
  54.  
  55.     printf("Hello world!\n");
  56.  
  57.     /* Print chip information */
  58.     esp_chip_info_t chip_info;
  59.     esp_chip_info(&chip_info);
  60.     printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
  61.             CONFIG_IDF_TARGET,
  62.             chip_info.cores,
  63.             (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
  64.             (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
  65.  
  66.     printf("silicon revision %d, ", chip_info.revision);
  67.  
  68.     printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
  69.             (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
  70.  
  71.     printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
  72.  
  73.     hw_gpio_init();
  74.  
  75.     for (;;) {
  76.  
  77.         hw_gpio_toggle();
  78.  
  79.     }
  80. }

Re: ESP32-S3-WROOM-1 GPIO stays high for an extended period

Posted: Sat Jan 14, 2023 3:58 pm
by mikedawes
Root causing this myself -- too much coffee and not enough sleep. The behavior I observed was a preemptive context switch while the GPIO was set high.