ESP32-C3浅休眠时中断一直触发 [IDFGH-5383]

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

ESP32-C3浅休眠时中断一直触发 [IDFGH-5383]

Postby lwshowl » Sun Jun 06, 2021 6:00 am

目前在用ESP32-C3,用BLE 低功耗后 要启用自动浅休眠,开启了浅休眠之后GPIO 中断一直不停触发,不管在设置里面内部上拉 还是外部47K上拉。
我确定已经去抖动了,在中断里面解绑了中断,等中断服务结束之后重新绑定的中断。在中断里才会增加的变量也一直在增加,不开自动浅休眠就没这个问题,请问有人知道是什么情况吗
  1. io_conf.mode = GPIO_MODE_INPUT;
  2. io_conf.intr_type = GPIO_INTR_POSEDGE;
  3. io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
  4. io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
  5. io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
  6. gpio_config(&io_conf);
  7. // change gpio intrrupt type for one pin
  8. gpio_set_intr_type(GPIO_NUM_10, GPIO_INTR_ANYEDGE);
  9. // //install gpio isr service
  10.  gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  11. // // //hook isr handler for specific gpio pin again
  12. gpio_isr_handler_add(GPIO_NUM_10, lock_isr_handler, (void *)GPIO_NUM_10);
  13.  
  14. void lock_isr_handler(void *arg)
  15. {
  16.     is_reporting++;
  17.     gpio_isr_handler_remove(GPIO_NUM_10);
  18.     uint8_t event = event_REPORT;
  19.     xQueueSend(event_Queue, &event, portMAX_DELAY);
  20. }
  21.  

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP32-C3浅休眠时中断一直触发

Postby ESP_Gargamel » Mon Jun 07, 2021 2:34 am

你能整一个能复现问题的 .c 吗?可能也不需要 BLE 部分。用得什么开发板?

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

Re: ESP32-C3浅休眠时中断一直触发

Postby lwshowl » Mon Jun 07, 2021 5:19 pm

