summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/uart.c
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2015-05-31 15:37:37 -0700
committerDamien George <damien.p.george@gmail.com>2015-06-01 00:14:46 +0100
commit3ac2d06bd13f1cedb8242eaacc6c608ac08c3520 (patch)
treeb0397ac9b155e0cd77c6647a90c4fb3e76017091 /stmhal/uart.c
parent18fda7b42f1063f7b1d34c87a0d8697f28b0f312 (diff)
downloadmicropython-3ac2d06bd13f1cedb8242eaacc6c608ac08c3520.tar.gz
micropython-3ac2d06bd13f1cedb8242eaacc6c608ac08c3520.zip
stmhal: Add support for UART5
I tested this on my CERB40 board and it seems to be working fine.
Diffstat (limited to 'stmhal/uart.c')
-rw-r--r--stmhal/uart.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/stmhal/uart.c b/stmhal/uart.c
index e1357b1f64..70b7390c0a 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -185,6 +185,31 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
break;
#endif
+ #if defined(UART5) && \
+ defined(MICROPY_HW_UART5_TX_PORT) && \
+ defined(MICROPY_HW_UART5_TX_PIN) && \
+ defined(MICROPY_HW_UART5_RX_PORT) && \
+ defined(MICROPY_HW_UART5_RX_PIN)
+ case PYB_UART_5:
+ UARTx = UART5;
+ irqn = UART5_IRQn;
+ GPIO_AF_UARTx = GPIO_AF8_UART5;
+ GPIO_Port = MICROPY_HW_UART5_TX_PORT;
+ GPIO_Pin = MICROPY_HW_UART5_TX_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
+
#if defined(MICROPY_HW_UART6_PORT) && defined(MICROPY_HW_UART6_PINS)
// USART6 is on PC6/PC7 (CK on PC8)
case PYB_UART_6:
@@ -596,6 +621,13 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
__UART4_RELEASE_RESET();
__UART4_CLK_DISABLE();
#endif
+ #if defined(UART5)
+ } else if (uart->Instance == UART5) {
+ HAL_NVIC_DisableIRQ(UART5_IRQn);
+ __UART5_FORCE_RESET();
+ __UART5_RELEASE_RESET();
+ __UART5_CLK_DISABLE();
+ #endif
} else if (uart->Instance == USART6) {
HAL_NVIC_DisableIRQ(USART6_IRQn);
__USART6_FORCE_RESET();