summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/uart.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-08-03 00:20:08 +0100
committerDamien George <damien.p.george@gmail.com>2015-08-03 00:22:16 +0100
commita632037866c55e04fe6d5c3f96e39067e4ad5579 (patch)
tree8a6caf5d7f16d91c2c794c708573a062f38feb1d /stmhal/uart.c
parentc0e39864c6f2876375dc57009fd3341e51e62295 (diff)
downloadmicropython-a632037866c55e04fe6d5c3f96e39067e4ad5579.tar.gz
micropython-a632037866c55e04fe6d5c3f96e39067e4ad5579.zip
stmhal: Add better support for UART having Tx and Rx on different ports.
Thanks to Dave Hylands for the patch.
Diffstat (limited to 'stmhal/uart.c')
-rw-r--r--stmhal/uart.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/stmhal/uart.c b/stmhal/uart.c
index 9ff1668e3a..01771be3f8 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -114,9 +114,10 @@ void uart_deinit(void) {
STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
USART_TypeDef *UARTx;
IRQn_Type irqn;
- uint32_t GPIO_Pin;
+ uint32_t GPIO_Pin, GPIO_Pin2;
uint8_t GPIO_AF_UARTx = 0;
GPIO_TypeDef* GPIO_Port = NULL;
+ GPIO_TypeDef* GPIO_Port2 = NULL;
switch (uart_obj->uart_id) {
#if defined(MICROPY_HW_UART1_PORT) && defined(MICROPY_HW_UART1_PINS)
@@ -197,18 +198,10 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
irqn = UART5_IRQn;
GPIO_AF_UARTx = GPIO_AF8_UART5;
GPIO_Port = MICROPY_HW_UART5_TX_PORT;
+ GPIO_Port2 = MICROPY_HW_UART5_RX_PORT;
GPIO_Pin = MICROPY_HW_UART5_TX_PIN;
+ GPIO_Pin2 = MICROPY_HW_UART5_RX_PIN;
__UART5_CLK_ENABLE();
-
- // The code after the case only deals with the case where the TX & RX
- // pins are on the same port. UART5 has them on different ports.
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Pin = MICROPY_HW_UART5_RX_PIN;
- GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
- GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStructure.Pull = GPIO_PULLUP;
- GPIO_InitStructure.Alternate = GPIO_AF_UARTx;
- HAL_GPIO_Init(MICROPY_HW_UART5_RX_PORT, &GPIO_InitStructure);
break;
#endif
@@ -242,6 +235,13 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
GPIO_InitStructure.Alternate = GPIO_AF_UARTx;
HAL_GPIO_Init(GPIO_Port, &GPIO_InitStructure);
+ // init GPIO for second pin if needed
+ if (GPIO_Port2 != NULL) {
+ mp_hal_gpio_clock_enable(GPIO_Port2);
+ GPIO_InitStructure.Pin = GPIO_Pin2;
+ HAL_GPIO_Init(GPIO_Port2, &GPIO_InitStructure);
+ }
+
// init UARTx
HAL_UART_Init(&uart_obj->uart);