我现在用的C++ 哦,这段代码应该可以复现问题
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "esp_system.h"
  4. #include "esp_log.h"
  5. #include "driver/uart.h"
  6. #include "driver/gpio.h"
  7. #include "driver/gpio.h"
  8. // #include "app_ble.h"
  9. #include "esp_pm.h"
  10. #include "esp_sleep.h"
  11. #include "soc/uart_periph.h"
  12. #include "soc/rtc_cntl_reg.h"
  13. #include "esp_timer.h"
  14.  
  15. SemaphoreHandle_t init_finish_semaphore;
  16. QueueHandle_t event_Queue;
  17.  
  18. #define pdSECOND pdMS_TO_TICKS(1000)
  19.  
  20. #define GPIO_OUTPUT_IO_1 2
  21. #define GPIO_OUTPUT_IO_3 4
  22. #define GPIO_OUTPUT_IO_4 6
  23. #define GPIO_OUTPUT_IO_5 10
  24.  
  25. #define GPIO_OUTPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_1 | 1ULL << GPIO_OUTPUT_IO_3 | 1ULL << GPIO_OUTPUT_IO_4))
  26. #define GPIO_INPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_5))
  27. #define ESP_INTR_FLAG_DEFAULT 0
  28.  
  29. #define event_REPORT (uint8_t)0
  30.  
  31. void timer_init();
  32. void pin_Setup();
  33. void lock_isr_handler(void *arg);
  34. uint32_t counter_isr = 0;
  35.  
  36. void uart_thread(void *)
  37. {
  38.  
  39.     uint8_t *data = (uint8_t *)malloc(sizeof(1024));
  40.     uint8_t event;
  41.     int32_t result = 0;
  42.  
  43.     xSemaphoreTake(init_finish_semaphore, portMAX_DELAY);
  44.     ESP_LOGI("DBG", "enter event loop");
  45.     while (1)
  46.     {
  47.         xQueueReceive(event_Queue, &event, portMAX_DELAY);
  48.         switch (event)
  49.         {
  50.         case event_REPORT:
  51.             ESP_LOGI("DBG", "INTR TRIGGERED");
  52.             vTaskDelay(pdMS_TO_TICKS(3000));
  53.             gpio_isr_handler_add(GPIO_NUM_10, lock_isr_handler, (void *)0);
  54.         }
  55.     }
  56. }
  57.  
  58. void lock_isr_handler(void *arg)
  59. {
  60.     // ESP_LOGI("LOCK_PIN","Interupt triggered");
  61.     // is_reporting++;
  62.     gpio_isr_handler_remove(GPIO_NUM_10);
  63.     counter_isr++;
  64.     uint8_t event = event_REPORT;
  65.     xQueueSend(event_Queue, &event, portMAX_DELAY);
  66. }
  67.  
  68. void pin_Setup()
  69. {
  70.     gpio_config_t io_conf;
  71.     //disable interrupt
  72.     io_conf.intr_type = GPIO_INTR_DISABLE;
  73.     //set as output mode
  74.     io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
  75.     //bit mask of the pins that you want to set,e.g.GPIO18/19
  76.     io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
  77.     //disable pull-down mode
  78.     io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
  79.     //disable pull-up mode
  80.     io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
  81.     //configure GPIO with the given settings
  82.     gpio_config(&io_conf);
  83.  
  84.     io_conf.mode = GPIO_MODE_INPUT;
  85.     io_conf.intr_type = GPIO_INTR_ANYEDGE;
  86.     io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
  87.     io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
  88.     io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
  89.  
  90.     gpio_config(&io_conf);
  91.  
  92.     gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  93.     gpio_isr_handler_add(GPIO_NUM_10, lock_isr_handler, (void *)GPIO_NUM_10);
  94.     // gpio_sleep_sel_dis(GPIO_NUM_10);
  95.     gpio_wakeup_enable(GPIO_NUM_4, GPIO_INTR_HIGH_LEVEL);
  96.     esp_sleep_enable_gpio_wakeup();
  97.  
  98.     printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
  99. }
  100.  
  101. static void periodic_timer_callback(void *arg)
  102. {
  103.     int64_t time_since_boot = esp_timer_get_time();
  104.     ESP_LOGI("timer", "Periodic timer called, time since boot: %lld us", time_since_boot);
  105.     uint8_t event = event_REPORT;
  106.     xQueueSend(event_Queue, &event, portMAX_DELAY);
  107. }
  108.  
  109. void timer_init()
  110. {
  111.     const esp_timer_create_args_t periodic_timer_args = {
  112.         .callback = &periodic_timer_callback,
  113.         /* name is optional, but may help identify the timer when debugging */
  114.         .name = "periodic"};
  115.  
  116.     esp_timer_handle_t periodic_timer;
  117.  
  118.     ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
  119.  
  120.     ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, (uint64_t)(86400000000)));
  121.  
  122.     /* Print debugging information about timers to console every 2 seconds */
  123.  
  124.     ESP_ERROR_CHECK(esp_timer_dump(stdout));
  125.     // usleep(1000000);
  126.  
  127.     /* Timekeeping continues in light sleep, and timers are scheduled
  128.      * correctly after light sleep.
  129.      */
  130.     // ESP_LOGI("timer", "Entering light sleep for 0.5s, time since boot: %lld us",
  131.     //          esp_timer_get_time());
  132.  
  133.     // ESP_ERROR_CHECK(esp_sleep_enable_timer_wakeup((uint64_t)(100 * 12 * 60 * 60 * 1000 * 1000)));
  134. }
  135.  
  136. extern "C" void app_main(void)
  137. {
  138.  
  139.     esp_pm_config_esp32c3_t pm_config = {
  140.         .max_freq_mhz = 160,
  141.         .min_freq_mhz = 80,
  142.         .light_sleep_enable = true,
  143.     };
  144.  
  145.     ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
  146.  
  147.     //initialize mutex
  148.     portMUX_TYPE my_mutex;
  149.     vPortCPUInitializeMutex(&my_mutex);
  150.     //initialize semaphores
  151.     init_finish_semaphore = xSemaphoreCreateBinary();
  152.     event_Queue = xQueueCreate(200, sizeof(uint8_t));
  153.  
  154.     //set up all the pins
  155.     pin_Setup();
  156.     //init timer
  157.     timer_init();
  158.     //initialize queues and tasks
  159.     xTaskCreate(uart_thread, "uart_task", 30000, NULL, 6, NULL);
  160.     vTaskDelay(pdMS_TO_TICKS(1000));
  161.  
  162.     xSemaphoreGive(init_finish_semaphore);
  163.  
  164.     vTaskDelay(pdMS_TO_TICKS(1000));
  165.     uint8_t event = event_REPORT;
  166.     xQueueSend(event_Queue, &event, portMAX_DELAY);
  167.  
  168.     while (1)
  169.     {
  170.         ESP_LOGI("DBG", "GPIO10:%d counter:%d" , gpio_get_level(GPIO_NUM_10),counter_isr);
  171.         vTaskDelay(pdMS_TO_TICKS(1000));
  172.     }
  173. }

