stmhal: Refactor UART configuration to use pin objects.

This follows the pattern of other peripherals (I2C, SPI) to specify the
pins using pin objects instead of a pair of GPIO port and pin number.  It
makes it easier to customise the UART pins for a particular board.
This commit is contained in:
Rami Ali 2016-12-05 12:21:45 +11:00 committed by Damien George
parent 4fc607a1d7
commit 27a503f632
24 changed files with 250 additions and 282 deletions

View File

@ -24,24 +24,22 @@
#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_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_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_TX (pin_D8)
#define MICROPY_HW_UART3_RX (pin_D9)
#define MICROPY_HW_UART3_RTS (pin_D12)
#define MICROPY_HW_UART3_CTS (pin_D11)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART5_TX (pin_C12)
#define MICROPY_HW_UART5_RX (pin_D2)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -38,3 +38,9 @@ JP37,PC7
JP38,PC8
JP39,PC9
JP40,VUSB
UART1_TX,PA9
UART1_RX,PA10
UART3_TX,PD8
UART3_RX,PD9
UART3_RTS,PD12
UART3_CTS,PD11

1 JP1 3.3V
38 JP38 PC8
39 JP39 PC9
40 JP40 VUSB
41 UART1_TX PA9
42 UART1_RX PA10
43 UART3_TX PD8
44 UART3_RX PD9
45 UART3_RTS PD12
46 UART3_CTS PD11

View File

@ -28,14 +28,14 @@
#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)
#define MICROPY_HW_UART1_TX (pin_B6)
#define MICROPY_HW_UART1_RX (pin_B7)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART6_TX (pin_A11)
#define MICROPY_HW_UART6_RX (pin_A12)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -23,20 +23,20 @@
#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)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_TX (pin_D8)
#define MICROPY_HW_UART3_RX (pin_D9)
#define MICROPY_HW_UART3_RTS (pin_D12)
#define MICROPY_HW_UART3_CTS (pin_D11)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -46,3 +46,7 @@ PA12,PA12
PD2,PD2
BOOT0,BOOT0
PA15,PA15
UART3_TX,PD8
UART3_RX,PD9
UART3_RTS,PD12
UART3_CTS,PD11

1 PC0 PC0
46 PD2 PD2
47 BOOT0 BOOT0
48 PA15 PA15
49 UART3_TX PD8
50 UART3_RX PD9
51 UART3_RTS PD12
52 UART3_CTS PD11

View File

@ -29,8 +29,8 @@ void LIMIFROG_board_early_init(void);
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_4
// USART config
#define MICROPY_HW_UART3_PORT (GPIOC)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_TX (pin_C10)
#define MICROPY_HW_UART3_RX (pin_C11)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B8)

View File

@ -28,20 +28,22 @@ void NETDUINO_PLUS_2_board_early_init(void);
#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)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_TX (pin_D8)
#define MICROPY_HW_UART3_RX (pin_D9)
#define MICROPY_HW_UART3_RTS (pin_D12)
#define MICROPY_HW_UART3_CTS (pin_D11)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART5_TX (pin_C12)
#define MICROPY_HW_UART5_RX (pin_D2)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -27,4 +27,9 @@ PWR_SD,PB1
PWR_HDR,PB2
PWR_ETH,PC15
RST_ETH,PD2
UART1_TX,PA9
UART3_TX,PD8
UART3_RX,PD9
UART3_RTS,PD12
UART3_CTS,PD11
UART5_TX,PC12

1 D0 PC7
27 PWR_HDR PB2
28 PWR_ETH PC15
29 RST_ETH PD2
30 UART1_TX PA9
31 UART3_TX PD8
32 UART3_RX PD9
33 UART3_RTS PD12
34 UART3_CTS PD11
35 UART5_TX PC12

View File

