Skip to content

Commit

Permalink
🔧 Some STM32 UART Sanity Checks (MarlinFirmware#24795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellensp authored and thinkyhead committed Dec 16, 2022
1 parent 682a9b6 commit 4d9bf91
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@
#endif

/**
* Automatic backlash, position and hotend offset calibration
* Automatic backlash, position, and hotend offset calibration
*
* Enable G425 to run automatic calibration using an electrically-
* conductive cube, bolt, or washer mounted on the bed.
Expand Down
16 changes: 9 additions & 7 deletions Marlin/src/HAL/AVR/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
#if SERIAL_IN_USE(0)
// D0-D1. No known conflicts.
#endif
#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__)
#if SERIAL_IN_USE(1) && (CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19))
#error "Serial Port 1 pin D18 and/or D19 conflicts with another pin on the board."
#endif
#else
#if SERIAL_IN_USE(1) && (CHECK_SERIAL_PIN(10) || CHECK_SERIAL_PIN(11))
#error "Serial Port 1 pin D10 and/or D11 conflicts with another pin on the board."
#if SERIAL_IN_USE(1)
#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__)
#if CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19)
#error "Serial Port 1 pin D18 and/or D19 conflicts with another pin on the board."
#endif
#else
#if CHECK_SERIAL_PIN(10) || CHECK_SERIAL_PIN(11)
#error "Serial Port 1 pin D10 and/or D11 conflicts with another pin on the board."
#endif
#endif
#endif
#if SERIAL_IN_USE(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17))
Expand Down
59 changes: 59 additions & 0 deletions Marlin/src/HAL/STM32/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,62 @@
#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) && NOT_TARGET(STM32H7xx, STM32F4xx, STM32F1xx)
#error "TFT_COLOR_UI, TFT_LVGL_UI and TFT_CLASSIC_UI are currently only supported on STM32H7, STM32F4 and STM32F1 hardware."
#endif

/**
* Check for common serial pin conflicts
*/
#define _CHECK_SERIAL_PIN(N) (( \
BTN_EN1 == N || DOGLCD_CS == N || HEATER_BED_PIN == N || FAN_PIN == N || \
SDIO_D2_PIN == N || SDIO_D3_PIN == N || SDIO_CK_PIN == N || SDIO_CMD_PIN == N \
))
#define CHECK_SERIAL_PIN(T,N) defined(UART##N##_##T##_PIN) && _CHECK_SERIAL_PIN(UART##N##_##T##_PIN)
#if SERIAL_IN_USE(1)
#if CHECK_SERIAL_PIN(TX,1)
#error "Serial Port 1 TX IO pins conflict with another pin on the board."
#endif
#if CHECK_SERIAL_PIN(RX,1)
#error "Serial Port 1 RX IO pins conflict with another pin on the board."
#endif
#endif
#if SERIAL_IN_USE(2)
#if CHECK_SERIAL_PIN(TX,2)
#error "Serial Port 2 TX IO pins conflict with another pin on the board."
#endif
#if CHECK_SERIAL_PIN(RX,2)
#error "Serial Port 2 RX IO pins conflict with another pin on the board."
#endif
#endif
#if SERIAL_IN_USE(3)
#if CHECK_SERIAL_PIN(TX,3)
#error "Serial Port 3 TX IO pins conflict with another pin on the board."
#endif
#if CHECK_SERIAL_PIN(RX,3)
#error "Serial Port 3 RX IO pins conflict with another pin on the board."
#endif
#endif
#if SERIAL_IN_USE(4)
#if CHECK_SERIAL_PIN(TX,4)
#error "Serial Port 4 TX IO pins conflict with another pin on the board."
#endif
#if CHECK_SERIAL_PIN(RX,4)
#error "Serial Port 4 RX IO pins conflict with another pin on the board."
#endif
#endif
#if SERIAL_IN_USE(5)
#if CHECK_SERIAL_PIN(TX,5)
#error "Serial Port 5 TX IO pins conflict with another pin on the board."
#endif
#if CHECK_SERIAL_PIN(RX,5)
#error "Serial Port 5 RX IO pins conflict with another pin on the board."
#endif
#endif
#if SERIAL_IN_USE(6)
#if CHECK_SERIAL_PIN(TX,6)
#error "Serial Port 6 TX IO pins conflict with another pin on the board."
#endif
#if CHECK_SERIAL_PIN(RX,6)
#error "Serial Port 6 RX IO pins conflict with another pin on the board."
#endif
#endif
#undef CHECK_SERIAL_PIN
#undef _CHECK_SERIAL_PIN
10 changes: 5 additions & 5 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2446,11 +2446,11 @@
//

