stm32/uart: Add UART RX/CTS pin pull config options.
Some checks are pending
JavaScript code lint and formatting with Biome / eslint (push) Waiting to run
Check code formatting / code-formatting (push) Waiting to run
Check code size / build (push) Waiting to run
Check spelling with codespell / codespell (push) Waiting to run
Check commit message formatting / build (push) Waiting to run
Build docs / build (push) Waiting to run
Check examples / embedding (push) Waiting to run
Package mpremote / build (push) Waiting to run
.mpy file format and tools / test (push) Waiting to run
Build ports metadata / build (push) Waiting to run
cc3200 port / build (push) Waiting to run
esp32 port / build_idf (esp32_build_cmod_spiram_s2) (push) Waiting to run
esp32 port / build_idf (esp32_build_s3_c3) (push) Waiting to run
esp8266 port / build (push) Waiting to run
mimxrt port / build (push) Waiting to run
nrf port / build (push) Waiting to run
powerpc port / build (push) Waiting to run
qemu port / build_and_test_arm (push) Waiting to run
qemu port / build_and_test_rv32 (push) Waiting to run
renesas-ra port / build_renesas_ra_board (push) Waiting to run
rp2 port / build (push) Waiting to run
samd port / build (push) Waiting to run
stm32 port / build_stm32 (stm32_misc_build) (push) Waiting to run
stm32 port / build_stm32 (stm32_nucleo_build) (push) Waiting to run
stm32 port / build_stm32 (stm32_pyb_build) (push) Waiting to run
unix port / minimal (push) Waiting to run
unix port / reproducible (push) Waiting to run
unix port / standard (push) Waiting to run
unix port / standard_v2 (push) Waiting to run
unix port / coverage (push) Waiting to run
unix port / coverage_32bit (push) Waiting to run
unix port / nanbox (push) Waiting to run
unix port / float (push) Waiting to run
unix port / stackless_clang (push) Waiting to run
unix port / float_clang (push) Waiting to run
unix port / settrace (push) Waiting to run
unix port / settrace_stackless (push) Waiting to run
unix port / macos (push) Waiting to run
unix port / qemu_mips (push) Waiting to run
unix port / qemu_arm (push) Waiting to run
unix port / qemu_riscv64 (push) Waiting to run
webassembly port / build (push) Waiting to run
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-mingw (i686, mingw32, dev) (push) Waiting to run
windows port / build-mingw (i686, mingw32, standard) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, dev) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, standard) (push) Waiting to run
windows port / cross-build-on-linux (push) Waiting to run
zephyr port / build (push) Waiting to run
Python code lint and formatting with ruff / ruff (push) Waiting to run

The UART driver enables a pull-up on RX/CTS pins by default.  This can
cause UART to fail to receive in certain situations, eg with RS485
transceivers.

This commit adds compile-time configuration options to set the pull mode on
the RX and CTS pins of each UART.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader
2024-09-19 09:37:50 +02:00
committed by Damien George
parent 3e085c3aa6
commit eec5eb4260

View File