@ -12,11 +12,10 @@
#define MICROPY_HW_CLK_PLLQ (7)
// UART config
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// UART 2 connects to the STM32F103 (STLINK) on the Nucleo board
// and this is exposed as a USB Serial port.
#define MICROPY_HW_UART_REPL PYB_UART_2

View File

@ -12,11 +12,10 @@
#define MICROPY_HW_CLK_PLLQ (4)
// UART config
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// UART 2 connects to the STM32F103 (STLINK) on the Nucleo board
// and this is exposed as a USB Serial port.
#define MICROPY_HW_UART_REPL PYB_UART_2

View File

@ -23,29 +23,25 @@
#define MICROPY_HW_CLK_PLLQ (7)
// 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 (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_UART1_TX (pin_B6)
#define MICROPY_HW_UART1_RX (pin_B7)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_TX (pin_D8)
#define MICROPY_HW_UART3_RX (pin_D9)
#define MICROPY_HW_UART3_RTS (pin_D12)
#define MICROPY_HW_UART3_CTS (pin_D11)
#if MICROPY_HW_HAS_SWITCH == 0
// NOTE: A0 also connects to the user switch. To use UART4 you should
// set MICROPY_HW_HAS_SWITCH to 0, and also remove SB20 (on the back
// of the board near the USER switch).
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#endif
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B8)

View File

@ -28,17 +28,17 @@
#define MICROPY_HW_RTC_USE_CALOUT (1)
// UART config
#define MICROPY_HW_UART1_NAME "XB"
#define MICROPY_HW_UART1_PORT (GPIOB)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_NAME "XA"
#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_NAME "YA"
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART1_NAME "XB"
#define MICROPY_HW_UART1_TX (pin_B6)
#define MICROPY_HW_UART1_RX (pin_B7)
#define MICROPY_HW_UART2_NAME "XA"
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_NAME "X"

View File

@ -28,24 +28,24 @@
#define MICROPY_HW_RTC_USE_CALOUT (1)
// UART config
#define MICROPY_HW_UART1_NAME "XB"
#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_NAME "YB"
#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_NAME "XA"
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART1_NAME "XB"
#define MICROPY_HW_UART1_TX (pin_B6)
#define MICROPY_HW_UART1_RX (pin_B7)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_NAME "YB"
#define MICROPY_HW_UART3_TX (pin_B10)
#define MICROPY_HW_UART3_RX (pin_B11)
#define MICROPY_HW_UART3_RTS (pin_B14)
#define MICROPY_HW_UART3_CTS (pin_B13)
#define MICROPY_HW_UART4_NAME "XA"
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_NAME "X"

View File

@ -28,24 +28,24 @@
#define MICROPY_HW_RTC_USE_CALOUT (1)
// UART config
#define MICROPY_HW_UART1_NAME "XB"
#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_NAME "YB"
#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_NAME "XA"
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART1_NAME "XB"
#define MICROPY_HW_UART1_TX (pin_B6)
#define MICROPY_HW_UART1_RX (pin_B7)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_NAME "YB"
#define MICROPY_HW_UART3_TX (pin_B10)
#define MICROPY_HW_UART3_RX (pin_B11)
#define MICROPY_HW_UART3_RTS (pin_B14)
#define MICROPY_HW_UART3_CTS (pin_B13)
#define MICROPY_HW_UART4_NAME "XA"
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_NAME "X"

View File

@ -24,20 +24,20 @@
#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)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_TX (pin_B10)
#define MICROPY_HW_UART3_RX (pin_B11)
#define MICROPY_HW_UART3_RTS (pin_B14)
#define MICROPY_HW_UART3_CTS (pin_B13)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// X-skin: X9=PB6=SCL, X10=PB7=SDA
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -37,3 +37,4 @@ SW,PA13
SD,PC13
MMA_INT,PB2
MMA_AVDD,PB5
UART1_TX,PA9

1 B13 PB13
37 SD PC13
38 MMA_INT PB2
39 MMA_AVDD PB5
40 UART1_TX PA9

View File

