diff --git a/components/esp_driver_i2c/Kconfig b/components/esp_driver_i2c/Kconfig index 294aa05977..4f75a6f779 100644 --- a/components/esp_driver_i2c/Kconfig +++ b/components/esp_driver_i2c/Kconfig @@ -2,6 +2,7 @@ menu "ESP-Driver:I2C Configurations" depends on SOC_I2C_SUPPORTED config I2C_ISR_IRAM_SAFE bool "I2C ISR IRAM-Safe" + select I2C_MASTER_ISR_HANDLER_IN_IRAM default n help Ensure the I2C interrupt is IRAM-Safe by allowing the interrupt handler to be @@ -23,4 +24,10 @@ menu "ESP-Driver:I2C Configurations" help I2C slave version 2 solves some existing known issues. Such as write/read workflow, stretch handling, etc. + config I2C_MASTER_ISR_HANDLER_IN_IRAM + bool "Place I2C master ISR handler into IRAM" + default y + help + Place I2C master ISR handler into IRAM for better performance and fewer cache misses. + endmenu # I2C Configurations diff --git a/components/esp_driver_i2c/i2c_master.c b/components/esp_driver_i2c/i2c_master.c index 61f24794ca..1f69ec8920 100644 --- a/components/esp_driver_i2c/i2c_master.c +++ b/components/esp_driver_i2c/i2c_master.c @@ -646,7 +646,7 @@ static esp_err_t s_i2c_transaction_start(i2c_master_dev_handle_t i2c_dev, int xf ///////////////////////////////I2C DRIVERS////////////////////////////////////////////////////////////// -IRAM_ATTR static void i2c_isr_receive_handler(i2c_master_bus_t *i2c_master) +I2C_MASTER_ISR_ATTR static void i2c_isr_receive_handler(i2c_master_bus_t *i2c_master) { i2c_hal_context_t *hal = &i2c_master->base->hal; @@ -681,7 +681,7 @@ IRAM_ATTR static void i2c_isr_receive_handler(i2c_master_bus_t *i2c_master) #endif } -static void IRAM_ATTR i2c_master_isr_handler_default(void *arg) +static void i2c_master_isr_handler_default(void *arg) { i2c_master_bus_handle_t i2c_master = (i2c_master_bus_t*) arg; diff --git a/components/esp_driver_i2c/i2c_private.h b/components/esp_driver_i2c/i2c_private.h index 89b763c624..2e080161d5 100644 --- a/components/esp_driver_i2c/i2c_private.h +++ b/components/esp_driver_i2c/i2c_private.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -42,6 +42,12 @@ extern "C" { #define LP_I2C_BUS_CLK_ATOMIC() PERIPH_RCC_ATOMIC() #endif +#ifdef CONFIG_I2C_MASTER_ISR_HANDLER_IN_IRAM +#define I2C_MASTER_ISR_ATTR IRAM_ATTR +#else +#define I2C_MASTER_ISR_ATTR +#endif + #if CONFIG_I2C_ISR_IRAM_SAFE #define I2C_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) #else diff --git a/components/esp_driver_i2c/linker.lf b/components/esp_driver_i2c/linker.lf index 7a3bcd47e5..8dbbda1fb3 100644 --- a/components/esp_driver_i2c/linker.lf +++ b/components/esp_driver_i2c/linker.lf @@ -1,6 +1,8 @@ [mapping:i2c_driver] archive: libesp_driver_i2c.a entries: + if I2C_MASTER_ISR_HANDLER_IN_IRAM = y: + i2c_master: i2c_master_isr_handler_default (noflash) if I2C_ISR_IRAM_SAFE = y: i2c_master: s_i2c_send_command_async (noflash) i2c_master: s_i2c_write_command (noflash) diff --git a/components/esp_driver_i2c/test_apps/i2c_test_apps/pytest_i2c.py b/components/esp_driver_i2c/test_apps/i2c_test_apps/pytest_i2c.py index 7840f8d32e..fbcfd363e9 100644 --- a/components/esp_driver_i2c/test_apps/i2c_test_apps/pytest_i2c.py +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/pytest_i2c.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest from pytest_embedded import Dut