Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add uart sanity checks for stm32 boards starting with creality v4 boards #24795

Merged
Merged
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
97 changes: 96 additions & 1 deletion Marlin/src/pins/pinsDebug_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,9 @@
#if PIN_EXISTS(FET_SAFETY)
REPORT_NAME_DIGITAL(__LINE__, FET_SAFETY_PIN)
#endif

// Touch Interface Pins

#if PIN_EXISTS(TOUCH_MISO)
REPORT_NAME_DIGITAL(__LINE__, TOUCH_MISO_PIN)
#endif
Expand All @@ -1844,27 +1847,45 @@
#if PIN_EXISTS(TOUCH_INT)
REPORT_NAME_DIGITAL(__LINE__, TOUCH_INT_PIN)
#endif

// USB CS/Interrupt Pins

#if PIN_EXISTS(USB_CS)
REPORT_NAME_DIGITAL(__LINE__, USB_CS_PIN)
#endif
#if PIN_EXISTS(USB_INTR)
REPORT_NAME_DIGITAL(__LINE__, USB_INTR_PIN)
#endif

// MMU2 Reset Pin

#if PIN_EXISTS(MMU2_RST)
REPORT_NAME_DIGITAL(__LINE__, MMU2_RST_PIN)
#endif

// Backlash / Position / Hotend Offset Calibration Pin

#if PIN_EXISTS(CALIBRATION)
REPORT_NAME_DIGITAL(__LINE__, CALIBRATION_PIN)
#endif

// Smart Effector

#if PIN_EXISTS(SMART_EFFECTOR_MOD)
REPORT_NAME_DIGITAL(__LINE__, SMART_EFFECTOR_MOD_PIN)
#endif

// Closed Loop

#if PIN_EXISTS(CLOSED_LOOP_ENABLE)
REPORT_NAME_DIGITAL(__LINE__, CLOSED_LOOP_ENABLE_PIN)
#endif
#if PIN_EXISTS(CLOSED_LOOP_MOVE_COMPLETE)
REPORT_NAME_DIGITAL(__LINE__, CLOSED_LOOP_MOVE_COMPLETE_PIN)
#endif

// ESP WiFi Pins

#if PIN_EXISTS(ESP_WIFI_MODULE_RESET)
REPORT_NAME_DIGITAL(__LINE__, ESP_WIFI_MODULE_RESET_PIN)
#endif
Expand All @@ -1877,7 +1898,9 @@
#if PIN_EXISTS(ESP_WIFI_MODULE_GPIO2)
REPORT_NAME_DIGITAL(__LINE__, ESP_WIFI_MODULE_GPIO2_PIN)
#endif
// TFT PINS

// TFT Pins

#if PIN_EXISTS(TFT_CS)
REPORT_NAME_DIGITAL(__LINE__, TFT_CS_PIN)
#endif
Expand All @@ -1896,3 +1919,75 @@
#if PIN_EXISTS(TFT_RESET)
REPORT_NAME_DIGITAL(__LINE__, TFT_RESET_PIN)
#endif

// Hardware UART Pins

#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 pins

#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
23 changes: 23 additions & 0 deletions Marlin/src/pins/stm32f1/pins_CREALITY_V4.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,26 @@
#define NEOPIXEL_PIN PA13

#endif

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

// Hardware UART pins
#define UART1_TX_PIN PA9 // default use CH340 RX
#define UART1_RX_PIN PA10 // default use CH340 TX
#define UART2_TX_PIN PA2 // default use HEATER_BED_PIN
#define UART2_RX_PIN PA3 // not connected
#define UART3_TX_PIN PB10 // default use LCD connector
#define UART3_RX_PIN PB11 // default use LCD connector
#define UART4_TX_PIN PC10 // default use sdcard SDIO_D2
#define UART4_RX_PIN PC11 // default use sdcard SDIO_D3
#define UART5_TX_PIN PC12 // default use sdcard SDIO_CK
#define UART5_RX_PIN PD2 // default use sdcard SDIO_CMD
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

// 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