// Flag the indexed hardware serial ports in use
#define SERIAL_IN_USE(N) ( (defined(SERIAL_PORT) && SERIAL_PORT == N) \
|| (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == N) \
|| (defined(SERIAL_PORT_3) && SERIAL_PORT_3 == N) \
|| (defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == N) \
|| (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == N) )
#define SERIAL_IN_USE(N) ( (defined(SERIAL_PORT) && N == SERIAL_PORT) \
|| (defined(SERIAL_PORT_2) && N == SERIAL_PORT_2) \
|| (defined(SERIAL_PORT_3) && N == SERIAL_PORT_3) \
|| (defined(MMU2_SERIAL_PORT) && N == MMU2_SERIAL_PORT) \
|| (defined(LCD_SERIAL_PORT) && N == LCD_SERIAL_PORT) )

// Flag the named hardware serial ports in use
#define TMC_UART_IS(A,N) (defined(A##_HARDWARE_SERIAL) && (CAT(HW_,A##_HARDWARE_SERIAL) == HW_Serial##N || CAT(HW_,A##_HARDWARE_SERIAL) == HW_MSerial##N))
Expand Down
74 changes: 74 additions & 0 deletions Marlin/src/pins/pinsDebug_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,80 @@
REPORT_NAME_DIGITAL(__LINE__, TFT_RESET_PIN)
#endif

//
// Hardware UART
//
#if SERIAL_IN_USE(1)
#if PIN_EXISTS(UART1_TX)
REPORT_NAME_DIGITAL(__LINE__, UART1_TX_PIN)
#endif
#if PIN_EXISTS(UART1_RX)
REPORT_NAME_DIGITAL(__LINE__, UART1_RX_PIN)
#endif
#endif
#if SERIAL_IN_USE(2)
#if PIN_EXISTS(UART2_TX)
REPORT_NAME_DIGITAL(__LINE__, UART2_TX_PIN)
#endif
#if PIN_EXISTS(UART2_RX)
REPORT_NAME_DIGITAL(__LINE__, UART2_RX_PIN)
#endif
#endif
#if SERIAL_IN_USE(3)
#if PIN_EXISTS(UART3_TX)
REPORT_NAME_DIGITAL(__LINE__, UART3_TX_PIN)
#endif
#if PIN_EXISTS(UART3_RX)
REPORT_NAME_DIGITAL(__LINE__, UART3_RX_PIN)
#endif
#endif
#if SERIAL_IN_USE(4)
#if PIN_EXISTS(UART4_TX)
REPORT_NAME_DIGITAL(__LINE__, UART4_TX_PIN)
#endif
#if PIN_EXISTS(UART4_RX)
REPORT_NAME_DIGITAL(__LINE__, UART4_RX_PIN)
#endif
#endif
#if SERIAL_IN_USE(5)
#if PIN_EXISTS(UART5_TX)
REPORT_NAME_DIGITAL(__LINE__, UART5_TX_PIN)
#endif
#if PIN_EXISTS(UART5_RX)
REPORT_NAME_DIGITAL(__LINE__, UART5_RX_PIN)
#endif
#endif
#if SERIAL_IN_USE(6)
#if PIN_EXISTS(UART6_TX)
REPORT_NAME_DIGITAL(__LINE__, UART6_TX_PIN)
#endif
#if PIN_EXISTS(UART6_RX)
REPORT_NAME_DIGITAL(__LINE__, UART6_RX_PIN)
#endif
#endif

