From 219ef5e407742bedf1326929a5cd70a86516a65b Mon Sep 17 00:00:00 2001 From: KurtE Date: Wed, 6 Apr 2022 15:58:27 -0700 Subject: [PATCH 1/3] disable on mimxrt10xx (Teensy40 41) Serial port Hooks As mentioned in issue #6241 the commit to setup port hooks is now causing all input/output that are to go to the Mu window to also go to the LpUart that is defined the port serial.c and in this case it goes to lpuart4, which on Teensy 4, 4.1 is used on Arduino Serial2. With this new code this port no longer works properly. This is one way to solve it, in that there is a #if defined() that if not set, all of the code in this file is ignored and the higher level supervisor stub versions of these functions will be used, which don't interfere with Serial2 and my test sketch works again. Note: the PR for Switch to Port Serial Hooks, also changed code in other ports. I have not tried to see how. There are other more global fixes for this, in which maybe a higer level #if that disables the code within the top level supervisor. Or could be software controlled Again this may not be the final solution, but at least it gets Serial2 up and running agin. --- ports/mimxrt10xx/supervisor/serial.c | 58 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/ports/mimxrt10xx/supervisor/serial.c b/ports/mimxrt10xx/supervisor/serial.c index b3c37b077d..9d4971e089 100644 --- a/ports/mimxrt10xx/supervisor/serial.c +++ b/ports/mimxrt10xx/supervisor/serial.c @@ -26,65 +26,65 @@ * THE SOFTWARE. */ +#include "supervisor/serial.h" #include "py/mphal.h" #include -#include "supervisor/serial.h" #include "fsl_clock.h" #include "fsl_lpuart.h" // TODO: Switch this to using DEBUG_UART. - +#if defined(USE_DEBUG_PORT_CODE) // static LPUART_Type *uart_instance = LPUART1; // evk static LPUART_Type *uart_instance = LPUART4; // feather 1011 // static LPUART_Type *uart_instance = LPUART2; // feather 1062 static uint32_t UartSrcFreq(void) { - uint32_t freq; + uint32_t freq; - /* To make it simple, we assume default PLL and divider settings, and the only variable - from application is use PLL3 source or OSC source */ - /* PLL3 div6 80M */ - if (CLOCK_GetMux(kCLOCK_UartMux) == 0) { - freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); - } else { - freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); - } + /* To make it simple, we assume default PLL and divider settings, and the only + variable from application is use PLL3 source or OSC source */ + /* PLL3 div6 80M */ + if (CLOCK_GetMux(kCLOCK_UartMux) == 0) { + freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / + (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } else { + freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } - return freq; + return freq; } void port_serial_init(void) { - lpuart_config_t config; + lpuart_config_t config; - LPUART_GetDefaultConfig(&config); - config.baudRate_Bps = 115200; - config.enableTx = true; - config.enableRx = true; + LPUART_GetDefaultConfig(&config); + config.baudRate_Bps = 115200; + config.enableTx = true; + config.enableRx = true; - LPUART_Init(uart_instance, &config, UartSrcFreq()); + LPUART_Init(uart_instance, &config, UartSrcFreq()); } -bool port_serial_connected(void) { - return true; -} +bool port_serial_connected(void) { return true; } char port_serial_read(void) { - uint8_t data; + uint8_t data; - LPUART_ReadBlocking(uart_instance, &data, sizeof(data)); + LPUART_ReadBlocking(uart_instance, &data, sizeof(data)); - return data; + return data; } bool port_serial_bytes_available(void) { - return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag; + return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag; } void port_serial_write_substring(const char *text, uint32_t len) { - if (len == 0) { - return; - } + if (len == 0) { + return; + } - LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len); + LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len); } +#endif // USE_DEBUG_PORT_CODE From 7ff0036a2674461784f1ce63d76b529744ebe1a6 Mon Sep 17 00:00:00 2001 From: KurtE Date: Fri, 8 Apr 2022 15:59:27 -0700 Subject: [PATCH 2/3] Fix the pre-check stuff --- ports/mimxrt10xx/supervisor/serial.c | 55 +++++++++++++++------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/ports/mimxrt10xx/supervisor/serial.c b/ports/mimxrt10xx/supervisor/serial.c index 9d4971e089..4223ab4f5b 100644 --- a/ports/mimxrt10xx/supervisor/serial.c +++ b/ports/mimxrt10xx/supervisor/serial.c @@ -34,57 +34,60 @@ #include "fsl_lpuart.h" // TODO: Switch this to using DEBUG_UART. +// Need official way to turn off the port serial code when it is not needed #if defined(USE_DEBUG_PORT_CODE) // static LPUART_Type *uart_instance = LPUART1; // evk static LPUART_Type *uart_instance = LPUART4; // feather 1011 // static LPUART_Type *uart_instance = LPUART2; // feather 1062 static uint32_t UartSrcFreq(void) { - uint32_t freq; + uint32_t freq; - /* To make it simple, we assume default PLL and divider settings, and the only - variable from application is use PLL3 source or OSC source */ - /* PLL3 div6 80M */ - if (CLOCK_GetMux(kCLOCK_UartMux) == 0) { - freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / - (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); - } else { - freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); - } + /* To make it simple, we assume default PLL and divider settings, and the only + variable from application is use PLL3 source or OSC source */ + /* PLL3 div6 80M */ + if (CLOCK_GetMux(kCLOCK_UartMux) == 0) { + freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / + (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } else { + freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } - return freq; + return freq; } void port_serial_init(void) { - lpuart_config_t config; + lpuart_config_t config; - LPUART_GetDefaultConfig(&config); - config.baudRate_Bps = 115200; - config.enableTx = true; - config.enableRx = true; + LPUART_GetDefaultConfig(&config); + config.baudRate_Bps = 115200; + config.enableTx = true; + config.enableRx = true; - LPUART_Init(uart_instance, &config, UartSrcFreq()); + LPUART_Init(uart_instance, &config, UartSrcFreq()); } -bool port_serial_connected(void) { return true; } +bool port_serial_connected(void) { + return true; +} char port_serial_read(void) { - uint8_t data; + uint8_t data; - LPUART_ReadBlocking(uart_instance, &data, sizeof(data)); + LPUART_ReadBlocking(uart_instance, &data, sizeof(data)); - return data; + return data; } bool port_serial_bytes_available(void) { - return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag; + return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag; } void port_serial_write_substring(const char *text, uint32_t len) { - if (len == 0) { - return; - } + if (len == 0) { + return; + } - LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len); + LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len); } #endif // USE_DEBUG_PORT_CODE From 49769cfea408aa212d7310acefa8c91f1a2eaa92 Mon Sep 17 00:00:00 2001 From: KurtE Date: Tue, 19 Apr 2022 14:02:16 -0700 Subject: [PATCH 3/3] Convert to use debug rx/tx pins to trigger adding this code As per review request --- ports/mimxrt10xx/supervisor/serial.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/mimxrt10xx/supervisor/serial.c b/ports/mimxrt10xx/supervisor/serial.c index 4223ab4f5b..63f468beaf 100644 --- a/ports/mimxrt10xx/supervisor/serial.c +++ b/ports/mimxrt10xx/supervisor/serial.c @@ -34,12 +34,11 @@ #include "fsl_lpuart.h" // TODO: Switch this to using DEBUG_UART. -// Need official way to turn off the port serial code when it is not needed -#if defined(USE_DEBUG_PORT_CODE) +// If the board defined a debug uart tx or rx pin then we enable this code +#if defined(CIRCUITPY_DEBUG_UART_TX) || defined(CIRCUITPY_DEBUG_UART_RX) // static LPUART_Type *uart_instance = LPUART1; // evk static LPUART_Type *uart_instance = LPUART4; // feather 1011 // static LPUART_Type *uart_instance = LPUART2; // feather 1062 - static uint32_t UartSrcFreq(void) { uint32_t freq;