目前用的是安信可的ESP32-C3 32S 开发板,我使用单独的ESP32-C3 32S 模块也会出现这样的问题。
一开始我在面包板用一根跳线连接IO10 和 VDD3V3 触发了中断,后来就去掉跳线了,IO10 什么也没连,
但是IO10 的中断一直在触发
这是运行结果图
Attachments
QQ截图20210608011224.jpg
QQ截图20210608011224.jpg (196.77 KiB) Viewed 8511 times

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP32-C3浅休眠时中断一直触发

Postby ESP_Gargamel » Tue Jun 08, 2021 11:24 am

你在 menuconfig 做了哪些配置?我在设置了 PM_ENABLE 和 FREERTOS_USE_TICKLESS_IDLE 后,使用你的代码,没有遇到问题。

Code: Select all

I (18483) DBG: GPIO10:0 counter:0
I (19493) DBG: GPIO10:0 counter:0
I (20503) DBG: GPIO10:0 counter:0
I (21513) DBG: GPIO10:0 counter:0
I (22523) DBG: GPIO10:0 counter:0
I (23533) DBG: GPIO10:0 counter:0
I (24543) DBG: GPIO10:0 counter:0
I (25553) DBG: GPIO10:0 counter:0
I (26563) DBG: GPIO10:0 counter:0
I (27573) DBG: GPIO10:0 counter:0
I (28583) DBG: GPIO10:0 counter:0
I (29593) DBG: GPIO10:0 counter:0
I (30603) DBG: GPIO10:0 counter:0
I (31613) DBG: GPIO10:0 counter:0
I (32623) DBG: GPIO10:0 counter:0
I (33633) DBG: GPIO10:0 counter:0
I (34643) DBG: GPIO10:0 counter:0
I (35653) DBG: GPIO10:0 counter:0
I (36663) DBG: GPIO10:0 counter:0
I (37673) DBG: GPIO10:0 counter:0
I (38683) DBG: GPIO10:0 counter:0
I (39693) DBG: GPIO10:0 counter:0
I (40703) DBG: GPIO10:0 counter:0
I (41713) DBG: GPIO10:0 counter:0
I (42723) DBG: GPIO10:0 counter:0
I (43733) DBG: GPIO10:0 counter:0
I (44743) DBG: GPIO10:0 counter:0
I (45753) DBG: GPIO10:0 counter:0
I (46763) DBG: GPIO10:0 counter:0
附件是我这边的 bin,你可以试一下,去掉后缀 .txt,地址 0x10000。或者你可以提供你的 bin,我这边对比一下。如果我们的结果不一致,那再来看看开发板上的区别。
Attachments
blink.bin.txt
(186.27 KiB) Downloaded 489 times

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

Re: ESP32-C3浅休眠时中断一直触发

Postby lwshowl » Tue Jun 08, 2021 2:17 pm

我加了一个外置32k 的晶振,rtc 时钟也是的外置32k ,而且打开了menuconfig 里面的power down cpu in light sleep
我不知道怎么刷bin 文件,我贴下我的bin 吧
Attachments
bed_esp32.bin.txt
(218.5 KiB) Downloaded 881 times

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP32-C3浅休眠时中断一直触发

Postby ESP_Gargamel » Wed Jun 09, 2021 2:00 am

也没有问题。

Code: Select all

