Skip to content

Commit 219ef5e

Browse files
committed
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.
1 parent b0bb5ff commit 219ef5e

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

ports/mimxrt10xx/supervisor/serial.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,65 +26,65 @@
2626
* THE SOFTWARE.
2727
*/
2828

29+
#include "supervisor/serial.h"
2930
#include "py/mphal.h"
3031
#include <string.h>
31-
#include "supervisor/serial.h"
3232

3333
#include "fsl_clock.h"
3434
#include "fsl_lpuart.h"
3535

3636
// TODO: Switch this to using DEBUG_UART.
37-
37+
#if defined(USE_DEBUG_PORT_CODE)
3838
// static LPUART_Type *uart_instance = LPUART1; // evk
3939
static LPUART_Type *uart_instance = LPUART4; // feather 1011
4040
// static LPUART_Type *uart_instance = LPUART2; // feather 1062
4141

4242
static uint32_t UartSrcFreq(void) {
43-
uint32_t freq;
44-
45-
/* To make it simple, we assume default PLL and divider settings, and the only variable
46-
from application is use PLL3 source or OSC source */
47-
/* PLL3 div6 80M */
48-
if (CLOCK_GetMux(kCLOCK_UartMux) == 0) {
49-
freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
50-
} else {
51-
freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
52-
}
53-
54-
return freq;
43+
uint32_t freq;
44+
45+
/* To make it simple, we assume default PLL and divider settings, and the only
46+
variable from application is use PLL3 source or OSC source */
47+
/* PLL3 div6 80M */
48+
if (CLOCK_GetMux(kCLOCK_UartMux) == 0) {
49+
freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) /
50+
(CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
51+
} else {
52+
freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
53+
}
54+
55+
return freq;
5556
}
5657

5758
void port_serial_init(void) {
58-
lpuart_config_t config;
59+
lpuart_config_t config;
5960

60-
LPUART_GetDefaultConfig(&config);
61-
config.baudRate_Bps = 115200;
62-
config.enableTx = true;
63-
config.enableRx = true;
61+
LPUART_GetDefaultConfig(&config);
62+
config.baudRate_Bps = 115200;
63+
config.enableTx = true;
64+
config.enableRx = true;
6465

65-
LPUART_Init(uart_instance, &config, UartSrcFreq());
66+
LPUART_Init(uart_instance, &config, UartSrcFreq());
6667
}
6768

68-
bool port_serial_connected(void) {
69-
return true;
70-
}
69+
bool port_serial_connected(void) { return true; }
7170

7271
char port_serial_read(void) {
73-
uint8_t data;
72+
uint8_t data;
7473

75-
LPUART_ReadBlocking(uart_instance, &data, sizeof(data));
74+
LPUART_ReadBlocking(uart_instance, &data, sizeof(data));
7675

77-
return data;
76+
return data;
7877
}
7978

8079
bool port_serial_bytes_available(void) {
81-
return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag;
80+
return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag;
8281
}
8382

8483
void port_serial_write_substring(const char *text, uint32_t len) {
85-
if (len == 0) {
86-
return;
87-
}
84+
if (len == 0) {
85+
return;
86+
}
8887

89-
LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len);
88+
LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len);
9089
}
90+
#endif // USE_DEBUG_PORT_CODE

0 commit comments

Comments
 (0)