TWAI Driver Installation Fails with IRAM Enabled on ESP32-S3
Posted: Fri Nov 22, 2024 7:55 pm
I'm experiencing issues with the TWAI driver installation on an ESP32-S3 when trying to enable IRAM functionality. The driver works perfectly without IRAM flags but fails with error 0x102 when IRAM is enabled.
Hardware Setup
- ESP32-S3
- SN65HVD230 CAN transceiver
- Standard CAN bus termination (120Ω)
- Operating at 250 kbit/s
Implementation Details
Working Configuration (without IRAM):
Failing Configuration (with IRAM):
Steps Taken:
1. Implemented proper DRAM data structures:
2. Minimized ISR to rule out complexity issues:
3. Added all necessary build flags:
Current Status
- Driver installation fails with error 0x102 only when IRAM flags are enabled
- All C++ bindings have been minimized
- ISR and data structures are properly placed in IRAM/DRAM
- Even a minimal implementation fails
Any insights into why the TWAI driver installation fails with IRAM enabled would be greatly appreciated.
Hardware Setup
- ESP32-S3
- SN65HVD230 CAN transceiver
- Standard CAN bus termination (120Ω)
- Operating at 250 kbit/s
Implementation Details
Working Configuration (without IRAM):
Code: Select all
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_14, GPIO_NUM_13, TWAI_MODE_NORMAL);
g_config.rx_queue_len = 64;
g_config.tx_queue_len = 32;
g_config.intr_flags = ESP_INTR_FLAG_LEVEL1; // Works fine
Code: Select all
g_config.intr_flags = ESP_INTR_FLAG_LEVEL1 | ESP_INTR_FLAG_IRAM; // Fails with 0x102
1. Implemented proper DRAM data structures:
Code: Select all
volatile isr_data_t g_isr_data __attribute__((section(".dram1.data")));
Code: Select all
void IRAM_ATTR twai_isr_handler(void* arg) {
// Even empty ISR fails
}
Code: Select all
build_flags =
-DCONFIG_TWAI_ISR_IN_IRAM=1
-DCONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID=1
-DCONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT=1
-DCONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC=1
-DCONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST=1
- Driver installation fails with error 0x102 only when IRAM flags are enabled
- All C++ bindings have been minimized
- ISR and data structures are properly placed in IRAM/DRAM
- Even a minimal implementation fails
Any insights into why the TWAI driver installation fails with IRAM enabled would be greatly appreciated.