Skip to content

Commit 7ff0036

Browse files
committed
Fix the pre-check stuff
1 parent 219ef5e commit 7ff0036

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

ports/mimxrt10xx/supervisor/serial.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,57 +34,60 @@
3434
#include "fsl_lpuart.h"
3535

3636
// TODO: Switch this to using DEBUG_UART.
37+
// Need official way to turn off the port serial code when it is not needed
3738
#if defined(USE_DEBUG_PORT_CODE)
3839
// static LPUART_Type *uart_instance = LPUART1; // evk
3940
static LPUART_Type *uart_instance = LPUART4; // feather 1011
4041
// static LPUART_Type *uart_instance = LPUART2; // feather 1062
4142

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

5859
void port_serial_init(void) {
59-
lpuart_config_t config;
60+
lpuart_config_t config;
6061

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

66-
LPUART_Init(uart_instance, &config, UartSrcFreq());
67+
LPUART_Init(uart_instance, &config, UartSrcFreq());
6768
}
6869

69-
bool port_serial_connected(void) { return true; }
70+
bool port_serial_connected(void) {
71+
return true;
72+
}
7073

7174
char port_serial_read(void) {
72-
uint8_t data;
75+
uint8_t data;
7376

74-
LPUART_ReadBlocking(uart_instance, &data, sizeof(data));
77+
LPUART_ReadBlocking(uart_instance, &data, sizeof(data));
7578

76-
return data;
79+
return data;
7780
}
7881

7982
bool port_serial_bytes_available(void) {
80-
return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag;
83+
return LPUART_GetStatusFlags(uart_instance) & kLPUART_RxDataRegFullFlag;
8184
}
8285

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

88-
LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len);
91+
LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len);
8992
}
9093
#endif // USE_DEBUG_PORT_CODE

0 commit comments

Comments
 (0)