Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 2378be4

Browse files
rambodpgeorge
authored andcommitted
stmhal: Allow to configure UART pins completely via mpconfigboard.h.
1 parent 8c8d7f3 commit 2378be4

File tree

9 files changed

+153
-37
lines changed

9 files changed

+153
-37
lines changed

stmhal/boards/CERB40/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
2626
#define MICROPY_HW_CLK_PLLQ (7)
2727

28+
// UART config
29+
#define MICROPY_HW_UART1_PORT (GPIOA)
30+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
31+
#define MICROPY_HW_UART2_PORT (GPIOA)
32+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
33+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
34+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
35+
#define MICROPY_HW_UART3_PORT (GPIOD)
36+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
37+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
38+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
39+
#define MICROPY_HW_UART4_PORT (GPIOA)
40+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
41+
#define MICROPY_HW_UART6_PORT (GPIOC)
42+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
43+
2844
// I2C busses
2945
#define MICROPY_HW_I2C1_SCL (pin_B6)
3046
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/boards/ESPRUINO_PICO/mpconfigboard.h

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
// does not have a 32kHz crystal
2727
#define MICROPY_HW_RTC_USE_LSE (0)
2828

29+
// UART config
30+
#define MICROPY_HW_UART1_PORT (GPIOB)
31+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
32+
#define MICROPY_HW_UART2_PORT (GPIOA)
33+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
34+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
35+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
36+
#define MICROPY_HW_UART6_PORT (GPIOA)
37+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_11 | GPIO_PIN_12)
38+
2939
// I2C busses
3040
#define MICROPY_HW_I2C1_SCL (pin_B6)
3141
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/boards/HYDRABUS/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
2525
#define MICROPY_HW_CLK_PLLQ (7)
2626

27+
// UART config
28+
#define MICROPY_HW_UART1_PORT (GPIOA)
29+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
30+
#define MICROPY_HW_UART2_PORT (GPIOA)
31+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
32+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
33+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
34+
#define MICROPY_HW_UART3_PORT (GPIOD)
35+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
36+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
37+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
38+
#define MICROPY_HW_UART4_PORT (GPIOA)
39+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
40+
#define MICROPY_HW_UART6_PORT (GPIOC)
41+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
42+
2743
// I2C busses
2844
#define MICROPY_HW_I2C1_SCL (pin_B6)
2945
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
2929
#define MICROPY_HW_CLK_PLLQ (7)
3030

31+
// UART config
32+
#define MICROPY_HW_UART1_PORT (GPIOA)
33+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
34+
#define MICROPY_HW_UART2_PORT (GPIOA)
35+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
36+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
37+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
38+
#define MICROPY_HW_UART3_PORT (GPIOD)
39+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
40+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
41+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
42+
#define MICROPY_HW_UART4_PORT (GPIOA)
43+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
44+
#define MICROPY_HW_UART6_PORT (GPIOC)
45+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
46+
3147
// I2C busses
3248
#define MICROPY_HW_I2C2_SCL (pin_B10)
3349
#define MICROPY_HW_I2C2_SDA (pin_B11)

stmhal/boards/PYBV10/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828
// The pyboard has a 32kHz crystal for the RTC
2929
#define MICROPY_HW_RTC_USE_LSE (1)
3030

31+
// UART config
32+
#define MICROPY_HW_UART1_PORT (GPIOB)
33+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
34+
#define MICROPY_HW_UART2_PORT (GPIOA)
35+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
36+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
37+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
38+
#define MICROPY_HW_UART3_PORT (GPIOB)
39+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
40+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
41+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
42+
#define MICROPY_HW_UART4_PORT (GPIOA)
43+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
44+
#define MICROPY_HW_UART6_PORT (GPIOC)
45+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
46+
3147
// X-skin: X9=PB6=SCL, X10=PB7=SDA
3248
#define MICROPY_HW_I2C1_SCL (pin_B6)
3349
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/boards/PYBV3/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@
2727
// The pyboard has a 32kHz crystal for the RTC
2828
#define MICROPY_HW_RTC_USE_LSE (1)
2929

