Cache disabled but cached memory region accessed with UART and ESP_INTR_FLAG_IRAM

BenSuffolk
Posts: 2
Joined: Wed Aug 17, 2022 5:36 am

Cache disabled but cached memory region accessed with UART and ESP_INTR_FLAG_IRAM

Postby BenSuffolk » Wed Aug 17, 2022 5:57 am

I have a situation where I am using a UART1 (or 2) on pins mapped through the GPIO matrix, and I am using the IRAM interrupt. HOwever when I then try to use LitteFS to save to FLASH I get a Panic.

I am using a custom built PCB with an ESP WROVER-E and I'm using the Arduino Framework via platform.io which reports to be using ESP-IDF v4.4.1-1-gb8050b365e

The GPIO I am using for the UART is TX = 5, RX = 19, EN/RTS = 18. I have also tried a second set of GPIO that I have TX = 21, RX = 23, EN/RTS = 22. These are pins I have currently baked into a PCB design so am keen not to change them if I can.

I'm using the https://github.com/someweisguy/esp_dmx library to handle all the UART code and interrupts etc.

This is the error I am getting:

Code: Select all

Guru Meditation Error: Core  1 panic'ed (Cache disabled but cached memory region accessed). 

Core  1 register dump:
PC      : 0x400e692c  PS      : 0x00060035  A0      : 0x40086abc  A1      : 0x3ffbf22c  
A2      : 0x00000078  A3      : 0x3ffbdcc0  A4      : 0x00000020  A5      : 0x3ffbdcbc  
A6      : 0x3ffbc2f8  A7      : 0x00000001  A8      : 0x8008165c  A9      : 0x00000078  
A10     : 0x3ffbdcbc  A11     : 0x3ffbc45c  A12     : 0x3ffbf244  A13     : 0x3ffbdcbc  
A14     : 0x3ffc4608  A15     : 0x84022044  SAR     : 0x00000017  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x400865a9  LEND    : 0x400865b1  LCOUNT  : 0x00000027  


Backtrace:0x400e6929:0x3ffbf22c |<-CORRUPTED
  #0  0x400e6929:0x3ffbf22c in uart_ll_write_txfifo at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/hal/esp32/include/hal/uart_ll.h:235
      (inlined by) uart_hal_write_txfifo at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/hal/uart_hal_iram.c:40




ELF file SHA256: 0000000000000000

Rebooting...
And this is some sample code that will cause the issues

Code: Select all

#include <Arduino.h>
#include <esp_dmx.h>
#include "FS.h"
#include <LittleFS.h>

int transmitPin = 5;
int receivePin = 19;
int enablePin = 18;

dmx_port_t dmxPort = 1;

byte data[DMX_MAX_PACKET_SIZE];

QueueHandle_t queue;

unsigned int timer = 0;
bool dmxIsConnected = false;

void setup() {
  Serial.begin(115200);

  /*
  * Open the file system
  */
  if(!LittleFS.begin(true)) {
   Serial.println("Formatted");
   LittleFS.mkdir("/dmx");
  }


  dmx_config_t dmxConfig = DMX_DEFAULT_CONFIG;
  dmx_param_config(dmxPort, &dmxConfig);
  dmx_set_pin(dmxPort, transmitPin, receivePin, enablePin);

  int queueSize = 1;
  int interruptPriority = 1;
  dmx_driver_install(dmxPort, DMX_MAX_PACKET_SIZE, queueSize, &queue,
                     interruptPriority);
}

void loop() {
  dmx_event_t packet;

  if (xQueueReceive(queue, &packet, DMX_PACKET_TIMEOUT_TICK)) {

    if (packet.status == DMX_OK) {

      if (!dmxIsConnected) {
        Serial.println("DMX connected!");
        dmxIsConnected = true;
      }

      dmx_read_packet(dmxPort, data, packet.size);
      timer += packet.duration;

      if (timer >= 1000000) {
        Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n",
                      data[0], data[1]);
        timer -= 1000000;
      }

    } else {
      Serial.println("DMX error!");
    }

   /*
    * Save the DMX Packet to a file
    */
   File file = LittleFS.open("/dmx/00.dmx", "w");

   for(uint16_t x=0; x<DMX_MAX_PACKET_SIZE; x++) {
    file.write(data[x]);
   }
   
   file.close();


  } else if (dmxIsConnected) {
    Serial.println("DMX timed out! Uninstalling DMX driver...");
    dmx_driver_delete(dmxPort);

    while (true) yield();
  }
}
I have raised this with the esp_dmx author here https://github.com/someweisguy/esp_dmx/issues/25 and one suggestion is that because I'm using pins that default for use with SPI that might be causing an issue, as he has used different pins that do not cause an issue with the same code. I have avoided GPIO for the internal flash though (6 - 11) so was not expecting this to be an issue.

I have an SPI ethernet (W5500) connected using the HSPI SPI bus on GPIO 15,14,13,12 and using 4 for interrupt and 2 for reset.

I have I2C running on 25 & 32

Then 2 UARTS for DMX (one to send and one to receive) send on TX = 21, RX = 23, EN = 22. Receive on TX = 5, RX = 19, EN = 18

Then 3 LED outputs on 27, 26, 33

But the sample code that causes the issue only enables and uses the one UART (5,19,18). I have also tried using the second set of pins (21,23,22) that I have connected on my PCB with the same results.

I can't easily swap the pins around as this is a custom PCB I have fabricated. Its my first real ESP32 project, and from what I had read the GPOI Matrix was going to make this very simple to do the PCB layout as I could move everything around very easily to keep for simple routing.

I'm hoping we can find a software solution to this rather than having to change the PCB design.

Does anybody have any thought on this?

Should this be posted in the ESP-IDF forum instead?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Cache disabled but cached memory region accessed with UART and ESP_INTR_FLAG_IRAM

Postby ESP_Sprite » Thu Aug 18, 2022 1:33 am

I doubt the GPIO pins have anything to do with it; they check out. I think the library you're using isn't entirely IRAM-safe (as in: it has an interrupt that is marked as ESP_INTR_FLAG_IRAM but calls functions or accesses data that is in flash); the developer of that library may not have noticed as he doesn't normally write to flash during library use.

Who is online

Users browsing this forum: No registered users and 55 guests