stmhal/uart: Add support for UART7 and UART8 on F7 MCUs.

This commit is contained in:
Damien George 2016-12-05 15:14:22 +11:00
parent 27a503f632
commit aaab6a9921
4 changed files with 71 additions and 4 deletions

View File

@ -187,8 +187,10 @@ extern const struct _mp_obj_module_t mp_module_network;
#if defined(MCU_SERIES_F7)
#define PYB_EXTI_NUM_VECTORS (24)
#define MICROPY_HW_MAX_UART (8)
#else
#define PYB_EXTI_NUM_VECTORS (23)
#define MICROPY_HW_MAX_UART (6)
#endif
#define MP_STATE_PORT MP_STATE_VM
@ -215,7 +217,7 @@ extern const struct _mp_obj_module_t mp_module_network;
struct _pyb_uart_obj_t *pyb_stdio_uart; \
\
/* pointers to all UART objects (if they have been created) */ \
struct _pyb_uart_obj_t *pyb_uart_obj_all[6]; \
struct _pyb_uart_obj_t *pyb_uart_obj_all[MICROPY_HW_MAX_UART]; \
\
/* pointers to all CAN objects (if they have been created) */ \
struct _pyb_can_obj_t *pyb_can_obj_all[2]; \

View File

@ -677,6 +677,22 @@ void USART6_IRQHandler(void) {
IRQ_EXIT(USART6_IRQn);
}
#if defined(MICROPY_HW_UART7_TX)
void UART7_IRQHandler(void) {
IRQ_ENTER(UART7_IRQn);
uart_irq_handler(7);
IRQ_EXIT(UART7_IRQn);
}
#endif
#if defined(MICROPY_HW_UART8_TX)
void UART8_IRQHandler(void) {
IRQ_ENTER(UART8_IRQn);
uart_irq_handler(8);
IRQ_EXIT(UART8_IRQn);
}
#endif
#if MICROPY_HW_ENABLE_CAN
void CAN1_RX0_IRQHandler(void) {
IRQ_ENTER(CAN1_RX0_IRQn);

View File

@ -37,8 +37,6 @@
#include "irq.h"
#include "genhdr/pins.h"
//TODO: Add UART7/8 support for MCU_SERIES_F7
/// \moduleref pyb
/// \class UART - duplex serial communication bus
///
@ -206,6 +204,28 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
break;
#endif
#if defined(MICROPY_HW_UART7_TX) && defined(MICROPY_HW_UART7_RX)
case PYB_UART_7:
uart_unit = 7;
UARTx = UART7;
irqn = UART7_IRQn;
pins[0] = &MICROPY_HW_UART7_TX;
pins[1] = &MICROPY_HW_UART7_RX;
__UART7_CLK_ENABLE();
break;
#endif
#if defined(MICROPY_HW_UART8_TX) && defined(MICROPY_HW_UART8_RX)
case PYB_UART_8:
uart_unit = 8;
UARTx = UART8;
irqn = UART8_IRQn;
pins[0] = &MICROPY_HW_UART8_TX;
pins[1] = &MICROPY_HW_UART8_RX;
__UART8_CLK_ENABLE();
break;
#endif
default:
// UART does not exist or is not configured for this board
return false;
@ -537,7 +557,19 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
// compute actual baudrate that was configured
// (this formula assumes UART_OVERSAMPLING_16)
uint32_t actual_baudrate;
uint32_t actual_baudrate = 0;
#if defined(MCU_SERIES_F7)
UART_ClockSourceTypeDef clocksource = UART_CLOCKSOURCE_UNDEFINED;
UART_GETCLOCKSOURCE(&self->uart, clocksource);
switch (clocksource) {
case UART_CLOCKSOURCE_PCLK1: actual_baudrate = HAL_RCC_GetPCLK1Freq(); break;
case UART_CLOCKSOURCE_PCLK2: actual_baudrate = HAL_RCC_GetPCLK2Freq(); break;
case UART_CLOCKSOURCE_HSI: actual_baudrate = HSI_VALUE; break;
case UART_CLOCKSOURCE_SYSCLK: actual_baudrate = HAL_RCC_GetSysClockFreq(); break;
case UART_CLOCKSOURCE_LSE: actual_baudrate = LSE_VALUE; break;
case UART_CLOCKSOURCE_UNDEFINED: break;
}
#else
if (self->uart.Instance == USART1
#if defined(USART6)
|| self->uart.Instance == USART6
@ -547,6 +579,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
} else {
actual_baudrate = HAL_RCC_GetPCLK1Freq();
}
#endif
actual_baudrate /= self->uart.Instance->BRR;
// check we could set the baudrate within 5%
@ -694,6 +727,20 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
__USART6_RELEASE_RESET();
__USART6_CLK_DISABLE();
#endif
#if defined(UART7)
} else if (uart->Instance == UART7) {
HAL_NVIC_DisableIRQ(UART7_IRQn);
__UART7_FORCE_RESET();
__UART7_RELEASE_RESET();
__UART7_CLK_DISABLE();
#endif
#if defined(UART8)
} else if (uart->Instance == UART8) {
HAL_NVIC_DisableIRQ(UART8_IRQn);
__UART8_FORCE_RESET();
__UART8_RELEASE_RESET();
__UART8_CLK_DISABLE();
#endif
}
return mp_const_none;
}

View File

@ -32,6 +32,8 @@ typedef enum {
PYB_UART_4 = 4,
PYB_UART_5 = 5,
PYB_UART_6 = 6,
PYB_UART_7 = 7,
PYB_UART_8 = 8,
} pyb_uart_t;
typedef struct _pyb_uart_obj_t pyb_uart_obj_t;