30+
// UART config
31+
#define MICROPY_HW_UART1_PORT (GPIOA)
32+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
33+
#define MICROPY_HW_UART2_PORT (GPIOA)
34+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
35+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
36+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
37+
#define MICROPY_HW_UART3_PORT (GPIOB)
38+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
39+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
40+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
41+
#define MICROPY_HW_UART4_PORT (GPIOA)
42+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
43+
#define MICROPY_HW_UART6_PORT (GPIOC)
44+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
45+
3046
// X-skin: X9=PB6=SCL, X10=PB7=SDA
3147
#define MICROPY_HW_I2C1_SCL (pin_B6)
3248
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/boards/PYBV4/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@
2727
// The pyboard has a 32kHz crystal for the RTC
2828
#define MICROPY_HW_RTC_USE_LSE (1)
2929

30+
// UART config
31+
#define MICROPY_HW_UART1_PORT (GPIOB)
32+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
33+
#define MICROPY_HW_UART2_PORT (GPIOA)
34+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
35+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
36+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
37+
#define MICROPY_HW_UART3_PORT (GPIOB)
38+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
39+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
40+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
41+
#define MICROPY_HW_UART4_PORT (GPIOA)
42+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
43+
#define MICROPY_HW_UART6_PORT (GPIOC)
44+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
45+
3046
// X-skin: X9=PB6=SCL, X10=PB7=SDA
3147
#define MICROPY_HW_I2C1_SCL (pin_B6)
3248
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/boards/STM32F4DISC/mpconfigboard.h

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
2525
#define MICROPY_HW_CLK_PLLQ (7)
2626

27+
// UART config
28+
#define MICROPY_HW_UART1_PORT (GPIOA)
29+
#define MICROPY_HW_UART1_PINS (GPIO_PIN_9 | GPIO_PIN_10)
30+
#define MICROPY_HW_UART2_PORT (GPIOA)
31+
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
32+
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
33+
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
34+
#define MICROPY_HW_UART3_PORT (GPIOD)
35+
#define MICROPY_HW_UART3_PINS (GPIO_PIN_8 | GPIO_PIN_9)
36+
#define MICROPY_HW_UART3_RTS (GPIO_PIN_12)
37+
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
38+
#define MICROPY_HW_UART4_PORT (GPIOA)
39+
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
40+
#define MICROPY_HW_UART6_PORT (GPIOC)
41+
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
42+
2743
// I2C busses
2844
#define MICROPY_HW_I2C1_SCL (pin_B6)
2945
#define MICROPY_HW_I2C1_SDA (pin_B7)

stmhal/uart.c

+31-37
Original file line numberDiff line numberDiff line change
@@ -117,94 +117,88 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
117117
GPIO_TypeDef* GPIO_Port = NULL;
118118

119119
switch (uart_obj->uart_id) {
120+
#if defined(MICROPY_HW_UART1_PORT) && defined(MICROPY_HW_UART1_PINS)
120121
// USART1 is on PA9/PA10 (CK on PA8), PB6/PB7
121122
case PYB_UART_1:
122123
UARTx = USART1;
123124
irqn = USART1_IRQn;
124125
GPIO_AF_UARTx = GPIO_AF7_USART1;
125-
126-
#if defined (PYBV4) || defined(PYBV10)
127-
GPIO_Port = GPIOB;
128-
GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7;
129-
#else
130-
GPIO_Port = GPIOA;
131-
GPIO_Pin = GPIO_PIN_9 | GPIO_PIN_10;
132-
#endif
133-
126+
GPIO_Port = MICROPY_HW_UART1_PORT;
127+
GPIO_Pin = MICROPY_HW_UART1_PINS;
134128
__USART1_CLK_ENABLE();
135129
break;
130+
#endif
136131

132+
#if defined(MICROPY_HW_UART2_PORT) && defined(MICROPY_HW_UART2_PINS)
137133
// USART2 is on PA2/PA3 (CTS,RTS,CK on PA0,PA1,PA4), PD5/PD6 (CK on PD7)
138134
case PYB_UART_2:
139135
UARTx = USART2;
140136
irqn = USART2_IRQn;
141137
GPIO_AF_UARTx = GPIO_AF7_USART2;
142-
143-
GPIO_Port = GPIOA;
144-
GPIO_Pin = GPIO_PIN_2 | GPIO_PIN_3;
145-
138+
GPIO_Port = MICROPY_HW_UART2_PORT;
139+
GPIO_Pin = MICROPY_HW_UART2_PINS;
140+
#if defined(MICROPY_HW_UART2_RTS)
146141
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
147-
GPIO_Pin |= GPIO_PIN_1;
142+
GPIO_Pin |= MICROPY_HW_UART2_RTS;
148143
}
144+
#endif
145+
#if defined(MICROPY_HW_UART2_CTS)
149146
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
150-
GPIO_Pin |= GPIO_PIN_0;
147+
GPIO_Pin |= MICROPY_HW_UART2_CTS;
151148
}
152-
149+
#endif
153150
__USART2_CLK_ENABLE();
154151
break;
152+
#endif
155153

