From fe7452c5cbc9086abfdaeac316351cfa17de61c4 Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 26 May 2020 04:48:33 +0800 Subject: [PATCH] TMC serial multiplexer, FYSETC AIO-II (#18080) --- Marlin/src/feature/tmc_util.h | 4 ++ Marlin/src/module/stepper/trinamic.cpp | 6 ++- Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h | 44 +++++++++---------- Marlin/src/sd/cardreader.cpp | 2 +- .../PlatformIO/scripts/STM32F103RC_fysetc.py | 22 ++-------- 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index 73e9109ea2..77e4ce517c 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -149,9 +149,13 @@ class TMCMarlin : public TMC220 TMCMarlin(Stream * SerialPort, const float RS, const uint8_t) : TMC2208Stepper(SerialPort, RS) {} + TMCMarlin(Stream * SerialPort, const float RS, uint8_t addr, const uint16_t mul_pin1, const uint16_t mul_pin2) : + TMC2208Stepper(SerialPort, RS, addr, mul_pin1, mul_pin2) + {} TMCMarlin(const uint16_t RX, const uint16_t TX, const float RS, const uint8_t, const bool has_rx=true) : TMC2208Stepper(RX, TX, RS, has_rx) {} + uint16_t rms_current() { return TMC2208Stepper::rms_current(); } inline void rms_current(const uint16_t mA) { this->val_mA = mA; diff --git a/Marlin/src/module/stepper/trinamic.cpp b/Marlin/src/module/stepper/trinamic.cpp index ed238ede7d..26a0f58959 100644 --- a/Marlin/src/module/stepper/trinamic.cpp +++ b/Marlin/src/module/stepper/trinamic.cpp @@ -49,7 +49,11 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; #define __TMC_SPI_DEFINE(IC, ST, L, AI) TMCMarlin stepper##ST(ST##_CS_PIN, float(ST##_RSENSE), ST##_CHAIN_POS) #endif -#define TMC_UART_HW_DEFINE(IC, ST, L, AI) TMCMarlin stepper##ST(&ST##_HARDWARE_SERIAL, float(ST##_RSENSE), ST##_SLAVE_ADDRESS) +#if ENABLED(TMC_SERIAL_MULTIPLEXER) + #define TMC_UART_HW_DEFINE(IC, ST, L, AI) TMCMarlin stepper##ST(&ST##_HARDWARE_SERIAL, float(ST##_RSENSE), ST##_SLAVE_ADDRESS, SERIAL_MUL_PIN1, SERIAL_MUL_PIN2) +#else + #define TMC_UART_HW_DEFINE(IC, ST, L, AI) TMCMarlin stepper##ST(&ST##_HARDWARE_SERIAL, float(ST##_RSENSE), ST##_SLAVE_ADDRESS) +#endif #define TMC_UART_SW_DEFINE(IC, ST, L, AI) TMCMarlin stepper##ST(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN, float(ST##_RSENSE), ST##_SLAVE_ADDRESS, ST##_SERIAL_RX_PIN > -1) #define _TMC_SPI_DEFINE(IC, ST, AI) __TMC_SPI_DEFINE(IC, ST, TMC_##ST##_LABEL, AI) diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index 187aec7636..fc9cfd6a7c 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -30,7 +30,7 @@ #define DISABLE_JTAG -#define pins_v2_20190128 // geo-f:add for new pins define +#define pins_v2_20190128 // new pins define // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 @@ -84,32 +84,32 @@ #define E0_DIR_PIN PC14 #define E0_ENABLE_PIN PC13 +#if HAS_TMC220x + + /** + * TMC2208/TMC2209 stepper drivers + */ + + // + // Hardware serial with switch + // + #define X_HARDWARE_SERIAL Serial1 + #define Y_HARDWARE_SERIAL Serial1 + #define Z_HARDWARE_SERIAL Serial1 + #define E0_HARDWARE_SERIAL Serial1 + #define TMC_SERIAL_MULTIPLEXER + #define SERIAL_MUL_PIN1 PB13 + #define SERIAL_MUL_PIN2 PB12 + +#endif + // // Stepper current PWM // - -// X:PA2 Y:PA3 Z:PB12 E:PB13 // changed for test -//#define MOTOR_CURRENT_PWM_XY_PIN PA3 -//#define MOTOR_CURRENT_PWM_Z_PIN PA2 // PB12 -//#define MOTOR_CURRENT_PWM_XY_PIN PB6 -//#define MOTOR_CURRENT_PWM_Z_PIN PB7 // PB12 -//#define MOTOR_CURRENT_PWM_E_PIN -1 // PB13 -// Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range #ifndef MOTOR_CURRENT_PWM_RANGE - #define MOTOR_CURRENT_PWM_RANGE 1500 // geo-f:old 2000 + #define MOTOR_CURRENT_PWM_RANGE 1500 // origin:2000 #endif -#define DEFAULT_PWM_MOTOR_CURRENT {500, 500, 400} // geo-f:old 1300 1300 1250 - -// 采用 SDIO PCB从左到右数 -// 1:PC10 - SDIO_D2 -// 2:PC11 - SDIO_D3 -// 3:PD2 - SDIO_CMD -// 4:VCC -// 5:PC12 - SDIO_CK -// 6:VDD -// 7:PC8 - SDIO_D0 -// 8:PC9 - SDIO_D1 -// 9:PA15 - SD_DETECT_PIN +#define DEFAULT_PWM_MOTOR_CURRENT { 500, 500, 400 } // origin: {1300,1300,1250} // // Heaters / Fans diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 54a17f57aa..7b4b74915e 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -393,7 +393,7 @@ void CardReader::manage_media() { if (stat) { // Media Inserted safe_delay(500); // Some boards need a delay to get settled mount(); // Try to mount the media - #if MB(FYSETC_CHEETAH) + #if MB(FYSETC_CHEETAH, FYSETC_AIO_II) reset_stepper_drivers(); // Workaround for Cheetah bug #endif if (!isMounted()) stat = 0; // Not mounted? diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py b/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py index 67a75f5b47..134f63d668 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py @@ -2,7 +2,10 @@ from os.path import join from os.path import expandvars Import("env", "projenv") -# Relocate firmware from 0x08000000 to 0x08002000 +# Relocate firmware from 0x08000000 to 0x08010000 +# for define in env['CPPDEFINES']: +# if define[0] == "VECT_TAB_ADDR": +# env['CPPDEFINES'].remove(define) #env['CPPDEFINES'].remove(("VECT_TAB_ADDR", 134217728)) #env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08010000")) @@ -14,14 +17,6 @@ env.AddPostAction( "\"" + join("$BUILD_DIR","${PROGNAME}.hex") + "\"", # Note: $BUILD_DIR is a full path ]), "Building $TARGET")) -# please keep $SOURCE variable, it will be replaced with a path to firmware - -# Generic -#env.Replace( -# UPLOADER="serial_upload.bat" -# UPLOADCMD="$UPLOADER stm32loader.py $SOURCE" -#) - # In-line command with arguments UPLOAD_TOOL="stm32flash" platform = env.PioPlatform() @@ -32,12 +27,3 @@ env.Replace( UPLOADER=UPLOAD_TOOL, UPLOADCMD=expandvars(UPLOAD_TOOL + " -v -i rts,-dtr,dtr -R -b 115200 -g 0x8000000 -w \"" + join("$BUILD_DIR","${PROGNAME}.hex")+"\"" + " $UPLOAD_PORT") ) - -# Python callback -#def on_upload(source, target, env): -# print source, target -# firmware_path = str(source[0]) -# # do something -# env.Execute(".\serial_upload.bat") - -#env.Replace(UPLOADCMD=on_upload)