TWAI Driver Installation Fails with IRAM Enabled on ESP32-S3

inF1704
Posts: 3
Joined: Fri Nov 22, 2024 2:27 pm

TWAI Driver Installation Fails with IRAM Enabled on ESP32-S3

Postby inF1704 » 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):

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
Failing Configuration (with IRAM):

Code: Select all

g_config.intr_flags = ESP_INTR_FLAG_LEVEL1 | ESP_INTR_FLAG_IRAM;  // Fails with 0x102
Steps Taken:

1. Implemented proper DRAM data structures:

Code: Select all

volatile isr_data_t g_isr_data __attribute__((section(".dram1.data")));
2. Minimized ISR to rule out complexity issues:

Code: Select all

void IRAM_ATTR twai_isr_handler(void* arg) {
    // Even empty ISR fails
}
3. Added all necessary build flags:

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
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.

inF1704
Posts: 3
Joined: Fri Nov 22, 2024 2:27 pm

Re: TWAI Driver Installation Fails with IRAM Enabled on ESP32-S3

Postby inF1704 » Fri Nov 29, 2024 9:37 pm

Was anybody successful in a project to implement TWAI ISR in IRAM?

username
Posts: 555
Joined: Thu May 03, 2018 1:18 pm

Re: TWAI Driver Installation Fails with IRAM Enabled on ESP32-S3

Postby username » Sun Dec 01, 2024 10:06 am

Not sure if this will help. But there is a note about using it in IRAM.

Place the TWAI ISR in to IRAM. This will allow the ISR to avoid cache misses, and also be able to run whilst the cache is disabled (such as when writing to SPI Flash). Note that if this option is enabled: - Users should also set the ESP_INTR_FLAG_IRAM in the driver configuration structure when installing the driver (see docs for specifics). - Alert logging (i.e., setting of the TWAI_ALERT_AND_LOG flag) will have no effect.

inF1704
Posts: 3
Joined: Fri Nov 22, 2024 2:27 pm

Re: TWAI Driver Installation Fails with IRAM Enabled on ESP32-S3

Postby inF1704 » Mon Dec 02, 2024 8:17 am

Hello username,

that is a good point. I will try to test it without the FLAG.

Code: Select all

g_config.intr_flags = ESP_INTR_FLAG_IRAM;  // Fails with 0x102[/quote]

Who is online

Users browsing this forum: MicroController and 47 guests