Crash when using rmt and reading flash at the same time

cruvus
Posts: 59
Joined: Fri Jul 08, 2022 5:08 pm
Location: Planet Earth

Crash when using rmt and reading flash at the same time

Postby cruvus » Sat Jul 23, 2022 9:03 pm

ESP32 rev0 on TTGO, using IDF 4.4.1. Compiled with -Os parameter (important).

Code: Select all

#include <string.h>
#include "driver/rmt.h"
#include "nvs_flash.h"

void app_main(void) {
	rmt_config_t tx = {
		.channel = RMT_CHANNEL_0,
		.gpio_num = 20,
		.mem_block_num = 1,
		.clk_div = 40,
		.tx_config.idle_output_en = true,
		.rmt_mode = RMT_MODE_TX,
	};
	rmt_config(&tx);
	rmt_set_source_clk(tx.channel, RMT_BASECLK_APB);
	rmt_driver_install(tx.channel, 0, ESP_INTR_FLAG_IRAM);

	rmt_item32_t items[512] = {};
	for (int i = 0; i < 512; i++) {
		items[i].duration0 = 1;
		items[i].level0 = 0;
		items[i].duration1 = 1;
		items[i].level1 = 1;
	}
	rmt_write_items(RMT_CHANNEL_0, items, 512, false);

	while (true) {
		uint32_t crashme;
		esp_flash_read(NULL, (void *)&crashme, 0, sizeof(crashme));
	}
}
Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed).

Core 0 register dump:
PC : 0x400e41b0 PS : 0x00060034 A0 : 0x40082578 A1 : 0x3ffb0b60
0x400e41b0: rmt_ll_get_tx_err_interrupt_status at C:/Users/***/esp/esp-idf/components/hal/esp32/include/hal/rmt_ll.h:307

0x40082578: _xt_lowint1 at C:/Users/***/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1111

A2 : 0x3ffb1298 A3 : 0x00000000 A4 : 0x00000080 A5 : 0x00000001
A6 : 0x00000001 A7 : 0x00000020 A8 : 0x80082d2a A9 : 0x00000020
A10 : 0x3ff56000 A11 : 0x3ffb55f0 A12 : 0xffffffff A13 : 0x00000000
A14 : 0x3ffb12a4 A15 : 0x00000000 SAR : 0x00000008 EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x40082079 LEND : 0x40082081 LCOUNT : 0x00000027
0x40082079: esp_timer_impl_get_counter_reg at C:/Users/***/esp/esp-idf/components/esp_timer/src/esp_timer_impl_lac.c:118 (discriminator 2)

0x40082081: esp_timer_impl_get_counter_reg at C:/Users/***/esp/esp-idf/components/esp_timer/src/esp_timer_impl_lac.c:128 (discriminator 1)



Backtrace:0x400e41ad:0x3ffb0b600x40082575:0x3ffb0ba0 0x4008a059:0x3ffb4eb0 0x400840ca:0x3ffb4f30 0x400d4245:0x3ffb4f70 0x400e4874:0x3ffb57c0
0x400e41ad: esp_efuse_utility_get_number_of_items at C:/Users/***/esp/esp-idf/components/efuse/src/esp_efuse_utility.c:241

0x40082575: _xt_lowint1 at C:/Users/***/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1111

0x4008a059: spi_flash_chip_generic_detect_size at C:/Users/***/esp/esp-idf/components/spi_flash/spi_flash_chip_generic.c:119

0x400840ca: esp_flash_read at C:/Users/***/esp/esp-idf/components/spi_flash/esp_flash_api.c:832

0x400d4245: app_main at C:\Users\***\esp\rmt_inline_crash\build/../main/main.c:29 (discriminator 1)

0x400e4874: main_task at C:/Users/***/esp/esp-idf/components/freertos/port/port_common.c:129
The problem is in
https://github.com/espressif/esp-idf/bl ... l/rmt_ll.h
The functions there are not really "inline" when compiled with -Os. Thus they end up in flash unreachable during flash operations. Solution: Use __attribute__((always_inline)) (I think you defined it FORCE_INLINE_ATTR).
I've seen in uart_ll.h the low level functions are inlined properly. But e.g. in i2c_ll.h they are not. I haven't tried anything with I2C or looked into all the other ll files yet, but maybe other peripherals suffer from a similar bug. Whoever fixes rmt_ll.h should check the other components, too.
ESP32 / ESP-IDF 5.1.4

cruvus
Posts: 59
Joined: Fri Jul 08, 2022 5:08 pm
Location: Planet Earth

Re: Crash when using rmt and reading flash at the same time

Postby cruvus » Mon Jul 25, 2022 6:09 pm

ESP32 / ESP-IDF 5.1.4

Who is online

Users browsing this forum: No registered users and 99 guests