stm32/uart: Add support for USART3-8 on F0 MCUs.
This commit is contained in:
parent
84f4d58479
commit
cdc01408c7
@ -215,7 +215,11 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
|
|||||||
case PYB_UART_3:
|
case PYB_UART_3:
|
||||||
uart_unit = 3;
|
uart_unit = 3;
|
||||||
UARTx = USART3;
|
UARTx = USART3;
|
||||||
|
#if defined(STM32F0)
|
||||||
|
irqn = USART3_8_IRQn;
|
||||||
|
#else
|
||||||
irqn = USART3_IRQn;
|
irqn = USART3_IRQn;
|
||||||
|
#endif
|
||||||
pins[0] = MICROPY_HW_UART3_TX;
|
pins[0] = MICROPY_HW_UART3_TX;
|
||||||
pins[1] = MICROPY_HW_UART3_RX;
|
pins[1] = MICROPY_HW_UART3_RX;
|
||||||
#if defined(MICROPY_HW_UART3_RTS)
|
#if defined(MICROPY_HW_UART3_RTS)
|
||||||
@ -235,22 +239,34 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
|
|||||||
#if defined(MICROPY_HW_UART4_TX) && defined(MICROPY_HW_UART4_RX)
|
#if defined(MICROPY_HW_UART4_TX) && defined(MICROPY_HW_UART4_RX)
|
||||||
case PYB_UART_4:
|
case PYB_UART_4:
|
||||||
uart_unit = 4;
|
uart_unit = 4;
|
||||||
|
#if defined(STM32F0)
|
||||||
|
UARTx = USART4;
|
||||||
|
irqn = USART3_8_IRQn;
|
||||||
|
__HAL_RCC_USART4_CLK_ENABLE();
|
||||||
|
#else
|
||||||
UARTx = UART4;
|
UARTx = UART4;
|
||||||
irqn = UART4_IRQn;
|
irqn = UART4_IRQn;
|
||||||
|
__HAL_RCC_UART4_CLK_ENABLE();
|
||||||
|
#endif
|
||||||
pins[0] = MICROPY_HW_UART4_TX;
|
pins[0] = MICROPY_HW_UART4_TX;
|
||||||
pins[1] = MICROPY_HW_UART4_RX;
|
pins[1] = MICROPY_HW_UART4_RX;
|
||||||
__HAL_RCC_UART4_CLK_ENABLE();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MICROPY_HW_UART5_TX) && defined(MICROPY_HW_UART5_RX)
|
#if defined(MICROPY_HW_UART5_TX) && defined(MICROPY_HW_UART5_RX)
|
||||||
case PYB_UART_5:
|
case PYB_UART_5:
|
||||||
uart_unit = 5;
|
uart_unit = 5;
|
||||||
|
#if defined(STM32F0)
|
||||||
|
UARTx = USART5;
|
||||||
|
irqn = USART3_8_IRQn;
|
||||||
|
__HAL_RCC_USART5_CLK_ENABLE();
|
||||||
|
#else
|
||||||
UARTx = UART5;
|
UARTx = UART5;
|
||||||
irqn = UART5_IRQn;
|
irqn = UART5_IRQn;
|
||||||
|
__HAL_RCC_UART5_CLK_ENABLE();
|
||||||
|
#endif
|
||||||
pins[0] = MICROPY_HW_UART5_TX;
|
pins[0] = MICROPY_HW_UART5_TX;
|
||||||
pins[1] = MICROPY_HW_UART5_RX;
|
pins[1] = MICROPY_HW_UART5_RX;
|
||||||
__HAL_RCC_UART5_CLK_ENABLE();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -258,7 +274,11 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
|
|||||||
case PYB_UART_6:
|
case PYB_UART_6:
|
||||||
uart_unit = 6;
|
uart_unit = 6;
|
||||||
UARTx = USART6;
|
UARTx = USART6;
|
||||||
|
#if defined(STM32F0)
|
||||||
|
irqn = USART3_8_IRQn;
|
||||||
|
#else
|
||||||
irqn = USART6_IRQn;
|
irqn = USART6_IRQn;
|
||||||
|
#endif
|
||||||
pins[0] = MICROPY_HW_UART6_TX;
|
pins[0] = MICROPY_HW_UART6_TX;
|
||||||
pins[1] = MICROPY_HW_UART6_RX;
|
pins[1] = MICROPY_HW_UART6_RX;
|
||||||
#if defined(MICROPY_HW_UART6_RTS)
|
#if defined(MICROPY_HW_UART6_RTS)
|
||||||
@ -278,11 +298,17 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
|
|||||||
#if defined(MICROPY_HW_UART7_TX) && defined(MICROPY_HW_UART7_RX)
|
#if defined(MICROPY_HW_UART7_TX) && defined(MICROPY_HW_UART7_RX)
|
||||||
case PYB_UART_7:
|
case PYB_UART_7:
|
||||||
uart_unit = 7;
|
uart_unit = 7;
|
||||||
|
#if defined(STM32F0)
|
||||||
|
UARTx = USART7;
|
||||||
|
irqn = USART3_8_IRQn;
|
||||||
|
__HAL_RCC_USART7_CLK_ENABLE();
|
||||||
|
#else
|
||||||
UARTx = UART7;
|
UARTx = UART7;
|
||||||
irqn = UART7_IRQn;
|
irqn = UART7_IRQn;
|
||||||
|
__HAL_RCC_UART7_CLK_ENABLE();
|
||||||
|
#endif
|
||||||
pins[0] = MICROPY_HW_UART7_TX;
|
pins[0] = MICROPY_HW_UART7_TX;
|
||||||
pins[1] = MICROPY_HW_UART7_RX;
|
pins[1] = MICROPY_HW_UART7_RX;
|
||||||
__HAL_RCC_UART7_CLK_ENABLE();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -806,6 +832,14 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||||||
} else if (strcmp(port, MICROPY_HW_UART6_NAME) == 0) {
|
} else if (strcmp(port, MICROPY_HW_UART6_NAME) == 0) {
|
||||||
uart_id = PYB_UART_6;
|
uart_id = PYB_UART_6;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MICROPY_HW_UART7_NAME
|
||||||
|
} else if (strcmp(port, MICROPY_HW_UART7_NAME) == 0) {
|
||||||
|
uart_id = PYB_UART_7;
|
||||||
|
#endif
|
||||||
|
#ifdef MICROPY_HW_UART8_NAME
|
||||||
|
} else if (strcmp(port, MICROPY_HW_UART8_NAME) == 0) {
|
||||||
|
uart_id = PYB_UART_8;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) doesn't exist", port));
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) doesn't exist", port));
|
||||||
}
|
}
|
||||||
@ -876,6 +910,12 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
|||||||
__HAL_RCC_UART4_RELEASE_RESET();
|
__HAL_RCC_UART4_RELEASE_RESET();
|
||||||
__HAL_RCC_UART4_CLK_DISABLE();
|
__HAL_RCC_UART4_CLK_DISABLE();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(USART4)
|
||||||
|
} else if (uart->Instance == USART4) {
|
||||||
|
__HAL_RCC_USART4_FORCE_RESET();
|
||||||
|
__HAL_RCC_USART4_RELEASE_RESET();
|
||||||
|
__HAL_RCC_USART4_CLK_DISABLE();
|
||||||
|
#endif
|
||||||
#if defined(UART5)
|
#if defined(UART5)
|
||||||
} else if (uart->Instance == UART5) {
|
} else if (uart->Instance == UART5) {
|
||||||
HAL_NVIC_DisableIRQ(UART5_IRQn);
|
HAL_NVIC_DisableIRQ(UART5_IRQn);
|
||||||
@ -883,6 +923,12 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
|||||||
__HAL_RCC_UART5_RELEASE_RESET();
|
__HAL_RCC_UART5_RELEASE_RESET();
|
||||||
__HAL_RCC_UART5_CLK_DISABLE();
|
__HAL_RCC_UART5_CLK_DISABLE();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(USART5)
|
||||||
|
} else if (uart->Instance == USART5) {
|
||||||
|
__HAL_RCC_USART5_FORCE_RESET();
|
||||||
|
__HAL_RCC_USART5_RELEASE_RESET();
|
||||||
|
__HAL_RCC_USART5_CLK_DISABLE();
|
||||||
|
#endif
|
||||||
#if defined(UART6)
|
#if defined(UART6)
|
||||||
} else if (uart->Instance == USART6) {
|
} else if (uart->Instance == USART6) {
|
||||||
HAL_NVIC_DisableIRQ(USART6_IRQn);
|
HAL_NVIC_DisableIRQ(USART6_IRQn);
|
||||||
@ -897,6 +943,12 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
|||||||
__HAL_RCC_UART7_RELEASE_RESET();
|
__HAL_RCC_UART7_RELEASE_RESET();
|
||||||
__HAL_RCC_UART7_CLK_DISABLE();
|
__HAL_RCC_UART7_CLK_DISABLE();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(USART7)
|
||||||
|
} else if (uart->Instance == USART7) {
|
||||||
|
__HAL_RCC_USART7_FORCE_RESET();
|
||||||
|
__HAL_RCC_USART7_RELEASE_RESET();
|
||||||
|
__HAL_RCC_USART7_CLK_DISABLE();
|
||||||
|
#endif
|
||||||
#if defined(UART8)
|
#if defined(UART8)
|
||||||
} else if (uart->Instance == UART8) {
|
} else if (uart->Instance == UART8) {
|
||||||
HAL_NVIC_DisableIRQ(UART8_IRQn);
|
HAL_NVIC_DisableIRQ(UART8_IRQn);
|
||||||
@ -904,6 +956,12 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
|||||||
__HAL_RCC_UART8_RELEASE_RESET();
|
__HAL_RCC_UART8_RELEASE_RESET();
|
||||||
__HAL_RCC_UART8_CLK_DISABLE();
|
__HAL_RCC_UART8_CLK_DISABLE();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(USART8)
|
||||||
|
} else if (uart->Instance == USART8) {
|
||||||
|
__HAL_RCC_USART8_FORCE_RESET();
|
||||||
|
__HAL_RCC_USART8_RELEASE_RESET();
|
||||||
|
__HAL_RCC_USART8_CLK_DISABLE();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user