Skip to content

Commit 1775b65

Browse files
committed
stmhal: Remove PYBVxx defines and use config vars for UART/CAN names.
Now all stmhal-based boards can name their peripherals (if they want) to any string.
1 parent 9ae3fc6 commit 1775b65

File tree

7 files changed

+48
-35
lines changed

7 files changed

+48
-35
lines changed

stmhal/boards/PYBV10/mpconfigboard.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define PYBV10
2-
31
#define MICROPY_HW_BOARD_NAME "PYBv1.0"
42
#define MICROPY_HW_MCU_NAME "STM32F405RG"
53
#define MICROPY_PY_SYS_PLATFORM "pyboard"
@@ -29,18 +27,22 @@
2927
#define MICROPY_HW_RTC_USE_LSE (1)
3028

3129
// UART config
30+
#define MICROPY_HW_UART1_NAME "XB"
3231
#define MICROPY_HW_UART1_PORT (GPIOB)
3332
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
3433
#define MICROPY_HW_UART2_PORT (GPIOA)
3534
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
3635
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
3736
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
37+
#define MICROPY_HW_UART3_NAME "YB"
3838
#define MICROPY_HW_UART3_PORT (GPIOB)
3939
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
4040
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
4141
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
42+
#define MICROPY_HW_UART4_NAME "XA"
4243
#define MICROPY_HW_UART4_PORT (GPIOA)
4344
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
45+
#define MICROPY_HW_UART6_NAME "YA"
4446
#define MICROPY_HW_UART6_PORT (GPIOC)
4547
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
4648

@@ -52,6 +54,10 @@
5254
#define MICROPY_HW_I2C2_SCL (pin_B10)
5355
#define MICROPY_HW_I2C2_SDA (pin_B11)
5456

57+
// CAN busses
58+
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
59+
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
60+
5561
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
5662
#define MICROPY_HW_USRSW_PIN (pin_B3)
5763
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)

stmhal/boards/PYBV3/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define PYBV3
2-
31
#define MICROPY_HW_BOARD_NAME "PYBv3"
42
#define MICROPY_HW_MCU_NAME "STM32F405RG"
53

stmhal/boards/PYBV4/mpconfigboard.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#define PYBV4
2-
31
#define MICROPY_HW_BOARD_NAME "PYBv4"
42
#define MICROPY_HW_MCU_NAME "STM32F405RG"
3+
#define MICROPY_PY_SYS_PLATFORM "pyboard"
54

65
#define MICROPY_HW_HAS_SWITCH (1)
76
#define MICROPY_HW_HAS_SDCARD (1)
@@ -28,18 +27,22 @@
2827
#define MICROPY_HW_RTC_USE_LSE (1)
2928

3029
// UART config
30+
#define MICROPY_HW_UART1_NAME "XB"
3131
#define MICROPY_HW_UART1_PORT (GPIOB)
3232
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
3333
#define MICROPY_HW_UART2_PORT (GPIOA)
3434
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
3535
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
3636
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
37+
#define MICROPY_HW_UART3_NAME "YB"
3738
#define MICROPY_HW_UART3_PORT (GPIOB)
3839
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
3940
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
4041
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
42+
#define MICROPY_HW_UART4_NAME "XA"
4143
#define MICROPY_HW_UART4_PORT (GPIOA)
4244
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
45+
#define MICROPY_HW_UART6_NAME "YA"
4346
#define MICROPY_HW_UART6_PORT (GPIOC)
4447
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
4548

@@ -51,6 +54,10 @@
5154
#define MICROPY_HW_I2C2_SCL (pin_B10)
5255
#define MICROPY_HW_I2C2_SDA (pin_B11)
5356

57+
// CAN busses
58+
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
59+
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
60+
5461
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
5562
#define MICROPY_HW_USRSW_PIN (pin_B3)
5663
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)