@@ -252,6 +252,9 @@ bool uart_init(machine_uart_obj_t *uart_obj,
const machine_pin_obj_t *pins[4] = {0};
// Default pull is pull-up on RX and CTS (the input pins).
uint32_t pins_pull[4] = { GPIO_NOPULL, GPIO_PULLUP, GPIO_NOPULL, GPIO_PULLUP };
switch (uart_obj->uart_id) {
#if defined(MICROPY_HW_UART1_TX) && defined(MICROPY_HW_UART1_RX)
case PYB_UART_1:
@@ -270,6 +273,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART1_CTS;
}
#endif
#if defined(MICROPY_HW_UART1_RX_PULL)
pins_pull[1] = MICROPY_HW_UART1_RX_PULL;
#endif
#if defined(MICROPY_HW_UART1_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART1_CTS_PULL;
#endif
__HAL_RCC_USART1_CLK_ENABLE();
break;
#endif
@@ -295,6 +304,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART2_CTS;
}
#endif
#if defined(MICROPY_HW_UART2_RX_PULL)
pins_pull[1] = MICROPY_HW_UART2_RX_PULL;
#endif
#if defined(MICROPY_HW_UART2_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART2_CTS_PULL;
#endif
__HAL_RCC_USART2_CLK_ENABLE();
break;
#endif
@@ -322,6 +337,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART3_CTS;
}
#endif
#if defined(MICROPY_HW_UART3_RX_PULL)
pins_pull[1] = MICROPY_HW_UART3_RX_PULL;
#endif
#if defined(MICROPY_HW_UART3_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART3_CTS_PULL;
#endif
__HAL_RCC_USART3_CLK_ENABLE();
break;
#endif
@@ -358,6 +379,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART4_CTS;
}
#endif
#if defined(MICROPY_HW_UART4_RX_PULL)
pins_pull[1] = MICROPY_HW_UART4_RX_PULL;
#endif
#if defined(MICROPY_HW_UART4_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART4_CTS_PULL;
#endif
break;
#endif
@@ -393,6 +420,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART5_CTS;
}
#endif
#if defined(MICROPY_HW_UART5_RX_PULL)
pins_pull[1] = MICROPY_HW_UART5_RX_PULL;
#endif
#if defined(MICROPY_HW_UART5_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART5_CTS_PULL;
#endif
break;
#endif
@@ -419,6 +452,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART6_CTS;
}
#endif
#if defined(MICROPY_HW_UART6_RX_PULL)
pins_pull[1] = MICROPY_HW_UART6_RX_PULL;
#endif
#if defined(MICROPY_HW_UART6_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART6_CTS_PULL;
#endif
__HAL_RCC_USART6_CLK_ENABLE();
break;
#endif
@@ -447,6 +486,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART7_CTS;
}
#endif
#if defined(MICROPY_HW_UART7_RX_PULL)
pins_pull[1] = MICROPY_HW_UART7_RX_PULL;
#endif
#if defined(MICROPY_HW_UART7_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART7_CTS_PULL;
#endif
break;
#endif
@@ -474,6 +519,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_UART8_CTS;
}
#endif
#if defined(MICROPY_HW_UART8_RX_PULL)
pins_pull[1] = MICROPY_HW_UART8_RX_PULL;
#endif
#if defined(MICROPY_HW_UART8_CTS_PULL)
pins_pull[3] = MICROPY_HW_UART8_CTS_PULL;
#endif
break;
#endif
@@ -485,6 +536,9 @@ bool uart_init(machine_uart_obj_t *uart_obj,
__HAL_RCC_UART9_CLK_ENABLE();
pins[0] = MICROPY_HW_UART9_TX;
pins[1] = MICROPY_HW_UART9_RX;
#if defined(MICROPY_HW_UART9_RX_PULL)
pins_pull[1] = MICROPY_HW_UART9_RX_PULL;
#endif
break;
#endif
@@ -502,6 +556,9 @@ bool uart_init(machine_uart_obj_t *uart_obj,
#endif
pins[0] = MICROPY_HW_UART10_TX;
pins[1] = MICROPY_HW_UART10_RX;
#if defined(MICROPY_HW_UART10_RX_PULL)
pins_pull[1] = MICROPY_HW_UART10_RX_PULL;
#endif
break;
#endif
@@ -527,6 +584,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_LPUART1_CTS;
}
#endif
#if defined(MICROPY_HW_LPUART1_RX_PULL)
pins_pull[1] = MICROPY_HW_LPUART1_RX_PULL;
#endif
#if defined(MICROPY_HW_LPUART1_CTS_PULL)
pins_pull[3] = MICROPY_HW_LPUART1_CTS_PULL;
#endif
__HAL_RCC_LPUART1_CLK_ENABLE();
break;
#endif
@@ -551,6 +614,12 @@ bool uart_init(machine_uart_obj_t *uart_obj,
pins[3] = MICROPY_HW_LPUART2_CTS;
}
#endif
#if defined(MICROPY_HW_LPUART2_RX_PULL)
pins_pull[1] = MICROPY_HW_LPUART2_RX_PULL;
#endif
#if defined(MICROPY_HW_LPUART2_CTS_PULL)
pins_pull[3] = MICROPY_HW_LPUART2_CTS_PULL;
#endif
__HAL_RCC_LPUART2_CLK_ENABLE();
break;
#endif
@@ -564,10 +633,7 @@ bool uart_init(machine_uart_obj_t *uart_obj,
for (uint i = 0; i < 4; i++) {
if (pins[i] != NULL) {
// Configure pull-up on RX and CTS (the input pins).
uint32_t pull = (i & 1) ? MP_HAL_PIN_PULL_UP : MP_HAL_PIN_PULL_NONE;
bool ret = mp_hal_pin_config_alt(pins[i], mode, pull, uart_fn, uart_unit);
if (!ret) {
if (!mp_hal_pin_config_alt(pins[i], mode, pins_pull[i], uart_fn, uart_unit)) {
return false;
}
}