From 75ecc46739787ba20355f44123868e829c02b779 Mon Sep 17 00:00:00 2001 From: tanek liang Date: Sat, 9 Dec 2017 11:12:46 +0800 Subject: [PATCH 1/2] [bsp] fixed uart overrun bugs --- bsp/imxrt1052-evk/drivers/usart.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bsp/imxrt1052-evk/drivers/usart.c b/bsp/imxrt1052-evk/drivers/usart.c index 0635eaee5c..934a1ee8c7 100644 --- a/bsp/imxrt1052-evk/drivers/usart.c +++ b/bsp/imxrt1052-evk/drivers/usart.c @@ -320,18 +320,32 @@ static int imxrt_getc(struct rt_serial_device *serial) */ static void uart_isr(struct rt_serial_device *serial) { - struct imxrt_uart *uart = (struct imxrt_uart *) serial->parent.user_data; + struct imxrt_uart *uart; + LPUART_Type *base; + RT_ASSERT(serial != RT_NULL); + + uart = (struct imxrt_uart *) serial->parent.user_data; RT_ASSERT(uart != RT_NULL); + + base = uart->uart_base; + RT_ASSERT(base != RT_NULL); /* enter interrupt */ rt_interrupt_enter(); /* UART in mode Receiver -------------------------------------------------*/ - if (LPUART_GetStatusFlags(uart->uart_base) & kLPUART_RxDataRegFullFlag) + if (LPUART_GetStatusFlags(base) & kLPUART_RxDataRegFullFlag) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); } + + /* If RX overrun. */ + if (LPUART_STAT_OR_MASK & base->STAT) + { + /* Clear overrun flag, otherwise the RX does not work. */ + base->STAT = ((base->STAT & 0x3FE00000U) | LPUART_STAT_OR_MASK); + } /* leave interrupt */ rt_interrupt_leave(); From 3b44eac542c5418537c6fcf0db7e3818351574bd Mon Sep 17 00:00:00 2001 From: tanek liang Date: Sat, 9 Dec 2017 11:24:16 +0800 Subject: [PATCH 2/2] [bsp] replace magic number as link script symbol --- .../Libraries/arm/MIMXRT1052xxxxx_flexspi_nor.scf | 5 +++++ .../Libraries/gcc/MIMXRT1052xxxxx_flexspi_nor.ld | 10 +++++++--- .../Libraries/iar/MIMXRT1052xxxxx_flexspi_nor.icf | 1 + bsp/imxrt1052-evk/drivers/board.h | 13 ++++++++----- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/bsp/imxrt1052-evk/Libraries/arm/MIMXRT1052xxxxx_flexspi_nor.scf b/bsp/imxrt1052-evk/Libraries/arm/MIMXRT1052xxxxx_flexspi_nor.scf index 04885943a3..eedd3bd998 100644 --- a/bsp/imxrt1052-evk/Libraries/arm/MIMXRT1052xxxxx_flexspi_nor.scf +++ b/bsp/imxrt1052-evk/Libraries/arm/MIMXRT1052xxxxx_flexspi_nor.scf @@ -67,6 +67,9 @@ #define Heap_Size 0x0400 #endif +#define RTT_HEAP_SIZE \ + (m_data_size - ImageLength(RW_m_data) - ImageLength(ARM_LIB_HEAP) - ImageLength(ARM_LIB_STACK)) + LR_m_text m_text_start m_text_size { ; load region size_region ER_m_text m_text_start m_text_size { ; load address = execution address * (RESET,+FIRST) @@ -81,6 +84,8 @@ LR_m_text m_text_start m_text_size { ; load region size_region } ARM_LIB_STACK +0 EMPTY Stack_Size { ; Stack region growing down } + RTT_HEAP +0 EMPTY RTT_HEAP_SIZE { + } RW_m_ncache m_ncache_start m_ncache_size { ; ncache RW data * (NonCacheable.init) diff --git a/bsp/imxrt1052-evk/Libraries/gcc/MIMXRT1052xxxxx_flexspi_nor.ld b/bsp/imxrt1052-evk/Libraries/gcc/MIMXRT1052xxxxx_flexspi_nor.ld index 810d52673f..993d8589a9 100644 --- a/bsp/imxrt1052-evk/Libraries/gcc/MIMXRT1052xxxxx_flexspi_nor.ld +++ b/bsp/imxrt1052-evk/Libraries/gcc/MIMXRT1052xxxxx_flexspi_nor.ld @@ -253,12 +253,16 @@ SECTIONS stack_start = .; . += STACK_SIZE; stack_end = .; + __StackTop = .; + } > m_dtcm + + .RTT_HEAP : + { heap_start = .; + . = ALIGN(8); } > m_dtcm - /* Initializes stack on the end of block */ - __StackTop = stack_end; - PROVIDE(__stack = __StackTop); + PROVIDE(heap_end = ORIGIN(m_dtcm) + LENGTH(m_dtcm)); .ARM.attributes 0 : { *(.ARM.attributes) } diff --git a/bsp/imxrt1052-evk/Libraries/iar/MIMXRT1052xxxxx_flexspi_nor.icf b/bsp/imxrt1052-evk/Libraries/iar/MIMXRT1052xxxxx_flexspi_nor.icf index 6a285752ab..04bea11a34 100644 --- a/bsp/imxrt1052-evk/Libraries/iar/MIMXRT1052xxxxx_flexspi_nor.icf +++ b/bsp/imxrt1052-evk/Libraries/iar/MIMXRT1052xxxxx_flexspi_nor.icf @@ -81,6 +81,7 @@ if (isdefinedsymbol(__heap_size__)) { define exported symbol __VECTOR_TABLE = m_interrupts_start; define exported symbol __VECTOR_RAM = m_interrupts_start; define exported symbol __RAM_VECTOR_TABLE_SIZE = 0x0; +define exported symbol __RTT_HEAP_END = m_dtcm_end; define memory mem with size = 4G; define region TEXT_region = mem:[from m_interrupts_start to m_interrupts_end] diff --git a/bsp/imxrt1052-evk/drivers/board.h b/bsp/imxrt1052-evk/drivers/board.h index 43b2580552..80a61f1a3a 100644 --- a/bsp/imxrt1052-evk/drivers/board.h +++ b/bsp/imxrt1052-evk/drivers/board.h @@ -21,19 +21,22 @@ #include #ifdef __CC_ARM -extern int Image$$ARM_LIB_STACK$$ZI$$Limit; -#define HEAP_BEGIN (&Image$$ARM_LIB_STACK$$ZI$$Limit) -#define HEAP_END (0x2001FFFFu) +extern int Image$$RTT_HEAP$$ZI$$Base; +extern int Image$$RTT_HEAP$$ZI$$Limit; +#define HEAP_BEGIN (&Image$$RTT_HEAP$$ZI$$Base) +#define HEAP_END (&Image$$RTT_HEAP$$ZI$$Limit) #elif __ICCARM__ #pragma section="HEAP" #define HEAP_BEGIN (__segment_end("HEAP")) -#define HEAP_END (0x2001FFFFu) +extern void __RTT_HEAP_END; +#define HEAP_END (&__RTT_HEAP_END) #else extern int heap_start; +extern int heap_end; #define HEAP_BEGIN (&heap_start) -#define HEAP_END (0x2001FFFFu) +#define HEAP_END (&heap_end) #endif #define HEAP_SIZE ((uint32_t)HEAP_END - (uint32_t)HEAP_BEGIN)