stmhal/can.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,13 @@ STATIC mp_obj_t pyb_can_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
352352
if (MP_OBJ_IS_STR(args[0])) {
353353
const char *port = mp_obj_str_get_str(args[0]);
354354
if (0) {
355-
#if defined(PYBV10)
356-
} else if (strcmp(port, "YA") == 0) {
357-
o->can_id = PYB_CAN_YA;
358-
} else if (strcmp(port, "YB") == 0) {
359-
o->can_id = PYB_CAN_YB;
355+
#ifdef MICROPY_HW_CAN1_NAME
356+
} else if (strcmp(port, MICROPY_HW_CAN1_NAME) == 0) {
357+
o->can_id = PYB_CAN_1;
358+
#endif
359+
#ifdef MICROPY_HW_CAN2_NAME
360+
} else if (strcmp(port, MICROPY_HW_CAN2_NAME) == 0) {
361+
o->can_id = PYB_CAN_2;
360362
#endif
361363
} else {
362364
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN port %s does not exist", port));

stmhal/can.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
#define PYB_CAN_1 (1)
2828
#define PYB_CAN_2 (2)
2929

30-
// aliases for pyboard
31-
#if defined(PYBV10)
32-
#define PYB_CAN_YA PYB_CAN_1 // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
33-
#define PYB_CAN_YB PYB_CAN_2 // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
34-
#endif
35-
3630
extern const mp_obj_type_t pyb_can_type;
3731

3832
void can_init0(void);

stmhal/uart.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,30 @@ STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t
504504
if (MP_OBJ_IS_STR(args[0])) {
505505
const char *port = mp_obj_str_get_str(args[0]);
506506
if (0) {
507-
#if defined(PYBV10)
508-
} else if (strcmp(port, "XA") == 0) {
509-
uart_id = PYB_UART_XA;
510-
} else if (strcmp(port, "XB") == 0) {
511-
uart_id = PYB_UART_XB;
512-
} else if (strcmp(port, "YA") == 0) {
513-
uart_id = PYB_UART_YA;
514-
} else if (strcmp(port, "YB") == 0) {
515-
uart_id = PYB_UART_YB;
516-
#endif
507+
#ifdef MICROPY_HW_UART1_NAME
508+
} else if (strcmp(port, MICROPY_HW_UART1_NAME) == 0) {
509+
uart_id = PYB_UART_1;
510+
#endif
511+
#ifdef MICROPY_HW_UART2_NAME
512+
} else if (strcmp(port, MICROPY_HW_UART2_NAME) == 0) {
513+
uart_id = PYB_UART_2;
514+
#endif
515+
#ifdef MICROPY_HW_UART3_NAME
516+
} else if (strcmp(port, MICROPY_HW_UART3_NAME) == 0) {
517+
uart_id = PYB_UART_3;
518+
#endif
519+
#ifdef MICROPY_HW_UART4_NAME
520+
} else if (strcmp(port, MICROPY_HW_UART4_NAME) == 0) {
521+
uart_id = PYB_UART_4;
522+
#endif
523+
#ifdef MICROPY_HW_UART5_NAME
524+
} else if (strcmp(port, MICROPY_HW_UART5_NAME) == 0) {
525+
uart_id = PYB_UART_5;
526+
#endif
527+
#ifdef MICROPY_HW_UART6_NAME
528+
} else if (strcmp(port, MICROPY_HW_UART6_NAME) == 0) {
529+
uart_id = PYB_UART_6;
530+
#endif
517531
} else {
518532
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) does not exist", port));
519533
}

stmhal/uart.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ typedef enum {
3232
PYB_UART_4 = 4,
3333
PYB_UART_5 = 5,
3434
PYB_UART_6 = 6,
35-
36-
#if defined(PYBV10)
37-
PYB_UART_XA = 4, // UART4 on X1, X2 = PA0, PA1
38-
PYB_UART_XB = 1, // USART1 on X9, X10 = PB6, PB7
39-
PYB_UART_YA = 6, // USART6 on Y1, Y2 = PC6, PC7
40-
PYB_UART_YB = 3, // USART3 on Y9, Y10 = PB10, PB11
41-
#endif
42-
4335
} pyb_uart_t;
4436

4537
typedef struct _pyb_uart_obj_t pyb_uart_obj_t;

0 commit comments

Comments
 (0)