156-
#if defined(USART3)
154+
#if defined(USART3) && defined(MICROPY_HW_UART3_PORT) && defined(MICROPY_HW_UART3_PINS)
157155
// USART3 is on PB10/PB11 (CK,CTS,RTS on PB12,PB13,PB14), PC10/PC11 (CK on PC12), PD8/PD9 (CK on PD10)
158156
case PYB_UART_3:
159157
UARTx = USART3;
160158
irqn = USART3_IRQn;
161159
GPIO_AF_UARTx = GPIO_AF7_USART3;
162-
163-
#if defined(PYBV3) || defined(PYBV4) | defined(PYBV10)
164-
GPIO_Port = GPIOB;
165-
GPIO_Pin = GPIO_PIN_10 | GPIO_PIN_11;
166-
160+
GPIO_Port = MICROPY_HW_UART3_PORT;
161+
GPIO_Pin = MICROPY_HW_UART3_PINS;
162+
#if defined(MICROPY_HW_UART3_RTS)
167163
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
168-
GPIO_Pin |= GPIO_PIN_14;
164+
GPIO_Pin |= MICROPY_HW_UART3_RTS;
169165
}
166+
#endif
167+
#if defined(MICROPY_HW_UART3_CTS)
170168
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
171-
GPIO_Pin |= GPIO_PIN_13;
169+
GPIO_Pin |= MICROPY_HW_UART3_CTS;
172170
}
173-
#else
174-
GPIO_Port = GPIOD;
175-
GPIO_Pin = GPIO_PIN_8 | GPIO_PIN_9;
176-
#endif
171+
#endif
177172
__USART3_CLK_ENABLE();
178173
break;
179174
#endif
180175

181-
#if defined(UART4)
176+
#if defined(UART4) && defined(MICROPY_HW_UART4_PORT) && defined(MICROPY_HW_UART4_PINS)
182177
// UART4 is on PA0/PA1, PC10/PC11
183178
case PYB_UART_4:
184179
UARTx = UART4;
185180
irqn = UART4_IRQn;
186181
GPIO_AF_UARTx = GPIO_AF8_UART4;
187-
188-
GPIO_Port = GPIOA;
189-
GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1;
190-
182+
GPIO_Port = MICROPY_HW_UART4_PORT;
183+
GPIO_Pin = MICROPY_HW_UART4_PINS;
191184
__UART4_CLK_ENABLE();
192185
break;
193186
#endif
194187

188+
#if defined(MICROPY_HW_UART6_PORT) && defined(MICROPY_HW_UART6_PINS)
195189
// USART6 is on PC6/PC7 (CK on PC8)
196190
case PYB_UART_6:
197191
UARTx = USART6;
198192
irqn = USART6_IRQn;
199193
GPIO_AF_UARTx = GPIO_AF8_USART6;
200-
201-
GPIO_Port = GPIOC;
202-
GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7;
203-
194+
GPIO_Port = MICROPY_HW_UART6_PORT;
195+
GPIO_Pin = MICROPY_HW_UART6_PINS;
204196
__USART6_CLK_ENABLE();
205197
break;
198+
#endif
206199

207200
default:
201+
// UART does not exist or is not configured for this board
208202
return false;
209203
}
210204

0 commit comments

Comments
 (0)