@ -25,14 +25,14 @@
#define MICROPY_HW_RTC_USE_LSE (0)
// 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_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -23,10 +23,10 @@
#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 (GPIOD)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_8 | GPIO_PIN_9)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_D8)
#define MICROPY_HW_UART2_RX (pin_D9)
// I2C busses
#define MICROPY_HW_I2C3_SCL (pin_A8)

View File

@ -28,20 +28,20 @@
#define MICROPY_HW_CLK_PLLQ (8) //divide core clock by this to get 48MHz
// UART config
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART2_PORT (GPIOD)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_5 | GPIO_PIN_6)
#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)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_D5)
#define MICROPY_HW_UART2_RX (pin_D6)
#define MICROPY_HW_UART2_RTS (pin_D1)
#define MICROPY_HW_UART2_CTS (pin_D0)
#define MICROPY_HW_UART3_TX (pin_D8)
#define MICROPY_HW_UART3_RX (pin_D9)
#define MICROPY_HW_UART3_RTS (pin_D12)
#define MICROPY_HW_UART3_CTS (pin_D11)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_A8)

View File

@ -27,33 +27,29 @@
// A9 is used for USB VBUS detect, and A10 is used for USB_FS_ID.
// UART1 is also on PB6/7 but PB6 is tied to the Audio SCL line.
// Without board modifications, this makes UART1 unusable on this board.
#define MICROPY_HW_UART1_PORT (GPIOA)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#endif
#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_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART2_RTS (pin_A1)
#define MICROPY_HW_UART2_CTS (pin_A0)
#define MICROPY_HW_UART3_TX (pin_D8)
#define MICROPY_HW_UART3_RX (pin_D9)
#define MICROPY_HW_UART3_RTS (pin_D12)
#define MICROPY_HW_UART3_CTS (pin_D11)
#if MICROPY_HW_HAS_SWITCH == 0
// NOTE: A0 also connects to the user switch. To use UART4 you should
// set MICROPY_HW_HAS_SWITCH to 0, and also remove SB20 (on the back
// of the board near the USER switch).
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART4_TX (pin_A0)
#define MICROPY_HW_UART4_RX (pin_A1)
#endif
// NOTE: PC7 is connected to MCLK on the Audio chip. This is an input signal
// so I think as long as you're not using the audio chip then it should
// be fine to use as a UART pin.
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
// I2C busses
#define MICROPY_HW_I2C1_SCL (pin_B6)

View File

@ -35,16 +35,12 @@ void STM32F7DISC_board_early_init(void);
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_7 // 210-216 MHz needs 7 wait states
// UART config
#define MICROPY_HW_UART1_TX_PORT (GPIOA)
#define MICROPY_HW_UART1_TX_PIN (GPIO_PIN_9)
#define MICROPY_HW_UART1_RX_PORT (GPIOB)
#define MICROPY_HW_UART1_RX_PIN (GPIO_PIN_7)
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART7_PORT (GPIOF)
#define MICROPY_HW_UART7_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_B7)
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
#define MICROPY_HW_UART7_TX (pin_F6)
#define MICROPY_HW_UART7_RX (pin_F7)
#define MICROPY_HW_UART_REPL PYB_UART_1
#define MICROPY_HW_UART_REPL_BAUD 115200

View File

@ -26,9 +26,8 @@
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_4
// USART config
#define MICROPY_HW_UART2_PORT (GPIOD)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_5 | GPIO_PIN_6)
#define MICROPY_HW_UART2_TX (pin_D5)
#define MICROPY_HW_UART2_RX (pin_D6)
// USART 2 is connected to the virtual com port on the ST-LINK
#define MICROPY_HW_UART_REPL PYB_UART_2
#define MICROPY_HW_UART_REPL_BAUD 115200

View File