//
// SDIO
//
#if PIN_EXISTS(SDIO_D0)
REPORT_NAME_DIGITAL(__LINE__, SDIO_D0_PIN)
#endif
#if PIN_EXISTS(SDIO_D1)
REPORT_NAME_DIGITAL(__LINE__, SDIO_D1_PIN)
#endif
#if PIN_EXISTS(SDIO_D2)
REPORT_NAME_DIGITAL(__LINE__, SDIO_D2_PIN)
#endif
#if PIN_EXISTS(SDIO_D3)
REPORT_NAME_DIGITAL(__LINE__, SDIO_D3_PIN)
#endif
#if PIN_EXISTS(SDIO_CK)
REPORT_NAME_DIGITAL(__LINE__, SDIO_CK_PIN)
#endif
#if PIN_EXISTS(SDIO_CMD)
REPORT_NAME_DIGITAL(__LINE__, SDIO_CMD_PIN)
#endif

//
// Miscellaneous
//
Expand Down
55 changes: 39 additions & 16 deletions Marlin/src/pins/stm32f1/pins_CREALITY_V4.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@
* GND | 9 10 | 5V
* ------
*/
#define EXP3_01_PIN PC6
#define EXP3_02_PIN PB2
#define EXP3_03_PIN PB10
#define EXP3_04_PIN PB11
#define EXP3_05_PIN PB14
#define EXP3_06_PIN PB13
#define EXP3_07_PIN PB12
#define EXP3_08_PIN PB15
#define EXP3_01_PIN PC6
#define EXP3_02_PIN PB2
#define EXP3_03_PIN PB10
#define EXP3_04_PIN PB11
#define EXP3_05_PIN PB14
#define EXP3_06_PIN PB13
#define EXP3_07_PIN PB12
#define EXP3_08_PIN PB15

#elif EITHER(VET6_12864_LCD, DWIN_VET6_CREALITY_LCD)

Expand All @@ -194,14 +194,14 @@
* GND | 9 10 | 5V
* ------
*/
#define EXP3_01_PIN -1
#define EXP3_02_PIN PC5
#define EXP3_03_PIN PB10
#define EXP3_04_PIN -1
#define EXP3_05_PIN PA6
#define EXP3_06_PIN PA5
#define EXP3_07_PIN PA4
#define EXP3_08_PIN PA7
#define EXP3_01_PIN -1
#define EXP3_02_PIN PC5
#define EXP3_03_PIN PB10
#define EXP3_04_PIN -1
#define EXP3_05_PIN PA6
#define EXP3_06_PIN PA5
#define EXP3_07_PIN PA4
#define EXP3_08_PIN PA7

#elif EITHER(CR10_STOCKDISPLAY, FYSETC_MINI_12864_2_1)
#error "Define RET6_12864_LCD or VET6_12864_LCD to select pins for the LCD with the Creality V4 controller."
Expand Down Expand Up @@ -283,3 +283,26 @@
#define NEOPIXEL_PIN PA13

#endif

// Pins for documentation and sanity checks only.
// Changing these will not change the pin they are on.

// Hardware UART pins
#define UART1_TX_PIN PA9 // default uses CH340 RX
#define UART1_RX_PIN PA10 // default uses CH340 TX
#define UART2_TX_PIN PA2 // default uses HEATER_BED_PIN
#define UART2_RX_PIN PA3 // not connected
#define UART3_TX_PIN PB10 // default uses LCD connector
#define UART3_RX_PIN PB11 // default uses LCD connector
#define UART4_TX_PIN PC10 // default uses sdcard SDIO_D2
#define UART4_RX_PIN PC11 // default uses sdcard SDIO_D3
#define UART5_TX_PIN PC12 // default uses sdcard SDIO_CK
#define UART5_RX_PIN PD2 // default uses sdcard SDIO_CMD

// SDIO pins
#define SDIO_D0_PIN PC8
#define SDIO_D1_PIN PC9
#define SDIO_D2_PIN PC10
#define SDIO_D3_PIN PC11
#define SDIO_CK_PIN PC12
#define SDIO_CMD_PIN PD2

0 comments on commit 4d9bf91

Please sign in to comment.