From: Angus Gratton Date: Tue, 22 Nov 2016 23:47:40 +0000 (+1100) Subject: UART driver: Fix crash in ISR due to "UART" static array moved to flash X-Git-Tag: v1.0~27^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d05f41a70583a4631d6a7520a8772b216df05f6;p=esp-idf UART driver: Fix crash in ISR due to "UART" static array moved to flash Ref: http://esp32.com/viewtopic.php?f=13&t=546&sid=76ff371ae2b259441a2cf355e96d74b9#p2275 This is a really subtle bug, gcc noticed the UART array elements are read-only so implicitly moved the elements to .rodata as if it was const. However this array is accessed from the UART ISR, so has to be in IRAM or DRAM. --- diff --git a/components/driver/uart.c b/components/driver/uart.c index 02610e7b49..59b4904dcd 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -84,7 +84,8 @@ typedef struct { static uart_obj_t *p_uart_obj[UART_NUM_MAX] = {0}; -static uart_dev_t* UART[UART_NUM_MAX] = {&UART0, &UART1, &UART2}; +/* DRAM_ATTR is required to avoid UART array placed in flash, due to accessed from ISR */ +static DRAM_ATTR uart_dev_t* const UART[UART_NUM_MAX] = {&UART0, &UART1, &UART2}; static portMUX_TYPE uart_spinlock[UART_NUM_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED}; esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit)