stmhal: Allow to configure UART pins completely via mpconfigboard.h.

This commit is contained in:
Eero af Heurlin 2015-05-02 19:31:39 +03:00 committed by Damien George
parent 8c8d7f3c60
commit 2378be4e93
9 changed files with 153 additions and 37 deletions

View File

@ -25,6 +25,22 @@
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2) #define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7) #define MICROPY_HW_CLK_PLLQ (7)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOD)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// I2C busses // I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -26,6 +26,16 @@
// does not have a 32kHz crystal // does not have a 32kHz crystal
#define MICROPY_HW_RTC_USE_LSE (0) #define MICROPY_HW_RTC_USE_LSE (0)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOB)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART6_PORT (GPIOA)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_11 | GPIO_PIN_12)
// I2C busses // I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -24,6 +24,22 @@
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2) #define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7) #define MICROPY_HW_CLK_PLLQ (7)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOD)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// I2C busses // I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -28,6 +28,22 @@
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2) #define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7) #define MICROPY_HW_CLK_PLLQ (7)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOD)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// I2C busses // I2C busses
#define MICROPY_HW_I2C2_SCL (pin_B10) #define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11) #define MICROPY_HW_I2C2_SDA (pin_B11)

View File

@ -28,6 +28,22 @@
// The pyboard has a 32kHz crystal for the RTC // The pyboard has a 32kHz crystal for the RTC
#define MICROPY_HW_RTC_USE_LSE (1) #define MICROPY_HW_RTC_USE_LSE (1)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOB)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOB)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// X-skin: X9=PB6=SCL, X10=PB7=SDA // X-skin: X9=PB6=SCL, X10=PB7=SDA
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -27,6 +27,22 @@
// The pyboard has a 32kHz crystal for the RTC // The pyboard has a 32kHz crystal for the RTC
#define MICROPY_HW_RTC_USE_LSE (1) #define MICROPY_HW_RTC_USE_LSE (1)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOB)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// X-skin: X9=PB6=SCL, X10=PB7=SDA // X-skin: X9=PB6=SCL, X10=PB7=SDA
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -27,6 +27,22 @@
// The pyboard has a 32kHz crystal for the RTC // The pyboard has a 32kHz crystal for the RTC
#define MICROPY_HW_RTC_USE_LSE (1) #define MICROPY_HW_RTC_USE_LSE (1)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOB)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOB)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// X-skin: X9=PB6=SCL, X10=PB7=SDA // X-skin: X9=PB6=SCL, X10=PB7=SDA
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -24,6 +24,22 @@
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2) #define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7) #define MICROPY_HW_CLK_PLLQ (7)
// UART config
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_PORT (GPIOD)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
// I2C busses // I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7) #define MICROPY_HW_I2C1_SDA (pin_B7)

View File

@ -117,94 +117,88 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
GPIO_TypeDef* GPIO_Port = NULL; GPIO_TypeDef* GPIO_Port = NULL;
switch (uart_obj->uart_id) { switch (uart_obj->uart_id) {
#if defined(MICROPY_HW_UART1_PORT) && defined(MICROPY_HW_UART1_PINS)
// USART1 is on PA9/PA10 (CK on PA8), PB6/PB7 // USART1 is on PA9/PA10 (CK on PA8), PB6/PB7
case PYB_UART_1: case PYB_UART_1:
UARTx = USART1; UARTx = USART1;
irqn = USART1_IRQn; irqn = USART1_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART1; GPIO_AF_UARTx = GPIO_AF7_USART1;
GPIO_Port = MICROPY_HW_UART1_PORT;
#if defined (PYBV4) || defined(PYBV10) GPIO_Pin = MICROPY_HW_UART1_PINS;
GPIO_Port = GPIOB;
GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7;
#else
GPIO_Port = GPIOA;
GPIO_Pin = GPIO_PIN_9 | GPIO_PIN_10;
#endif
__USART1_CLK_ENABLE(); __USART1_CLK_ENABLE();
break; break;
#endif
#if defined(MICROPY_HW_UART2_PORT) && defined(MICROPY_HW_UART2_PINS)
// USART2 is on PA2/PA3 (CTS,RTS,CK on PA0,PA1,PA4), PD5/PD6 (CK on PD7) // USART2 is on PA2/PA3 (CTS,RTS,CK on PA0,PA1,PA4), PD5/PD6 (CK on PD7)
case PYB_UART_2: case PYB_UART_2:
UARTx = USART2; UARTx = USART2;
irqn = USART2_IRQn; irqn = USART2_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART2; GPIO_AF_UARTx = GPIO_AF7_USART2;
GPIO_Port = MICROPY_HW_UART2_PORT;
GPIO_Port = GPIOA; GPIO_Pin = MICROPY_HW_UART2_PINS;
GPIO_Pin = GPIO_PIN_2 | GPIO_PIN_3; #if defined(MICROPY_HW_UART2_RTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) { if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
GPIO_Pin |= GPIO_PIN_1; GPIO_Pin |= MICROPY_HW_UART2_RTS;
} }
#endif
#if defined(MICROPY_HW_UART2_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) { if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
GPIO_Pin |= GPIO_PIN_0; GPIO_Pin |= MICROPY_HW_UART2_CTS;
} }
#endif
__USART2_CLK_ENABLE(); __USART2_CLK_ENABLE();
break; break;
#endif
#if defined(USART3) #if defined(USART3) && defined(MICROPY_HW_UART3_PORT) && defined(MICROPY_HW_UART3_PINS)
// USART3 is on PB10/PB11 (CK,CTS,RTS on PB12,PB13,PB14), PC10/PC11 (CK on PC12), PD8/PD9 (CK on PD10) // USART3 is on PB10/PB11 (CK,CTS,RTS on PB12,PB13,PB14), PC10/PC11 (CK on PC12), PD8/PD9 (CK on PD10)
case PYB_UART_3: case PYB_UART_3:
UARTx = USART3; UARTx = USART3;
irqn = USART3_IRQn; irqn = USART3_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART3; GPIO_AF_UARTx = GPIO_AF7_USART3;
GPIO_Port = MICROPY_HW_UART3_PORT;
#if defined(PYBV3) || defined(PYBV4) | defined(PYBV10) GPIO_Pin = MICROPY_HW_UART3_PINS;
GPIO_Port = GPIOB; #if defined(MICROPY_HW_UART3_RTS)
GPIO_Pin = GPIO_PIN_10 | GPIO_PIN_11;
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) { if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
GPIO_Pin |= GPIO_PIN_14; GPIO_Pin |= MICROPY_HW_UART3_RTS;
} }
#endif
#if defined(MICROPY_HW_UART3_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) { if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
GPIO_Pin |= GPIO_PIN_13; GPIO_Pin |= MICROPY_HW_UART3_CTS;
} }
#else #endif
GPIO_Port = GPIOD;
GPIO_Pin = GPIO_PIN_8 | GPIO_PIN_9;
#endif
__USART3_CLK_ENABLE(); __USART3_CLK_ENABLE();
break; break;
#endif #endif
#if defined(UART4) #if defined(UART4) && defined(MICROPY_HW_UART4_PORT) && defined(MICROPY_HW_UART4_PINS)
// UART4 is on PA0/PA1, PC10/PC11 // UART4 is on PA0/PA1, PC10/PC11
case PYB_UART_4: case PYB_UART_4:
UARTx = UART4; UARTx = UART4;
irqn = UART4_IRQn; irqn = UART4_IRQn;
GPIO_AF_UARTx = GPIO_AF8_UART4; GPIO_AF_UARTx = GPIO_AF8_UART4;
GPIO_Port = MICROPY_HW_UART4_PORT;
GPIO_Port = GPIOA; GPIO_Pin = MICROPY_HW_UART4_PINS;
GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1;
__UART4_CLK_ENABLE(); __UART4_CLK_ENABLE();
break; break;
#endif #endif
#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:
UARTx = USART6; UARTx = USART6;
irqn = USART6_IRQn; irqn = USART6_IRQn;
GPIO_AF_UARTx = GPIO_AF8_USART6; GPIO_AF_UARTx = GPIO_AF8_USART6;
GPIO_Port = MICROPY_HW_UART6_PORT;
GPIO_Port = GPIOC; GPIO_Pin = MICROPY_HW_UART6_PINS;
GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7;
__USART6_CLK_ENABLE(); __USART6_CLK_ENABLE();
break; break;
#endif
default: default:
// UART does not exist or is not configured for this board
return false; return false;
} }