kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/clear_intr_status_when_enable_intr_v3.1' into 'release/v3.1'
driver(gpio): fix the gpio interrupt false triggering issue(backport v3.1) See merge request idf/esp-idf!2806pull/2666/head
commit
4314b00289
|
@ -91,9 +91,19 @@ esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void gpio_intr_status_clr(gpio_num_t gpio_num)
|
||||||
|
{
|
||||||
|
if (gpio_num < 32) {
|
||||||
|
GPIO.status_w1tc = BIT(gpio_num);
|
||||||
|
} else {
|
||||||
|
GPIO.status1_w1tc.intr_st = BIT(gpio_num - 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static esp_err_t gpio_intr_enable_on_core (gpio_num_t gpio_num, uint32_t core_id)
|
static esp_err_t gpio_intr_enable_on_core (gpio_num_t gpio_num, uint32_t core_id)
|
||||||
{
|
{
|
||||||
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||||
|
gpio_intr_status_clr(gpio_num);
|
||||||
if (core_id == 0) {
|
if (core_id == 0) {
|
||||||
GPIO.pin[gpio_num].int_ena = GPIO_PRO_CPU_INTR_ENA; //enable pro cpu intr
|
GPIO.pin[gpio_num].int_ena = GPIO_PRO_CPU_INTR_ENA; //enable pro cpu intr
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,6 +121,7 @@ esp_err_t gpio_intr_disable(gpio_num_t gpio_num)
|
||||||
{
|
{
|
||||||
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||||
GPIO.pin[gpio_num].int_ena = 0; //disable GPIO intr
|
GPIO.pin[gpio_num].int_ena = 0; //disable GPIO intr
|
||||||
|
gpio_intr_status_clr(gpio_num);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +260,11 @@ esp_err_t gpio_config(const gpio_config_t *pGPIOConfig)
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
io_reg = GPIO_PIN_MUX_REG[io_num];
|
io_reg = GPIO_PIN_MUX_REG[io_num];
|
||||||
if (((gpio_pin_mask >> io_num) & BIT(0)) && io_reg) {
|
if (((gpio_pin_mask >> io_num) & BIT(0))) {
|
||||||
|
if (!io_reg) {
|
||||||
|
ESP_LOGE(GPIO_TAG, "IO%d is not a valid GPIO",io_num);
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
if(RTC_GPIO_IS_VALID_GPIO(io_num)){
|
if(RTC_GPIO_IS_VALID_GPIO(io_num)){
|
||||||
rtc_gpio_deinit(io_num);
|
rtc_gpio_deinit(io_num);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,16 @@
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
|
|
||||||
|
#define WAKE_UP_IGNORE 1 // gpio_wakeup function development is not completed yet, set it deprecated.
|
||||||
#define GPIO_OUTPUT_IO 18 // default output GPIO
|
#define GPIO_OUTPUT_IO 18 // default output GPIO
|
||||||
#define GPIO_INPUT_IO 19 // default input GPIO
|
#define GPIO_INPUT_IO 19 // default input GPIO
|
||||||
#define GPIO_OUTPUT_MAX GPIO_NUM_34
|
#define GPIO_OUTPUT_MAX GPIO_NUM_34
|
||||||
static volatile int disable_intr_times = 0; // use this to calculate how many times it go into interrupt
|
static volatile int disable_intr_times = 0; // use this to calculate how many times it go into interrupt
|
||||||
static volatile int level_intr_times = 0; // use this to get how many times the level interrupt happened
|
static volatile int level_intr_times = 0; // use this to get how many times the level interrupt happened
|
||||||
static volatile int edge_intr_times = 0; // use this to get how many times the edge interrupt happened
|
static volatile int edge_intr_times = 0; // use this to get how many times the edge interrupt happened
|
||||||
|
#if !WAKE_UP_IGNORE
|
||||||
static bool wake_up_result = false; // use this to judge the wake up event happen or not
|
static bool wake_up_result = false; // use this to judge the wake up event happen or not
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* do some initialization operation in this function
|
* do some initialization operation in this function
|
||||||
|
@ -70,6 +73,7 @@ static void gpio_isr_level_handler2(void* arg)
|
||||||
ets_printf("GPIO[%d] intr, val: %d, level_intr_times = %d\n", gpio_num, gpio_get_level(gpio_num), level_intr_times);
|
ets_printf("GPIO[%d] intr, val: %d, level_intr_times = %d\n", gpio_num, gpio_get_level(gpio_num), level_intr_times);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !WAKE_UP_IGNORE
|
||||||
// get result of waking up or not
|
// get result of waking up or not
|
||||||
static void sleep_wake_up(void *arg)
|
static void sleep_wake_up(void *arg)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +96,7 @@ static void trigger_wake_up(void *arg)
|
||||||
gpio_set_level(GPIO_OUTPUT_IO, 1);
|
gpio_set_level(GPIO_OUTPUT_IO, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void prompt_to_continue(const char* str)
|
static void prompt_to_continue(const char* str)
|
||||||
{
|
{
|
||||||
|
@ -465,6 +469,7 @@ TEST_CASE("GPIO repeate call service and isr has no memory leak test","[gpio][te
|
||||||
TEST_ASSERT_INT32_WITHIN(size, esp_get_free_heap_size(), 100);
|
TEST_ASSERT_INT32_WITHIN(size, esp_get_free_heap_size(), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !WAKE_UP_IGNORE
|
||||||
//this function development is not completed yet, set it ignored
|
//this function development is not completed yet, set it ignored
|
||||||
TEST_CASE("GPIO wake up enable and disenable test", "[gpio][ignore]")
|
TEST_CASE("GPIO wake up enable and disenable test", "[gpio][ignore]")
|
||||||
{
|
{
|
||||||
|
@ -479,6 +484,7 @@ TEST_CASE("GPIO wake up enable and disenable test", "[gpio][ignore]")
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
TEST_ASSERT_FALSE(wake_up_result);
|
TEST_ASSERT_FALSE(wake_up_result);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// this case need the resistance to pull up the voltage or pull down the voltage
|
// this case need the resistance to pull up the voltage or pull down the voltage
|
||||||
// ignored because the voltage needs to be tested with multimeter
|
// ignored because the voltage needs to be tested with multimeter
|
||||||
|
|
Ładowanie…
Reference in New Issue