I (633) cpu_start: Project name:     bed_esp32
I (638) cpu_start: App version:      1
I (643) cpu_start: Compile time:     Jun  8 2021 22:10:27
I (649) cpu_start: ELF file SHA256:  a8ad249342d12bae...
I (655) cpu_start: ESP-IDF:          v4.4-dev-1254-g639e7ad49-dirty
I (662) heap_init: Initializing. RAM available for dynamic allocation:
I (669) heap_init: At 3FC90DF0 len 0002F210 (188 KiB): DRAM
I (675) heap_init: At 3FCC0000 len 0001F060 (124 KiB): STACK/DRAM
I (682) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM
I (689) spi_flash: detected chip: generic
I (693) spi_flash: flash io: dio
W (697) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (721) sleep: Configure to isolate all GPIO pins in sleep state
I (721) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 40, Light sleep: DISABLED
I (727) sleep: Disable automatic switching of GPIO sleep configuration
I (734) cpu_start: Starting scheduler.
I (00:00:00.166) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 80, Light sleep: ENABLED
I (00:00:00.176) sleep: Enable automatic switching of GPIO sleep configuration
I (00:00:00.184) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (00:00:00.194) gpio: GPIO[4]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (00:00:00.204) gpio: GPIO[6]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (00:00:00.214) gpio: GPIO[10]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:3 
Minimum free heap size: 282268 bytes
Timer stats:
Name                  Period      Alarm       
timer@0x3fc9adf8      86400000000  86400800595 
I (00:00:01.271) DBG: enter event loop
I (00:00:02.364) DBG: INTR TRIGGERED
I (00:00:02.364) DBG: GPIO10:0 counter:0
I (00:00:03.457) DBG: GPIO10:0 counter:0
I (00:00:04.550) DBG: GPIO10:0 counter:0
I (00:00:05.643) DBG: GPIO10:0 counter:0
I (00:00:06.736) DBG: GPIO10:0 counter:0
I (00:00:07.829) DBG: GPIO10:0 counter:0
I (00:00:08.922) DBG: GPIO10:0 counter:0
I (00:00:10.015) DBG: GPIO10:0 counter:0
I (00:00:11.108) DBG: GPIO10:0 counter:0
I (00:00:12.200) DBG: GPIO10:0 counter:0
I (00:00:13.294) DBG: GPIO10:0 counter:0
I (00:00:14.387) DBG: GPIO10:0 counter:0
I (00:00:15.480) DBG: GPIO10:0 counter:0
I (00:00:16.572) DBG: GPIO10:0 counter:0
I (00:00:17.665) DBG: GPIO10:0 counter:0
I (00:00:18.758) DBG: GPIO10:0 counter:0
I (00:00:19.851) DBG: GPIO10:0 counter:0
I (00:00:20.944) DBG: GPIO10:0 counter:0
I (00:00:22.037) DBG: GPIO10:0 counter:0
I (00:00:23.130) DBG: GPIO10:0 counter:0
I (00:00:24.223) DBG: GPIO10:0 counter:0
I (00:00:25.316) DBG: GPIO10:0 counter:0
I (00:00:26.410) DBG: GPIO10:0 counter:0
这边暂时没有带 32K 的板子,你如果不用 32K,会如何?你可以通过一些对比,先排查下是什么引入的这个问题。

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

Re: ESP32-C3浅休眠时中断一直触发

Postby lwshowl » Wed Jun 09, 2021 5:35 am

我是触发一次中断之后,过段时间中断会重复触发

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

Re: ESP32-C3浅休眠时中断一直触发

Postby lwshowl » Wed Jun 09, 2021 5:36 am

我看看去掉32k 会不会这样

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

Re: ESP32-C3浅休眠时中断一直触发

Postby lwshowl » Wed Jun 09, 2021 11:12 am

我在安信可的开发板问题好像解决了,但是我用安信可模块的板子依然是不断触发,不知道是不是因为我是直接用电池供电,没有外部稳压器的原因

lwshowl
Posts: 27
Joined: Sat Jun 05, 2021 7:33 am

Re: ESP32-C3浅休眠时中断一直触发

Postby lwshowl » Wed Jun 09, 2021 11:46 am

不过在安信可的板子上面,我设置的是按上升或者下降沿触发,但是我把IO10 接到安信可板子上的AMS1117-3.3 的输出上之后,中断一直在触发。把IO10 不接3.3V之后就不触发了

Who is online

Users browsing this forum: No registered users and 141 guests