Commit 3ac2d06b authored by Dave Hylands's avatar Dave Hylands Committed by Damien George
Browse files

stmhal: Add support for UART5

I tested this on my CERB40 board and it seems to be working fine.
parent 18fda7b4
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11) #define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
#define MICROPY_HW_UART4_PORT (GPIOA) #define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1) #define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART5_TX_PORT (GPIOC)
#define MICROPY_HW_UART5_TX_PIN (GPIO_PIN_12)
#define MICROPY_HW_UART5_RX_PORT (GPIOD)
#define MICROPY_HW_UART5_RX_PIN (GPIO_PIN_2)
#define MICROPY_HW_UART6_PORT (GPIOC) #define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7) #define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
......
...@@ -413,6 +413,10 @@ void UART4_IRQHandler(void) { ...@@ -413,6 +413,10 @@ void UART4_IRQHandler(void) {
uart_irq_handler(4); uart_irq_handler(4);
} }
void UART5_IRQHandler(void) {
uart_irq_handler(5);
}
void USART6_IRQHandler(void) { void USART6_IRQHandler(void) {
uart_irq_handler(6); uart_irq_handler(6);
} }
......
...@@ -185,6 +185,31 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) { ...@@ -185,6 +185,31 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
break; break;
#endif #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) #if defined(MICROPY_HW_UART6_PORT) && defined(MICROPY_HW_UART6_PINS)
// USART6 is on PC6/PC7 (CK on PC8) // USART6 is on PC6/PC7 (CK on PC8)
case PYB_UART_6: case PYB_UART_6:
...@@ -596,6 +621,13 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) { ...@@ -596,6 +621,13 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
__UART4_RELEASE_RESET(); __UART4_RELEASE_RESET();
__UART4_CLK_DISABLE(); __UART4_CLK_DISABLE();
#endif #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) { } else if (uart->Instance == USART6) {
HAL_NVIC_DisableIRQ(USART6_IRQn); HAL_NVIC_DisableIRQ(USART6_IRQn);
__USART6_FORCE_RESET(); __USART6_FORCE_RESET();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment