From e298266eff9a53dd0bdddf5488135681d09baa77 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 17 Oct 2022 21:41:22 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20CONF=5FSERIAL=5FIS=20=3D>=20SERI?= =?UTF-8?q?AL=5FIN=5FUSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/AVR/inc/SanityCheck.h | 10 +++++----- Marlin/src/HAL/DUE/inc/SanityCheck.h | 8 ++++---- Marlin/src/HAL/STM32/eeprom_flash.cpp | 18 ++++++++++-------- Marlin/src/inc/Conditionals_post.h | 6 +++--- Marlin/src/pins/pinsDebug.h | 16 ++++++++-------- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h index 89425ca853..411b0198f1 100644 --- a/Marlin/src/HAL/AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h @@ -37,22 +37,22 @@ || X_ENA_PIN == N || Y_ENA_PIN == N || Z_ENA_PIN == N \ || BTN_EN1 == N || BTN_EN2 == N \ ) -#if CONF_SERIAL_IS(0) +#if SERIAL_IN_USE(0) // D0-D1. No known conflicts. #endif #if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__) - #if CONF_SERIAL_IS(1) && (CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19)) + #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 CONF_SERIAL_IS(1) && (CHECK_SERIAL_PIN(10) || CHECK_SERIAL_PIN(11)) + #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." #endif #endif -#if CONF_SERIAL_IS(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17)) +#if SERIAL_IN_USE(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17)) #error "Serial Port 2 pin D16 and/or D17 conflicts with another pin on the board." #endif -#if CONF_SERIAL_IS(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15)) +#if SERIAL_IN_USE(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15)) #error "Serial Port 3 pin D14 and/or D15 conflicts with another pin on the board." #endif #undef CHECK_SERIAL_PIN diff --git a/Marlin/src/HAL/DUE/inc/SanityCheck.h b/Marlin/src/HAL/DUE/inc/SanityCheck.h index 13484f7029..1f5acc360c 100644 --- a/Marlin/src/HAL/DUE/inc/SanityCheck.h +++ b/Marlin/src/HAL/DUE/inc/SanityCheck.h @@ -36,15 +36,15 @@ || X_DIR_PIN == N || Y_DIR_PIN == N || Z_DIR_PIN == N \ || X_ENA_PIN == N || Y_ENA_PIN == N || Z_ENA_PIN == N \ ) -#if CONF_SERIAL_IS(0) // D0-D1. No known conflicts. +#if SERIAL_IN_USE(0) // D0-D1. No known conflicts. #endif -#if CONF_SERIAL_IS(1) && (CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19)) +#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 -#if CONF_SERIAL_IS(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17)) +#if SERIAL_IN_USE(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17)) #error "Serial Port 2 pin D16 and/or D17 conflicts with another pin on the board." #endif -#if CONF_SERIAL_IS(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15)) +#if SERIAL_IN_USE(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15)) #error "Serial Port 3 pin D14 and/or D15 conflicts with another pin on the board." #endif #undef CHECK_SERIAL_PIN diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp index 7c8cc8dd21..78db07c6c0 100644 --- a/Marlin/src/HAL/STM32/eeprom_flash.cpp +++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp @@ -95,7 +95,7 @@ static_assert(IS_FLASH_SECTOR(FLASH_SECTOR), "FLASH_SECTOR is invalid"); static_assert(IS_POWER_OF_2(FLASH_UNIT_SIZE), "FLASH_UNIT_SIZE should be a power of 2, please check your chip's spec sheet"); -#endif +#endif // FLASH_EEPROM_LEVELING static bool eeprom_data_written = false; @@ -189,15 +189,15 @@ bool PersistentStore::access_finish() { UNLOCK_FLASH(); - uint32_t offset = 0; - uint32_t address = SLOT_ADDRESS(current_slot); - uint32_t address_end = address + MARLIN_EEPROM_SIZE; - uint32_t data = 0; + uint32_t offset = 0, + address = SLOT_ADDRESS(current_slot), + address_end = address + MARLIN_EEPROM_SIZE, + data = 0; bool success = true; while (address < address_end) { - memcpy(&data, ram_eeprom + offset, sizeof(uint32_t)); + memcpy(&data, ram_eeprom + offset, sizeof(data)); status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data); if (status == HAL_OK) { address += sizeof(uint32_t); @@ -221,7 +221,8 @@ bool PersistentStore::access_finish() { return success; - #else + #else !FLASH_EEPROM_LEVELING + // The following was written for the STM32F4 but may work with other MCUs as well. // Most STM32F4 flash does not allow reading from flash during erase operations. // This takes about a second on a STM32F407 with a 128kB sector used as EEPROM. @@ -235,7 +236,8 @@ bool PersistentStore::access_finish() { TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT()); eeprom_data_written = false; - #endif + + #endif // !FLASH_EEPROM_LEVELING } return true; diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 90ed750d4a..bb9a1ac640 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2446,7 +2446,7 @@ // // Flag the indexed hardware serial ports in use -#define CONF_SERIAL_IS(N) ( (defined(SERIAL_PORT) && SERIAL_PORT == N) \ +#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) \ @@ -2454,7 +2454,7 @@ // 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)) -#define ANY_SERIAL_IS(N) ( CONF_SERIAL_IS(N) \ +#define ANY_SERIAL_IS(N) ( SERIAL_IN_USE(N) \ || TMC_UART_IS(X, N) || TMC_UART_IS(Y , N) || TMC_UART_IS(Z , N) \ || TMC_UART_IS(I, N) || TMC_UART_IS(J , N) || TMC_UART_IS(K , N) \ || TMC_UART_IS(U, N) || TMC_UART_IS(V , N) || TMC_UART_IS(W , N) \ @@ -2481,7 +2481,7 @@ #define HW_MSerial9 518 #define HW_MSerial10 519 -#if CONF_SERIAL_IS(-1) +#if SERIAL_IN_USE(-1) #define USING_HW_SERIALUSB 1 #endif #if ANY_SERIAL_IS(0) diff --git a/Marlin/src/pins/pinsDebug.h b/Marlin/src/pins/pinsDebug.h index b662f09ba9..b938496915 100644 --- a/Marlin/src/pins/pinsDebug.h +++ b/Marlin/src/pins/pinsDebug.h @@ -49,19 +49,19 @@ // manually add pins that have names that are macros which don't play well with these macros #if ANY(AVR_ATmega2560_FAMILY, AVR_ATmega1284_FAMILY, ARDUINO_ARCH_SAM, TARGET_LPC1768) - #if CONF_SERIAL_IS(0) + #if SERIAL_IN_USE(0) static const char RXD_NAME_0[] PROGMEM = { "RXD0" }; static const char TXD_NAME_0[] PROGMEM = { "TXD0" }; #endif - #if CONF_SERIAL_IS(1) + #if SERIAL_IN_USE(1) static const char RXD_NAME_1[] PROGMEM = { "RXD1" }; static const char TXD_NAME_1[] PROGMEM = { "TXD1" }; #endif - #if CONF_SERIAL_IS(2) + #if SERIAL_IN_USE(2) static const char RXD_NAME_2[] PROGMEM = { "RXD2" }; static const char TXD_NAME_2[] PROGMEM = { "TXD2" }; #endif - #if CONF_SERIAL_IS(3) + #if SERIAL_IN_USE(3) static const char RXD_NAME_3[] PROGMEM = { "RXD3" }; static const char TXD_NAME_3[] PROGMEM = { "TXD3" }; #endif @@ -99,7 +99,7 @@ const PinInfo pin_array[] PROGMEM = { * 2 bytes containing the digital/analog bool flag */ - #if CONF_SERIAL_IS(0) + #if SERIAL_IN_USE(0) #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM) { RXD_NAME_0, 0, true }, { TXD_NAME_0, 1, true }, @@ -112,7 +112,7 @@ const PinInfo pin_array[] PROGMEM = { #endif #endif - #if CONF_SERIAL_IS(1) + #if SERIAL_IN_USE(1) #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM) { RXD_NAME_1, 19, true }, { TXD_NAME_1, 18, true }, @@ -130,7 +130,7 @@ const PinInfo pin_array[] PROGMEM = { #endif #endif - #if CONF_SERIAL_IS(2) + #if SERIAL_IN_USE(2) #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM) { RXD_NAME_2, 17, true }, { TXD_NAME_2, 16, true }, @@ -145,7 +145,7 @@ const PinInfo pin_array[] PROGMEM = { #endif #endif - #if CONF_SERIAL_IS(3) + #if SERIAL_IN_USE(3) #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM) { RXD_NAME_3, 15, true }, { TXD_NAME_3, 14, true },