@ -21,10 +21,8 @@ CONDITIONAL_VAR = {
'I2C' : 'MICROPY_HW_I2C{num}_SCL',
'I2S' : 'MICROPY_HW_ENABLE_I2S{num}',
'SPI' : 'MICROPY_HW_SPI{num}_SCK',
'UART' : 'MICROPY_HW_UART{num}_PORT',
'UART5' : 'MICROPY_HW_UART5_TX_PORT',
'USART' : 'MICROPY_HW_UART{num}_PORT',
'USART1': 'MICROPY_HW_UART1_TX_PORT',
'UART' : 'MICROPY_HW_UART{num}_TX',
'USART' : 'MICROPY_HW_UART{num}_TX',
}
def parse_port_pin(name_str):

View File

@ -35,6 +35,7 @@
#include "py/mphal.h"
#include "uart.h"
#include "irq.h"
#include "genhdr/pins.h"
//TODO: Add UART7/8 support for MCU_SERIES_F7
@ -114,120 +115,93 @@ void uart_deinit(void) {
STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
USART_TypeDef *UARTx;
IRQn_Type irqn;
uint32_t GPIO_Pin, GPIO_Pin2 = 0;
uint8_t GPIO_AF_UARTx = 0;
GPIO_TypeDef* GPIO_Port = NULL;
GPIO_TypeDef* GPIO_Port2 = NULL;
int uart_unit;
const pin_obj_t *pins[4] = {0};
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
#if defined(MICROPY_HW_UART1_TX) && defined(MICROPY_HW_UART1_RX)
case PYB_UART_1:
uart_unit = 1;
UARTx = USART1;
irqn = USART1_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART1;
GPIO_Port = MICROPY_HW_UART1_PORT;
GPIO_Pin = MICROPY_HW_UART1_PINS;
pins[0] = &MICROPY_HW_UART1_TX;
pins[1] = &MICROPY_HW_UART1_RX;
__USART1_CLK_ENABLE();
break;
#endif
#if defined(MICROPY_HW_UART1_TX_PORT) && \
defined(MICROPY_HW_UART1_TX_PIN) && \
defined(MICROPY_HW_UART1_RX_PORT) && \
defined(MICROPY_HW_UART1_RX_PIN)
case PYB_UART_1:
UARTx = USART1;
irqn = USART1_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART1;
GPIO_Port = MICROPY_HW_UART1_TX_PORT;
GPIO_Pin = MICROPY_HW_UART1_TX_PIN;
GPIO_Port2 = MICROPY_HW_UART1_RX_PORT;
GPIO_Pin2 = MICROPY_HW_UART1_RX_PIN;
__USART1_CLK_ENABLE();
break;
#endif
#if defined(MICROPY_HW_UART2_PORT) && defined(MICROPY_HW_UART2_PINS)
#if defined(MICROPY_HW_UART2_TX) && defined(MICROPY_HW_UART2_RX)
case PYB_UART_2:
uart_unit = 2;
UARTx = USART2;
irqn = USART2_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART2;
GPIO_Port = MICROPY_HW_UART2_PORT;
GPIO_Pin = MICROPY_HW_UART2_PINS;
pins[0] = &MICROPY_HW_UART2_TX;
pins[1] = &MICROPY_HW_UART2_RX;
#if defined(MICROPY_HW_UART2_RTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
GPIO_Pin |= MICROPY_HW_UART2_RTS;
pins[2] = &MICROPY_HW_UART2_RTS;
}
#endif
#if defined(MICROPY_HW_UART2_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
GPIO_Pin |= MICROPY_HW_UART2_CTS;
pins[3] = &MICROPY_HW_UART2_CTS;
}
#endif
__USART2_CLK_ENABLE();
break;
#endif
#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)
#if defined(MICROPY_HW_UART3_TX) && defined(MICROPY_HW_UART3_RX)
case PYB_UART_3:
uart_unit = 3;
UARTx = USART3;
irqn = USART3_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART3;
GPIO_Port = MICROPY_HW_UART3_PORT;
GPIO_Pin = MICROPY_HW_UART3_PINS;
pins[0] = &MICROPY_HW_UART3_TX;
pins[1] = &MICROPY_HW_UART3_RX;
#if defined(MICROPY_HW_UART3_RTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
GPIO_Pin |= MICROPY_HW_UART3_RTS;
pins[2] = &MICROPY_HW_UART3_RTS;
}
#endif
#if defined(MICROPY_HW_UART3_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
GPIO_Pin |= MICROPY_HW_UART3_CTS;
pins[3] = &MICROPY_HW_UART3_CTS;
}
#endif
__USART3_CLK_ENABLE();
break;
#endif
#if defined(UART4) && defined(MICROPY_HW_UART4_PORT) && defined(MICROPY_HW_UART4_PINS)
// UART4 is on PA0/PA1, PC10/PC11
#if defined(MICROPY_HW_UART4_TX) && defined(MICROPY_HW_UART4_RX)
case PYB_UART_4:
uart_unit = 4;
UARTx = UART4;
irqn = UART4_IRQn;
GPIO_AF_UARTx = GPIO_AF8_UART4;
GPIO_Port = MICROPY_HW_UART4_PORT;
GPIO_Pin = MICROPY_HW_UART4_PINS;
pins[0] = &MICROPY_HW_UART4_TX;
pins[1] = &MICROPY_HW_UART4_RX;
__UART4_CLK_ENABLE();
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)
#if defined(MICROPY_HW_UART5_TX) && defined(MICROPY_HW_UART5_RX)
case PYB_UART_5:
uart_unit = 5;
UARTx = UART5;
irqn = UART5_IRQn;
GPIO_AF_UARTx = GPIO_AF8_UART5;
GPIO_Port = MICROPY_HW_UART5_TX_PORT;
GPIO_Port2 = MICROPY_HW_UART5_RX_PORT;
GPIO_Pin = MICROPY_HW_UART5_TX_PIN;
GPIO_Pin2 = MICROPY_HW_UART5_RX_PIN;
pins[0] = &MICROPY_HW_UART5_TX;
pins[1] = &MICROPY_HW_UART5_RX;
__UART5_CLK_ENABLE();
break;
#endif
#if defined(MICROPY_HW_UART6_PORT) && defined(MICROPY_HW_UART6_PINS)
// USART6 is on PC6/PC7 (CK on PC8)
#if defined(MICROPY_HW_UART6_TX) && defined(MICROPY_HW_UART6_RX)
case PYB_UART_6:
uart_unit = 6;
UARTx = USART6;
irqn = USART6_IRQn;
GPIO_AF_UARTx = GPIO_AF8_USART6;
GPIO_Port = MICROPY_HW_UART6_PORT;
GPIO_Pin = MICROPY_HW_UART6_PINS;
pins[0] = &MICROPY_HW_UART6_TX;
pins[1] = &MICROPY_HW_UART6_RX;
__USART6_CLK_ENABLE();
break;
#endif
@ -237,26 +211,21 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
return false;
}
uint32_t mode = MP_HAL_PIN_MODE_ALT;
uint32_t pull = MP_HAL_PIN_PULL_UP;
for (uint i = 0; i < 4; i++) {
if (pins[i] != NULL) {
bool ret = mp_hal_pin_config_alt(pins[i], mode, pull, AF_FN_UART, uart_unit);
if (!ret) {
return false;
}
}
}
uart_obj->irqn = irqn;
uart_obj->uart.Instance = UARTx;
// init GPIO
mp_hal_gpio_clock_enable(GPIO_Port);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_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(GPIO_Port, &GPIO_InitStructure);
// init GPIO for second pin if needed
if (GPIO_Port2 != NULL) {
mp_hal_gpio_clock_enable(GPIO_Port2);
GPIO_InitStructure.Pin = GPIO_Pin2;
HAL_GPIO_Init(GPIO_Port2, &GPIO_InitStructure);
}
// init UARTx
HAL_UART_Init(&uart_obj->uart);