]> granicus.if.org Git - esp-idf/commitdiff
UART driver: Fix crash in ISR due to "UART" static array moved to flash
authorAngus Gratton <angus@espressif.com>
Tue, 22 Nov 2016 23:47:40 +0000 (10:47 +1100)
committerAngus Gratton <angus@espressif.com>
Tue, 22 Nov 2016 23:58:03 +0000 (10:58 +1100)
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.

components/driver/uart.c

index 02610e7b49bbbe4d946163a52e73f0febb152187..59b4904dcd7ece413a1ecb4dbb6815afd81f288f 100644 (file)
@@ -84,7 +84,8 @@ typedef struct {
 \r
 \r
 static uart_obj_t *p_uart_obj[UART_NUM_MAX] = {0};\r
-static uart_dev_t* UART[UART_NUM_MAX] = {&UART0, &UART1, &UART2};\r
+/* DRAM_ATTR is required to avoid UART array placed in flash, due to accessed from ISR */\r
+static DRAM_ATTR uart_dev_t* const UART[UART_NUM_MAX] = {&UART0, &UART1, &UART2};\r
 static portMUX_TYPE uart_spinlock[UART_NUM_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED};\r
 \r
 esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit)\r