diff --git a/.circleci/config.yml b/.circleci/config.yml
index 73fe1f0a37..d474f034ba 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -51,13 +51,12 @@ jobs:
export PATH=`pwd`/buildroot/bin/:${PATH}
# Generate custom version include
- generate_version ./Marlin/src/inc
- cat ./Marlin/src/inc/_Version.h
+ generate_version ./Marlin/
+ cat ./Marlin/Version.h
#
- # Backup pins_RAMPS.h
- #
- cp Marlin/src/pins/pins_RAMPS.h Marlin/src/pins/pins_RAMPS.h.backup
+ # Back up pins_RAMPS.h
#
+ backup_ramps
env_backup
@@ -241,14 +240,14 @@ jobs:
build_marlin_pio ./ ${TEST_PLATFORM}
restore_configs
echo testing STM32F1 targets...
- export TEST_PLATFORM="-e STM32F1"
+ export TEST_PLATFORM="-e STM32F103RE"
restore_configs
- echo use_example_configs STM32F10
- use_example_configs STM32F10
+ echo use_example_configs STM32/STM32F103RE
+ use_example_configs STM32/STM32F103RE
build_marlin_pio ./ ${TEST_PLATFORM}
restore_configs
- echo use_example_configs stm32f103ret6
- use_example_configs stm32f103ret6
+ echo use_example_configs STM32/stm32f103ret6
+ use_example_configs STM32/stm32f103ret6
build_marlin_pio ./ ${TEST_PLATFORM}
restore_configs
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000000..946acca2d7
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+custom: http://www.thinkyhead.com/donate-to-marlin
diff --git a/.github/issue_template.md b/.github/issue_template.md
index 58b4894f67..ecfb36f0d5 100644
--- a/.github/issue_template.md
+++ b/.github/issue_template.md
@@ -1,8 +1,8 @@
SCLK, MOSI, MISO
- * INT --> SD_DETECT_PIN
+ * INT --> SD_DETECT_PIN [1]
* SS --> SDSS
+ *
+ * [1] On AVR an interrupt-capable pin is best for UHS3 compatibility.
*/
//#define USB_FLASH_DRIVE_SUPPORT
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
- #define USB_CS_PIN SDSS
- #define USB_INTR_PIN SD_DETECT_PIN
+ #define USB_CS_PIN SDSS
+ #define USB_INTR_PIN SD_DETECT_PIN
+
+ /**
+ * USB Host Shield Library
+ *
+ * - UHS2 uses no interrupts and has been production-tested
+ * on a LulzBot TAZ Pro with a 32-bit Archim board.
+ *
+ * - UHS3 is newer code with better USB compatibility. But it
+ * is less tested and is known to interfere with Servos.
+ * [1] This requires USB_INTR_PIN to be interrupt-capable.
+ */
+ //#define USE_UHS3_USB
#endif
/**
@@ -967,19 +1088,27 @@
// Add an optimized binary file transfer mode, initiated with 'M28 B1'
//#define BINARY_FILE_TRANSFER
- // LPC-based boards have on-board SD Card options. Override here or defaults apply.
- #ifdef TARGET_LPC1768
- //#define LPC_SD_LCD // Use the SD drive in the external LCD controller.
- //#define LPC_SD_ONBOARD // Use the SD drive on the control board. (No SD_DETECT_PIN. M21 to init.)
- //#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD (as defined in a pins file).
- //#define USB_SD_DISABLED // Disable SD Card access over USB (for security).
- #if ENABLED(LPC_SD_ONBOARD)
- //#define USB_SD_ONBOARD // Provide the onboard SD card to the host as a USB mass storage device.
- #endif
+ #if HAS_SDCARD_CONNECTION
+ /**
+ * Set this option to one of the following (or the board's defaults apply):
+ *
+ * LCD - Use the SD drive in the external LCD controller.
+ * ONBOARD - Use the SD drive on the control board. (No SD_DETECT_PIN. M21 to init.)
+ * CUSTOM_CABLE - Use a custom cable to access the SD (as defined in a pins file).
+ *
+ * :[ 'LCD', 'ONBOARD', 'CUSTOM_CABLE' ]
+ */
+ //#define SDCARD_CONNECTION LCD
#endif
#endif // SDSUPPORT
+/**
+ * By default an onboard SD card reader may be shared as a USB mass-
+ * storage device. This option hides the SD card from the host PC.
+ */
+//#define NO_SD_HOST_DRIVE // Disable SD Card access over USB (for security).
+
/**
* Additional options for Graphical Displays
*
@@ -1052,6 +1181,7 @@
//#define STATUS_FAN_FRAMES 3 // :[0,1,2,3,4] Number of fan animation frames
//#define STATUS_HEAT_PERCENT // Show heating in a progress bar
#define BOOT_MARLIN_LOGO_SMALL // Show a smaller Marlin logo on the Boot Screen (saving 399 bytes of flash)
+ //#define BOOT_MARLIN_LOGO_ANIMATED // Animated Marlin logo. Costs ~3260 (or ~940) bytes of PROGMEM.
// Frivolous Game Options
#if ENABLED(SKR13)
@@ -1062,6 +1192,101 @@
#endif // HAS_GRAPHICAL_LCD
+//
+// Lulzbot Touch UI
+//
+#if ENABLED(LULZBOT_TOUCH_UI)
+ // Display board used
+ //#define LCD_FTDI_VM800B35A // FTDI 3.5" with FT800 (320x240)
+ //#define LCD_4DSYSTEMS_4DLCD_FT843 // 4D Systems 4.3" (480x272)
+ //#define LCD_HAOYU_FT800CB // Haoyu with 4.3" or 5" (480x272)
+ //#define LCD_HAOYU_FT810CB // Haoyu with 5" (800x480)
+ //#define LCD_ALEPHOBJECTS_CLCD_UI // Aleph Objects Color LCD UI
+
+ // Correct the resolution if not using the stock TFT panel.
+ //#define TOUCH_UI_320x240
+ //#define TOUCH_UI_480x272
+ //#define TOUCH_UI_800x480
+
+ // Mappings for boards with a standard RepRapDiscount Display connector
+ //#define AO_EXP1_PINMAP // AlephObjects CLCD UI EXP1 mapping
+ //#define AO_EXP2_PINMAP // AlephObjects CLCD UI EXP2 mapping
+ //#define CR10_TFT_PINMAP // Rudolph Riedel's CR10 pin mapping
+ //#define OTHER_PIN_LAYOUT // Define pins manually below
+ #if ENABLED(OTHER_PIN_LAYOUT)
+ // The pins for CS and MOD_RESET (PD) must be chosen.
+ #define CLCD_MOD_RESET 9
+ #define CLCD_SPI_CS 10
+
+ // If using software SPI, specify pins for SCLK, MOSI, MISO
+ //#define CLCD_USE_SOFT_SPI
+ #if ENABLED(CLCD_USE_SOFT_SPI)
+ #define CLCD_SOFT_SPI_MOSI 11
+ #define CLCD_SOFT_SPI_MISO 12
+ #define CLCD_SOFT_SPI_SCLK 13
+ #endif
+ #endif
+
+ // Display Orientation. An inverted (i.e. upside-down) display
+ // is supported on the FT800. The FT810 and beyond also support
+ // portrait and mirrored orientations.
+ //#define TOUCH_UI_INVERTED
+ //#define TOUCH_UI_PORTRAIT
+ //#define TOUCH_UI_MIRRORED
+
+ // UTF8 processing and rendering.
+ // Unsupported characters are shown as '?'.
+ //#define TOUCH_UI_USE_UTF8
+ #if ENABLED(TOUCH_UI_USE_UTF8)
+ // Western accents support. These accented characters use
+ // combined bitmaps and require relatively little storage.
+ #define TOUCH_UI_UTF8_WESTERN_CHARSET
+ #if ENABLED(TOUCH_UI_UTF8_WESTERN_CHARSET)
+ // Additional character groups. These characters require
+ // full bitmaps and take up considerable storage:
+ //#define TOUCH_UI_UTF8_SUPERSCRIPTS // ¹ ² ³
+ //#define TOUCH_UI_UTF8_COPYRIGHT // © ®
+ //#define TOUCH_UI_UTF8_GERMANIC // ß
+ //#define TOUCH_UI_UTF8_SCANDINAVIAN // Æ Ð Ø Þ æ ð ø þ
+ //#define TOUCH_UI_UTF8_PUNCTUATION // « » ¿ ¡
+ //#define TOUCH_UI_UTF8_CURRENCY // ¢ £ ¤ ¥
+ //#define TOUCH_UI_UTF8_ORDINALS // º ª
+ //#define TOUCH_UI_UTF8_MATHEMATICS // ± × ÷
+ //#define TOUCH_UI_UTF8_FRACTIONS // ¼ ½ ¾
+ //#define TOUCH_UI_UTF8_SYMBOLS // µ ¶ ¦ § ¬
+ #endif
+ #endif
+
+ // Use a smaller font when labels don't fit buttons
+ #define TOUCH_UI_FIT_TEXT
+
+ // Allow language selection from menu at run-time (otherwise use LCD_LANGUAGE)
+ //#define LCD_LANGUAGE_1 en
+ //#define LCD_LANGUAGE_2 fr
+ //#define LCD_LANGUAGE_3 de
+ //#define LCD_LANGUAGE_4 es
+ //#define LCD_LANGUAGE_5 it
+
+ // Use a numeric passcode for "Screen lock" keypad.
+ // (recommended for smaller displays)
+ //#define TOUCH_UI_PASSCODE
+
+ // Output extra debug info for Touch UI events
+ //#define TOUCH_UI_DEBUG
+#endif
+
+//
+// FSMC Graphical TFT
+//
+#if ENABLED(FSMC_GRAPHICAL_TFT)
+ //#define TFT_MARLINUI_COLOR 0xFFFF // White
+ //#define TFT_MARLINBG_COLOR 0x0000 // Black
+ //#define TFT_DISABLED_COLOR 0x0003 // Almost black
+ //#define TFT_BTCANCEL_COLOR 0xF800 // Red
+ //#define TFT_BTARROWS_COLOR 0xDEE6 // 11011 110111 00110 Yellow
+ //#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan
+#endif
+
// @section safety
/**
@@ -1134,16 +1359,53 @@
* See http://marlinfw.org/docs/features/lin_advance.html for full instructions.
* Mention @Sebastianv650 on GitHub to alert the author of any issues.
*/
-#if DISABLED(SKR13)
+#if E0_DRIVER_TYPE != TMC2208_STANDALONE
#define LIN_ADVANCE
#endif
#if ENABLED(LIN_ADVANCE)
- #define LIN_ADVANCE_K 0.0 // Unit: mm compression per 1mm/s extruder speed
- //#define LA_DEBUG // If enabled, this will generate debug information output over USB.
+ //#define EXTRA_LIN_ADVANCE_K // Enable for second linear advance constants
+ #define LIN_ADVANCE_K 0.0 // Unit: mm compression per 1mm/s extruder speed
+ //#define LA_DEBUG // If enabled, this will generate debug information output over USB.
#endif
// @section leveling
+/**
+ * Points to probe for all 3-point Leveling procedures.
+ * Override if the automatically selected points are inadequate.
+ */
+#if EITHER(AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_UBL)
+ //#define PROBE_PT_1_X 15
+ //#define PROBE_PT_1_Y 180
+ //#define PROBE_PT_2_X 15
+ //#define PROBE_PT_2_Y 20
+ //#define PROBE_PT_3_X 170
+ //#define PROBE_PT_3_Y 20
+#endif
+
+/**
+ * Override MIN_PROBE_EDGE for each side of the build plate
+ * Useful to get probe points to exact positions on targets or
+ * to allow leveling to avoid plate clamps on only specific
+ * sides of the bed.
+ *
+ * If you are replacing the prior *_PROBE_BED_POSITION options,
+ * LEFT and FRONT values in most cases will map directly over
+ * RIGHT and REAR would be the inverse such as
+ * (X/Y_BED_SIZE - RIGHT/BACK_PROBE_BED_POSITION)
+ *
+ * This will allow all positions to match at compilation, however
+ * should the probe position be modified with M851XY then the
+ * probe points will follow. This prevents any change from causing
+ * the probe to be unable to reach any points.
+ */
+#if PROBE_SELECTED && !IS_KINEMATIC
+ //#define MIN_PROBE_EDGE_LEFT MIN_PROBE_EDGE
+ //#define MIN_PROBE_EDGE_RIGHT MIN_PROBE_EDGE
+ //#define MIN_PROBE_EDGE_FRONT MIN_PROBE_EDGE
+ //#define MIN_PROBE_EDGE_BACK MIN_PROBE_EDGE
+#endif
+
#if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
// Override the mesh area if the automatic (max) area is too large
//#define MESH_MIN_X MESH_INSET
@@ -1206,7 +1468,7 @@
#define MIN_STEPS_PER_SEGMENT 6
/**
- * Minimum delay after setting the stepper DIR (in ns)
+ * Minimum delay before and after setting the stepper DIR (in ns)
* 0 : No delay (Expect at least 10µS since one Stepper ISR must transpire)
* 20 : Minimum for TMC2xxx drivers
* 200 : Minimum for A4988 drivers
@@ -1218,7 +1480,8 @@
*
* Override the default value based on the driver type set in Configuration.h.
*/
-//#define MINIMUM_STEPPER_DIR_DELAY 650
+//#define MINIMUM_STEPPER_POST_DIR_DELAY 650
+//#define MINIMUM_STEPPER_PRE_DIR_DELAY 650
/**
* Minimum stepper driver pulse width (in µs)
@@ -1293,6 +1556,9 @@
//#define SERIAL_XON_XOFF
#endif
+// Add M575 G-code to change the baud rate
+//#define BAUD_RATE_GCODE
+
#if ENABLED(SDSUPPORT)
// Enable this option to collect and display the maximum
// RX queue usage after transferring a file to SD.
@@ -1350,19 +1616,19 @@
*/
#define FWRETRACT
#if ENABLED(FWRETRACT)
- #define FWRETRACT_AUTORETRACT // costs ~500 bytes of PROGMEM
+ #define FWRETRACT_AUTORETRACT // Override slicer retractions
#if ENABLED(FWRETRACT_AUTORETRACT)
- #define MIN_AUTORETRACT 0.1 // When auto-retract is on, convert E moves of this length and over
- #define MAX_AUTORETRACT 10.0 // Upper limit for auto-retract conversion
+ #define MIN_AUTORETRACT 0.1 // (mm) Don't convert E moves under this length
+ #define MAX_AUTORETRACT 10.0 // (mm) Don't convert E moves over this length
#endif
- #define RETRACT_LENGTH 3 // Default retract length (positive mm)
- #define RETRACT_LENGTH_SWAP 13 // Default swap retract length (positive mm), for extruder change
- #define RETRACT_FEEDRATE 45 // Default feedrate for retracting (mm/s)
- #define RETRACT_ZRAISE 0 // Default retract Z-raise (mm)
- #define RETRACT_RECOVER_LENGTH 0 // Default additional recover length (mm, added to retract length when recovering)
- #define RETRACT_RECOVER_LENGTH_SWAP 0 // Default additional swap recover length (mm, added to retract length when recovering from extruder change)
- #define RETRACT_RECOVER_FEEDRATE 8 // Default feedrate for recovering from retraction (mm/s)
- #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // Default feedrate for recovering from swap retraction (mm/s)
+ #define RETRACT_LENGTH 3 // (mm) Default retract length (positive value)
+ #define RETRACT_LENGTH_SWAP 13 // (mm) Default swap retract length (positive value)
+ #define RETRACT_FEEDRATE 45 // (mm/s) Default feedrate for retracting
+ #define RETRACT_ZRAISE 0 // (mm) Default retract Z-raise
+ #define RETRACT_RECOVER_LENGTH 0 // (mm) Default additional recover length (added to retract length on recover)
+ #define RETRACT_RECOVER_LENGTH_SWAP 0 // (mm) Default additional swap recover length (added to retract length on recover from toolchange)
+ #define RETRACT_RECOVER_FEEDRATE 8 // (mm/s) Default feedrate for recovering from retraction
+ #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // (mm/s) Default feedrate for recovering from swap retraction
#if ENABLED(MIXING_EXTRUDER)
//#define RETRACT_SYNC_MIXING // Retract and restore all mixing steppers simultaneously
#endif
@@ -1375,6 +1641,7 @@
#if EXTRUDERS > 1
// Z raise distance for tool-change, as needed for some extruders
#define TOOLCHANGE_ZRAISE 2 // (mm)
+ //#define TOOLCHANGE_NO_RETURN // Never return to the previous position on tool-change
// Retract and prime filament on tool-change
//#define TOOLCHANGE_FILAMENT_SWAP
@@ -1567,78 +1834,91 @@
#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.
#define X_MICROSTEPS 16 // 0..256
#define X_RSENSE 0.11
+ #define X_CHAIN_POS -1 // <=0 : Not chained. 1 : MCU MOSI connected. 2 : Next in chain, ...
#endif
#if AXIS_IS_TMC(X2)
#define X2_CURRENT 800
#define X2_MICROSTEPS 16
#define X2_RSENSE 0.11
+ #define X2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Y)
#define Y_CURRENT 800
#define Y_MICROSTEPS 16
#define Y_RSENSE 0.11
+ #define Y_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Y2)
#define Y2_CURRENT 800
#define Y2_MICROSTEPS 16
#define Y2_RSENSE 0.11
+ #define Y2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Z)
#define Z_CURRENT 800
#define Z_MICROSTEPS 16
#define Z_RSENSE 0.11
+ #define Z_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Z2)
#define Z2_CURRENT 800
#define Z2_MICROSTEPS 16
#define Z2_RSENSE 0.11
+ #define Z2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Z3)
#define Z3_CURRENT 800
#define Z3_MICROSTEPS 16
#define Z3_RSENSE 0.11
+ #define Z3_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E0)
#define E0_CURRENT 800
#define E0_MICROSTEPS 16
#define E0_RSENSE 0.11
+ #define E0_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E1)
#define E1_CURRENT 800
#define E1_MICROSTEPS 16
#define E1_RSENSE 0.11
+ #define E1_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E2)
#define E2_CURRENT 800
#define E2_MICROSTEPS 16
#define E2_RSENSE 0.11
+ #define E2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E3)
#define E3_CURRENT 800
#define E3_MICROSTEPS 16
#define E3_RSENSE 0.11
+ #define E3_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E4)
#define E4_CURRENT 800
#define E4_MICROSTEPS 16
#define E4_RSENSE 0.11
+ #define E4_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E5)
#define E5_CURRENT 800
#define E5_MICROSTEPS 16
#define E5_RSENSE 0.11
+ #define E5_CHAIN_POS -1
#endif
/**
@@ -1660,7 +1940,6 @@
//#define E5_CS_PIN -1
/**
- * Use software SPI for TMC2130.
* Software option for SPI driven drivers (TMC2130, TMC2160, TMC2660, TMC5130 and TMC5160).
* The default SW SPI pins are defined the respective pins files,
* but you can override or define them here.
@@ -1670,6 +1949,32 @@
//#define TMC_SW_MISO -1
//#define TMC_SW_SCK -1
+ /**
+ * Four TMC2209 drivers can use the same HW/SW serial port with hardware configured addresses.
+ * Set the address using jumpers on pins MS1 and MS2.
+ * Address | MS1 | MS2
+ * 0 | LOW | LOW
+ * 1 | HIGH | LOW
+ * 2 | LOW | HIGH
+ * 3 | HIGH | HIGH
+ *
+ * Set *_SERIAL_TX_PIN and *_SERIAL_RX_PIN to match for all drivers
+ * on the same serial port, either here or in your board's pins file.
+ */
+ #define X_SLAVE_ADDRESS 0
+ #define Y_SLAVE_ADDRESS 0
+ #define Z_SLAVE_ADDRESS 0
+ #define X2_SLAVE_ADDRESS 0
+ #define Y2_SLAVE_ADDRESS 0
+ #define Z2_SLAVE_ADDRESS 0
+ #define Z3_SLAVE_ADDRESS 0
+ #define E0_SLAVE_ADDRESS 0
+ #define E1_SLAVE_ADDRESS 0
+ #define E2_SLAVE_ADDRESS 0
+ #define E3_SLAVE_ADDRESS 0
+ #define E4_SLAVE_ADDRESS 0
+ #define E5_SLAVE_ADDRESS 0
+
/**
* Software enable
*
@@ -1679,7 +1984,7 @@
//#define SOFTWARE_DRIVER_ENABLE
/**
- * TMC2130, TMC2160, TMC2208, TMC5130 and TMC5160 only
+ * TMC2130, TMC2160, TMC2208, TMC2209, TMC5130 and TMC5160 only
* Use Trinamic's ultra quiet stepping mode.
* When disabled, Marlin will use spreadCycle stepping mode.
*/
@@ -1705,7 +2010,7 @@
/**
* Monitor Trinamic drivers for error conditions,
- * like overtemperature and short to ground. TMC2208 requires hardware serial.
+ * like overtemperature and short to ground.
* In the case of overtemperature Marlin can decrease the driver current until error condition clears.
* Other detected conditions can be used to stop the current print.
* Relevant g-codes:
@@ -1723,7 +2028,7 @@
#endif
/**
- * TMC2130, TMC2160, TMC2208, TMC5130 and TMC5160 only
+ * TMC2130, TMC2160, TMC2208, TMC2209, TMC5130 and TMC5160 only
* The driver will switch to spreadCycle when stepper speed is over HYBRID_THRESHOLD.
* This mode allows for faster movements at the expense of higher noise levels.
* STEALTHCHOP_(XY|Z|E) must be enabled to use HYBRID_THRESHOLD.
@@ -1746,19 +2051,29 @@
#define E5_HYBRID_THRESHOLD 30
/**
- * TMC2130, TMC2160, TMC2660, TMC5130, and TMC5160 only
- * Use StallGuard2 to sense an obstacle and trigger an endstop.
+ * Use StallGuard2 to home / probe X, Y, Z.
+ *
+ * TMC2130, TMC2160, TMC2209, TMC2660, TMC5130, and TMC5160 only
* Connect the stepper driver's DIAG1 pin to the X/Y endstop pin.
* X, Y, and Z homing will always be done in spreadCycle mode.
*
- * X/Y/Z_STALL_SENSITIVITY is used for tuning the trigger sensitivity.
- * Higher values make the system LESS sensitive.
- * Lower value make the system MORE sensitive.
- * Too low values can lead to false positives, while too high values will collide the axis without triggering.
- * It is advised to set X/Y/Z_HOME_BUMP_MM to 0.
- * M914 X/Y/Z to live tune the setting
+ * X/Y/Z_STALL_SENSITIVITY is the default stall threshold.
+ * Use M914 X Y Z to set the stall threshold at runtime:
+ *
+ * Sensitivity TMC2209 Others
+ * HIGHEST 255 -64 (Too sensitive => False positive)
+ * LOWEST 0 63 (Too insensitive => No trigger)
+ *
+ * It is recommended to set [XYZ]_HOME_BUMP_MM to 0.
+ *
+ * SPI_ENDSTOPS *** Beta feature! *** TMC2130 Only ***
+ * Poll the driver through SPI to determine load when homing.
+ * Removes the need for a wire from DIAG1 to an endstop pin.
+ *
+ * IMPROVE_HOMING_RELIABILITY tunes acceleration and jerk when
+ * homing and adds a guard period for endstop triggering.
*/
- //#define SENSORLESS_HOMING // TMC2130 only
+ //#define SENSORLESS_HOMING // StallGuard capable drivers only
/**
* Use StallGuard2 to probe the bed with the nozzle.
@@ -1766,14 +2081,24 @@
* CAUTION: This could cause damage to machines that use a lead screw or threaded rod
* to move the Z axis. Take extreme care when attempting to enable this feature.
*/
- //#define SENSORLESS_PROBING // TMC2130 only
+ //#define SENSORLESS_PROBING // StallGuard capable drivers only
#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING)
+ // TMC2209: 0...255. TMC2130: -64...63
#define X_STALL_SENSITIVITY 8
+ #define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY
#define Y_STALL_SENSITIVITY 8
//#define Z_STALL_SENSITIVITY 8
+ //#define SPI_ENDSTOPS // TMC2130 only
+ //#define IMPROVE_HOMING_RELIABILITY
#endif
+ /**
+ * Beta feature!
+ * Create a 50/50 square wave step pulse optimal for stepper drivers.
+ */
+ //#define SQUARE_WAVE_STEPPING
+
/**
* Enable M122 debugging command for TMC stepper drivers.
* M122 S0/1 will enable continous reporting.
@@ -1819,7 +2144,7 @@
#define X_OVERCURRENT 2000 // (mA) Current where the driver detects an over current (VALID: 375 x (1 - 16) - 6A max - rounds down)
#define X_STALLCURRENT 1500 // (mA) Current where the driver detects a stall (VALID: 31.25 * (1-128) - 4A max - rounds down)
#define X_MAX_VOLTAGE 127 // 0-255, Maximum effective voltage seen by stepper
- #define X_CHAIN_POS 0 // Position in SPI chain, 0=Not in chain, 1=Nearest MOSI
+ #define X_CHAIN_POS -1 // Position in SPI chain. (<=0 : Not in chain. 1 : Nearest MOSI)
#endif
#if AXIS_DRIVER_TYPE_X2(L6470)
@@ -1827,7 +2152,7 @@
#define X2_OVERCURRENT 2000
#define X2_STALLCURRENT 1500
#define X2_MAX_VOLTAGE 127
- #define X2_CHAIN_POS 0
+ #define X2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Y(L6470)
@@ -1835,7 +2160,7 @@
#define Y_OVERCURRENT 2000
#define Y_STALLCURRENT 1500
#define Y_MAX_VOLTAGE 127
- #define Y_CHAIN_POS 0
+ #define Y_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Y2(L6470)
@@ -1843,7 +2168,7 @@
#define Y2_OVERCURRENT 2000
#define Y2_STALLCURRENT 1500
#define Y2_MAX_VOLTAGE 127
- #define Y2_CHAIN_POS 0
+ #define Y2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Z(L6470)
@@ -1851,7 +2176,7 @@
#define Z_OVERCURRENT 2000
#define Z_STALLCURRENT 1500
#define Z_MAX_VOLTAGE 127
- #define Z_CHAIN_POS 0
+ #define Z_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Z2(L6470)
@@ -1859,7 +2184,7 @@
#define Z2_OVERCURRENT 2000
#define Z2_STALLCURRENT 1500
#define Z2_MAX_VOLTAGE 127
- #define Z2_CHAIN_POS 0
+ #define Z2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Z3(L6470)
@@ -1867,7 +2192,7 @@
#define Z3_OVERCURRENT 2000
#define Z3_STALLCURRENT 1500
#define Z3_MAX_VOLTAGE 127
- #define Z3_CHAIN_POS 0
+ #define Z3_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E0(L6470)
@@ -1875,7 +2200,7 @@
#define E0_OVERCURRENT 2000
#define E0_STALLCURRENT 1500
#define E0_MAX_VOLTAGE 127
- #define E0_CHAIN_POS 0
+ #define E0_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E1(L6470)
@@ -1883,7 +2208,7 @@
#define E1_OVERCURRENT 2000
#define E1_STALLCURRENT 1500
#define E1_MAX_VOLTAGE 127
- #define E1_CHAIN_POS 0
+ #define E1_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E2(L6470)
@@ -1891,7 +2216,7 @@
#define E2_OVERCURRENT 2000
#define E2_STALLCURRENT 1500
#define E2_MAX_VOLTAGE 127
- #define E2_CHAIN_POS 0
+ #define E2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E3(L6470)
@@ -1899,7 +2224,7 @@
#define E3_OVERCURRENT 2000
#define E3_STALLCURRENT 1500
#define E3_MAX_VOLTAGE 127
- #define E3_CHAIN_POS 0
+ #define E3_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E4(L6470)
@@ -1907,7 +2232,7 @@
#define E4_OVERCURRENT 2000
#define E4_STALLCURRENT 1500
#define E4_MAX_VOLTAGE 127
- #define E4_CHAIN_POS 0
+ #define E4_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E5(L6470)
@@ -1915,7 +2240,7 @@
#define E5_OVERCURRENT 2000
#define E5_STALLCURRENT 1500
#define E5_MAX_VOLTAGE 127
- #define E5_CHAIN_POS 0
+ #define E5_CHAIN_POS -1
#endif
/**
@@ -2020,36 +2345,53 @@
*
* See http://marlinfw.org/docs/configuration/laser_spindle.html for more config details.
*/
-//#define SPINDLE_LASER_ENABLE
-#if ENABLED(SPINDLE_LASER_ENABLE)
+//#define SPINDLE_FEATURE
+//#define LASER_FEATURE
+#if EITHER(SPINDLE_FEATURE, LASER_FEATURE)
+ #define SPINDLE_LASER_ACTIVE_HIGH false // Set to "true" if the on/off function is active HIGH
+ #define SPINDLE_LASER_PWM true // Set to "true" if your controller supports setting the speed/power
+ #define SPINDLE_LASER_PWM_INVERT true // Set to "true" if the speed/power goes up when you want it to go slower
+ #define SPINDLE_LASER_POWERUP_DELAY 5000 // (ms) Delay to allow the spindle/laser to come up to speed/power
+ #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop
- #define SPINDLE_LASER_ENABLE_INVERT false // set to "true" if the on/off function is reversed
- #define SPINDLE_LASER_PWM true // set to true if your controller supports setting the speed/power
- #define SPINDLE_LASER_PWM_INVERT true // set to "true" if the speed/power goes up when you want it to go slower
- #define SPINDLE_LASER_POWERUP_DELAY 5000 // delay in milliseconds to allow the spindle/laser to come up to speed/power
- #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // delay in milliseconds to allow the spindle to stop
- #define SPINDLE_DIR_CHANGE true // set to true if your spindle controller supports changing spindle direction
- #define SPINDLE_INVERT_DIR false
- #define SPINDLE_STOP_ON_DIR_CHANGE true // set to true if Marlin should stop the spindle before changing rotation direction
+ #if ENABLED(SPINDLE_FEATURE)
+ //#define SPINDLE_CHANGE_DIR // Enable if your spindle controller can change spindle direction
+ #define SPINDLE_CHANGE_DIR_STOP // Enable if the spindle should stop before changing spin direction
+ #define SPINDLE_INVERT_DIR false // Set to "true" if the spin direction is reversed
- /**
- * The M3 & M4 commands use the following equation to convert PWM duty cycle to speed/power
- *
- * SPEED/POWER = PWM duty cycle * SPEED_POWER_SLOPE + SPEED_POWER_INTERCEPT
- * where PWM duty cycle varies from 0 to 255
- *
- * set the following for your controller (ALL MUST BE SET)
- */
+ /**
+ * The M3 & M4 commands use the following equation to convert PWM duty cycle to speed/power
+ *
+ * SPEED/POWER = PWM duty cycle * SPEED_POWER_SLOPE + SPEED_POWER_INTERCEPT
+ * where PWM duty cycle varies from 0 to 255
+ *
+ * set the following for your controller (ALL MUST BE SET)
+ */
+ #define SPEED_POWER_SLOPE 118.4
+ #define SPEED_POWER_INTERCEPT 0
+ #define SPEED_POWER_MIN 5000
+ #define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM
+ #else
+ #define SPEED_POWER_SLOPE 0.3922
+ #define SPEED_POWER_INTERCEPT 0
+ #define SPEED_POWER_MIN 10
+ #define SPEED_POWER_MAX 100 // 0-100%
+ #endif
+#endif
- #define SPEED_POWER_SLOPE 118.4
- #define SPEED_POWER_INTERCEPT 0
- #define SPEED_POWER_MIN 5000
- #define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM
-
- //#define SPEED_POWER_SLOPE 0.3922
- //#define SPEED_POWER_INTERCEPT 0
- //#define SPEED_POWER_MIN 10
- //#define SPEED_POWER_MAX 100 // 0-100%
+/**
+ * Coolant Control
+ *
+ * Add the M7, M8, and M9 commands to turn mist or flood coolant on and off.
+ *
+ * Note: COOLANT_MIST_PIN and/or COOLANT_FLOOD_PIN must also be defined.
+ */
+//#define COOLANT_CONTROL
+#if ENABLED(COOLANT_CONTROL)
+ #define COOLANT_MIST // Enable if mist coolant is present
+ #define COOLANT_FLOOD // Enable if flood coolant is present
+ #define COOLANT_MIST_INVERT false // Set "true" if the on/off function is reversed
+ #define COOLANT_FLOOD_INVERT false // Set "true" if the on/off function is reversed
#endif
/**
@@ -2103,6 +2445,13 @@
*/
#define EXTENDED_CAPABILITIES_REPORT
+/**
+ * Expected Printer Check
+ * Add the M16 G-code to compare a string to the MACHINE_NAME.
+ * M16 with a non-matching string causes the printer to halt.
+ */
+//#define EXPECTED_PRINTER_CHECK
+
/**
* Disable all Volumetric extrusion options
*/
@@ -2157,6 +2506,13 @@
//#define VARIABLE_G0_FEEDRATE // The G0 feedrate is set by F in G0 motion mode
#endif
+/**
+ * Startup commands
+ *
+ * Execute certain G-code commands immediately after power-on.
+ */
+//#define STARTUP_COMMANDS "M17 Z"
+
/**
* G-code Macros
*
@@ -2181,7 +2537,7 @@
#define CommBedTmp "65"
#if ENABLED(DUAL_Z)
- #define ALIGN_CMD "G34I3\n"
+ #define ALIGN_CMD "G34I20\n"
#else
#define ALIGN_CMD ""
#endif
@@ -2193,7 +2549,7 @@
#endif
#define USER_DESC_2 "PID Tune"
- #define USER_GCODE_2 "M106 S128 \n M303 C8 S225 E1 U \n M500 \n M117 PID Tune Done"
+ #define USER_GCODE_2 "M106 S128 \n M303 C8 S225 E0 U \n M500 \n M117 PID Tune Done"
#define USER_DESC_3 "Prep for Z Adjust"
#define USER_GCODE_3 "M190 S" CommBedTmp" \n M104 S235 \n G28 \n G29 L1 \n G1 X100 Y 100 \n G1 Z0"
@@ -2224,10 +2580,6 @@
#define HOST_PROMPT_SUPPORT
#endif
-//===========================================================================
-//====================== I2C Position Encoder Settings ======================
-//===========================================================================
-
/**
* I2C position encoders for closed loop control.
* Developed by Chris Barr at Aus3D.
@@ -2308,6 +2660,22 @@
#endif // I2C_POSITION_ENCODERS
+/**
+ * Analog Joystick(s)
+ */
+//#define JOYSTICK
+#if ENABLED(JOYSTICK)
+ #define JOY_X_PIN 5 // RAMPS: Suggested pin A5 on AUX2
+ #define JOY_Y_PIN 10 // RAMPS: Suggested pin A10 on AUX2
+ #define JOY_Z_PIN 12 // RAMPS: Suggested pin A12 on AUX2
+ #define JOY_EN_PIN 44 // RAMPS: Suggested pin D44 on AUX2
+
+ // Use M119 to find reasonable values after connecting your hardware:
+ #define JOY_X_LIMITS { 5600, 8190-100, 8190+100, 10800 } // min, deadzone start, deadzone end, max
+ #define JOY_Y_LIMITS { 5600, 8250-100, 8250+100, 11000 }
+ #define JOY_Z_LIMITS { 4800, 8080-100, 8080+100, 11550 }
+#endif
+
/**
* MAX7219 Debug Matrix
*
@@ -2326,6 +2694,7 @@
#define MAX7219_ROTATE 0 // Rotate the display clockwise (in multiples of +/- 90°)
// connector at: right=0 bottom=-90 top=90 left=180
//#define MAX7219_REVERSE_ORDER // The individual LED matrix units may be in reversed order
+ //#define MAX7219_SIDE_BY_SIDE // Big chip+matrix boards can be chained side-by-side
/**
* Sample debug features
@@ -2436,7 +2805,7 @@
/**
* M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/
-#define PINS_DEBUGGING
+//#define PINS_DEBUGGING
// Enable Marlin dev mode which adds some special commands
//#define MARLIN_DEV_MODE
diff --git a/Marlin/Makefile b/Marlin/Makefile
index acf9c94c71..d765fc19da 100644
--- a/Marlin/Makefile
+++ b/Marlin/Makefile
@@ -122,169 +122,213 @@ ifeq ($(HARDWARE_MOTHERBOARD),0)
#
# MEGA/RAMPS up to 1.2
-else ifeq ($(HARDWARE_MOTHERBOARD),3)
+else ifeq ($(HARDWARE_MOTHERBOARD),1000)
# RAMPS 1.3 (Power outputs: Hotend, Fan, Bed)
-else ifeq ($(HARDWARE_MOTHERBOARD),33)
+else ifeq ($(HARDWARE_MOTHERBOARD),1010)
# RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Bed)
-else ifeq ($(HARDWARE_MOTHERBOARD),34)
+else ifeq ($(HARDWARE_MOTHERBOARD),1011)
# RAMPS 1.3 (Power outputs: Hotend, Fan0, Fan1)
-else ifeq ($(HARDWARE_MOTHERBOARD),35)
+else ifeq ($(HARDWARE_MOTHERBOARD),1012)
# RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Fan)
-else ifeq ($(HARDWARE_MOTHERBOARD),36)
+else ifeq ($(HARDWARE_MOTHERBOARD),1013)
# RAMPS 1.3 (Power outputs: Spindle, Controller Fan)
-else ifeq ($(HARDWARE_MOTHERBOARD),38)
+else ifeq ($(HARDWARE_MOTHERBOARD),1014)
# RAMPS 1.4 (Power outputs: Hotend, Fan, Bed)
-else ifeq ($(HARDWARE_MOTHERBOARD),43)
+else ifeq ($(HARDWARE_MOTHERBOARD),1020)
# RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Bed)
-else ifeq ($(HARDWARE_MOTHERBOARD),44)
+else ifeq ($(HARDWARE_MOTHERBOARD),1021)
# RAMPS 1.4 (Power outputs: Hotend, Fan0, Fan1)
-else ifeq ($(HARDWARE_MOTHERBOARD),45)
+else ifeq ($(HARDWARE_MOTHERBOARD),1022)
# RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Fan)
-else ifeq ($(HARDWARE_MOTHERBOARD),46)
+else ifeq ($(HARDWARE_MOTHERBOARD),1023)
# RAMPS 1.4 (Power outputs: Spindle, Controller Fan)
-else ifeq ($(HARDWARE_MOTHERBOARD),48)
+else ifeq ($(HARDWARE_MOTHERBOARD),1024)
# RAMPS Plus 3DYMY (Power outputs: Hotend, Fan, Bed)
-else ifeq ($(HARDWARE_MOTHERBOARD),143)
+else ifeq ($(HARDWARE_MOTHERBOARD),1030)
# RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Bed)
-else ifeq ($(HARDWARE_MOTHERBOARD),144)
+else ifeq ($(HARDWARE_MOTHERBOARD),1031)
# RAMPS Plus 3DYMY (Power outputs: Hotend, Fan0, Fan1)
-else ifeq ($(HARDWARE_MOTHERBOARD),145)
+else ifeq ($(HARDWARE_MOTHERBOARD),1032)
# RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Fan)
-else ifeq ($(HARDWARE_MOTHERBOARD),146)
+else ifeq ($(HARDWARE_MOTHERBOARD),1033)
# RAMPS Plus 3DYMY (Power outputs: Spindle, Controller Fan)
-else ifeq ($(HARDWARE_MOTHERBOARD),148)
+else ifeq ($(HARDWARE_MOTHERBOARD),1034)
#
# RAMPS Derivatives - ATmega1280, ATmega2560
#
# 3Drag Controller
-else ifeq ($(HARDWARE_MOTHERBOARD),77)
+else ifeq ($(HARDWARE_MOTHERBOARD),1100)
# Velleman K8200 Controller (derived from 3Drag Controller)
-else ifeq ($(HARDWARE_MOTHERBOARD),78)
+else ifeq ($(HARDWARE_MOTHERBOARD),1101)
# Velleman K8400 Controller (derived from 3Drag Controller)
-else ifeq ($(HARDWARE_MOTHERBOARD),79)
+else ifeq ($(HARDWARE_MOTHERBOARD),1102)
# 2PrintBeta BAM&DICE with STK drivers
-else ifeq ($(HARDWARE_MOTHERBOARD),401)
+else ifeq ($(HARDWARE_MOTHERBOARD),1103)
# 2PrintBeta BAM&DICE Due with STK drivers
-else ifeq ($(HARDWARE_MOTHERBOARD),402)
+else ifeq ($(HARDWARE_MOTHERBOARD),1104)
# MKS BASE v1.0
-else ifeq ($(HARDWARE_MOTHERBOARD),40)
+else ifeq ($(HARDWARE_MOTHERBOARD),1105)
+# MKS v1.4 with A4982 stepper drivers
+else ifeq ($(HARDWARE_MOTHERBOARD),1106)
# MKS v1.5 with Allegro A4982 stepper drivers
-else ifeq ($(HARDWARE_MOTHERBOARD),405)
+else ifeq ($(HARDWARE_MOTHERBOARD),1107)
# MKS BASE 1.0 with Heroic HR4982 stepper drivers
-else ifeq ($(HARDWARE_MOTHERBOARD),41)
+else ifeq ($(HARDWARE_MOTHERBOARD),1108)
# MKS GEN v1.3 or 1.4
-else ifeq ($(HARDWARE_MOTHERBOARD),47)
+else ifeq ($(HARDWARE_MOTHERBOARD),1109)
# MKS GEN L
-else ifeq ($(HARDWARE_MOTHERBOARD),53)
+else ifeq ($(HARDWARE_MOTHERBOARD),1110)
# zrib V2.0 control board (Chinese knock off RAMPS replica)
-else ifeq ($(HARDWARE_MOTHERBOARD),504)
+else ifeq ($(HARDWARE_MOTHERBOARD),1111)
+# Bigtreetech or BIQU KFB2.0
+else ifeq ($(HARDWARE_MOTHERBOARD),1112)
# Felix 2.0+ Electronics Board (RAMPS like)
-else ifeq ($(HARDWARE_MOTHERBOARD),37)
+else ifeq ($(HARDWARE_MOTHERBOARD),1113)
# Invent-A-Part RigidBoard
-else ifeq ($(HARDWARE_MOTHERBOARD),42)
+else ifeq ($(HARDWARE_MOTHERBOARD),1114)
# Invent-A-Part RigidBoard V2
-else ifeq ($(HARDWARE_MOTHERBOARD),52)
+else ifeq ($(HARDWARE_MOTHERBOARD),1115)
# Sainsmart 2-in-1 board
-else ifeq ($(HARDWARE_MOTHERBOARD),49)
+else ifeq ($(HARDWARE_MOTHERBOARD),1116)
# Ultimaker
-else ifeq ($(HARDWARE_MOTHERBOARD),7)
+else ifeq ($(HARDWARE_MOTHERBOARD),1117)
# Ultimaker (Older electronics. Pre 1.5.4. This is rare)
-else ifeq ($(HARDWARE_MOTHERBOARD),71)
+else ifeq ($(HARDWARE_MOTHERBOARD),1118)
MCU ?= atmega1280
+
# Azteeg X3
-else ifeq ($(HARDWARE_MOTHERBOARD),67)
+else ifeq ($(HARDWARE_MOTHERBOARD),1119)
# Azteeg X3 Pro
-else ifeq ($(HARDWARE_MOTHERBOARD),68)
+else ifeq ($(HARDWARE_MOTHERBOARD),1120)
# Ultimainboard 2.x (Uses TEMP_SENSOR 20)
-else ifeq ($(HARDWARE_MOTHERBOARD),72)
+else ifeq ($(HARDWARE_MOTHERBOARD),1121)
# Rumba
-else ifeq ($(HARDWARE_MOTHERBOARD),80)
+else ifeq ($(HARDWARE_MOTHERBOARD),1122)
# Raise3D Rumba
-else ifeq ($(HARDWARE_MOTHERBOARD),333)
+else ifeq ($(HARDWARE_MOTHERBOARD),1123)
+# Rapide Lite RL200 Rumba
+else ifeq ($(HARDWARE_MOTHERBOARD),1124)
# Formbot T-Rex 2 Plus
-else ifeq ($(HARDWARE_MOTHERBOARD),95)
+else ifeq ($(HARDWARE_MOTHERBOARD),1125)
# Formbot T-Rex 3
-else ifeq ($(HARDWARE_MOTHERBOARD),96)
+else ifeq ($(HARDWARE_MOTHERBOARD),1126)
# Formbot Raptor
-else ifeq ($(HARDWARE_MOTHERBOARD),97)
+else ifeq ($(HARDWARE_MOTHERBOARD),1127)
# Formbot Raptor 2
-else ifeq ($(HARDWARE_MOTHERBOARD),98)
+else ifeq ($(HARDWARE_MOTHERBOARD),1128)
# bq ZUM Mega 3D
-else ifeq ($(HARDWARE_MOTHERBOARD),503)
+else ifeq ($(HARDWARE_MOTHERBOARD),1129)
# MakeBoard Mini v2.1.2 is a control board sold by MicroMake
-else ifeq ($(HARDWARE_MOTHERBOARD),431)
+else ifeq ($(HARDWARE_MOTHERBOARD),1130)
# TriGorilla Anycubic version 1.3 based on RAMPS EFB
-else ifeq ($(HARDWARE_MOTHERBOARD),343)
+else ifeq ($(HARDWARE_MOTHERBOARD),1131)
# TriGorilla Anycubic version 1.4 based on RAMPS EFB
-else ifeq ($(HARDWARE_MOTHERBOARD),443)
+else ifeq ($(HARDWARE_MOTHERBOARD),1132)
+# TriGorilla Anycubic version 1.4 Rev 1.1
+else ifeq ($(HARDWARE_MOTHERBOARD),1133)
# Creality: Ender-4, CR-8
-else ifeq ($(HARDWARE_MOTHERBOARD),243)
+else ifeq ($(HARDWARE_MOTHERBOARD),1134)
# Creality: CR10S, CR20, CR-X
-else ifeq ($(HARDWARE_MOTHERBOARD),244)
-# Fysetc F6
-else ifeq ($(HARDWARE_MOTHERBOARD),541)
+else ifeq ($(HARDWARE_MOTHERBOARD),1135)
+# Dagoma F5
+else ifeq ($(HARDWARE_MOTHERBOARD),1136)
+# FYSETC F6
+else ifeq ($(HARDWARE_MOTHERBOARD),1137)
# Duplicator i3 Plus
-else ifeq ($(HARDWARE_MOTHERBOARD),31)
+else ifeq ($(HARDWARE_MOTHERBOARD),1138)
# VORON
-else ifeq ($(HARDWARE_MOTHERBOARD),441)
+else ifeq ($(HARDWARE_MOTHERBOARD),1139)
+# TRONXY V3 1.0
+else ifeq ($(HARDWARE_MOTHERBOARD),1140)
+# Z-Bolt X Series
+else ifeq ($(HARDWARE_MOTHERBOARD),1141)
+# TT OSCAR
+else ifeq ($(HARDWARE_MOTHERBOARD),1142)
+# Overlord/Overlord Pro
+else ifeq ($(HARDWARE_MOTHERBOARD),1143)
+# ADIMLab Gantry v1
+else ifeq ($(HARDWARE_MOTHERBOARD),1144)
+# ADIMLab Gantry v2
+else ifeq ($(HARDWARE_MOTHERBOARD),1145)
+
+#
+# RAMBo and derivatives
+#
+
+# Rambo
+else ifeq ($(HARDWARE_MOTHERBOARD),1200)
+# Mini-Rambo
+else ifeq ($(HARDWARE_MOTHERBOARD),1201)
+# Mini-Rambo 1.0a
+else ifeq ($(HARDWARE_MOTHERBOARD),1202)
+# Einsy Rambo
+else ifeq ($(HARDWARE_MOTHERBOARD),1203)
+# Einsy Retro
+else ifeq ($(HARDWARE_MOTHERBOARD),1204)
+# abee Scoovo X9H
+else ifeq ($(HARDWARE_MOTHERBOARD),1205)
#
# Other ATmega1280, ATmega2560
#
# Cartesio CN Controls V11
-else ifeq ($(HARDWARE_MOTHERBOARD),111)
+else ifeq ($(HARDWARE_MOTHERBOARD),1300)
# Cartesio CN Controls V12
-else ifeq ($(HARDWARE_MOTHERBOARD),112)
+else ifeq ($(HARDWARE_MOTHERBOARD),1301)
+# Cartesio CN Controls V15
+else ifeq ($(HARDWARE_MOTHERBOARD),1302)
# Cheaptronic v1.0
-else ifeq ($(HARDWARE_MOTHERBOARD),2)
+else ifeq ($(HARDWARE_MOTHERBOARD),1303)
# Cheaptronic v2.0
-else ifeq ($(HARDWARE_MOTHERBOARD),21)
+else ifeq ($(HARDWARE_MOTHERBOARD),1304)
# Makerbot Mightyboard Revision E
-else ifeq ($(HARDWARE_MOTHERBOARD),200)
+else ifeq ($(HARDWARE_MOTHERBOARD),1305)
# Megatronics
-else ifeq ($(HARDWARE_MOTHERBOARD),70)
+else ifeq ($(HARDWARE_MOTHERBOARD),1306)
# Megatronics v2.0
-else ifeq ($(HARDWARE_MOTHERBOARD),701)
+else ifeq ($(HARDWARE_MOTHERBOARD),1307)
# Megatronics v3.0
-else ifeq ($(HARDWARE_MOTHERBOARD),703)
+else ifeq ($(HARDWARE_MOTHERBOARD),1308)
# Megatronics v3.1
-else ifeq ($(HARDWARE_MOTHERBOARD),704)
-# Rambo
-else ifeq ($(HARDWARE_MOTHERBOARD),301)
-# Mini-Rambo
-else ifeq ($(HARDWARE_MOTHERBOARD),302)
-# Mini-Rambo 1.0a
-else ifeq ($(HARDWARE_MOTHERBOARD),303)
-# Einsy Rambo
-else ifeq ($(HARDWARE_MOTHERBOARD),304)
-# Einsy Retro
-else ifeq ($(HARDWARE_MOTHERBOARD),305)
+else ifeq ($(HARDWARE_MOTHERBOARD),1309)
+# Megatronics v3.2
+else ifeq ($(HARDWARE_MOTHERBOARD),1310)
# Elefu Ra Board (v3)
-else ifeq ($(HARDWARE_MOTHERBOARD),21)
+else ifeq ($(HARDWARE_MOTHERBOARD),1311)
# Leapfrog
-else ifeq ($(HARDWARE_MOTHERBOARD),999)
+else ifeq ($(HARDWARE_MOTHERBOARD),1312)
# Mega controller
-else ifeq ($(HARDWARE_MOTHERBOARD),310)
-# abee Scoovo X9H
-else ifeq ($(HARDWARE_MOTHERBOARD),321)
+else ifeq ($(HARDWARE_MOTHERBOARD),1313)
+# Geeetech GT2560 Rev B for Mecreator2
+else ifeq ($(HARDWARE_MOTHERBOARD),1314)
# Geeetech GT2560 Rev. A
-else ifeq ($(HARDWARE_MOTHERBOARD),74)
+else ifeq ($(HARDWARE_MOTHERBOARD),1315)
# Geeetech GT2560 Rev. A+ (with auto level probe)
-else ifeq ($(HARDWARE_MOTHERBOARD),75)
+else ifeq ($(HARDWARE_MOTHERBOARD),1316)
+# Geeetech GT2560 Rev B for A10(M/D)
+else ifeq ($(HARDWARE_MOTHERBOARD),1317)
+# Geeetech GT2560 Rev B for A20(M/D)
+else ifeq ($(HARDWARE_MOTHERBOARD),1318)
+# Einstart retrofit
+else ifeq ($(HARDWARE_MOTHERBOARD),1319)
+# Wanhao 0ne+ i3 Mini
+else ifeq ($(HARDWARE_MOTHERBOARD),1320)
#
# ATmega1281, ATmega2561
#
-else ifeq ($(HARDWARE_MOTHERBOARD),702)
+# Minitronics v1.0/1.1
+else ifeq ($(HARDWARE_MOTHERBOARD),1400)
MCU ?= atmega1281
-else ifeq ($(HARDWARE_MOTHERBOARD),25)
+# Silvergate v1.0
+else ifeq ($(HARDWARE_MOTHERBOARD),1401)
MCU ?= atmega1281
#
@@ -292,43 +336,43 @@ else ifeq ($(HARDWARE_MOTHERBOARD),25)
#
# Sanguinololu < 1.2
-else ifeq ($(HARDWARE_MOTHERBOARD),6)
+else ifeq ($(HARDWARE_MOTHERBOARD),1500)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Sanguinololu 1.2 and above
-else ifeq ($(HARDWARE_MOTHERBOARD),62)
+else ifeq ($(HARDWARE_MOTHERBOARD),1501)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Melzi
-else ifeq ($(HARDWARE_MOTHERBOARD),63)
+else ifeq ($(HARDWARE_MOTHERBOARD),1502)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Melzi with ATmega1284 (MaKr3d version)
-else ifeq ($(HARDWARE_MOTHERBOARD),66)
+else ifeq ($(HARDWARE_MOTHERBOARD),1503)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Melzi Creality3D board (for CR-10 etc)
-else ifeq ($(HARDWARE_MOTHERBOARD),89)
+else ifeq ($(HARDWARE_MOTHERBOARD),1504)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Melzi Malyan M150 board
-else ifeq ($(HARDWARE_MOTHERBOARD),92)
+else ifeq ($(HARDWARE_MOTHERBOARD),1505)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Tronxy X5S
-else ifeq ($(HARDWARE_MOTHERBOARD),505)
+else ifeq ($(HARDWARE_MOTHERBOARD),1506)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# STB V1.1
-else ifeq ($(HARDWARE_MOTHERBOARD),64)
+else ifeq ($(HARDWARE_MOTHERBOARD),1507)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Azteeg X1
-else ifeq ($(HARDWARE_MOTHERBOARD),65)
+else ifeq ($(HARDWARE_MOTHERBOARD),1508)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Anet 1.0 (Melzi clone)
-else ifeq ($(HARDWARE_MOTHERBOARD),69)
+else ifeq ($(HARDWARE_MOTHERBOARD),1509)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
@@ -337,51 +381,51 @@ else ifeq ($(HARDWARE_MOTHERBOARD),69)
#
# Gen3 Monolithic Electronics
-else ifeq ($(HARDWARE_MOTHERBOARD),22)
+else ifeq ($(HARDWARE_MOTHERBOARD),1600)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Gen3+
-else ifeq ($(HARDWARE_MOTHERBOARD),9)
+else ifeq ($(HARDWARE_MOTHERBOARD),1601)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Gen6
-else ifeq ($(HARDWARE_MOTHERBOARD),5)
+else ifeq ($(HARDWARE_MOTHERBOARD),1602)
HARDWARE_VARIANT ?= Gen6
MCU ?= atmega644p
# Gen6 deluxe
-else ifeq ($(HARDWARE_MOTHERBOARD),51)
+else ifeq ($(HARDWARE_MOTHERBOARD),1603)
HARDWARE_VARIANT ?= Gen6
MCU ?= atmega644p
# Gen7 custom (Alfons3 Version)
-else ifeq ($(HARDWARE_MOTHERBOARD),10)
+else ifeq ($(HARDWARE_MOTHERBOARD),1604)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega644
F_CPU ?= 20000000
# Gen7 v1.1, v1.2
-else ifeq ($(HARDWARE_MOTHERBOARD),11)
+else ifeq ($(HARDWARE_MOTHERBOARD),1605)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega644p
F_CPU ?= 20000000
# Gen7 v1.3
-else ifeq ($(HARDWARE_MOTHERBOARD),12)
+else ifeq ($(HARDWARE_MOTHERBOARD),1606)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega644p
F_CPU ?= 20000000
# Gen7 v1.4
-else ifeq ($(HARDWARE_MOTHERBOARD),13)
+else ifeq ($(HARDWARE_MOTHERBOARD),1607)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega1284p
F_CPU ?= 20000000
# Alpha OMCA board
-else ifeq ($(HARDWARE_MOTHERBOARD),90)
+else ifeq ($(HARDWARE_MOTHERBOARD),1608)
HARDWARE_VARIANT ?= SanguinoA
MCU ?= atmega644
# Final OMCA board
-else ifeq ($(HARDWARE_MOTHERBOARD),91)
+else ifeq ($(HARDWARE_MOTHERBOARD),1609)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Sethi 3D_1
-else ifeq ($(HARDWARE_MOTHERBOARD),20)
+else ifeq ($(HARDWARE_MOTHERBOARD),1610)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
@@ -390,46 +434,46 @@ else ifeq ($(HARDWARE_MOTHERBOARD),20)
#
# Teensylu
-else ifeq ($(HARDWARE_MOTHERBOARD),8)
+else ifeq ($(HARDWARE_MOTHERBOARD),1700)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Printrboard (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),81)
+else ifeq ($(HARDWARE_MOTHERBOARD),1701)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Printrboard Revision F (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),811)
+else ifeq ($(HARDWARE_MOTHERBOARD),1702)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Brainwave (AT90USB646)
-else ifeq ($(HARDWARE_MOTHERBOARD),82)
+else ifeq ($(HARDWARE_MOTHERBOARD),1703)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb646
# Brainwave Pro (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),83)
+else ifeq ($(HARDWARE_MOTHERBOARD),1704)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# SAV Mk-I (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),84)
+else ifeq ($(HARDWARE_MOTHERBOARD),1705)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Teensy++2.0 (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),85)
+else ifeq ($(HARDWARE_MOTHERBOARD),1706)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# 5DPrint D8 Driver Board
-else ifeq ($(HARDWARE_MOTHERBOARD),88)
+else ifeq ($(HARDWARE_MOTHERBOARD),1707)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# UltiMachine Archim1 (with DRV8825 drivers)
-else ifeq ($(HARDWARE_MOTHERBOARD),1591)
+else ifeq ($(HARDWARE_MOTHERBOARD),3023)
HARDWARE_VARIANT ?= archim
MCPU = cortex-m3
F_CPU = 84000000L
IS_MCU = 0
# UltiMachine Archim2 (with TMC2130 drivers)
-else ifeq ($(HARDWARE_MOTHERBOARD),1592)
+else ifeq ($(HARDWARE_MOTHERBOARD),3024)
HARDWARE_VARIANT ?= archim
MCPU = cortex-m3
F_CPU = 84000000L
@@ -576,7 +620,7 @@ ifeq ($(U8GLIB), 1)
endif
ifeq ($(TMC), 1)
- LIB_CXXSRC += TMCStepper.cpp COOLCONF.cpp DRV_STATUS.cpp IHOLD_IRUN.cpp CHOPCONF.cpp GCONF.cpp PWMCONF.cpp DRV_CONF.cpp DRVCONF.cpp DRVCTRL.cpp DRVSTATUS.cpp ENCMODE.cpp RAMP_STAT.cpp SGCSCONF.cpp SHORT_CONF.cpp SMARTEN.cpp SW_MODE.cpp SW_SPI.cpp TMC2130Stepper.cpp TMC2208Stepper.cpp TMC2660Stepper.cpp TMC5130Stepper.cpp TMC5160Stepper.cpp
+ LIB_CXXSRC += TMCStepper.cpp COOLCONF.cpp DRV_STATUS.cpp IHOLD_IRUN.cpp CHOPCONF.cpp GCONF.cpp PWMCONF.cpp DRV_CONF.cpp DRVCONF.cpp DRVCTRL.cpp DRVSTATUS.cpp ENCMODE.cpp RAMP_STAT.cpp SGCSCONF.cpp SHORT_CONF.cpp SMARTEN.cpp SW_MODE.cpp SW_SPI.cpp TMC2130Stepper.cpp TMC2208Stepper.cpp TMC2209Stepper.cpp TMC2660Stepper.cpp TMC5130Stepper.cpp TMC5160Stepper.cpp
endif
ifeq ($(RELOC_WORKAROUND), 1)
@@ -647,9 +691,9 @@ LIBWARN = -w -Wno-packed-bitfield-compat
CSTANDARD = -std=gnu99
CXXSTANDARD = -std=gnu++11
CDEBUG = -g$(DEBUG)
-CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas
-CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas
-CTUNING = -fsigned-char -funsigned-bitfields -fpack-struct -fno-exceptions \
+CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter
+CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter
+CTUNING = -fsigned-char -funsigned-bitfields -fno-exceptions \
-fshort-enums -ffunction-sections -fdata-sections
ifneq ($(HARDWARE_MOTHERBOARD),)
CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD}
@@ -663,7 +707,7 @@ ASFLAGS := $(CDEFS)
ifeq ($(HARDWARE_VARIANT), archim)
LD_PREFIX = -Wl,--gc-sections,-Map,Marlin.ino.map,--cref,--check-sections,--entry=Reset_Handler,--unresolved-symbols=report-all,--warn-common,--warn-section-align
LD_SUFFIX = $(LDLIBS)
- LDFLAGS = -lm -gcc -T$(LDSCRIPT) -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid
+ LDFLAGS = -lm -T$(LDSCRIPT) -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid
else
LD_PREFIX = -Wl,--gc-sections,--relax
LDFLAGS = -lm
@@ -740,7 +784,7 @@ ifeq (${AVRDUDE_PROGRAMMER}, arduino)
stty -hup < $(UPLOAD_PORT); true
endif
- # Display size of file.
+# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex
ELFSIZE = $(SIZE) $(SIZE_FLAGS) $(BUILD_DIR)/$(TARGET).elf; \
$(SIZE) $(BUILD_DIR)/$(TARGET).elf
@@ -790,7 +834,7 @@ extcoff: $(TARGET).elf
.elf.sym:
$(NM) -n $< > $@
- # Link: create ELF output file from library.
+# Link: create ELF output file from library.
$(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h
$(Pecho) " CXX $@"
diff --git a/Marlin/Marlin.ino b/Marlin/Marlin.ino
index 842b2a14b9..ae5bca1dfe 100644
--- a/Marlin/Marlin.ino
+++ b/Marlin/Marlin.ino
@@ -3,7 +3,7 @@
Marlin Firmware
- (c) 2011-2018 MarlinFirmware
+ (c) 2011-2019 MarlinFirmware
Portions of Marlin are (c) by their respective authors.
All code complies with GPLv2 and/or GPLv3
diff --git a/Marlin/Version.h b/Marlin/Version.h
new file mode 100644
index 0000000000..3cff3b6629
--- /dev/null
+++ b/Marlin/Version.h
@@ -0,0 +1,76 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+////////////////////////////
+// VENDOR VERSION EXAMPLE //
+////////////////////////////
+
+/**
+ * Marlin release version identifier
+ */
+#define SHORT_BUILD_VERSION "2.0.x_SX4H"
+
+/**
+ * Verbose version identifier which should contain a reference to the location
+ * from where the binary was downloaded or the source code was compiled.
+ */
+#define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION " TM3D"
+
+/**
+ * The STRING_DISTRIBUTION_DATE represents when the binary file was built,
+ * here we define this default string as the date where the latest release
+ * version was tagged.
+ */
+#define STRING_DISTRIBUTION_DATE "2019-10-19"
+
+/**
+ * Defines a generic printer name to be output to the LCD after booting Marlin.
+ */
+#define MACHINE_NAME "TM3D SX4"
+
+/**
+ * The SOURCE_CODE_URL is the location where users will find the Marlin Source
+ * Code which is installed on the device. In most cases —unless the manufacturer
+ * has a distinct Github fork— the Source Code URL should just be the main
+ * Marlin repository.
+ */
+#define SOURCE_CODE_URL "https://github.com/InsanityAutomation/Marlin/tree/TM_SX4_2.0"
+
+/**
+ * Default generic printer UUID.
+ */
+//#define DEFAULT_MACHINE_UUID "cede2a2f-41a2-4748-9b12-c55c62f367ff"
+
+/**
+ * The WEBSITE_URL is the location where users can get more information such as
+ * documentation about a specific Marlin release.
+ */
+#define WEBSITE_URL "tinymachines3d.com"
+
+/**
+ * Set the vendor info the serial USB interface, if changable
+ * Currently only supported by DUE platform
+ */
+//#define USB_DEVICE_VENDOR_ID 0x0000
+//#define USB_DEVICE_PRODUCT_ID 0x0000
+//#define USB_DEVICE_MANUFACTURE_NAME WEBSITE_URL
diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h
new file mode 100644
index 0000000000..cecdd8b67b
--- /dev/null
+++ b/Marlin/src/HAL/HAL.h
@@ -0,0 +1,32 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include "platforms.h"
+
+#include HAL_PATH(.,HAL.h)
+
+inline void watchdog_refresh() {
+ #if ENABLED(USE_WATCHDOG)
+ HAL_watchdog_refresh();
+ #endif
+}
diff --git a/Marlin/src/HAL/HAL_AVR/HAL.cpp b/Marlin/src/HAL/HAL_AVR/HAL.cpp
index c240c787ac..4a10f73dcf 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,50 +22,35 @@
#ifdef __AVR__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
//uint8_t MCUSR;
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
+
+void HAL_init() {
+ // Init Servo Pins
+ #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
+ #if HAS_SERVO_0
+ INIT_SERVO(0);
+ #endif
+ #if HAS_SERVO_1
+ INIT_SERVO(1);
+ #endif
+ #if HAS_SERVO_2
+ INIT_SERVO(2);
+ #endif
+ #if HAS_SERVO_3
+ INIT_SERVO(3);
+ #endif
+}
#if ENABLED(SDSUPPORT)
diff --git a/Marlin/src/HAL/HAL_AVR/HAL.h b/Marlin/src/HAL/HAL_AVR/HAL.h
index 9dc5e95c55..246353677f 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL.h
+++ b/Marlin/src/HAL/HAL_AVR/HAL.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
@@ -18,33 +18,29 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include
-
#include "../shared/Marduino.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_AVR.h"
-#include "watchdog_AVR.h"
-#include "math_AVR.h"
+#include "fastio.h"
+#include "watchdog.h"
+#include "math.h"
#ifdef USBCON
#include "HardwareSerial.h"
#else
+ #define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion
#include "MarlinSerial.h"
#endif
+#include
#include
#include
#include
#include
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//#define analogInputToDigitalPin(IO) IO
@@ -59,20 +55,21 @@
// On AVR this is in math.h?
//#define square(x) ((x)*(x))
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef uint16_t hal_timer_t;
#define HAL_TIMER_TYPE_MAX 0xFFFF
typedef int8_t pin_t;
+#define SHARED_SERVOS HAS_SERVOS
#define HAL_SERVO_LIB Servo
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
//extern uint8_t MCUSR;
@@ -104,20 +101,25 @@ typedef int8_t pin_t;
#endif
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-//void cli(void);
+void HAL_init();
+
+//void cli();
//void _delay_ms(const int delay);
-inline void HAL_clear_reset_source(void) { MCUSR = 0; }
-inline uint8_t HAL_get_reset_source(void) { return MCUSR; }
+inline void HAL_clear_reset_source() { MCUSR = 0; }
+inline uint8_t HAL_get_reset_source() { return MCUSR; }
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
extern "C" {
- int freeMemory(void);
+ int freeMemory();
}
+#pragma GCC diagnostic pop
// timers
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
@@ -144,8 +146,7 @@ extern "C" {
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
-FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
- UNUSED(frequency);
+FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
switch (timer_num) {
case STEP_TIMER_NUM:
// waveform generation = 0100 = CTC
@@ -197,9 +198,9 @@ FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t freque
/* 18 cycles maximum latency */
#define HAL_STEP_TIMER_ISR() \
-extern "C" void TIMER1_COMPA_vect (void) __attribute__ ((signal, naked, used, externally_visible)); \
-extern "C" void TIMER1_COMPA_vect_bottom (void) asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
-void TIMER1_COMPA_vect (void) { \
+extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal, naked, used, externally_visible)); \
+extern "C" void TIMER1_COMPA_vect_bottom() asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
+void TIMER1_COMPA_vect() { \
__asm__ __volatile__ ( \
A("push r16") /* 2 Save R16 */ \
A("in r16, __SREG__") /* 1 Get SREG */ \
@@ -266,13 +267,13 @@ void TIMER1_COMPA_vect (void) { \
: \
); \
} \
-void TIMER1_COMPA_vect_bottom(void)
+void TIMER1_COMPA_vect_bottom()
/* 14 cycles maximum latency */
#define HAL_TEMP_TIMER_ISR() \
-extern "C" void TIMER0_COMPB_vect (void) __attribute__ ((signal, naked, used, externally_visible)); \
-extern "C" void TIMER0_COMPB_vect_bottom(void) asm ("TIMER0_COMPB_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
-void TIMER0_COMPB_vect (void) { \
+extern "C" void TIMER0_COMPB_vect() __attribute__ ((signal, naked, used, externally_visible)); \
+extern "C" void TIMER0_COMPB_vect_bottom() asm ("TIMER0_COMPB_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
+void TIMER0_COMPB_vect() { \
__asm__ __volatile__ ( \
A("push r16") /* 2 Save R16 */ \
A("in r16, __SREG__") /* 1 Get SREG */ \
@@ -332,7 +333,7 @@ void TIMER0_COMPB_vect (void) { \
: \
); \
} \
-void TIMER0_COMPB_vect_bottom(void)
+void TIMER0_COMPB_vect_bottom()
// ADC
#ifdef DIDR2
@@ -341,7 +342,7 @@ void TIMER0_COMPB_vect_bottom(void)
#define HAL_ANALOG_SELECT(pin) do{ SBI(DIDR0, pin); }while(0)
#endif
-inline void HAL_adc_init(void) {
+inline void HAL_adc_init() {
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
DIDR0 = 0;
#ifdef DIDR2
diff --git a/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp b/Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
similarity index 77%
rename from Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
index 592a4bca68..7a0f7246ee 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,56 +21,41 @@
*/
/**
- * Originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
+ * Adapted from Arduino Sd2Card Library
+ * Copyright (c) 2009 by William Greiman
*/
/**
- * Description: HAL for AVR - SPI functions
+ * HAL for AVR - SPI functions
*/
#ifdef __AVR__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-void spiBegin (void) {
- SET_OUTPUT(SS_PIN);
- WRITE(SS_PIN, HIGH);
+void spiBegin() {
+ OUT_WRITE(SS_PIN, HIGH);
SET_OUTPUT(SCK_PIN);
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);
#if DISABLED(SOFTWARE_SPI)
// SS must be in output mode even it is not chip select
- SET_OUTPUT(SS_PIN);
+ //SET_OUTPUT(SS_PIN);
// set SS high - may be chip select for another SPI device
- #if SET_SPI_SS_HIGH
- WRITE(SS_PIN, HIGH);
- #endif // SET_SPI_SS_HIGH
+ //#if SET_SPI_SS_HIGH
+ //WRITE(SS_PIN, HIGH);
+ //#endif
// set a default rate
spiInit(1);
- #endif // SOFTWARE_SPI
+ #endif
}
+#if NONE(SOFTWARE_SPI, FORCE_SOFT_SPI)
-#if DISABLED(SOFTWARE_SPI, FORCE_SOFT_SPI)
-
- //------------------------------------------------------------------------------
+ // ------------------------
// Hardware SPI
- //------------------------------------------------------------------------------
+ // ------------------------
// make sure SPCR rate is in expected bits
#if (SPR0 != 0 || SPR1 != 1)
@@ -96,7 +81,7 @@ void spiBegin (void) {
}
/** SPI receive a byte */
- uint8_t spiRec(void) {
+ uint8_t spiRec() {
SPDR = 0xFF;
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
return SPDR;
@@ -184,28 +169,27 @@ void spiBegin (void) {
// Invert the SPI2X bit
clockDiv ^= 0x1;
- SPCR = _BV(SPE) | _BV(MSTR) | ((bitOrder == SPI_LSBFIRST) ? _BV(DORD) : 0) |
+ SPCR = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |
(dataMode << CPHA) | ((clockDiv >> 1) << SPR0);
SPSR = clockDiv | 0x01;
}
-#else
+#else // SOFTWARE_SPI || FORCE_SOFT_SPI
- /** nop to tune soft SPI timing */
+ // ------------------------
+ // Software SPI
+ // ------------------------
+
+ // nop to tune soft SPI timing
#define nop asm volatile ("\tnop\n")
- /** Set SPI rate */
- void spiInit(uint8_t spiRate) {
- UNUSED(spiRate); // nothing to do
- }
+ void spiInit(uint8_t) { /* do nothing */ }
- /** Begin SPI transaction, set clock, bit order, data mode */
- void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
- UNUSED(spiBeginTransaction); // nothing to do
- }
+ // Begin SPI transaction, set clock, bit order, data mode
+ void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) { /* do nothing */ }
- /** Soft SPI receive byte */
+ // Soft SPI receive byte
uint8_t spiRec() {
uint8_t data = 0;
// no interrupts during byte receive - about 8µs
@@ -230,13 +214,13 @@ void spiBegin (void) {
return data;
}
- /** Soft SPI read data */
+ // Soft SPI read data
void spiRead(uint8_t* buf, uint16_t nbyte) {
for (uint16_t i = 0; i < nbyte; i++)
buf[i] = spiRec();
}
- /** Soft SPI send byte */
+ // Soft SPI send byte
void spiSend(uint8_t data) {
// no interrupts during byte send - about 8µs
cli();
@@ -257,13 +241,13 @@ void spiBegin (void) {
sei();
}
- /** Soft SPI send block */
+ // Soft SPI send block
void spiSendBlock(uint8_t token, const uint8_t* buf) {
spiSend(token);
for (uint16_t i = 0; i < 512; i++)
spiSend(buf[i]);
}
-#endif // SOFTWARE_SPI, FORCE_SOFT_SPI
+#endif // SOFTWARE_SPI || FORCE_SOFT_SPI
#endif // __AVR__
diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
index 9bc224bd2b..3502aa6b0c 100644
--- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
+++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -271,7 +271,7 @@
// (called with TX irqs disabled)
template
- FORCE_INLINE void MarlinSerial::_tx_udr_empty_irq(void) {
+ FORCE_INLINE void MarlinSerial::_tx_udr_empty_irq() {
if (Cfg::TX_SIZE > 0) {
// Read positions
uint8_t t = tx_buffer.tail;
@@ -363,13 +363,13 @@
}
template
- int MarlinSerial::peek(void) {
+ int MarlinSerial::peek() {
const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail;
return h == t ? -1 : rx_buffer.buffer[t];
}
template
- int MarlinSerial::read(void) {
+ int MarlinSerial::read() {
const ring_buffer_pos_t h = atomic_read_rx_head();
// Read the tail. Main thread owns it, so it is safe to directly read it
@@ -412,13 +412,13 @@
}
template
- typename MarlinSerial::ring_buffer_pos_t MarlinSerial::available(void) {
+ typename MarlinSerial::ring_buffer_pos_t MarlinSerial::available() {
const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail;
return (ring_buffer_pos_t)(Cfg::RX_SIZE + h - t) & (Cfg::RX_SIZE - 1);
}
template
- void MarlinSerial::flush(void) {
+ void MarlinSerial::flush() {
// Set the tail to the head:
// - Read the RX head index in a safe way. (See atomic_read_rx_head.)
@@ -505,7 +505,7 @@
}
template
- void MarlinSerial::flushTX(void) {
+ void MarlinSerial::flushTX() {
if (Cfg::TX_SIZE == 0) {
// No bytes written, no need to flush. This special case is needed since there's
@@ -595,7 +595,7 @@
}
template
- void MarlinSerial::println(void) {
+ void MarlinSerial::println() {
print('\r');
print('\n');
}
diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
index 5ada120c6d..7560d880e3 100644
--- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
+++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -205,18 +205,18 @@
public:
FORCE_INLINE static void store_rxd_char();
- FORCE_INLINE static void _tx_udr_empty_irq(void);
+ FORCE_INLINE static void _tx_udr_empty_irq();
public:
MarlinSerial() {};
static void begin(const long);
static void end();
- static int peek(void);
- static int read(void);
- static void flush(void);
- static ring_buffer_pos_t available(void);
+ static int peek();
+ static int read();
+ static void flush();
+ static ring_buffer_pos_t available();
static void write(const uint8_t c);
- static void flushTX(void);
+ static void flushTX();
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
@@ -245,7 +245,7 @@
static void println(long, int = DEC);
static void println(unsigned long, int = DEC);
static void println(double, int = 2);
- static void println(void);
+ static void println();
operator bool() { return true; }
private:
@@ -275,7 +275,6 @@
#endif // !USBCON
-
#ifdef INTERNAL_SERIAL_PORT
template
struct MarlinInternalSerialCfg {
diff --git a/Marlin/src/HAL/HAL_AVR/SanityCheck.h b/Marlin/src/HAL/HAL_AVR/SanityCheck.h
deleted file mode 100644
index 68bfdc16a0..0000000000
--- a/Marlin/src/HAL/HAL_AVR/SanityCheck.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Test AVR specific configuration values for errors at compile-time.
- */
-
-/**
- * Digipot requirement
- */
- #if ENABLED(DIGIPOT_MCP4018)
- #if !defined(DIGIPOTS_I2C_SDA_X) || !defined(DIGIPOTS_I2C_SDA_Y) || !defined(DIGIPOTS_I2C_SDA_Z) \
- || !defined(DIGIPOTS_I2C_SDA_E0) || !defined(DIGIPOTS_I2C_SDA_E1)
- #error "DIGIPOT_MCP4018 requires DIGIPOTS_I2C_SDA_* pins to be defined."
- #endif
-#endif
-
-/**
- * Checks for FAST PWM
- */
-#if ENABLED(FAST_PWM_FAN) && (ENABLED(USE_OCR2A_AS_TOP) && defined(TCCR2))
- #error "USE_OCR2A_AS_TOP does not apply to devices with a single output TIMER2"
-#endif
-
-/**
- * Sanity checks for Spindle / Laser
- */
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !(WITHIN(SPINDLE_LASER_PWM_PIN, 2, 13) || WITHIN(SPINDLE_LASER_PWM_PIN, 44, 46))
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif SPINDLE_LASER_POWERUP_DELAY < 1
- #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13)
- #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt."
- #elif PIN_EXISTS(X_MAX) && X_MAX_PIN == SPINDLE_LASER_PWM_PIN
- #error "SPINDLE_LASER_PWM pin is in use by X_MAX endstop."
- #elif PIN_EXISTS(X_MIN) && X_MIN_PIN == SPINDLE_LASER_PWM_PIN
- #error "SPINDLE_LASER_PWM pin is in use by X_MIN endstop."
- #elif PIN_EXISTS(Z_STEP) && Z_STEP_PIN == SPINDLE_LASER_PWM_PIN
- #error "SPINDLE_LASER_PWM pin in use by Z_STEP."
- #elif NUM_SERVOS > 0 && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5)
- #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E5_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E5_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E5_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #elif PIN_EXISTS(MOTOR_CURRENT_PWM_XY) && SPINDLE_LASER_PWM_PIN == MOTOR_CURRENT_PWM_XY_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by MOTOR_CURRENT_PWM_XY."
- #elif PIN_EXISTS(MOTOR_CURRENT_PWM_Z) && SPINDLE_LASER_PWM_PIN == MOTOR_CURRENT_PWM_Z_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by MOTOR_CURRENT_PWM_Z."
- #elif PIN_EXISTS(MOTOR_CURRENT_PWM_E) && SPINDLE_LASER_PWM_PIN == MOTOR_CURRENT_PWM_E_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by MOTOR_CURRENT_PWM_E."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-/**
- * The Trinamic library includes SoftwareSerial.h, leading to a compile error.
- */
-#if HAS_TRINAMIC && ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- #error "TMCStepper includes SoftwareSerial.h which is incompatible with ENDSTOP_INTERRUPTS_FEATURE. Disable ENDSTOP_INTERRUPTS_FEATURE to continue."
-#endif
diff --git a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp b/Marlin/src/HAL/HAL_AVR/Servo.cpp
similarity index 97%
rename from Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/Servo.cpp
index 3d9251acbd..33818edb96 100644
--- a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/Servo.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -131,7 +131,7 @@ void initISR(timer16_Sequence_t timer) {
TCCR1A = 0; // normal counting mode
TCCR1B = _BV(CS11); // set prescaler of 8
TCNT1 = 0; // clear the timer count
- #if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__)
+ #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
SBI(TIFR, OCF1A); // clear any pending interrupts;
SBI(TIMSK, OCIE1A); // enable the output compare interrupt
#else
diff --git a/Marlin/src/HAL/HAL_AVR/ServoTimers.h b/Marlin/src/HAL/HAL_AVR/ServoTimers.h
index 17b1e1fbb0..4991caefe6 100644
--- a/Marlin/src/HAL/HAL_AVR/ServoTimers.h
+++ b/Marlin/src/HAL/HAL_AVR/ServoTimers.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -53,8 +53,8 @@
* --------------------
*/
-#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
-#define PRESCALER 8 // timer prescaler
+#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
+#define SERVO_TIMER_PRESCALER 8 // timer prescaler
// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
diff --git a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
index cabf830c90..b80fee610d 100644
--- a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -36,12 +36,12 @@
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
*/
-#include "../../core/macros.h"
-#include
#include "../../module/endstops.h"
+#include
+
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
/**
* Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
@@ -102,153 +102,124 @@ void pciSetup(const int8_t pin) {
ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
#endif
-void setup_endstop_interrupts( void ) {
-
+void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
#if HAS_X_MAX
- #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT) // if pin has an external interrupt
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
+ #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT)
+ _ATTACH(X_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable"); // if pin has no pin change interrupt - error
- pciSetup(X_MAX_PIN); // assign it
+ static_assert(digitalPinToPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable");
+ pciSetup(X_MAX_PIN);
#endif
#endif
-
#if HAS_X_MIN
#if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(X_MIN_PIN), "X_MIN_PIN is not interrupt-capable");
pciSetup(X_MIN_PIN);
#endif
#endif
-
#if HAS_Y_MAX
#if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Y_MAX_PIN), "Y_MAX_PIN is not interrupt-capable");
pciSetup(Y_MAX_PIN);
#endif
#endif
-
#if HAS_Y_MIN
#if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Y_MIN_PIN), "Y_MIN_PIN is not interrupt-capable");
pciSetup(Y_MIN_PIN);
#endif
#endif
-
#if HAS_Z_MAX
#if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z_MAX_PIN), "Z_MAX_PIN is not interrupt-capable");
pciSetup(Z_MAX_PIN);
#endif
#endif
-
#if HAS_Z_MIN
#if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z_MIN_PIN), "Z_MIN_PIN is not interrupt-capable");
pciSetup(Z_MIN_PIN);
#endif
#endif
-
#if HAS_X2_MAX
#if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X2_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(X2_MAX_PIN), "X2_MAX_PIN is not interrupt-capable");
pciSetup(X2_MAX_PIN);
#endif
#endif
-
#if HAS_X2_MIN
#if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X2_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(X2_MIN_PIN), "X2_MIN_PIN is not interrupt-capable");
pciSetup(X2_MIN_PIN);
#endif
#endif
-
#if HAS_Y2_MAX
#if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y2_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Y2_MAX_PIN), "Y2_MAX_PIN is not interrupt-capable");
pciSetup(Y2_MAX_PIN);
#endif
#endif
-
#if HAS_Y2_MIN
#if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y2_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Y2_MIN_PIN), "Y2_MIN_PIN is not interrupt-capable");
pciSetup(Y2_MIN_PIN);
#endif
#endif
-
#if HAS_Z2_MAX
#if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z2_MAX_PIN), "Z2_MAX_PIN is not interrupt-capable");
pciSetup(Z2_MAX_PIN);
#endif
#endif
-
#if HAS_Z2_MIN
#if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z2_MIN_PIN), "Z2_MIN_PIN is not interrupt-capable");
pciSetup(Z2_MIN_PIN);
#endif
#endif
-
#if HAS_Z3_MAX
#if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z3_MAX_PIN), "Z3_MAX_PIN is not interrupt-capable");
pciSetup(Z3_MAX_PIN);
#endif
#endif
-
#if HAS_Z3_MIN
#if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z3_MIN_PIN), "Z3_MIN_PIN is not interrupt-capable");
pciSetup(Z3_MIN_PIN);
#endif
#endif
-
#if HAS_Z_MIN_PROBE_PIN
#if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN), "Z_MIN_PROBE_PIN is not interrupt-capable");
pciSetup(Z_MIN_PROBE_PIN);
#endif
diff --git a/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp b/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
index f8005f2423..4884ede63f 100644
--- a/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
+++ b/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include "../../inc/MarlinConfigPre.h"
-#if ENABLED(FAST_PWM_FAN)
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
#include "HAL.h"
@@ -59,19 +59,19 @@ Timer get_pwm_timer(const pin_t pin) {
#ifdef TCCR2
case TIMER2: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2, nullptr, nullptr},
- /*OCRnQ*/ { (uint16_t*)&OCR2, nullptr, nullptr},
+ /*TCCRnQ*/ { &TCCR2, nullptr, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2, nullptr, nullptr },
/*ICRn*/ nullptr,
/*n, q*/ 2, 0
};
}
- #elif defined TCCR2A
+ #elif defined(TCCR2A)
#if ENABLED(USE_OCR2A_AS_TOP)
case TIMER2A: break; // protect TIMER2A
case TIMER2B: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr},
- /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr},
+ /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
/*ICRn*/ nullptr,
/*n, q*/ 2, 1
};
@@ -81,8 +81,8 @@ Timer get_pwm_timer(const pin_t pin) {
case TIMER2B: ++q;
case TIMER2A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr},
- /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr},
+ /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
/*ICRn*/ nullptr,
2, q
};
@@ -91,13 +91,24 @@ Timer get_pwm_timer(const pin_t pin) {
#endif
#endif
#endif
- #ifdef TCCR3A
+ #ifdef OCR3C
case TIMER3C: ++q;
case TIMER3B: ++q;
case TIMER3A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR3A, &TCCR3B, &TCCR3C},
- /*OCRnQ*/ { &OCR3A, &OCR3B, &OCR3C},
+ /*TCCRnQ*/ { &TCCR3A, &TCCR3B, &TCCR3C },
+ /*OCRnQ*/ { &OCR3A, &OCR3B, &OCR3C },
+ /*ICRn*/ &ICR3,
+ /*n, q*/ 3, q
+ };
+ return timer;
+ }
+ #elif defined(OCR3B)
+ case TIMER3B: ++q;
+ case TIMER3A: {
+ Timer timer = {
+ /*TCCRnQ*/ { &TCCR3A, &TCCR3B, nullptr },
+ /*OCRnQ*/ { &OCR3A, &OCR3B, nullptr },
/*ICRn*/ &ICR3,
/*n, q*/ 3, q
};
@@ -109,8 +120,8 @@ Timer get_pwm_timer(const pin_t pin) {
case TIMER4B: ++q;
case TIMER4A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C},
- /*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C},
+ /*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C },
+ /*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C },
/*ICRn*/ &ICR4,
/*n, q*/ 4, q
};
@@ -122,7 +133,7 @@ Timer get_pwm_timer(const pin_t pin) {
case TIMER5B: ++q;
case TIMER5A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C},
+ /*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C },
/*OCRnQ*/ { &OCR5A, &OCR5B, &OCR5C },
/*ICRn*/ &ICR5,
/*n, q*/ 5, q
@@ -132,8 +143,8 @@ Timer get_pwm_timer(const pin_t pin) {
#endif
}
Timer timer = {
- /*TCCRnQ*/ { nullptr, nullptr, nullptr},
- /*OCRnQ*/ { nullptr, nullptr, nullptr},
+ /*TCCRnQ*/ { nullptr, nullptr, nullptr },
+ /*OCRnQ*/ { nullptr, nullptr, nullptr },
/*ICRn*/ nullptr,
0, 0
};
@@ -267,5 +278,5 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
}
}
-#endif // FAST_PWM_FAN
+#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
#endif // __AVR__
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AVR.cpp b/Marlin/src/HAL/HAL_AVR/fastio.cpp
similarity index 96%
rename from Marlin/src/HAL/HAL_AVR/fastio_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/fastio.cpp
index c58f9da41d..f0f7688f1b 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/fastio.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
#ifdef __AVR__
-#include "fastio_AVR.h"
+#include "fastio.h"
#ifdef FASTIO_EXT_START
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h b/Marlin/src/HAL/HAL_AVR/fastio.h
similarity index 95%
rename from Marlin/src/HAL/HAL_AVR/fastio_AVR.h
rename to Marlin/src/HAL/HAL_AVR/fastio.h
index f0ef7af1c8..501a7cdf06 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,7 +28,6 @@
*/
#include
-#include "../../core/macros.h"
#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__))
#define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
@@ -40,15 +39,15 @@
* Include Ports and Functions
*/
#if AVR_ATmega328_FAMILY
- #include "fastio_168.h"
+ #include "fastio/fastio_168.h"
#elif AVR_ATmega1284_FAMILY
- #include "fastio_644.h"
+ #include "fastio/fastio_644.h"
#elif AVR_ATmega2560_FAMILY
- #include "fastio_1280.h"
+ #include "fastio/fastio_1280.h"
#elif AVR_AT90USB1286_FAMILY
- #include "fastio_AT90USB.h"
+ #include "fastio/fastio_AT90USB.h"
#elif AVR_ATmega2561_FAMILY
- #include "fastio_1281.h"
+ #include "fastio/fastio_1281.h"
#else
#error "No FastIO definition for the selected AVR Board."
#endif
@@ -273,6 +272,8 @@ enum ClockSource2 : char {
#define SET_FOCB(T,V) SET_FOC(T,B,V)
#define SET_FOCC(T,V) SET_FOC(T,C,V)
+#if 0
+
/**
* PWM availability macros
*/
@@ -286,11 +287,11 @@ enum ClockSource2 : char {
#if ANY_PIN(FAN, FAN1, FAN2)
#if PIN_EXISTS(FAN2)
- #define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN || P == FAN2_PIN)
+ #define PWM_CHK_FAN_A(P) (P == FAN0_PIN || P == FAN1_PIN || P == FAN2_PIN)
#elif PIN_EXISTS(FAN1)
- #define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN)
+ #define PWM_CHK_FAN_A(P) (P == FAN0_PIN || P == FAN1_PIN)
#else
- #define PWM_CHK_FAN_A(P) (P == FAN_PIN)
+ #define PWM_CHK_FAN_A(P) (P == FAN0_PIN)
#endif
#else
#define PWM_CHK_FAN_A(P) false
@@ -336,6 +337,8 @@ enum ClockSource2 : char {
#define PWM_CHK(P) (PWM_CHK_HEATER(P) || PWM_CHK_SERVO(P) || PWM_CHK_MOTOR_CURRENT(P) || PWM_CHK_FAN_A(P) || PWM_CHK_FAN_B(P))
+#endif // PWM_CHK is not used in Marlin
+
// define which hardware PWMs are available for the current CPU
// all timer 1 PWMS deleted from this list because they are never available
#if AVR_ATmega2560_FAMILY
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_1280.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_1280.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
index 2c37b0a697..62de534d53 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_1280.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
* Logical Pin : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 78 79 80 xx xx 84 85 71 70 xx xx xx xx xx 81 82 83 xx xx 72 72 75 76 77 74 xx xx xx xx xx
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
// change for your board
#define DEBUG_LED DIO21
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_1281.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_1281.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
index be34d0727c..e3d2f12851 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_1281.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
* Port: A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7 E0 E1 E2 E3 E4 E5 E6 E7 F0 F1 F2 F3 F4 F5 F6 F7 G0 G1 G2 G3 G4 G5
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
// change for your board
#define DEBUG_LED DIO46
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_168.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
similarity index 98%
rename from Marlin/src/HAL/HAL_AVR/fastio_168.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
index d981287086..f6ee7a5d00 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_168.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
* Port: B0 B1 B2 B3 B4 B5 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
#define DEBUG_LED AIO5
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_644.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
similarity index 98%
rename from Marlin/src/HAL/HAL_AVR/fastio_644.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
index 0ce458be58..180a3c4e32 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_644.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@
* +--------+
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
#define DEBUG_LED DIO0
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
index f744c65132..3f17a2e261 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
* The logical pins 46 and 47 are not supported by Teensyduino, but are supported below as E2 and E3
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
// change for your board
#define DEBUG_LED DIO31 /* led D5 red */
diff --git a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
similarity index 78%
rename from Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h
rename to Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
index 4076c2b03a..85f26f4016 100644
--- a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h
+++ b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,8 +20,3 @@
*
*/
#pragma once
-
-extern IWDG_HandleTypeDef hiwdg;
-
-void watchdog_init();
-void watchdog_reset();
diff --git a/Marlin/src/HAL/HAL_AVR/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_AVR/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h b/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h
new file mode 100644
index 0000000000..93fadf20a5
--- /dev/null
+++ b/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h
@@ -0,0 +1,61 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Test AVR-specific configuration values for errors at compile-time.
+ */
+
+/**
+ * Digipot requirement
+ */
+ #if ENABLED(DIGIPOT_MCP4018)
+ #if !defined(DIGIPOTS_I2C_SDA_X) || !defined(DIGIPOTS_I2C_SDA_Y) || !defined(DIGIPOTS_I2C_SDA_Z) \
+ || !defined(DIGIPOTS_I2C_SDA_E0) || !defined(DIGIPOTS_I2C_SDA_E1)
+ #error "DIGIPOT_MCP4018 requires DIGIPOTS_I2C_SDA_* pins to be defined."
+ #endif
+#endif
+
+/**
+ * Checks for FAST PWM
+ */
+#if ENABLED(FAST_PWM_FAN) && (ENABLED(USE_OCR2A_AS_TOP) && defined(TCCR2))
+ #error "USE_OCR2A_AS_TOP does not apply to devices with a single output TIMER2"
+#endif
+
+/**
+ * Sanity checks for Spindle / Laser PWM
+ */
+#if ENABLED(SPINDLE_LASER_PWM)
+ #if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13)
+ #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt."
+ #elif NUM_SERVOS > 0 && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5)
+ #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system."
+ #endif
+#endif
+
+/**
+ * The Trinamic library includes SoftwareSerial.h, leading to a compile error.
+ */
+#if HAS_TRINAMIC && ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ #error "TMCStepper includes SoftwareSerial.h which is incompatible with ENDSTOP_INTERRUPTS_FEATURE. Disable ENDSTOP_INTERRUPTS_FEATURE to continue."
+#endif
diff --git a/Marlin/src/HAL/HAL_AVR/math_AVR.h b/Marlin/src/HAL/HAL_AVR/math.h
similarity index 96%
rename from Marlin/src/HAL/HAL_AVR/math_AVR.h
rename to Marlin/src/HAL/HAL_AVR/math.h
index 8299b8bbd3..d397cc4e9a 100644
--- a/Marlin/src/HAL/HAL_AVR/math_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/math.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp
index 4c2f9ea4f1..116a8288e2 100644
--- a/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_AVR/pinsDebug.h b/Marlin/src/HAL/HAL_AVR/pinsDebug.h
index 8df4ffcf87..e4738e0332 100644
--- a/Marlin/src/HAL/HAL_AVR/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_AVR/pinsDebug.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -230,18 +227,9 @@ static void print_is_also_tied() { SERIAL_ECHOPGM(" is also tied to this pin");
void com_print(uint8_t N, uint8_t Z) {
const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
SERIAL_ECHOPGM(" COM");
- SERIAL_CHAR(N + '0');
- switch (Z) {
- case 'A':
- SERIAL_ECHOPAIR("A: ", ((*TCCRA & (_BV(7) | _BV(6))) >> 6));
- break;
- case 'B':
- SERIAL_ECHOPAIR("B: ", ((*TCCRA & (_BV(5) | _BV(4))) >> 4));
- break;
- case 'C':
- SERIAL_ECHOPAIR("C: ", ((*TCCRA & (_BV(3) | _BV(2))) >> 2));
- break;
- }
+ SERIAL_CHAR('0' + N);
+ SERIAL_CHAR('A' + Z);
+ SERIAL_ECHOPAIR(": ", int((*TCCRA >> (6 - Z * 2)) & 0x03));
}
void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N - WGM bit layout
@@ -356,6 +344,8 @@ static void pwm_details(uint8_t pin) {
timer_prefix(0, 'A', 3);
#endif
}
+ #else
+ UNUSED(print_is_also_tied);
#endif
} // pwm_details
@@ -403,4 +393,4 @@ static void pwm_details(uint8_t pin) {
#endif
-#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer);} while (0)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
diff --git a/Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h b/Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h
index e97d694bb0..4388430779 100644
--- a/Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h
+++ b/Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h b/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
index 028c8f02a4..e5bb82f226 100644
--- a/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
+++ b/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -50,7 +47,7 @@
const uint8_t PROGMEM digital_pin_to_port_PGM_plus_70[] = {
// PORTLIST
- // -------------------------------------------
+ // ------------------------
PE , // PE 0 ** 0 ** USART0_RX
PE , // PE 1 ** 1 ** USART0_TX
PE , // PE 4 ** 2 ** PWM2
@@ -143,7 +140,7 @@ const uint8_t PROGMEM digital_pin_to_port_PGM_plus_70[] = {
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM_plus_70[] = {
// PIN IN PORT
- // -------------------------------------------
+ // ------------------------
_BV( 0 ) , // PE 0 ** 0 ** USART0_RX
_BV( 1 ) , // PE 1 ** 1 ** USART0_TX
_BV( 4 ) , // PE 4 ** 2 ** PWM2
@@ -237,7 +234,7 @@ const uint8_t PROGMEM digital_pin_to_bit_mask_PGM_plus_70[] = {
const uint8_t PROGMEM digital_pin_to_timer_PGM_plus_70[] = {
// TIMERS
- // -------------------------------------------
+ // ------------------------
NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX
NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX
TIMER3B , // PE 4 ** 2 ** PWM2
diff --git a/Marlin/src/HAL/HAL_AVR/spi_pins.h b/Marlin/src/HAL/HAL_AVR/spi_pins.h
index 85d2d8f6e5..c7951acfa3 100644
--- a/Marlin/src/HAL/HAL_AVR/spi_pins.h
+++ b/Marlin/src/HAL/HAL_AVR/spi_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_AVR/u8g_com_HAL_AVR_sw_spi.cpp b/Marlin/src/HAL/HAL_AVR/u8g_com_HAL_AVR_sw_spi.cpp
index 426e1c942c..bc08bc379b 100644
--- a/Marlin/src/HAL/HAL_AVR/u8g_com_HAL_AVR_sw_spi.cpp
+++ b/Marlin/src/HAL/HAL_AVR/u8g_com_HAL_AVR_sw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp b/Marlin/src/HAL/HAL_AVR/watchdog.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/watchdog.cpp
index 0d3cc81886..63a5031966 100644
--- a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
#if ENABLED(USE_WATCHDOG)
-#include "watchdog_AVR.h"
+#include "watchdog.h"
#include "../../Marlin.h"
diff --git a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.h b/Marlin/src/HAL/HAL_AVR/watchdog.h
similarity index 85%
rename from Marlin/src/HAL/HAL_AVR/watchdog_AVR.h
rename to Marlin/src/HAL/HAL_AVR/watchdog.h
index ed5150fe08..efd725d7d7 100644
--- a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,4 +28,4 @@ void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or AVR will go into emergency procedures.
-inline void watchdog_reset() { wdt_reset(); }
+inline void HAL_watchdog_refresh() { wdt_reset(); }
diff --git a/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp b/Marlin/src/HAL/HAL_DUE/DebugMonitor.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/DebugMonitor.cpp
index 89206fa94c..20f10ce405 100644
--- a/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/DebugMonitor.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "../../core/macros.h"
#include "../../core/serial.h"
-#include
#include "../shared/backtrace/unwinder.h"
#include "../shared/backtrace/unwmemaccess.h"
+#include
+
// Debug monitor that dumps to the Programming port all status when
// an exception or WDT timeout happens - And then resets the board
@@ -41,7 +42,7 @@
#define sw_barrier() __asm__ volatile("": : :"memory");
// (re)initialize UART0 as a monitor output to 250000,n,8,1
-static void TXBegin(void) {
+static void TXBegin() {
// Disable UART interrupt in NVIC
NVIC_DisableIRQ( UART_IRQn );
@@ -234,7 +235,7 @@ void HardFault_HandlerC(unsigned long *sp, unsigned long lr, unsigned long cause
for (;;) WDT_Restart(WDT);
}
-__attribute__((naked)) void NMI_Handler(void) {
+__attribute__((naked)) void NMI_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -247,7 +248,7 @@ __attribute__((naked)) void NMI_Handler(void) {
);
}
-__attribute__((naked)) void HardFault_Handler(void) {
+__attribute__((naked)) void HardFault_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -260,7 +261,7 @@ __attribute__((naked)) void HardFault_Handler(void) {
);
}
-__attribute__((naked)) void MemManage_Handler(void) {
+__attribute__((naked)) void MemManage_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -273,7 +274,7 @@ __attribute__((naked)) void MemManage_Handler(void) {
);
}
-__attribute__((naked)) void BusFault_Handler(void) {
+__attribute__((naked)) void BusFault_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -286,7 +287,7 @@ __attribute__((naked)) void BusFault_Handler(void) {
);
}
-__attribute__((naked)) void UsageFault_Handler(void) {
+__attribute__((naked)) void UsageFault_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -299,7 +300,7 @@ __attribute__((naked)) void UsageFault_Handler(void) {
);
}
-__attribute__((naked)) void DebugMon_Handler(void) {
+__attribute__((naked)) void DebugMon_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -313,7 +314,7 @@ __attribute__((naked)) void DebugMon_Handler(void) {
}
/* This is NOT an exception, it is an interrupt handler - Nevertheless, the framing is the same */
-__attribute__((naked)) void WDT_Handler(void) {
+__attribute__((naked)) void WDT_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -326,7 +327,7 @@ __attribute__((naked)) void WDT_Handler(void) {
);
}
-__attribute__((naked)) void RSTC_Handler(void) {
+__attribute__((naked)) void RSTC_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
diff --git a/Marlin/src/HAL/HAL_DUE/EepromEmulation_Due.cpp b/Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp
similarity index 98%
rename from Marlin/src/HAL/HAL_DUE/EepromEmulation_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp
index 07f746a17d..c7b7007053 100644
--- a/Marlin/src/HAL/HAL_DUE/EepromEmulation_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp
@@ -31,12 +31,12 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../shared/persistent_store_api.h"
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS) && DISABLED(I2C_EEPROM, SPI_EEPROM)
+#if ENABLED(EEPROM_SETTINGS) && NONE(I2C_EEPROM, SPI_EEPROM)
#include "../shared/Marduino.h"
+#include "../shared/persistent_store_api.h"
#define EEPROMSize 4096
#define PagesPerGroup 128
@@ -922,8 +922,7 @@ static void ee_Init() {
if (!ee_IsPageClean(grp * PagesPerGroup + page)) {
#ifdef EE_EMU_DEBUG
SERIAL_ECHO_START();
- SERIAL_ECHOPAIR("EEPROM Page ",page);
- SERIAL_ECHOLNPAIR(" not clean on group ",grp);
+ SERIAL_ECHOLNPAIR("EEPROM Page ", page, " not clean on group ", grp);
SERIAL_FLUSH();
#endif
ee_PageErase(grp * PagesPerGroup + page);
@@ -944,7 +943,7 @@ static void ee_Init() {
#ifdef EE_EMU_DEBUG
SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Active page: ",curPage);
+ SERIAL_ECHOLNPAIR("EEPROM Active page: ", curPage);
SERIAL_FLUSH();
#endif
@@ -953,8 +952,7 @@ static void ee_Init() {
if (!ee_IsPageClean(curGroup * PagesPerGroup + page)) {
#ifdef EE_EMU_DEBUG
SERIAL_ECHO_START();
- SERIAL_ECHOPAIR("EEPROM Page ",page);
- SERIAL_ECHOLNPAIR(" not clean on active group ",curGroup);
+ SERIAL_ECHOLNPAIR("EEPROM Page ", page, " not clean on active group ", curGroup);
SERIAL_FLUSH();
ee_Dump(curGroup * PagesPerGroup + page, getFlashStorage(curGroup * PagesPerGroup + page));
#endif
@@ -993,7 +991,7 @@ void eeprom_read_block(void* __dst, const void* __src, size_t __n) {
}
}
-void eeprom_flush(void) {
+void eeprom_flush() {
ee_Flush();
}
diff --git a/Marlin/src/HAL/HAL_DUE/HAL.cpp b/Marlin/src/HAL/HAL_DUE/HAL.cpp
index cefe308e81..130779896d 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL.cpp
+++ b/Marlin/src/HAL/HAL_DUE/HAL.cpp
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
@@ -25,56 +25,24 @@
#ifdef ARDUINO_ARCH_SAM
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include
#include "usb/usb_task.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// HAL initialization task
-void HAL_init(void) {
+void HAL_init() {
// Initialize the USB stack
#if ENABLED(SDSUPPORT)
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
@@ -83,20 +51,20 @@ void HAL_init(void) {
}
// HAL idle task
-void HAL_idletask(void) {
+void HAL_idletask() {
// Perform USB stack housekeeping
usb_task_idle();
}
// Disable interrupts
-void cli(void) { noInterrupts(); }
+void cli() { noInterrupts(); }
// Enable interrupts
-void sei(void) { interrupts(); }
+void sei() { interrupts(); }
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
switch ((RSTC->RSTC_SR >> 8) & 0x07) {
case 0: return RST_POWER_ON;
case 1: return RST_BACKUP;
@@ -119,18 +87,18 @@ extern "C" {
// Return free memory between end of heap (or end bss) and whatever is current
int freeMemory() {
int free_memory, heap_end = (int)_sbrk(0);
- return (int)&free_memory - (heap_end ? heap_end : (int)&_ebss);
+ return (int)&free_memory - (heap_end ?: (int)&_ebss);
}
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_adc_start_conversion(const uint8_t adc_pin) {
HAL_adc_result = analogRead(adc_pin);
}
-uint16_t HAL_adc_get_result(void) {
+uint16_t HAL_adc_get_result() {
// nop
return HAL_adc_result;
}
diff --git a/Marlin/src/HAL/HAL_DUE/HAL.h b/Marlin/src/HAL/HAL_DUE/HAL.h
index af22119f17..54ade88e75 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL.h
+++ b/Marlin/src/HAL/HAL_DUE/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -32,34 +32,51 @@
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_Due.h"
-#include "watchdog_Due.h"
-#include "HAL_timers_Due.h"
+#include "fastio.h"
+#include "watchdog.h"
+#include "timers.h"
#include
-// Serial ports
-#if !WITHIN(SERIAL_PORT, -1, 3)
- #error "SERIAL_PORT must be from -1 to 3"
+// Define MYSERIAL0/1 before MarlinSerial includes!
+#if SERIAL_PORT == -1
+ #define MYSERIAL0 Serial1
+#elif SERIAL_PORT == 0
+ #define MYSERIAL0 Serial
+#elif SERIAL_PORT == 1
+ #define MYSERIAL0 Serial1
+#elif SERIAL_PORT == 2
+ #define MYSERIAL0 Serial2
+#elif SERIAL_PORT == 3
+ #define MYSERIAL0 Serial3
+#else
+ #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
-// MYSERIAL0 required before MarlinSerial includes!
-#define MYSERIAL0 customizedSerial1
-
#ifdef SERIAL_PORT_2
- #if !WITHIN(SERIAL_PORT_2, -1, 3)
- #error "SERIAL_PORT_2 must be from -1 to 3"
- #elif SERIAL_PORT_2 == SERIAL_PORT
- #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
+ #if SERIAL_PORT_2 == SERIAL_PORT
+ #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration."
+ #endif
+ #if SERIAL_PORT_2 == -1
+ #define MYSERIAL1 Serial1
+ #elif SERIAL_PORT_2 == 0
+ #define MYSERIAL1 Serial
+ #elif SERIAL_PORT_2 == 1
+ #define MYSERIAL1 Serial1
+ #elif SERIAL_PORT_2 == 2
+ #define MYSERIAL1 Serial2
+ #elif SERIAL_PORT_2 == 3
+ #define MYSERIAL1 Serial3
+ #else
+ #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif
#define NUM_SERIAL 2
- #define MYSERIAL1 customizedSerial2
#else
#define NUM_SERIAL 1
#endif
-#include "MarlinSerial_Due.h"
-#include "MarlinSerialUSB_Due.h"
+#include "MarlinSerial.h"
+#include "MarlinSerialUSB.h"
// On AVR this is in math.h?
#define square(x) ((x)*(x))
@@ -68,10 +85,6 @@
#define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
#endif
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
// Fix bug in pgm_read_ptr
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*((void**)(addr)))
@@ -80,6 +93,7 @@
typedef int8_t pin_t;
+#define SHARED_SERVOS HAS_SERVOS
#define HAL_SERVO_LIB Servo
//
@@ -91,22 +105,11 @@ typedef int8_t pin_t;
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()
-void cli(void); // Disable interrupts
-void sei(void); // Enable interrupts
+void cli(); // Disable interrupts
+void sei(); // Enable interrupts
-void HAL_clear_reset_source(void); // clear reset reason
-uint8_t HAL_get_reset_source(void); // get reset reason
-
-//
-// SPI: Extended functions taking a channel number (Hardware SPI only)
-//
-
-// Write single byte to specified SPI channel
-void spiSend(uint32_t chan, byte b);
-// Write buffer to specified SPI channel
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-// Read single byte from specified SPI channel
-uint8_t spiRec(uint32_t chan);
+void HAL_clear_reset_source(); // clear reset reason
+uint8_t HAL_get_reset_source(); // get reset reason
//
// EEPROM
@@ -127,14 +130,14 @@ extern uint16_t HAL_adc_result; // result of last ADC conversion
#define HAL_ANALOG_SELECT(pin)
-inline void HAL_adc_init(void) {}//todo
+inline void HAL_adc_init() {}//todo
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
//
// Pin Map
@@ -152,20 +155,23 @@ void noTone(const pin_t _pin);
// Enable hooks into idle and setup for HAL
#define HAL_IDLETASK 1
-#define HAL_INIT 1
-void HAL_idletask(void);
-void HAL_init(void);
+void HAL_idletask();
+void HAL_init();
//
// Utility functions
//
void _delay_ms(const int delay);
-int freeMemory(void);
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+int freeMemory();
+#pragma GCC diagnostic pop
#ifdef __cplusplus
extern "C" {
#endif
-char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);
+char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
#ifdef __cplusplus
}
#endif
diff --git a/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp b/Marlin/src/HAL/HAL_DUE/HAL_SPI.cpp
similarity index 96%
rename from Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/HAL_SPI.cpp
index 5adc7fcf09..35763a5ec7 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/HAL_SPI.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
/**
* Software SPI functions originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
+ * Copyright (c) 2009 by William Greiman
*
* Completely rewritten and tuned by Eduardo José Tagle in 2017/2018
* in ARM thumb2 inline assembler and tuned for maximum speed and performance
@@ -37,27 +37,18 @@
#ifdef ARDUINO_ARCH_SAM
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include "../shared/Delay.h"
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if EITHER(DUE_SOFTWARE_SPI, FORCE_SOFT_SPI)
- // --------------------------------------------------------------------------
- // software SPI
- // --------------------------------------------------------------------------
+ // ------------------------
+ // Software SPI
+ // ------------------------
// Make sure GCC optimizes this file.
// Note that this line triggers a bug in GCC which is fixed by casting.
@@ -160,13 +151,12 @@
(((uint32_t)(addr) & 0xF0000000) + 0x02000000 + ((uint32_t)(addr)&0xFFFFF)*32 + (bit)*4)
// run at ~8 .. ~10Mhz - Rx version (Tx line not altered)
- static uint8_t spiTransferRx0(uint8_t bout) { // using Mode 0
+ static uint8_t spiTransferRx0(uint8_t) { // using Mode 0
uint32_t bin = 0;
uint32_t work = 0;
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(MISO_PIN))+0x3C, PIN_SHIFT(MISO_PIN)); /* PDSR of port in bitband area */
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SCK_PIN)) + 0x30; /* SODR of port */
uint32_t SCK_MASK = PIN_MASK(SCK_PIN);
- UNUSED(bout);
/* The software SPI routine */
__asm__ __volatile__(
@@ -437,7 +427,7 @@
static void spiTxBlockX(const uint8_t* buf, uint32_t todo) {
do {
- (void) spiTransferTx(*buf++);
+ (void)spiTransferTx(*buf++);
} while (--todo);
}
@@ -551,9 +541,9 @@
// slave selects controlled by SPI controller
// doesn't support changing SPI speeds for SD card
- // --------------------------------------------------------------------------
+ // ------------------------
// hardware SPI
- // --------------------------------------------------------------------------
+ // ------------------------
static bool spiInitialized = false;
void spiInit(uint8_t spiRate) {
diff --git a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp b/Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
index 6fbeb3a1f8..b9f14823f6 100644
--- a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "InterruptVectors_Due.h"
+#include "InterruptVectors.h"
/* The relocated Exception/Interrupt Table - According to the ARM
reference manual, alignment to 128 bytes should suffice, but in
@@ -48,7 +48,7 @@ static DeviceVectors ram_tab = { nullptr };
* If it is not, then it copies the ROM table to the SRAM and relocates the table
* by reprogramming the NVIC registers
*/
-static pfnISR_Handler* get_relocated_table_addr(void) {
+static pfnISR_Handler* get_relocated_table_addr() {
// Get the address of the interrupt/exception table
uint32_t isrtab = SCB->VTOR;
diff --git a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.h b/Marlin/src/HAL/HAL_DUE/InterruptVectors.h
similarity index 87%
rename from Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.h
rename to Marlin/src/HAL/HAL_DUE/InterruptVectors.h
index 71de4bf52e..87dd049624 100644
--- a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/InterruptVectors.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,8 +24,6 @@
/**
* InterruptVectors_Due.h
*
- * Copyright (c) 2017 Eduardo José Tagle. All right reserved
- *
* This module relocates the Interrupt vector table to SRAM, allowing new
* interrupt handlers to be added at runtime. This is required because the
* Arduino runtime steals interrupt handlers that Marlin MUST use to support
@@ -39,7 +37,7 @@
#ifdef ARDUINO_ARCH_SAM
// ISR handler type
-typedef void (*pfnISR_Handler)(void);
+typedef void (*pfnISR_Handler)();
// Install a new interrupt vector handler for the given irq, returning the old one
pfnISR_Handler install_isr(IRQn_Type irq, pfnISR_Handler newHandler);
diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp b/Marlin/src/HAL/HAL_DUE/MarlinSerial.cpp
similarity index 97%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/MarlinSerial.cpp
index 4be9c43f47..7b88b6d43e 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,8 +29,8 @@
#include "../../inc/MarlinConfig.h"
-#include "MarlinSerial_Due.h"
-#include "InterruptVectors_Due.h"
+#include "MarlinSerial.h"
+#include "InterruptVectors.h"
#include "../../Marlin.h"
template typename MarlinSerial::ring_buffer_r MarlinSerial::rx_buffer = { 0, 0, { 0 } };
@@ -178,7 +178,7 @@ FORCE_INLINE void MarlinSerial::store_rxd_char() {
}
template
-FORCE_INLINE void MarlinSerial::_tx_thr_empty_irq(void) {
+FORCE_INLINE void MarlinSerial::_tx_thr_empty_irq() {
if (Cfg::TX_SIZE > 0) {
// Read positions
uint8_t t = tx_buffer.tail;
@@ -221,7 +221,7 @@ FORCE_INLINE void MarlinSerial::_tx_thr_empty_irq(void) {
}
template
-void MarlinSerial::UART_ISR(void) {
+void MarlinSerial::UART_ISR() {
const uint32_t status = HWUART->UART_SR;
// Data received?
@@ -308,13 +308,13 @@ void MarlinSerial::end() {
}
template
-int MarlinSerial::peek(void) {
+int MarlinSerial::peek() {
const int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail];
return v;
}
template
-int MarlinSerial::read(void) {
+int MarlinSerial::read() {
const ring_buffer_pos_t h = rx_buffer.head;
ring_buffer_pos_t t = rx_buffer.tail;
@@ -354,13 +354,13 @@ int MarlinSerial::read(void) {
}
template
-typename MarlinSerial::ring_buffer_pos_t MarlinSerial::available(void) {
+typename MarlinSerial::ring_buffer_pos_t MarlinSerial::available() {
const ring_buffer_pos_t h = rx_buffer.head, t = rx_buffer.tail;
return (ring_buffer_pos_t)(Cfg::RX_SIZE + h - t) & (Cfg::RX_SIZE - 1);
}
template
-void MarlinSerial::flush(void) {
+void MarlinSerial::flush() {
rx_buffer.tail = rx_buffer.head;
if (Cfg::XONOFF) {
@@ -431,7 +431,7 @@ void MarlinSerial::write(const uint8_t c) {
}
template
-void MarlinSerial::flushTX(void) {
+void MarlinSerial::flushTX() {
// TX
if (Cfg::TX_SIZE == 0) {
@@ -520,7 +520,7 @@ void MarlinSerial::print(double n, int digits) {
}
template
-void MarlinSerial::println(void) {
+void MarlinSerial::println() {
print('\r');
print('\n');
}
diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h b/Marlin/src/HAL/HAL_DUE/MarlinSerial.h
similarity index 94%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h
rename to Marlin/src/HAL/HAL_DUE/MarlinSerial.h
index 9b03d46f28..92806f15b4 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -108,19 +108,19 @@ protected:
static ring_buffer_pos_t rx_max_enqueued;
FORCE_INLINE static void store_rxd_char();
- FORCE_INLINE static void _tx_thr_empty_irq(void);
- static void UART_ISR(void);
+ FORCE_INLINE static void _tx_thr_empty_irq();
+ static void UART_ISR();
public:
MarlinSerial() {};
static void begin(const long);
static void end();
- static int peek(void);
- static int read(void);
- static void flush(void);
- static ring_buffer_pos_t available(void);
+ static int peek();
+ static int read();
+ static void flush();
+ static ring_buffer_pos_t available();
static void write(const uint8_t c);
- static void flushTX(void);
+ static void flushTX();
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
@@ -149,7 +149,7 @@ public:
static void println(long, int = DEC);
static void println(unsigned long, int = DEC);
static void println(double, int = 2);
- static void println(void);
+ static void println();
operator bool() { return true; }
private:
diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.cpp
similarity index 90%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.cpp
index 7b1100dd9d..f7f48d5f42 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
#if SERIAL_PORT == -1
-#include "MarlinSerialUSB_Due.h"
+#include "MarlinSerialUSB.h"
#if ENABLED(EMERGENCY_PARSER)
#include "../../feature/emergency_parser.h"
@@ -39,11 +39,11 @@
// Imports from Atmel USB Stack/CDC implementation
extern "C" {
- bool usb_task_cdc_isenabled(void);
- bool usb_task_cdc_dtr_active(void);
- bool udi_cdc_is_rx_ready(void);
- int udi_cdc_getc(void);
- bool udi_cdc_is_tx_ready(void);
+ bool usb_task_cdc_isenabled();
+ bool usb_task_cdc_dtr_active();
+ bool udi_cdc_is_rx_ready();
+ int udi_cdc_getc();
+ bool udi_cdc_is_tx_ready();
int udi_cdc_putc(int value);
};
@@ -55,13 +55,11 @@ static int pending_char = -1;
#endif
// Public Methods
-void MarlinSerialUSB::begin(const long baud_setting) {
-}
+void MarlinSerialUSB::begin(const long) {}
-void MarlinSerialUSB::end() {
-}
+void MarlinSerialUSB::end() {}
-int MarlinSerialUSB::peek(void) {
+int MarlinSerialUSB::peek() {
if (pending_char >= 0)
return pending_char;
@@ -82,7 +80,7 @@ int MarlinSerialUSB::peek(void) {
return pending_char;
}
-int MarlinSerialUSB::read(void) {
+int MarlinSerialUSB::read() {
if (pending_char >= 0) {
int ret = pending_char;
pending_char = -1;
@@ -106,7 +104,7 @@ int MarlinSerialUSB::read(void) {
return c;
}
-bool MarlinSerialUSB::available(void) {
+bool MarlinSerialUSB::available() {
/* If Pending chars */
return pending_char >= 0 ||
/* or USB CDC enumerated and configured on the PC side and some
@@ -114,8 +112,8 @@ bool MarlinSerialUSB::available(void) {
(usb_task_cdc_isenabled() && udi_cdc_is_rx_ready());
}
-void MarlinSerialUSB::flush(void) { }
-void MarlinSerialUSB::flushTX(void) { }
+void MarlinSerialUSB::flush() { }
+void MarlinSerialUSB::flushTX() { }
void MarlinSerialUSB::write(const uint8_t c) {
@@ -185,7 +183,7 @@ void MarlinSerialUSB::print(double n, int digits) {
printFloat(n, digits);
}
-void MarlinSerialUSB::println(void) {
+void MarlinSerialUSB::println() {
print('\r');
print('\n');
}
diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.h
similarity index 90%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h
rename to Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.h
index 5025b82284..3d9d4bafaa 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,11 +43,11 @@ public:
MarlinSerialUSB() {};
static void begin(const long);
static void end();
- static int peek(void);
- static int read(void);
- static void flush(void);
- static void flushTX(void);
- static bool available(void);
+ static int peek();
+ static int read();
+ static void flush();
+ static void flushTX();
+ static bool available();
static void write(const uint8_t c);
#if ENABLED(SERIAL_STATS_DROPPED_RX)
@@ -80,7 +80,7 @@ public:
static void println(long, int = DEC);
static void println(unsigned long, int = DEC);
static void println(double, int = 2);
- static void println(void);
+ static void println();
operator bool() { return true; }
private:
diff --git a/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp b/Marlin/src/HAL/HAL_DUE/Servo.cpp
similarity index 87%
rename from Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/Servo.cpp
index d9e41f9541..f48fdf5796 100644
--- a/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/Servo.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -50,25 +50,25 @@
static volatile int8_t Channel[_Nbr_16timers]; // counter for the servo being pulsed for each timer (or -1 if refresh interval)
-//------------------------------------------------------------------------------
+// ------------------------
/// Interrupt handler for the TC0 channel 1.
-//------------------------------------------------------------------------------
+// ------------------------
void Servo_Handler(timer16_Sequence_t timer, Tc *pTc, uint8_t channel);
#ifdef _useTimer1
- void HANDLER_FOR_TIMER1(void) { Servo_Handler(_timer1, TC_FOR_TIMER1, CHANNEL_FOR_TIMER1); }
+ void HANDLER_FOR_TIMER1() { Servo_Handler(_timer1, TC_FOR_TIMER1, CHANNEL_FOR_TIMER1); }
#endif
#ifdef _useTimer2
- void HANDLER_FOR_TIMER2(void) { Servo_Handler(_timer2, TC_FOR_TIMER2, CHANNEL_FOR_TIMER2); }
+ void HANDLER_FOR_TIMER2() { Servo_Handler(_timer2, TC_FOR_TIMER2, CHANNEL_FOR_TIMER2); }
#endif
#ifdef _useTimer3
- void HANDLER_FOR_TIMER3(void) { Servo_Handler(_timer3, TC_FOR_TIMER3, CHANNEL_FOR_TIMER3); }
+ void HANDLER_FOR_TIMER3() { Servo_Handler(_timer3, TC_FOR_TIMER3, CHANNEL_FOR_TIMER3); }
#endif
#ifdef _useTimer4
- void HANDLER_FOR_TIMER4(void) { Servo_Handler(_timer4, TC_FOR_TIMER4, CHANNEL_FOR_TIMER4); }
+ void HANDLER_FOR_TIMER4() { Servo_Handler(_timer4, TC_FOR_TIMER4, CHANNEL_FOR_TIMER4); }
#endif
#ifdef _useTimer5
- void HANDLER_FOR_TIMER5(void) { Servo_Handler(_timer5, TC_FOR_TIMER5, CHANNEL_FOR_TIMER5); }
+ void HANDLER_FOR_TIMER5() { Servo_Handler(_timer5, TC_FOR_TIMER5, CHANNEL_FOR_TIMER5); }
#endif
void Servo_Handler(timer16_Sequence_t timer, Tc *tc, uint8_t channel) {
@@ -137,7 +137,7 @@ void initISR(timer16_Sequence_t timer) {
#endif
}
-void finISR(timer16_Sequence_t timer) {
+void finISR(timer16_Sequence_t) {
#ifdef _useTimer1
TC_Stop(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1);
#endif
diff --git a/Marlin/src/HAL/HAL_DUE/ServoTimers.h b/Marlin/src/HAL/HAL_DUE/ServoTimers.h
index 84129ef2b6..c32c938253 100644
--- a/Marlin/src/HAL/HAL_DUE/ServoTimers.h
+++ b/Marlin/src/HAL/HAL_DUE/ServoTimers.h
@@ -36,8 +36,8 @@
//!#define _useTimer4
#define _useTimer5
-#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
-#define PRESCALER 32 // timer prescaler
+#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
+#define SERVO_TIMER_PRESCALER 32 // timer prescaler
/*
TC0, chan 0 => TC0_Handler
diff --git a/Marlin/src/HAL/HAL_DUE/Tone.cpp b/Marlin/src/HAL/HAL_DUE/Tone.cpp
index 292be1401f..2af97aac61 100644
--- a/Marlin/src/HAL/HAL_DUE/Tone.cpp
+++ b/Marlin/src/HAL/HAL_DUE/Tone.cpp
@@ -1,9 +1,11 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,7 +31,7 @@
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "HAL_timers_Due.h"
+#include "timers.h"
static pin_t tone_pin;
volatile static int32_t toggles;
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_shared_hw_spi.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
similarity index 61%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_shared_hw_spi.cpp
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
index 9e92519ef6..5e5a4e5fc1 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_shared_hw_spi.cpp
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,66 +21,57 @@
*/
-/*
-
- based on u8g_com_msp430_hw_spi.c
-
- Universal 8bit Graphics Library
-
- Copyright (c) 2012, olikraus@gmail.com
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright notice, this
- list of conditions and the following disclaimer in the documentation and/or other
- materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*/
+/**
+ * Based on u8g_com_msp430_hw_spi.c
+ *
+ * Universal 8bit Graphics Library
+ *
+ * Copyright (c) 2012, olikraus@gmail.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
#ifdef __SAM3X8E__
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
#if HAS_GRAPHICAL_LCD
#include
-#include "../../Marlin.h"
-
-#define SPI_FULL_SPEED 0
-#define SPI_HALF_SPEED 1
-#define SPI_QUARTER_SPEED 2
-#define SPI_EIGHTH_SPEED 3
-#define SPI_SIXTEENTH_SPEED 4
-#define SPI_SPEED_5 5
-#define SPI_SPEED_6 6
+#include "../../../Marlin.h"
void spiBegin();
void spiInit(uint8_t spiRate);
void spiSend(uint8_t b);
void spiSend(const uint8_t* buf, size_t n);
-#include "../shared/Marduino.h"
-#include "fastio_Due.h"
+#include "../../shared/Marduino.h"
+#include "../fastio.h"
void u8g_SetPIOutput_DUE_hw_spi(u8g_t *u8g, uint8_t pin_index) {
PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
similarity index 95%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
index 74beb6a243..47e56fddb0 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -55,11 +55,11 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
#if ENABLED(U8GLIB_ST7920)
-#include "../shared/Delay.h"
+#include "../../shared/Delay.h"
#include
@@ -145,8 +145,8 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
}
#if ENABLED(LIGHTWEIGHT_UI)
- #include "../../lcd/ultralcd.h"
- #include "../shared/HAL_ST7920.h"
+ #include "../../../lcd/ultralcd.h"
+ #include "../../shared/HAL_ST7920.h"
#define ST7920_CS_PIN LCD_PINS_RS
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi.cpp
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
index 802e11757f..e078bc420f 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi.cpp
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -55,17 +55,17 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
-#if HAS_GRAPHICAL_LCD && !ENABLED(U8GLIB_ST7920)
+#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
#undef SPI_SPEED
#define SPI_SPEED 2 // About 2 MHz
#include "u8g_com_HAL_DUE_sw_spi_shared.h"
-#include "../shared/Marduino.h"
-#include "../shared/Delay.h"
+#include "../../shared/Marduino.h"
+#include "../../shared/Delay.h"
#include
@@ -144,5 +144,5 @@ uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
return 1;
}
-#endif // HAS_GRAPHICAL_LCD
+#endif // HAS_GRAPHICAL_LCD && !U8GLIB_ST7920
#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
index b7f52d58e0..d3609f60ef 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -55,11 +55,11 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
#if HAS_GRAPHICAL_LCD
-#include "../shared/Delay.h"
+#include "../../shared/Delay.h"
#include
@@ -87,7 +87,7 @@ void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
MOSI_pPio->PIO_CODR = MOSI_dwMask;
DELAY_NS(48);
SCK_pPio->PIO_SODR = SCK_dwMask;
- DELAY_NS(125);
+ DELAY_NS(905);
val <<= 1;
SCK_pPio->PIO_CODR = SCK_dwMask;
}
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.h b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
similarity index 82%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.h
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
index aa75cf9fa1..b832474150 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.h
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,8 +21,9 @@
*/
#pragma once
-#include "../../inc/MarlinConfigPre.h"
-#include "../shared/Marduino.h"
+#include "../../../inc/MarlinConfigPre.h"
+#include "../../shared/Marduino.h"
+#include
void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index);
void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level);
diff --git a/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h b/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
index eb4833ecd6..daa2b3c15e 100644
--- a/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,45 +38,46 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
/**
* Endstop interrupts for Due based targets.
* On Due, all pins support external interrupt capability.
*/
-void setup_endstop_interrupts(void) {
+void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
#if HAS_X_MAX
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
+ _ATTACH(X_MAX_PIN);
#endif
#if HAS_X_MIN
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#endif
#if HAS_Y_MAX
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#endif
#if HAS_Y_MIN
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#endif
#if HAS_Z_MAX
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#endif
#if HAS_Z_MIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#endif
#if HAS_Z2_MAX
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#endif
#if HAS_Z2_MIN
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#endif
#if HAS_Z3_MAX
- attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#endif
#if HAS_Z3_MIN
- attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#endif
#if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#endif
}
diff --git a/Marlin/src/HAL/HAL_DUE/fastio_Due.h b/Marlin/src/HAL/HAL_DUE/fastio.h
similarity index 96%
rename from Marlin/src/HAL/HAL_DUE/fastio_Due.h
rename to Marlin/src/HAL/HAL_DUE/fastio.h
index fd89a248e2..a97a944e33 100644
--- a/Marlin/src/HAL/HAL_DUE/fastio_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -39,6 +39,8 @@
#include
+#include "../../inc/MarlinConfigPre.h"
+
/**
* Utility functions
*/
@@ -62,28 +64,20 @@
// Read a pin
#define _READ(IO) bool(DIO ## IO ## _WPORT -> PIO_PDSR & MASK(DIO ## IO ## _PIN))
-// Write to a pin
-#define _WRITE_VAR(IO,V) do { \
- volatile Pio* port = digitalPinToPort(IO); \
- const uint32_t mask = digitalPinToBitMask(IO); \
- if (V) port->PIO_SODR = mask; \
- else port->PIO_CODR = mask; \
-} while(0)
-
// Write to a pin
#define _WRITE(IO,V) do { \
volatile Pio* port = (DIO ## IO ## _WPORT); \
const uint32_t mask = MASK(DIO ## IO ## _PIN); \
if (V) port->PIO_SODR = mask; \
else port->PIO_CODR = mask; \
-} while(0)
+}while(0)
// Toggle a pin
#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
#if MB(PRINTRBOARD_G2)
- #include "G2_pins.h"
+ #include "fastio/G2_pins.h"
// Set pin as input
#define _SET_INPUT(IO) do{ \
@@ -160,7 +154,6 @@
#define READ(IO) _READ(IO)
// Write to a pin (wrapper)
-#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
#define WRITE(IO,V) _WRITE(IO,V)
// Toggle a pin (wrapper)
diff --git a/Marlin/src/HAL/HAL_DUE/G2_PWM.cpp b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.cpp
similarity index 98%
rename from Marlin/src/HAL/HAL_DUE/G2_PWM.cpp
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.cpp
index cfb064097e..4afd83ad4b 100644
--- a/Marlin/src/HAL/HAL_DUE/G2_PWM.cpp
+++ b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
* Some jitter in the Vref signal is OK so the interrupt priority is left at its default value.
*/
-#include "../../inc/MarlinConfig.h"
+#include "../../../inc/MarlinConfig.h"
#if MB(PRINTRBOARD_G2)
diff --git a/Marlin/src/HAL/HAL_DUE/G2_PWM.h b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.h
similarity index 93%
rename from Marlin/src/HAL/HAL_DUE/G2_PWM.h
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.h
index 5cbeaceba9..4a84dfe64a 100644
--- a/Marlin/src/HAL/HAL_DUE/G2_PWM.h
+++ b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,14 +19,15 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* This module is stripped down version of the LPC1768_PWM.h file from
* PR #7500. It is hardwired for the PRINTRBOARD_G2 Motor Current needs.
*/
-#include "../../inc/MarlinConfigPre.h"
-#include "../../module/stepper.h"
+#include "../../../inc/MarlinConfigPre.h"
+#include "../../../module/stepper.h"
//C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\module\stepper.h
//C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\HAL\HAL_DUE\G2_PWM.h
diff --git a/Marlin/src/HAL/HAL_DUE/G2_pins.h b/Marlin/src/HAL/HAL_DUE/fastio/G2_pins.h
similarity index 99%
rename from Marlin/src/HAL/HAL_DUE/G2_pins.h
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_pins.h
index 49849a67d5..e5ce834f45 100644
--- a/Marlin/src/HAL/HAL_DUE/G2_pins.h
+++ b/Marlin/src/HAL/HAL_DUE/fastio/G2_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_DUE/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_DUE/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_DUE/SanityCheck.h b/Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h
similarity index 94%
rename from Marlin/src/HAL/HAL_DUE/SanityCheck.h
rename to Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h
index 30a5d72b25..a8d51edfab 100644
--- a/Marlin/src/HAL/HAL_DUE/SanityCheck.h
+++ b/Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Test Arduino Due specific configuration values for errors at compile-time.
diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
index 4d788acae6..fc1baa22ac 100644
--- a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
@@ -29,16 +29,16 @@
#include "../../inc/MarlinConfig.h"
#include "../shared/persistent_store_api.h"
-#if DISABLED(I2C_EEPROM, SPI_EEPROM)
+#if !defined(E2END) && NONE(I2C_EEPROM, SPI_EEPROM)
#define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp)
#endif
-extern void eeprom_flush(void);
+extern void eeprom_flush();
bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() {
- #if DISABLED(I2C_EEPROM, SPI_EEPROM)
+ #if NONE(I2C_EEPROM, SPI_EEPROM)
eeprom_flush();
#endif
return true;
diff --git a/Marlin/src/HAL/HAL_DUE/pinsDebug.h b/Marlin/src/HAL/HAL_DUE/pinsDebug.h
index 9b6cbe1cc4..ed78f8adbb 100644
--- a/Marlin/src/HAL/HAL_DUE/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_DUE/pinsDebug.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -65,9 +62,8 @@
#define digitalRead_mod(p) extDigitalRead(p) // AVR digitalRead disabled PWM before it read the pin
#define PRINT_PORT(p)
-#define NAME_FORMAT(p) PSTR("%-##p##s")
-#define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
-#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer);} while (0)
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
#define GET_ARRAY_PIN(p) pin_array[p].pin
#define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
diff --git a/Marlin/src/HAL/HAL_DUE/spi_pins.h b/Marlin/src/HAL/HAL_DUE/spi_pins.h
index 58916c91ee..64ee17a9d8 100644
--- a/Marlin/src/HAL/HAL_DUE/spi_pins.h
+++ b/Marlin/src/HAL/HAL_DUE/spi_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -41,7 +41,7 @@
#define SPI_CHAN 0
#else
#define SPI_PIN 87
- #define SPI_CHAN 1
+ #define SPI_CHAN 1
#endif
#define SCK_PIN 76
#define MISO_PIN 74
diff --git a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp b/Marlin/src/HAL/HAL_DUE/timers.cpp
similarity index 69%
rename from Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/timers.cpp
index 43c8e572b6..6925f93498 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/timers.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -28,42 +28,29 @@
#ifdef ARDUINO_ARCH_SAM
-// --------------------------------------------------------------------------
+// ------------------------
// Includes
-// --------------------------------------------------------------------------
+// ------------------------
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "HAL_timers_Due.h"
+#include "timers.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define NUM_HARDWARE_TIMERS 9
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TC0, 0, TC0_IRQn, 3}, // 0 - [servo timer5]
{ TC0, 1, TC1_IRQn, 0}, // 1
{ TC0, 2, TC2_IRQn, 2}, // 2 - stepper
- { TC1, 0, TC3_IRQn, 0}, // 3
+ { TC1, 0, TC3_IRQn, 0}, // 3 - stepper for BOARD_ARCHIM1
{ TC1, 1, TC4_IRQn, 15}, // 4 - temperature
{ TC1, 2, TC5_IRQn, 3}, // 5 - [servo timer3]
{ TC2, 0, TC6_IRQn, 14}, // 6 - tone
@@ -71,17 +58,9 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TC2, 2, TC8_IRQn, 0}, // 8
};
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
/*
Timer_clock1: Prescaler 2 -> 42MHz
diff --git a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h b/Marlin/src/HAL/HAL_DUE/timers.h
similarity index 81%
rename from Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
rename to Marlin/src/HAL/HAL_DUE/timers.h
index a2676e0875..b7b2cf7341 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
@@ -26,15 +26,11 @@
* For ARDUINO_ARCH_SAM
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -43,7 +39,9 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
+#ifndef STEP_TIMER_NUM
#define STEP_TIMER_NUM 2 // index of timer to use for stepper
+#endif
#define TEMP_TIMER_NUM 4 // index of timer to use for temperature
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
@@ -65,13 +63,15 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() void TC2_Handler()
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() void TC2_Handler()
+#endif
#define HAL_TEMP_TIMER_ISR() void TC4_Handler()
#define HAL_TONE_TIMER_ISR() void TC6_Handler()
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
Tc *pTimerRegs;
@@ -80,15 +80,15 @@ typedef struct {
uint8_t priority;
} tTimerConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
extern const tTimerConfig TimerConfig[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
diff --git a/Marlin/src/HAL/HAL_DUE/usb/compiler.h b/Marlin/src/HAL/HAL_DUE/usb/compiler.h
index d9ecd3f0fe..7719c129c3 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/compiler.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/compiler.h
@@ -112,7 +112,7 @@
* \def unused
* \brief Marking \a v as a unused parameter or value.
*/
-#define unused(v) do { (void)(v); } while(0)
+#define unused(v) do { (void)(v); }while(0)
/**
* \def barrier
@@ -169,7 +169,7 @@
* heuristics and inline the function no matter how big it thinks it
* becomes.
*/
-#if defined(__CC_ARM)
+#ifdef __CC_ARM
# define __always_inline __forceinline
#elif (defined __GNUC__)
#ifdef __always_inline
@@ -187,7 +187,7 @@
* This annotation instructs the compiler to ignore its inlining
* heuristics and not inline the function.
*/
-#if defined(__CC_ARM)
+#ifdef __CC_ARM
# define __no_inline __attribute__((noinline))
#elif (defined __GNUC__)
# define __no_inline __attribute__((__noinline__))
@@ -204,7 +204,7 @@
*
* \param expr Expression to evaluate and supposed to be nonzero.
*/
-#if defined(_ASSERT_ENABLE_)
+#ifdef _ASSERT_ENABLE_
# if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
// Assert() is defined in unit_test/suite.h
# include "unit_test/suite.h"
@@ -230,7 +230,7 @@
/* Define NO_INIT attribute */
#if 0 //ndef NO_INIT
-#if defined ( __CC_ARM )
+#ifdef __CC_ARM
# define NO_INIT __attribute__((zero_init))
#elif defined ( __ICCARM__ )
# define NO_INIT __no_init
@@ -262,7 +262,7 @@
//! @{
typedef unsigned char Bool; //!< Boolean.
#ifndef __cplusplus
-#if !defined(__bool_true_false_are_defined)
+#ifndef __bool_true_false_are_defined
typedef unsigned char bool; //!< Boolean.
#endif
#endif
@@ -443,7 +443,7 @@ typedef struct
#define DISABLE 0
#define ENABLE 1
#ifndef __cplusplus
-#if !defined(__bool_true_false_are_defined)
+#ifndef __bool_true_false_are_defined
#define false 0
#define true 1
#endif
@@ -998,14 +998,14 @@ typedef U8 Byte; //!< 8-bit unsigned integer.
#endif // #ifndef __ASSEMBLY__
-#if defined(__ICCARM__)
+#ifdef __ICCARM__
#define SHORTENUM __packed
#elif defined(__GNUC__)
#define SHORTENUM __attribute__((packed))
#endif
/* No operation */
-#if defined(__ICCARM__)
+#ifdef __ICCARM__
#define nop() __no_operation()
#elif defined(__GNUC__)
#define nop() (__NOP())
diff --git a/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h b/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h
index 6934494e57..8d5924d375 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h
@@ -48,9 +48,7 @@
#define _CONF_USB_H_
#undef UNUSED /* To avoid a macro clash as macros.h already defines it */
-#include "../../../core/macros.h" /* For ENABLED()/DISABLED() */
-#include "../../../core/boards.h" /* For MB() */
-#include "../../../../Configuration.h" /* For CUSTOM_MACHINE_NAME definition - We just need the name, no C++ allowed! */
+#include "../../../inc/MarlinConfigPre.h"
#include "compiler.h"
/**
@@ -59,8 +57,6 @@
*/
//! Device definition (mandatory)
-#define USB_DEVICE_VENDOR_ID 0x03EB /* ATMEL VID */
-#define USB_DEVICE_PRODUCT_ID 0x2424 /* MSC / CDC */
#define USB_DEVICE_MAJOR_VERSION 1
#define USB_DEVICE_MINOR_VERSION 0
#define USB_DEVICE_POWER 100 // Consumption on Vbus line (mA)
@@ -70,15 +66,6 @@
// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED)
// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
-//! USB Device string definitions (Optional)
-#define USB_DEVICE_MANUFACTURE_NAME "marlinfw.org"
-#ifdef CUSTOM_MACHINE_NAME
- #define USB_DEVICE_PRODUCT_NAME CUSTOM_MACHINE_NAME
-#else
- #define USB_DEVICE_PRODUCT_NAME "3D Printer"
-#endif
-#define USB_DEVICE_SERIAL_NAME "123985739853"
-
/**
* Device speeds support
* Low speed not supported by CDC and MSC
diff --git a/Marlin/src/HAL/HAL_DUE/usb/osc.h b/Marlin/src/HAL/HAL_DUE/usb/osc.h
index fe09d6fd3e..3a9543507b 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/osc.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/osc.h
@@ -61,27 +61,27 @@ extern "C" {
* Below BOARD_XXX macros are related to the specific board, and
* should be defined by the board code, otherwise default value are used.
*/
-#if !defined(BOARD_FREQ_SLCK_XTAL)
+#ifndef BOARD_FREQ_SLCK_XTAL
# warning The board slow clock xtal frequency has not been defined.
# define BOARD_FREQ_SLCK_XTAL (32768UL)
#endif
-#if !defined(BOARD_FREQ_SLCK_BYPASS)
+#ifndef BOARD_FREQ_SLCK_BYPASS
# warning The board slow clock bypass frequency has not been defined.
# define BOARD_FREQ_SLCK_BYPASS (32768UL)
#endif
-#if !defined(BOARD_FREQ_MAINCK_XTAL)
+#ifndef BOARD_FREQ_MAINCK_XTAL
# warning The board main clock xtal frequency has not been defined.
# define BOARD_FREQ_MAINCK_XTAL (12000000UL)
#endif
-#if !defined(BOARD_FREQ_MAINCK_BYPASS)
+#ifndef BOARD_FREQ_MAINCK_BYPASS
# warning The board main clock bypass frequency has not been defined.
# define BOARD_FREQ_MAINCK_BYPASS (12000000UL)
#endif
-#if !defined(BOARD_OSC_STARTUP_US)
+#ifndef BOARD_OSC_STARTUP_US
# warning The board main clock xtal startup time has not been defined.
# define BOARD_OSC_STARTUP_US (15625UL)
#endif
diff --git a/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp b/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp
index 468e9ee45d..b85a2b09a1 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp
+++ b/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp
@@ -15,11 +15,11 @@ extern "C" {
#define SD_MMC_BLOCK_SIZE 512
-void sd_mmc_spi_mem_init(void) {
+void sd_mmc_spi_mem_init() {
}
-Ctrl_status sd_mmc_spi_test_unit_ready(void) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
+Ctrl_status sd_mmc_spi_test_unit_ready() {
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
return CTRL_GOOD;
}
@@ -27,24 +27,18 @@ Ctrl_status sd_mmc_spi_test_unit_ready(void) {
// NOTE: This function is defined as returning the address of the last block
// in the card, which is cardSize() - 1
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1;
return CTRL_GOOD;
}
-bool sd_mmc_spi_unload(bool unload) {
- return true;
-}
+bool sd_mmc_spi_unload(bool) { return true; }
-bool sd_mmc_spi_wr_protect(void) {
- return false;
-}
+bool sd_mmc_spi_wr_protect() { return false; }
-bool sd_mmc_spi_removal(void) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
- return true;
- return false;
+bool sd_mmc_spi_removal() {
+ return (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted());
}
#if ACCESS_USB == true
@@ -61,7 +55,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE];
// #define DEBUG_MMC
Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC
@@ -98,7 +92,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
}
Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC
diff --git a/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h b/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h
index e5e7603c9a..6fadb9f36c 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h
@@ -43,12 +43,12 @@
* \asf_license_stop
*
*/
+
/*
* Support and FAQ: visit Atmel Support
*/
-#ifndef _SPC_PROTOCOL_H_
-#define _SPC_PROTOCOL_H_
-
+#ifndef _SPC_PROTOCOL_H_
+#define _SPC_PROTOCOL_H_
/**
* \ingroup usb_msc_protocol
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udd.h b/Marlin/src/HAL/HAL_DUE/usb/udd.h
index 10807f43d7..c87763de23 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udd.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udd.h
@@ -94,11 +94,11 @@ typedef struct {
uint16_t payload_size;
//! Callback called after reception of ZLP from setup request
- void (*callback) (void);
+ void (*callback)(void);
//! Callback called when the buffer given (.payload) is full or empty.
//! This one return false to abort data transfer, or true with a new buffer in .payload.
- bool(*over_under_run) (void);
+ bool (*over_under_run)(void);
} udd_ctrl_request_t;
extern udd_ctrl_request_t udd_g_ctrlreq;
@@ -123,7 +123,7 @@ extern udd_ctrl_request_t udd_g_ctrlreq;
* Registered by routine udd_ep_wait_stall_clear()
* Callback called when endpoint stall is cleared.
*/
-typedef void (*udd_callback_halt_cleared_t) (void);
+typedef void (*udd_callback_halt_cleared_t)(void);
/**
* \brief End of transfer callback function type.
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi.h b/Marlin/src/HAL/HAL_DUE/usb/udi.h
index 1fc7ae5d01..709908cad9 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi.h
@@ -82,7 +82,7 @@ typedef struct {
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
- bool(*enable) (void);
+ bool (*enable)(void);
/**
* \brief Disable the interface.
@@ -95,7 +95,7 @@ typedef struct {
* - the device is detached from the host (i.e. Vbus is no
* longer present)
*/
- void (*disable) (void);
+ void (*disable)(void);
/**
* \brief Handle a control request directed at an interface.
@@ -108,7 +108,7 @@ typedef struct {
*
* \return \c 1 if this interface supports the SETUP request, otherwise \c 0.
*/
- bool(*setup) (void);
+ bool (*setup)(void);
/**
* \brief Returns the current setting of the selected interface.
@@ -117,12 +117,12 @@ typedef struct {
*
* \return alternate setting of selected interface
*/
- uint8_t(*getsetting) (void);
+ uint8_t (*getsetting)(void);
/**
* \brief To signal that a SOF is occurred
*/
- void(*sof_notify) (void);
+ void (*sof_notify)(void);
} udi_api_t;
//@}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
index e54ee570fa..60c9546ce2 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
@@ -458,7 +458,7 @@ void udi_cdc_data_sof_notify(void)
}
-//-------------------------------------------------
+// ------------------------
//------- Internal routines to control serial line
static uint8_t udi_cdc_setup_to_port(void)
@@ -579,7 +579,7 @@ static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n,
}
-//-------------------------------------------------
+// ------------------------
//------- Internal routines to process data transfer
@@ -781,7 +781,7 @@ static void udi_cdc_tx_send(uint8_t port)
}
-//---------------------------------------------
+// ------------------------
//------- Application interface
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
index 45c5cef5ae..526419c860 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
@@ -55,7 +55,7 @@
#include "udi.h"
// Check the number of port
-#ifndef UDI_CDC_PORT_NB
+#ifndef UDI_CDC_PORT_NB
# define UDI_CDC_PORT_NB 1
#endif
#if (UDI_CDC_PORT_NB < 1) || (UDI_CDC_PORT_NB > 7)
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc_conf.h b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc_conf.h
index b99d611171..cbd3eb00ae 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc_conf.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc_conf.h
@@ -50,7 +50,7 @@
#include "usb_protocol_cdc.h"
#include "conf_usb.h"
-#ifndef UDI_CDC_PORT_NB
+#ifndef UDI_CDC_PORT_NB
# define UDI_CDC_PORT_NB 1
#endif
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
index 97d3f2990b..627bca0d4f 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
@@ -457,7 +457,7 @@ uint8_t udi_msc_getsetting(void)
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process CBW packet
static void udi_msc_cbw_invalid(void)
@@ -613,7 +613,7 @@ static bool udi_msc_cbw_validate(uint32_t alloc_len, uint8_t dir_flag)
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process small data packet
static void udi_msc_data_send(uint8_t * buffer, uint8_t buf_size)
@@ -645,7 +645,7 @@ static void udi_msc_data_sent(udd_ep_status_t status, iram_size_t nb_sent,
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process CSW packet
static void udi_msc_csw_process(void)
@@ -691,7 +691,7 @@ static void udi_msc_csw_sent(udd_ep_status_t status, iram_size_t nb_sent,
}
-//---------------------------------------------
+// ------------------------
//------- Routines manage sense data
static void udi_msc_clear_sense(void)
@@ -757,7 +757,7 @@ static void udi_msc_sense_command_invalid(void)
}
-//---------------------------------------------
+// ------------------------
//------- Routines manage SCSI Commands
static void udi_msc_spc_requestsense(void)
diff --git a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c
index 0dfcd5ac1f..9bac29276c 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c
@@ -40,6 +40,7 @@
* \asf_license_stop
*
*/
+
/*
* Support and FAQ: visit Atmel Support
*/
@@ -505,7 +506,7 @@ static bool udd_ep_interrupt(void);
//@}
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED GLOBAL EVENTS
/**
@@ -1306,7 +1307,7 @@ void udd_test_mode_packet(void)
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED THE CONTROL ENDPOINT
static void udd_reset_ep_ctrl(void)
@@ -1728,7 +1729,7 @@ static bool udd_ctrl_interrupt(void)
}
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED THE BULK/INTERRUPT/ISOCHRONOUS ENDPOINTS
#if (0 != USB_DEVICE_MAX_EP)
@@ -1904,7 +1905,7 @@ static void udd_ep_in_sent(udd_ep_id_t ep)
ptr_src = &ptr_job->buf[ptr_job->buf_cnt];
nb_remain = ptr_job->buf_size - ptr_job->buf_cnt;
// Fill a bank even if no data (ZLP)
- nb_data = MIN(nb_remain, pkt_size);
+ nb_data = min(nb_remain, pkt_size);
// Modify job information
ptr_job->buf_cnt += nb_data;
ptr_job->buf_load = nb_data;
diff --git a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h
index 1cd6914f85..97877994bf 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h
@@ -291,7 +291,7 @@ extern "C" {
//! available greater size, then applies register format of UOTGHS controller
//! for endpoint size bit-field.
#undef udd_format_endpoint_size
-#define udd_format_endpoint_size(size) (32 - clz(((uint32_t)MIN(MAX(size, 8), 1024) << 1) - 1) - 1 - 3)
+#define udd_format_endpoint_size(size) (32 - clz(((uint32_t)min(max(size, 8), 1024) << 1) - 1) - 1 - 3)
//! Configures the selected endpoint size
#define udd_configure_endpoint_size(ep, size) (Wr_bitfield(UOTGHS_ARRAY(UOTGHS_DEVEPTCFG[0], ep), UOTGHS_DEVEPTCFG_EPSIZE_Msk, udd_format_endpoint_size(size)))
//! Gets the configured selected endpoint size
diff --git a/Marlin/src/HAL/HAL_DUE/usb/usb_task.c b/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
index c9de09c113..b735858018 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
@@ -75,14 +75,14 @@ void usb_task_idle(void) {
bool usb_task_msc_isenabled(void) { return main_b_msc_enable; }
#endif
-bool usb_task_cdc_enable(const uint8_t port) { return ((main_b_cdc_enable = true)); }
-void usb_task_cdc_disable(const uint8_t port) { main_b_cdc_enable = false; main_b_dtr_active = false; }
+bool usb_task_cdc_enable(const uint8_t port) { UNUSED(port); return ((main_b_cdc_enable = true)); }
+void usb_task_cdc_disable(const uint8_t port) { UNUSED(port); main_b_cdc_enable = false; main_b_dtr_active = false; }
bool usb_task_cdc_isenabled(void) { return main_b_cdc_enable; }
/*! \brief Called by CDC interface
* Callback running when CDC device have received data
*/
-void usb_task_cdc_rx_notify(const uint8_t port) { }
+void usb_task_cdc_rx_notify(const uint8_t port) { UNUSED(port); }
/*! \brief Configures communication line
*
@@ -90,13 +90,13 @@ void usb_task_cdc_rx_notify(const uint8_t port) { }
*/
static uint16_t dwDTERate = 0;
void usb_task_cdc_config(const uint8_t port, usb_cdc_line_coding_t *cfg) {
- // Store last DTE rate
- dwDTERate = cfg->dwDTERate;
+ UNUSED(port);
+ // Store last DTE rate
+ dwDTERate = cfg->dwDTERate;
}
-
void usb_task_cdc_set_dtr(const uint8_t port, const bool b_enable) {
-
+ UNUSED(port);
// Keep DTR status
main_b_dtr_active = b_enable;
diff --git a/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp b/Marlin/src/HAL/HAL_DUE/watchdog.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/watchdog.cpp
index 2bf8080b76..1f51b75c18 100644
--- a/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#include "../../inc/MarlinConfig.h"
#include "../../Marlin.h"
-#include "watchdog_Due.h"
+#include "watchdog.h"
// Override Arduino runtime to either config or disable the watchdog
//
@@ -32,7 +32,7 @@
// process, because watchdog initialization at hardware reset on SAM3X8E
// is unreliable, and there is risk of unintended resets if we delay
// that initialization to a later time.
-void watchdogSetup(void) {
+void watchdogSetup() {
#if ENABLED(USE_WATCHDOG)
@@ -106,7 +106,7 @@ void watchdogSetup(void) {
// Initialize watchdog - On SAM3X, Watchdog was already configured
// and enabled or disabled at startup, so no need to reconfigure it
// here.
- void watchdog_init(void) {
+ void watchdog_init() {
// Reset watchdog to start clean
WDT_Restart(WDT);
}
diff --git a/Marlin/src/HAL/HAL_DUE/watchdog_Due.h b/Marlin/src/HAL/HAL_DUE/watchdog.h
similarity index 85%
rename from Marlin/src/HAL/HAL_DUE/watchdog_Due.h
rename to Marlin/src/HAL/HAL_DUE/watchdog.h
index 07187bfe6b..6e70adef81 100644
--- a/Marlin/src/HAL/HAL_DUE/watchdog_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,4 +30,4 @@ void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or AVR will go into emergency procedures.
-inline void watchdog_reset() { watchdogReset(); }
+inline void HAL_watchdog_refresh() { watchdogReset(); }
diff --git a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.cpp b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.cpp
index 6b1277b204..544b1b3f67 100644
--- a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h
index 082fa7df04..9fca4fcbea 100644
--- a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h
+++ b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
#ifdef ARDUINO_ARCH_ESP32
@@ -28,7 +29,7 @@ class FlushableHardwareSerial : public HardwareSerial {
public:
FlushableHardwareSerial(int uart_nr);
- inline void flushTX(void) { /* No need to flush the hardware serial, but defined here for compatibility. */ }
+ inline void flushTX() { /* No need to flush the hardware serial, but defined here for compatibility. */ }
};
extern FlushableHardwareSerial flushableSerial;
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.cpp b/Marlin/src/HAL/HAL_ESP32/HAL.cpp
index 00a40fbbe8..81567eeede 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/HAL.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,11 +22,8 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
+#include "timers.h"
#include
#include
#include
@@ -48,55 +45,44 @@
#endif
#endif
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
+// ------------------------
+// Externs
+// ------------------------
portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define V_REF 1100
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
-esp_adc_cal_characteristics_t characteristics;
+esp_adc_cal_characteristics_t characteristics[ADC_ATTEN_MAX];
+adc_atten_t attenuations[ADC1_CHANNEL_MAX] = {};
+uint32_t thresholds[ADC_ATTEN_MAX];
+volatile int numPWMUsed = 0,
+ pwmPins[MAX_PWM_PINS],
+ pwmValues[MAX_PWM_PINS];
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-void HAL_init(void) {
+void HAL_init() {
i2s_init();
}
-void HAL_init_board(void) {
+void HAL_init_board() {
#if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
spiffs_init();
#endif
@@ -113,24 +99,24 @@ void HAL_init_board(void) {
#endif
}
-void HAL_idletask(void) {
+void HAL_idletask() {
#if ENABLED(OTASUPPORT)
OTA_handle();
#endif
}
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
-uint8_t HAL_get_reset_source(void) { return rtc_get_reset_reason(1); }
+uint8_t HAL_get_reset_source() { return rtc_get_reset_reason(1); }
void _delay_ms(int delay_ms) { delay(delay_ms); }
// return free memory between end of heap (or end bss) and whatever is current
int freeMemory() { return ESP.getFreeHeap(); }
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
#define ADC1_CHANNEL(pin) ADC1_GPIO ## pin ## _CHANNEL
adc1_channel_t get_channel(int pin) {
@@ -145,65 +131,134 @@ adc1_channel_t get_channel(int pin) {
return ADC1_CHANNEL_MAX;
}
+void adc1_set_attenuation(adc1_channel_t chan, adc_atten_t atten) {
+ if (attenuations[chan] != atten) {
+ adc1_config_channel_atten(chan, atten);
+ attenuations[chan] = atten;
+ }
+}
+
void HAL_adc_init() {
// Configure ADC
adc1_config_width(ADC_WIDTH_12Bit);
// Configure channels only if used as (re-)configuring a pin for ADC that is used elsewhere might have adverse effects
#if HAS_TEMP_ADC_0
- adc1_config_channel_atten(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_1
- adc1_config_channel_atten(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_2
- adc1_config_channel_atten(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_3
- adc1_config_channel_atten(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_4
- adc1_config_channel_atten(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_5
- adc1_config_channel_atten(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
#endif
#if HAS_HEATED_BED
- adc1_config_channel_atten(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_CHAMBER
- adc1_config_channel_atten(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
- adc1_config_channel_atten(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
#endif
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.
// That's why we're not setting it up here.
- // Calculate ADC characteristics i.e. gain and offset factors
- esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, V_REF, &characteristics);
+ // Calculate ADC characteristics (i.e., gain and offset factors for each attenuation level)
+ for (int i = 0; i < ADC_ATTEN_MAX; i++) {
+ esp_adc_cal_characterize(ADC_UNIT_1, (adc_atten_t)i, ADC_WIDTH_BIT_12, V_REF, &characteristics[i]);
+
+ // Change attenuation 100mV below the calibrated threshold
+ thresholds[i] = esp_adc_cal_raw_to_voltage(4095, &characteristics[i]);
+ }
}
void HAL_adc_start_conversion(uint8_t adc_pin) {
+ const adc1_channel_t chan = get_channel(adc_pin);
uint32_t mv;
- esp_adc_cal_get_voltage((adc_channel_t)get_channel(adc_pin), &characteristics, &mv);
+ esp_adc_cal_get_voltage((adc_channel_t)chan, &characteristics[attenuations[chan]], &mv);
+ HAL_adc_result = mv * 1023.0 / 3300.0;
- HAL_adc_result = mv*1023.0/3300.0;
+ // Change the attenuation level based on the new reading
+ adc_atten_t atten;
+ if (mv < thresholds[ADC_ATTEN_DB_0] - 100)
+ atten = ADC_ATTEN_DB_0;
+ else if (mv > thresholds[ADC_ATTEN_DB_0] - 50 && mv < thresholds[ADC_ATTEN_DB_2_5] - 100)
+ atten = ADC_ATTEN_DB_2_5;
+ else if (mv > thresholds[ADC_ATTEN_DB_2_5] - 50 && mv < thresholds[ADC_ATTEN_DB_6] - 100)
+ atten = ADC_ATTEN_DB_6;
+ else if (mv > thresholds[ADC_ATTEN_DB_6] - 50)
+ atten = ADC_ATTEN_DB_11;
+ else return;
+
+ adc1_set_attenuation(chan, atten);
}
-void analogWrite(int pin, int value) {
- static int cnt_channel = 1,
- pin_to_channel[40] = {};
- if (pin_to_channel[pin] == 0) {
- ledcAttachPin(pin, cnt_channel);
- ledcSetup(cnt_channel, 490, 8);
- ledcWrite(cnt_channel, value);
-
- pin_to_channel[pin] = cnt_channel++;
+void analogWrite(pin_t pin, int value) {
+ // Use ledc hardware for internal pins
+ if (pin < 34) {
+ static int cnt_channel = 1, pin_to_channel[40] = { 0 };
+ if (pin_to_channel[pin] == 0) {
+ ledcAttachPin(pin, cnt_channel);
+ ledcSetup(cnt_channel, 490, 8);
+ ledcWrite(cnt_channel, value);
+ pin_to_channel[pin] = cnt_channel++;
+ }
+ ledcWrite(pin_to_channel[pin], value);
+ return;
}
- ledcWrite(pin_to_channel[pin], value);
+ int idx = -1;
+
+ // Search Pin
+ for (int i = 0; i < numPWMUsed; ++i)
+ if (pwmPins[i] == pin) { idx = i; break; }
+
+ // not found ?
+ if (idx < 0) {
+ // No slots remaining
+ if (numPWMUsed >= MAX_PWM_PINS) return;
+
+ // Take new slot for pin
+ idx = numPWMUsed;
+ pwmPins[idx] = pin;
+ // Start timer on first use
+ if (idx == 0) HAL_timer_start(PWM_TIMER_NUM, PWM_TIMER_FREQUENCY);
+
+ ++numPWMUsed;
+ }
+
+ // Use 7bit internal value - add 1 to have 100% high at 255
+ pwmValues[idx] = (value + 1) / 2;
+}
+
+// Handle PWM timer interrupt
+HAL_PWM_TIMER_ISR() {
+ HAL_timer_isr_prologue(PWM_TIMER_NUM);
+
+ static uint8_t count = 0;
+
+ for (int i = 0; i < numPWMUsed; ++i) {
+ if (count == 0) // Start of interval
+ WRITE(pwmPins[i], pwmValues[i] ? HIGH : LOW);
+ else if (pwmValues[i] == count) // End of duration
+ WRITE(pwmPins[i], LOW);
+ }
+
+ // 128 for 7 Bit resolution
+ count = (count + 1) & 0x7F;
+
+ HAL_timer_isr_epilogue(PWM_TIMER_NUM);
}
#endif // ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.h b/Marlin/src/HAL/HAL_ESP32/HAL.h
index 9e4ab78a9a..0736ff3c59 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL.h
+++ b/Marlin/src/HAL/HAL_ESP32/HAL.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
@@ -24,28 +24,24 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_ESP32.h"
-#include "watchdog_ESP32.h"
+#include "fastio.h"
+#include "watchdog.h"
#include "i2s.h"
-#include "HAL_timers_ESP32.h"
+#include "timers.h"
#include "WebSocketSerial.h"
#include "FlushableHardwareSerial.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
extern portMUX_TYPE spinlock;
@@ -69,36 +65,39 @@ extern portMUX_TYPE spinlock;
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef int16_t pin_t;
#define HAL_SERVO_LIB Servo
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
/** result of last ADC conversion */
extern uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// clear reset reason
-void HAL_clear_reset_source (void);
+void HAL_clear_reset_source();
// reset reason
-uint8_t HAL_get_reset_source(void);
+uint8_t HAL_get_reset_source();
void _delay_ms(int delay);
-int freeMemory(void);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+int freeMemory();
+#pragma GCC diagnostic pop
-void analogWrite(int pin, int value);
+void analogWrite(pin_t pin, int value);
// EEPROM
void eeprom_write_byte(uint8_t *pos, unsigned char value);
@@ -109,7 +108,7 @@ void eeprom_update_block (const void *__src, void *__dst, size_t __n);
// ADC
#define HAL_ANALOG_SELECT(pin)
-void HAL_adc_init(void);
+void HAL_adc_init();
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
@@ -123,8 +122,7 @@ void HAL_adc_start_conversion(uint8_t adc_pin);
// Enable hooks into idle and setup for HAL
#define HAL_IDLETASK 1
-#define HAL_INIT 1
#define BOARD_INIT() HAL_init_board();
-void HAL_idletask(void);
-void HAL_init(void);
-void HAL_init_board(void);
+void HAL_idletask();
+void HAL_init();
+void HAL_init_board();
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/HAL_SPI.cpp
similarity index 71%
rename from Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/HAL_SPI.cpp
index d48b14d610..eba880b4fd 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/HAL_SPI.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,47 +23,43 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
#include "../shared/HAL_SPI.h"
-#include "pins_arduino.h"
+#include
#include "spi_pins.h"
-#include "../../core/macros.h"
#include
-// --------------------------------------------------------------------------
+#include "../../core/macros.h"
+
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
static SPISettings spiConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if ENABLED(SOFTWARE_SPI)
- // --------------------------------------------------------------------------
+ // ------------------------
// Software SPI
- // --------------------------------------------------------------------------
+ // ------------------------
#error "Software SPI not supported for ESP32. Use Hardware SPI."
#else
-// --------------------------------------------------------------------------
+// ------------------------
// Hardware SPI
-// --------------------------------------------------------------------------
+// ------------------------
void spiBegin() {
#if !PIN_EXISTS(SS)
#error "SS_PIN not defined!"
#endif
- WRITE(SS_PIN, HIGH);
- SET_OUTPUT(SS_PIN);
+ OUT_WRITE(SS_PIN, HIGH);
}
void spiInit(uint8_t spiRate) {
@@ -84,7 +80,7 @@ void spiInit(uint8_t spiRate) {
SPI.begin();
}
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/Servo.cpp
similarity index 55%
rename from Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/Servo.cpp
index bf3d228a6a..3c3b8fa704 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/Servo.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,30 +25,32 @@
#if HAS_SERVOS
-#include "HAL_Servo_ESP32.h"
+#include "Servo.h"
-int Servo::channel_next_free = 0;
+// Adjacent channels (0/1, 2/3 etc.) share the same timer and therefore the same frequency and resolution settings on ESP32,
+// so we only allocate servo channels up high to avoid side effects with regards to analogWrite (fans, leds, laser pwm etc.)
+int Servo::channel_next_free = 12;
Servo::Servo() {
- this->channel = channel_next_free++;
+ channel = channel_next_free++;
}
-int8_t Servo::attach(const int pin) {
- if (this->channel >= CHANNEL_MAX_NUM) return -1;
- if (pin > 0) this->pin = pin;
+int8_t Servo::attach(const int inPin) {
+ if (channel >= CHANNEL_MAX_NUM) return -1;
+ if (pin > 0) pin = inPin;
- ledcSetup(this->channel, 50, 16); // channel X, 50 Hz, 16-bit depth
- ledcAttachPin(this->pin, this->channel);
+ ledcSetup(channel, 50, 16); // channel X, 50 Hz, 16-bit depth
+ ledcAttachPin(pin, channel);
return true;
}
-void Servo::detach() { ledcDetachPin(this->pin) }
+void Servo::detach() { ledcDetachPin(pin); }
-int Servo::read() { return this->degrees; }
+int Servo::read() { return degrees; }
-void Servo::write(int degrees) {
- this->degrees = constrain(degrees, MIN_ANGLE, MAX_ANGLE);
- int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
+void Servo::write(int inDegrees) {
+ degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
+ int us = map(degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
ledcWrite(channel, duty);
}
@@ -56,11 +58,11 @@ void Servo::write(int degrees) {
void Servo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->channel]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[channel]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.h b/Marlin/src/HAL/HAL_ESP32/Servo.h
similarity index 93%
rename from Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/Servo.h
index b6c250038e..7b73ef0f3c 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/Servo.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
index f997ca9d98..9a38d3996a 100644
--- a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -66,15 +66,15 @@ ring_buffer_pos_t RingBuffer::write(const uint8_t *buffer, ring_buffer_pos_t siz
return written;
}
-int RingBuffer::available(void) {
+int RingBuffer::available() {
return (size - read_index + write_index) & (size - 1);
}
-int RingBuffer::peek(void) {
+int RingBuffer::peek() {
return available() ? data[read_index] : -1;
}
-int RingBuffer::read(void) {
+int RingBuffer::read() {
if (available()) {
const int ret = data[read_index];
read_index = NEXT_INDEX(read_index, size);
@@ -94,7 +94,7 @@ ring_buffer_pos_t RingBuffer::read(uint8_t *buffer) {
return len;
}
-void RingBuffer::flush(void) { read_index = write_index; }
+void RingBuffer::flush() { read_index = write_index; }
// WebSocketSerial impl
WebSocketSerial::WebSocketSerial()
@@ -120,10 +120,10 @@ void WebSocketSerial::begin(const long baud_setting) {
}
void WebSocketSerial::end() { }
-int WebSocketSerial::peek(void) { return rx_buffer.peek(); }
-int WebSocketSerial::read(void) { return rx_buffer.read(); }
-int WebSocketSerial::available(void) { return rx_buffer.available(); }
-void WebSocketSerial::flush(void) { rx_buffer.flush(); }
+int WebSocketSerial::peek() { return rx_buffer.peek(); }
+int WebSocketSerial::read() { return rx_buffer.read(); }
+int WebSocketSerial::available() { return rx_buffer.available(); }
+void WebSocketSerial::flush() { rx_buffer.flush(); }
size_t WebSocketSerial::write(const uint8_t c) {
size_t ret = tx_buffer.write(c);
@@ -145,7 +145,7 @@ size_t WebSocketSerial::write(const uint8_t* buffer, size_t size) {
return written;
}
-void WebSocketSerial::flushTX(void) {
+void WebSocketSerial::flushTX() {
// No need to do anything as there's no benefit to sending partial lines over the websocket connection.
}
diff --git a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.h b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.h
index 6100587555..9590271b01 100644
--- a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.h
+++ b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -45,11 +45,11 @@ public:
RingBuffer(ring_buffer_pos_t size);
~RingBuffer();
- int available(void);
- int peek(void);
- int read(void);
+ int available();
+ int peek();
+ int read();
ring_buffer_pos_t read(uint8_t *buffer);
- void flush(void);
+ void flush();
ring_buffer_pos_t write(const uint8_t c);
ring_buffer_pos_t write(const uint8_t* buffer, ring_buffer_pos_t size);
};
@@ -62,11 +62,11 @@ public:
WebSocketSerial();
void begin(const long);
void end();
- int available(void);
- int peek(void);
- int read(void);
- void flush(void);
- void flushTX(void);
+ int available();
+ int peek();
+ int read();
+ void flush();
+ void flushTX();
size_t write(const uint8_t c);
size_t write(const uint8_t* buffer, size_t size);
diff --git a/Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h b/Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h
index d4c8cbd490..31a3e4d667 100644
--- a/Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,40 +38,41 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void ICACHE_RAM_ATTR endstop_ISR(void) { endstops.update(); }
+void ICACHE_RAM_ATTR endstop_ISR() { endstops.update(); }
-void setup_endstop_interrupts(void) {
+void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
#if HAS_X_MAX
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MAX_PIN);
#endif
#if HAS_X_MIN
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#endif
#if HAS_Y_MAX
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#endif
#if HAS_Y_MIN
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#endif
#if HAS_Z_MAX
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#endif
#if HAS_Z_MIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#endif
#if HAS_Z2_MAX
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#endif
#if HAS_Z2_MIN
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#endif
#if HAS_Z3_MAX
- attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#endif
#if HAS_Z3_MIN
- attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#endif
#if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#endif
}
diff --git a/Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h b/Marlin/src/HAL/HAL_ESP32/fastio.h
similarity index 90%
rename from Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/fastio.h
index c996d643a6..1641116b90 100644
--- a/Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -66,7 +66,7 @@
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
// PWM outputs
-#define PWM_PIN(P) (P < 34) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
+#define PWM_PIN(P) (P < 34 || P > 127) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
// Toggle pin value
#define TOGGLE(IO) WRITE(IO, !READ(IO))
diff --git a/Marlin/src/HAL/HAL_ESP32/i2s.cpp b/Marlin/src/HAL/HAL_ESP32/i2s.cpp
index 87c3959e7c..1f7c508cf1 100644
--- a/Marlin/src/HAL/HAL_ESP32/i2s.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/i2s.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,10 +21,11 @@
*/
#ifdef ARDUINO_ARCH_ESP32
+#include "../../inc/MarlinConfigPre.h"
+
#include "i2s.h"
#include "../shared/Marduino.h"
-#include "../../core/macros.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/i2s_struct.h"
@@ -55,7 +56,7 @@ static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1};
static i2s_dma_t dma;
// output value
-uint32_t i2s_port_data;
+uint32_t i2s_port_data = 0;
#define I2S_ENTER_CRITICAL() portENTER_CRITICAL(&i2s_spinlock[i2s_num])
#define I2S_EXIT_CRITICAL() portEXIT_CRITICAL(&i2s_spinlock[i2s_num])
@@ -139,13 +140,13 @@ static void IRAM_ATTR i2s_intr_handler_default(void *arg) {
}
void stepperTask(void* parameter) {
- uint32_t i, remaining = 0;
+ uint32_t remaining = 0;
while (1) {
xQueueReceive(dma.queue, &dma.current, portMAX_DELAY);
dma.rw_pos = 0;
- for (i = 0; i < DMA_SAMPLE_COUNT; i++) {
+ while (dma.rw_pos < DMA_SAMPLE_COUNT) {
// Fill with the port data post pulse_phase until the next step
if (remaining) {
i2s_push_sample();
@@ -253,7 +254,13 @@ int i2s_init() {
I2S0.fifo_conf.dscr_en = 0;
- I2S0.conf_chan.tx_chan_mod = 0;
+ I2S0.conf_chan.tx_chan_mod = (
+ #if ENABLED(I2S_STEPPER_SPLIT_STREAM)
+ 4
+ #else
+ 0
+ #endif
+ );
I2S0.fifo_conf.tx_fifo_mod = 0;
I2S0.conf.tx_mono = 0;
@@ -313,10 +320,19 @@ int i2s_init() {
}
void i2s_write(uint8_t pin, uint8_t val) {
+ #if ENABLED(I2S_STEPPER_SPLIT_STREAM)
+ if (pin >= 16) {
+ SET_BIT_TO(I2S0.conf_single_data, pin, val);
+ return;
+ }
+ #endif
SET_BIT_TO(i2s_port_data, pin, val);
}
uint8_t i2s_state(uint8_t pin) {
+ #if ENABLED(I2S_STEPPER_SPLIT_STREAM)
+ if (pin >= 16) return TEST(I2S0.conf_single_data, pin);
+ #endif
return TEST(i2s_port_data, pin);
}
diff --git a/Marlin/src/HAL/HAL_ESP32/i2s.h b/Marlin/src/HAL/HAL_ESP32/i2s.h
index 42c35aa12d..971405a343 100644
--- a/Marlin/src/HAL/HAL_ESP32/i2s.h
+++ b/Marlin/src/HAL/HAL_ESP32/i2s.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,9 +33,3 @@ uint8_t i2s_state(uint8_t pin);
void i2s_write(uint8_t pin, uint8_t val);
void i2s_push_sample();
-
-// pin definitions
-
-#define I2S_WS 25
-#define I2S_BCK 26
-#define I2S_DATA 27
diff --git a/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_ESP32/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_ESP32/SanityCheck.h b/Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h
similarity index 87%
rename from Marlin/src/HAL/HAL_ESP32/SanityCheck.h
rename to Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h
index f911d84ce0..9c62a353e7 100644
--- a/Marlin/src/HAL/HAL_ESP32/SanityCheck.h
+++ b/Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
#if ENABLED(EMERGENCY_PARSER)
#error "EMERGENCY_PARSER is not yet implemented for ESP32. Disable EMERGENCY_PARSER to continue."
diff --git a/Marlin/src/HAL/HAL_ESP32/ota.cpp b/Marlin/src/HAL/HAL_ESP32/ota.cpp
index 40ec1ab875..98ea3b5eb7 100644
--- a/Marlin/src/HAL/HAL_ESP32/ota.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/ota.cpp
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
diff --git a/Marlin/src/HAL/HAL_ESP32/ota.h b/Marlin/src/HAL/HAL_ESP32/ota.h
index 80e04e123d..7e89e93ce2 100644
--- a/Marlin/src/HAL/HAL_ESP32/ota.h
+++ b/Marlin/src/HAL/HAL_ESP32/ota.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
diff --git a/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp b/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp
index 1894697cb2..5227da3568 100644
--- a/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/servotimers.h b/Marlin/src/HAL/HAL_ESP32/servotimers.h
index 0604ca0a25..85f26f4016 100644
--- a/Marlin/src/HAL/HAL_ESP32/servotimers.h
+++ b/Marlin/src/HAL/HAL_ESP32/servotimers.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,3 +19,4 @@
* along with this program. If not, see .
*
*/
+#pragma once
diff --git a/Marlin/src/HAL/HAL_ESP32/spi_pins.h b/Marlin/src/HAL/HAL_ESP32/spi_pins.h
index 4ef6d14ec3..03ab215224 100644
--- a/Marlin/src/HAL/HAL_ESP32/spi_pins.h
+++ b/Marlin/src/HAL/HAL_ESP32/spi_pins.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/spiffs.cpp b/Marlin/src/HAL/HAL_ESP32/spiffs.cpp
index b49ee9d4a8..a3e1bd8a25 100644
--- a/Marlin/src/HAL/HAL_ESP32/spiffs.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/spiffs.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/spiffs.h b/Marlin/src/HAL/HAL_ESP32/spiffs.h
index e1573340cd..8a1ee2f191 100644
--- a/Marlin/src/HAL/HAL_ESP32/spiffs.h
+++ b/Marlin/src/HAL/HAL_ESP32/spiffs.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/timers.cpp
similarity index 66%
rename from Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/timers.cpp
index 41d17df78a..79a79e37cd 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/timers.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,10 +22,6 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "esp_types.h"
#include "soc/timer_group_struct.h"
@@ -34,74 +30,53 @@
#include "HAL.h"
-#include "HAL_timers_ESP32.h"
+#include "timers.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define NUM_HARDWARE_TIMERS 4
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
static timg_dev_t *TG[2] = {&TIMERG0, &TIMERG1};
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TIMER_GROUP_0, TIMER_0, STEPPER_TIMER_PRESCALE, stepTC_Handler }, // 0 - Stepper
{ TIMER_GROUP_0, TIMER_1, TEMP_TIMER_PRESCALE, tempTC_Handler }, // 1 - Temperature
- { TIMER_GROUP_1, TIMER_0, 1, nullptr }, // 2
+ { TIMER_GROUP_1, TIMER_0, PWM_TIMER_PRESCALE, pwmTC_Handler }, // 2 - PWM
{ TIMER_GROUP_1, TIMER_1, 1, nullptr }, // 3
};
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-void IRAM_ATTR timer_group0_isr(void *para) {
- const int timer_idx = (int)para;
+void IRAM_ATTR timer_isr(void *para) {
+ const tTimerConfig& timer = TimerConfig[(int)para];
// Retrieve the interrupt status and the counter value
// from the timer that reported the interrupt
- uint32_t intr_status = TIMERG0.int_st_timers.val;
- TIMERG0.hw_timer[timer_idx].update = 1;
+ uint32_t intr_status = TG[timer.group]->int_st_timers.val;
+ TG[timer.group]->hw_timer[timer.idx].update = 1;
// Clear the interrupt
- if (intr_status & BIT(timer_idx)) {
- switch (timer_idx) {
- case TIMER_0: TIMERG0.int_clr_timers.t0 = 1; break;
- case TIMER_1: TIMERG0.int_clr_timers.t1 = 1; break;
+ if (intr_status & BIT(timer.idx)) {
+ switch (timer.idx) {
+ case TIMER_0: TG[timer.group]->int_clr_timers.t0 = 1; break;
+ case TIMER_1: TG[timer.group]->int_clr_timers.t1 = 1; break;
+ case TIMER_MAX: break;
}
}
- const tTimerConfig timer = TimerConfig[timer_idx];
timer.fn();
// After the alarm has been triggered
// Enable it again so it gets triggered the next time
- TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
+ TG[timer.group]->hw_timer[timer.idx].config.alarm_en = TIMER_ALARM_EN;
}
/**
@@ -131,8 +106,7 @@ void HAL_timer_start(const uint8_t timer_num, uint32_t frequency) {
timer_enable_intr(timer.group, timer.idx);
- // TODO need to deal with timer_group1_isr
- timer_isr_register(timer.group, timer.idx, timer_group0_isr, (void*)timer.idx, 0, nullptr);
+ timer_isr_register(timer.group, timer.idx, timer_isr, (void*)timer_num, 0, nullptr);
timer_start(timer.group, timer.idx);
}
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h b/Marlin/src/HAL/HAL_ESP32/timers.h
similarity index 75%
rename from Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/timers.h
index d2baddce20..4b01f4ba7c 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/timers.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,10 +21,6 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "driver/timer.h"
@@ -33,9 +29,9 @@
#include "../../inc/MarlinConfig.h"
#include "../../pins/pins.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -44,6 +40,7 @@ typedef uint64_t hal_timer_t;
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
+#define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
@@ -63,6 +60,14 @@ typedef uint64_t hal_timer_t;
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
+#define PWM_TIMER_PRESCALE 10
+#if ENABLED(FAST_PWM_FAN)
+ #define PWM_TIMER_FREQUENCY FAST_PWM_FAN_FREQUENCY
+#else
+ #define PWM_TIMER_FREQUENCY (50*128) // 50Hz and 7bit resolution
+#endif
+#define MAX_PWM_PINS 32 // Number of PWM pin-slots
+
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
@@ -74,33 +79,34 @@ typedef uint64_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler(void)
-#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler(void)
+#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
+#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
+#define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
-extern "C" void tempTC_Handler(void);
-extern "C" void stepTC_Handler(void);
+extern "C" void tempTC_Handler();
+extern "C" void stepTC_Handler();
+extern "C" void pwmTC_Handler();
-
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
timer_group_t group;
timer_idx_t idx;
uint32_t divider;
- void (*fn)(void);
+ void (*fn)();
} tTimerConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
extern const tTimerConfig TimerConfig[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start (const uint8_t timer_num, uint32_t frequency);
void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t count);
diff --git a/Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/watchdog.cpp
similarity index 82%
rename from Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/watchdog.cpp
index b1c98cb55c..d05e67c856 100644
--- a/Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,13 +26,13 @@
#if ENABLED(USE_WATCHDOG)
-#include "watchdog_ESP32.h"
+#include "watchdog.h"
-void watchdogSetup(void) {
+void watchdogSetup() {
// do whatever. don't remove this function.
}
-void watchdog_init(void) {
+void watchdog_init() {
// TODO
}
diff --git a/Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h b/Marlin/src/HAL/HAL_ESP32/watchdog.h
similarity index 84%
rename from Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/watchdog.h
index 6ee92a73ec..6647ecefe6 100644
--- a/Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,4 +25,4 @@
void watchdog_init();
// Reset watchdog.
-inline void watchdog_reset() { }
+inline void HAL_watchdog_refresh() {}
diff --git a/Marlin/src/HAL/HAL_ESP32/web.cpp b/Marlin/src/HAL/HAL_ESP32/web.cpp
index 65d72ab088..c593fc0242 100644
--- a/Marlin/src/HAL/HAL_ESP32/web.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/web.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,16 +22,18 @@
#ifdef ARDUINO_ARCH_ESP32
+#include
+#undef DISABLED // esp32-hal-gpio.h
+
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(WEBSUPPORT)
-#include
#include "wifi.h"
AsyncEventSource events("/events"); // event source (Server-Sent events)
-void onNotFound(AsyncWebServerRequest *request){
+void onNotFound(AsyncWebServerRequest *request) {
request->send(404);
}
diff --git a/Marlin/src/HAL/HAL_ESP32/web.h b/Marlin/src/HAL/HAL_ESP32/web.h
index 4173fd91b0..d1d91b9c0f 100644
--- a/Marlin/src/HAL/HAL_ESP32/web.h
+++ b/Marlin/src/HAL/HAL_ESP32/web.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/wifi.cpp b/Marlin/src/HAL/HAL_ESP32/wifi.cpp
index ba81cd948c..19f1d8fb85 100644
--- a/Marlin/src/HAL/HAL_ESP32/wifi.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/wifi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_ESP32/wifi.h b/Marlin/src/HAL/HAL_ESP32/wifi.h
index 7be40ef900..4cd656cb33 100644
--- a/Marlin/src/HAL/HAL_ESP32/wifi.h
+++ b/Marlin/src/HAL/HAL_ESP32/wifi.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/HAL.cpp b/Marlin/src/HAL/HAL_LINUX/HAL.cpp
index 3d2dd5cd82..316f6b452a 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/HAL.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,10 +31,10 @@ HalSerial usb_serial;
extern "C" void u8g_xMicroDelay(uint16_t val) {
DELAY_US(val);
}
-extern "C" void u8g_MicroDelay(void) {
+extern "C" void u8g_MicroDelay() {
u8g_xMicroDelay(1);
}
-extern "C" void u8g_10MicroDelay(void) {
+extern "C" void u8g_10MicroDelay() {
u8g_xMicroDelay(10);
}
extern "C" void u8g_Delay(uint16_t val) {
@@ -47,11 +47,11 @@ int freeMemory() {
return 0;
}
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
-void HAL_adc_init(void) {
+void HAL_adc_init() {
}
@@ -64,18 +64,18 @@ void HAL_adc_start_conversion(const uint8_t ch) {
active_ch = ch;
}
-bool HAL_adc_finished(void) {
+bool HAL_adc_finished() {
return true;
}
-uint16_t HAL_adc_get_result(void) {
+uint16_t HAL_adc_get_result() {
pin_t pin = analogInputToDigitalPin(active_ch);
if (!VALID_PIN(pin)) return 0;
uint16_t data = ((Gpio::get(pin) >> 2) & 0x3FF);
return data; // return 10bit value as Marlin expects
}
-void HAL_pwm_init(void) {
+void HAL_pwm_init() {
}
diff --git a/Marlin/src/HAL/HAL_LINUX/HAL.h b/Marlin/src/HAL/HAL_LINUX/HAL.h
index b3cabdfe6f..5bd283e5c1 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL.h
+++ b/Marlin/src/HAL/HAL_LINUX/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -23,10 +23,6 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#define F_CPU 100000000
#define SystemCoreClock F_CPU
#include
@@ -60,9 +56,11 @@ uint8_t _getc();
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "HAL_timers.h"
+#include "timers.h"
#include "serial.h"
+#define SHARED_SERVOS HAS_SERVOS
+
extern HalSerial usb_serial;
#define MYSERIAL0 usb_serial
#define NUM_SERIAL 1
@@ -80,16 +78,13 @@ extern HalSerial usb_serial;
#define ENABLE_ISRS()
#define DISABLE_ISRS()
-//Utility functions
-int freeMemory(void);
+inline void HAL_init() {}
-// SPI: Extended functions which take a channel number (hardware SPI only)
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
+// Utility functions
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+int freeMemory();
+#pragma GCC diagnostic pop
// ADC
#define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin)
@@ -97,10 +92,14 @@ uint8_t spiRec(uint32_t chan);
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
-void HAL_adc_init(void);
+void HAL_adc_init();
void HAL_adc_enable_channel(int pin);
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
+
+// Reset source
+inline void HAL_clear_reset_source(void) {}
+inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
/* ---------------- Delay in cycles */
FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
diff --git a/Marlin/src/HAL/HAL_LINUX/SanityCheck.h b/Marlin/src/HAL/HAL_LINUX/SanityCheck.h
deleted file mode 100644
index 0b4322512f..0000000000
--- a/Marlin/src/HAL/HAL_LINUX/SanityCheck.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-/**
- * Test X86_64 configuration values for errors at compile-time.
- */
-
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
- #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
- #elif SPINDLE_LASER_POWERUP_DELAY < 1
- #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
-#endif
diff --git a/Marlin/src/HAL/HAL_LINUX/arduino.cpp b/Marlin/src/HAL/HAL_LINUX/arduino.cpp
index 408c96153d..88128dd91a 100644
--- a/Marlin/src/HAL/HAL_LINUX/arduino.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/arduino.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,8 +28,8 @@
#include "../shared/Delay.h"
// Interrupts
-void cli(void) { } // Disable
-void sei(void) { } // Enable
+void cli() { } // Disable
+void sei() { } // Enable
// Time functions
void _delay_ms(const int delay_ms) {
@@ -90,7 +90,7 @@ void eeprom_read_block(void *__dst, const void *__src, size_t __n) { }
void eeprom_update_block(const void *__src, void *__dst, size_t __n) { }
-char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s) {
+char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s) {
char format_string[20];
snprintf(format_string, 20, "%%%d.%df", __width, __prec);
sprintf(__s, format_string, __val);
diff --git a/Marlin/src/HAL/HAL_LINUX/fastio.h b/Marlin/src/HAL/HAL_LINUX/fastio.h
index dcf9136f78..5c2d6fcb7e 100644
--- a/Marlin/src/HAL/HAL_LINUX/fastio.h
+++ b/Marlin/src/HAL/HAL_LINUX/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -51,8 +51,6 @@
#define _READ(IO) READ_PIN(IO)
/// Write to a pin
-#define _WRITE_VAR(IO,V) digitalWrite(IO,V)
-
#define _WRITE(IO,V) WRITE_PIN(IO,V)
/// toggle a pin
@@ -84,7 +82,6 @@
#define READ(IO) _READ(IO)
/// Write to a pin wrapper
-#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
#define WRITE(IO,V) _WRITE(IO,V)
/// toggle a pin wrapper
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp
index 961f5c5d98..39dd3d1b3b 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Clock.h b/Marlin/src/HAL/HAL_LINUX/hardware/Clock.h
index e3dafe250a..e61051a0a3 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Clock.h
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Clock.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.cpp
index 0aeeb9c674..aced728172 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.h b/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.h
index a53ad029c4..37f3bc7a44 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.h
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Gpio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Heater.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/Heater.cpp
index a07f6ab202..59da64d337 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Heater.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Heater.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Heater.h b/Marlin/src/HAL/HAL_LINUX/hardware/Heater.h
index 90e9da21df..e0c250f62c 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Heater.h
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Heater.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.cpp
index 8fc2dc95c5..675afd4a21 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.h b/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.h
index 61cce9c106..afc2125971 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.h
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.cpp
index c50390d736..df133e9e18 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.h b/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.h
index 0e3b4b7503..1e8e887de5 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.h
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Timer.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/Timer.cpp
index 2bda5bc8cc..1c930cfce1 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Timer.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Timer.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Timer.h b/Marlin/src/HAL/HAL_LINUX/hardware/Timer.h
index 6aadbcbcb1..740d8ef4e8 100644
--- a/Marlin/src/HAL/HAL_LINUX/hardware/Timer.h
+++ b/Marlin/src/HAL/HAL_LINUX/hardware/Timer.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LINUX/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h b/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h
new file mode 100644
index 0000000000..776fa2f139
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h
@@ -0,0 +1,35 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Test X86_64-specific configuration values for errors at compile-time.
+ */
+
+// Emulating RAMPS
+#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
+ #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
+#endif
+
+#if ENABLED(FAST_PWM_FAN)
+ #error "FAST_PWM_FAN is not yet implemented for this platform."
+#endif
diff --git a/Marlin/src/HAL/HAL_LINUX/include/Arduino.h b/Marlin/src/HAL/HAL_LINUX/include/Arduino.h
index 60f14cc44f..13a8206e1b 100644
--- a/Marlin/src/HAL/HAL_LINUX/include/Arduino.h
+++ b/Marlin/src/HAL/HAL_LINUX/include/Arduino.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,16 +43,12 @@
#define FALLING 0x03
#define RISING 0x04
-#define E2END 0xFFF // EEPROM end address
-
typedef uint8_t byte;
#define PROGMEM
#define PSTR(v) (v)
#define PGM_P const char *
// Used for libraries, preprocessor, and constants
-#define min(a,b) ((a)<(b)?(a):(b))
-#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#ifndef isnan
@@ -67,9 +63,9 @@ typedef uint8_t byte;
#define constrain(value, arg_min, arg_max) ((value) < (arg_min) ? (arg_min) :((value) > (arg_max) ? (arg_max) : (value)))
//Interrupts
-void cli(void); // Disable
-void sei(void); // Enable
-void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);
+void cli(); // Disable
+void sei(); // Enable
+void attachInterrupt(uint32_t pin, void (*callback)(), uint32_t mode);
void detachInterrupt(uint32_t pin);
extern "C" void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode);
extern "C" void GpioDisableInt(uint32_t port, uint32_t pin);
@@ -113,13 +109,13 @@ uint16_t analogRead(pin_t);
// EEPROM
void eeprom_write_byte(unsigned char *pos, unsigned char value);
unsigned char eeprom_read_byte(unsigned char *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
+void eeprom_read_block(void *__dst, const void *__src, size_t __n);
+void eeprom_update_block(const void *__src, void *__dst, size_t __n);
int32_t random(int32_t);
int32_t random(int32_t, int32_t);
void randomSeed(uint32_t);
-char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);
+char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
int map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);
diff --git a/Marlin/src/HAL/HAL_LINUX/include/pinmapping.cpp b/Marlin/src/HAL/HAL_LINUX/include/pinmapping.cpp
index dca18a676b..a4ddb1b1ff 100644
--- a/Marlin/src/HAL/HAL_LINUX/include/pinmapping.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/include/pinmapping.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/include/pinmapping.h b/Marlin/src/HAL/HAL_LINUX/include/pinmapping.h
index effc464c73..a24f0b3ed1 100644
--- a/Marlin/src/HAL/HAL_LINUX/include/pinmapping.h
+++ b/Marlin/src/HAL/HAL_LINUX/include/pinmapping.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/include/serial.h b/Marlin/src/HAL/HAL_LINUX/include/serial.h
index 9b439de985..c6da82ad5a 100644
--- a/Marlin/src/HAL/HAL_LINUX/include/serial.h
+++ b/Marlin/src/HAL/HAL_LINUX/include/serial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -83,8 +83,9 @@ public:
HalSerial() { host_connected = true; }
- void begin(int32_t baud) {
- }
+ void begin(int32_t) {}
+
+ void end() {}
int peek() {
uint8_t value;
@@ -107,11 +108,11 @@ public:
void flush() { receive_buffer.clear(); }
- uint8_t availableForWrite(void){
+ uint8_t availableForWrite() {
return transmit_buffer.free() > 255 ? 255 : (uint8_t)transmit_buffer.free();
}
- void flushTX(void){
+ void flushTX() {
if (host_connected)
while (transmit_buffer.available()) { /* nada */ }
}
@@ -141,10 +142,10 @@ public:
void print_bin(uint32_t value, uint8_t num_digits) {
uint32_t mask = 1 << (num_digits -1);
for (uint8_t i = 0; i < num_digits; i++) {
- if (!(i % 4) && i) write(' ');
- if (!(i % 16) && i) write(' ');
- if (value & mask) write('1');
- else write('0');
+ if (!(i % 4) && i) write(' ');
+ if (!(i % 16) && i) write(' ');
+ if (value & mask) write('1');
+ else write('0');
value <<= 1;
}
}
@@ -199,7 +200,7 @@ public:
void println(unsigned long value, int nbase = 0) { print(value, nbase); println(); }
void println(float value, int round = 6) { printf("%f\n" , value); }
void println(double value, int round = 6) { printf("%f\n" , value); }
- void println(void) { print('\n'); }
+ void println() { print('\n'); }
volatile RingBuffer receive_buffer;
volatile RingBuffer transmit_buffer;
diff --git a/Marlin/src/HAL/HAL_LINUX/main.cpp b/Marlin/src/HAL/HAL_LINUX/main.cpp
index bbaa4b076a..4231affba7 100644
--- a/Marlin/src/HAL/HAL_LINUX/main.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/main.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -49,7 +49,7 @@ void write_serial_thread() {
void read_serial_thread() {
char buffer[255] = {};
for (;;) {
- std::size_t len = MIN(usb_serial.receive_buffer.free(), 254U);
+ std::size_t len = _MIN(usb_serial.receive_buffer.free(), 254U);
if (fgets(buffer, len, stdin))
for (std::size_t i = 0; i < strlen(buffer); i++)
usb_serial.receive_buffer.write(buffer[i]);
@@ -104,7 +104,7 @@ void simulation_loop() {
}
}
-int main(void) {
+int main() {
std::thread write_serial (write_serial_thread);
std::thread read_serial (read_serial_thread);
diff --git a/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
index f09b64416f..c4965d90e3 100644
--- a/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,8 @@
#include "../shared/persistent_store_api.h"
#include
-uint8_t buffer[E2END];
+#define LINUX_EEPROM_SIZE (E2END + 1)
+uint8_t buffer[LINUX_EEPROM_SIZE];
char filename[] = "eeprom.dat";
bool PersistentStore::access_start() {
@@ -40,8 +41,8 @@ bool PersistentStore::access_start() {
fseek(eeprom_file, 0L, SEEK_END);
std::size_t file_size = ftell(eeprom_file);
- if (file_size < E2END) {
- memset(buffer + file_size, eeprom_erase_value, E2END - file_size);
+ if (file_size < LINUX_EEPROM_SIZE) {
+ memset(buffer + file_size, eeprom_erase_value, LINUX_EEPROM_SIZE - file_size);
}
else {
fseek(eeprom_file, 0L, SEEK_SET);
@@ -60,7 +61,7 @@ bool PersistentStore::access_finish() {
return true;
}
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
std::size_t bytes_written = 0;
for (std::size_t i = 0; i < size; i++) {
diff --git a/Marlin/src/HAL/HAL_LINUX/pinsDebug.h b/Marlin/src/HAL/HAL_LINUX/pinsDebug.h
index cead56c30a..a28d2b60b9 100644
--- a/Marlin/src/HAL/HAL_LINUX/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_LINUX/pinsDebug.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,9 +32,8 @@
#define digitalRead_mod(p) digitalRead(p)
#define PRINT_PORT(p)
#define GET_ARRAY_PIN(p) pin_array[p].pin
-#define NAME_FORMAT(p) PSTR("%-##p##s")
-#define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
-#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer);} while (0)
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
// active ADC function/mode/code values for PINSEL registers
diff --git a/Marlin/src/HAL/HAL_LINUX/servo_private.h b/Marlin/src/HAL/HAL_LINUX/servo_private.h
index c0e0a0c710..2aba9a37db 100644
--- a/Marlin/src/HAL/HAL_LINUX/servo_private.h
+++ b/Marlin/src/HAL/HAL_LINUX/servo_private.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LINUX/spi_pins.h b/Marlin/src/HAL/HAL_LINUX/spi_pins.h
index fe510ddcff..fdd09b1c03 100644
--- a/Marlin/src/HAL/HAL_LINUX/spi_pins.h
+++ b/Marlin/src/HAL/HAL_LINUX/spi_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,11 +21,12 @@
*/
#pragma once
-#include "src/core/macros.h"
+#include "../../core/macros.h"
+#include "../../inc/MarlinConfigPre.h"
-#if BOTH(SDSUPPORT, DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
+#if HAS_GRAPHICAL_LCD && ENABLED(SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
#define LPC_SOFTWARE_SPI // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
- // needed due to the speed and mode requred for communicating with each device being different.
+ // needed due to the speed and mode required for communicating with each device being different.
// This requirement can be removed if the SPI access to these devices is updated to use
// spiBeginTransaction.
#endif
diff --git a/Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp b/Marlin/src/HAL/HAL_LINUX/timers.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp
rename to Marlin/src/HAL/HAL_LINUX/timers.cpp
index f7b46725af..f293d7f408 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/timers.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -25,7 +25,7 @@
#include "hardware/Timer.h"
#include "../../inc/MarlinConfig.h"
-#include "HAL_timers.h"
+#include "timers.h"
/**
* Use POSIX signals to attempt to emulate Interrupts
@@ -37,7 +37,7 @@ HAL_TEMP_TIMER_ISR();
Timer timers[2];
-void HAL_timer_init(void) {
+void HAL_timer_init() {
timers[0].init(0, STEPPER_TIMER_RATE, TIMER0_IRQHandler);
timers[1].init(1, TEMP_TIMER_RATE, TIMER1_IRQHandler);
}
diff --git a/Marlin/src/HAL/HAL_LINUX/HAL_timers.h b/Marlin/src/HAL/HAL_LINUX/timers.h
similarity index 88%
rename from Marlin/src/HAL/HAL_LINUX/HAL_timers.h
rename to Marlin/src/HAL/HAL_LINUX/timers.h
index 9505fc568a..8022aabd26 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL_timers.h
+++ b/Marlin/src/HAL/HAL_LINUX/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
@@ -24,15 +24,11 @@
* HAL timers for Linux X86_64
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -63,16 +59,16 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler(void)
-#define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler(void)
+#define HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler()
+#define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler()
// PWM timer
#define HAL_PWM_TIMER
-#define HAL_PWM_TIMER_ISR() extern "C" void TIMER3_IRQHandler(void)
+#define HAL_PWM_TIMER_ISR() extern "C" void TIMER3_IRQHandler()
#define HAL_PWM_TIMER_IRQn
-void HAL_timer_init(void);
+void HAL_timer_init();
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare);
diff --git a/Marlin/src/HAL/HAL_LINUX/watchdog.cpp b/Marlin/src/HAL/HAL_LINUX/watchdog.cpp
index a70eb82b98..6338ea3b1d 100644
--- a/Marlin/src/HAL/HAL_LINUX/watchdog.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,19 +28,9 @@
#include "watchdog.h"
-void watchdog_init(void) {}
+void watchdog_init() {}
+void HAL_watchdog_refresh() {}
-void HAL_clear_reset_source(void) {}
-
-uint8_t HAL_get_reset_source(void) {
- return RST_POWER_ON;
-}
-
-void watchdog_reset() {}
-
-#else
- void HAL_clear_reset_source(void) {}
- uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
-#endif // USE_WATCHDOG
+#endif
#endif // __PLAT_LINUX__
diff --git a/Marlin/src/HAL/HAL_LINUX/watchdog.h b/Marlin/src/HAL/HAL_LINUX/watchdog.h
index 1355ea77ec..51d30c8437 100644
--- a/Marlin/src/HAL/HAL_LINUX/watchdog.h
+++ b/Marlin/src/HAL/HAL_LINUX/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,5 @@
#define WDT_TIMEOUT 4000000 // 4 second timeout
-void watchdog_init(void);
-void watchdog_reset(void);
-void HAL_clear_reset_source(void);
-uint8_t HAL_get_reset_source(void);
+void watchdog_init();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_LPC1768/DebugMonitor_LPC1768.cpp b/Marlin/src/HAL/HAL_LPC1768/DebugMonitor.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_LPC1768/DebugMonitor_LPC1768.cpp
rename to Marlin/src/HAL/HAL_LPC1768/DebugMonitor.cpp
index 998e56b6de..fefee386e5 100644
--- a/Marlin/src/HAL/HAL_LPC1768/DebugMonitor_LPC1768.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/DebugMonitor.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@
#define sw_barrier() __asm__ volatile("": : :"memory");
// (re)initialize UART0 as a monitor output to 250000,n,8,1
-static void TXBegin(void) {
+static void TXBegin() {
}
// Send character through UART with no interrupts
@@ -210,7 +210,7 @@ void HardFault_HandlerC(unsigned long *sp, unsigned long lr, unsigned long cause
}
extern "C" {
-__attribute__((naked)) void NMI_Handler(void) {
+__attribute__((naked)) void NMI_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -223,7 +223,7 @@ __attribute__((naked)) void NMI_Handler(void) {
);
}
-__attribute__((naked)) void HardFault_Handler(void) {
+__attribute__((naked)) void HardFault_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -236,7 +236,7 @@ __attribute__((naked)) void HardFault_Handler(void) {
);
}
-__attribute__((naked)) void MemManage_Handler(void) {
+__attribute__((naked)) void MemManage_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -249,7 +249,7 @@ __attribute__((naked)) void MemManage_Handler(void) {
);
}
-__attribute__((naked)) void BusFault_Handler(void) {
+__attribute__((naked)) void BusFault_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -262,7 +262,7 @@ __attribute__((naked)) void BusFault_Handler(void) {
);
}
-__attribute__((naked)) void UsageFault_Handler(void) {
+__attribute__((naked)) void UsageFault_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -275,7 +275,7 @@ __attribute__((naked)) void UsageFault_Handler(void) {
);
}
-__attribute__((naked)) void DebugMon_Handler(void) {
+__attribute__((naked)) void DebugMon_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -289,7 +289,7 @@ __attribute__((naked)) void DebugMon_Handler(void) {
}
/* This is NOT an exception, it is an interrupt handler - Nevertheless, the framing is the same */
-__attribute__((naked)) void WDT_IRQHandler(void) {
+__attribute__((naked)) void WDT_IRQHandler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
@@ -302,7 +302,7 @@ __attribute__((naked)) void WDT_IRQHandler(void) {
);
}
-__attribute__((naked)) void RSTC_Handler(void) {
+__attribute__((naked)) void RSTC_Handler() {
__asm__ __volatile__ (
".syntax unified" "\n\t"
A("tst lr, #4")
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
index ac242ca4ab..2607ecfb46 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,14 +26,18 @@
#include "../shared/Delay.h"
#include "../../../gcode/parser.h"
+#if ENABLED(USE_WATCHDOG)
+ #include "watchdog.h"
+#endif
+
// U8glib required functions
extern "C" void u8g_xMicroDelay(uint16_t val) {
DELAY_US(val);
}
-extern "C" void u8g_MicroDelay(void) {
+extern "C" void u8g_MicroDelay() {
u8g_xMicroDelay(1);
}
-extern "C" void u8g_10MicroDelay(void) {
+extern "C" void u8g_10MicroDelay() {
u8g_xMicroDelay(10);
}
extern "C" void u8g_Delay(uint16_t val) {
@@ -65,4 +69,17 @@ void flashFirmware(int16_t value) {
NVIC_SystemReset();
}
+void HAL_clear_reset_source(void) {
+ #if ENABLED(USE_WATCHDOG)
+ watchdog_clear_timeout_flag();
+ #endif
+}
+
+uint8_t HAL_get_reset_source(void) {
+ #if ENABLED(USE_WATCHDOG)
+ if (watchdog_timed_out()) return RST_WATCHDOG;
+ #endif
+ return RST_POWER_ON;
+}
+
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL.h b/Marlin/src/HAL/HAL_LPC1768/HAL.h
index 5a11dfd671..7ea6d288be 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL.h
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -27,7 +27,6 @@
*/
#define CPU_32_BIT
-#define HAL_INIT
void HAL_init();
@@ -35,14 +34,14 @@ void HAL_init();
#include
#include
-extern "C" volatile millis_t _millis;
+extern "C" volatile uint32_t _millis;
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "HAL_timers.h"
+#include "timers.h"
#include "MarlinSerial.h"
#include
@@ -112,18 +111,10 @@ extern "C" volatile millis_t _millis;
//
// Utility functions
//
-int freeMemory(void);
-
-//
-// SPI: Extended functions taking a channel number (Hardware SPI only)
-//
-
-// Write single byte to specified SPI channel
-void spiSend(uint32_t chan, byte b);
-// Write buffer to specified SPI channel
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-// Read single byte from specified SPI channel
-uint8_t spiRec(uint32_t chan);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+int freeMemory();
+#pragma GCC diagnostic pop
//
// ADC API
@@ -134,7 +125,7 @@ uint8_t spiRec(uint32_t chan);
// Memory usage per ADC channel (bytes): (6 * ADC_MEDIAN_FILTER_SIZE) + 16
// 8 * ((6 * 23) + 16 ) = 1232 Bytes for 8 channels
-#define ADC_LOWPASS_K_VALUE (6) // Higher values increase rise time
+#define ADC_LOWPASS_K_VALUE (2) // Higher values increase rise time
// Rise time sample delays for 100% signal convergence on full range step
// (1 : 13, 2 : 32, 3 : 67, 4 : 139, 5 : 281, 6 : 565, 7 : 1135, 8 : 2273)
// K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
@@ -147,16 +138,13 @@ using FilteredADC = LPC176x::ADC;
#define HAL_READ_ADC() FilteredADC::get_result()
#define HAL_ADC_READY() FilteredADC::finished_conversion()
-// A grace period to allow ADC readings to stabilize, preventing false alarms
-#define THERMAL_PROTECTION_GRACE_PERIOD 1000
-
// Parse a G-code word into a pin index
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
// P0.6 thru P0.9 are for the onboard SD card
#define HAL_SENSITIVE_PINS P0_06, P0_07, P0_08, P0_09
#define HAL_IDLETASK 1
-void HAL_idletask(void);
+void HAL_idletask();
#define PLATFORM_M997_SUPPORT
void flashFirmware(int16_t value);
@@ -176,3 +164,7 @@ void set_pwm_frequency(const pin_t pin, int f_desired);
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
*/
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
+
+// Reset source
+void HAL_clear_reset_source(void);
+uint8_t HAL_get_reset_source(void);
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
index 31dc9c4da0..5652db988b 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
/**
* Software SPI functions originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
+ * Copyright (c) 2009 by William Greiman
*/
/**
@@ -49,15 +49,11 @@
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if ENABLED(LPC_SOFTWARE_SPI)
#include "SoftwareSPI.h"
@@ -162,7 +158,7 @@
// setup for SPI mode
SSP_CFG_Type HW_SPI_init; // data structure to hold init values
SSP_ConfigStructInit(&HW_SPI_init); // set values for SPI mode
- HW_SPI_init.ClockRate = Marlin_speed[MIN(spiRate, 6)]; // put in the specified bit rate
+ HW_SPI_init.ClockRate = Marlin_speed[_MIN(spiRate, 6)]; // put in the specified bit rate
HW_SPI_init.Mode |= SSP_CR1_SSP_EN;
SSP_Init(LPC_SSPn, &HW_SPI_init); // puts the values into the proper bits in the SSP0 registers
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp
index 589c65e03e..a8778f7446 100644
--- a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,28 +27,28 @@
#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0)
MarlinSerial MSerial(LPC_UART0);
- extern "C" void UART0_IRQHandler(void) {
+ extern "C" void UART0_IRQHandler() {
MSerial.IRQHandler();
}
#endif
#if (defined(SERIAL_PORT) && SERIAL_PORT == 1) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 1)
MarlinSerial MSerial1((LPC_UART_TypeDef *) LPC_UART1);
- extern "C" void UART1_IRQHandler(void) {
+ extern "C" void UART1_IRQHandler() {
MSerial1.IRQHandler();
}
#endif
#if (defined(SERIAL_PORT) && SERIAL_PORT == 2) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 2)
MarlinSerial MSerial2(LPC_UART2);
- extern "C" void UART2_IRQHandler(void) {
+ extern "C" void UART2_IRQHandler() {
MSerial2.IRQHandler();
}
#endif
#if (defined(SERIAL_PORT) && SERIAL_PORT == 3) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 3)
MarlinSerial MSerial3(LPC_UART3);
- extern "C" void UART3_IRQHandler(void) {
+ extern "C" void UART3_IRQHandler() {
MSerial3.IRQHandler();
}
#endif
diff --git a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.h b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.h
index ca59a5b721..8050685538 100644
--- a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.h
+++ b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -49,6 +49,8 @@ public:
{
}
+ void end() {}
+
#if ENABLED(EMERGENCY_PARSER)
bool recv_callback(const char c) override {
emergency_parser.update(emergency_state, c);
diff --git a/Marlin/src/HAL/HAL_LPC1768/SanityCheck.h b/Marlin/src/HAL/HAL_LPC1768/SanityCheck.h
deleted file mode 100644
index 2338b34ee3..0000000000
--- a/Marlin/src/HAL/HAL_LPC1768/SanityCheck.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-/**
- * Test Re-ARM specific configuration values for errors at compile-time.
- */
-
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
- #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
- #elif SPINDLE_LASER_POWERUP_DELAY < 1
- #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-#if IS_RE_ARM_BOARD && ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && HAS_DRIVER(TMC2130) && DISABLED(TMC_USE_SW_SPI)
- #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI"
-#endif
-
-#if 1 < (ENABLED(LPC_SD_CUSTOM_CABLE) + ENABLED(LPC_SD_LCD) + ENABLED(LPC_SD_ONBOARD))
- #error "Enable only one of LPC_SD_CUSTOM_CABLE, LPC_SD_LCD, or LPC_SD_ONBOARD."
-#endif
-
-#if 1 < (ENABLED(USB_SD_DISABLED) + ENABLED(USB_SD_ONBOARD))
- #error "Enable only one of USB_SD_DISABLED or USB_SD_ONBOARD."
-#endif
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_Servo_LPC1768.h b/Marlin/src/HAL/HAL_LPC1768/Servo.h
similarity index 86%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_Servo_LPC1768.h
rename to Marlin/src/HAL/HAL_LPC1768/Servo.h
index 83ac8f0eab..1bbf84c73e 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_Servo_LPC1768.h
+++ b/Marlin/src/HAL/HAL_LPC1768/Servo.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
@@ -56,11 +57,11 @@ class libServo: public Servo {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(servo_info[this->servoIndex].Pin.nbr) >= 0) { // try to reattach
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]); // delay to allow servo to reach position
+ if (attach(servo_info[servoIndex].Pin.nbr) >= 0) { // try to reattach
+ write(value);
+ safe_delay(servo_delay[servoIndex]); // delay to allow servo to reach position
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h b/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
index d853962e0c..53e4b15809 100644
--- a/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,73 +38,74 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
-void setup_endstop_interrupts(void) {
+void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
#if HAS_X_MAX
#if !LPC1768_PIN_INTERRUPT_M(X_MAX_PIN)
- #error "X_MAX_PIN is not an INTERRUPT capable pin."
+ #error "X_MAX_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MAX_PIN);
#endif
#if HAS_X_MIN
#if !LPC1768_PIN_INTERRUPT_M(X_MIN_PIN)
- #error "X_MIN_PIN is not an INTERRUPT capable pin."
+ #error "X_MIN_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#endif
#if HAS_Y_MAX
#if !LPC1768_PIN_INTERRUPT_M(Y_MAX_PIN)
- #error "Y_MAX_PIN is not an INTERRUPT capable pin."
+ #error "Y_MAX_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#endif
#if HAS_Y_MIN
#if !LPC1768_PIN_INTERRUPT_M(Y_MIN_PIN)
- #error "Y_MIN_PIN is not an INTERRUPT capable pin."
+ #error "Y_MIN_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#endif
#if HAS_Z_MAX
#if !LPC1768_PIN_INTERRUPT_M(Z_MAX_PIN)
- #error "Z_MAX_PIN is not an INTERRUPT capable pin."
+ #error "Z_MAX_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#endif
#if HAS_Z_MIN
#if !LPC1768_PIN_INTERRUPT_M(Z_MIN_PIN)
- #error "Z_MIN_PIN is not an INTERRUPT capable pin."
+ #error "Z_MIN_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#endif
#if HAS_Z2_MAX
#if !LPC1768_PIN_INTERRUPT_M(Z2_MAX_PIN)
- #error "Z2_MAX_PIN is not an INTERRUPT capable pin."
+ #error "Z2_MAX_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#endif
#if HAS_Z2_MIN
#if !LPC1768_PIN_INTERRUPT_M(Z2_MIN_PIN)
- #error "Z2_MIN_PIN is not an INTERRUPT capable pin."
+ #error "Z2_MIN_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#endif
#if HAS_Z3_MAX
#if !LPC1768_PIN_INTERRUPT_M(Z3_MIN_PIN)
- #error "Z3_MIN_PIN is not an INTERRUPT capable pin."
+ #error "Z3_MIN_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#endif
#if HAS_Z3_MIN
#if !LPC1768_PIN_INTERRUPT_M(Z3_MIN_PIN)
- #error "Z3_MIN_PIN is not an INTERRUPT capable pin."
+ #error "Z3_MIN_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#endif
#if HAS_Z_MIN_PROBE_PIN
#if !LPC1768_PIN_INTERRUPT_M(Z_MIN_PROBE_PIN)
- #error "Z_MIN_PROBE_PIN is not an INTERRUPT capable pin."
+ #error "Z_MIN_PROBE_PIN is not INTERRUPT-capable."
#endif
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#endif
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/fast_pwm.cpp b/Marlin/src/HAL/HAL_LPC1768/fast_pwm.cpp
index 5e3c2ae6cb..1cc2032778 100644
--- a/Marlin/src/HAL/HAL_LPC1768/fast_pwm.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/fast_pwm.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#include "../../inc/MarlinConfigPre.h"
-#if ENABLED(FAST_PWM_FAN)
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
#include
@@ -36,5 +36,5 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
pwm_write_ratio(pin, invert ? 1.0f - (float)v / v_size : (float)v / v_size);
}
-#endif // FAST_PWM_FAN
+#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/fastio.h b/Marlin/src/HAL/HAL_LPC1768/fastio.h
index 3a47c3cadb..a00a4946c1 100644
--- a/Marlin/src/HAL/HAL_LPC1768/fastio.h
+++ b/Marlin/src/HAL/HAL_LPC1768/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -63,8 +63,6 @@
#define _READ(IO) READ_PIN(IO)
/// Write to a pin
-#define _WRITE_VAR(IO,V) digitalWrite(IO,V)
-
#define _WRITE(IO,V) WRITE_PIN(IO,V)
/// toggle a pin
@@ -92,7 +90,6 @@
#define READ(IO) _READ(IO)
/// Write to a pin wrapper
-#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
#define WRITE(IO,V) _WRITE(IO,V)
/// toggle a pin wrapper
diff --git a/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h
new file mode 100644
index 0000000000..6223e006df
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h
@@ -0,0 +1,34 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Test LPC176x-specific configuration values for errors at compile-time.
+ */
+
+//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
+// #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
+//#endif
+
+#if IS_RE_ARM_BOARD && ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && HAS_DRIVER(TMC2130) && DISABLED(TMC_USE_SW_SPI)
+ #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI"
+#endif
diff --git a/Marlin/src/HAL/HAL_LPC1768/include/SPI.h b/Marlin/src/HAL/HAL_LPC1768/include/SPI.h
index edffb1556e..559759ea03 100644
--- a/Marlin/src/HAL/HAL_LPC1768/include/SPI.h
+++ b/Marlin/src/HAL/HAL_LPC1768/include/SPI.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
* along with this program. If not, see .
*
*/
-
#pragma once
#include "../../shared/HAL_SPI.h"
diff --git a/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.c b/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.c
index ae088ed250..3ad1aff017 100644
--- a/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.c
+++ b/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.c
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -89,7 +89,7 @@ uint8_t digipot_mcp4451_start(uint8_t sla) { // send slave address and write bi
return 1;
}
-void digipot_mcp4451_init(void) {
+void digipot_mcp4451_init() {
/**
* Init I2C pin connect
*/
diff --git a/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.h b/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.h
index 9fba04c03c..d7e4b0dc7a 100644
--- a/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.h
+++ b/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -45,7 +45,7 @@
#include
uint8_t digipot_mcp4451_start(uint8_t sla);
-void digipot_mcp4451_init(void);
+void digipot_mcp4451_init();
uint8_t digipot_mcp4451_send_byte(uint8_t data);
#ifdef __cplusplus
diff --git a/Marlin/src/HAL/HAL_LPC1768/main.cpp b/Marlin/src/HAL/HAL_LPC1768/main.cpp
index cc74eedc1b..b20841bdeb 100644
--- a/Marlin/src/HAL/HAL_LPC1768/main.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/main.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,19 +38,17 @@ extern "C" {
#include "../../sd/cardreader.h"
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "HAL_timers.h"
+#include "timers.h"
extern uint32_t MSC_SD_Init(uint8_t pdrv);
extern "C" int isLPC1769();
-extern "C" void disk_timerproc(void);
+extern "C" void disk_timerproc();
-void SysTick_Callback() {
- disk_timerproc();
-}
+void SysTick_Callback() { disk_timerproc(); }
void HAL_init() {
- // Support the 4 LEDs some LPC176x boards have
+ // Init LEDs
#if PIN_EXISTS(LED)
SET_DIR_OUTPUT(LED_PIN);
WRITE_PIN_CLR(LED_PIN);
@@ -74,17 +72,50 @@ void HAL_init() {
}
#endif
+ // Init Servo Pins
+ #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
+ #if HAS_SERVO_0
+ INIT_SERVO(0);
+ #endif
+ #if HAS_SERVO_1
+ INIT_SERVO(1);
+ #endif
+ #if HAS_SERVO_2
+ INIT_SERVO(2);
+ #endif
+ #if HAS_SERVO_3
+ INIT_SERVO(3);
+ #endif
+
//debug_frmwrk_init();
//_DBG("\n\nDebug running\n");
// Initialise the SD card chip select pins as soon as possible
#if PIN_EXISTS(SS)
- WRITE(SS_PIN, HIGH);
- SET_OUTPUT(SS_PIN);
+ OUT_WRITE(SS_PIN, HIGH);
#endif
- #if defined(ONBOARD_SD_CS) && ONBOARD_SD_CS > -1
- WRITE(ONBOARD_SD_CS, HIGH);
- SET_OUTPUT(ONBOARD_SD_CS);
+ #if PIN_EXISTS(ONBOARD_SD_CS) && ONBOARD_SD_CS_PIN != SS_PIN
+ OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH);
+ #endif
+
+ #ifdef LPC1768_ENABLE_CLKOUT_12M
+ /**
+ * CLKOUTCFG register
+ * bit 8 (CLKOUT_EN) = enables CLKOUT signal. Disabled for now to prevent glitch when enabling GPIO.
+ * bits 7:4 (CLKOUTDIV) = set to 0 for divider setting of /1
+ * bits 3:0 (CLKOUTSEL) = set to 1 to select main crystal oscillator as CLKOUT source
+ */
+ LPC_SC->CLKOUTCFG = (0<<8)|(0<<4)|(1<<0);
+ // set P1.27 pin to function 01 (CLKOUT)
+ PINSEL_CFG_Type PinCfg;
+ PinCfg.Portnum = 1;
+ PinCfg.Pinnum = 27;
+ PinCfg.Funcnum = 1; // function 01 (CLKOUT)
+ PinCfg.OpenDrain = 0; // not open drain
+ PinCfg.Pinmode = 2; // no pull-up/pull-down
+ PINSEL_ConfigPin(&PinCfg);
+ // now set CLKOUT_EN bit
+ LPC_SC->CLKOUTCFG |= (1<<8);
#endif
USB_Init(); // USB Initialization
@@ -92,7 +123,7 @@ void HAL_init() {
delay(1000); // Give OS time to notice
USB_Connect(TRUE);
- #if DISABLED(USB_SD_DISABLED)
+ #if !BOTH(SHARED_SD_CARD, INIT_SDCARD_ON_BOOT) && DISABLED(NO_SD_HOST_DRIVE)
MSC_SD_Init(0); // Enable USB SD card access
#endif
@@ -118,16 +149,16 @@ void HAL_init() {
}
// HAL idle task
-void HAL_idletask(void) {
- #if BOTH(SDSUPPORT, SHARED_SD_CARD)
+void HAL_idletask() {
+ #if ENABLED(SHARED_SD_CARD)
// If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
// this will not reliably detect delete operations. To be safe we will lock
- // the disk if Marlin has it mounted. Unfortuately there is currently no way
+ // the disk if Marlin has it mounted. Unfortunately there is currently no way
// to unmount the disk from the LCD menu.
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
- if (card.isDetected())
+ if (card.isMounted())
MSC_Aquire_Lock();
else
MSC_Release_Lock();
diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_api.h b/Marlin/src/HAL/HAL_LPC1768/persistent_store_api.h
index c3c6f67254..cafa53b30e 100644
--- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_api.h
+++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_api.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
* along with this program. If not, see .
*
*/
+#pragma once
+
#include "../shared/persistent_store_api.h"
#define FLASH_EEPROM_EMULATION
diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
index 4b02544e1b..dac7d7a3a9 100644
--- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
index 7f8bfe2f02..2454dea195 100644
--- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
@@ -125,7 +125,7 @@ static void debug_rw(const bool write, int &pos, const uint8_t *value, const siz
// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
// } FRESULT;
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
if (!eeprom_file_open) return true;
FRESULT s;
UINT bytes_written = 0;
diff --git a/Marlin/src/HAL/HAL_LPC1768/pinsDebug.h b/Marlin/src/HAL/HAL_LPC1768/pinsDebug.h
index af3d7c92e7..e39f2d2453 100644
--- a/Marlin/src/HAL/HAL_LPC1768/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_LPC1768/pinsDebug.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,9 +32,8 @@
#define digitalRead_mod(p) extDigitalRead(p)
#define PRINT_PORT(p)
#define GET_ARRAY_PIN(p) pin_array[p].pin
-#define NAME_FORMAT(p) PSTR("%-##p##s")
-#define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
-#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%d.%02d"), LPC1768_PIN_PORT(p), LPC1768_PIN_PIN(p)); SERIAL_ECHO(buffer);} while (0)
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%d.%02d"), LPC1768_PIN_PORT(p), LPC1768_PIN_PIN(p)); SERIAL_ECHO(buffer); }while(0)
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
// pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
diff --git a/Marlin/src/HAL/HAL_LPC1768/spi_pins.h b/Marlin/src/HAL/HAL_LPC1768/spi_pins.h
index c0a072851e..acf991a9d7 100644
--- a/Marlin/src/HAL/HAL_LPC1768/spi_pins.h
+++ b/Marlin/src/HAL/HAL_LPC1768/spi_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,11 +21,11 @@
*/
#pragma once
-#include "src/core/macros.h"
+#include "../../core/macros.h"
#if ENABLED(SDSUPPORT) && HAS_GRAPHICAL_LCD && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
#define LPC_SOFTWARE_SPI // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
- // needed due to the speed and mode requred for communicating with each device being different.
+ // needed due to the speed and mode required for communicating with each device being different.
// This requirement can be removed if the SPI access to these devices is updated to use
// spiBeginTransaction.
#endif
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp b/Marlin/src/HAL/HAL_LPC1768/timers.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp
rename to Marlin/src/HAL/HAL_LPC1768/timers.cpp
index 26427bbacc..7bf7ff3880 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/timers.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -29,9 +29,9 @@
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
-#include "HAL_timers.h"
+#include "timers.h"
-void HAL_timer_init(void) {
+void HAL_timer_init() {
SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
LPC_TIM0->PR = (HAL_TIMER_RATE) / (STEPPER_TIMER_RATE) - 1; // Use prescaler to set frequency if needed
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h b/Marlin/src/HAL/HAL_LPC1768/timers.h
similarity index 90%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_timers.h
rename to Marlin/src/HAL/HAL_LPC1768/timers.h
index 9c50753a83..73ea728af1 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h
+++ b/Marlin/src/HAL/HAL_LPC1768/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* This program is free software: you can redistribute it and/or modify
@@ -25,10 +25,6 @@
* HAL For LPC1768
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "../../core/macros.h"
@@ -51,13 +47,13 @@
#define SBIT_MR3R 10
#define SBIT_MR3S 11
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define _HAL_TIMER(T) _CAT(LPC_TIM, T)
#define _HAL_TIMER_IRQ(T) TIMER##T##_IRQn
-#define __HAL_TIMER_ISR(T) extern "C" void TIMER##T##_IRQHandler(void)
+#define __HAL_TIMER_ISR(T) extern "C" void TIMER##T##_IRQHandler()
#define _HAL_TIMER_ISR(T) __HAL_TIMER_ISR(T)
typedef uint32_t hal_timer_t;
@@ -95,10 +91,10 @@ typedef uint32_t hal_timer_t;
#define STEP_TIMER _HAL_TIMER(STEP_TIMER_NUM)
#define TEMP_TIMER _HAL_TIMER(TEMP_TIMER_NUM)
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
-void HAL_timer_init(void);
+// ------------------------
+void HAL_timer_init();
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.c
similarity index 97%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.c
index 1e3cb04987..dc81396b09 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.c
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -163,7 +163,7 @@ uint8_t u8g_i2c_send_byte(uint8_t data) {
return 1;
}
-void u8g_i2c_stop(void) {
+void u8g_i2c_stop() {
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.h b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.h
similarity index 85%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.h
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.h
index 296858fa28..9dd594cd9e 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.h
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,9 +19,10 @@
* along with this program. If not, see .
*
*/
+#pragma once
void u8g_i2c_init(uint8_t options);
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos);
uint8_t u8g_i2c_start(uint8_t sla);
uint8_t u8g_i2c_send_byte(uint8_t data);
-void u8g_i2c_stop(void);
+void u8g_i2c_stop();
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_defines.h b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_defines.h
similarity index 93%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_defines.h
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_defines.h
index 2deb094657..1153329d89 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_defines.h
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_defines.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* LPC1768 LCD-specific defines
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_delay.h b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_delay.h
similarity index 85%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_delay.h
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_delay.h
index d329c18537..8806e87477 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_delay.h
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_delay.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* LCD delay routines - used by all the drivers.
@@ -34,8 +35,8 @@
#endif
void U8g_delay(int msec);
-void u8g_MicroDelay(void);
-void u8g_10MicroDelay(void);
+void u8g_MicroDelay();
+void u8g_10MicroDelay();
#ifdef __cplusplus
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.c b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_pin_routines.c
similarity index 96%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.c
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_pin_routines.c
index 4c8708495f..d441b7b4d0 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.c
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_pin_routines.c
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.h b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_pin_routines.h
similarity index 90%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.h
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_pin_routines.h
index 3c89d4e987..569706b483 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.h
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_pin_routines.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Low level pin manipulation routines - used by all the drivers.
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
index 65de10dea7..057a137445 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -59,16 +59,8 @@
#if HAS_GRAPHICAL_LCD
-//#include
#include
-
-#define SPI_FULL_SPEED 0
-#define SPI_HALF_SPEED 1
-#define SPI_QUARTER_SPEED 2
-#define SPI_EIGHTH_SPEED 3
-#define SPI_SIXTEENTH_SPEED 4
-#define SPI_SPEED_5 5
-#define SPI_SPEED_6 6
+#include "../../shared/HAL_SPI.h"
void spiBegin();
void spiInit(uint8_t spiRate);
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
index b47863c68d..b624b24d35 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction
index 08f8ce526e..0222c62280 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -138,7 +138,7 @@ uint8_t u8g_i2c_start_sw(uint8_t sla) { // assert start condition and then send
}
-void u8g_i2c_stop_sw(void) { }
+void u8g_i2c_stop_sw() { }
void u8g_i2c_init_sw(uint8_t clock_option) { u8g_i2c_start(0); } // send slave address and write bit
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
index 3a9ffa8e23..ac289c1a20 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -59,18 +59,10 @@
#if HAS_GRAPHICAL_LCD
-//#include
#include
+#include "../../shared/HAL_SPI.h"
#include "../../shared/Delay.h"
-#define SPI_FULL_SPEED 0
-#define SPI_HALF_SPEED 1
-#define SPI_QUARTER_SPEED 2
-#define SPI_EIGHTH_SPEED 3
-#define SPI_SIXTEENTH_SPEED 4
-#define SPI_SPEED_5 5
-#define SPI_SPEED_6 6
-
void spiBegin();
void spiInit(uint8_t spiRate);
void spiSend(uint8_t b);
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
index 496c4cb75c..59414e896b 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
index 748149bb03..e243d40013 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py b/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
index 36242c9605..7f2a023630 100644
--- a/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
+++ b/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
@@ -17,7 +17,7 @@ def print_error(e):
print('\nUnable to find destination disk (' + e + ')\n' \
'Please select it in platformio.ini using the upload_port keyword ' \
'(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \
- 'or copy the firmware (.pioenvs/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n')
+ 'or copy the firmware (.pio/build/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n')
try:
if current_OS == 'Windows':
@@ -31,7 +31,7 @@ try:
#
import subprocess
# typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
- driveStr = subprocess.check_output("fsutil fsinfo drives")
+ driveStr = subprocess.check_output("fsutil fsinfo drives").decode('utf8')
# typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
driveStr = driveStr.strip().lstrip('Drives: ')
# typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\',
@@ -44,7 +44,7 @@ try:
for drive in drives:
final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
try:
- volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
+ volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT).decode('utf8')
except Exception as e:
continue
else:
diff --git a/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp b/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp
index d143bae709..c83931745a 100644
--- a/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp
@@ -1,13 +1,37 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
#ifdef TARGET_LPC1768
+
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(EMERGENCY_PARSER)
- #include "../../feature/emergency_parser.h"
- EmergencyParser::State emergency_state;
- bool CDC_RecvCallback(const char buffer) {
- emergency_parser.update(emergency_state, buffer);
- return true;
- }
-#endif // ENABLED(EMERGENCY_PARSER)
+#include "../../feature/emergency_parser.h"
+EmergencyParser::State emergency_state;
+bool CDC_RecvCallback(const char buffer) {
+ emergency_parser.update(emergency_state, buffer);
+ return true;
+}
+
+#endif // EMERGENCY_PARSER
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
index 4418cc2364..f122bf9984 100644
--- a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#include "lpc17xx_wdt.h"
#include "watchdog.h"
-void watchdog_init(void) {
+void watchdog_init() {
#if ENABLED(WATCHDOG_RESET_MANUAL)
// We enable the watchdog timer, but only for the interrupt.
@@ -56,28 +56,16 @@ void watchdog_init(void) {
WDT_Start(WDT_TIMEOUT);
}
-void HAL_clear_reset_source(void) {
- WDT_ClrTimeOutFlag();
-}
-
-uint8_t HAL_get_reset_source(void) {
- if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
- return RST_POWER_ON;
-}
-
-void watchdog_reset() {
+void HAL_watchdog_refresh() {
WDT_Feed();
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
-#else
-
-void watchdog_init(void) {}
-void watchdog_reset(void) {}
-void HAL_clear_reset_source(void) {}
-uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
+// Timeout state
+bool watchdog_timed_out() { return TEST(WDT_ReadTimeOutFlag(), 0); }
+void watchdog_clear_timeout_flag() { WDT_ClrTimeOutFlag(); }
#endif // USE_WATCHDOG
diff --git a/Marlin/src/HAL/HAL_LPC1768/watchdog.h b/Marlin/src/HAL/HAL_LPC1768/watchdog.h
index 1355ea77ec..dd6617ea31 100644
--- a/Marlin/src/HAL/HAL_LPC1768/watchdog.h
+++ b/Marlin/src/HAL/HAL_LPC1768/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,8 @@
#define WDT_TIMEOUT 4000000 // 4 second timeout
-void watchdog_init(void);
-void watchdog_reset(void);
-void HAL_clear_reset_source(void);
-uint8_t HAL_get_reset_source(void);
+void watchdog_init();
+void HAL_watchdog_refresh();
+
+bool watchdog_timed_out();
+void watchdog_clear_timeout_flag();
diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL.cpp b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp
new file mode 100644
index 0000000000..1d7521270f
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp
@@ -0,0 +1,476 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifdef __SAMD51__
+
+#include "../../inc/MarlinConfig.h"
+#include "Adafruit_ZeroDMA.h"
+#include "wiring_private.h"
+
+// ------------------------
+// Local defines
+// ------------------------
+
+#if HAS_TEMP_ADC_0
+ #define GET_TEMP_0_ADC() PIN_TO_ADC(TEMP_0_PIN)
+#else
+ #define GET_TEMP_0_ADC() -1
+#endif
+#if HAS_TEMP_ADC_1
+ #define GET_TEMP_1_ADC() PIN_TO_ADC(TEMP_1_PIN)
+#else
+ #define GET_TEMP_1_ADC() -1
+#endif
+#if HAS_TEMP_ADC_2
+ #define GET_TEMP_2_ADC() PIN_TO_ADC(TEMP_2_PIN)
+#else
+ #define GET_TEMP_2_ADC() -1
+#endif
+#if HAS_TEMP_ADC_3
+ #define GET_TEMP_3_ADC() PIN_TO_ADC(TEMP_3_PIN)
+#else
+ #define GET_TEMP_3_ADC() -1
+#endif
+#if HAS_TEMP_ADC_4
+ #define GET_TEMP_4_ADC() PIN_TO_ADC(TEMP_4_PIN)
+#else
+ #define GET_TEMP_4_ADC() -1
+#endif
+#if HAS_TEMP_ADC_5
+ #define GET_TEMP_5_ADC() PIN_TO_ADC(TEMP_5_PIN)
+#else
+ #define GET_TEMP_5_ADC() -1
+#endif
+#if HAS_TEMP_ADC_BED
+ #define GET_BED_ADC() PIN_TO_ADC(TEMP_BED_PIN)
+#else
+ #define GET_BED_ADC() -1
+#endif
+#if HAS_TEMP_ADC_CHAMBER
+ #define GET_CHAMBER_ADC() PIN_TO_ADC(TEMP_CHAMBER_PIN)
+#else
+ #define GET_CHAMBER_ADC() -1
+#endif
+#if ENABLED(FILAMENT_WIDTH_SENSOR)
+ #define GET_FILAMENT_WIDTH_ADC() PIN_TO_ADC(FILWIDTH_PIN)
+#else
+ #define GET_FILAMENT_WIDTH_ADC() -1
+#endif
+#if HAS_ADC_BUTTONS
+ #define GET_BUTTONS_ADC() PIN_TO_ADC(ADC_KEYPAD_PIN)
+#else
+ #define GET_BUTTONS_ADC() -1
+#endif
+
+#define IS_ADC_REQUIRED(n) (GET_TEMP_0_ADC() == n || GET_TEMP_1_ADC() == n || GET_TEMP_2_ADC() == n \
+ || GET_TEMP_3_ADC() == n || GET_TEMP_4_ADC() == n || GET_TEMP_5_ADC() == n \
+ || GET_BED_ADC() == n \
+ || GET_CHAMBER_ADC() == n \
+ || GET_FILAMENT_WIDTH_ADC() == n \
+ || GET_BUTTONS_ADC() == n)
+
+#define ADC0_IS_REQUIRED IS_ADC_REQUIRED(0)
+#define ADC1_IS_REQUIRED IS_ADC_REQUIRED(1)
+#define ADC_IS_REQUIRED (ADC0_IS_REQUIRED || ADC1_IS_REQUIRED)
+#if ADC0_IS_REQUIRED
+ #define FIRST_ADC 0
+#else
+ #define FIRST_ADC 1
+#endif
+#if ADC1_IS_REQUIRED
+ #define LAST_ADC 1
+#else
+ #define LAST_ADC 0
+#endif
+
+#define DMA_IS_REQUIRED ADC_IS_REQUIRED
+
+// ------------------------
+// Types
+// ------------------------
+
+#if DMA_IS_REQUIRED
+
+ // Struct must be 32 bits aligned because of DMA accesses but fields needs to be 8 bits packed
+ typedef struct __attribute__((aligned(4), packed)) {
+ ADC_INPUTCTRL_Type INPUTCTRL;
+ } HAL_DMA_DAC_Registers; // DMA transfered registers
+
+#endif
+
+// ------------------------
+// Private Variables
+// ------------------------
+
+uint16_t HAL_adc_result;
+
+#if ADC_IS_REQUIRED
+
+ // Pins used by ADC inputs. Order must be ADC0 inputs first then ADC1
+ const uint8_t adc_pins[] = {
+ // ADC0 pins
+ #if GET_TEMP_0_ADC() == 0
+ TEMP_0_PIN,
+ #endif
+ #if GET_TEMP_1_ADC() == 0
+ TEMP_1_PIN,
+ #endif
+ #if GET_TEMP_2_ADC() == 0
+ TEMP_2_PIN,
+ #endif
+ #if GET_TEMP_3_ADC() == 0
+ TEMP_3_PIN,
+ #endif
+ #if GET_TEMP_4_ADC() == 0
+ TEMP_4_PIN,
+ #endif
+ #if GET_TEMP_5_ADC() == 0
+ TEMP_5_PIN,
+ #endif
+ #if GET_BED_ADC() == 0
+ TEMP_BED_PIN,
+ #endif
+ #if GET_CHAMBER_ADC() == 0
+ TEMP_CHAMBER_PIN,
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 0
+ FILWIDTH_PIN,
+ #endif
+ #if GET_BUTTONS_ADC() == 0
+ ADC_KEYPAD_PIN,
+ #endif
+ // ADC1 pins
+ #if GET_TEMP_0_ADC() == 1
+ TEMP_0_PIN,
+ #endif
+ #if GET_TEMP_1_ADC() == 1
+ TEMP_1_PIN,
+ #endif
+ #if GET_TEMP_2_ADC() == 1
+ TEMP_2_PIN,
+ #endif
+ #if GET_TEMP_3_ADC() == 1
+ TEMP_3_PIN,
+ #endif
+ #if GET_TEMP_4_ADC() == 1
+ TEMP_4_PIN,
+ #endif
+ #if GET_TEMP_5_ADC() == 1
+ TEMP_5_PIN,
+ #endif
+ #if GET_BED_ADC() == 1
+ TEMP_BED_PIN,
+ #endif
+ #if GET_CHAMBER_ADC() == 1
+ TEMP_CHAMBER_PIN,
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 1
+ FILWIDTH_PIN,
+ #endif
+ #if GET_BUTTONS_ADC() == 1
+ ADC_KEYPAD_PIN,
+ #endif
+ };
+
+ uint16_t HAL_adc_results[COUNT(adc_pins)];
+
+ #if ADC0_IS_REQUIRED
+ Adafruit_ZeroDMA adc0DMAProgram,
+ adc0DMARead;
+
+ const HAL_DMA_DAC_Registers adc0_dma_regs_list[] = {
+ #if GET_TEMP_0_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_0_PIN) },
+ #endif
+ #if GET_TEMP_1_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_1_PIN) },
+ #endif
+ #if GET_TEMP_2_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_2_PIN) },
+ #endif
+ #if GET_TEMP_3_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_3_PIN) },
+ #endif
+ #if GET_TEMP_4_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_4_PIN) },
+ #endif
+ #if GET_TEMP_5_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_5_PIN) },
+ #endif
+ #if GET_BED_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_BED_PIN) },
+ #endif
+ #if GET_CHAMBER_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 0
+ { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
+ #endif
+ #if GET_BUTTONS_ADC() == 0
+ { PIN_TO_INPUTCTRL(ADC_KEYPAD_PIN) },
+ #endif
+ };
+
+ #define ADC0_AINCOUNT COUNT(adc0_dma_regs_list)
+ #endif // ADC0_IS_REQUIRED
+
+ #if ADC1_IS_REQUIRED
+ Adafruit_ZeroDMA adc1DMAProgram,
+ adc1DMARead;
+
+ const HAL_DMA_DAC_Registers adc1_dma_regs_list[] = {
+ #if GET_TEMP_0_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_0_PIN) },
+ #endif
+ #if GET_TEMP_1_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_1_PIN) },
+ #endif
+ #if GET_TEMP_2_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_2_PIN) },
+ #endif
+ #if GET_TEMP_3_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_3_PIN) },
+ #endif
+ #if GET_TEMP_4_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_4_PIN) },
+ #endif
+ #if GET_TEMP_5_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_5_PIN) },
+ #endif
+ #if GET_BED_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_BED_PIN) },
+ #endif
+ #if GET_CHAMBER_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 1
+ { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
+ #endif
+ #if GET_BUTTONS_ADC() == 1
+ { PIN_TO_INPUTCTRL(ADC_KEYPAD_PIN) },
+ #endif
+ };
+
+ #define ADC1_AINCOUNT COUNT(adc1_dma_regs_list)
+ #endif // ADC1_IS_REQUIRED
+
+#endif // ADC_IS_REQUIRED
+
+// ------------------------
+// Private functions
+// ------------------------
+
+#if DMA_IS_REQUIRED
+
+ void dma_init() {
+ DmacDescriptor *descriptor;
+
+ #if ADC0_IS_REQUIRED
+ adc0DMAProgram.setTrigger(ADC0_DMAC_ID_SEQ);
+ adc0DMAProgram.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc0DMAProgram.loop(true);
+ if (adc0DMAProgram.allocate() == DMA_STATUS_OK) {
+ descriptor = adc0DMAProgram.addDescriptor(
+ (void *)adc0_dma_regs_list, // SRC
+ (void *)&ADC0->DSEQDATA.reg, // DEST
+ sizeof(adc0_dma_regs_list) / 4, // CNT
+ DMA_BEAT_SIZE_WORD,
+ true, // SRCINC
+ false, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_SRC // STEPSEL
+ );
+ if (descriptor != nullptr)
+ descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
+ adc0DMAProgram.startJob();
+ }
+
+ adc0DMARead.setTrigger(ADC0_DMAC_ID_RESRDY);
+ adc0DMARead.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc0DMARead.loop(true);
+ if (adc0DMARead.allocate() == DMA_STATUS_OK) {
+ adc0DMARead.addDescriptor(
+ (void *)&ADC0->RESULT.reg, // SRC
+ &HAL_adc_results, // DEST
+ ADC0_AINCOUNT, // CNT
+ DMA_BEAT_SIZE_HWORD,
+ false, // SRCINC
+ true, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_DST // STEPSEL
+ );
+ adc0DMARead.startJob();
+ }
+ #endif
+ #if ADC1_IS_REQUIRED
+ adc1DMAProgram.setTrigger(ADC1_DMAC_ID_SEQ);
+ adc1DMAProgram.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc1DMAProgram.loop(true);
+ if (adc1DMAProgram.allocate() == DMA_STATUS_OK) {
+ descriptor = adc1DMAProgram.addDescriptor(
+ (void *)adc1_dma_regs_list, // SRC
+ (void *)&ADC1->DSEQDATA.reg, // DEST
+ sizeof(adc1_dma_regs_list) / 4, // CNT
+ DMA_BEAT_SIZE_WORD,
+ true, // SRCINC
+ false, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_SRC // STEPSEL
+ );
+ if (descriptor != nullptr)
+ descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
+ adc1DMAProgram.startJob();
+ }
+
+ adc1DMARead.setTrigger(ADC1_DMAC_ID_RESRDY);
+ adc1DMARead.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc1DMARead.loop(true);
+ if (adc1DMARead.allocate() == DMA_STATUS_OK) {
+ adc1DMARead.addDescriptor(
+ (void *)&ADC1->RESULT.reg, // SRC
+ &HAL_adc_results[ADC0_AINCOUNT], // DEST
+ ADC1_AINCOUNT, // CNT
+ DMA_BEAT_SIZE_HWORD,
+ false, // SRCINC
+ true, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_DST // STEPSEL
+ );
+ adc1DMARead.startJob();
+ }
+ #endif
+
+ DMAC->PRICTRL0.bit.RRLVLEN0 = true; // Activate round robin for DMA channels required by ADCs
+ }
+
+#endif // DMA_IS_REQUIRED
+
+// ------------------------
+// Public functions
+// ------------------------
+
+// HAL initialization task
+void HAL_init() {
+ #if DMA_IS_REQUIRED
+ dma_init();
+ #endif
+ #if ENABLED(SDSUPPORT)
+ // SD_DETECT_PIN may be removed if NO_SD_HOST_DRIVE is not defined in Configuration_adv.h
+ #if SD_CONNECTION_IS(ONBOARD) && PIN_EXISTS(SD_DETECT)
+ SET_INPUT_PULLUP(SD_DETECT_PIN);
+ #endif
+ OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
+ #endif
+}
+
+// HAL idle task
+/*
+void HAL_idletask() {
+}
+*/
+
+void HAL_clear_reset_source() { }
+
+#pragma push_macro("WDT")
+#undef WDT // Required to be able to use '.bit.WDT'. Compiler wrongly replace struct field with WDT define
+uint8_t HAL_get_reset_source() {
+ RSTC_RCAUSE_Type resetCause;
+
+ resetCause.reg = REG_RSTC_RCAUSE;
+ if (resetCause.bit.POR) return RST_POWER_ON;
+ else if (resetCause.bit.EXT) return RST_EXTERNAL;
+ else if (resetCause.bit.BODCORE || resetCause.bit.BODVDD) return RST_BROWN_OUT;
+ else if (resetCause.bit.WDT) return RST_WATCHDOG;
+ else if (resetCause.bit.SYST || resetCause.bit.NVM) return RST_SOFTWARE;
+ else if (resetCause.bit.BACKUP) return RST_BACKUP;
+ return 0;
+}
+#pragma pop_macro("WDT")
+
+extern "C" {
+ void * _sbrk(int incr);
+
+ extern unsigned int __bss_end__; // end of bss section
+}
+
+// Return free memory between end of heap (or end bss) and whatever is current
+int freeMemory() {
+ int free_memory, heap_end = (int)_sbrk(0);
+ return (int)&free_memory - (heap_end ?: (int)&__bss_end__);
+}
+
+// ------------------------
+// ADC
+// ------------------------
+
+void HAL_adc_init() {
+ #if ADC_IS_REQUIRED
+ memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results)); // Fill result with invalid values
+
+ for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi)
+ pinPeripheral(adc_pins[pi], PIO_ANALOG);
+
+ for (uint8_t ai = FIRST_ADC; ai <= LAST_ADC; ++ai) {
+ Adc* adc = ((Adc*[])ADC_INSTS)[ai];
+
+ // ADC clock setup
+ GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN = false;
+ SYNC(GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN);
+ GCLK->PCHCTRL[ADC0_GCLK_ID + ai].reg = GCLK_PCHCTRL_GEN_GCLK1 | GCLK_PCHCTRL_CHEN; // 48MHz startup code programmed
+ SYNC(!GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN);
+ adc->CTRLA.bit.PRESCALER = ADC_CTRLA_PRESCALER_DIV32_Val; // 1.5MHZ adc clock
+
+ // ADC setup
+ // Preloaded data (fixed for all ADC instances hence not loaded by DMA)
+ adc->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val; // VRefA pin
+ SYNC(adc->SYNCBUSY.bit.REFCTRL);
+ adc->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_10BIT_Val;
+ SYNC(adc->SYNCBUSY.bit.CTRLB);
+ adc->SAMPCTRL.bit.SAMPLEN = (6 - 1); // Sampling clocks
+ // Registers loaded by DMA
+ adc->DSEQCTRL.bit.INPUTCTRL = true;
+
+ adc->DSEQCTRL.bit.AUTOSTART = true; // Start conversion after DMA sequence
+
+ adc->CTRLA.bit.ENABLE = true; // Enable ADC
+ SYNC(adc->SYNCBUSY.bit.ENABLE);
+ }
+ #endif // ADC_IS_REQUIRED
+}
+
+void HAL_adc_start_conversion(const uint8_t adc_pin) {
+ #if ADC_IS_REQUIRED
+ for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi) {
+ if (adc_pin == adc_pins[pi]) {
+ HAL_adc_result = HAL_adc_results[pi];
+ return;
+ }
+ }
+ #endif
+
+ HAL_adc_result = 0xFFFF;
+}
+
+uint16_t HAL_adc_get_result() {
+ return HAL_adc_result;
+}
+
+#endif // __SAMD51__
diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL.h b/Marlin/src/HAL/HAL_SAMD51/HAL.h
new file mode 100644
index 0000000000..3489a4d285
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/HAL.h
@@ -0,0 +1,156 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#define CPU_32_BIT
+
+#include "../shared/Marduino.h"
+#include "../shared/math_32bit.h"
+#include "../shared/HAL_SPI.h"
+#include "fastio.h"
+#include "watchdog.h"
+#include "timers.h"
+
+#ifdef ADAFRUIT_GRAND_CENTRAL_M4
+ #include "MarlinSerial_AGCM4.h"
+
+ // Serial ports
+ #if !WITHIN(SERIAL_PORT, -1, 3)
+ #error "SERIAL_PORT must be from -1 to 3"
+ #endif
+
+ // MYSERIAL0 required before MarlinSerial includes!
+ #if SERIAL_PORT == -1
+ #define MYSERIAL0 Serial
+ #elif SERIAL_PORT == 0
+ #define MYSERIAL0 Serial1
+ #elif SERIAL_PORT == 1
+ #define MYSERIAL0 Serial2
+ #elif SERIAL_PORT == 2
+ #define MYSERIAL0 Serial3
+ #else
+ #define MYSERIAL0 Serial4
+ #endif
+
+ #ifdef SERIAL_PORT_2
+ #if !WITHIN(SERIAL_PORT_2, -1, 3)
+ #error "SERIAL_PORT_2 must be from -1 to 3"
+ #elif SERIAL_PORT_2 == SERIAL_PORT
+ #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
+ #endif
+ #define NUM_SERIAL 2
+ #if SERIAL_PORT_2 == -1
+ #define MYSERIAL1 Serial
+ #elif SERIAL_PORT_2 == 0
+ #define MYSERIAL1 Serial1
+ #elif SERIAL_PORT_2 == 1
+ #define MYSERIAL1 Serial2
+ #elif SERIAL_PORT_2 == 2
+ #define MYSERIAL1 Serial3
+ #else
+ #define MYSERIAL1 Serial4
+ #endif
+ #else
+ #define NUM_SERIAL 1
+ #endif
+
+#endif // ADAFRUIT_GRAND_CENTRAL_M4
+
+typedef int8_t pin_t;
+
+#define SHARED_SERVOS HAS_SERVOS
+#define HAL_SERVO_LIB Servo
+
+//
+// Interrupts
+//
+#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
+#define CRITICAL_SECTION_END if (!primask) __enable_irq()
+#define ISRS_ENABLED() (!__get_PRIMASK())
+#define ENABLE_ISRS() __enable_irq()
+#define DISABLE_ISRS() __disable_irq()
+
+#define cli() __disable_irq() // Disable interrupts
+#define sei() __enable_irq() // Enable interrupts
+
+void HAL_clear_reset_source(); // clear reset reason
+uint8_t HAL_get_reset_source(); // get reset reason
+
+//
+// EEPROM
+//
+void eeprom_write_byte(uint8_t *pos, unsigned char value);
+uint8_t eeprom_read_byte(uint8_t *pos);
+
+//
+// ADC
+//
+extern uint16_t HAL_adc_result; // result of last ADC conversion
+
+#define HAL_ANALOG_SELECT(pin)
+
+void HAL_adc_init();
+
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_READ_ADC() HAL_adc_result
+#define HAL_ADC_READY() true
+
+void HAL_adc_start_conversion(const uint8_t adc_pin);
+uint16_t HAL_adc_get_result();
+
+//
+// Pin Map
+//
+#define GET_PIN_MAP_PIN(index) index
+#define GET_PIN_MAP_INDEX(pin) pin
+#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+
+//
+// Tone
+//
+void toneInit();
+void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
+void noTone(const pin_t _pin);
+
+// Enable hooks into idle and setup for HAL
+void HAL_init();
+/*
+#define HAL_IDLETASK 1
+void HAL_idletask();
+*/
+
+//
+// Utility functions
+//
+FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+int freeMemory();
+#pragma GCC diagnostic pop
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
+#ifdef __cplusplus
+ }
+#endif
diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp b/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp
new file mode 100644
index 0000000000..bbd12912a2
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp
@@ -0,0 +1,151 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+/**
+ * Hardware and software SPI implementations are included in this file.
+ *
+ * Control of the slave select pin(s) is handled by the calling routines and
+ * SAMD51 let hardware SPI handling to remove SS from its logic.
+ */
+
+#ifdef __SAMD51__
+
+// --------------------------------------------------------------------------
+// Includes
+// --------------------------------------------------------------------------
+
+#include "../../inc/MarlinConfig.h"
+#include
+
+// --------------------------------------------------------------------------
+// Public functions
+// --------------------------------------------------------------------------
+
+#if EITHER(SOFTWARE_SPI, FORCE_SOFT_SPI)
+
+ // ------------------------
+ // Software SPI
+ // ------------------------
+ #error "Software SPI not supported for SAMD51. Use Hardware SPI."
+
+ #if SD_CONNECTION_IS(ONBOARD)
+ #endif
+
+#else // !SOFTWARE_SPI
+
+ #ifdef ADAFRUIT_GRAND_CENTRAL_M4
+ #if SD_CONNECTION_IS(ONBOARD)
+ #define sdSPI SDCARD_SPI
+ #else
+ #define sdSPI SPI
+ #endif
+ #endif
+
+ static SPISettings spiConfig;
+
+ // ------------------------
+ // Hardware SPI
+ // ------------------------
+ void spiBegin() {
+ spiInit(SPI_HALF_SPEED);
+ }
+
+ void spiInit(uint8_t spiRate) {
+ // Use datarates Marlin uses
+ uint32_t clock;
+ switch (spiRate) {
+ case SPI_FULL_SPEED: clock = 8000000; break;
+ case SPI_HALF_SPEED: clock = 4000000; break;
+ case SPI_QUARTER_SPEED: clock = 2000000; break;
+ case SPI_EIGHTH_SPEED: clock = 1000000; break;
+ case SPI_SIXTEENTH_SPEED: clock = 500000; break;
+ case SPI_SPEED_5: clock = 250000; break;
+ case SPI_SPEED_6: clock = 125000; break;
+ default: clock = 4000000; break; // Default from the SPI library
+ }
+ spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
+ sdSPI.begin();
+ }
+
+ /**
+ * @brief Receives a single byte from the SPI port.
+ *
+ * @return Byte received
+ *
+ * @details
+ */
+ uint8_t spiRec() {
+ sdSPI.beginTransaction(spiConfig);
+ uint8_t returnByte = sdSPI.transfer(0xFF);
+ sdSPI.endTransaction();
+ return returnByte;
+ }
+
+ /**
+ * @brief Receives a number of bytes from the SPI port to a buffer
+ *
+ * @param buf Pointer to starting address of buffer to write to.
+ * @param nbyte Number of bytes to receive.
+ * @return Nothing
+ */
+ void spiRead(uint8_t* buf, uint16_t nbyte) {
+ if (nbyte == 0) return;
+ memset(buf, 0xFF, nbyte);
+ sdSPI.beginTransaction(spiConfig);
+ sdSPI.transfer(buf, nbyte);
+ sdSPI.endTransaction();
+ }
+
+ /**
+ * @brief Sends a single byte on SPI port
+ *
+ * @param b Byte to send
+ *
+ * @details
+ */
+ void spiSend(uint8_t b) {
+ sdSPI.beginTransaction(spiConfig);
+ sdSPI.transfer(b);
+ sdSPI.endTransaction();
+ }
+
+ /**
+ * @brief Write token and then write from 512 byte buffer to SPI (for SD card)
+ *
+ * @param buf Pointer with buffer start address
+ * @return Nothing
+ *
+ * @details Uses DMA
+ */
+ void spiSendBlock(uint8_t token, const uint8_t* buf) {
+ sdSPI.beginTransaction(spiConfig);
+ sdSPI.transfer(token);
+ sdSPI.transfer((uint8_t*)buf, nullptr, 512);
+ sdSPI.endTransaction();
+ }
+
+ void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
+ spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
+ sdSPI.beginTransaction(spiConfig);
+ }
+#endif // !SOFTWARE_SPI
+
+#endif // __SAMD51__
diff --git a/Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.cpp b/Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.cpp
new file mode 100644
index 0000000000..2da4d8c07e
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.cpp
@@ -0,0 +1,55 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifdef ADAFRUIT_GRAND_CENTRAL_M4
+
+/**
+ * Framework doesn't define some serial to save sercom resources
+ * hence if these are used I need to define them
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1
+ Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
+ void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
+ void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
+ void SERCOM4_2_Handler() { Serial2.IrqHandler(); }
+ void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
+#endif
+
+#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2
+ Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
+ void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
+ void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
+ void SERCOM1_2_Handler() { Serial3.IrqHandler(); }
+ void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
+#endif
+
+#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3
+ Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
+ void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
+ void SERCOM5_1_Handler() { Serial4.IrqHandler(); }
+ void SERCOM5_2_Handler() { Serial4.IrqHandler(); }
+ void SERCOM5_3_Handler() { Serial4.IrqHandler(); }
+#endif
+
+#endif // ADAFRUIT_GRAND_CENTRAL_M4
diff --git a/Marlin/src/HAL/HAL_STM32F7/spi_pins.h b/Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.h
similarity index 78%
rename from Marlin/src/HAL/HAL_STM32F7/spi_pins.h
rename to Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.h
index 527325d6f4..0768d8a04e 100644
--- a/Marlin/src/HAL/HAL_STM32F7/spi_pins.h
+++ b/Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.h
@@ -1,6 +1,8 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,10 +20,6 @@
*/
#pragma once
-/**
- * Define SPI Pins: SCK, MISO, MOSI, SS
- */
-#define SCK_PIN PA5
-#define MISO_PIN PA6
-#define MOSI_PIN PA7
-#define SS_PIN PA8
+extern Uart Serial2;
+extern Uart Serial3;
+extern Uart Serial4;
diff --git a/Marlin/src/HAL/HAL_SAMD51/SAMD51.h b/Marlin/src/HAL/HAL_SAMD51/SAMD51.h
new file mode 100644
index 0000000000..d29d134c00
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/SAMD51.h
@@ -0,0 +1,70 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#define SYNC(sc) while (sc) { \
+ asm(""); \
+ }
+
+// Get SAMD port/pin from specified arduino pin
+#define GET_SAMD_PORT(P) _GET_SAMD_PORT(PIN_TO_SAMD_PIN(P))
+#define GET_SAMD_PIN(P) _GET_SAMD_PIN(PIN_TO_SAMD_PIN(P))
+
+// Get external interrupt line associated to specified arduino pin
+#define PIN_TO_EILINE(P) _SAMDPORTPIN_TO_EILINE(GET_SAMD_PORT(P), GET_SAMD_PIN(P))
+
+// Get adc/ain associated to specified arduino pin
+#define PIN_TO_ADC(P) (ANAPIN_TO_ADCAIN(P) >> 8)
+#define PIN_TO_AIN(P) (ANAPIN_TO_ADCAIN(P) & 0xFF)
+
+// Private defines
+#define PIN_TO_SAMD_PIN(P) DIO##P##_PIN
+
+#define _GET_SAMD_PORT(P) ((P) >> 5)
+#define _GET_SAMD_PIN(P) ((P) & 0x1F)
+
+// Get external interrupt line
+#define _SAMDPORTPIN_TO_EILINE(P,B) ((P == 0 && WITHIN(B, 0, 31) && B != 8 && B != 26 && B != 28 && B != 29) ? (B) & 0xF \
+ : (P == 1 && (WITHIN(B, 0, 25) || WITHIN(B, 30, 31))) ? (B) & 0xF \
+ : (P == 1 && WITHIN(B, 26, 29)) ? 12 + (B) - 26 \
+ : (P == 2 && (WITHIN(B, 0, 6) || WITHIN(B, 10, 31)) && B != 29) ? (B) & 0xF \
+ : (P == 2 && B == 7) ? 9 \
+ : (P == 3 && WITHIN(B, 0, 1)) ? (B) \
+ : (P == 3 && WITHIN(B, 8, 12)) ? 3 + (B) - 8 \
+ : (P == 3 && WITHIN(B, 20, 21)) ? 10 + (B) - 20 \
+ : -1)
+
+// Get adc/ain
+#define ANAPIN_TO_ADCAIN(P) _PIN_TO_ADCAIN(ANAPIN_TO_SAMDPIN(P))
+#define _PIN_TO_ADCAIN(P) _SAMDPORTPIN_TO_ADCAIN(_GET_SAMD_PORT(P), _GET_SAMD_PIN(P))
+
+#define _SAMDPORTPIN_TO_ADCAIN(P,B) ((P == 0 && WITHIN(B, 2, 3)) ? 0x000 + (B) - 2 \
+ : (P == 0 && WITHIN(B, 4, 7)) ? 0x000 + (B) \
+ : (P == 0 && WITHIN(B, 8, 9)) ? 0x100 + 2 + (B) - 8 \
+ : (P == 0 && WITHIN(B, 10, 11)) ? 0x000 + (B) \
+ : (P == 1 && WITHIN(B, 0, 3)) ? 0x000 + 12 + (B) \
+ : (P == 1 && WITHIN(B, 4, 7)) ? 0x100 + 6 + (B) - 4 \
+ : (P == 1 && WITHIN(B, 8, 9)) ? 0x100 + (B) - 8 \
+ : (P == 2 && WITHIN(B, 0, 1)) ? 0x100 + 10 + (B) \
+ : (P == 2 && WITHIN(B, 2, 3)) ? 0x100 + 4 + (B) - 2 \
+ : (P == 2 && WITHIN(B, 30, 31)) ? 0x100 + 12 + (B) - 30 \
+ : (P == 3 && WITHIN(B, 0, 1)) ? 0x100 + 14 + (B) \
+ : -1)
diff --git a/Marlin/src/HAL/HAL_SAMD51/Servo.cpp b/Marlin/src/HAL/HAL_SAMD51/Servo.cpp
new file mode 100644
index 0000000000..dbae750425
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/Servo.cpp
@@ -0,0 +1,226 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+/**
+ * This comes from Arduino library which at the moment is buggy and uncompilable
+ */
+
+#ifdef __SAMD51__
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_SERVOS
+
+#include "../shared/Marduino.h"
+#include "../shared/servo.h"
+#include "../shared/servo_private.h"
+#include "SAMD51.h"
+#include "timers.h"
+
+#define __TC_GCLK_ID(t) TC##t##_GCLK_ID
+#define _TC_GCLK_ID(t) __TC_GCLK_ID(t)
+#define TC_GCLK_ID _TC_GCLK_ID(SERVO_TC)
+
+#define _TC_PRESCALER(d) TC_CTRLA_PRESCALER_DIV##d##_Val
+#define TC_PRESCALER(d) _TC_PRESCALER(d)
+
+#define __SERVO_IRQn(t) TC##t##_IRQn
+#define _SERVO_IRQn(t) __SERVO_IRQn(t)
+#define SERVO_IRQn _SERVO_IRQn(SERVO_TC)
+
+#define HAL_SERVO_TIMER_ISR() TC_HANDLER(SERVO_TC)
+
+#define TIMER_TCCHANNEL(t) ((t) & 1)
+#define TC_COUNTER_START_VAL 0xFFFF
+
+
+static volatile int8_t currentServoIndex[_Nbr_16timers]; // index for the servo being pulsed for each timer (or -1 if refresh interval)
+
+FORCE_INLINE static uint16_t getTimerCount() {
+ Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+
+ tc->COUNT16.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.CTRLB || tc->COUNT16.SYNCBUSY.bit.COUNT);
+
+ return tc->COUNT16.COUNT.reg;
+}
+
+// ----------------------------
+// Interrupt handler for the TC
+// ----------------------------
+HAL_SERVO_TIMER_ISR() {
+ Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ const timer16_Sequence_t timer =
+ #ifndef _useTimer1
+ _timer2
+ #elif !defined(_useTimer2)
+ _timer1
+ #else
+ (tc->COUNT16.INTFLAG.reg & tc->COUNT16.INTENSET.reg & TC_INTFLAG_MC0) ? _timer1 : _timer2
+ #endif
+ ;
+ const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
+
+ if (currentServoIndex[timer] < 0) {
+ #if defined(_useTimer1) && defined(_useTimer2)
+ if (currentServoIndex[timer ^ 1] >= 0) {
+ // Wait for both channels
+ // Clear the interrupt
+ tc->COUNT16.INTFLAG.reg = (tcChannel == 0) ? TC_INTFLAG_MC0 : TC_INTFLAG_MC1;
+ return;
+ }
+ #endif
+ tc->COUNT16.COUNT.reg = TC_COUNTER_START_VAL;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.COUNT);
+ }
+ else if (SERVO_INDEX(timer, currentServoIndex[timer]) < ServoCount && SERVO(timer, currentServoIndex[timer]).Pin.isActive)
+ digitalWrite(SERVO(timer, currentServoIndex[timer]).Pin.nbr, LOW); // pulse this channel low if activated
+
+ // Select the next servo controlled by this timer
+ currentServoIndex[timer]++;
+
+ if (SERVO_INDEX(timer, currentServoIndex[timer]) < ServoCount && currentServoIndex[timer] < SERVOS_PER_TIMER) {
+ if (SERVO(timer, currentServoIndex[timer]).Pin.isActive) // check if activated
+ digitalWrite(SERVO(timer, currentServoIndex[timer]).Pin.nbr, HIGH); // it's an active channel so pulse it high
+
+ tc->COUNT16.CC[tcChannel].reg = getTimerCount() - (uint16_t)SERVO(timer, currentServoIndex[timer]).ticks;
+ }
+ else {
+ // finished all channels so wait for the refresh period to expire before starting over
+ currentServoIndex[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel
+
+ const uint16_t tcCounterValue = getTimerCount();
+
+ if ((TC_COUNTER_START_VAL - tcCounterValue) + 4UL < usToTicks(REFRESH_INTERVAL)) // allow a few ticks to ensure the next OCR1A not missed
+ tc->COUNT16.CC[tcChannel].reg = TC_COUNTER_START_VAL - (uint16_t)usToTicks(REFRESH_INTERVAL);
+ else
+ tc->COUNT16.CC[tcChannel].reg = (uint16_t)(tcCounterValue - 4UL); // at least REFRESH_INTERVAL has elapsed
+ }
+ if (tcChannel == 0) {
+ SYNC(tc->COUNT16.SYNCBUSY.bit.CC0);
+ // Clear the interrupt
+ tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0;
+ }
+ else {
+ SYNC(tc->COUNT16.SYNCBUSY.bit.CC1);
+ // Clear the interrupt
+ tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC1;
+ }
+}
+
+void initISR(timer16_Sequence_t timer) {
+ Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
+
+ static bool initialized = false; // Servo TC has been initialized
+ if (!initialized) {
+ NVIC_DisableIRQ(SERVO_IRQn);
+
+ // Disable the timer
+ tc->COUNT16.CTRLA.bit.ENABLE = false;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.ENABLE);
+
+ // Select GCLK0 as timer/counter input clock source
+ GCLK->PCHCTRL[TC_GCLK_ID].bit.CHEN = false;
+ SYNC(GCLK->PCHCTRL[TC_GCLK_ID].bit.CHEN);
+ GCLK->PCHCTRL[TC_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK0 | GCLK_PCHCTRL_CHEN; // 120MHz startup code programmed
+ SYNC(!GCLK->PCHCTRL[TC_GCLK_ID].bit.CHEN);
+
+ // Reset the timer
+ tc->COUNT16.CTRLA.bit.SWRST = true;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.SWRST);
+ SYNC(tc->COUNT16.CTRLA.bit.SWRST);
+
+ // Set timer counter mode to 16 bits
+ tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16;
+
+ // Set timer counter mode as normal PWM
+ tc->COUNT16.WAVE.bit.WAVEGEN = TCC_WAVE_WAVEGEN_NPWM_Val;
+
+ // Set the prescaler factor
+ tc->COUNT16.CTRLA.bit.PRESCALER = TC_PRESCALER(SERVO_TIMER_PRESCALER);
+
+ // Count down
+ tc->COUNT16.CTRLBSET.reg = TC_CTRLBCLR_DIR;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.CTRLB);
+
+ // Reset all servo indexes
+ memset((void *)currentServoIndex, 0xFF, sizeof(currentServoIndex));
+
+ // Configure interrupt request
+ NVIC_ClearPendingIRQ(SERVO_IRQn);
+ NVIC_SetPriority(SERVO_IRQn, 5);
+ NVIC_EnableIRQ(SERVO_IRQn);
+
+ initialized = true;
+ }
+
+ if (!tc->COUNT16.CTRLA.bit.ENABLE) {
+ // Reset the timer counter
+ tc->COUNT16.COUNT.reg = TC_COUNTER_START_VAL;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.COUNT);
+
+ // Enable the timer and start it
+ tc->COUNT16.CTRLA.bit.ENABLE = true;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.ENABLE);
+ }
+ // First interrupt request after 1 ms
+ tc->COUNT16.CC[tcChannel].reg = getTimerCount() - (uint16_t)usToTicks(1000UL);
+
+ if (tcChannel == 0 ) {
+ SYNC(tc->COUNT16.SYNCBUSY.bit.CC0);
+
+ // Clear pending match interrupt
+ tc->COUNT16.INTFLAG.reg = TC_INTENSET_MC0;
+ // Enable the match channel interrupt request
+ tc->COUNT16.INTENSET.reg = TC_INTENSET_MC0;
+ }
+ else {
+ SYNC(tc->COUNT16.SYNCBUSY.bit.CC1);
+
+ // Clear pending match interrupt
+ tc->COUNT16.INTFLAG.reg = TC_INTENSET_MC1;
+ // Enable the match channel interrupt request
+ tc->COUNT16.INTENSET.reg = TC_INTENSET_MC1;
+ }
+}
+
+void finISR(timer16_Sequence_t timer) {
+ Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
+
+ // Disable the match channel interrupt request
+ tc->COUNT16.INTENCLR.reg = (tcChannel == 0) ? TC_INTENCLR_MC0 : TC_INTENCLR_MC1;
+
+ if (true
+ #if defined(_useTimer1) && defined(_useTimer2)
+ && (tc->COUNT16.INTENCLR.reg & (TC_INTENCLR_MC0|TC_INTENCLR_MC1)) == 0
+ #endif
+ ) {
+ // Disable the timer if not used
+ tc->COUNT16.CTRLA.bit.ENABLE = false;
+ SYNC(tc->COUNT16.SYNCBUSY.bit.ENABLE);
+ }
+}
+
+#endif // HAS_SERVOS
+
+#endif // __SAMD51__
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h b/Marlin/src/HAL/HAL_SAMD51/ServoTimers.h
similarity index 55%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h
rename to Marlin/src/HAL/HAL_SAMD51/ServoTimers.h
index 687aaa39ec..8b77d5b503 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h
+++ b/Marlin/src/HAL/HAL_SAMD51/ServoTimers.h
@@ -1,9 +1,8 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,19 +18,22 @@
* along with this program. If not, see .
*
*/
-
#pragma once
-#include
+#define _useTimer1
+#define _useTimer2
-// Inherit and expand on the official library
-class libServo : public Servo {
- public:
- int8_t attach(const int pin);
- int8_t attach(const int pin, const int min, const int max);
- void move(const int value);
- private:
- uint16_t min_ticks;
- uint16_t max_ticks;
- uint8_t servoIndex; // index into the channel data for this servo
-};
+#define TRIM_DURATION 5 // compensation ticks to trim adjust for digitalWrite delays
+#define SERVO_TIMER_PRESCALER 64 // timer prescaler factor to 64 (avoid overflowing 16-bit clock counter, at 120MHz this is 1831 ticks per millisecond
+
+#define SERVO_TC 3
+
+typedef enum {
+ #ifdef _useTimer1
+ _timer1,
+ #endif
+ #ifdef _useTimer2
+ _timer2,
+ #endif
+ _Nbr_16timers
+} timer16_Sequence_t;
diff --git a/Marlin/src/HAL/HAL_SAMD51/endstop_interrupts.h b/Marlin/src/HAL/HAL_SAMD51/endstop_interrupts.h
new file mode 100644
index 0000000000..1f66e02e31
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/endstop_interrupts.h
@@ -0,0 +1,184 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Endstop interrupts for ATMEL SAMD51 based targets.
+ *
+ * On SAMD51, all pins support external interrupt capability.
+ * Any pin can be used for external interrupts, but there are some restrictions.
+ * At most 16 different external interrupts can be used at one time.
+ * Further, you can’t just pick any 16 pins to use. This is because every pin on the SAMD51
+ * connects to what is called an EXTINT line, and only one pin per EXTINT line can be used for external
+ * interrupts at a time
+ */
+
+/**
+ * Endstop Interrupts
+ *
+ * Without endstop interrupts the endstop pins must be polled continually in
+ * the temperature-ISR via endstops.update(), most of the time finding no change.
+ * With this feature endstops.update() is called only when we know that at
+ * least one endstop has changed state, saving valuable CPU cycles.
+ *
+ * This feature only works when all used endstop pins can generate an 'external interrupt'.
+ *
+ * Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
+ * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
+ */
+
+#include "../../module/endstops.h"
+
+#define MATCH_EILINE(P1,P2) (P1 != P2 && PIN_TO_EILINE(P1) == PIN_TO_EILINE(P2))
+#if HAS_X_MAX
+ #define MATCH_X_MAX_EILINE(P) MATCH_EILINE(P, X_MAX_PIN)
+#else
+ #define MATCH_X_MAX_EILINE(P) false
+#endif
+#if HAS_X_MIN
+ #define MATCH_X_MIN_EILINE(P) MATCH_EILINE(P, X_MIN_PIN)
+#else
+ #define MATCH_X_MIN_EILINE(P) false
+#endif
+#if HAS_Y_MAX
+ #define MATCH_Y_MAX_EILINE(P) MATCH_EILINE(P, Y_MAX_PIN)
+#else
+ #define MATCH_Y_MAX_EILINE(P) false
+#endif
+#if HAS_Y_MIN
+ #define MATCH_Y_MIN_EILINE(P) MATCH_EILINE(P, Y_MIN_PIN)
+#else
+ #define MATCH_Y_MIN_EILINE(P) false
+#endif
+#if HAS_Z_MAX
+ #define MATCH_Z_MAX_EILINE(P) MATCH_EILINE(P, Z_MAX_PIN)
+#else
+ #define MATCH_Z_MAX_EILINE(P) false
+#endif
+#if HAS_Z_MIN
+ #define MATCH_Z_MIN_EILINE(P) MATCH_EILINE(P, Z_MIN_PIN)
+#else
+ #define MATCH_Z_MIN_EILINE(P) false
+#endif
+#if HAS_Z2_MAX
+ #define MATCH_Z2_MAX_EILINE(P) MATCH_EILINE(P, Z2_MAX_PIN)
+#else
+ #define MATCH_Z2_MAX_EILINE(P) false
+#endif
+#if HAS_Z2_MIN
+ #define MATCH_Z2_MIN_EILINE(P) MATCH_EILINE(P, Z2_MIN_PIN)
+#else
+ #define MATCH_Z2_MIN_EILINE(P) false
+#endif
+#if HAS_Z3_MAX
+ #define MATCH_Z3_MAX_EILINE(P) MATCH_EILINE(P, Z3_MAX_PIN)
+#else
+ #define MATCH_Z3_MAX_EILINE(P) false
+#endif
+#if HAS_Z3_MIN
+ #define MATCH_Z3_MIN_EILINE(P) MATCH_EILINE(P, Z3_MIN_PIN)
+#else
+ #define MATCH_Z3_MIN_EILINE(P) false
+#endif
+#if HAS_Z_MIN_PROBE_PIN
+ #define MATCH_Z_MIN_PROBE_EILINE(P) MATCH_EILINE(P, Z_MIN_PROBE_PIN)
+#else
+ #define MATCH_Z_MIN_PROBE_EILINE(P) false
+#endif
+#define AVAILABLE_EILINE(P) (PIN_TO_EILINE(P) != -1 \
+ && !MATCH_X_MAX_EILINE(P) && !MATCH_X_MIN_EILINE(P) \
+ && !MATCH_Y_MAX_EILINE(P) && !MATCH_Y_MIN_EILINE(P) \
+ && !MATCH_Z_MAX_EILINE(P) && !MATCH_Z_MIN_EILINE(P) \
+ && !MATCH_Z2_MAX_EILINE(P) && !MATCH_Z2_MIN_EILINE(P) \
+ && !MATCH_Z3_MAX_EILINE(P) && !MATCH_Z3_MIN_EILINE(P) \
+ && !MATCH_Z_MIN_PROBE_EILINE(P))
+
+// One ISR for all EXT-Interrupts
+void endstop_ISR() { endstops.update(); }
+
+void setup_endstop_interrupts() {
+ #if HAS_X_MAX
+ #if !AVAILABLE_EILINE(X_MAX_PIN)
+ static_assert(false, "X_MAX_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_X_MIN
+ #if !AVAILABLE_EILINE(X_MIN_PIN)
+ static_assert(false, "X_MIN_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Y_MAX
+ #if !AVAILABLE_EILINE(Y_MAX_PIN)
+ static_assert(false, "Y_MAX_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Y_MIN
+ #if !AVAILABLE_EILINE(Y_MIN_PIN)
+ static_assert(false, "Y_MIN_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z_MAX
+ #if !AVAILABLE_EILINE(Z_MAX_PIN)
+ static_assert(false, "Z_MAX_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z_MIN
+ #if !AVAILABLE_EILINE(Z_MIN_PIN)
+ static_assert(false, "Z_MIN_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z2_MAX
+ #if !AVAILABLE_EILINE(Z2_MAX_PIN)
+ static_assert(false, "Z2_MAX_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z2_MIN
+ #if !AVAILABLE_EILINE(Z2_MIN_PIN)
+ static_assert(false, "Z2_MIN_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z3_MAX
+ #if !AVAILABLE_EILINE(Z3_MAX_PIN)
+ static_assert(false, "Z3_MAX_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z3_MIN
+ #if !AVAILABLE_EILINE(Z3_MIN_PIN)
+ static_assert(false, "Z3_MIN_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
+ #endif
+ #if HAS_Z_MIN_PROBE_PIN
+ #if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
+ static_assert(false, "Z_MIN_PROBE_PIN has no EXTINT line available.");
+ #endif
+ attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
+ #endif
+}
diff --git a/Marlin/src/HAL/HAL_SAMD51/fastio.h b/Marlin/src/HAL/HAL_SAMD51/fastio.h
new file mode 100644
index 0000000000..ecd9acea44
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/fastio.h
@@ -0,0 +1,252 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Fast IO functions for SAMD51
+ */
+
+#include "SAMD51.h"
+
+/**
+ * Utility functions
+ */
+
+#ifndef MASK
+ #define MASK(PIN) (1 << PIN)
+#endif
+
+/**
+ * Magic I/O routines
+ *
+ * Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
+ */
+
+// Read a pin
+#define READ(IO) ((PORT->Group[(EPortType)GET_SAMD_PORT(IO)].IN.reg & MASK(GET_SAMD_PIN(IO))) != 0)
+
+// Write to a pin
+#define WRITE(IO,V) do{ \
+ const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
+ const uint32_t mask = MASK(GET_SAMD_PIN(IO)); \
+ \
+ if (V) PORT->Group[port].OUTSET.reg = mask; \
+ else PORT->Group[port].OUTCLR.reg = mask; \
+ }while(0)
+
+// Toggle a pin
+#define TOGGLE(IO) PORT->Group[(EPortType)GET_SAMD_PORT(IO)].OUTTGL.reg = MASK(GET_SAMD_PIN(IO));
+
+// Set pin as input
+#define SET_INPUT(IO) do{ \
+ const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
+ const uint32_t pin = GET_SAMD_PIN(IO); \
+ \
+ PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN); \
+ PORT->Group[port].DIRCLR.reg = MASK(pin); \
+ }while(0)
+// Set pin as input with pullup
+#define SET_INPUT_PULLUP(IO) do{ \
+ const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
+ const uint32_t pin = GET_SAMD_PIN(IO); \
+ const uint32_t mask = MASK(pin); \
+ \
+ PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN | PORT_PINCFG_PULLEN); \
+ PORT->Group[port].DIRCLR.reg = mask; \
+ PORT->Group[port].OUTSET.reg = mask; \
+ }while(0)
+// Set pin as input with pulldown
+#define SET_INPUT_PULLDOWN(IO) do{ \
+ const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
+ const uint32_t pin = GET_SAMD_PIN(IO); \
+ const uint32_t mask = MASK(pin); \
+ \
+ PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN | PORT_PINCFG_PULLEN); \
+ PORT->Group[port].DIRCLR.reg = mask; \
+ PORT->Group[port].OUTCLR.reg = mask; \
+ }while(0)
+// Set pin as output (push pull)
+#define SET_OUTPUT(IO) do{ \
+ const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
+ const uint32_t pin = GET_SAMD_PIN(IO); \
+ \
+ PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN); \
+ PORT->Group[port].DIRSET.reg = MASK(pin); \
+ }while(0)
+// Set pin as output (open drain)
+#define SET_OUTPUT_OD(IO) do{ \
+ const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
+ const uint32_t pin = GET_SAMD_PIN(IO); \
+ \
+ PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_PULLEN); \
+ PORT->Group[port].DIRCLR.reg = MASK(pin); \
+ }while(0)
+// Set pin as PWM (push pull)
+#define SET_PWM(IO) SET_OUTPUT(IO)
+// Set pin as PWM (open drain)
+#define SET_PWM_OD(IO) SET_OUTPUT_OD(IO)
+
+// check if pin is an output
+#define IS_OUTPUT(IO) ((PORT->Group[(EPortType)GET_SAMD_PORT(IO)].DIR.reg & MASK(GET_SAMD_PIN(IO))) \
+ || (PORT->Group[(EPortType)GET_SAMD_PORT(IO)].PINCFG[GET_SAMD_PIN(IO)].reg & (PORT_PINCFG_INEN | PORT_PINCFG_PULLEN)) == PORT_PINCFG_PULLEN)
+// check if pin is an input
+#define IS_INPUT(IO) !IS_OUTPUT(IO)
+
+// Shorthand
+#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
+#define OUT_WRITE_OD(IO,V) do{ SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0)
+
+// digitalRead/Write wrappers
+#define extDigitalRead(IO) digitalRead(IO)
+#define extDigitalWrite(IO,V) digitalWrite(IO,V)
+
+/**
+ * Ports and functions
+ * Added as necessary or if I feel like it- not a comprehensive list!
+ */
+
+#ifdef ADAFRUIT_GRAND_CENTRAL_M4
+
+ /*
+ * Adafruit Grand Central M4 has a lot of PWMs the availables are listed here.
+ * Some of these share the same source and so can't be used in the same time
+ */
+ #define PWM_PIN(P) (WITHIN(P, 2, 13) || WITHIN(P, 22, 23) || WITHIN(P, 44, 45) || P == 48)
+
+ // Return fullfilled ADCx->INPUTCTRL.reg
+ #define PIN_TO_INPUTCTRL(P) ( (PIN_TO_AIN(P) == 0) ? ADC_INPUTCTRL_MUXPOS_AIN0 \
+ : (PIN_TO_AIN(P) == 1) ? ADC_INPUTCTRL_MUXPOS_AIN1 \
+ : (PIN_TO_AIN(P) == 2) ? ADC_INPUTCTRL_MUXPOS_AIN2 \
+ : (PIN_TO_AIN(P) == 3) ? ADC_INPUTCTRL_MUXPOS_AIN3 \
+ : (PIN_TO_AIN(P) == 4) ? ADC_INPUTCTRL_MUXPOS_AIN4 \
+ : (PIN_TO_AIN(P) == 5) ? ADC_INPUTCTRL_MUXPOS_AIN5 \
+ : (PIN_TO_AIN(P) == 6) ? ADC_INPUTCTRL_MUXPOS_AIN6 \
+ : (PIN_TO_AIN(P) == 7) ? ADC_INPUTCTRL_MUXPOS_AIN7 \
+ : (PIN_TO_AIN(P) == 8) ? ADC_INPUTCTRL_MUXPOS_AIN8 \
+ : (PIN_TO_AIN(P) == 9) ? ADC_INPUTCTRL_MUXPOS_AIN9 \
+ : (PIN_TO_AIN(P) == 10) ? ADC_INPUTCTRL_MUXPOS_AIN10 \
+ : (PIN_TO_AIN(P) == 11) ? ADC_INPUTCTRL_MUXPOS_AIN11 \
+ : (PIN_TO_AIN(P) == 12) ? ADC_INPUTCTRL_MUXPOS_AIN12 \
+ : (PIN_TO_AIN(P) == 13) ? ADC_INPUTCTRL_MUXPOS_AIN13 \
+ : (PIN_TO_AIN(P) == 14) ? ADC_INPUTCTRL_MUXPOS_AIN14 \
+ : ADC_INPUTCTRL_MUXPOS_AIN15)
+
+ #define ANAPIN_TO_SAMDPIN(P) ( (P == 0) ? PIN_TO_SAMD_PIN(67) \
+ : (P == 1) ? PIN_TO_SAMD_PIN(68) \
+ : (P == 2) ? PIN_TO_SAMD_PIN(69) \
+ : (P == 3) ? PIN_TO_SAMD_PIN(70) \
+ : (P == 4) ? PIN_TO_SAMD_PIN(71) \
+ : (P == 5) ? PIN_TO_SAMD_PIN(72) \
+ : (P == 6) ? PIN_TO_SAMD_PIN(73) \
+ : (P == 7) ? PIN_TO_SAMD_PIN(74) \
+ : (P == 8) ? PIN_TO_SAMD_PIN(54) \
+ : (P == 9) ? PIN_TO_SAMD_PIN(55) \
+ : (P == 10) ? PIN_TO_SAMD_PIN(56) \
+ : (P == 11) ? PIN_TO_SAMD_PIN(57) \
+ : (P == 12) ? PIN_TO_SAMD_PIN(58) \
+ : (P == 13) ? PIN_TO_SAMD_PIN(59) \
+ : (P == 14) ? PIN_TO_SAMD_PIN(60) \
+ : (P == 15) ? PIN_TO_SAMD_PIN(61) \
+ : (P == 16) ? PIN_TO_SAMD_PIN(12) \
+ : (P == 17) ? PIN_TO_SAMD_PIN(13) \
+ : PIN_TO_SAMD_PIN(9))
+
+ #define digitalPinToAnalogInput(P) (WITHIN(P, 67, 74) ? (P) - 67 : WITHIN(P, 54, 61) ? 8 + (P) - 54 : WITHIN(P, 12, 13) ? 16 + (P) - 12 : P == 9 ? 18 : -1)
+
+ /*
+ * pins
+ */
+
+ // PORTA
+ #define DIO67_PIN PIN_PA02 // A0
+ #define DIO59_PIN PIN_PA04 // A13
+ #define DIO68_PIN PIN_PA05 // A1
+ #define DIO60_PIN PIN_PA06 // A14
+ #define DIO61_PIN PIN_PA07 // A15
+ #define DIO26_PIN PIN_PA12
+ #define DIO27_PIN PIN_PA13
+ #define DIO28_PIN PIN_PA14
+ #define DIO23_PIN PIN_PA15
+ #define DIO37_PIN PIN_PA16
+ #define DIO36_PIN PIN_PA17
+ #define DIO35_PIN PIN_PA18
+ #define DIO34_PIN PIN_PA19
+ #define DIO33_PIN PIN_PA20
+ #define DIO32_PIN PIN_PA21
+ #define DIO31_PIN PIN_PA22
+ #define DIO30_PIN PIN_PA23
+ // PORTB
+ #define DIO12_PIN PIN_PB00 // A16
+ #define DIO13_PIN PIN_PB01 // A17
+ #define DIO9_PIN PIN_PB02 // A18
+ #define DIO69_PIN PIN_PB03 // A2
+ #define DIO74_PIN PIN_PB04 // A7
+ #define DIO54_PIN PIN_PB05 // A8
+ #define DIO55_PIN PIN_PB06 // A9
+ #define DIO56_PIN PIN_PB07 // A10
+ #define DIO57_PIN PIN_PB08 // A11
+ #define DIO58_PIN PIN_PB09 // A12
+ #define DIO18_PIN PIN_PB12
+ #define DIO19_PIN PIN_PB13
+ #define DIO39_PIN PIN_PB14
+ #define DIO38_PIN PIN_PB15
+ #define DIO14_PIN PIN_PB16
+ #define DIO15_PIN PIN_PB17
+ #define DIO8_PIN PIN_PB18
+ #define DIO29_PIN PIN_PB19
+ #define DIO20_PIN PIN_PB20
+ #define DIO21_PIN PIN_PB21
+ #define DIO10_PIN PIN_PB22
+ #define DIO11_PIN PIN_PB23
+ #define DIO1_PIN PIN_PB24
+ #define DIO0_PIN PIN_PB25
+ #define DIO83_PIN PIN_PB28 // SD_CS
+ #define DIO95_PIN PIN_PB31 // SD_CD
+ // PORTC
+ #define DIO70_PIN PIN_PC00 // A3
+ #define DIO71_PIN PIN_PC01 // A4
+ #define DIO72_PIN PIN_PC02 // A5
+ #define DIO73_PIN PIN_PC03 // A6
+ #define DIO48_PIN PIN_PC04
+ #define DIO49_PIN PIN_PC05
+ #define DIO46_PIN PIN_PC06
+ #define DIO47_PIN PIN_PC07
+ #define DIO45_PIN PIN_PC10
+ #define DIO44_PIN PIN_PC11
+ #define DIO41_PIN PIN_PC12
+ #define DIO40_PIN PIN_PC13
+ #define DIO43_PIN PIN_PC14
+ #define DIO42_PIN PIN_PC15
+ #define DIO25_PIN PIN_PC16
+ #define DIO24_PIN PIN_PC17
+ #define DIO2_PIN PIN_PC18
+ #define DIO3_PIN PIN_PC19
+ #define DIO4_PIN PIN_PC20
+ #define DIO5_PIN PIN_PC21
+ #define DIO16_PIN PIN_PC22
+ #define DIO17_PIN PIN_PC23
+ #define DIO88_PIN PIN_PC24 // NEOPIXEL
+ // PORTD
+ #define DIO22_PIN PIN_PD12
+ #define DIO6_PIN PIN_PD20
+ #define DIO7_PIN PIN_PD21
+
+#endif // ADAFRUIT_GRAND_CENTRAL_M4
diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h b/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h
new file mode 100644
index 0000000000..0f27d8bf35
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h
@@ -0,0 +1,48 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+/**
+ * Test SAMD51 specific configuration values for errors at compile-time.
+ */
+
+#if defined(ADAFRUIT_GRAND_CENTRAL_M4) && SD_CONNECTION_IS(CUSTOM_CABLE)
+ #error "No custom SD drive cable defined for this board."
+#endif
+
+#if defined(MAX6675_SCK_PIN) && defined(MAX6675_DO_PIN) && (MAX6675_SCK_PIN == SCK1 || MAX6675_DO_PIN == MISO1)
+ #error "OnBoard SPI BUS can't be shared with other devices."
+#endif
+
+#if ENABLED(EMERGENCY_PARSER)
+ #error "EMERGENCY_PARSER is not yet implemented for SAMD51. Disable EMERGENCY_PARSER to continue."
+#endif
+
+#if ENABLED(SDIO_SUPPORT)
+ #error "SDIO_SUPPORT is not supported."
+#endif
+
+#if ENABLED(FAST_PWM_FAN)
+ #error "FAST_PWM_FAN is not yet implemented for this platform."
+#endif
+
+#if ENABLED(EEPROM_SETTINGS) && NONE(SPI_EEPROM, I2C_EEPROM)
+ #warning "Did you activate the SmartEEPROM? See https://github.com/GMagician/SAMD51-SmartEEprom-Activator"
+#endif
diff --git a/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp
new file mode 100644
index 0000000000..e41dd85c85
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp
@@ -0,0 +1,129 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifdef __SAMD51__
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(EEPROM_SETTINGS)
+
+#include "../shared/persistent_store_api.h"
+
+#if NONE(SPI_EEPROM, I2C_EEPROM)
+ #define NVMCTRL_CMD(c) do{ \
+ SYNC(!NVMCTRL->STATUS.bit.READY); \
+ NVMCTRL->INTFLAG.bit.DONE = true; \
+ NVMCTRL->CTRLB.reg = c | NVMCTRL_CTRLB_CMDEX_KEY; \
+ SYNC(NVMCTRL->INTFLAG.bit.DONE); \
+ }while(0)
+ #define NVMCTRL_FLUSH() do{ \
+ if (NVMCTRL->SEESTAT.bit.LOAD) \
+ NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_SEEFLUSH); \
+ }while(0)
+#endif
+
+bool PersistentStore::access_start() {
+ #if NONE(SPI_EEPROM, I2C_EEPROM)
+ NVMCTRL->SEECFG.reg = NVMCTRL_SEECFG_WMODE_BUFFERED; // Buffered mode and segment reallocation active
+ #endif
+
+ return true;
+}
+
+bool PersistentStore::access_finish() {
+ #if NONE(SPI_EEPROM, I2C_EEPROM)
+ NVMCTRL_FLUSH();
+ if (!NVMCTRL->SEESTAT.bit.LOCK)
+ NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access
+ #endif
+
+ return true;
+}
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ #if NONE(SPI_EEPROM, I2C_EEPROM)
+ if (NVMCTRL->SEESTAT.bit.RLOCK)
+ NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access
+ #endif
+
+ while (size--) {
+ const uint8_t v = *value;
+ #if ANY(SPI_EEPROM, I2C_EEPROM)
+ uint8_t * const p = (uint8_t * const)pos;
+ if (v != eeprom_read_byte(p)) {
+ eeprom_write_byte(p, v);
+ delay(2);
+ if (eeprom_read_byte(p) != v) {
+ SERIAL_ECHO_MSG(MSG_ERR_EEPROM_WRITE);
+ return true;
+ }
+ }
+ #else
+ SYNC(NVMCTRL->SEESTAT.bit.BUSY);
+ if (NVMCTRL->INTFLAG.bit.SEESFULL)
+ NVMCTRL_FLUSH(); // Next write will trigger a sector reallocation. I need to flush 'pagebuffer'
+ ((volatile uint8_t *)SEEPROM_ADDR)[pos] = v;
+ SYNC(!NVMCTRL->INTFLAG.bit.SEEWRC);
+ #endif
+ crc16(crc, &v, 1);
+ pos++;
+ value++;
+ }
+ return false;
+}
+
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
+ while (size--) {
+ uint8_t c;
+ #if ANY(SPI_EEPROM, I2C_EEPROM)
+ c = eeprom_read_byte((uint8_t*)pos);
+ #else
+ SYNC(NVMCTRL->SEESTAT.bit.BUSY);
+ c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];
+ #endif
+ if (writing) *value = c;
+ crc16(crc, &c, 1);
+ pos++;
+ value++;
+ }
+ return false;
+}
+
+size_t PersistentStore::capacity() {
+ #if ANY(SPI_EEPROM, I2C_EEPROM)
+ return E2END + 1;
+ #else
+ const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
+ sblk = NVMCTRL->SEESTAT.bit.SBLK;
+
+ if (!psz && !sblk) return 0;
+ else if (psz <= 2) return (0x200 << psz);
+ else if (sblk == 1 || psz == 3) return 4096;
+ else if (sblk == 2 || psz == 4) return 8192;
+ else if (sblk <= 4 || psz == 5) return 16384;
+ else if (sblk >= 9 && psz == 7) return 65536;
+ else return 32768;
+ #endif
+}
+
+#endif // EEPROM_SETTINGS
+
+#endif // __SAMD51__
diff --git a/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h b/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h
new file mode 100644
index 0000000000..64f6929c00
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h
@@ -0,0 +1,153 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#define NUMBER_PINS_TOTAL PINS_COUNT
+
+#define digitalRead_mod(p) extDigitalRead(p)
+#define PRINT_PORT(p) do{ SERIAL_ECHOPGM(" Port: "); sprintf_P(buffer, PSTR("%c%02ld"), 'A' + g_APinDescription[p].ulPort, g_APinDescription[p].ulPin); SERIAL_ECHO(buffer); }while (0)
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
+#define GET_ARRAY_PIN(p) pin_array[p].pin
+#define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
+#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL)
+#define DIGITAL_PIN_TO_ANALOG_PIN(p) digitalPinToAnalogInput(p)
+#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P)!=-1)
+#define pwm_status(pin) digitalPinHasPWM(pin)
+#define MULTI_NAME_PAD 27 // space needed to be pretty if not first name assigned to a pin
+
+// pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
+// uses pin index
+#define M43_NEVER_TOUCH(Q) ((Q) >= 75)
+
+bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
+ const EPortType samdport = g_APinDescription[pin].ulPort;
+ const uint32_t samdpin = g_APinDescription[pin].ulPin;
+ return PORT->Group[samdport].DIR.reg & MASK(samdpin) || (PORT->Group[samdport].PINCFG[samdpin].reg & (PORT_PINCFG_INEN | PORT_PINCFG_PULLEN)) == PORT_PINCFG_PULLEN;
+}
+
+void pwm_details(int32_t pin) {
+ if (pwm_status(pin)) {
+ //uint32_t chan = g_APinDescription[pin].ulPWMChannel TODO when fast pwm is operative;
+ //SERIAL_ECHOPAIR("PWM = ", duty);
+ }
+}
+
+/**
+ * AGCM4 Board pin | PORT | Label
+ * ----------------+--------+-------
+ * 0 | PB25 | "RX0"
+ * 1 | PB24 | "TX0"
+ * 2 | PC18 |
+ * 3 | PC19 |
+ * 4 | PC20 |
+ * 5 | PC21 |
+ * 6 | PD20 |
+ * 7 | PD21 |
+ * 8 | PB18 |
+ * 9 | PB2 |
+ * 10 | PB22 |
+ * 11 | PB23 |
+ * 12 | PB0 | "A16"
+ * 13 | PB1 | LED AMBER "L" / "A17"
+ * 14 | PB16 | "TX3"
+ * 15 | PB17 | "RX3"
+ * 16 | PC22 | "TX2"
+ * 17 | PC23 | "RX2"
+ * 18 | PB12 | "TX1" / "A18"
+ * 19 | PB13 | "RX1"
+ * 20 | PB20 | "SDA"
+ * 21 | PB21 | "SCL"
+ * 22 | PD12 |
+ * 23 | PA15 |
+ * 24 | PC17 |
+ * 25 | PC16 |
+ * 26 | PA12 |
+ * 27 | PA13 |
+ * 28 | PA14 |
+ * 29 | PB19 |
+ * 30 | PA23 |
+ * 31 | PA22 |
+ * 32 | PA21 |
+ * 33 | PA20 |
+ * 34 | PA19 |
+ * 35 | PA18 |
+ * 36 | PA17 |
+ * 37 | PA16 |
+ * 38 | PB15 |
+ * 39 | PB14 |
+ * 40 | PC13 |
+ * 41 | PC12 |
+ * 42 | PC15 |
+ * 43 | PC14 |
+ * 44 | PC11 |
+ * 45 | PC10 |
+ * 46 | PC6 |
+ * 47 | PC7 |
+ * 48 | PC4 |
+ * 49 | PC5 |
+ * 50 | PD11 |
+ * 51 | PD8 |
+ * 52 | PD9 |
+ * 53 | PD10 |
+ * 54 | PB5 | "A8"
+ * 55 | PB6 | "A9"
+ * 56 | PB7 | "A10"
+ * 57 | PB8 | "A11"
+ * 58 | PB9 | "A12"
+ * 69 | PA4 | "A13"
+ * 60 | PA6 | "A14"
+ * 61 | PA7 | "A15"
+ * 62 | PB17 |
+ * 63 | PB20 |
+ * 64 | PD11 |
+ * 65 | PD8 |
+ * 66 | PD9 |
+ * 67 | PA2 | "A0" / "DAC0"
+ * 68 | PA5 | "A1" / "DAC1"
+ * 69 | PB3 | "A2"
+ * 70 | PC0 | "A3"
+ * 71 | PC1 | "A4"
+ * 72 | PC2 | "A5"
+ * 73 | PC3 | "A6"
+ * 74 | PB4 | "A7"
+ * 75 | PC31 | LED GREEN "RX"
+ * 76 | PC30 | LED GREEN "TX"
+ * 77 | PA27 | USB: Host enable
+ * 78 | PA24 | USB: D-
+ * 79 | PA25 | USB: D+
+ * 80 | PB29 | SD: MISO
+ * 81 | PB27 | SD: SCK
+ * 82 | PB26 | SD: MOSI
+ * 83 | PB28 | SD: CS
+ * 84 | PA3 | AREF
+ * 85 | PA2 | DAC0 (Duplicate)
+ * 86 | PA5 | DAC1 (Duplicate)
+ * 87 | PB1 | LED AMBER "L" (Duplicate)
+ * 88 | PC24 | NeoPixel
+ * 89 | PB10 | QSPI: SCK
+ * 90 | PB11 | QSPI: CS
+ * 91 | PA8 | QSPI: IO0
+ * 92 | PA9 | QSPI: IO1
+ * 93 | PA10 | QSPI: IO2
+ * 94 | PA11 | QSPI: IO3
+ *
+ */
diff --git a/Marlin/src/HAL/HAL_SAMD51/spi_pins.h b/Marlin/src/HAL/HAL_SAMD51/spi_pins.h
new file mode 100644
index 0000000000..3315fa08ac
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/spi_pins.h
@@ -0,0 +1,54 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#ifdef ADAFRUIT_GRAND_CENTRAL_M4
+
+ /*
+ * AGCM4 Default SPI Pins
+ *
+ * SS SCK MISO MOSI
+ * +-------------------------+
+ * SPI | 53 52 50 51 |
+ * SPI1 | 83 81 80 82 |
+ * +-------------------------+
+ * Any pin can be used for Chip Select (SS_PIN)
+ */
+ #ifndef SCK_PIN
+ #define SCK_PIN 52
+ #endif
+ #ifndef MISO_PIN
+ #define MISO_PIN 50
+ #endif
+ #ifndef MOSI_PIN
+ #define MOSI_PIN 51
+ #endif
+ #ifndef SDSS
+ #define SDSS 53
+ #endif
+
+#else
+
+ #error "Unsupported board!"
+
+#endif
+
+#define SS_PIN SDSS
diff --git a/Marlin/src/HAL/HAL_SAMD51/timers.cpp b/Marlin/src/HAL/HAL_SAMD51/timers.cpp
new file mode 100644
index 0000000000..63902c3c5e
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/timers.cpp
@@ -0,0 +1,135 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifdef __SAMD51__
+
+// --------------------------------------------------------------------------
+// Includes
+// --------------------------------------------------------------------------
+#include "../../inc/MarlinConfig.h"
+#include "timers.h"
+
+// --------------------------------------------------------------------------
+// Local defines
+// --------------------------------------------------------------------------
+
+#define NUM_HARDWARE_TIMERS 8
+
+// --------------------------------------------------------------------------
+// Private Variables
+// --------------------------------------------------------------------------
+
+const tTimerConfig TimerConfig[NUM_HARDWARE_TIMERS] = {
+ { TC0, TC0_IRQn, TC_PRIORITY(0) },
+ { TC1, TC1_IRQn, TC_PRIORITY(1) },
+ { TC2, TC2_IRQn, TC_PRIORITY(2) }, // Reserved by framework tone function
+ { TC3, TC3_IRQn, TC_PRIORITY(3) }, // Reserved by servo library
+ { TC4, TC4_IRQn, TC_PRIORITY(4) },
+ { TC5, TC5_IRQn, TC_PRIORITY(5) },
+ { TC6, TC6_IRQn, TC_PRIORITY(6) },
+ { TC7, TC7_IRQn, TC_PRIORITY(7) }
+};
+
+// --------------------------------------------------------------------------
+// Private functions
+// --------------------------------------------------------------------------
+
+FORCE_INLINE void Disable_Irq(IRQn_Type irq) {
+ NVIC_DisableIRQ(irq);
+
+ // We NEED memory barriers to ensure Interrupts are actually disabled!
+ // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
+ __DSB();
+ __ISB();
+}
+
+// --------------------------------------------------------------------------
+// Public functions
+// --------------------------------------------------------------------------
+
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
+ Tc * const tc = TimerConfig[timer_num].pTimer;
+ IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
+
+ // Disable interrupt, just in case it was already enabled
+ Disable_Irq(irq);
+
+ // Disable timer interrupt
+ tc->COUNT32.INTENCLR.reg = TC_INTENCLR_OVF; // disable overflow interrupt
+
+ // TCn clock setup
+ const uint8_t clockID = GCLK_CLKCTRL_IDs[TCC_INST_NUM + timer_num];
+ GCLK->PCHCTRL[clockID].bit.CHEN = false;
+ SYNC(GCLK->PCHCTRL[clockID].bit.CHEN);
+ GCLK->PCHCTRL[clockID].reg = GCLK_PCHCTRL_GEN_GCLK0 | GCLK_PCHCTRL_CHEN; // 120MHz startup code programmed
+ SYNC(!GCLK->PCHCTRL[clockID].bit.CHEN);
+
+ // Stop timer, just in case, to be able to reconfigure it
+ tc->COUNT32.CTRLA.bit.ENABLE = false;
+ SYNC(tc->COUNT32.SYNCBUSY.bit.ENABLE);
+
+ // Reset timer
+ tc->COUNT32.CTRLA.bit.SWRST = true;
+ SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
+
+ NVIC_SetPriority(irq, TimerConfig[timer_num].priority);
+
+ // Wave mode, reset counter on overflow on 0 (I use count down to prevent double buffer use)
+ tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
+ tc->COUNT32.CTRLA.reg = TC_CTRLA_MODE_COUNT32 | TC_CTRLA_PRESCALER_DIV1;
+ tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_DIR;
+ SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
+
+ // Set compare value
+ tc->COUNT32.COUNT.reg = tc->COUNT32.CC[0].reg = HAL_TIMER_RATE / frequency;
+
+ // And start timer
+ tc->COUNT32.CTRLA.bit.ENABLE = true;
+ SYNC(tc->COUNT32.SYNCBUSY.bit.ENABLE);
+
+ // Enable interrupt on RC compare
+ tc->COUNT32.INTENSET.reg = TC_INTENCLR_OVF; // enable overflow interrupt
+
+ // Finally, enable IRQ
+ NVIC_EnableIRQ(irq);
+}
+
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
+ IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
+ NVIC_EnableIRQ(irq);
+}
+
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
+ IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
+ Disable_Irq(irq);
+}
+
+// missing from CMSIS: Check if interrupt is enabled or not
+static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
+ return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0;
+}
+
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
+ IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
+ return NVIC_GetEnabledIRQ(irq);
+}
+
+#endif // __SAMD51__
diff --git a/Marlin/src/HAL/HAL_SAMD51/timers.h b/Marlin/src/HAL/HAL_SAMD51/timers.h
new file mode 100644
index 0000000000..80c37d14af
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/timers.h
@@ -0,0 +1,116 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+
+// --------------------------------------------------------------------------
+// Defines
+// --------------------------------------------------------------------------
+
+typedef uint32_t hal_timer_t;
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
+
+#define HAL_TIMER_RATE SystemCoreClock // frequency of timers peripherals
+
+#define STEP_TIMER_NUM 0 // index of timer to use for stepper (also +1 for 32bits counter)
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
+#define TEMP_TIMER_NUM 4 // index of timer to use for temperature (also +1 for 32bits counter)
+
+#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
+
+#define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
+
+#define PULSE_TIMER_RATE STEPPER_TIMER_RATE
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
+
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
+
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
+
+#define TC_PRIORITY(t) (t == STEP_TIMER_NUM || t == PULSE_TIMER_NUM) ? 2 \
+ : (t == TEMP_TIMER_NUM) ? 6 \
+ : 7
+
+#define _TC_HANDLER(t) void TC##t##_Handler()
+#define TC_HANDLER(t) _TC_HANDLER(t)
+#define HAL_STEP_TIMER_ISR() TC_HANDLER(STEP_TIMER_NUM)
+#if STEP_TIMER_NUM != PULSE_TIMER_NUM
+ #define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
+#endif
+#define HAL_TEMP_TIMER_ISR() TC_HANDLER(TEMP_TIMER_NUM)
+
+// --------------------------------------------------------------------------
+// Types
+// --------------------------------------------------------------------------
+
+typedef struct {
+ Tc *pTimer;
+ IRQn_Type IRQ_Id;
+ uint8_t priority;
+} tTimerConfig;
+
+// --------------------------------------------------------------------------
+// Public Variables
+// --------------------------------------------------------------------------
+
+extern const tTimerConfig TimerConfig[];
+
+// --------------------------------------------------------------------------
+// Public functions
+// --------------------------------------------------------------------------
+
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
+
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
+ Tc * const tc = TimerConfig[timer_num].pTimer;
+ tc->COUNT32.CC[0].reg = HAL_TIMER_TYPE_MAX - compare;
+}
+
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
+ Tc * const tc = TimerConfig[timer_num].pTimer;
+ return (hal_timer_t)(HAL_TIMER_TYPE_MAX - tc->COUNT32.CC[0].reg);
+}
+
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
+ Tc * const tc = TimerConfig[timer_num].pTimer;
+ tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
+ SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
+ return HAL_TIMER_TYPE_MAX - tc->COUNT32.COUNT.reg;
+}
+
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
+
+FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
+ Tc * const tc = TimerConfig[timer_num].pTimer;
+ // Clear interrupt flag
+ tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF;
+}
+
+#define HAL_timer_isr_epilogue(timer_num)
diff --git a/Marlin/src/HAL/HAL_SAMD51/watchdog.cpp b/Marlin/src/HAL/HAL_SAMD51/watchdog.cpp
new file mode 100644
index 0000000000..69a6de4ef7
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/watchdog.cpp
@@ -0,0 +1,53 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifdef __SAMD51__
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(USE_WATCHDOG)
+
+ #include "watchdog.h"
+
+ void watchdog_init() {
+ // The low-power oscillator used by the WDT runs at 32,768 Hz with
+ // a 1:32 prescale, thus 1024 Hz, though probably not super precise.
+
+ // Setup WDT clocks
+ MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
+ MCLK->APBAMASK.bit.WDT_ = true;
+ OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
+
+ WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config
+ SYNC(WDT->SYNCBUSY.bit.ENABLE);
+
+ WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt
+ WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096; // Set at least 4s period for chip reset
+
+ HAL_watchdog_refresh();
+
+ WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode
+ SYNC(WDT->SYNCBUSY.bit.ENABLE);
+ }
+
+#endif // USE_WATCHDOG
+
+#endif // __SAMD51__
diff --git a/Marlin/src/HAL/HAL_SAMD51/watchdog.h b/Marlin/src/HAL/HAL_SAMD51/watchdog.h
new file mode 100644
index 0000000000..b626b0b06a
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/watchdog.h
@@ -0,0 +1,31 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+// Initialize watchdog with a 4 second interrupt time
+void watchdog_init();
+
+// Reset watchdog. MUST be called at least every 4 seconds after the
+// first watchdog_init or SAMD will go into emergency procedures.
+inline void HAL_watchdog_refresh() {
+ SYNC(WDT->SYNCBUSY.bit.CLEAR); // Test first if previous is 'ongoing' to save time waiting for command execution
+ WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
+}
diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp
index 881168a129..edc161a5d3 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL.cpp
+++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2017 Victor Perez
@@ -23,64 +23,30 @@
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
#include "../../inc/MarlinConfig.h"
#include "../shared/Delay.h"
-#if ENABLED(EEPROM_EMULATED_WITH_SRAM)
+#if ENABLED(SRAM_EEPROM_EMULATION)
#if STM32F7xx
#include "stm32f7xx_ll_pwr.h"
#elif STM32F4xx
#include "stm32f4xx_ll_pwr.h"
#else
- #error "EEPROM_EMULATED_WITH_SRAM is currently only supported for STM32F4xx and STM32F7xx"
+ #error "SRAM_EEPROM_EMULATION is currently only supported for STM32F4xx and STM32F7xx"
#endif
-#endif // EEPROM_EMULATED_WITH_SRAM
+#endif
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
-
+// ------------------------
// Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
@@ -94,7 +60,7 @@ uint16_t HAL_adc_result;
#endif
// HAL initialization task
-void HAL_init(void) {
+void HAL_init() {
FastIO_init();
#if ENABLED(SDSUPPORT)
@@ -105,7 +71,7 @@ void HAL_init(void) {
OUT_WRITE(LED_PIN, LOW);
#endif
- #if ENABLED(EEPROM_EMULATED_WITH_SRAM)
+ #if ENABLED(SRAM_EEPROM_EMULATION)
// Enable access to backup SRAM
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
@@ -118,9 +84,9 @@ void HAL_init(void) {
#endif // EEPROM_EMULATED_SRAM
}
-void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
+void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) return RST_SOFTWARE;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET) return RST_EXTERNAL;
@@ -134,16 +100,15 @@ extern "C" {
extern unsigned int _ebss; // end of bss section
}
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
-void HAL_adc_start_conversion(const uint8_t adc_pin) {
- HAL_adc_result = analogRead(adc_pin);
-}
+// TODO: Make sure this doesn't cause any delay
+void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
-uint16_t HAL_adc_get_result(void) {
- return HAL_adc_result;
-}
+uint16_t HAL_adc_get_result() { return HAL_adc_result; }
-#endif // ARDUINO_ARCH_STM32
+void flashFirmware(int16_t) { NVIC_SystemReset(); }
+
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/HAL.h b/Marlin/src/HAL/HAL_STM32/HAL.h
index c84fe325a2..dae75d42f2 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL.h
+++ b/Marlin/src/HAL/HAL_STM32/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2017 Victor Perez
@@ -24,15 +24,12 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
+#include "../../core/macros.h"
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_STM32.h"
-#include "watchdog_STM32.h"
+#include "fastio.h"
+#include "watchdog.h"
#include "../../inc/MarlinConfigPre.h"
@@ -42,9 +39,9 @@
#include
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#if SERIAL_PORT == 0
#error "Serial port 0 does not exist"
@@ -99,7 +96,7 @@
#define NUM_SERIAL 1
#endif
-#include "HAL_timers_STM32.h"
+#include "timers.h"
/**
* TODO: review this to return 1 for pins that are not analog input
@@ -127,57 +124,50 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
-typedef int8_t pin_t;
+typedef int16_t pin_t;
#define HAL_SERVO_LIB libServo
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
-/** result of last ADC conversion */
+// result of last ADC conversion
extern uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// Memory related
#define __bss_end __bss_end__
// Enable hooks into setup for HAL
-#define HAL_INIT 1
-void HAL_init(void);
+void HAL_init();
-/** clear reset reason */
-void HAL_clear_reset_source (void);
+// Clear reset reason
+void HAL_clear_reset_source();
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
+// Reset reason
+uint8_t HAL_get_reset_source();
void _delay_ms(const int delay);
extern "C" char* _sbrk(int incr);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+
static inline int freeMemory() {
volatile char top;
return &top - reinterpret_cast(_sbrk(0));
}
-//
-// SPI: Extended functions which take a channel number (hardware SPI only)
-//
-
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
+#pragma GCC diagnostic pop
//
// EEPROM
@@ -186,8 +176,8 @@ uint8_t spiRec(uint32_t chan);
// Wire library should work for i2c EEPROMs
void eeprom_write_byte(uint8_t *pos, unsigned char value);
uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
+void eeprom_read_block(void *__dst, const void *__src, size_t __n);
+void eeprom_update_block(const void *__src, void *__dst, size_t __n);
//
// ADC
@@ -195,7 +185,7 @@ void eeprom_update_block (const void *__src, void *__dst, size_t __n);
#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
-inline void HAL_adc_init(void) {}
+inline void HAL_adc_init() {}
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
@@ -203,8 +193,11 @@ inline void HAL_adc_init(void) {}
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+
+#define PLATFORM_M997_SUPPORT
+void flashFirmware(int16_t value);
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp b/Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp
similarity index 65%
rename from Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp
index 86cdb57811..45bd26d720 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,36 +22,31 @@
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
static SPISettings spiConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if ENABLED(SOFTWARE_SPI)
- // --------------------------------------------------------------------------
+ // ------------------------
// Software SPI
- // --------------------------------------------------------------------------
+ // ------------------------
#error "Software SPI not supported for STM32. Use Hardware SPI."
#else
-// --------------------------------------------------------------------------
+// ------------------------
// Hardware SPI
-// --------------------------------------------------------------------------
+// ------------------------
/**
* VGPV SPI speed start and PCLK2/2, by default 108/2 = 54Mhz
@@ -64,13 +59,12 @@ static SPISettings spiConfig;
*
* @details Only configures SS pin since stm32duino creates and initialize the SPI object
*/
-void spiBegin(void) {
+void spiBegin() {
#if !PIN_EXISTS(SS)
#error "SS_PIN not defined!"
#endif
- SET_OUTPUT(SS_PIN);
- WRITE(SS_PIN, HIGH);
+ OUT_WRITE(SS_PIN, HIGH);
}
/** Configure SPI for specified SPI speed */
@@ -78,16 +72,17 @@ void spiInit(uint8_t spiRate) {
// Use datarates Marlin uses
uint32_t clock;
switch (spiRate) {
- case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000
- case SPI_HALF_SPEED: clock = 5000000; break;
- case SPI_QUARTER_SPEED: clock = 2500000; break;
- case SPI_EIGHTH_SPEED: clock = 1250000; break;
- case SPI_SPEED_5: clock = 625000; break;
- case SPI_SPEED_6: clock = 300000; break;
- default:
- clock = 4000000; // Default from the SPI library
+ case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000
+ case SPI_HALF_SPEED: clock = 5000000; break;
+ case SPI_QUARTER_SPEED: clock = 2500000; break;
+ case SPI_EIGHTH_SPEED: clock = 1250000; break;
+ case SPI_SPEED_5: clock = 625000; break;
+ case SPI_SPEED_6: clock = 300000; break;
+ default:
+ clock = 4000000; // Default from the SPI library
}
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
+
SPI.begin();
}
@@ -98,7 +93,7 @@ void spiInit(uint8_t spiRate) {
*
* @details
*/
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
@@ -153,4 +148,4 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
#endif // SOFTWARE_SPI
-#endif // ARDUINO_ARCH_STM32
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/SanityCheck.h b/Marlin/src/HAL/HAL_STM32/SanityCheck.h
deleted file mode 100644
index 6c6ede24b4..0000000000
--- a/Marlin/src/HAL/HAL_STM32/SanityCheck.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Test Re-ARM specific configuration values for errors at compile-time.
- */
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
- #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
- #elif SPINDLE_LASER_POWERUP_DELAY < 1
- #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-#if ENABLED(EMERGENCY_PARSER)
- #error "EMERGENCY_PARSER is not yet implemented for STM32. Disable EMERGENCY_PARSER to continue."
-#endif
-
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
-#endif
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp b/Marlin/src/HAL/HAL_STM32/Servo.cpp
similarity index 68%
rename from Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/Servo.cpp
index 1f22767e27..2882f071ac 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/Servo.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,37 +22,36 @@
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
-#include "HAL_Servo_STM32.h"
+#include "Servo.h"
uint8_t servoPin[MAX_SERVOS] = { 0 };
int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex]);
+ if (servoIndex >= MAX_SERVOS) return -1;
+ if (pin > 0) servoPin[servoIndex] = pin;
+ return super::attach(servoPin[servoIndex]);
}
int8_t libServo::attach(const int pin, const int min, const int max) {
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex], min, max);
+ if (pin > 0) servoPin[servoIndex] = pin;
+ return super::attach(servoPin[servoIndex], min, max);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
#endif // HAS_SERVOS
-#endif // ARDUINO_ARCH_STM32
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h b/Marlin/src/HAL/HAL_STM32/Servo.h
similarity index 86%
rename from Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h
rename to Marlin/src/HAL/HAL_STM32/Servo.h
index 6805c48a54..592f3a0662 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/Servo.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ class libServo : public Servo {
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
private:
+ typedef Servo super;
uint16_t min_ticks, max_ticks;
uint8_t servoIndex; // index into the channel data for this servo
};
diff --git a/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
index 23eca4bab7..d0aa731e89 100644
--- a/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,9 +25,9 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
-void setup_endstop_interrupts(void) {
+void setup_endstop_interrupts() {
#if HAS_X_MAX
attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
#endif
diff --git a/Marlin/src/HAL/HAL_STM32/fastio_STM32.cpp b/Marlin/src/HAL/HAL_STM32/fastio.cpp
similarity index 87%
rename from Marlin/src/HAL/HAL_STM32/fastio_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/fastio.cpp
index 3ee075cf26..33685cedda 100644
--- a/Marlin/src/HAL/HAL_STM32/fastio_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/fastio.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_STM32/fastio_STM32.h b/Marlin/src/HAL/HAL_STM32/fastio.h
similarity index 80%
rename from Marlin/src/HAL/HAL_STM32/fastio_STM32.h
rename to Marlin/src/HAL/HAL_STM32/fastio.h
index 77c2eaf4fe..917ee3a1a6 100644
--- a/Marlin/src/HAL/HAL_STM32/fastio_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/fastio.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,25 +27,25 @@
* These use GPIO register access for fast port manipulation.
*/
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
extern GPIO_TypeDef * FastIOPortMap[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void FastIO_init(); // Must be called before using fast io macros
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define _BV32(b) (1UL << (b))
-#if !defined(PWM)
+#ifndef PWM
#define PWM OUTPUT
#endif
@@ -53,7 +53,7 @@ void FastIO_init(); // Must be called before using fast io macros
#define _WRITE(IO, V) do { \
if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \
else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \
- } while(0)
+ }while(0)
#else
#define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + (V ? 0 : 16)))
#endif
@@ -65,7 +65,6 @@ void FastIO_init(); // Must be called before using fast io macros
#define _SET_MODE(IO,M) pinMode(IO, M)
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
-#define WRITE_VAR(IO,V) _WRITE(IO,V)
#define WRITE(IO,V) _WRITE(IO,V)
#define READ(IO) _READ(IO)
#define TOGGLE(IO) _TOGGLE(IO)
diff --git a/Marlin/src/HAL/HAL_STM32/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_STM32/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_STM32/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_STM32/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32/inc/SanityCheck.h b/Marlin/src/HAL/HAL_STM32/inc/SanityCheck.h
new file mode 100644
index 0000000000..9a1727bceb
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/inc/SanityCheck.h
@@ -0,0 +1,37 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Test STM32-specific configuration values for errors at compile-time.
+ */
+//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
+// #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
+//#endif
+
+#if ENABLED(EMERGENCY_PARSER)
+ #error "EMERGENCY_PARSER is not yet implemented for STM32. Disable EMERGENCY_PARSER to continue."
+#endif
+
+#if ENABLED(FAST_PWM_FAN)
+ #error "FAST_PWM_FAN is not yet implemented for this platform."
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
index a6c50f0f7d..c94bce3b65 100644
--- a/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
@@ -24,24 +24,24 @@
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS)
+#if ENABLED(EEPROM_SETTINGS) && ANY(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
#include "../shared/persistent_store_api.h"
-#if DISABLED(EEPROM_EMULATED_WITH_SRAM, SPI_EEPROM, I2C_EEPROM)
+#if ENABLED(FLASH_EEPROM_EMULATION)
#include
static bool eeprom_data_written = false;
#endif
bool PersistentStore::access_start() {
- #if DISABLED(EEPROM_EMULATED_WITH_SRAM, SPI_EEPROM, I2C_EEPROM)
+ #if ENABLED(FLASH_EEPROM_EMULATION)
eeprom_buffer_fill();
#endif
return true;
}
bool PersistentStore::access_finish() {
- #if DISABLED(EEPROM_EMULATED_WITH_SRAM, SPI_EEPROM, I2C_EEPROM)
+ #if ENABLED(FLASH_EEPROM_EMULATION)
if (eeprom_data_written) {
eeprom_buffer_flush();
eeprom_data_written = false;
@@ -66,7 +66,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return true;
}
}
- #elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
+ #elif ENABLED(FLASH_EEPROM_EMULATION)
eeprom_buffered_write_byte(pos, v);
#else
*(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
@@ -76,20 +76,20 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
pos++;
value++;
};
- #if DISABLED(EEPROM_EMULATED_WITH_SRAM, SPI_EEPROM, I2C_EEPROM)
+ #if ENABLED(FLASH_EEPROM_EMULATION)
eeprom_data_written = true;
#endif
return false;
}
-bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing) {
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
// Read from either external EEPROM, program flash or Backup SRAM
const uint8_t c = (
#if EITHER(SPI_EEPROM, I2C_EEPROM)
eeprom_read_byte((uint8_t*)pos)
- #elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
+ #elif ENABLED(FLASH_EEPROM_EMULATION)
eeprom_buffered_read_byte(pos)
#else
(*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)))
@@ -105,14 +105,14 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
}
size_t PersistentStore::capacity() {
- #if EITHER(SPI_EEPROM, I2C_EEPROM)
- return E2END + 1;
- #elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
- return E2END + 1;
- #else
- return 4096; // 4kB
- #endif
+ return (
+ #if ENABLED(SRAM_EEPROM_EMULATION)
+ 4096 // 4kB
+ #else
+ E2END + 1
+ #endif
+ );
}
-#endif // EEPROM_SETTINGS
-#endif // ARDUINO_ARCH_STM32
+#endif // EEPROM_SETTINGS && (FLASH_EEPROM_EMULATION || SRAM_EEPROM_EMULATION || SPI_EEPROM || I2C_EEPROM)
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp
new file mode 100644
index 0000000000..6ce63073c4
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp
@@ -0,0 +1,103 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+/**
+ * Implementation of EEPROM settings in SD Card
+ */
+
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
+
+#include "../shared/persistent_store_api.h"
+
+#ifndef E2END
+ #define E2END 0xFFF // 4KB
+#endif
+#define HAL_EEPROM_SIZE int(E2END + 1)
+
+#define _ALIGN(x) __attribute__ ((aligned(x)))
+static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
+
+#if ENABLED(SDSUPPORT)
+
+ #include "../../sd/cardreader.h"
+
+ #define EEPROM_FILENAME "eeprom.dat"
+
+ bool PersistentStore::access_start() {
+ if (!card.isMounted()) return false;
+
+ SdFile file, root = card.getroot();
+ if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
+ return true;
+
+ int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
+ if (bytes_read < 0) return false;
+ for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
+ HAL_eeprom_data[bytes_read] = 0xFF;
+ file.close();
+ return true;
+ }
+
+ bool PersistentStore::access_finish() {
+ if (!card.isMounted()) return false;
+
+ SdFile file, root = card.getroot();
+ int bytes_written = 0;
+ if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
+ bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
+ file.close();
+ }
+ return (bytes_written == HAL_EEPROM_SIZE);
+ }
+
+#else // !SDSUPPORT
+
+ #error "Please define an EEPROM, a SDCARD or disable EEPROM_SETTINGS."
+
+#endif // !SDSUPPORT
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ for (size_t i = 0; i < size; i++)
+ HAL_eeprom_data[pos + i] = value[i];
+ crc16(crc, value, size);
+ pos += size;
+ return false;
+}
+
+bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
+ for (size_t i = 0; i < size; i++) {
+ uint8_t c = HAL_eeprom_data[pos + i];
+ if (writing) value[i] = c;
+ crc16(crc, &c, 1);
+ }
+ pos += size;
+ return false;
+}
+
+size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
+
+#endif // EEPROM_SETTINGS
+#endif // STM32
diff --git a/Marlin/src/HAL/HAL_STM32/pinsDebug.h b/Marlin/src/HAL/HAL_STM32/pinsDebug.h
index 3759c2d6c3..4e27cee195 100644
--- a/Marlin/src/HAL/HAL_STM32/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_STM32/pinsDebug.h
@@ -1 +1,34 @@
-#error "PINS_DEBUGGING is not yet supported for STM32!"
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#if !(defined(NUM_DIGITAL_PINS) || defined(BOARD_NR_GPIO_PINS))
+ #error "M43 not supported for this board"
+#endif
+
+// Strange - STM32F4 comes to HAL_STM32 rather than HAL_STM32F4 for these files
+#ifdef STM32F4
+ #ifdef NUM_DIGITAL_PINS // Only in ST's Arduino core (STM32duino, STM32Core)
+ #include "pinsDebug_STM32duino.h"
+ #elif defined(BOARD_NR_GPIO_PINS) // Only in STM32GENERIC (Maple)
+ #include "pinsDebug_STM32GENERIC.h"
+ #else
+ #error "M43 not supported for this board"
+ #endif
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32GENERIC.h b/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32GENERIC.h
new file mode 100644
index 0000000000..b1c2562185
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32GENERIC.h
@@ -0,0 +1,125 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Support routines for STM32GENERIC (Maple)
+ */
+
+/**
+ * Translation of routines & variables used by pinsDebug.h
+ */
+
+#ifdef BOARD_NR_GPIO_PINS // Only in STM32GENERIC (Maple)
+
+#ifdef __STM32F1__
+ #include "../HAL_STM32F1/fastio.h"
+#elif defined(STM32F4) || defined(STM32F7)
+ #include "../HAL_STM32_F4_F7/fastio.h"
+#else
+ #include "fastio.h"
+#endif
+
+extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
+
+#define NUM_DIGITAL_PINS BOARD_NR_GPIO_PINS
+#define NUMBER_PINS_TOTAL BOARD_NR_GPIO_PINS
+#define VALID_PIN(pin) (pin >= 0 && pin < BOARD_NR_GPIO_PINS)
+#define GET_ARRAY_PIN(p) pin_t(pin_array[p].pin)
+#define pwm_status(pin) PWM_PIN(pin)
+#define digitalRead_mod(p) extDigitalRead(p)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3hd "), int16_t(p)); SERIAL_ECHO(buffer); }while(0)
+#define PRINT_PORT(p) print_port(p)
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
+#define MULTI_NAME_PAD 21 // space needed to be pretty if not first name assigned to a pin
+
+// pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
+#ifndef M43_NEVER_TOUCH
+ #define M43_NEVER_TOUCH(Q) (Q >= 9 && Q <= 12) // SERIAL/USB pins PA9(TX) PA10(RX)
+#endif
+
+static inline int8_t get_pin_mode(pin_t pin) {
+ return VALID_PIN(pin) ? _GET_MODE(pin) : -1;
+}
+
+static inline pin_t DIGITAL_PIN_TO_ANALOG_PIN(pin_t pin) {
+ if (!VALID_PIN(pin)) return -1;
+ int8_t adc_channel = int8_t(PIN_MAP[pin].adc_channel);
+ #ifdef NUM_ANALOG_INPUTS
+ if (adc_channel >= NUM_ANALOG_INPUTS) adc_channel = ADCx;
+ #endif
+ return pin_t(adc_channel);
+}
+
+static inline bool IS_ANALOG(pin_t pin) {
+ if (!VALID_PIN(pin)) return false;
+ if (PIN_MAP[pin].adc_channel != ADCx) {
+ #ifdef NUM_ANALOG_INPUTS
+ if (PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS) return false;
+ #endif
+ return _GET_MODE(pin) == GPIO_INPUT_ANALOG && !M43_NEVER_TOUCH(pin);
+ }
+ return false;
+}
+
+static inline bool GET_PINMODE(const pin_t pin) {
+ return VALID_PIN(pin) && !IS_INPUT(pin);
+}
+
+static inline bool GET_ARRAY_IS_DIGITAL(const int16_t array_pin) {
+ const pin_t pin = GET_ARRAY_PIN(array_pin);
+ return (!IS_ANALOG(pin)
+ #ifdef NUM_ANALOG_INPUTS
+ || PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS
+ #endif
+ );
+}
+
+#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
+
+static inline void pwm_details(const pin_t pin) {
+ if (PWM_PIN(pin)) {
+ timer_dev * const tdev = PIN_MAP[pin].timer_device;
+ const uint8_t channel = PIN_MAP[pin].timer_channel;
+ const char num = (
+ #if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
+ tdev == &timer8 ? '8' :
+ tdev == &timer5 ? '5' :
+ #endif
+ tdev == &timer4 ? '4' :
+ tdev == &timer3 ? '3' :
+ tdev == &timer2 ? '2' :
+ tdev == &timer1 ? '1' : '?'
+ );
+ char buffer[10];
+ sprintf_P(buffer, PSTR(" TIM%c CH%c"), num, ('0' + channel));
+ SERIAL_ECHO(buffer);
+ }
+}
+
+static inline void print_port(pin_t pin) {
+ const char port = 'A' + char(pin >> 4); // pin div 16
+ const int16_t gbit = PIN_MAP[pin].gpio_bit;
+ char buffer[8];
+ sprintf_P(buffer, PSTR("P%c%hd "), port, gbit);
+ if (gbit < 10) SERIAL_CHAR(' ');
+ SERIAL_ECHO(buffer);
+}
+
+#endif // BOARD_NR_GPIO_PINS
diff --git a/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32duino.h b/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32duino.h
new file mode 100644
index 0000000000..9d9796eabe
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32duino.h
@@ -0,0 +1,275 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+
+#ifdef NUM_DIGITAL_PINS // Only in ST's Arduino core (STM32duino, STM32Core)
+
+/**
+ * Life gets complicated if you want an easy to use 'M43 I' output (in port/pin order)
+ * because the variants in this platform do not always define all the I/O port/pins
+ * that a CPU has.
+ *
+ * VARIABLES:
+ * Ard_num - Arduino pin number - defined by the platform. It is used by digitalRead and
+ * digitalWrite commands and by M42.
+ * - does not contain port/pin info
+ * - is not in port/pin order
+ * - typically a variant will only assign Ard_num to port/pins that are actually used
+ * Index - M43 counter - only used to get Ard_num
+ * x - a parameter/argument used to search the pin_array to try to find a signal name
+ * associated with a Ard_num
+ * Port_pin - port number and pin number for use with CPU registers and printing reports
+ *
+ * Since M43 uses digitalRead and digitalWrite commands, only the Port_pins with an Ard_num
+ * are accessed and/or displayed.
+ *
+ * Three arrays are used.
+ *
+ * digitalPin[] is provided by the platform. It consists of the Port_pin numbers in
+ * Arduino pin number order.
+ *
+ * pin_array is a structure generated by the pins/pinsDebug.h header file. It is generated by
+ * the preprocessor. Only the signals associated with enabled options are in this table.
+ * It contains:
+ * - name of the signal
+ * - the Ard_num assigned by the pins_YOUR_BOARD.h file using the platform defines.
+ * EXAMPLE: "#define KILL_PIN PB1" results in Ard_num of 57. 57 is then used as an
+ * index into digitalPin[] to get the Port_pin number
+ * - if it is a digital or analog signal. PWMs are considered digital here.
+ *
+ * pin_xref is a structure generated by this header file. It is generated by the
+ * preprocessor. It is in port/pin order. It contains just the port/pin numbers defined by the
+ * platform for this variant.
+ * - Ard_num
+ * - printable version of Port_pin
+ *
+ * Routines with an "x" as a parameter/argument are used to search the pin_array to try to
+ * find a signal name associated with a port/pin.
+ *
+ * NOTE - the Arduino pin number is what is used by the M42 command, NOT the port/pin for that
+ * signal. The Arduino pin number is listed by the M43 I command.
+ */
+
+extern const PinName digitalPin[]; // provided by the platform
+
+////////////////////////////////////////////////////////
+//
+// make a list of the Arduino pin numbers in the Port/Pin order
+//
+
+#define _PIN_ADD_2(NAME_ALPHA, ARDUINO_NUM) { {NAME_ALPHA}, ARDUINO_NUM },
+#define _PIN_ADD(NAME_ALPHA, ARDUINO_NUM) { NAME_ALPHA, ARDUINO_NUM },
+#define PIN_ADD(NAME) _PIN_ADD(#NAME, NAME)
+
+typedef struct {
+ char Port_pin_alpha[5];
+ pin_t Ard_num;
+} XrefInfo;
+
+const XrefInfo pin_xref[] PROGMEM = {
+ #include "pins_Xref.h"
+};
+
+////////////////////////////////////////////////////////////
+
+#define MODE_PIN_INPUT 0 // Input mode (reset state)
+#define MODE_PIN_OUTPUT 1 // General purpose output mode
+#define MODE_PIN_ALT 2 // Alternate function mode
+#define MODE_PIN_ANALOG 3 // Analog mode
+
+#define PIN_NUM(P) (P & 0x000F)
+#define PIN_NUM_ALPHA_LEFT(P) (((P & 0x000F) < 10) ? ('0' + (P & 0x000F)) : '1')
+#define PIN_NUM_ALPHA_RIGHT(P) (((P & 0x000F) > 9) ? ('0' + (P & 0x000F) - 10) : 0 )
+#define PORT_NUM(P) ((P >> 4) & 0x0007)
+#define PORT_ALPHA(P) ('A' + (P >> 4))
+
+/**
+ * Translation of routines & variables used by pinsDebug.h
+ */
+#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
+#define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
+#define digitalRead_mod(Ard_num) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
+#define PRINT_PIN(Q)
+#define PRINT_PORT(ANUM) port_print(ANUM)
+#define DIGITAL_PIN_TO_ANALOG_PIN(ANUM) -1 // will report analog pin number in the print port routine
+#define GET_PIN_MAP_PIN_M43(Index) pin_xref[Index].Ard_num
+
+// x is a variable used to search pin_array
+#define GET_ARRAY_IS_DIGITAL(x) ((bool) pin_array[x].is_digital)
+#define GET_ARRAY_PIN(x) ((pin_t) pin_array[x].pin)
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
+#define MULTI_NAME_PAD 33 // space needed to be pretty if not first name assigned to a pin
+
+#ifndef M43_NEVER_TOUCH
+ #define _M43_NEVER_TOUCH(Index) (Index >= 9 && Index <= 12) // SERIAL/USB pins: PA9(TX) PA10(RX) PA11(USB_DM) PA12(USB_DP)
+ #ifdef KILL_PIN
+ #define M43_NEVER_TOUCH(Index) m43_never_touch(Index)
+
+ bool m43_never_touch(const pin_t Index) {
+ static pin_t M43_kill_index = -1;
+ if (M43_kill_index < 0)
+ for (M43_kill_index = 0; M43_kill_index < NUMBER_PINS_TOTAL; M43_kill_index++)
+ if (KILL_PIN == GET_PIN_MAP_PIN_M43(M43_kill_index)) break;
+ return _M43_NEVER_TOUCH(Index) || Index == M43_kill_index; // KILL_PIN and SERIAL/USB
+ }
+ #else
+ #define M43_NEVER_TOUCH(Index) _M43_NEVER_TOUCH(Index)
+ #endif
+#endif
+
+uint8_t get_pin_mode(const pin_t Ard_num) {
+ uint32_t mode_all = 0;
+ const PinName dp = digitalPin[Ard_num];
+ switch (PORT_ALPHA(dp)) {
+ case 'A' : mode_all = GPIOA->MODER; break;
+ case 'B' : mode_all = GPIOB->MODER; break;
+ case 'C' : mode_all = GPIOC->MODER; break;
+ case 'D' : mode_all = GPIOD->MODER; break;
+ #ifdef PE_0
+ case 'E' : mode_all = GPIOE->MODER; break;
+ #elif defined(PF_0)
+ case 'F' : mode_all = GPIOF->MODER; break;
+ #elif defined(PG_0)
+ case 'G' : mode_all = GPIOG->MODER; break;
+ #elif defined(PH_0)
+ case 'H' : mode_all = GPIOH->MODER; break;
+ #elif defined(PI_0)
+ case 'I' : mode_all = GPIOI->MODER; break;
+ #elif defined(PJ_0)
+ case 'J' : mode_all = GPIOJ->MODER; break;
+ #elif defined(PK_0)
+ case 'K' : mode_all = GPIOK->MODER; break;
+ #elif defined(PL_0)
+ case 'L' : mode_all = GPIOL->MODER; break;
+ #endif
+ }
+ return (mode_all >> (2 * uint8_t(PIN_NUM(dp)))) & 0x03;
+}
+
+bool GET_PINMODE(const pin_t Ard_num) {
+ const uint8_t pin_mode = get_pin_mode(Ard_num);
+ return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT; // assume all alt definitions are PWM
+}
+
+int8_t digital_pin_to_analog_pin(pin_t Ard_num) {
+ Ard_num -= NUM_ANALOG_FIRST;
+ return (Ard_num >= 0 && Ard_num < NUM_ANALOG_INPUTS) ? Ard_num : -1;
+}
+
+bool IS_ANALOG(const pin_t Ard_num) {
+ return get_pin_mode(Ard_num) == MODE_PIN_ANALOG;
+}
+
+bool is_digital(const pin_t x) {
+ const uint8_t pin_mode = get_pin_mode(pin_array[x].pin);
+ return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT;
+}
+
+void port_print(const pin_t Ard_num) {
+ char buffer[16];
+ pin_t Index;
+ for (Index = 0; Index < NUMBER_PINS_TOTAL; Index++)
+ if (Ard_num == GET_PIN_MAP_PIN_M43(Index)) break;
+
+ const char * ppa = pin_xref[Index].Port_pin_alpha;
+ sprintf_P(buffer, PSTR("%s"), ppa);
+ SERIAL_ECHO(buffer);
+ if (ppa[3] == '\0') SERIAL_CHAR(' ');
+
+ // print analog pin number
+ const int8_t Port_pin = digital_pin_to_analog_pin(Ard_num);
+ if (Port_pin >= 0) {
+ sprintf_P(buffer, PSTR(" (A%d) "), Port_pin);
+ SERIAL_ECHO(buffer);
+ if (Port_pin < 10) SERIAL_CHAR(' ');
+ }
+ else
+ SERIAL_ECHO_SP(7);
+
+ // Print number to be used with M42
+ sprintf_P(buffer, PSTR(" M42 P%d "), Ard_num);
+ SERIAL_ECHO(buffer);
+ if (Ard_num < 10) SERIAL_CHAR(' ');
+ if (Ard_num < 100) SERIAL_CHAR(' ');
+}
+
+bool pwm_status(const pin_t Ard_num) {
+ return get_pin_mode(Ard_num) == MODE_PIN_ALT;
+}
+
+void pwm_details(const pin_t Ard_num) {
+ if (pwm_status(Ard_num)) {
+ uint32_t alt_all = 0;
+ const PinName dp = digitalPin[Ard_num];
+ pin_t pin_number = uint8_t(PIN_NUM(dp));
+ const bool over_7 = pin_number >= 8;
+ const uint8_t ind = over_7 ? 1 : 0;
+ switch (PORT_ALPHA(dp)) { // get alt function
+ case 'A' : alt_all = GPIOA->AFR[ind]; break;
+ case 'B' : alt_all = GPIOB->AFR[ind]; break;
+ case 'C' : alt_all = GPIOC->AFR[ind]; break;
+ case 'D' : alt_all = GPIOD->AFR[ind]; break;
+ #ifdef PE_0
+ case 'E' : alt_all = GPIOE->AFR[ind]; break;
+ #elif defined (PF_0)
+ case 'F' : alt_all = GPIOF->AFR[ind]; break;
+ #elif defined (PG_0)
+ case 'G' : alt_all = GPIOG->AFR[ind]; break;
+ #elif defined (PH_0)
+ case 'H' : alt_all = GPIOH->AFR[ind]; break;
+ #elif defined (PI_0)
+ case 'I' : alt_all = GPIOI->AFR[ind]; break;
+ #elif defined (PJ_0)
+ case 'J' : alt_all = GPIOJ->AFR[ind]; break;
+ #elif defined (PK_0)
+ case 'K' : alt_all = GPIOK->AFR[ind]; break;
+ #elif defined (PL_0)
+ case 'L' : alt_all = GPIOL->AFR[ind]; break;
+ #endif
+ }
+ if (over_7) pin_number -= 8;
+
+ uint8_t alt_func = (alt_all >> (4 * pin_number)) & 0x0F;
+ SERIAL_ECHOPAIR("Alt Function: ", alt_func);
+ if (alt_func < 10) SERIAL_CHAR(' ');
+ SERIAL_ECHOPGM(" - ");
+ switch (alt_func) {
+ case 0 : SERIAL_ECHOPGM("system (misc. I/O)"); break;
+ case 1 : SERIAL_ECHOPGM("TIM1/TIM2 (probably PWM)"); break;
+ case 2 : SERIAL_ECHOPGM("TIM3..5 (probably PWM)"); break;
+ case 3 : SERIAL_ECHOPGM("TIM8..11 (probably PWM)"); break;
+ case 4 : SERIAL_ECHOPGM("I2C1..3"); break;
+ case 5 : SERIAL_ECHOPGM("SPI1/SPI2"); break;
+ case 6 : SERIAL_ECHOPGM("SPI3"); break;
+ case 7 : SERIAL_ECHOPGM("USART1..3"); break;
+ case 8 : SERIAL_ECHOPGM("USART4..6"); break;
+ case 9 : SERIAL_ECHOPGM("CAN1/CAN2, TIM12..14 (probably PWM)"); break;
+ case 10 : SERIAL_ECHOPGM("OTG"); break;
+ case 11 : SERIAL_ECHOPGM("ETH"); break;
+ case 12 : SERIAL_ECHOPGM("FSMC, SDIO, OTG"); break;
+ case 13 : SERIAL_ECHOPGM("DCMI"); break;
+ case 14 : SERIAL_ECHOPGM("unused (shouldn't see this)"); break;
+ case 15 : SERIAL_ECHOPGM("EVENTOUT"); break;
+ }
+ }
+} // pwm_details
+
+#endif // NUM_DIGITAL_PINS
diff --git a/Marlin/src/HAL/HAL_STM32/pins_Xref.h b/Marlin/src/HAL/HAL_STM32/pins_Xref.h
new file mode 100644
index 0000000000..84278c3916
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/pins_Xref.h
@@ -0,0 +1,612 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+//
+// make a list of the Arduino pin numbers in the Port/Pin order
+//
+#ifdef PA0
+ PIN_ADD(PA0)
+#endif
+#ifdef PA1
+ PIN_ADD(PA1)
+#endif
+#ifdef PA2
+ PIN_ADD(PA2)
+#endif
+#ifdef PA3
+ PIN_ADD(PA3)
+#endif
+#ifdef PA4
+ PIN_ADD(PA4)
+#endif
+#ifdef PA5
+ PIN_ADD(PA5)
+#endif
+#ifdef PA6
+ PIN_ADD(PA6)
+#endif
+#ifdef PA7
+ PIN_ADD(PA7)
+#endif
+#ifdef PA8
+ PIN_ADD(PA8)
+#endif
+#ifdef PA9
+ PIN_ADD(PA9)
+#endif
+#ifdef PA10
+ PIN_ADD(PA10)
+#endif
+#ifdef PA11
+ PIN_ADD(PA11)
+#endif
+#ifdef PA12
+ PIN_ADD(PA12)
+#endif
+#ifdef PA13
+ PIN_ADD(PA13)
+#endif
+#ifdef PA14
+ PIN_ADD(PA14)
+#endif
+#ifdef PA15
+ PIN_ADD(PA15)
+#endif
+
+#ifdef PB0
+ PIN_ADD(PB0)
+#endif
+#ifdef PB1
+ PIN_ADD(PB1)
+#endif
+#ifdef PB2
+ PIN_ADD(PB2)
+#endif
+#ifdef PB3
+ PIN_ADD(PB3)
+#endif
+#ifdef PB4
+ PIN_ADD(PB4)
+#endif
+#ifdef PB5
+ PIN_ADD(PB5)
+#endif
+#ifdef PB6
+ PIN_ADD(PB6)
+#endif
+#ifdef PB7
+ PIN_ADD(PB7)
+#endif
+#ifdef PB8
+ PIN_ADD(PB8)
+#endif
+#ifdef PB9
+ PIN_ADD(PB9)
+#endif
+#ifdef PB10
+ PIN_ADD(PB10)
+#endif
+#ifdef PB11
+ PIN_ADD(PB11)
+#endif
+#ifdef PB12
+ PIN_ADD(PB12)
+#endif
+#ifdef PB13
+ PIN_ADD(PB13)
+#endif
+#ifdef PB14
+ PIN_ADD(PB14)
+#endif
+#ifdef PB15
+ PIN_ADD(PB15)
+#endif
+
+#ifdef PC0
+ PIN_ADD(PC0)
+#endif
+#ifdef PC1
+ PIN_ADD(PC1)
+#endif
+#ifdef PC2
+ PIN_ADD(PC2)
+#endif
+#ifdef PC3
+ PIN_ADD(PC3)
+#endif
+#ifdef PC4
+ PIN_ADD(PC4)
+#endif
+#ifdef PC5
+ PIN_ADD(PC5)
+#endif
+#ifdef PC6
+ PIN_ADD(PC6)
+#endif
+#ifdef PC7
+ PIN_ADD(PC7)
+#endif
+#ifdef PC8
+ PIN_ADD(PC8)
+#endif
+#ifdef PC9
+ PIN_ADD(PC9)
+#endif
+#ifdef PC10
+ PIN_ADD(PC10)
+#endif
+#ifdef PC11
+ PIN_ADD(PC11)
+#endif
+#ifdef PC12
+ PIN_ADD(PC12)
+#endif
+#ifdef PC13
+ PIN_ADD(PC13)
+#endif
+#ifdef PC14
+ PIN_ADD(PC14)
+#endif
+#ifdef PC15
+ PIN_ADD(PC15)
+#endif
+
+#ifdef PD0
+ PIN_ADD(PD0)
+#endif
+#ifdef PD1
+ PIN_ADD(PD1)
+#endif
+#ifdef PD2
+ PIN_ADD(PD2)
+#endif
+#ifdef PD3
+ PIN_ADD(PD3)
+#endif
+#ifdef PD4
+ PIN_ADD(PD4)
+#endif
+#ifdef PD5
+ PIN_ADD(PD5)
+#endif
+#ifdef PD6
+ PIN_ADD(PD6)
+#endif
+#ifdef PD7
+ PIN_ADD(PD7)
+#endif
+#ifdef PD8
+ PIN_ADD(PD8)
+#endif
+#ifdef PD9
+ PIN_ADD(PD9)
+#endif
+#ifdef PD10
+ PIN_ADD(PD10)
+#endif
+#ifdef PD11
+ PIN_ADD(PD11)
+#endif
+#ifdef PD12
+ PIN_ADD(PD12)
+#endif
+#ifdef PD13
+ PIN_ADD(PD13)
+#endif
+#ifdef PD14
+ PIN_ADD(PD14)
+#endif
+#ifdef PD15
+ PIN_ADD(PD15)
+#endif
+
+#ifdef PE0
+ PIN_ADD(PE0)
+#endif
+#ifdef PE1
+ PIN_ADD(PE1)
+#endif
+#ifdef PE2
+ PIN_ADD(PE2)
+#endif
+#ifdef PE3
+ PIN_ADD(PE3)
+#endif
+#ifdef PE4
+ PIN_ADD(PE4)
+#endif
+#ifdef PE5
+ PIN_ADD(PE5)
+#endif
+#ifdef PE6
+ PIN_ADD(PE6)
+#endif
+#ifdef PE7
+ PIN_ADD(PE7)
+#endif
+#ifdef PE8
+ PIN_ADD(PE8)
+#endif
+#ifdef PE9
+ PIN_ADD(PE9)
+#endif
+#ifdef PE10
+ PIN_ADD(PE10)
+#endif
+#ifdef PE11
+ PIN_ADD(PE11)
+#endif
+#ifdef PE12
+ PIN_ADD(PE12)
+#endif
+#ifdef PE13
+ PIN_ADD(PE13)
+#endif
+#ifdef PE14
+ PIN_ADD(PE14)
+#endif
+#ifdef PE15
+ PIN_ADD(PE15)
+#endif
+
+#ifdef PF0
+ PIN_ADD(PF0)
+#endif
+#ifdef PF1
+ PIN_ADD(PF1)
+#endif
+#ifdef PF2
+ PIN_ADD(PF2)
+#endif
+#ifdef PF3
+ PIN_ADD(PF3)
+#endif
+#ifdef PF4
+ PIN_ADD(PF4)
+#endif
+#ifdef PF5
+ PIN_ADD(PF5)
+#endif
+#ifdef PF6
+ PIN_ADD(PF6)
+#endif
+#ifdef PF7
+ PIN_ADD(PF7)
+#endif
+#ifdef PF8
+ PIN_ADD(PF8)
+#endif
+#ifdef PF9
+ PIN_ADD(PF9)
+#endif
+#ifdef PF10
+ PIN_ADD(PF10)
+#endif
+#ifdef PF11
+ PIN_ADD(PF11)
+#endif
+#ifdef PF12
+ PIN_ADD(PF12)
+#endif
+#ifdef PF13
+ PIN_ADD(PF13)
+#endif
+#ifdef PF14
+ PIN_ADD(PF14)
+#endif
+#ifdef PF15
+ PIN_ADD(PF15)
+#endif
+
+#ifdef PG0
+ PIN_ADD(PG0)
+#endif
+#ifdef PG1
+ PIN_ADD(PG1)
+#endif
+#ifdef PG2
+ PIN_ADD(PG2)
+#endif
+#ifdef PG3
+ PIN_ADD(PG3)
+#endif
+#ifdef PG4
+ PIN_ADD(PG4)
+#endif
+#ifdef PG5
+ PIN_ADD(PG5)
+#endif
+#ifdef PG6
+ PIN_ADD(PG6)
+#endif
+#ifdef PG7
+ PIN_ADD(PG7)
+#endif
+#ifdef PG8
+ PIN_ADD(PG8)
+#endif
+#ifdef PG9
+ PIN_ADD(PG9)
+#endif
+#ifdef PG10
+ PIN_ADD(PG10)
+#endif
+#ifdef PG11
+ PIN_ADD(PG11)
+#endif
+#ifdef PG12
+ PIN_ADD(PG12)
+#endif
+#ifdef PG13
+ PIN_ADD(PG13)
+#endif
+#ifdef PG14
+ PIN_ADD(PG14)
+#endif
+#ifdef PG15
+ PIN_ADD(PG15)
+#endif
+
+#ifdef PH0
+ PIN_ADD(PH0)
+#endif
+#ifdef PH1
+ PIN_ADD(PH1)
+#endif
+#ifdef PH2
+ PIN_ADD(PH2)
+#endif
+#ifdef PH3
+ PIN_ADD(PH3)
+#endif
+#ifdef PH4
+ PIN_ADD(PH4)
+#endif
+#ifdef PH5
+ PIN_ADD(PH5)
+#endif
+#ifdef PH6
+ PIN_ADD(PH6)
+#endif
+#ifdef PH7
+ PIN_ADD(PH7)
+#endif
+#ifdef PH8
+ PIN_ADD(PH8)
+#endif
+#ifdef PH9
+ PIN_ADD(PH9)
+#endif
+#ifdef PH10
+ PIN_ADD(PH10)
+#endif
+#ifdef PH11
+ PIN_ADD(PH11)
+#endif
+#ifdef PH12
+ PIN_ADD(PH12)
+#endif
+#ifdef PH13
+ PIN_ADD(PH13)
+#endif
+#ifdef PH14
+ PIN_ADD(PH14)
+#endif
+#ifdef PH15
+ PIN_ADD(PH15)
+#endif
+
+#ifdef PI0
+ PIN_ADD(PI0)
+#endif
+#ifdef PI1
+ PIN_ADD(PI1)
+#endif
+#ifdef PI2
+ PIN_ADD(PI2)
+#endif
+#ifdef PI3
+ PIN_ADD(PI3)
+#endif
+#ifdef PI4
+ PIN_ADD(PI4)
+#endif
+#ifdef PI5
+ PIN_ADD(PI5)
+#endif
+#ifdef PI6
+ PIN_ADD(PI6)
+#endif
+#ifdef PI7
+ PIN_ADD(PI7)
+#endif
+#ifdef PI8
+ PIN_ADD(PI8)
+#endif
+#ifdef PI9
+ PIN_ADD(PI9)
+#endif
+#ifdef PI10
+ PIN_ADD(PI10)
+#endif
+#ifdef PI11
+ PIN_ADD(PI11)
+#endif
+#ifdef PI12
+ PIN_ADD(PI12)
+#endif
+#ifdef PI13
+ PIN_ADD(PI13)
+#endif
+#ifdef PI14
+ PIN_ADD(PI14)
+#endif
+#ifdef PI15
+ PIN_ADD(PI15)
+#endif
+
+#ifdef PJ0
+ PIN_ADD(PJ0)
+#endif
+#ifdef PJ1
+ PIN_ADD(PJ1)
+#endif
+#ifdef PJ2
+ PIN_ADD(PJ2)
+#endif
+#ifdef PJ3
+ PIN_ADD(PJ3)
+#endif
+#ifdef PJ4
+ PIN_ADD(PJ4)
+#endif
+#ifdef PJ5
+ PIN_ADD(PJ5)
+#endif
+#ifdef PJ6
+ PIN_ADD(PJ6)
+#endif
+#ifdef PJ7
+ PIN_ADD(PJ7)
+#endif
+#ifdef PJ8
+ PIN_ADD(PJ8)
+#endif
+#ifdef PJ9
+ PIN_ADD(PJ9)
+#endif
+#ifdef PJ10
+ PIN_ADD(PJ10)
+#endif
+#ifdef PJ11
+ PIN_ADD(PJ11)
+#endif
+#ifdef PJ12
+ PIN_ADD(PJ12)
+#endif
+#ifdef PJ13
+ PIN_ADD(PJ13)
+#endif
+#ifdef PJ14
+ PIN_ADD(PJ14)
+#endif
+#ifdef PJ15
+ PIN_ADD(PJ15)
+#endif
+
+#ifdef PK0
+ PIN_ADD(PK0)
+#endif
+#ifdef PK1
+ PIN_ADD(PK1)
+#endif
+#ifdef PK2
+ PIN_ADD(PK2)
+#endif
+#ifdef PK3
+ PIN_ADD(PK3)
+#endif
+#ifdef PK4
+ PIN_ADD(PK4)
+#endif
+#ifdef PK5
+ PIN_ADD(PK5)
+#endif
+#ifdef PK6
+ PIN_ADD(PK6)
+#endif
+#ifdef PK7
+ PIN_ADD(PK7)
+#endif
+#ifdef PK8
+ PIN_ADD(PK8)
+#endif
+#ifdef PK9
+ PIN_ADD(PK9)
+#endif
+#ifdef PK10
+ PIN_ADD(PK10)
+#endif
+#ifdef PK11
+ PIN_ADD(PK11)
+#endif
+#ifdef PK12
+ PIN_ADD(PK12)
+#endif
+#ifdef PK13
+ PIN_ADD(PK13)
+#endif
+#ifdef PK14
+ PIN_ADD(PK14)
+#endif
+#ifdef PK15
+ PIN_ADD(PK15)
+#endif
+
+#ifdef PL0
+ PIN_ADD(PL0)
+#endif
+#ifdef PL1
+ PIN_ADD(PL1)
+#endif
+#ifdef PL2
+ PIN_ADD(PL2)
+#endif
+#ifdef PL3
+ PIN_ADD(PL3)
+#endif
+#ifdef PL4
+ PIN_ADD(PL4)
+#endif
+#ifdef PL5
+ PIN_ADD(PL5)
+#endif
+#ifdef PL6
+ PIN_ADD(PL6)
+#endif
+#ifdef PL7
+ PIN_ADD(PL7)
+#endif
+#ifdef PL8
+ PIN_ADD(PL8)
+#endif
+#ifdef PL9
+ PIN_ADD(PL9)
+#endif
+#ifdef PL10
+ PIN_ADD(PL10)
+#endif
+#ifdef PL11
+ PIN_ADD(PL11)
+#endif
+#ifdef PL12
+ PIN_ADD(PL12)
+#endif
+#ifdef PL13
+ PIN_ADD(PL13)
+#endif
+#ifdef PL14
+ PIN_ADD(PL14)
+#endif
+#ifdef PL15
+ PIN_ADD(PL15)
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32/spi_pins.h b/Marlin/src/HAL/HAL_STM32/spi_pins.h
index ba325b48e4..f8c9546b63 100644
--- a/Marlin/src/HAL/HAL_STM32/spi_pins.h
+++ b/Marlin/src/HAL/HAL_STM32/spi_pins.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp
similarity index 63%
rename from Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/timers.cpp
index 28d8d095c7..51f84e657f 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/timers.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -19,53 +19,28 @@
* along with this program. If not, see .
*
*/
+
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
-#include "HAL_timers_STM32.h"
+#include "timers.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define NUM_HARDWARE_TIMERS 2
-//#define PRESCALER 1
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
-stm32f4_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
+stm32_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
bool timers_initialized[NUM_HARDWARE_TIMERS] = { false };
@@ -115,4 +90,4 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F);
}
-#endif // ARDUINO_ARCH_STM32
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.h b/Marlin/src/HAL/HAL_STM32/timers.h
similarity index 79%
rename from Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.h
rename to Marlin/src/HAL/HAL_STM32/timers.h
index e92da9a5c8..aefe880b4e 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2017 Victor Perez
*
@@ -21,16 +21,12 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "../../inc/MarlinConfig.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -49,7 +45,7 @@
#define TEMP_TIMER 17
#endif
-#elif defined STM32F1xx
+#elif defined(STM32F1xx)
#define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals
@@ -61,19 +57,7 @@
#define TEMP_TIMER 2
#endif
-#elif defined STM32F4xx
-
- #define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals
-
- #ifndef STEP_TIMER
- #define STEP_TIMER 5
- #endif
-
- #ifndef TEMP_TIMER
- #define TEMP_TIMER 7
- #endif
-
-#elif defined STM32F7xx
+#elif defined(STM32F4xx) || defined(STM32F7xx)
#define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals
@@ -140,21 +124,21 @@ extern void Temp_Handler(stimer_t *htim);
#define HAL_STEP_TIMER_ISR() void Step_Handler(stimer_t *htim)
#define HAL_TEMP_TIMER_ISR() void Temp_Handler(stimer_t *htim)
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
-typedef stimer_t stm32f4_timer_t;
+typedef stimer_t stm32_timer_t;
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
-extern stm32f4_timer_t TimerHandle[];
+extern stm32_timer_t TimerHandle[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
void HAL_timer_enable_interrupt(const uint8_t timer_num);
diff --git a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp b/Marlin/src/HAL/HAL_STM32/watchdog.cpp
similarity index 74%
rename from Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/watchdog.cpp
index e47de64953..4defadaa77 100644
--- a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,21 +22,23 @@
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-#include "../../inc/MarlinConfig.h"
+#include "../../inc/MarlinConfigPre.h"
#if ENABLED(USE_WATCHDOG)
- #include "watchdog_STM32.h"
+ #include "../../inc/MarlinConfig.h"
+
+ #include "watchdog.h"
#include
void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout
- void watchdog_reset() {
+ void HAL_watchdog_refresh() {
IWatchdog.reload();
- #if PIN_EXISTS(LED)
+ #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
#endif // USE_WATCHDOG
-#endif // ARDUINO_ARCH_STM32
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.h b/Marlin/src/HAL/HAL_STM32/watchdog.h
similarity index 83%
rename from Marlin/src/HAL/HAL_STM32/watchdog_STM32.h
rename to Marlin/src/HAL/HAL_STM32/watchdog.h
index bd3598c0bb..6855016737 100644
--- a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,4 +22,4 @@
#pragma once
void watchdog_init();
-void watchdog_reset();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
index 89bece08bb..cba41dd3c2 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2017 Victor Perez
@@ -27,26 +27,18 @@
#ifdef __STM32F1__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-#include
#include "../../inc/MarlinConfig.h"
+#include "HAL.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
+#include
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
#define __I
#define __IO volatile
- typedef struct
- {
+ typedef struct {
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
__IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
@@ -70,13 +62,10 @@
__IO uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
} SCB_Type;
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
+
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
@@ -89,21 +78,22 @@
#define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */
#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
-#ifdef SERIAL_USB
+// ------------------------
+
+#if (defined(SERIAL_USB) && !defined(USE_USB_COMPOSITE))
USBSerial SerialUSB;
#endif
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
STM32ADC adc(ADC1);
-uint8_t adc_pins[] = {
+const uint8_t adc_pins[] = {
#if HAS_TEMP_ADC_0
TEMP_0_PIN,
#endif
@@ -131,6 +121,15 @@ uint8_t adc_pins[] = {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
FILWIDTH_PIN,
#endif
+ #if HAS_JOY_ADC_X
+ JOY_X_PIN,
+ #endif
+ #if HAS_JOY_ADC_Y
+ JOY_Y_PIN,
+ #endif
+ #if HAS_JOY_ADC_Z
+ JOY_Z_PIN,
+ #endif
};
enum TEMP_PINS : char {
@@ -161,19 +160,23 @@ enum TEMP_PINS : char {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
FILWIDTH,
#endif
- ADC_PIN_COUNT
+ #if HAS_JOY_ADC_X
+ JOY_X,
+ #endif
+ #if HAS_JOY_ADC_Y
+ JOY_Y,
+ #endif
+ #if HAS_JOY_ADC_Z
+ JOY_Z,
+ #endif
+ ADC_PIN_COUNT
};
uint16_t HAL_adc_results[ADC_PIN_COUNT];
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private functions
-// --------------------------------------------------------------------------
+// ------------------------
static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
uint32_t reg_value;
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */
@@ -186,9 +189,9 @@ static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
SCB->AIRCR = reg_value;
}
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
//
// Leave PA11/PA12 intact if USBSerial is not used
@@ -198,34 +201,63 @@ static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
#if SERIAL_PORT > 0
#if SERIAL_PORT2
#if SERIAL_PORT2 > 0
- void board_setup_usb(void) {}
+ void board_setup_usb() {}
#endif
#else
- void board_setup_usb(void) {}
+ void board_setup_usb() {}
#endif
#endif
} }
#endif
-void HAL_init(void) {
+void HAL_init() {
NVIC_SetPriorityGrouping(0x3);
+ #if PIN_EXISTS(LED)
+ OUT_WRITE(LED_PIN, LOW);
+ #endif
+ #ifdef USE_USB_COMPOSITE
+ MSC_SD_init();
+ #endif
+ #if PIN_EXISTS(USB_CONNECT)
+ OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING); // USB clear connection
+ delay(1000); // Give OS time to notice
+ OUT_WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
+ #endif
+}
+
+// HAL idle task
+void HAL_idletask() {
+ #ifdef USE_USB_COMPOSITE
+ #if ENABLED(SHARED_SD_CARD)
+ // If Marlin is using the SD card we need to lock it to prevent access from
+ // a PC via USB.
+ // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
+ // this will not reliably detect delete operations. To be safe we will lock
+ // the disk if Marlin has it mounted. Unfortunately there is currently no way
+ // to unmount the disk from the LCD menu.
+ // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
+ /* copy from lpc1768 framework, should be fixed later for process SHARED_SD_CARD*/
+ #endif
+ // process USB mass storage device class loop
+ MarlinMSC.loop();
+ #endif
}
/* VGPV Done with defines
// disable interrupts
-void cli(void) { noInterrupts(); }
+void cli() { noInterrupts(); }
// enable interrupts
-void sei(void) { interrupts(); }
+void sei() { interrupts(); }
*/
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
/**
* TODO: Check this and change or remove.
* currently returns 1 that's equal to poweron reset.
*/
-uint8_t HAL_get_reset_source(void) { return 1; }
+uint8_t HAL_get_reset_source() { return 1; }
void _delay_ms(const int delay_ms) { delay(delay_ms); }
@@ -261,15 +293,19 @@ extern "C" {
}
*/
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
// Init the AD in continuous capture mode
-void HAL_adc_init(void) {
+void HAL_adc_init() {
// configure the ADC
adc.calibrate();
- adc.setSampleRate(ADC_SMPR_41_5); // ?
- adc.setPins(adc_pins, ADC_PIN_COUNT);
+ #if F_CPU > 72000000
+ adc.setSampleRate(ADC_SMPR_71_5); // 71.5 ADC cycles
+ #else
+ adc.setSampleRate(ADC_SMPR_41_5); // 41.5 ADC cycles
+ #endif
+ adc.setPins((uint8_t *)adc_pins, ADC_PIN_COUNT);
adc.setDMA(HAL_adc_results, (uint16_t)ADC_PIN_COUNT, (uint32_t)(DMA_MINC_MODE | DMA_CIRC_MODE), nullptr);
adc.setScanMode();
adc.setContinuous();
@@ -304,6 +340,15 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
#if HAS_TEMP_ADC_5
case TEMP_5_PIN: pin_index = TEMP_5; break;
#endif
+ #if HAS_JOY_ADC_X
+ case JOY_X_PIN: pin_index = JOY_X; break;
+ #endif
+ #if HAS_JOY_ADC_Y
+ case JOY_Y_PIN: pin_index = JOY_Y; break;
+ #endif
+ #if HAS_JOY_ADC_Z
+ case JOY_Z_PIN: pin_index = JOY_Z; break;
+ #endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
case FILWIDTH_PIN: pin_index = FILWIDTH; break;
#endif
@@ -311,6 +356,19 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
HAL_adc_result = (HAL_adc_results[(int)pin_index] >> 2) & 0x3FF; // shift to get 10 bits only.
}
-uint16_t HAL_adc_get_result(void) { return HAL_adc_result; }
+uint16_t HAL_adc_get_result() { return HAL_adc_result; }
+
+uint16_t analogRead(pin_t pin) {
+ const bool is_analog = _GET_MODE(pin) == GPIO_INPUT_ANALOG;
+ return is_analog ? analogRead(uint8_t(pin)) : 0;
+}
+
+// Wrapper to maple unprotected analogWrite
+void analogWrite(pin_t pin, int pwm_val8) {
+ if (PWM_PIN(pin))
+ analogWrite(uint8_t(pin), pwm_val8);
+}
+
+void flashFirmware(int16_t value) { nvic_sys_reset(); }
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.h b/Marlin/src/HAL/HAL_STM32F1/HAL.h
index f47c38a163..f1017c82df 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL.h
+++ b/Marlin/src/HAL/HAL_STM32F1/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2017 Victor Perez
@@ -28,43 +28,41 @@
#define CPU_32_BIT
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../core/macros.h"
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F1.h"
-#include "watchdog_STM32F1.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "HAL_timers_STM32F1.h"
+#include "timers.h"
#include
#include
#include "../../inc/MarlinConfigPre.h"
-// --------------------------------------------------------------------------
+#ifdef USE_USB_COMPOSITE
+ #include "msc_sd.h"
+#endif
+
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#ifdef SERIAL_USB
- #define UsbSerial Serial
+ #ifndef USE_USB_COMPOSITE
+ #define UsbSerial Serial
+ #else
+ #define UsbSerial MarlinCompositeSerial
+ #endif
#define MSerial1 Serial1
#define MSerial2 Serial2
#define MSerial3 Serial3
#define MSerial4 Serial4
#define MSerial5 Serial5
#else
- extern USBSerial SerialUSB;
- #define UsbSerial SerialUSB
#define MSerial1 Serial
#define MSerial2 Serial1
#define MSerial3 Serial2
@@ -117,9 +115,10 @@
#define NUM_SERIAL 1
#endif
-// Use HAL_init() to set interrupt grouping.
-#define HAL_INIT
+// Set interrupt grouping for this MCU
void HAL_init();
+#define HAL_IDLETASK 1
+void HAL_idletask();
/**
* TODO: review this to return 1 for pins that are not analog input
@@ -157,22 +156,22 @@ void HAL_init();
#define RST_SOFTWARE 32
#define RST_BACKUP 64
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef int8_t pin_t;
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
-/** result of last ADC conversion */
+// Result of last ADC conversion
extern uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// Disable interrupts
#define cli() noInterrupts()
@@ -183,21 +182,25 @@ extern uint16_t HAL_adc_result;
// Memory related
#define __bss_end __bss_end__
-/** clear reset reason */
-void HAL_clear_reset_source(void);
+// Clear reset reason
+void HAL_clear_reset_source();
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
+// Reset reason
+uint8_t HAL_get_reset_source();
void _delay_ms(const int delay);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+
/*
extern "C" {
- int freeMemory(void);
+ int freeMemory();
}
*/
extern "C" char* _sbrk(int incr);
+
/*
static int freeMemory() {
volatile int top;
@@ -206,9 +209,6 @@ static int freeMemory() {
}
*/
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-function"
-
static int freeMemory() {
volatile char top;
return &top - reinterpret_cast(_sbrk(0));
@@ -216,17 +216,6 @@ static int freeMemory() {
#pragma GCC diagnostic pop
-//
-// SPI: Extended functions which take a channel number (hardware SPI only)
-//
-
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
-
//
// EEPROM
//
@@ -246,14 +235,17 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT_ANALOG);
-void HAL_adc_init(void);
+void HAL_adc_init();
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
+
+uint16_t analogRead(pin_t pin); // need HAL_ANALOG_SELECT() first
+void analogWrite(pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
@@ -261,3 +253,6 @@ uint16_t HAL_adc_get_result(void);
#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
#define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
+
+#define PLATFORM_M997_SUPPORT
+void flashFirmware(int16_t value);
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_SPI.cpp
similarity index 56%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/HAL_SPI.cpp
index cbc6c7fe1a..9f3f34239d 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/HAL_SPI.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
/**
* Software SPI functions originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
+ * Copyright (c) 2009 by William Greiman
*/
/**
@@ -32,39 +32,25 @@
#ifdef __STM32F1__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-#include "../shared/HAL_SPI.h"
-#include "pins_arduino.h"
-#include "spi_pins.h"
-#include "../../core/macros.h"
+#include "../../inc/MarlinConfig.h"
#include
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-static SPISettings spiConfig;
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if ENABLED(SOFTWARE_SPI)
- // --------------------------------------------------------------------------
+ // ------------------------
// Software SPI
- // --------------------------------------------------------------------------
+ // ------------------------
#error "Software SPI not supported for STM32F1. Use hardware SPI."
#else
-// --------------------------------------------------------------------------
+// ------------------------
// Hardware SPI
-// --------------------------------------------------------------------------
+// ------------------------
/**
* VGPV SPI speed start and F_CPU/2, by default 72/2 = 36Mhz
@@ -78,11 +64,9 @@ static SPISettings spiConfig;
* @details Only configures SS pin since libmaple creates and initialize the SPI object
*/
void spiBegin() {
- #if !PIN_EXISTS(SS)
- #error "SS_PIN not defined!"
+ #if PIN_EXISTS(SS)
+ OUT_WRITE(SS_PIN, HIGH);
#endif
- SET_OUTPUT(SS_PIN);
- WRITE(SS_PIN, HIGH);
}
/**
@@ -94,18 +78,31 @@ void spiBegin() {
* @details
*/
void spiInit(uint8_t spiRate) {
+ /**
+ * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
+ * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
+ * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
+ */
+ #if SPI_DEVICE == 1
+ #define SPI_CLOCK_MAX SPI_CLOCK_DIV4
+ #else
+ #define SPI_CLOCK_MAX SPI_CLOCK_DIV2
+ #endif
uint8_t clock;
switch (spiRate) {
- case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break;
+ case SPI_FULL_SPEED: clock = SPI_CLOCK_MAX ; break;
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break;
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
- default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
+ default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
}
- spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
+ SPI.setModule(SPI_DEVICE);
SPI.begin();
+ SPI.setClockDivider(clock);
+ SPI.setBitOrder(MSBFIRST);
+ SPI.setDataMode(SPI_MODE0);
}
/**
@@ -115,10 +112,8 @@ void spiInit(uint8_t spiRate) {
*
* @details
*/
-uint8_t spiRec(void) {
- SPI.beginTransaction(spiConfig);
- uint8_t returnByte = SPI.transfer(0xFF);
- SPI.endTransaction();
+uint8_t spiRec() {
+ uint8_t returnByte = SPI.transfer(ff);
return returnByte;
}
@@ -132,9 +127,7 @@ uint8_t spiRec(void) {
* @details Uses DMA
*/
void spiRead(uint8_t* buf, uint16_t nbyte) {
- SPI.beginTransaction(spiConfig);
SPI.dmaTransfer(0, const_cast(buf), nbyte);
- SPI.endTransaction();
}
/**
@@ -145,9 +138,7 @@ void spiRead(uint8_t* buf, uint16_t nbyte) {
* @details
*/
void spiSend(uint8_t b) {
- SPI.beginTransaction(spiConfig);
SPI.send(b);
- SPI.endTransaction();
}
/**
@@ -159,27 +150,25 @@ void spiSend(uint8_t b) {
* @details Use DMA
*/
void spiSendBlock(uint8_t token, const uint8_t* buf) {
- SPI.beginTransaction(spiConfig);
SPI.send(token);
SPI.dmaSend(const_cast(buf), 512);
- SPI.endTransaction();
}
-/**
- * @brief Begin SPI transaction, set clock, bit order, data mode
- *
- * @param spiClock Clock setting
- * @param bitOrder Bit Order setting
- * @param dataMode Data Mode setting
- * @return Nothing
- *
- * @details Uses an SPI Config via SPISettings
- */
-void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
- spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
- SPI.beginTransaction(spiConfig);
+#if ENABLED(SPI_EEPROM)
+
+// Read single byte from specified SPI channel
+uint8_t spiRec(uint32_t chan) { return SPI.transfer(ff); }
+
+// Write single byte to specified SPI channel
+void spiSend(uint32_t chan, byte b) { SPI.send(b); }
+
+// Write buffer to specified SPI channel
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n) {
+ for (size_t p = 0; p < n; p++) spiSend(chan, buf[p]);
}
+#endif // SPI_EEPROM
+
#endif // SOFTWARE_SPI
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp
deleted file mode 100644
index ef81db69f3..0000000000
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#ifdef __STM32F1__
-
-#include "../../inc/MarlinConfig.h"
-
-#if HAS_SERVOS
-
-uint8_t ServoCount = 0;
-
-#include "HAL_Servo_STM32F1.h"
-
-//#include "Servo.h"
-
-#include
-#include
-#include
-#include
-
-/**
- * 20 millisecond period config. For a 1-based prescaler,
- *
- * (prescaler * overflow / CYC_MSEC) msec = 1 timer cycle = 20 msec
- * => prescaler * overflow = 20 * CYC_MSEC
- *
- * This uses the smallest prescaler that allows an overflow < 2^16.
- */
-#define MAX_OVERFLOW ((1 << 16) - 1)
-#define CYC_MSEC (1000 * CYCLES_PER_MICROSECOND)
-#define TAU_MSEC 20
-#define TAU_USEC (TAU_MSEC * 1000)
-#define TAU_CYC (TAU_MSEC * CYC_MSEC)
-#define SERVO_PRESCALER (TAU_CYC / MAX_OVERFLOW + 1)
-#define SERVO_OVERFLOW ((uint16_t)round((double)TAU_CYC / SERVO_PRESCALER))
-
-// Unit conversions
-#define US_TO_COMPARE(us) ((uint16_t)map((us), 0, TAU_USEC, 0, SERVO_OVERFLOW))
-#define COMPARE_TO_US(c) ((uint32_t)map((c), 0, SERVO_OVERFLOW, 0, TAU_USEC))
-#define ANGLE_TO_US(a) ((uint16_t)(map((a), this->minAngle, this->maxAngle, \
- SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW)))
-#define US_TO_ANGLE(us) ((int16_t)(map((us), SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW, \
- this->minAngle, this->maxAngle)))
-
-libServo::libServo() {
- this->servoIndex = ServoCount < MAX_SERVOS ? ServoCount++ : INVALID_SERVO;
-}
-
-bool libServo::attach(const int32_t pin, const int32_t minAngle, const int32_t maxAngle) {
- if (this->servoIndex >= MAX_SERVOS) return false;
- if (!PWM_PIN(pin)) return false;
-
- this->minAngle = minAngle;
- this->maxAngle = maxAngle;
-
- timer_dev *tdev = PIN_MAP[pin].timer_device;
- uint8_t tchan = PIN_MAP[pin].timer_channel;
-
- pinMode(pin, PWM);
- pwmWrite(pin, 0);
-
- timer_pause(tdev);
- timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
- timer_set_reload(tdev, SERVO_OVERFLOW);
- timer_generate_update(tdev);
- timer_resume(tdev);
-
- this->pin = pin; // set attached()
-
- return true;
-}
-
-bool libServo::detach() {
- if (!this->attached()) return false;
- pwmWrite(this->pin, 0);
- return true;
-}
-
-int32_t libServo::read() const {
- if (this->attached()) {
- timer_dev *tdev = PIN_MAP[this->pin].timer_device;
- uint8_t tchan = PIN_MAP[this->pin].timer_channel;
- return US_TO_ANGLE(COMPARE_TO_US(timer_get_compare(tdev, tchan)));
- }
- return 0;
-}
-
-void libServo::move(const int32_t value) {
- constexpr uint16_t servo_delay[] = SERVO_DELAY;
- static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
-
- if (this->attached()) {
- pwmWrite(this->pin, US_TO_COMPARE(ANGLE_TO_US(constrain(value, this->minAngle, this->maxAngle))));
- safe_delay(servo_delay[this->servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
- #endif
- }
-}
-#endif // HAS_SERVOS
-
-#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/README.md b/Marlin/src/HAL/HAL_STM32F1/README.md
index 7defdc8749..b5bd5141fb 100644
--- a/Marlin/src/HAL/HAL_STM32F1/README.md
+++ b/Marlin/src/HAL/HAL_STM32F1/README.md
@@ -1,25 +1,11 @@
-# This HAL is for STM32F103 boards used with libmaple/stm32duino Arduino core.
+# STM32F1
-# This HAL is in development. Currently has been tested in Malyan M200 (103CBT6), Chitu 3d (103ZET6), and custom boards(103VET6).
+This HAL is for STM32F103 boards used with [Arduino STM32](https://github.com/rogerclarkmelbourne/Arduino_STM32) framework.
-### The stm32 core needs a modification in the file util.h to avoid conflict with Marlin macros for Debug.
-Since only 1 file needs change in the stm32duino core, it's preferable over making changes to Marlin.
-
-
-After these lines:
-<>
-#else
-#define ASSERT_FAULT(exp) (void)((0))
-#endif
-<>
+Currently has been tested in Malyan M200 (103CBT6), SKRmini (103RCT6), Chitu 3d (103ZET6), and various 103VET6 boards.
### Main developers:
-Victorpv
-xC000005
-
-
-### Most up to date repository for this HAL:
-https://github.com/victorpv/Marlin/tree/bugfix-2.0.x
-
-PRs should only be sent to Marlin bugfix-2.0.x branch once tested in printing so not to introduce new bugs.
-For testing/dev, you can submit to the above branch
+- Victorpv
+- xC000005
+- thisiskeithb
+- tpruvot
diff --git a/Marlin/src/HAL/HAL_STM32F1/SPI.cpp b/Marlin/src/HAL/HAL_STM32F1/SPI.cpp
new file mode 100644
index 0000000000..101b42a53a
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SPI.cpp
@@ -0,0 +1,715 @@
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *****************************************************************************/
+
+/**
+ * @author Marti Bolivar
+ * @brief Wirish SPI implementation.
+ */
+
+#ifdef __STM32F1__
+
+#include
+
+#include
+#include
+#include
+
+#include
+#include
+
+/** Time in ms for DMA receive timeout */
+#define DMA_TIMEOUT 100
+
+#if CYCLES_PER_MICROSECOND != 72
+ #warning "Unexpected clock speed; SPI frequency calculation will be incorrect"
+#endif
+
+struct spi_pins { uint8_t nss, sck, miso, mosi; };
+
+static const spi_pins* dev_to_spi_pins(spi_dev *dev);
+static void configure_gpios(spi_dev *dev, bool as_master);
+static spi_baud_rate determine_baud_rate(spi_dev *dev, uint32_t freq);
+
+#if (BOARD_NR_SPI >= 3) && !defined(STM32_HIGH_DENSITY)
+ #error "The SPI library is misconfigured: 3 SPI ports only available on high density STM32 devices"
+#endif
+
+static const spi_pins board_spi_pins[] __FLASH__ = {
+ #if BOARD_NR_SPI >= 1
+ { BOARD_SPI1_NSS_PIN,
+ BOARD_SPI1_SCK_PIN,
+ BOARD_SPI1_MISO_PIN,
+ BOARD_SPI1_MOSI_PIN },
+ #endif
+ #if BOARD_NR_SPI >= 2
+ { BOARD_SPI2_NSS_PIN,
+ BOARD_SPI2_SCK_PIN,
+ BOARD_SPI2_MISO_PIN,
+ BOARD_SPI2_MOSI_PIN },
+ #endif
+ #if BOARD_NR_SPI >= 3
+ { BOARD_SPI3_NSS_PIN,
+ BOARD_SPI3_SCK_PIN,
+ BOARD_SPI3_MISO_PIN,
+ BOARD_SPI3_MOSI_PIN },
+ #endif
+};
+
+#if BOARD_NR_SPI >= 1
+ static void *_spi1_this;
+#endif
+#if BOARD_NR_SPI >= 2
+ static void *_spi2_this;
+#endif
+#if BOARD_NR_SPI >= 3
+ static void *_spi3_this;
+#endif
+
+/**
+ * Constructor
+ */
+SPIClass::SPIClass(uint32_t spi_num) {
+ _currentSetting = &_settings[spi_num - 1]; // SPI channels are called 1 2 and 3 but the array is zero indexed
+
+ switch (spi_num) {
+ #if BOARD_NR_SPI >= 1
+ case 1:
+ _currentSetting->spi_d = SPI1;
+ _spi1_this = (void*)this;
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case 2:
+ _currentSetting->spi_d = SPI2;
+ _spi2_this = (void*)this;
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case 3:
+ _currentSetting->spi_d = SPI3;
+ _spi3_this = (void*)this;
+ break;
+ #endif
+ default: ASSERT(0);
+ }
+
+ // Init things specific to each SPI device
+ // clock divider setup is a bit of hack, and needs to be improved at a later date.
+ #if BOARD_NR_SPI >= 1
+ _settings[0].spi_d = SPI1;
+ _settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
+ _settings[0].spiDmaDev = DMA1;
+ _settings[0].spiTxDmaChannel = DMA_CH3;
+ _settings[0].spiRxDmaChannel = DMA_CH2;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ _settings[1].spi_d = SPI2;
+ _settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
+ _settings[1].spiDmaDev = DMA1;
+ _settings[1].spiTxDmaChannel = DMA_CH5;
+ _settings[1].spiRxDmaChannel = DMA_CH4;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ _settings[2].spi_d = SPI3;
+ _settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
+ _settings[2].spiDmaDev = DMA2;
+ _settings[2].spiTxDmaChannel = DMA_CH2;
+ _settings[2].spiRxDmaChannel = DMA_CH1;
+ #endif
+
+ // added for DMA callbacks.
+ _currentSetting->state = SPI_STATE_IDLE;
+}
+
+/**
+ * Set up/tear down
+ */
+void SPIClass::updateSettings() {
+ uint32_t flags = ((_currentSetting->bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB) | _currentSetting->dataSize | SPI_SW_SLAVE | SPI_SOFT_SS);
+ spi_master_enable(_currentSetting->spi_d, (spi_baud_rate)_currentSetting->clockDivider, (spi_mode)_currentSetting->dataMode, flags);
+}
+
+void SPIClass::begin() {
+ spi_init(_currentSetting->spi_d);
+ configure_gpios(_currentSetting->spi_d, 1);
+ updateSettings();
+ // added for DMA callbacks.
+ _currentSetting->state = SPI_STATE_READY;
+}
+
+void SPIClass::beginSlave() {
+ spi_init(_currentSetting->spi_d);
+ configure_gpios(_currentSetting->spi_d, 0);
+ uint32_t flags = ((_currentSetting->bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB) | _currentSetting->dataSize);
+ spi_slave_enable(_currentSetting->spi_d, (spi_mode)_currentSetting->dataMode, flags);
+ // added for DMA callbacks.
+ _currentSetting->state = SPI_STATE_READY;
+}
+
+void SPIClass::end() {
+ if (!spi_is_enabled(_currentSetting->spi_d)) return;
+
+ // Follows RM0008's sequence for disabling a SPI in master/slave
+ // full duplex mode.
+ while (spi_is_rx_nonempty(_currentSetting->spi_d)) {
+ // FIXME [0.1.0] remove this once you have an interrupt based driver
+ volatile uint16_t rx __attribute__((unused)) = spi_rx_reg(_currentSetting->spi_d);
+ }
+ waitSpiTxEnd(_currentSetting->spi_d);
+
+ spi_peripheral_disable(_currentSetting->spi_d);
+ // added for DMA callbacks.
+ // Need to add unsetting the callbacks for the DMA channels.
+ _currentSetting->state = SPI_STATE_IDLE;
+}
+
+/* Roger Clark added 3 functions */
+void SPIClass::setClockDivider(uint32_t clockDivider) {
+ _currentSetting->clockDivider = clockDivider;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_BR);
+ _currentSetting->spi_d->regs->CR1 = cr1 | (clockDivider & SPI_CR1_BR);
+}
+
+void SPIClass::setBitOrder(BitOrder bitOrder) {
+ _currentSetting->bitOrder = bitOrder;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_LSBFIRST);
+ if (bitOrder == LSBFIRST) cr1 |= SPI_CR1_LSBFIRST;
+ _currentSetting->spi_d->regs->CR1 = cr1;
+}
+
+/**
+ * Victor Perez. Added to test changing datasize from 8 to 16 bit modes on the fly.
+ * Input parameter should be SPI_CR1_DFF set to 0 or 1 on a 32bit word.
+ */
+void SPIClass::setDataSize(uint32_t datasize) {
+ _currentSetting->dataSize = datasize;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_DFF);
+ uint8_t en = spi_is_enabled(_currentSetting->spi_d);
+ spi_peripheral_disable(_currentSetting->spi_d);
+ _currentSetting->spi_d->regs->CR1 = cr1 | (datasize & SPI_CR1_DFF) | en;
+}
+
+void SPIClass::setDataMode(uint8_t dataMode) {
+ /**
+ * Notes:
+ * As far as we know the AVR numbers for dataMode match the numbers required by the STM32.
+ * From the AVR doc http://www.atmel.com/images/doc2585.pdf section 2.4
+ *
+ * SPI Mode CPOL CPHA Shift SCK-edge Capture SCK-edge
+ * 0 0 0 Falling Rising
+ * 1 0 1 Rising Falling
+ * 2 1 0 Rising Falling
+ * 3 1 1 Falling Rising
+ *
+ * On the STM32 it appears to be
+ *
+ * bit 1 - CPOL : Clock polarity
+ * (This bit should not be changed when communication is ongoing)
+ * 0 : CLK to 0 when idle
+ * 1 : CLK to 1 when idle
+ *
+ * bit 0 - CPHA : Clock phase
+ * (This bit should not be changed when communication is ongoing)
+ * 0 : The first clock transition is the first data capture edge
+ * 1 : The second clock transition is the first data capture edge
+ *
+ * If someone finds this is not the case or sees a logic error with this let me know ;-)
+ */
+ _currentSetting->dataMode = dataMode;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_CPOL|SPI_CR1_CPHA);
+ _currentSetting->spi_d->regs->CR1 = cr1 | (dataMode & (SPI_CR1_CPOL|SPI_CR1_CPHA));
+}
+
+void SPIClass::beginTransaction(uint8_t pin, SPISettings settings) {
+ setBitOrder(settings.bitOrder);
+ setDataMode(settings.dataMode);
+ setDataSize(settings.dataSize);
+ setClockDivider(determine_baud_rate(_currentSetting->spi_d, settings.clock));
+ begin();
+}
+
+void SPIClass::beginTransactionSlave(SPISettings settings) {
+ setBitOrder(settings.bitOrder);
+ setDataMode(settings.dataMode);
+ setDataSize(settings.dataSize);
+ beginSlave();
+}
+
+void SPIClass::endTransaction() { }
+
+/**
+ * I/O
+ */
+
+uint16_t SPIClass::read() {
+ while (!spi_is_rx_nonempty(_currentSetting->spi_d)) { /* nada */ }
+ return (uint16)spi_rx_reg(_currentSetting->spi_d);
+}
+
+void SPIClass::read(uint8_t *buf, uint32_t len) {
+ if (len == 0) return;
+ spi_rx_reg(_currentSetting->spi_d); // clear the RX buffer in case a byte is waiting on it.
+ spi_reg_map * regs = _currentSetting->spi_d->regs;
+ // start sequence: write byte 0
+ regs->DR = 0x00FF; // write the first byte
+ // main loop
+ while (--len) {
+ while(!(regs->SR & SPI_SR_TXE)) { /* nada */ } // wait for TXE flag
+ noInterrupts(); // go atomic level - avoid interrupts to surely get the previously received data
+ regs->DR = 0x00FF; // write the next data item to be transmitted into the SPI_DR register. This clears the TXE flag.
+ while (!(regs->SR & SPI_SR_RXNE)) { /* nada */ } // wait till data is available in the DR register
+ *buf++ = (uint8)(regs->DR); // read and store the received byte. This clears the RXNE flag.
+ interrupts(); // let systick do its job
+ }
+ // read remaining last byte
+ while (!(regs->SR & SPI_SR_RXNE)) { /* nada */ } // wait till data is available in the Rx register
+ *buf++ = (uint8)(regs->DR); // read and store the received byte
+}
+
+void SPIClass::write(uint16_t data) {
+ /* Added for 16bit data Victor Perez. Roger Clark
+ * Improved speed by just directly writing the single byte to the SPI data reg and wait for completion,
+ * by taking the Tx code from transfer(byte)
+ * This almost doubles the speed of this function.
+ */
+ spi_tx_reg(_currentSetting->spi_d, data); // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
+ waitSpiTxEnd(_currentSetting->spi_d);
+}
+
+void SPIClass::write16(uint16_t data) {
+ // Added by stevestrong: write two consecutive bytes in 8 bit mode (DFF=0)
+ spi_tx_reg(_currentSetting->spi_d, data>>8); // write high byte
+ while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // Wait until TXE=1
+ spi_tx_reg(_currentSetting->spi_d, data); // write low byte
+ waitSpiTxEnd(_currentSetting->spi_d);
+}
+
+void SPIClass::write(uint16_t data, uint32_t n) {
+ // Added by stevstrong: Repeatedly send same data by the specified number of times
+ spi_reg_map * regs = _currentSetting->spi_d->regs;
+ while (n--) {
+ regs->DR = data; // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
+ while (!(regs->SR & SPI_SR_TXE)) { /* nada */ } // wait till Tx empty
+ }
+ while (regs->SR & SPI_SR_BSY) { /* nada */ } // wait until BSY=0 before returning
+}
+
+void SPIClass::write(const void *data, uint32_t length) {
+ spi_dev * spi_d = _currentSetting->spi_d;
+ spi_tx(spi_d, data, length); // data can be array of bytes or words
+ waitSpiTxEnd(spi_d);
+}
+
+uint8_t SPIClass::transfer(uint8_t byte) const {
+ spi_dev * spi_d = _currentSetting->spi_d;
+ spi_rx_reg(spi_d); // read any previous data
+ spi_tx_reg(spi_d, byte); // Write the data item to be transmitted into the SPI_DR register
+ waitSpiTxEnd(spi_d);
+ return (uint8)spi_rx_reg(spi_d); // "... and read the last received data."
+}
+
+uint16_t SPIClass::transfer16(uint16_t data) const {
+ // Modified by stevestrong: write & read two consecutive bytes in 8 bit mode (DFF=0)
+ // This is more effective than two distinct byte transfers
+ spi_dev * spi_d = _currentSetting->spi_d;
+ spi_rx_reg(spi_d); // read any previous data
+ spi_tx_reg(spi_d, data>>8); // write high byte
+ waitSpiTxEnd(spi_d); // wait until TXE=1 and then wait until BSY=0
+ uint16_t ret = spi_rx_reg(spi_d)<<8; // read and shift high byte
+ spi_tx_reg(spi_d, data); // write low byte
+ waitSpiTxEnd(spi_d); // wait until TXE=1 and then wait until BSY=0
+ ret += spi_rx_reg(spi_d); // read low byte
+ return ret;
+}
+
+/**
+ * Roger Clark and Victor Perez, 2015
+ * Performs a DMA SPI transfer with at least a receive buffer.
+ * If a TX buffer is not provided, FF is sent over and over for the lenght of the transfer.
+ * On exit TX buffer is not modified, and RX buffer cotains the received data.
+ * Still in progress.
+ */
+void SPIClass::dmaTransferSet(const void *transmitBuf, void *receiveBuf) {
+ dma_init(_currentSetting->spiDmaDev);
+ //spi_rx_dma_enable(_currentSetting->spi_d);
+ //spi_tx_dma_enable(_currentSetting->spi_d);
+ dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, receiveBuf, dma_bit_size, (DMA_MINC_MODE | DMA_TRNS_CMPLT ));// receive buffer DMA
+ if (!transmitBuf) {
+ transmitBuf = &ff;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, (volatile void*)transmitBuf, dma_bit_size, (DMA_FROM_MEM));// Transmit FF repeatedly
+ }
+ else {
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, (volatile void*)transmitBuf, dma_bit_size, (DMA_MINC_MODE | DMA_FROM_MEM ));// Transmit buffer DMA
+ }
+ dma_set_priority(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, DMA_PRIORITY_LOW);
+ dma_set_priority(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, DMA_PRIORITY_VERY_HIGH);
+}
+
+uint8_t SPIClass::dmaTransferRepeat(uint16_t length) {
+ if (length == 0) return 0;
+ if (spi_is_rx_nonempty(_currentSetting->spi_d) == 1) spi_rx_reg(_currentSetting->spi_d);
+ _currentSetting->state = SPI_STATE_TRANSFER;
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, length);
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);// enable receive
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
+ spi_rx_dma_enable(_currentSetting->spi_d);
+ spi_tx_dma_enable(_currentSetting->spi_d);
+ if (_currentSetting->receiveCallback)
+ return 0;
+
+ //uint32_t m = millis();
+ uint8_t b = 0;
+ uint32_t m = millis();
+ while (!(dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)) {
+ // Avoid interrupts and just loop waiting for the flag to be set.
+ if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
+ }
+
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ spi_rx_dma_disable(_currentSetting->spi_d);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ _currentSetting->state = SPI_STATE_READY;
+ return b;
+}
+
+/**
+ * Roger Clark and Victor Perez, 2015
+ * Performs a DMA SPI transfer with at least a receive buffer.
+ * If a TX buffer is not provided, FF is sent over and over for the length of the transfer.
+ * On exit TX buffer is not modified, and RX buffer contains the received data.
+ * Still in progress.
+ */
+uint8_t SPIClass::dmaTransfer(const void *transmitBuf, void *receiveBuf, uint16_t length) {
+ dmaTransferSet(transmitBuf, receiveBuf);
+ return dmaTransferRepeat(length);
+}
+
+/**
+ * Roger Clark and Victor Perez, 2015
+ * Performs a DMA SPI send using a TX buffer.
+ * On exit TX buffer is not modified.
+ * Still in progress.
+ * 2016 - stevstrong - reworked to automatically detect bit size from SPI setting
+ */
+void SPIClass::dmaSendSet(const void * transmitBuf, bool minc) {
+ uint32_t flags = ( (DMA_MINC_MODE*minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
+ dma_init(_currentSetting->spiDmaDev);
+ dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, dma_bit_size,
+ (volatile void*)transmitBuf, dma_bit_size, flags);// Transmit buffer DMA
+ dma_set_priority(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, DMA_PRIORITY_LOW);
+}
+
+uint8_t SPIClass::dmaSendRepeat(uint16_t length) {
+ if (length == 0) return 0;
+
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
+ _currentSetting->state = SPI_STATE_TRANSMIT;
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel); // enable transmit
+ spi_tx_dma_enable(_currentSetting->spi_d);
+ if (_currentSetting->transmitCallback) return 0;
+
+ uint32_t m = millis();
+ uint8_t b = 0;
+ while (!(dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)) {
+ // Avoid interrupts and just loop waiting for the flag to be set.
+ if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
+ }
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ _currentSetting->state = SPI_STATE_READY;
+ return b;
+}
+
+uint8_t SPIClass::dmaSend(const void * transmitBuf, uint16_t length, bool minc) {
+ dmaSendSet(transmitBuf, minc);
+ return dmaSendRepeat(length);
+}
+
+uint8_t SPIClass::dmaSendAsync(const void * transmitBuf, uint16_t length, bool minc) {
+ uint8_t b = 0;
+
+ if (_currentSetting->state != SPI_STATE_READY) {
+ uint32_t m = millis();
+ while (!(dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)) {
+ //Avoid interrupts and just loop waiting for the flag to be set.
+ //delayMicroseconds(10);
+ if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
+ }
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ _currentSetting->state = SPI_STATE_READY;
+ }
+
+ if (length == 0) return 0;
+ uint32_t flags = ( (DMA_MINC_MODE*minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
+
+ dma_init(_currentSetting->spiDmaDev);
+ // TX
+ dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, (volatile void*)transmitBuf, dma_bit_size, flags);// Transmit buffer DMA
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
+ spi_tx_dma_enable(_currentSetting->spi_d);
+
+ _currentSetting->state = SPI_STATE_TRANSMIT;
+ return b;
+}
+
+
+/**
+ * New functions added to manage callbacks.
+ * Victor Perez 2017
+ */
+void SPIClass::onReceive(void(*callback)()) {
+ _currentSetting->receiveCallback = callback;
+ if (callback) {
+ switch (_currentSetting->spi_d->clk_id) {
+ #if BOARD_NR_SPI >= 1
+ case RCC_SPI1:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi1EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case RCC_SPI2:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi2EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case RCC_SPI3:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi3EventCallback);
+ break;
+ #endif
+ default:
+ ASSERT(0);
+ }
+ }
+ else {
+ dma_detach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ }
+}
+
+void SPIClass::onTransmit(void(*callback)()) {
+ _currentSetting->transmitCallback = callback;
+ if (callback) {
+ switch (_currentSetting->spi_d->clk_id) {
+ #if BOARD_NR_SPI >= 1
+ case RCC_SPI1:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi1EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case RCC_SPI2:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi2EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case RCC_SPI3:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi3EventCallback);
+ break;
+ #endif
+ default:
+ ASSERT(0);
+ }
+ }
+ else {
+ dma_detach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ }
+}
+
+/**
+ * TODO: check if better to first call the customer code, next disable the DMA requests.
+ * Also see if we need to check whether callbacks are set or not, may be better to be checked
+ * during the initial setup and only set the callback to EventCallback if they are set.
+ */
+void SPIClass::EventCallback() {
+ waitSpiTxEnd(_currentSetting->spi_d);
+ switch (_currentSetting->state) {
+ case SPI_STATE_TRANSFER:
+ while (spi_is_rx_nonempty(_currentSetting->spi_d)) { /* nada */ }
+ _currentSetting->state = SPI_STATE_READY;
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ spi_rx_dma_disable(_currentSetting->spi_d);
+ //dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ //dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ if (_currentSetting->receiveCallback)
+ _currentSetting->receiveCallback();
+ break;
+ case SPI_STATE_TRANSMIT:
+ _currentSetting->state = SPI_STATE_READY;
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ //dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ if (_currentSetting->transmitCallback)
+ _currentSetting->transmitCallback();
+ break;
+ default:
+ break;
+ }
+}
+
+void SPIClass::attachInterrupt() {
+ // Should be enableInterrupt()
+}
+
+void SPIClass::detachInterrupt() {
+ // Should be disableInterrupt()
+}
+
+/**
+ * Pin accessors
+ */
+
+uint8_t SPIClass::misoPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->miso;
+}
+
+uint8_t SPIClass::mosiPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->mosi;
+}
+
+uint8_t SPIClass::sckPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->sck;
+}
+
+uint8_t SPIClass::nssPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->nss;
+}
+
+/**
+ * Deprecated functions
+ */
+uint8_t SPIClass::send(uint8_t data) { write(data); return 1; }
+uint8_t SPIClass::send(uint8_t *buf, uint32_t len) { write(buf, len); return len; }
+uint8_t SPIClass::recv() { return read(); }
+
+/**
+ * DMA call back functions, one per port.
+ */
+#if BOARD_NR_SPI >= 1
+ void SPIClass::_spi1EventCallback() {
+ reinterpret_cast(_spi1_this)->EventCallback();
+ }
+#endif
+#if BOARD_NR_SPI >= 2
+ void SPIClass::_spi2EventCallback() {
+ reinterpret_cast(_spi2_this)->EventCallback();
+ }
+#endif
+#if BOARD_NR_SPI >= 3
+ void SPIClass::_spi3EventCallback() {
+ reinterpret_cast(_spi3_this)->EventCallback();
+ }
+#endif
+
+/**
+ * Auxiliary functions
+ */
+static const spi_pins* dev_to_spi_pins(spi_dev *dev) {
+ switch (dev->clk_id) {
+ #if BOARD_NR_SPI >= 1
+ case RCC_SPI1: return board_spi_pins;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case RCC_SPI2: return board_spi_pins + 1;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case RCC_SPI3: return board_spi_pins + 2;
+ #endif
+ default: return NULL;
+ }
+}
+
+static void disable_pwm(const stm32_pin_info *i) {
+ if (i->timer_device)
+ timer_set_mode(i->timer_device, i->timer_channel, TIMER_DISABLED);
+}
+
+static void configure_gpios(spi_dev *dev, bool as_master) {
+ const spi_pins *pins = dev_to_spi_pins(dev);
+ if (!pins) return;
+
+ const stm32_pin_info *nssi = &PIN_MAP[pins->nss],
+ *scki = &PIN_MAP[pins->sck],
+ *misoi = &PIN_MAP[pins->miso],
+ *mosii = &PIN_MAP[pins->mosi];
+
+ disable_pwm(nssi);
+ disable_pwm(scki);
+ disable_pwm(misoi);
+ disable_pwm(mosii);
+
+ spi_config_gpios(dev, as_master, nssi->gpio_device, nssi->gpio_bit,
+ scki->gpio_device, scki->gpio_bit, misoi->gpio_bit,
+ mosii->gpio_bit);
+}
+
+static const spi_baud_rate baud_rates[8] __FLASH__ = {
+ SPI_BAUD_PCLK_DIV_2,
+ SPI_BAUD_PCLK_DIV_4,
+ SPI_BAUD_PCLK_DIV_8,
+ SPI_BAUD_PCLK_DIV_16,
+ SPI_BAUD_PCLK_DIV_32,
+ SPI_BAUD_PCLK_DIV_64,
+ SPI_BAUD_PCLK_DIV_128,
+ SPI_BAUD_PCLK_DIV_256,
+};
+
+/**
+ * Note: This assumes you're on a LeafLabs-style board
+ * (CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz).
+ */
+static spi_baud_rate determine_baud_rate(spi_dev *dev, uint32_t freq) {
+ uint32_t clock = 0;
+ switch (rcc_dev_clk(dev->clk_id)) {
+ case RCC_AHB:
+ case RCC_APB2: clock = STM32_PCLK2; break; // 72 Mhz
+ case RCC_APB1: clock = STM32_PCLK1; break; // 36 Mhz
+ }
+ clock >>= 1;
+
+ uint8_t i = 0;
+ while (i < 7 && freq < clock) { clock >>= 1; i++; }
+ return baud_rates[i];
+}
+
+SPIClass SPI(1);
+
+#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/SPI.h b/Marlin/src/HAL/HAL_STM32F1/SPI.h
new file mode 100644
index 0000000000..0162ac13bb
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SPI.h
@@ -0,0 +1,417 @@
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *****************************************************************************/
+#pragma once
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+// SPI_HAS_TRANSACTION means SPI has
+// - beginTransaction()
+// - endTransaction()
+// - usingInterrupt()
+// - SPISetting(clock, bitOrder, dataMode)
+//#define SPI_HAS_TRANSACTION
+
+#define SPI_CLOCK_DIV2 SPI_BAUD_PCLK_DIV_2
+#define SPI_CLOCK_DIV4 SPI_BAUD_PCLK_DIV_4
+#define SPI_CLOCK_DIV8 SPI_BAUD_PCLK_DIV_8
+#define SPI_CLOCK_DIV16 SPI_BAUD_PCLK_DIV_16
+#define SPI_CLOCK_DIV32 SPI_BAUD_PCLK_DIV_32
+#define SPI_CLOCK_DIV64 SPI_BAUD_PCLK_DIV_64
+#define SPI_CLOCK_DIV128 SPI_BAUD_PCLK_DIV_128
+#define SPI_CLOCK_DIV256 SPI_BAUD_PCLK_DIV_256
+
+/*
+ * Roger Clark. 20150106
+ * Commented out redundant AVR defined
+ *
+#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
+#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
+#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
+
+// define SPI_AVR_EIMSK for AVR boards with external interrupt pins
+#ifdef EIMSK
+ #define SPI_AVR_EIMSK EIMSK
+#elif defined(GICR)
+ #define SPI_AVR_EIMSK GICR
+#elif defined(GIMSK)
+ #define SPI_AVR_EIMSK GIMSK
+#endif
+*/
+
+#ifndef STM32_LSBFIRST
+ #define STM32_LSBFIRST 0
+#endif
+#ifndef STM32_MSBFIRST
+ #define STM32_MSBFIRST 1
+#endif
+
+// PC13 or PA4
+#define BOARD_SPI_DEFAULT_SS PA4
+//#define BOARD_SPI_DEFAULT_SS PC13
+
+#define SPI_MODE0 SPI_MODE_0
+#define SPI_MODE1 SPI_MODE_1
+#define SPI_MODE2 SPI_MODE_2
+#define SPI_MODE3 SPI_MODE_3
+
+#define DATA_SIZE_8BIT SPI_CR1_DFF_8_BIT
+#define DATA_SIZE_16BIT SPI_CR1_DFF_16_BIT
+
+typedef enum {
+ SPI_STATE_IDLE,
+ SPI_STATE_READY,
+ SPI_STATE_RECEIVE,
+ SPI_STATE_TRANSMIT,
+ SPI_STATE_TRANSFER
+} spi_mode_t;
+
+class SPISettings {
+public:
+ SPISettings(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, DATA_SIZE_8BIT);
+ else
+ init_MightInline(inClock, inBitOrder, inDataMode, DATA_SIZE_8BIT);
+ }
+ SPISettings(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
+ else
+ init_MightInline(inClock, inBitOrder, inDataMode, inDataSize);
+ }
+ SPISettings(uint32_t inClock) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ else
+ init_MightInline(inClock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+ SPISettings() {
+ init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+private:
+ void init_MightInline(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
+ }
+ void init_AlwaysInline(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) __attribute__((__always_inline__)) {
+ clock = inClock;
+ bitOrder = inBitOrder;
+ dataMode = inDataMode;
+ dataSize = inDataSize;
+ }
+ uint32_t clock;
+ uint32_t dataSize;
+ uint32_t clockDivider;
+ BitOrder bitOrder;
+ uint8_t dataMode;
+ uint8_t _SSPin;
+ volatile spi_mode_t state;
+ spi_dev *spi_d;
+ dma_channel spiRxDmaChannel, spiTxDmaChannel;
+ dma_dev* spiDmaDev;
+ void (*receiveCallback)() = NULL;
+ void (*transmitCallback)() = NULL;
+
+ friend class SPIClass;
+};
+
+/*
+ * Kept for compat.
+ */
+static const uint8_t ff = 0xFF;
+
+/**
+ * @brief Wirish SPI interface.
+ *
+ * This implementation uses software slave management, so the caller
+ * is responsible for controlling the slave select line.
+ */
+class SPIClass {
+
+public:
+ /**
+ * @param spiPortNumber Number of the SPI port to manage.
+ */
+ SPIClass(uint32_t spiPortNumber);
+
+ /**
+ * @brief Equivalent to begin(SPI_1_125MHZ, MSBFIRST, 0).
+ */
+ void begin();
+
+ /**
+ * @brief Turn on a SPI port and set its GPIO pin modes for use as a slave.
+ *
+ * SPI port is enabled in full duplex mode, with software slave management.
+ *
+ * @param bitOrder Either LSBFIRST (little-endian) or MSBFIRST(big-endian)
+ * @param mode SPI mode to use
+ */
+ void beginSlave(uint32_t bitOrder, uint32_t mode);
+
+ /**
+ * @brief Equivalent to beginSlave(MSBFIRST, 0).
+ */
+ void beginSlave();
+
+ /**
+ * @brief Disables the SPI port, but leaves its GPIO pin modes unchanged.
+ */
+ void end();
+
+ void beginTransaction(SPISettings settings) { beginTransaction(BOARD_SPI_DEFAULT_SS, settings); }
+ void beginTransaction(uint8_t pin, SPISettings settings);
+ void endTransaction();
+
+ void beginTransactionSlave(SPISettings settings);
+
+ void setClockDivider(uint32_t clockDivider);
+ void setBitOrder(BitOrder bitOrder);
+ void setDataMode(uint8_t dataMode);
+
+ // SPI Configuration methods
+ void attachInterrupt();
+ void detachInterrupt();
+
+ /* Victor Perez. Added to change datasize from 8 to 16 bit modes on the fly.
+ * Input parameter should be SPI_CR1_DFF set to 0 or 1 on a 32bit word.
+ * Requires an added function spi_data_size on STM32F1 / cores / maple / libmaple / spi.c
+ */
+ void setDataSize(uint32_t ds);
+
+ /* Victor Perez 2017. Added to set and clear callback functions for callback
+ * on DMA transfer completion.
+ * onReceive used to set the callback in case of dmaTransfer (tx/rx), once rx is completed
+ * onTransmit used to set the callback in case of dmaSend (tx only). That function
+ * will NOT be called in case of TX/RX
+ */
+ void onReceive(void(*)());
+ void onTransmit(void(*)());
+
+ /*
+ * I/O
+ */
+
+ /**
+ * @brief Return the next unread byte/word.
+ *
+ * If there is no unread byte/word waiting, this function will block
+ * until one is received.
+ */
+ uint16_t read();
+
+ /**
+ * @brief Read length bytes, storing them into buffer.
+ * @param buffer Buffer to store received bytes into.
+ * @param length Number of bytes to store in buffer. This
+ * function will block until the desired number of
+ * bytes have been read.
+ */
+ void read(uint8_t *buffer, uint32_t length);
+
+ /**
+ * @brief Transmit one byte/word.
+ * @param data to transmit.
+ */
+ void write(uint16_t data);
+ void write16(uint16_t data); // write 2 bytes in 8 bit mode (DFF=0)
+
+ /**
+ * @brief Transmit one byte/word a specified number of times.
+ * @param data to transmit.
+ */
+ void write(uint16_t data, uint32_t n);
+
+ /**
+ * @brief Transmit multiple bytes/words.
+ * @param buffer Bytes/words to transmit.
+ * @param length Number of bytes/words in buffer to transmit.
+ */
+ void write(const void * buffer, uint32_t length);
+
+ /**
+ * @brief Transmit a byte, then return the next unread byte.
+ *
+ * This function transmits before receiving.
+ *
+ * @param data Byte to transmit.
+ * @return Next unread byte.
+ */
+ uint8_t transfer(uint8_t data) const;
+ uint16_t transfer16(uint16_t data) const;
+
+ /**
+ * @brief Sets up a DMA Transfer for "length" bytes.
+ * The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.
+ *
+ * This function transmits and receives to buffers.
+ *
+ * @param transmitBuf buffer Bytes to transmit. If passed as 0, it sends FF repeatedly for "length" bytes
+ * @param receiveBuf buffer Bytes to save received data.
+ * @param length Number of bytes in buffer to transmit.
+ */
+ uint8_t dmaTransfer(const void * transmitBuf, void * receiveBuf, uint16_t length);
+ void dmaTransferSet(const void *transmitBuf, void *receiveBuf);
+ uint8_t dmaTransferRepeat(uint16_t length);
+
+ /**
+ * @brief Sets up a DMA Transmit for SPI 8 or 16 bit transfer mode.
+ * The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.
+ *
+ * This function only transmits and does not care about the RX fifo.
+ *
+ * @param data buffer half words to transmit,
+ * @param length Number of bytes in buffer to transmit.
+ * @param minc Set to use Memory Increment mode, clear to use Circular mode.
+ */
+ uint8_t dmaSend(const void * transmitBuf, uint16_t length, bool minc = 1);
+ void dmaSendSet(const void * transmitBuf, bool minc);
+ uint8_t dmaSendRepeat(uint16_t length);
+
+ uint8_t dmaSendAsync(const void * transmitBuf, uint16_t length, bool minc = 1);
+ /*
+ * Pin accessors
+ */
+
+ /**
+ * @brief Return the number of the MISO (master in, slave out) pin
+ */
+ uint8_t misoPin();
+
+ /**
+ * @brief Return the number of the MOSI (master out, slave in) pin
+ */
+ uint8_t mosiPin();
+
+ /**
+ * @brief Return the number of the SCK (serial clock) pin
+ */
+ uint8_t sckPin();
+
+ /**
+ * @brief Return the number of the NSS (slave select) pin
+ */
+ uint8_t nssPin();
+
+ /* Escape hatch */
+
+ /**
+ * @brief Get a pointer to the underlying libmaple spi_dev for
+ * this HardwareSPI instance.
+ */
+ spi_dev* c_dev() { return _currentSetting->spi_d; }
+
+ spi_dev* dev() { return _currentSetting->spi_d; }
+
+ /**
+ * @brief Sets the number of the SPI peripheral to be used by
+ * this HardwareSPI instance.
+ *
+ * @param spi_num Number of the SPI port. 1-2 in low density devices
+ * or 1-3 in high density devices.
+ */
+ void setModule(int spi_num) {
+ _currentSetting = &_settings[spi_num - 1];// SPI channels are called 1 2 and 3 but the array is zero indexed
+ }
+
+ /* -- The following methods are deprecated --------------------------- */
+
+ /**
+ * @brief Deprecated.
+ *
+ * Use HardwareSPI::transfer() instead.
+ *
+ * @see HardwareSPI::transfer()
+ */
+ uint8_t send(uint8_t data);
+
+ /**
+ * @brief Deprecated.
+ *
+ * Use HardwareSPI::write() in combination with
+ * HardwareSPI::read() (or HardwareSPI::transfer()) instead.
+ *
+ * @see HardwareSPI::write()
+ * @see HardwareSPI::read()
+ * @see HardwareSPI::transfer()
+ */
+ uint8_t send(uint8_t *data, uint32_t length);
+
+ /**
+ * @brief Deprecated.
+ *
+ * Use HardwareSPI::read() instead.
+ *
+ * @see HardwareSPI::read()
+ */
+ uint8_t recv();
+
+private:
+
+ SPISettings _settings[BOARD_NR_SPI];
+ SPISettings *_currentSetting;
+
+ void updateSettings();
+
+ /*
+ * Functions added for DMA transfers with Callback.
+ * Experimental.
+ */
+
+ void EventCallback();
+
+ #if BOARD_NR_SPI >= 1
+ static void _spi1EventCallback();
+ #endif
+ #if BOARD_NR_SPI >= 2
+ static void _spi2EventCallback();
+ #endif
+ #if BOARD_NR_SPI >= 3
+ static void _spi3EventCallback();
+ #endif
+ /*
+ spi_dev *spi_d;
+ uint8_t _SSPin;
+ uint32_t clockDivider;
+ uint8_t dataMode;
+ BitOrder bitOrder;
+ */
+};
+
+/**
+ * @brief Wait until TXE (tx empty) flag is set and BSY (busy) flag unset.
+ */
+static inline void waitSpiTxEnd(spi_dev *spi_d) {
+ while (spi_is_tx_empty(spi_d) == 0) { /* nada */ } // wait until TXE=1
+ while (spi_is_busy(spi_d) != 0) { /* nada */ } // wait until BSY=0
+}
+
+extern SPIClass SPI;
diff --git a/Marlin/src/HAL/HAL_STM32F1/SanityCheck.h b/Marlin/src/HAL/HAL_STM32F1/SanityCheck.h
deleted file mode 100644
index c1470ca51e..0000000000
--- a/Marlin/src/HAL/HAL_STM32F1/SanityCheck.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-/**
- * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
- */
-
-/**
- * Test Re-ARM specific configuration values for errors at compile-time.
- */
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif SPINDLE_LASER_POWERUP_DELAY < 0
- #error "SPINDLE_LASER_POWERUP_DELAY must be positive"
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 0
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be positive"
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-#if ENABLED(EMERGENCY_PARSER)
- #error "EMERGENCY_PARSER is not yet implemented for STM32F1. Disable EMERGENCY_PARSER to continue."
-#endif
-
-#if ENABLED(SDIO_SUPPORT) && DISABLED(SDSUPPORT)
- #error "SDIO_SUPPORT requires SDSUPPORT. Enable SDSUPPORT to continue."
-#endif
-
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
-#endif
diff --git a/Marlin/src/HAL/HAL_STM32F1/Servo.cpp b/Marlin/src/HAL/HAL_STM32F1/Servo.cpp
new file mode 100644
index 0000000000..5dc2169154
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/Servo.cpp
@@ -0,0 +1,229 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifdef __STM32F1__
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_SERVOS
+
+uint8_t ServoCount = 0;
+
+#include "Servo.h"
+#include "timers.h"
+
+//#include "Servo.h"
+
+#include
+#include
+#include
+#include
+
+/**
+ * 20 millisecond period config. For a 1-based prescaler,
+ *
+ * (prescaler * overflow / CYC_MSEC) msec = 1 timer cycle = 20 msec
+ * => prescaler * overflow = 20 * CYC_MSEC
+ *
+ * This uses the smallest prescaler that allows an overflow < 2^16.
+ */
+#define MAX_OVERFLOW UINT16_MAX //((1 << 16) - 1)
+#define CYC_MSEC (1000 * CYCLES_PER_MICROSECOND)
+#define TAU_MSEC 20
+#define TAU_USEC (TAU_MSEC * 1000)
+#define TAU_CYC (TAU_MSEC * CYC_MSEC)
+#define SERVO_PRESCALER (TAU_CYC / MAX_OVERFLOW + 1)
+#define SERVO_OVERFLOW ((uint16_t)round((double)TAU_CYC / SERVO_PRESCALER))
+
+// Unit conversions
+#define US_TO_COMPARE(us) uint16_t(map((us), 0, TAU_USEC, 0, SERVO_OVERFLOW))
+#define COMPARE_TO_US(c) uint32_t(map((c), 0, SERVO_OVERFLOW, 0, TAU_USEC))
+#define ANGLE_TO_US(a) uint16_t(map((a), minAngle, maxAngle, SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW))
+#define US_TO_ANGLE(us) int16_t(map((us), SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW, minAngle, maxAngle))
+
+void libServo::servoWrite(uint8_t inPin, uint16_t duty_cycle) {
+ #ifdef SERVO0_TIMER_NUM
+ if (servoIndex == 0) {
+ pwmSetDuty(duty_cycle);
+ return;
+ }
+ #endif
+
+ timer_dev *tdev = PIN_MAP[inPin].timer_device;
+ uint8_t tchan = PIN_MAP[inPin].timer_channel;
+ if (tdev) timer_set_compare(tdev, tchan, duty_cycle);
+}
+
+libServo::libServo() {
+ servoIndex = ServoCount < MAX_SERVOS ? ServoCount++ : INVALID_SERVO;
+}
+
+bool libServo::attach(const int32_t inPin, const int32_t inMinAngle, const int32_t inMaxAngle) {
+ if (servoIndex >= MAX_SERVOS) return false;
+ if (inPin >= BOARD_NR_GPIO_PINS) return false;
+
+ minAngle = inMinAngle;
+ maxAngle = inMaxAngle;
+ angle = -1;
+
+ #ifdef SERVO0_TIMER_NUM
+ if (servoIndex == 0 && setupSoftPWM(inPin)) {
+ pin = inPin; // set attached()
+ return true;
+ }
+ #endif
+
+ if (!PWM_PIN(inPin)) return false;
+
+ timer_dev *tdev = PIN_MAP[inPin].timer_device;
+ //uint8_t tchan = PIN_MAP[inPin].timer_channel;
+
+ SET_PWM(inPin);
+ servoWrite(inPin, 0);
+
+ timer_pause(tdev);
+ timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
+ timer_set_reload(tdev, SERVO_OVERFLOW);
+ timer_generate_update(tdev);
+ timer_resume(tdev);
+
+ pin = inPin; // set attached()
+ return true;
+}
+
+bool libServo::detach() {
+ if (!attached()) return false;
+ angle = -1;
+ servoWrite(pin, 0);
+ return true;
+}
+
+int32_t libServo::read() const {
+ if (attached()) {
+ #ifdef SERVO0_TIMER_NUM
+ if (servoIndex == 0) return angle;
+ #endif
+ timer_dev *tdev = PIN_MAP[pin].timer_device;
+ uint8_t tchan = PIN_MAP[pin].timer_channel;
+ return US_TO_ANGLE(COMPARE_TO_US(timer_get_compare(tdev, tchan)));
+ }
+ return 0;
+}
+
+void libServo::move(const int32_t value) {
+ constexpr uint16_t servo_delay[] = SERVO_DELAY;
+ static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
+
+ if (attached()) {
+ angle = constrain(value, minAngle, maxAngle);
+ servoWrite(pin, US_TO_COMPARE(ANGLE_TO_US(angle)));
+ safe_delay(servo_delay[servoIndex]);
+ #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
+ detach();
+ #endif
+ }
+}
+
+#ifdef SERVO0_TIMER_NUM
+ extern "C" void Servo_IRQHandler() {
+ static timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
+ uint16_t SR = timer_get_status(tdev);
+ if (SR & TIMER_SR_CC1IF) { // channel 1 off
+ #ifdef SERVO0_PWM_OD
+ OUT_WRITE_OD(SERVO0_PIN, 1); // off
+ #else
+ OUT_WRITE(SERVO0_PIN, 0);
+ #endif
+ timer_reset_status_bit(tdev, TIMER_SR_CC1IF_BIT);
+ }
+ if (SR & TIMER_SR_CC2IF) { // channel 2 resume
+ #ifdef SERVO0_PWM_OD
+ OUT_WRITE_OD(SERVO0_PIN, 0); // on
+ #else
+ OUT_WRITE(SERVO0_PIN, 1);
+ #endif
+ timer_reset_status_bit(tdev, TIMER_SR_CC2IF_BIT);
+ }
+ }
+
+ bool libServo::setupSoftPWM(const int32_t inPin) {
+ timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
+ if (!tdev) return false;
+ #ifdef SERVO0_PWM_OD
+ OUT_WRITE_OD(inPin, 1);
+ #else
+ OUT_WRITE(inPin, 0);
+ #endif
+
+ timer_pause(tdev);
+ timer_set_mode(tdev, 1, TIMER_OUTPUT_COMPARE); // counter with isr
+ timer_oc_set_mode(tdev, 1, TIMER_OC_MODE_FROZEN, 0); // no pin output change
+ timer_oc_set_mode(tdev, 2, TIMER_OC_MODE_FROZEN, 0); // no pin output change
+ timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
+ timer_set_reload(tdev, SERVO_OVERFLOW);
+ timer_set_compare(tdev, 1, SERVO_OVERFLOW);
+ timer_set_compare(tdev, 2, SERVO_OVERFLOW);
+ timer_attach_interrupt(tdev, 1, Servo_IRQHandler);
+ timer_attach_interrupt(tdev, 2, Servo_IRQHandler);
+ timer_generate_update(tdev);
+ timer_resume(tdev);
+
+ return true;
+ }
+
+ void libServo::pwmSetDuty(const uint16_t duty_cycle) {
+ timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
+ timer_set_compare(tdev, 1, duty_cycle);
+ timer_generate_update(tdev);
+ if (duty_cycle) {
+ timer_enable_irq(tdev, 1);
+ timer_enable_irq(tdev, 2);
+ }
+ else {
+ timer_disable_irq(tdev, 1);
+ timer_disable_irq(tdev, 2);
+ #ifdef SERVO0_PWM_OD
+ OUT_WRITE_OD(pin, 1); // off
+ #else
+ OUT_WRITE(pin, 0);
+ #endif
+ }
+ }
+
+ void libServo::pauseSoftPWM() { // detach
+ timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
+ timer_pause(tdev);
+ pwmSetDuty(0);
+ }
+
+#else
+
+ bool libServo::setupSoftPWM(const int32_t inPin) { return false; }
+ void libServo::pwmSetDuty(const uint16_t duty_cycle) {}
+ void libServo::pauseSoftPWM() {}
+
+#endif
+
+#endif // HAS_SERVOS
+
+#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/Servo.h
similarity index 79%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/Servo.h
index ac83f086ee..92f4dd678d 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/Servo.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -41,13 +41,20 @@ class libServo {
public:
libServo();
bool attach(const int32_t pin, const int32_t minAngle=SERVO_DEFAULT_MIN_ANGLE, const int32_t maxAngle=SERVO_DEFAULT_MAX_ANGLE);
- bool attached() const { return this->pin != NOT_ATTACHED; }
+ bool attached() const { return pin != NOT_ATTACHED; }
bool detach();
void move(const int32_t value);
int32_t read() const;
private:
+ void servoWrite(uint8_t pin, const uint16_t duty_cycle);
+
uint8_t servoIndex; // index into the channel data for this servo
int32_t pin = NOT_ATTACHED;
int32_t minAngle;
int32_t maxAngle;
+ int32_t angle;
+
+ bool setupSoftPWM(const int32_t pin);
+ void pauseSoftPWM();
+ void pwmSetDuty(const uint16_t duty_cycle);
};
diff --git a/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.cpp
new file mode 100644
index 0000000000..99772a03c2
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.cpp
@@ -0,0 +1,60 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#if defined(__STM32F1__) && !defined(HAVE_SW_SERIAL)
+
+/**
+ * Empty class for Software Serial implementation (Custom RX/TX pins)
+ *
+ * TODO: Optionally use https://github.com/FYSETC/SoftwareSerialM if TMC UART is wanted
+ */
+
+#include "SoftwareSerial.h"
+
+// Constructor
+
+SoftwareSerial::SoftwareSerial(int8_t RX_pin, int8_t TX_pin) {}
+
+// Public
+
+void SoftwareSerial::begin(const uint32_t baudrate) {
+}
+
+bool SoftwareSerial::available() {
+ return false;
+}
+
+uint8_t SoftwareSerial::read() {
+ return 0;
+}
+
+uint16_t SoftwareSerial::write(uint8_t byte) {
+ return 0;
+}
+
+void SoftwareSerial::flush() {}
+
+void SoftwareSerial::listen() {
+ listening = true;
+}
+
+void SoftwareSerial::stopListening() {
+ listening = false;
+}
+
+#endif //__STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.h b/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.h
new file mode 100644
index 0000000000..0692b7e9f3
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.h
@@ -0,0 +1,42 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+
+#define SW_SERIAL_PLACEHOLDER 1
+
+class SoftwareSerial {
+public:
+ SoftwareSerial(int8_t RX_pin, int8_t TX_pin);
+
+ void begin(const uint32_t baudrate);
+
+ bool available();
+
+ uint8_t read();
+ uint16_t write(uint8_t byte);
+ void flush();
+
+ void listen();
+ void stopListening();
+
+protected:
+ bool listening;
+};
diff --git a/Marlin/src/HAL/HAL_STM32F1/STM32F1_flag_script.py b/Marlin/src/HAL/HAL_STM32F1/build_flags.py
similarity index 94%
rename from Marlin/src/HAL/HAL_STM32F1/STM32F1_flag_script.py
rename to Marlin/src/HAL/HAL_STM32F1/build_flags.py
index ce5a066741..6310740fe0 100644
--- a/Marlin/src/HAL/HAL_STM32F1/STM32F1_flag_script.py
+++ b/Marlin/src/HAL/HAL_STM32F1/build_flags.py
@@ -4,12 +4,10 @@ import sys
#dynamic build flags for generic compile options
if __name__ == "__main__":
args = " ".join([ "-std=gnu11",
- "-std=gnu++11",
"-Os",
"-mcpu=cortex-m3",
"-mthumb",
- "-ffreestanding",
"-fsigned-char",
"-fno-move-loop-invariants",
"-fno-strict-aliasing",
diff --git a/Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_fsmc.cpp b/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
similarity index 71%
rename from Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_fsmc.cpp
rename to Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
index 637b83bd5d..9d569772fa 100644
--- a/Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_fsmc.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,18 +26,21 @@
* Communication interface for FSMC
*/
-#include "../../inc/MarlinConfig.h"
+#include "../../../inc/MarlinConfig.h"
#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs
#if HAS_GRAPHICAL_LCD
-#include "U8glib.h"
-#include "libmaple/fsmc.h"
-#include "libmaple/gpio.h"
-#include "boards.h"
+#include
+#include
+#include
+#include
+#include
-#define LCD_READ_ID 0x04 /* Read display identification information */
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
/* Timing configuration */
#define FSMC_ADDRESS_SETUP_TIME 15 // AddressSetupTime
@@ -45,8 +48,12 @@
void LCD_IO_Init(uint8_t cs, uint8_t rs);
void LCD_IO_WriteData(uint16_t RegValue);
-void LCD_IO_WriteReg(uint8_t Reg);
+void LCD_IO_WriteReg(uint16_t Reg);
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
+#ifdef LCD_USE_DMA_FSMC
+ void LCD_IO_WriteMultiple(uint16_t data, uint32_t count);
+ void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
+#endif
static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
@@ -59,21 +66,25 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
static uint8_t isCommand;
switch (msg) {
- case U8G_COM_MSG_STOP:
- break;
+ case U8G_COM_MSG_STOP: break;
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_RESET);
+ #ifdef LCD_USE_DMA_FSMC
+ dma_init(FSMC_DMA_DEV);
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
+ #endif
+
LCD_IO_Init(u8g->pin_list[U8G_PI_CS], u8g->pin_list[U8G_PI_A0]);
- u8g_Delay(100);
+ u8g_Delay(50);
- if (arg_ptr != nullptr)
+ if (arg_ptr)
*((uint32_t *)arg_ptr) = LCD_IO_ReadData(LCD_READ_ID, 3);
-
isCommand = 0;
break;
- case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
+ case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
isCommand = arg_val == 0 ? 1 : 0;
break;
@@ -89,7 +100,6 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
break;
case U8G_COM_MSG_WRITE_SEQ:
-
for (uint8_t i = 0; i < arg_val; i += 2)
LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
break;
@@ -103,13 +113,13 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
#define __ASM __asm
#define __STATIC_INLINE static inline
-__attribute__((always_inline)) __STATIC_INLINE void __DSB(void) {
+__attribute__((always_inline)) __STATIC_INLINE void __DSB() {
__ASM volatile ("dsb 0xF":::"memory");
}
-#define FSMC_CS_NE1 PD7
+#define FSMC_CS_NE1 PD7
-#ifdef STM32_XL_DENSITY
+#if ENABLED(STM32_XL_DENSITY)
#define FSMC_CS_NE2 PG9
#define FSMC_CS_NE3 PG10
#define FSMC_CS_NE4 PG12
@@ -141,7 +151,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __DSB(void) {
#define FSMC_RS_A22 PE6
#define FSMC_RS_A23 PE2
-#ifdef STM32_XL_DENSITY
+#if ENABLED(STM32_XL_DENSITY)
#define FSMC_RS_A24 PG13
#define FSMC_RS_A25 PG14
#endif
@@ -163,7 +173,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
switch (cs) {
case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; break;
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; break;
case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; break;
case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; break;
@@ -174,7 +184,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
#define _ORADDR(N) controllerAddress |= (_BV32(N) - 2)
switch (rs) {
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
case FSMC_RS_A0: _ORADDR( 1); break;
case FSMC_RS_A1: _ORADDR( 2); break;
case FSMC_RS_A2: _ORADDR( 3); break;
@@ -200,7 +210,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
case FSMC_RS_A21: _ORADDR(22); break;
case FSMC_RS_A22: _ORADDR(23); break;
case FSMC_RS_A23: _ORADDR(24); break;
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
case FSMC_RS_A24: _ORADDR(25); break;
case FSMC_RS_A25: _ORADDR(26); break;
#endif
@@ -232,7 +242,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_CS_NEx
gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_RS_Ax
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
FSMC_NOR_PSRAM4_BASE->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
FSMC_NOR_PSRAM4_BASE->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
#else // PSRAM1 for STM32F103V (high density)
@@ -250,14 +260,14 @@ void LCD_IO_WriteData(uint16_t RegValue) {
__DSB();
}
-void LCD_IO_WriteReg(uint8_t Reg) {
- LCD->REG = (uint16_t)Reg;
+void LCD_IO_WriteReg(uint16_t Reg) {
+ LCD->REG = Reg;
__DSB();
}
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
volatile uint32_t data;
- LCD->REG = (uint16_t)RegValue;
+ LCD->REG = RegValue;
__DSB();
data = LCD->RAM; // dummy read
@@ -267,9 +277,48 @@ uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
data <<= 8;
data |= (LCD->RAM & 0x00FF);
}
- return (uint32_t)data;
+ return uint32_t(data);
}
-#endif // HAS_GRAPHICAL_LCD
+#if ENABLED(LCD_USE_DMA_FSMC)
+void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) {
+ while (count > 0) {
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, &color, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, count > 65535 ? 65535 : count);
+ dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+
+ while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+
+ count = count > 65535 ? count - 65535 : 0;
+ }
+}
+
+void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) {
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
+ dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+
+ while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+}
+
+void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) {
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
+ dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+}
+
+void LCD_IO_WaitSequence_Async() {
+ while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+}
+
+#endif // LCD_USE_DMA_FSMC
+
+#endif // HAS_GRAPHICAL_LCD
#endif // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN
diff --git a/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_swspi.cpp b/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
new file mode 100644
index 0000000000..753a5d5e70
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
@@ -0,0 +1,165 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#ifdef __STM32F1__
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_GRAPHICAL_LCD && ENABLED(FORCE_SOFT_SPI)
+
+#include "../HAL.h"
+#include
+
+#undef SPI_SPEED
+#define SPI_SPEED 0 // Fastest
+//#define SPI_SPEED 2 // Slower
+
+static uint8_t SPI_speed = SPI_SPEED;
+
+static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
+ for (uint8_t i = 0; i < 8; i++) {
+ if (spi_speed == 0) {
+ WRITE(DOGLCD_MOSI, !!(b & 0x80));
+ WRITE(DOGLCD_SCK, HIGH);
+ b <<= 1;
+ if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
+ WRITE(DOGLCD_SCK, LOW);
+ }
+ else {
+ const uint8_t state = (b & 0x80) ? HIGH : LOW;
+ for (uint8_t j = 0; j < spi_speed; j++)
+ WRITE(DOGLCD_MOSI, state);
+
+ for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
+ WRITE(DOGLCD_SCK, HIGH);
+
+ b <<= 1;
+ if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
+
+ for (uint8_t j = 0; j < spi_speed; j++)
+ WRITE(DOGLCD_SCK, LOW);
+ }
+ }
+ return b;
+}
+
+static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
+ for (uint8_t i = 0; i < 8; i++) {
+ const uint8_t state = (b & 0x80) ? HIGH : LOW;
+ if (spi_speed == 0) {
+ WRITE(DOGLCD_SCK, LOW);
+ WRITE(DOGLCD_MOSI, state);
+ WRITE(DOGLCD_MOSI, state); // need some setup time
+ WRITE(DOGLCD_SCK, HIGH);
+ }
+ else {
+ for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
+ WRITE(DOGLCD_SCK, LOW);
+
+ for (uint8_t j = 0; j < spi_speed; j++)
+ WRITE(DOGLCD_MOSI, state);
+
+ for (uint8_t j = 0; j < spi_speed; j++)
+ WRITE(DOGLCD_SCK, HIGH);
+ }
+ b <<= 1;
+ if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
+ }
+ return b;
+}
+
+static void u8g_sw_spi_HAL_STM32F1_shift_out(uint8_t val) {
+ #if ENABLED(FYSETC_MINI_12864)
+ swSpiTransfer_mode_3(val, SPI_speed);
+ #else
+ swSpiTransfer_mode_0(val, SPI_speed);
+ #endif
+}
+
+static uint8_t swSpiInit(const uint8_t spi_speed) {
+ #if PIN_EXISTS(LCD_RESET)
+ SET_OUTPUT(LCD_RESET_PIN);
+ #endif
+ SET_OUTPUT(DOGLCD_A0);
+ OUT_WRITE(DOGLCD_SCK, LOW);
+ OUT_WRITE(DOGLCD_MOSI, LOW);
+ OUT_WRITE(DOGLCD_CS, HIGH);
+ return spi_speed;
+}
+
+uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
+ switch (msg) {
+ case U8G_COM_MSG_INIT:
+ SPI_speed = swSpiInit(SPI_SPEED);
+ break;
+
+ case U8G_COM_MSG_STOP:
+ break;
+
+ case U8G_COM_MSG_RESET:
+ #if PIN_EXISTS(LCD_RESET)
+ WRITE(LCD_RESET_PIN, arg_val);
+ #endif
+ break;
+
+ case U8G_COM_MSG_CHIP_SELECT:
+ #if ENABLED(FYSETC_MINI_12864) // This LCD SPI is running mode 3 while SD card is running mode 0
+ if (arg_val) { // SCK idle state needs to be set to the proper idle state before
+ // the next chip select goes active
+ WRITE(DOGLCD_SCK, HIGH); // Set SCK to mode 3 idle state before CS goes active
+ WRITE(DOGLCD_CS, LOW);
+ }
+ else {
+ WRITE(DOGLCD_CS, HIGH);
+ WRITE(DOGLCD_SCK, LOW); // Set SCK to mode 0 idle state after CS goes inactive
+ }
+ #else
+ WRITE(DOGLCD_CS, !arg_val);
+ #endif
+ break;
+
+ case U8G_COM_MSG_WRITE_BYTE:
+ u8g_sw_spi_HAL_STM32F1_shift_out(arg_val);
+ break;
+
+ case U8G_COM_MSG_WRITE_SEQ: {
+ uint8_t *ptr = (uint8_t *)arg_ptr;
+ while (arg_val > 0) {
+ u8g_sw_spi_HAL_STM32F1_shift_out(*ptr++);
+ arg_val--;
+ }
+ } break;
+
+ case U8G_COM_MSG_WRITE_SEQ_P: {
+ uint8_t *ptr = (uint8_t *)arg_ptr;
+ while (arg_val > 0) {
+ u8g_sw_spi_HAL_STM32F1_shift_out(u8g_pgm_read(ptr));
+ ptr++;
+ arg_val--;
+ }
+ } break;
+
+ case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
+ WRITE(DOGLCD_A0, arg_val);
+ break;
+ }
+ return 1;
+}
+
+#endif // HAS_GRAPHICAL_LCD
+#endif // STM32F1
diff --git a/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h
index 85437c511d..d043b3b8db 100644
--- a/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -50,9 +50,9 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
-void setup_endstop_interrupts(void) {
+void setup_endstop_interrupts() {
#if HAS_X_MAX
attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE); // assign it
#endif
diff --git a/Marlin/src/HAL/HAL_STM32F1/fastio.h b/Marlin/src/HAL/HAL_STM32F1/fastio.h
new file mode 100644
index 0000000000..463d951c1e
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/fastio.h
@@ -0,0 +1,185 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Fast I/O interfaces for STM32F1
+ * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
+ */
+
+#include
+
+#define READ(IO) (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
+#define WRITE(IO,V) (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << ((V) ? 0 : 16))
+#define TOGGLE(IO) (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
+
+#define _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
+#define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
+#define _SET_OUTPUT(IO) _SET_MODE(IO, GPIO_OUTPUT_PP)
+#define _SET_OUTPUT_OD(IO) _SET_MODE(IO, GPIO_OUTPUT_OD)
+
+#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
+#define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0)
+
+#define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING)
+#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU)
+#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
+#define SET_PWM(IO) pinMode(IO, PWM) // do{ gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, GPIO_AF_OUTPUT_PP); timer_set_mode(PIN_MAP[pin].timer_device, PIN_MAP[pin].timer_channel, TIMER_PWM); }while(0)
+#define SET_PWM_OD(IO) pinMode(IO, PWM_OPEN_DRAIN)
+
+#define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
+#define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)
+
+#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr)
+
+// digitalRead/Write wrappers
+#define extDigitalRead(IO) digitalRead(IO)
+#define extDigitalWrite(IO,V) digitalWrite(IO,V)
+
+//
+// Pins Definitions
+//
+#define PA0 0x00
+#define PA1 0x01
+#define PA2 0x02
+#define PA3 0x03
+#define PA4 0x04
+#define PA5 0x05
+#define PA6 0x06
+#define PA7 0x07
+#define PA8 0x08
+#define PA9 0x09
+#define PA10 0x0A
+#define PA11 0x0B
+#define PA12 0x0C
+#define PA13 0x0D
+#define PA14 0x0E
+#define PA15 0x0F
+
+#define PB0 0x10
+#define PB1 0x11
+#define PB2 0x12
+#define PB3 0x13
+#define PB4 0x14
+#define PB5 0x15
+#define PB6 0x16
+#define PB7 0x17 // 36 pins (F103T)
+#define PB8 0x18
+#define PB9 0x19
+#define PB10 0x1A
+#define PB11 0x1B
+#define PB12 0x1C
+#define PB13 0x1D
+#define PB14 0x1E
+#define PB15 0x1F
+
+#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
+ #define PC13 0x20
+ #define PC14 0x21
+ #define PC15 0x22
+#else
+ #define PC0 0x20
+ #define PC1 0x21
+ #define PC2 0x22
+ #define PC3 0x23
+ #define PC4 0x24
+ #define PC5 0x25
+ #define PC6 0x26
+ #define PC7 0x27
+ #define PC8 0x28
+ #define PC9 0x29
+ #define PC10 0x2A
+ #define PC11 0x2B
+ #define PC12 0x2C
+ #define PC13 0x2D
+ #define PC14 0x2E
+ #define PC15 0x2F
+#endif
+
+#define PD0 0x30
+#define PD1 0x31
+#define PD2 0x32 // 64 pins (F103R)
+#define PD3 0x33
+#define PD4 0x34
+#define PD5 0x35
+#define PD6 0x36
+#define PD7 0x37
+#define PD8 0x38
+#define PD9 0x39
+#define PD10 0x3A
+#define PD11 0x3B
+#define PD12 0x3C
+#define PD13 0x3D
+#define PD14 0x3E
+#define PD15 0x3F
+
+#define PE0 0x40
+#define PE1 0x41
+#define PE2 0x42
+#define PE3 0x43
+#define PE4 0x44
+#define PE5 0x45
+#define PE6 0x46
+#define PE7 0x47
+#define PE8 0x48
+#define PE9 0x49
+#define PE10 0x4A
+#define PE11 0x4B
+#define PE12 0x4C
+#define PE13 0x4D
+#define PE14 0x4E
+#define PE15 0x4F // 100 pins (F103V)
+
+#define PF0 0x50
+#define PF1 0x51
+#define PF2 0x52
+#define PF3 0x53
+#define PF4 0x54
+#define PF5 0x55
+#define PF6 0x56
+#define PF7 0x57
+#define PF8 0x58
+#define PF9 0x59
+#define PF10 0x5A
+#define PF11 0x5B
+#define PF12 0x5C
+#define PF13 0x5D
+#define PF14 0x5E
+#define PF15 0x5F
+
+#define PG0 0x60
+#define PG1 0x61
+#define PG2 0x62
+#define PG3 0x63
+#define PG4 0x64
+#define PG5 0x65
+#define PG6 0x66
+#define PG7 0x67
+#define PG8 0x68
+#define PG9 0x69
+#define PG10 0x6A
+#define PG11 0x6B
+#define PG12 0x6C
+#define PG13 0x6D
+#define PG14 0x6E
+#define PG15 0x6F // 144 pins (F103Z)
diff --git a/Marlin/src/HAL/HAL_STM32F1/fastio_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/fastio_STM32F1.h
deleted file mode 100644
index ad225a8f9a..0000000000
--- a/Marlin/src/HAL/HAL_STM32F1/fastio_STM32F1.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Fast I/O interfaces for STM32F1
- * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
- */
-
-#include
-
-#define READ(IO) (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
-#define WRITE(IO,V) (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << (16 * !((bool)V)))
-#define TOGGLE(IO) (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
-#define WRITE_VAR(IO,V) WRITE(IO,V)
-
-#define _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
-#define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
-#define _SET_OUTPUT(IO) _SET_MODE(IO, GPIO_OUTPUT_PP)
-#define _SET_OUTPUT_OD(IO) _SET_MODE(IO, GPIO_OUTPUT_OD)
-
-#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); } while(0)
-#define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); } while(0)
-
-#define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING)
-#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU)
-#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
-#define SET_PWM(IO) pinMode(IO, PWM) // do{ gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, GPIO_AF_OUTPUT_PP); timer_set_mode(PIN_MAP[pin].timer_device, PIN_MAP[pin].timer_channel, TIMER_PWM); }while(0)
-#define SET_PWM_OD(IO) pinMode(IO, PWM_OPEN_DRAIN)
-
-#define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
-#define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP)
-
-#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr)
-
-// digitalRead/Write wrappers
-#define extDigitalRead(IO) digitalRead(IO)
-#define extDigitalWrite(IO,V) digitalWrite(IO,V)
-
diff --git a/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h b/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h
new file mode 100644
index 0000000000..f356c0da07
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h
@@ -0,0 +1,38 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Test STM32F1-specific configuration values for errors at compile-time.
+ */
+
+#if ENABLED(EMERGENCY_PARSER)
+ #error "EMERGENCY_PARSER is not yet implemented for STM32F1. Disable EMERGENCY_PARSER to continue."
+#endif
+
+#if ENABLED(SDIO_SUPPORT) && DISABLED(SDSUPPORT)
+ #error "SDIO_SUPPORT requires SDSUPPORT. Enable SDSUPPORT to continue."
+#endif
+
+#if ENABLED(FAST_PWM_FAN)
+ #error "FAST_PWM_FAN is not yet implemented for this platform."
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F1/maple_win_usb_driver/maple_serial.inf b/Marlin/src/HAL/HAL_STM32F1/maple_win_usb_driver/maple_serial.inf
new file mode 100644
index 0000000000..c39f4ce0ed
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/maple_win_usb_driver/maple_serial.inf
@@ -0,0 +1,56 @@
+;
+; STMicroelectronics Communication Device Class driver installation file
+; (C)2006 Copyright STMicroelectronics
+;
+
+[Version]
+Signature="$Windows NT$"
+Class=Ports
+ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
+Provider=%STM%
+LayoutFile=layout.inf
+
+[Manufacturer]
+%MFGNAME%=VirComDevice,NT,NTamd64
+
+[DestinationDirs]
+DefaultDestDir = 12
+
+[VirComDevice.NT]
+%DESCRIPTION%=DriverInstall,USB\VID_1EAF&PID_0029&MI_01
+%DESCRIPTION%=DriverInstall,USB\VID_1EAF&PID_0029&MI_01
+
+[VirComDevice.NTamd64]
+%DESCRIPTION%=DriverInstall,USB\VID_1EAF&PID_0029&MI_01
+%DESCRIPTION%=DriverInstall,USB\VID_1EAF&PID_0029&MI_01
+
+[DriverInstall.NT]
+Include=mdmcpq.inf
+CopyFiles=FakeModemCopyFileSection
+AddReg=DriverInstall.NT.AddReg
+
+[DriverInstall.NT.AddReg]
+HKR,,DevLoader,,*ntkern
+HKR,,NTMPDriver,,usbser.sys
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
+
+[DriverInstall.NT.Services]
+AddService=usbser, 0x00000002, DriverServiceInst
+
+[DriverServiceInst]
+DisplayName=%SERVICE%
+ServiceType=1
+StartType=3
+ErrorControl=1
+ServiceBinary=%12%\usbser.sys
+
+;------------------------------------------------------------------------------
+; String Definitions
+;------------------------------------------------------------------------------
+
+
+[Strings]
+STM = "LeafLabs"
+MFGNAME = "LeafLabs"
+DESCRIPTION = "Maple R3"
+SERVICE = "USB Virtual COM port"
diff --git a/Marlin/src/HAL/HAL_STM32F1/msc_sd.cpp b/Marlin/src/HAL/HAL_STM32F1/msc_sd.cpp
new file mode 100644
index 0000000000..81e430fa2a
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/msc_sd.cpp
@@ -0,0 +1,64 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#ifdef USE_USB_COMPOSITE
+
+#include "msc_sd.h"
+#include "SPI.h"
+
+#define PRODUCT_ID 0x29
+
+USBMassStorage MarlinMSC;
+USBCompositeSerial MarlinCompositeSerial;
+
+#include "../../inc/MarlinConfig.h"
+
+#ifdef HAS_ONBOARD_SD
+
+ #include "onboard_sd.h"
+
+ static bool MSC_Write(const uint8_t *writebuff, uint32_t startSector, uint16_t numSectors) {
+ return (disk_write(0, writebuff, startSector, numSectors) == RES_OK);
+ }
+ static bool MSC_Read(uint8_t *readbuff, uint32_t startSector, uint16_t numSectors) {
+ return (disk_read(0, readbuff, startSector, numSectors) == RES_OK);
+ }
+
+#endif
+
+void MSC_SD_init() {
+ USBComposite.setProductId(PRODUCT_ID);
+ // Just set MarlinCompositeSerial enabled to true
+ // because when MarlinCompositeSerial.begin() is used in setup()
+ // it clears all USBComposite devices.
+ MarlinCompositeSerial.begin();
+ USBComposite.end();
+ USBComposite.clear();
+ // Set api and register mass storage
+ #ifdef HAS_ONBOARD_SD
+ uint32_t cardSize;
+ if (disk_initialize(0) == RES_OK) {
+ if (disk_ioctl(0, GET_SECTOR_COUNT, (void *)(&cardSize)) == RES_OK) {
+ MarlinMSC.setDriveData(0, cardSize, MSC_Read, MSC_Write);
+ MarlinMSC.registerComponent();
+ }
+ }
+ #endif
+ // Register composite Serial
+ MarlinCompositeSerial.registerComponent();
+ USBComposite.begin();
+}
+
+#endif // USE_USB_COMPOSITE
diff --git a/Marlin/src/HAL/HAL_STM32F1/msc_sd.h b/Marlin/src/HAL/HAL_STM32F1/msc_sd.h
new file mode 100644
index 0000000000..9f06ca5fdb
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/msc_sd.h
@@ -0,0 +1,23 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+
+extern USBMassStorage MarlinMSC;
+extern USBCompositeSerial MarlinCompositeSerial;
+
+void MSC_SD_init();
diff --git a/Marlin/src/HAL/HAL_STM32F1/onboard_sd.cpp b/Marlin/src/HAL/HAL_STM32F1/onboard_sd.cpp
new file mode 100644
index 0000000000..6e9432896d
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/onboard_sd.cpp
@@ -0,0 +1,556 @@
+/**
+ * STM32F1: MMCv3/SDv1/SDv2 (SPI mode) control module
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
+ * Copyright (C) 2015, ChaN, all right reserved.
+ *
+ * This software is a free software and there is NO WARRANTY.
+ * No restriction on use. You can use, modify and redistribute it for
+ * personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
+ * Redistributions of source code must retain the above copyright notice.
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#ifdef HAS_ONBOARD_SD
+
+#include "onboard_sd.h"
+#include "SPI.h"
+#include "fastio.h"
+
+#ifdef SHARED_SD_CARD
+ #ifndef ON_BOARD_SPI_DEVICE
+ #define ON_BOARD_SPI_DEVICE SPI_DEVICE
+ #endif
+ #define ONBOARD_SD_SPI SPI
+#else
+ SPIClass OnBoardSPI(ON_BOARD_SPI_DEVICE);
+ #define ONBOARD_SD_SPI OnBoardSPI
+#endif
+
+#if ON_BOARD_SPI_DEVICE == 1
+ #define SPI_CLOCK_MAX SPI_BAUD_PCLK_DIV_4
+#else
+ #define SPI_CLOCK_MAX SPI_BAUD_PCLK_DIV_2
+#endif
+
+#define CS_LOW() {WRITE(ONBOARD_SD_CS_PIN, LOW);} /* Set OnBoardSPI cs low */
+#define CS_HIGH() {WRITE(ONBOARD_SD_CS_PIN, HIGH);} /* Set OnBoardSPI cs high */
+
+#define FCLK_FAST() ONBOARD_SD_SPI.setClockDivider(SPI_CLOCK_MAX)
+#define FCLK_SLOW() ONBOARD_SD_SPI.setClockDivider(SPI_BAUD_PCLK_DIV_256)
+
+/*--------------------------------------------------------------------------
+ Module Private Functions
+---------------------------------------------------------------------------*/
+
+/* MMC/SD command */
+#define CMD0 (0) /* GO_IDLE_STATE */
+#define CMD1 (1) /* SEND_OP_COND (MMC) */
+#define ACMD41 (0x80+41) /* SEND_OP_COND (SDC) */
+#define CMD8 (8) /* SEND_IF_COND */
+#define CMD9 (9) /* SEND_CSD */
+#define CMD10 (10) /* SEND_CID */
+#define CMD12 (12) /* STOP_TRANSMISSION */
+#define ACMD13 (0x80+13) /* SD_STATUS (SDC) */
+#define CMD16 (16) /* SET_BLOCKLEN */
+#define CMD17 (17) /* READ_SINGLE_BLOCK */
+#define CMD18 (18) /* READ_MULTIPLE_BLOCK */
+#define CMD23 (23) /* SET_BLOCK_COUNT (MMC) */
+#define ACMD23 (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */
+#define CMD24 (24) /* WRITE_BLOCK */
+#define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */
+#define CMD32 (32) /* ERASE_ER_BLK_START */
+#define CMD33 (33) /* ERASE_ER_BLK_END */
+#define CMD38 (38) /* ERASE */
+#define CMD48 (48) /* READ_EXTR_SINGLE */
+#define CMD49 (49) /* WRITE_EXTR_SINGLE */
+#define CMD55 (55) /* APP_CMD */
+#define CMD58 (58) /* READ_OCR */
+
+static volatile DSTATUS Stat = STA_NOINIT; /* Physical drive status */
+static volatile UINT timeout;
+static BYTE CardType; /* Card type flags */
+
+/*-----------------------------------------------------------------------*/
+/* Send/Receive data to the MMC (Platform dependent) */
+/*-----------------------------------------------------------------------*/
+
+/* Exchange a byte */
+static BYTE xchg_spi (
+ BYTE dat /* Data to send */
+) {
+ BYTE returnByte = ONBOARD_SD_SPI.transfer(dat);
+ return returnByte;
+}
+
+/* Receive multiple byte */
+static void rcvr_spi_multi (
+ BYTE *buff, /* Pointer to data buffer */
+ UINT btr /* Number of bytes to receive (16, 64 or 512) */
+) {
+ ONBOARD_SD_SPI.dmaTransfer(0, const_cast(buff), btr);
+}
+
+#if _DISKIO_WRITE
+
+ /* Send multiple bytes */
+ static void xmit_spi_multi (
+ const BYTE *buff, /* Pointer to the data */
+ UINT btx /* Number of bytes to send (multiple of 16) */
+ ) {
+ ONBOARD_SD_SPI.dmaSend(const_cast(buff), btx);
+ }
+
+#endif // _DISKIO_WRITE
+
+/*-----------------------------------------------------------------------*/
+/* Wait for card ready */
+/*-----------------------------------------------------------------------*/
+
+static int wait_ready ( /* 1:Ready, 0:Timeout */
+ UINT wt /* Timeout [ms] */
+) {
+ BYTE d;
+
+ timeout = millis() + wt;
+ do {
+ d = xchg_spi(0xFF);
+ /* This loop takes a while. Insert rot_rdq() here for multitask environment. */
+ } while (d != 0xFF && (timeout > millis())); /* Wait for card goes ready or timeout */
+
+ return (d == 0xFF) ? 1 : 0;
+}
+
+/*-----------------------------------------------------------------------*/
+/* Deselect card and release SPI */
+/*-----------------------------------------------------------------------*/
+
+static void deselect() {
+ CS_HIGH(); /* CS = H */
+ xchg_spi(0xFF); /* Dummy clock (force DO hi-z for multiple slave SPI) */
+}
+
+/*-----------------------------------------------------------------------*/
+/* Select card and wait for ready */
+/*-----------------------------------------------------------------------*/
+
+static int select() { /* 1:OK, 0:Timeout */
+ CS_LOW(); /* CS = L */
+ xchg_spi(0xFF); /* Dummy clock (force DO enabled) */
+
+ if (wait_ready(500)) return 1; /* Leading busy check: Wait for card ready */
+
+ deselect(); /* Timeout */
+ return 0;
+}
+
+/*-----------------------------------------------------------------------*/
+/* Control SPI module (Platform dependent) */
+/*-----------------------------------------------------------------------*/
+
+static void power_on() { /* Enable SSP module and attach it to I/O pads */
+ ONBOARD_SD_SPI.setModule(ON_BOARD_SPI_DEVICE);
+ ONBOARD_SD_SPI.begin();
+ ONBOARD_SD_SPI.setBitOrder(MSBFIRST);
+ ONBOARD_SD_SPI.setDataMode(SPI_MODE0);
+ OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH); /* Set CS# high */
+}
+
+static void power_off() { /* Disable SPI function */
+ select(); /* Wait for card ready */
+ deselect();
+}
+
+/*-----------------------------------------------------------------------*/
+/* Receive a data packet from the MMC */
+/*-----------------------------------------------------------------------*/
+
+static int rcvr_datablock ( /* 1:OK, 0:Error */
+ BYTE *buff, /* Data buffer */
+ UINT btr /* Data block length (byte) */
+) {
+ BYTE token;
+
+ timeout = millis() + 200;
+ do { /* Wait for DataStart token in timeout of 200ms */
+ token = xchg_spi(0xFF);
+ /* This loop will take a while. Insert rot_rdq() here for multitask environment. */
+ } while ((token == 0xFF) && (timeout > millis()));
+ if (token != 0xFE) return 0; /* Function fails if invalid DataStart token or timeout */
+
+ rcvr_spi_multi(buff, btr); /* Store trailing data to the buffer */
+ xchg_spi(0xFF); xchg_spi(0xFF); /* Discard CRC */
+
+ return 1; /* Function succeeded */
+}
+
+/*-----------------------------------------------------------------------*/
+/* Send a data packet to the MMC */
+/*-----------------------------------------------------------------------*/
+
+#if _DISKIO_WRITE
+
+ static int xmit_datablock ( /* 1:OK, 0:Failed */
+ const BYTE *buff, /* Ponter to 512 byte data to be sent */
+ BYTE token /* Token */
+ ) {
+ BYTE resp;
+
+ if (!wait_ready(500)) return 0; /* Leading busy check: Wait for card ready to accept data block */
+
+ xchg_spi(token); /* Send token */
+ if (token == 0xFD) return 1; /* Do not send data if token is StopTran */
+
+ xmit_spi_multi(buff, 512); /* Data */
+ xchg_spi(0xFF); xchg_spi(0xFF); /* Dummy CRC */
+
+ resp = xchg_spi(0xFF); /* Receive data resp */
+
+ return (resp & 0x1F) == 0x05 ? 1 : 0; /* Data was accepted or not */
+
+ /* Busy check is done at next transmission */
+ }
+
+#endif // _DISKIO_WRITE
+
+/*-----------------------------------------------------------------------*/
+/* Send a command packet to the MMC */
+/*-----------------------------------------------------------------------*/
+
+static BYTE send_cmd ( /* Return value: R1 resp (bit7==1:Failed to send) */
+ BYTE cmd, /* Command index */
+ DWORD arg /* Argument */
+) {
+ BYTE n, res;
+
+ if (cmd & 0x80) { /* Send a CMD55 prior to ACMD */
+ cmd &= 0x7F;
+ res = send_cmd(CMD55, 0);
+ if (res > 1) return res;
+ }
+
+ /* Select the card and wait for ready except to stop multiple block read */
+ if (cmd != CMD12) {
+ deselect();
+ if (!select()) return 0xFF;
+ }
+
+ /* Send command packet */
+ xchg_spi(0x40 | cmd); /* Start + command index */
+ xchg_spi((BYTE)(arg >> 24)); /* Argument[31..24] */
+ xchg_spi((BYTE)(arg >> 16)); /* Argument[23..16] */
+ xchg_spi((BYTE)(arg >> 8)); /* Argument[15..8] */
+ xchg_spi((BYTE)arg); /* Argument[7..0] */
+ n = 0x01; /* Dummy CRC + Stop */
+ if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */
+ if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */
+ xchg_spi(n);
+
+ /* Receive command resp */
+ if (cmd == CMD12) xchg_spi(0xFF); /* Diacard following one byte when CMD12 */
+ n = 10; /* Wait for response (10 bytes max) */
+ do
+ res = xchg_spi(0xFF);
+ while ((res & 0x80) && --n);
+
+ return res; /* Return received response */
+}
+
+/*--------------------------------------------------------------------------
+ Public Functions
+---------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------*/
+/* Initialize disk drive */
+/*-----------------------------------------------------------------------*/
+
+DSTATUS disk_initialize (
+ BYTE drv /* Physical drive number (0) */
+) {
+ BYTE n, cmd, ty, ocr[4];
+
+ if (drv) return STA_NOINIT; /* Supports only drive 0 */
+ power_on(); /* Initialize SPI */
+
+ if (Stat & STA_NODISK) return Stat; /* Is a card existing in the soket? */
+
+ FCLK_SLOW();
+ for (n = 10; n; n--) xchg_spi(0xFF); /* Send 80 dummy clocks */
+
+ ty = 0;
+ if (send_cmd(CMD0, 0) == 1) { /* Put the card SPI state */
+ timeout = millis() + 1000; /* Initialization timeout = 1 sec */
+ if (send_cmd(CMD8, 0x1AA) == 1) { /* Is the catd SDv2? */
+ for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); /* Get 32 bit return value of R7 resp */
+ if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* Does the card support 2.7-3.6V? */
+ while ((timeout > millis()) && send_cmd(ACMD41, 1UL << 30)) ; /* Wait for end of initialization with ACMD41(HCS) */
+ if ((timeout > millis()) && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
+ for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF);
+ ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* Check if the card is SDv2 */
+ }
+ }
+ } else { /* Not an SDv2 card */
+ if (send_cmd(ACMD41, 0) <= 1) { /* SDv1 or MMCv3? */
+ ty = CT_SD1; cmd = ACMD41; /* SDv1 (ACMD41(0)) */
+ } else {
+ ty = CT_MMC; cmd = CMD1; /* MMCv3 (CMD1(0)) */
+ }
+ while ((timeout > millis()) && send_cmd(cmd, 0)) ; /* Wait for the card leaves idle state */
+ if (!(timeout > millis()) || send_cmd(CMD16, 512) != 0) /* Set block length: 512 */
+ ty = 0;
+ }
+ }
+ CardType = ty; /* Card type */
+ deselect();
+
+ if (ty) { /* OK */
+ FCLK_FAST(); /* Set fast clock */
+ Stat &= ~STA_NOINIT; /* Clear STA_NOINIT flag */
+ } else { /* Failed */
+ power_off();
+ Stat = STA_NOINIT;
+ }
+
+ return Stat;
+}
+
+/*-----------------------------------------------------------------------*/
+/* Get disk status */
+/*-----------------------------------------------------------------------*/
+
+DSTATUS disk_status (
+ BYTE drv /* Physical drive number (0) */
+) {
+ if (drv) return STA_NOINIT; /* Supports only drive 0 */
+ return Stat; /* Return disk status */
+}
+
+/*-----------------------------------------------------------------------*/
+/* Read sector(s) */
+/*-----------------------------------------------------------------------*/
+
+DRESULT disk_read (
+ BYTE drv, /* Physical drive number (0) */
+ BYTE *buff, /* Pointer to the data buffer to store read data */
+ DWORD sector, /* Start sector number (LBA) */
+ UINT count /* Number of sectors to read (1..128) */
+) {
+ BYTE cmd;
+
+ if (drv || !count) return RES_PARERR; /* Check parameter */
+ if (Stat & STA_NOINIT) return RES_NOTRDY; /* Check if drive is ready */
+ if (!(CardType & CT_BLOCK)) sector *= 512; /* LBA ot BA conversion (byte addressing cards) */
+ FCLK_FAST();
+ cmd = count > 1 ? CMD18 : CMD17; /* READ_MULTIPLE_BLOCK : READ_SINGLE_BLOCK */
+ if (send_cmd(cmd, sector) == 0) {
+ do {
+ if (!rcvr_datablock(buff, 512)) break;
+ buff += 512;
+ } while (--count);
+ if (cmd == CMD18) send_cmd(CMD12, 0); /* STOP_TRANSMISSION */
+ }
+ deselect();
+
+ return count ? RES_ERROR : RES_OK; /* Return result */
+}
+
+/*-----------------------------------------------------------------------*/
+/* Write sector(s) */
+/*-----------------------------------------------------------------------*/
+
+#if _DISKIO_WRITE
+
+ DRESULT disk_write(
+ BYTE drv, /* Physical drive number (0) */
+ const BYTE *buff, /* Ponter to the data to write */
+ DWORD sector, /* Start sector number (LBA) */
+ UINT count /* Number of sectors to write (1..128) */
+ ) {
+ if (drv || !count) return RES_PARERR; /* Check parameter */
+ if (Stat & STA_NOINIT) return RES_NOTRDY; /* Check drive status */
+ if (Stat & STA_PROTECT) return RES_WRPRT; /* Check write protect */
+ FCLK_FAST();
+ if (!(CardType & CT_BLOCK)) sector *= 512; /* LBA ==> BA conversion (byte addressing cards) */
+
+ if (count == 1) { /* Single sector write */
+ if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
+ && xmit_datablock(buff, 0xFE)) {
+ count = 0;
+ }
+ }
+ else { /* Multiple sector write */
+ if (CardType & CT_SDC) send_cmd(ACMD23, count); /* Predefine number of sectors */
+ if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
+ do {
+ if (!xmit_datablock(buff, 0xFC)) break;
+ buff += 512;
+ } while (--count);
+ if (!xmit_datablock(0, 0xFD)) count = 1; /* STOP_TRAN token */
+ }
+ }
+ deselect();
+
+ return count ? RES_ERROR : RES_OK; /* Return result */
+ }
+
+#endif // _DISKIO_WRITE
+
+/*-----------------------------------------------------------------------*/
+/* Miscellaneous drive controls other than data read/write */
+/*-----------------------------------------------------------------------*/
+
+#if _DISKIO_IOCTL
+
+ DRESULT disk_ioctl (
+ BYTE drv, /* Physical drive number (0) */
+ BYTE cmd, /* Control command code */
+ void *buff /* Pointer to the conrtol data */
+ ) {
+ DRESULT res;
+ BYTE n, csd[16], *ptr = (BYTE *)buff;
+ DWORD *dp, st, ed, csize;
+ #if _DISKIO_ISDIO
+ SDIO_CMD *sdio = buff;
+ BYTE rc, *buf;
+ UINT dc;
+ #endif
+
+ if (drv) return RES_PARERR; /* Check parameter */
+ if (Stat & STA_NOINIT) return RES_NOTRDY; /* Check if drive is ready */
+
+ res = RES_ERROR;
+ FCLK_FAST();
+ switch (cmd) {
+ case CTRL_SYNC: /* Wait for end of internal write process of the drive */
+ if (select()) res = RES_OK;
+ break;
+
+ case GET_SECTOR_COUNT: /* Get drive capacity in unit of sector (DWORD) */
+ if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
+ if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */
+ csize = csd[9] + ((WORD)csd[8] << 8) + ((DWORD)(csd[7] & 63) << 16) + 1;
+ *(DWORD*)buff = csize << 10;
+ } else { /* SDC ver 1.XX or MMC ver 3 */
+ n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
+ csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1;
+ *(DWORD*)buff = csize << (n - 9);
+ }
+ res = RES_OK;
+ }
+ break;
+
+ case GET_BLOCK_SIZE: /* Get erase block size in unit of sector (DWORD) */
+ if (CardType & CT_SD2) { /* SDC ver 2.00 */
+ if (send_cmd(ACMD13, 0) == 0) { /* Read SD status */
+ xchg_spi(0xFF);
+ if (rcvr_datablock(csd, 16)) { /* Read partial block */
+ for (n = 64 - 16; n; n--) xchg_spi(0xFF); /* Purge trailing data */
+ *(DWORD*)buff = 16UL << (csd[10] >> 4);
+ res = RES_OK;
+ }
+ }
+ } else { /* SDC ver 1.XX or MMC */
+ if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { /* Read CSD */
+ if (CardType & CT_SD1) { /* SDC ver 1.XX */
+ *(DWORD*)buff = (((csd[10] & 63) << 1) + ((WORD)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1);
+ } else { /* MMC */
+ *(DWORD*)buff = ((WORD)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1);
+ }
+ res = RES_OK;
+ }
+ }
+ break;
+
+ case CTRL_TRIM: /* Erase a block of sectors (used when _USE_TRIM in ffconf.h is 1) */
+ if (!(CardType & CT_SDC)) break; /* Check if the card is SDC */
+ if (disk_ioctl(drv, MMC_GET_CSD, csd)) break; /* Get CSD */
+ if (!(csd[0] >> 6) && !(csd[10] & 0x40)) break; /* Check if sector erase can be applied to the card */
+ dp = (DWORD *)buff; st = dp[0]; ed = dp[1]; /* Load sector block */
+ if (!(CardType & CT_BLOCK)) {
+ st *= 512; ed *= 512;
+ }
+ if (send_cmd(CMD32, st) == 0 && send_cmd(CMD33, ed) == 0 && send_cmd(CMD38, 0) == 0 && wait_ready(30000)) { /* Erase sector block */
+ res = RES_OK; /* FatFs does not check result of this command */
+ }
+ break;
+
+ /* Following commands are never used by FatFs module */
+
+ case MMC_GET_TYPE: /* Get MMC/SDC type (BYTE) */
+ *ptr = CardType;
+ res = RES_OK;
+ break;
+
+ case MMC_GET_CSD: /* Read CSD (16 bytes) */
+ if (send_cmd(CMD9, 0) == 0 && rcvr_datablock(ptr, 16)) { /* READ_CSD */
+ res = RES_OK;
+ }
+ break;
+
+ case MMC_GET_CID: /* Read CID (16 bytes) */
+ if (send_cmd(CMD10, 0) == 0 && rcvr_datablock(ptr, 16)) { /* READ_CID */
+ res = RES_OK;
+ }
+ break;
+
+ case MMC_GET_OCR: /* Read OCR (4 bytes) */
+ if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
+ for (n = 4; n; n--) *ptr++ = xchg_spi(0xFF);
+ res = RES_OK;
+ }
+ break;
+
+ case MMC_GET_SDSTAT: /* Read SD status (64 bytes) */
+ if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */
+ xchg_spi(0xFF);
+ if (rcvr_datablock(ptr, 64)) res = RES_OK;
+ }
+ break;
+
+ #if _DISKIO_ISDIO
+
+ case ISDIO_READ:
+ sdio = buff;
+ if (send_cmd(CMD48, 0x80000000 | sdio->func << 28 | sdio->addr << 9 | ((sdio->ndata - 1) & 0x1FF)) == 0) {
+ for (Timer1 = 1000; (rc = xchg_spi(0xFF)) == 0xFF && Timer1; ) ;
+ if (rc == 0xFE) {
+ for (buf = sdio->data, dc = sdio->ndata; dc; dc--) *buf++ = xchg_spi(0xFF);
+ for (dc = 514 - sdio->ndata; dc; dc--) xchg_spi(0xFF);
+ res = RES_OK;
+ }
+ }
+ break;
+ case ISDIO_WRITE:
+ sdio = buff;
+ if (send_cmd(CMD49, 0x80000000 | sdio->func << 28 | sdio->addr << 9 | ((sdio->ndata - 1) & 0x1FF)) == 0) {
+ xchg_spi(0xFF); xchg_spi(0xFE);
+ for (buf = sdio->data, dc = sdio->ndata; dc; dc--) xchg_spi(*buf++);
+ for (dc = 514 - sdio->ndata; dc; dc--) xchg_spi(0xFF);
+ if ((xchg_spi(0xFF) & 0x1F) == 0x05) res = RES_OK;
+ }
+ break;
+ case ISDIO_MRITE:
+ sdio = buff;
+ if (send_cmd(CMD49, 0x84000000 | sdio->func << 28 | sdio->addr << 9 | sdio->ndata >> 8) == 0) {
+ xchg_spi(0xFF); xchg_spi(0xFE);
+ xchg_spi(sdio->ndata);
+ for (dc = 513; dc; dc--) xchg_spi(0xFF);
+ if ((xchg_spi(0xFF) & 0x1F) == 0x05) res = RES_OK;
+ }
+ break;
+
+ #endif // _DISKIO_ISDIO
+
+ default: res = RES_PARERR;
+ }
+
+ deselect();
+ return res;
+ }
+
+#endif // _DISKIO_IOCTL
+
+#endif // HAS_ONBOARD_SD
diff --git a/Marlin/src/HAL/HAL_STM32F1/onboard_sd.h b/Marlin/src/HAL/HAL_STM32F1/onboard_sd.h
new file mode 100644
index 0000000000..ec73162ba1
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/onboard_sd.h
@@ -0,0 +1,96 @@
+/*-----------------------------------------------------------------------
+/ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+/ * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
+/ * Low level disk interface module include file (C)ChaN, 2015
+/-----------------------------------------------------------------------*/
+
+#pragma once
+
+#define _DISKIO_WRITE 1 /* 1: Enable disk_write function */
+#define _DISKIO_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
+#define _DISKIO_ISDIO 0 /* 1: Enable iSDIO control fucntion */
+
+typedef unsigned char BYTE;
+typedef unsigned short WORD;
+typedef unsigned long DWORD;
+typedef unsigned int UINT;
+
+/* Status of Disk Functions */
+typedef BYTE DSTATUS;
+
+/* Results of Disk Functions */
+typedef enum {
+ RES_OK = 0, /* 0: Successful */
+ RES_ERROR, /* 1: R/W Error */
+ RES_WRPRT, /* 2: Write Protected */
+ RES_NOTRDY, /* 3: Not Ready */
+ RES_PARERR /* 4: Invalid Parameter */
+} DRESULT;
+
+
+#if _DISKIO_ISDIO
+/* Command structure for iSDIO ioctl command */
+typedef struct {
+ BYTE func; /* Function number: 0..7 */
+ WORD ndata; /* Number of bytes to transfer: 1..512, or mask + data */
+ DWORD addr; /* Register address: 0..0x1FFFF */
+ void* data; /* Pointer to the data (to be written | read buffer) */
+} SDIO_CMD;
+#endif
+
+/*---------------------------------------*/
+/* Prototypes for disk control functions */
+
+DSTATUS disk_initialize(BYTE pdrv);
+DSTATUS disk_status(BYTE pdrv);
+DRESULT disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
+#if _DISKIO_WRITE
+ DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
+#endif
+#if _DISKIO_IOCTL
+ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff);
+#endif
+
+/* Disk Status Bits (DSTATUS) */
+#define STA_NOINIT 0x01 /* Drive not initialized */
+#define STA_NODISK 0x02 /* No medium in the drive */
+#define STA_PROTECT 0x04 /* Write protected */
+
+/* Command code for disk_ioctrl fucntion */
+
+/* Generic command (Used by FatFs) */
+#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
+#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
+#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
+#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
+#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
+
+/* Generic command (Not used by FatFs) */
+#define CTRL_FORMAT 5 /* Create physical format on the media */
+#define CTRL_POWER_IDLE 6 /* Put the device idle state */
+#define CTRL_POWER_OFF 7 /* Put the device off state */
+#define CTRL_LOCK 8 /* Lock media removal */
+#define CTRL_UNLOCK 9 /* Unlock media removal */
+#define CTRL_EJECT 10 /* Eject media */
+
+/* MMC/SDC specific ioctl command (Not used by FatFs) */
+#define MMC_GET_TYPE 50 /* Get card type */
+#define MMC_GET_CSD 51 /* Get CSD */
+#define MMC_GET_CID 52 /* Get CID */
+#define MMC_GET_OCR 53 /* Get OCR */
+#define MMC_GET_SDSTAT 54 /* Get SD status */
+#define ISDIO_READ 55 /* Read data form SD iSDIO register */
+#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
+#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
+
+/* ATA/CF specific ioctl command (Not used by FatFs) */
+#define ATA_GET_REV 60 /* Get F/W revision */
+#define ATA_GET_MODEL 61 /* Get model name */
+#define ATA_GET_SN 62 /* Get serial number */
+
+/* MMC card type flags (MMC_GET_TYPE) */
+#define CT_MMC 0x01 /* MMC ver 3 */
+#define CT_SD1 0x02 /* SD ver 1 */
+#define CT_SD2 0x04 /* SD ver 2 */
+#define CT_SDC (CT_SD1|CT_SD2) /* SD */
+#define CT_BLOCK 0x08 /* Block addressing */
diff --git a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
similarity index 72%
rename from Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp
rename to Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
index b67c76c4c1..babcdeaee3 100644
--- a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
@@ -1,10 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
- * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,15 +18,26 @@
*
*/
-#if defined(STM32GENERIC) && defined(STM32F4)
-
-#include "../shared/persistent_store_api.h"
+#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS)
+#if ENABLED(EEPROM_SETTINGS) && EITHER(SPI_EEPROM, I2C_EEPROM)
-bool PersistentStore::access_start() { return true; }
+#include "../shared/persistent_store_api.h"
+
+bool PersistentStore::access_start() {
+ #if ENABLED(SPI_EEPROM)
+ #if SPI_CHAN_EEPROM1 == 1
+ SET_OUTPUT(BOARD_SPI1_SCK_PIN);
+ SET_OUTPUT(BOARD_SPI1_MOSI_PIN);
+ SET_INPUT(BOARD_SPI1_MISO_PIN);
+ SET_OUTPUT(SPI_EEPROM1_CS);
+ #endif
+ spiInit(0);
+ #endif
+ return true;
+}
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
@@ -52,10 +60,10 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false;
}
-bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing) {
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
uint8_t c = eeprom_read_byte((uint8_t*)pos);
- if (writing) *value = c;
+ if (writing && value) *value = c;
crc16(crc, &c, 1);
pos++;
value++;
@@ -65,5 +73,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
size_t PersistentStore::capacity() { return E2END + 1; }
-#endif // EEPROM_SETTINGS
-#endif // STM32GENERIC && STM32F4
+#endif // EEPROM_SETTINGS && EITHER(SPI_EEPROM, I2C_EEPROM)
+#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
index aa03474d2b..8097a28487 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
@@ -42,7 +42,6 @@
// Store settings in the last two pages
// Flash pages must be erased before writing, so keep track.
bool firstWrite = false;
-uint32_t pageBase = EEPROM_START_ADDRESS;
bool PersistentStore::access_start() {
firstWrite = true;
@@ -55,7 +54,7 @@ bool PersistentStore::access_finish() {
return true;
}
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
FLASH_Status status;
if (firstWrite) {
@@ -67,42 +66,27 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t si
firstWrite = false;
}
- // First write full words
- int i = 0;
- int wordsToWrite = size / sizeof(uint16_t);
- uint16_t* wordBuffer = (uint16_t *)value;
- while (wordsToWrite) {
- status = FLASH_ProgramHalfWord(pageBase + pos + (i * 2), wordBuffer[i]);
- if (status != FLASH_COMPLETE) return true;
- wordsToWrite--;
- i++;
- }
-
- // Now, write any remaining single byte
- const uint16_t odd = size & 1;
- if (odd) {
- uint16_t temp = value[size - 1];
- status = FLASH_ProgramHalfWord(pageBase + pos + i, temp);
- if (status != FLASH_COMPLETE) return true;
+ for (size_t i = 0; i < size; i++) {
+ if (FLASH_ProgramHalfWord(EEPROM_PAGE0_BASE + (pos + i) * 2, value[i]) != FLASH_COMPLETE)
+ return true;
}
crc16(crc, value, size);
- pos += size + odd;
+ pos += size;
return false;
}
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
- for (uint16_t i = 0; i < size; i++) {
- byte* accessPoint = (byte*)(pageBase + pos + i);
- uint8_t c = *accessPoint;
- if (writing) value[i] = c;
- crc16(crc, &c, 1);
+ for (size_t i = 0; i < size; i++) {
+ uint8_t v = *(uint16_t *)(EEPROM_PAGE0_BASE + (pos + i) * 2);
+ if (writing) value[i] = v;
+ crc16(crc, &v, 1);
}
- pos += ((size + 1) & ~1); // i.e., size+(size&1), round up odd values
+ pos += size;
return false;
}
-size_t PersistentStore::capacity() { return E2END + 1; }
+size_t PersistentStore::capacity() { return size_t(E2END + 1); }
#endif // EEPROM_SETTINGS && EEPROM FLASH
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
index 5ef638263b..38d5803f58 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,22 +22,24 @@
/**
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
+ * Implementation of EEPROM settings in SD Card
*/
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
+#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
#include "../shared/persistent_store_api.h"
#ifndef E2END
- #define E2END 4095
+ #define E2END 0xFFF // 4KB
#endif
-#define HAL_STM32F1_EEPROM_SIZE (E2END + 1)
+#define HAL_EEPROM_SIZE (E2END + 1)
-static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
+#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
+static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
#if ENABLED(SDSUPPORT)
@@ -46,30 +48,30 @@ static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
#define EEPROM_FILENAME "eeprom.dat"
bool PersistentStore::access_start() {
- if (!card.isDetected()) return false;
+ if (!card.isMounted()) return false;
SdFile file, root = card.getroot();
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
- return false;
+ return true; // false aborts the save
- int16_t bytes_read = file.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
+ int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
if (bytes_read < 0) return false;
- for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
- HAL_STM32F1_eeprom_content[bytes_read] = 0xFF;
+ for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
+ HAL_eeprom_data[bytes_read] = 0xFF;
file.close();
return true;
}
bool PersistentStore::access_finish() {
- if (!card.isDetected()) return false;
+ if (!card.isMounted()) return false;
SdFile file, root = card.getroot();
- int16_t bytes_written = 0;
+ int bytes_written = 0;
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
- bytes_written = file.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
+ bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
file.close();
}
- return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
+ return (bytes_written == HAL_EEPROM_SIZE);
}
#else // !SDSUPPORT
@@ -78,9 +80,9 @@ static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
#endif // !SDSUPPORT
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
for (size_t i = 0; i < size; i++)
- HAL_STM32F1_eeprom_content[pos + i] = value[i];
+ HAL_eeprom_data[pos + i] = value[i];
crc16(crc, value, size);
pos += size;
return false;
@@ -88,7 +90,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t si
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
for (size_t i = 0; i < size; i++) {
- uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
+ uint8_t c = HAL_eeprom_data[pos + i];
if (writing) value[i] = c;
crc16(crc, &c, 1);
}
@@ -96,7 +98,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return false;
}
-size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; }
+size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
#endif // EEPROM_SETTINGS
diff --git a/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h b/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h
index e5022f79a4..a8b632870a 100644
--- a/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h
@@ -1 +1,27 @@
-#error Debug pins is not supported on this Platform!
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#ifdef NUM_DIGITAL_PINS // Only in ST's Arduino core (STM32duino, STM32Core)
+ #include "../HAL_STM32/pinsDebug_STM32duino.h"
+#elif defined(BOARD_NR_GPIO_PINS) // Only in STM32GENERIC (Maple)
+ #include "../HAL_STM32/pinsDebug_STM32GENERIC.h"
+#else
+ #error "M43 not supported for this board"
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/sdio.cpp
similarity index 90%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/sdio.cpp
index a6627f0e61..c1cab57a9e 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/sdio.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,13 +25,15 @@
#include
+#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
+
#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
-#include "HAL_sdio_STM32F1.h"
+#include "sdio.h"
SDIO_CardInfoTypeDef SdCard;
-bool SDIO_Init(void) {
+bool SDIO_Init() {
uint32_t count = 0U;
SdCard.CardType = SdCard.CardVersion = SdCard.Class = SdCard.RelCardAdd = SdCard.BlockNbr = SdCard.BlockSize = SdCard.LogBlockNbr = SdCard.LogBlockSize = 0;
@@ -40,7 +42,7 @@ bool SDIO_Init(void) {
dma_init(SDIO_DMA_DEV);
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
- dma_set_priority(SDIO_DMA_DEV, SDIO_DMA_CHANNEL, DMA_PRIORITY_VERY_HIGH);
+ dma_set_priority(SDIO_DMA_DEV, SDIO_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
if (!SDIO_CmdGoIdleState()) return false;
if (!SDIO_CmdGoIdleState()) return false; /* Hotplugged cards tends to miss first CMD0, so give them a second chance. */
@@ -105,7 +107,7 @@ bool SDIO_ReadBlock_DMA(uint32_t blockAddress, uint8_t *data) {
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
if (SDIO->STA & SDIO_STA_RXDAVL) {
- while (SDIO->STA & SDIO_STA_RXDAVL) (void) SDIO->FIFO;
+ while (SDIO->STA & SDIO_STA_RXDAVL) (void)SDIO->FIFO;
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
return false;
}
@@ -124,6 +126,8 @@ bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
return false;
}
+uint32_t millis();
+
bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
if (blockAddress >= SdCard.LogBlockNbr) return false;
@@ -163,21 +167,21 @@ bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
return false;
}
-inline uint32_t SDIO_GetCardState(void) { return SDIO_CmdSendStatus(SdCard.RelCardAdd << 16U) ? (SDIO_GetResponse(SDIO_RESP1) >> 9U) & 0x0FU : SDIO_CARD_ERROR; }
+inline uint32_t SDIO_GetCardState() { return SDIO_CmdSendStatus(SdCard.RelCardAdd << 16U) ? (SDIO_GetResponse(SDIO_RESP1) >> 9U) & 0x0FU : SDIO_CARD_ERROR; }
-// --------------------------------------------------------------------------
+// ------------------------
// SD Commands and Responses
-// --------------------------------------------------------------------------
+// ------------------------
void SDIO_SendCommand(uint16_t command, uint32_t argument) { SDIO->ARG = argument; SDIO->CMD = (uint32_t)(SDIO_CMD_CPSMEN | command); }
-uint8_t SDIO_GetCommandResponse(void) { return (uint8_t)(SDIO->RESPCMD); }
+uint8_t SDIO_GetCommandResponse() { return (uint8_t)(SDIO->RESPCMD); }
uint32_t SDIO_GetResponse(uint32_t response) { return SDIO->RESP[response]; }
-bool SDIO_CmdGoIdleState(void) { SDIO_SendCommand(CMD0_GO_IDLE_STATE, 0); return SDIO_GetCmdError(); }
-bool SDIO_CmdSendCID(void) { SDIO_SendCommand(CMD2_ALL_SEND_CID, 0); return SDIO_GetCmdResp2(); }
+bool SDIO_CmdGoIdleState() { SDIO_SendCommand(CMD0_GO_IDLE_STATE, 0); return SDIO_GetCmdError(); }
+bool SDIO_CmdSendCID() { SDIO_SendCommand(CMD2_ALL_SEND_CID, 0); return SDIO_GetCmdResp2(); }
bool SDIO_CmdSetRelAdd(uint32_t *rca) { SDIO_SendCommand(CMD3_SET_REL_ADDR, 0); return SDIO_GetCmdResp6(SDMMC_CMD_SET_REL_ADDR, rca); }
bool SDIO_CmdSelDesel(uint32_t address) { SDIO_SendCommand(CMD7_SEL_DESEL_CARD, address); return SDIO_GetCmdResp1(SDMMC_CMD_SEL_DESEL_CARD); }
-bool SDIO_CmdOperCond(void) { SDIO_SendCommand(CMD8_HS_SEND_EXT_CSD, SDMMC_CHECK_PATTERN); return SDIO_GetCmdResp7(); }
+bool SDIO_CmdOperCond() { SDIO_SendCommand(CMD8_HS_SEND_EXT_CSD, SDMMC_CHECK_PATTERN); return SDIO_GetCmdResp7(); }
bool SDIO_CmdSendCSD(uint32_t argument) { SDIO_SendCommand(CMD9_SEND_CSD, argument); return SDIO_GetCmdResp2(); }
bool SDIO_CmdSendStatus(uint32_t argument) { SDIO_SendCommand(CMD13_SEND_STATUS, argument); return SDIO_GetCmdResp1(SDMMC_CMD_SEND_STATUS); }
bool SDIO_CmdReadSingleBlock(uint32_t address) { SDIO_SendCommand(CMD17_READ_SINGLE_BLOCK, address); return SDIO_GetCmdResp1(SDMMC_CMD_READ_SINGLE_BLOCK); }
@@ -208,7 +212,7 @@ bool SDIO_CmdAppSetClearCardDetect(uint32_t rsa) {
do { if (!--count) return false; } while (!SDIO_GET_FLAG(FLAGS)); \
}while(0)
-bool SDIO_GetCmdError(void) {
+bool SDIO_GetCmdError() {
SDIO_WAIT(SDIO_STA_CMDSENT);
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS);
@@ -228,7 +232,7 @@ bool SDIO_GetCmdResp1(uint8_t command) {
return (SDIO_GetResponse(SDIO_RESP1) & SDMMC_OCR_ERRORBITS) == SDMMC_ALLZERO;
}
-bool SDIO_GetCmdResp2(void) {
+bool SDIO_GetCmdResp2() {
SDIO_WAIT(SDIO_STA_CCRCFAIL | SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT);
if (SDIO_GET_FLAG(SDIO_STA_CCRCFAIL | SDIO_STA_CTIMEOUT)) {
@@ -240,7 +244,7 @@ bool SDIO_GetCmdResp2(void) {
return true;
}
-bool SDIO_GetCmdResp3(void) {
+bool SDIO_GetCmdResp3() {
SDIO_WAIT(SDIO_STA_CCRCFAIL | SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT);
if (SDIO_GET_FLAG(SDIO_STA_CTIMEOUT)) {
@@ -268,7 +272,7 @@ bool SDIO_GetCmdResp6(uint8_t command, uint32_t *rca) {
return true;
}
-bool SDIO_GetCmdResp7(void) {
+bool SDIO_GetCmdResp7() {
SDIO_WAIT(SDIO_STA_CCRCFAIL | SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT);
if (SDIO_GET_FLAG(SDIO_STA_CTIMEOUT)) {
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/sdio.h
similarity index 88%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/sdio.h
index bb48b3beda..ca0aced695 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/sdio.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2017 Victor Perez
*
@@ -21,18 +21,14 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../shared/Marduino.h"
-#include "libmaple/sdio.h"
-#include "libmaple/dma.h"
+#include
+#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define SDMMC_CMD_GO_IDLE_STATE ((uint8_t)0) /* Resets the SD memory card. */
#define SDMMC_CMD_ALL_SEND_CID ((uint8_t)2) /* Asks any card connected to the host to send the CID numbers on the CMD line. */
@@ -106,9 +102,9 @@
#define SDIO_CLOCK 18000000 /* 18 MHz */
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
uint32_t CardType; // Card Type
@@ -121,17 +117,17 @@ typedef struct {
uint32_t LogBlockSize; // Logical block size in bytes
} SDIO_CardInfoTypeDef;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-inline uint32_t SDIO_GetCardState(void);
+inline uint32_t SDIO_GetCardState();
-bool SDIO_CmdGoIdleState(void);
-bool SDIO_CmdSendCID(void);
+bool SDIO_CmdGoIdleState();
+bool SDIO_CmdSendCID();
bool SDIO_CmdSetRelAdd(uint32_t *rca);
bool SDIO_CmdSelDesel(uint32_t address);
-bool SDIO_CmdOperCond(void);
+bool SDIO_CmdOperCond();
bool SDIO_CmdSendCSD(uint32_t argument);
bool SDIO_CmdSendStatus(uint32_t argument);
bool SDIO_CmdReadSingleBlock(uint32_t address);
@@ -143,11 +139,11 @@ bool SDIO_CmdAppOperCommand(uint32_t sdType);
bool SDIO_CmdAppSetClearCardDetect(uint32_t rsa);
void SDIO_SendCommand(uint16_t command, uint32_t argument);
-uint8_t SDIO_GetCommandResponse(void);
+uint8_t SDIO_GetCommandResponse();
uint32_t SDIO_GetResponse(uint32_t response);
-bool SDIO_GetCmdError(void);
+bool SDIO_GetCmdError();
bool SDIO_GetCmdResp1(uint8_t command);
-bool SDIO_GetCmdResp2(void);
-bool SDIO_GetCmdResp3(void);
+bool SDIO_GetCmdResp2();
+bool SDIO_GetCmdResp3();
bool SDIO_GetCmdResp6(uint8_t command, uint32_t *rca);
-bool SDIO_GetCmdResp7(void);
+bool SDIO_GetCmdResp7();
diff --git a/Marlin/src/HAL/HAL_STM32F1/spi_pins.h b/Marlin/src/HAL/HAL_STM32F1/spi_pins.h
index 97005a309e..edea89cc7d 100644
--- a/Marlin/src/HAL/HAL_STM32F1/spi_pins.h
+++ b/Marlin/src/HAL/HAL_STM32F1/spi_pins.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,11 +23,36 @@
*/
/**
- * Define SPI Pins: SCK, MISO, MOSI, SS
+ * STM32F1 Default SPI Pins
*
- * Any PIN can be used for Chip Select (SS)
+ * SS SCK MISO MOSI
+ * +-----------------------------+
+ * SPI1 | PA4 PA5 PA6 PA7 |
+ * SPI2 | PB12 PB13 PB14 PB15 |
+ * SPI3 | PA15 PB3 PB4 PB5 |
+ * +-----------------------------+
+ * Any pin can be used for Chip Select (SS_PIN)
+ * SPI1 is enabled by default
*/
-#define SCK_PIN PA5
-#define MISO_PIN PA6
-#define MOSI_PIN PA7
-#define SS_PIN PA4
+#ifndef SCK_PIN
+ #define SCK_PIN PA5
+#endif
+#ifndef MISO_PIN
+ #define MISO_PIN PA6
+#endif
+#ifndef MOSI_PIN
+ #define MOSI_PIN PA7
+#endif
+#ifndef SS_PIN
+ #define SS_PIN PA4
+#endif
+#undef SDSS
+#define SDSS SS_PIN
+
+#if ENABLED(ENABLE_SPI3)
+ #define SPI_DEVICE 3
+#elif ENABLED(ENABLE_SPI2)
+ #define SPI_DEVICE 2
+#else
+ #define SPI_DEVICE 1
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/timers.cpp
similarity index 61%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/timers.cpp
index 866f5c2e26..a1f5f1e453 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/timers.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -26,61 +26,17 @@
#ifdef __STM32F1__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
+#include "../../inc/MarlinConfig.h"
#include "HAL.h"
+#include "timers.h"
-#include "HAL_timers_STM32F1.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
-#define NUM_HARDWARE_TIMERS 4
-
-//#define PRESCALER 1
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-/* VGPV
-const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
- { TC0, 0, TC0_IRQn, 0}, // 0 - [servo timer5]
- { TC0, 1, TC1_IRQn, 0}, // 1
- { TC0, 2, TC2_IRQn, 0}, // 2
- { TC1, 0, TC3_IRQn, 2}, // 3 - stepper
- { TC1, 1, TC4_IRQn, 15}, // 4 - temperature
- { TC1, 2, TC5_IRQn, 0}, // 5 - [servo timer3]
- { TC2, 0, TC6_IRQn, 0}, // 6
- { TC2, 1, TC7_IRQn, 0}, // 7
- { TC2, 2, TC8_IRQn, 0}, // 8
-};
-*/
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
/**
* Timer_clock1: Prescaler 2 -> 36 MHz
@@ -101,11 +57,14 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
case 3: irq_num = NVIC_TIMER3; break;
case 4: irq_num = NVIC_TIMER4; break;
case 5: irq_num = NVIC_TIMER5; break;
+ #if ENABLED(STM32_HIGH_DENSITY)
+ // 6 & 7 are basic timers, avoid them
+ case 8: irq_num = NVIC_TIMER8_CC; break;
+ #endif
default:
/**
- * We should not get here, add Sanitycheck for timer number. Should be a general timer
- * since basic timers do not have CC channels.
- * Advanced timers should be skipped if possible too, and are not listed above.
+ * This should never happen. Add a Sanitycheck for timer number.
+ * Should be a general timer since basic timers have no CC channels.
*/
break;
}
@@ -118,23 +77,27 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
switch (timer_num) {
case STEP_TIMER_NUM:
timer_pause(STEP_TIMER_DEV);
+ timer_set_mode(STEP_TIMER_DEV, STEP_TIMER_CHAN, TIMER_OUTPUT_COMPARE); // counter
timer_set_count(STEP_TIMER_DEV, 0);
timer_set_prescaler(STEP_TIMER_DEV, (uint16_t)(STEPPER_TIMER_PRESCALE - 1));
timer_set_reload(STEP_TIMER_DEV, 0xFFFF);
- timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE / frequency)));
+ timer_oc_set_mode(STEP_TIMER_DEV, STEP_TIMER_CHAN, TIMER_OC_MODE_FROZEN, TIMER_OC_NO_PRELOAD); // no output pin change
+ timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE / frequency)));
+ timer_no_ARR_preload_ARPE(STEP_TIMER_DEV); // Need to be sure no preload on ARR register
timer_attach_interrupt(STEP_TIMER_DEV, STEP_TIMER_CHAN, stepTC_Handler);
- nvic_irq_set_priority(irq_num, 1);
+ nvic_irq_set_priority(irq_num, STEP_TIMER_IRQ_PRIO);
timer_generate_update(STEP_TIMER_DEV);
timer_resume(STEP_TIMER_DEV);
break;
case TEMP_TIMER_NUM:
timer_pause(TEMP_TIMER_DEV);
+ timer_set_mode(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, TIMER_OUTPUT_COMPARE);
timer_set_count(TEMP_TIMER_DEV, 0);
timer_set_prescaler(TEMP_TIMER_DEV, (uint16_t)(TEMP_TIMER_PRESCALE - 1));
timer_set_reload(TEMP_TIMER_DEV, 0xFFFF);
- timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), ((F_CPU / TEMP_TIMER_PRESCALE) / frequency)));
+ timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), ((F_CPU / TEMP_TIMER_PRESCALE) / frequency)));
timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler);
- nvic_irq_set_priority(irq_num, 2);
+ nvic_irq_set_priority(irq_num, TEMP_TIMER_IRQ_PRIO);
timer_generate_update(TEMP_TIMER_DEV);
timer_resume(TEMP_TIMER_DEV);
break;
@@ -145,7 +108,6 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: ENABLE_STEPPER_DRIVER_INTERRUPT(); break;
case TEMP_TIMER_NUM: ENABLE_TEMPERATURE_INTERRUPT(); break;
- default: break;
}
}
@@ -153,12 +115,11 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: DISABLE_STEPPER_DRIVER_INTERRUPT(); break;
case TEMP_TIMER_NUM: DISABLE_TEMPERATURE_INTERRUPT(); break;
- default: break;
}
}
static inline bool timer_irq_enabled(const timer_dev * const dev, const uint8_t interrupt) {
- return bool(*bb_perip(&(dev->regs).adv->DIER, interrupt));
+ return bool(*bb_perip(&(dev->regs).gen->DIER, interrupt));
}
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
@@ -208,12 +169,12 @@ timer_dev* get_timer_dev(int number) {
case 12: return &timer12;
#endif
#if STM32_HAVE_TIMER(13)
- case 13: return &timer14;
+ case 13: return &timer13;
#endif
#if STM32_HAVE_TIMER(14)
case 14: return &timer14;
#endif
- default: return nullptr;
+ default: return nullptr;
}
}
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/timers.h
similarity index 71%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/timers.h
index b17d8a44d3..aba619fd10 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2017 Victor Perez
*
@@ -25,16 +25,13 @@
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include
+#include "../../core/boards.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
/**
* TODO: Check and confirm what timer we will use for each Temps and stepper driving.
@@ -45,7 +42,7 @@
typedef uint16_t hal_timer_t;
#define HAL_TIMER_TYPE_MAX 0xFFFF
-#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
+#define HAL_TIMER_RATE uint32_t(F_CPU) // frequency of timers peripherals
#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
@@ -55,9 +52,20 @@ typedef uint16_t hal_timer_t;
#else
#define STEP_TIMER_NUM 5 // for other boards, five is fine.
#endif
-#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
+#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
+//#define TEMP_TIMER_NUM 4 // 2->4, Timer 2 for Stepper Current PWM
#define PULSE_TIMER_NUM STEP_TIMER_NUM
+#if MB(BIGTREE_SKR_MINI_E3, BIGTREE_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE)
+ // SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
+ #define SERVO0_TIMER_NUM 8
+#else
+ #define SERVO0_TIMER_NUM 1 // SERVO0 or BLTOUCH
+#endif
+
+#define STEP_TIMER_IRQ_PRIO 1
+#define TEMP_TIMER_IRQ_PRIO 2
+
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -85,27 +93,22 @@ timer_dev* get_timer_dev(int number);
// TODO change this
-#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler(void)
-#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler(void)
+#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
+#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
-extern "C" void tempTC_Handler(void);
-extern "C" void stepTC_Handler(void);
+extern "C" void tempTC_Handler();
+extern "C" void stepTC_Handler();
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
-/*
-static HardwareTimer StepperTimer(STEP_TIMER_NUM);
-static HardwareTimer TempTimer(TEMP_TIMER_NUM);
-*/
-// --------------------------------------------------------------------------
+// ------------------------
+
+//static HardwareTimer StepperTimer(STEP_TIMER_NUM);
+//static HardwareTimer TempTimer(TEMP_TIMER_NUM);
+
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
void HAL_timer_enable_interrupt(const uint8_t timer_num);
@@ -124,43 +127,38 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
*/
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
- //compare = MIN(compare, HAL_TIMER_TYPE_MAX);
switch (timer_num) {
case STEP_TIMER_NUM:
- timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, compare);
- return;
+ // NOTE: WE have set ARPE = 0, which means the Auto reload register is not preloaded
+ // and there is no need to use any compare, as in the timer mode used, setting ARR to the compare value
+ // will result in exactly the same effect, ie trigerring an interrupt, and on top, set counter to 0
+ timer_set_reload(STEP_TIMER_DEV, compare); // We reload direct ARR as needed during counting up
+ break;
case TEMP_TIMER_NUM:
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare);
- return;
- default:
- return;
- }
-}
-
-FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
- switch (timer_num) {
- case STEP_TIMER_NUM:
- return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN);
- case TEMP_TIMER_NUM:
- return timer_get_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN);
- default:
- return 0;
+ break;
}
}
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM:
- timer_set_count(STEP_TIMER_DEV, 0);
+ // No counter to clear
timer_generate_update(STEP_TIMER_DEV);
return;
case TEMP_TIMER_NUM:
timer_set_count(TEMP_TIMER_DEV, 0);
timer_generate_update(TEMP_TIMER_DEV);
return;
- default:
- return;
}
}
#define HAL_timer_isr_epilogue(TIMER_NUM)
+
+// No command is available in framework to turn off ARPE bit, which is turned on by default in libmaple.
+// Needed here to reset ARPE=0 for stepper timer
+FORCE_INLINE static void timer_no_ARR_preload_ARPE(timer_dev *dev) {
+ bb_peri_set_bit(&(dev->regs).gen->CR1, TIMER_CR1_ARPE_BIT, 0);
+}
+
+#define TIMER_OC_NO_PRELOAD 0 // Need to disable preload also on compare registers.
diff --git a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
similarity index 83%
rename from Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
index 0cbfb7fa5e..17f5aa9725 100644
--- a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,16 +31,16 @@
#if ENABLED(USE_WATCHDOG)
#include
-#include "watchdog_STM32F1.h"
+#include "watchdog.h"
-void watchdog_reset() {
- #if PIN_EXISTS(LED)
+void HAL_watchdog_refresh() {
+ #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
iwdg_feed();
}
-void watchdogSetup(void) {
+void watchdogSetup() {
// do whatever. don't remove this function.
}
@@ -51,10 +51,9 @@ void watchdogSetup(void) {
*
* @details The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and 625 reload value (counts down to 0)
*/
-void watchdog_init(void) {
+void watchdog_init() {
//iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD);
}
#endif // USE_WATCHDOG
-
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/watchdog.h
similarity index 89%
rename from Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/watchdog.h
index db62d4448b..21f97dd7a1 100644
--- a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -41,4 +41,4 @@ void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or STM32F1 will reset.
-void watchdog_reset();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.cpp b/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.cpp
deleted file mode 100644
index 8bae46777d..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.cpp
+++ /dev/null
@@ -1,569 +0,0 @@
-/**
- ******************************************************************************
- * @file EEPROM/EEPROM_Emulation/src/eeprom.c
- * @author MCD Application Team
- * @version V1.2.6
- * @date 04-November-2016
- * @brief This file provides all the EEPROM emulation firmware functions.
- ******************************************************************************
- * @attention
- *
- * © Copyright © 2016 STMicroelectronics International N.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions are met:
- *
- * 1. Redistribution of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of other
- * contributors to this software may be used to endorse or promote products
- * derived from this software without specific written permission.
- * 4. This software, including modifications and/or derivative works of this
- * software, must execute solely and exclusively on microcontroller or
- * microprocessor devices manufactured by or for STMicroelectronics.
- * 5. Redistribution and use of this software other than as permitted under
- * this license is void and will automatically terminate your rights under
- * this license.
- *
- * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
- * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
- * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-/** @addtogroup EEPROM_Emulation
- * @{
- */
-#if defined(STM32GENERIC) && (defined(STM32F4))
-
-/* Includes ------------------------------------------------------------------*/
-#include "eeprom_emul.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-
-/* Global variable used to store variable value in read sequence */
-uint16_t DataVar = 0;
-
-/* Virtual address defined by the user: 0xFFFF value is prohibited */
-uint16_t VirtAddVarTab[NB_OF_VAR];
-
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-static HAL_StatusTypeDef EE_Format(void);
-static uint16_t EE_FindValidPage(uint8_t Operation);
-static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data);
-static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data);
-static uint16_t EE_VerifyPageFullyErased(uint32_t Address);
-
-/**
- * @brief Restore the pages to a known good state in case of page's status
- * corruption after a power loss.
- * @param None.
- * @retval - Flash error code: on write Flash error
- * - FLASH_COMPLETE: on success
- */
-uint16_t EE_Initialize(void) {
- uint16_t PageStatus0 = 6, PageStatus1 = 6;
- uint16_t VarIdx = 0;
- uint16_t EepromStatus = 0, ReadStatus = 0;
- int16_t x = -1;
- HAL_StatusTypeDef FlashStatus;
- uint32_t SectorError = 0;
- FLASH_EraseInitTypeDef pEraseInit;
-
-
- /* Get Page0 status */
- PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS);
- /* Get Page1 status */
- PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
-
- pEraseInit.TypeErase = TYPEERASE_SECTORS;
- pEraseInit.Sector = PAGE0_ID;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
-
- /* Check for invalid header states and repair if necessary */
- switch (PageStatus0) {
- case ERASED:
- if (PageStatus1 == VALID_PAGE) { /* Page0 erased, Page1 valid */
- /* Erase Page0 */
- if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- }
- else if (PageStatus1 == RECEIVE_DATA) { /* Page0 erased, Page1 receive */
- /* Erase Page0 */
- if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- /* Mark Page1 as valid */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE1_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- else { /* First EEPROM access (Page0&1 are erased) or invalid state -> format EEPROM */
- /* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- break;
-
- case RECEIVE_DATA:
- if (PageStatus1 == VALID_PAGE) { /* Page0 receive, Page1 valid */
- /* Transfer data from Page1 to Page0 */
- for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
- if (( *(__IO uint16_t*)(PAGE0_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
- x = VarIdx;
- if (VarIdx != x) {
- /* Read the last variables' updates */
- ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
- /* In case variable corresponding to the virtual address was found */
- if (ReadStatus != 0x1) {
- /* Transfer the variable to the Page0 */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
- /* If program operation was failed, a Flash error code is returned */
- if (EepromStatus != HAL_OK) return EepromStatus;
- }
- }
- }
- /* Mark Page0 as valid */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- pEraseInit.Sector = PAGE1_ID;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
- /* Erase Page1 */
- if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- }
- else if (PageStatus1 == ERASED) { /* Page0 receive, Page1 erased */
- pEraseInit.Sector = PAGE1_ID;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
- /* Erase Page1 */
- if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- /* Mark Page0 as valid */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- else { /* Invalid state -> format eeprom */
- /* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- break;
-
- case VALID_PAGE:
- if (PageStatus1 == VALID_PAGE) { /* Invalid state -> format eeprom */
- /* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- else if (PageStatus1 == ERASED) { /* Page0 valid, Page1 erased */
- pEraseInit.Sector = PAGE1_ID;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
- /* Erase Page1 */
- if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- }
- else { /* Page0 valid, Page1 receive */
- /* Transfer data from Page0 to Page1 */
- for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
- if ((*(__IO uint16_t*)(PAGE1_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
- x = VarIdx;
-
- if (VarIdx != x) {
- /* Read the last variables' updates */
- ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
- /* In case variable corresponding to the virtual address was found */
- if (ReadStatus != 0x1) {
- /* Transfer the variable to the Page1 */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
- /* If program operation was failed, a Flash error code is returned */
- if (EepromStatus != HAL_OK) return EepromStatus;
- }
- }
- }
- /* Mark Page1 as valid */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE1_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- pEraseInit.Sector = PAGE0_ID;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
- /* Erase Page0 */
- if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- }
- break;
-
- default: /* Any other state -> format eeprom */
- /* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- break;
- }
-
- return HAL_OK;
-}
-
-/**
- * @brief Verify if specified page is fully erased.
- * @param Address: page address
- * This parameter can be one of the following values:
- * @arg PAGE0_BASE_ADDRESS: Page0 base address
- * @arg PAGE1_BASE_ADDRESS: Page1 base address
- * @retval page fully erased status:
- * - 0: if Page not erased
- * - 1: if Page erased
- */
-uint16_t EE_VerifyPageFullyErased(uint32_t Address) {
- uint32_t ReadStatus = 1;
- uint16_t AddressValue = 0x5555;
- /* Check each active page address starting from end */
- while (Address <= PAGE0_END_ADDRESS) {
- /* Get the current location content to be compared with virtual address */
- AddressValue = (*(__IO uint16_t*)Address);
- /* Compare the read address with the virtual address */
- if (AddressValue != ERASED) {
- /* In case variable value is read, reset ReadStatus flag */
- ReadStatus = 0;
- break;
- }
- /* Next address location */
- Address += 4;
- }
- /* Return ReadStatus value: (0: Page not erased, 1: Sector erased) */
- return ReadStatus;
-}
-
-/**
- * @brief Returns the last stored variable data, if found, which correspond to
- * the passed virtual address
- * @param VirtAddress: Variable virtual address
- * @param Data: Global variable contains the read variable value
- * @retval Success or error status:
- * - 0: if variable was found
- * - 1: if the variable was not found
- * - NO_VALID_PAGE: if no valid page was found.
- */
-uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data) {
- uint16_t ValidPage = PAGE0;
- uint16_t AddressValue = 0x5555, ReadStatus = 1;
- uint32_t Address = EEPROM_START_ADDRESS, PageStartAddress = EEPROM_START_ADDRESS;
-
- /* Get active Page for read operation */
- ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
-
- /* Check if there is no valid page */
- if (ValidPage == NO_VALID_PAGE) return NO_VALID_PAGE;
-
- /* Get the valid Page start Address */
- PageStartAddress = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));
-
- /* Get the valid Page end Address */
- Address = (uint32_t)((EEPROM_START_ADDRESS - 2) + (uint32_t)((1 + ValidPage) * PAGE_SIZE));
-
- /* Check each active page address starting from end */
- while (Address > (PageStartAddress + 2)) {
- /* Get the current location content to be compared with virtual address */
- AddressValue = (*(__IO uint16_t*)Address);
-
- /* Compare the read address with the virtual address */
- if (AddressValue == VirtAddress) {
- /* Get content of Address-2 which is variable value */
- *Data = (*(__IO uint16_t*)(Address - 2));
- /* In case variable value is read, reset ReadStatus flag */
- ReadStatus = 0;
- break;
- }
- else /* Next address location */
- Address -= 4;
- }
- /* Return ReadStatus value: (0: variable exist, 1: variable doesn't exist) */
- return ReadStatus;
-}
-
-/**
- * @brief Writes/upadtes variable data in EEPROM.
- * @param VirtAddress: Variable virtual address
- * @param Data: 16 bit data to be written
- * @retval Success or error status:
- * - FLASH_COMPLETE: on success
- * - PAGE_FULL: if valid page is full
- * - NO_VALID_PAGE: if no valid page was found
- * - Flash error code: on write Flash error
- */
-uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data) {
- /* Write the variable virtual address and value in the EEPROM */
- uint16_t Status = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
-
- /* In case the EEPROM active page is full */
- if (Status == PAGE_FULL) /* Perform Page transfer */
- Status = EE_PageTransfer(VirtAddress, Data);
-
- /* Return last operation status */
- return Status;
-}
-
-/**
- * @brief Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE
- * @param None
- * @retval Status of the last operation (Flash write or erase) done during
- * EEPROM formating
- */
-static HAL_StatusTypeDef EE_Format(void) {
- HAL_StatusTypeDef FlashStatus = HAL_OK;
- uint32_t SectorError = 0;
- FLASH_EraseInitTypeDef pEraseInit;
-
- pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
- pEraseInit.Sector = PAGE0_ID;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
- /* Erase Page0 */
- if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
- /* Set Page0 as valid page: Write VALID_PAGE at Page0 base address */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
-
- pEraseInit.Sector = PAGE1_ID;
- /* Erase Page1 */
- if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- }
-
- return HAL_OK;
-}
-
-/**
- * @brief Find valid Page for write or read operation
- * @param Operation: operation to achieve on the valid page.
- * This parameter can be one of the following values:
- * @arg READ_FROM_VALID_PAGE: read operation from valid page
- * @arg WRITE_IN_VALID_PAGE: write operation from valid page
- * @retval Valid page number (PAGE or PAGE1) or NO_VALID_PAGE in case
- * of no valid page was found
- */
-static uint16_t EE_FindValidPage(uint8_t Operation) {
- uint16_t PageStatus0 = 6, PageStatus1 = 6;
-
- /* Get Page0 actual status */
- PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS);
-
- /* Get Page1 actual status */
- PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
-
- /* Write or read operation */
- switch (Operation) {
- case WRITE_IN_VALID_PAGE: /* ---- Write operation ---- */
- if (PageStatus1 == VALID_PAGE) {
- /* Page0 receiving data */
- if (PageStatus0 == RECEIVE_DATA) return PAGE0; /* Page0 valid */
- else return PAGE1; /* Page1 valid */
- }
- else if (PageStatus0 == VALID_PAGE) {
- /* Page1 receiving data */
- if (PageStatus1 == RECEIVE_DATA) return PAGE1; /* Page1 valid */
- else return PAGE0; /* Page0 valid */
- }
- else
- return NO_VALID_PAGE; /* No valid Page */
-
- case READ_FROM_VALID_PAGE: /* ---- Read operation ---- */
- if (PageStatus0 == VALID_PAGE)
- return PAGE0; /* Page0 valid */
- else if (PageStatus1 == VALID_PAGE)
- return PAGE1; /* Page1 valid */
- else
- return NO_VALID_PAGE; /* No valid Page */
-
- default:
- return PAGE0; /* Page0 valid */
- }
-}
-
-/**
- * @brief Verify if active page is full and Writes variable in EEPROM.
- * @param VirtAddress: 16 bit virtual address of the variable
- * @param Data: 16 bit data to be written as variable value
- * @retval Success or error status:
- * - FLASH_COMPLETE: on success
- * - PAGE_FULL: if valid page is full
- * - NO_VALID_PAGE: if no valid page was found
- * - Flash error code: on write Flash error
- */
-static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data) {
- HAL_StatusTypeDef FlashStatus = HAL_OK;
- uint16_t ValidPage = PAGE0;
- uint32_t Address = EEPROM_START_ADDRESS, PageEndAddress = EEPROM_START_ADDRESS+PAGE_SIZE;
-
- /* Get valid Page for write operation */
- ValidPage = EE_FindValidPage(WRITE_IN_VALID_PAGE);
-
- /* Check if there is no valid page */
- if (ValidPage == NO_VALID_PAGE) return NO_VALID_PAGE;
-
- /* Get the valid Page start Address */
- Address = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));
-
- /* Get the valid Page end Address */
- PageEndAddress = (uint32_t)((EEPROM_START_ADDRESS - 1) + (uint32_t)((ValidPage + 1) * PAGE_SIZE));
-
- /* Check each active page address starting from begining */
- while (Address < PageEndAddress) {
- /* Verify if Address and Address+2 contents are 0xFFFFFFFF */
- if ((*(__IO uint32_t*)Address) == 0xFFFFFFFF) {
- /* Set variable data */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address, Data);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- /* Set variable virtual address */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address + 2, VirtAddress);
- /* Return program operation status */
- return FlashStatus;
- }
- else /* Next address location */
- Address += 4;
- }
-
- /* Return PAGE_FULL in case the valid page is full */
- return PAGE_FULL;
-}
-
-/**
- * @brief Transfers last updated variables data from the full Page to
- * an empty one.
- * @param VirtAddress: 16 bit virtual address of the variable
- * @param Data: 16 bit data to be written as variable value
- * @retval Success or error status:
- * - FLASH_COMPLETE: on success
- * - PAGE_FULL: if valid page is full
- * - NO_VALID_PAGE: if no valid page was found
- * - Flash error code: on write Flash error
- */
-static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
- HAL_StatusTypeDef FlashStatus = HAL_OK;
- uint32_t NewPageAddress = EEPROM_START_ADDRESS;
- uint16_t OldPageId=0;
- uint16_t ValidPage = PAGE0, VarIdx = 0;
- uint16_t EepromStatus = 0, ReadStatus = 0;
- uint32_t SectorError = 0;
- FLASH_EraseInitTypeDef pEraseInit;
-
- /* Get active Page for read operation */
- ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
-
- if (ValidPage == PAGE1) { /* Page1 valid */
- /* New page address where variable will be moved to */
- NewPageAddress = PAGE0_BASE_ADDRESS;
- /* Old page ID where variable will be taken from */
- OldPageId = PAGE1_ID;
- }
- else if (ValidPage == PAGE0) { /* Page0 valid */
- /* New page address where variable will be moved to */
- NewPageAddress = PAGE1_BASE_ADDRESS;
- /* Old page ID where variable will be taken from */
- OldPageId = PAGE0_ID;
- }
- else
- return NO_VALID_PAGE; /* No valid Page */
-
- /* Set the new Page status to RECEIVE_DATA status */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, RECEIVE_DATA);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
-
- /* Write the variable passed as parameter in the new active page */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
- /* If program operation was failed, a Flash error code is returned */
- if (EepromStatus != HAL_OK) return EepromStatus;
-
- /* Transfer process: transfer variables from old to the new active page */
- for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
- if (VirtAddVarTab[VarIdx] != VirtAddress) { /* Check each variable except the one passed as parameter */
- /* Read the other last variable updates */
- ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
- /* In case variable corresponding to the virtual address was found */
- if (ReadStatus != 0x1) {
- /* Transfer the variable to the new active page */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
- /* If program operation was failed, a Flash error code is returned */
- if (EepromStatus != HAL_OK) return EepromStatus;
- }
- }
- }
-
- pEraseInit.TypeErase = TYPEERASE_SECTORS;
- pEraseInit.Sector = OldPageId;
- pEraseInit.NbSectors = 1;
- pEraseInit.VoltageRange = VOLTAGE_RANGE;
-
- /* Erase the old Page: Set old Page status to ERASED status */
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
-
- /* Set new Page status to VALID_PAGE status */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
-
- /* Return last operation flash status */
- return FlashStatus;
-}
-
-#endif // STM32F4 || STM32F4xx
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Marlin/src/HAL/HAL_STM32F4/EmulatedEeprom.cpp b/Marlin/src/HAL/HAL_STM32F4/EmulatedEeprom.cpp
deleted file mode 100644
index 1f3d753448..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/EmulatedEeprom.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#if defined(STM32GENERIC) && (defined(STM32F4))
-
-/**
- * Description: functions for I2C connected external EEPROM.
- * Not platform dependent.
- */
-
-#include "../../inc/MarlinConfig.h"
-
-#if ENABLED(EEPROM_SETTINGS) && DISABLED(I2C_EEPROM, SPI_EEPROM)
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-#include "EEPROM_Emul/eeprom_emul.h"
-
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-static bool eeprom_initialized = false;
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-// FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to
-// FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F4
-// #define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR
-
-// --------------------------------------------------------------------------
-// EEPROM
-// --------------------------------------------------------------------------
-
-
-void eeprom_init() {
- if (!eeprom_initialized) {
- HAL_FLASH_Unlock();
-
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
-
- /* EEPROM Init */
- if (EE_Initialize() != EE_OK)
- for (;;) HAL_Delay(1); // Spin forever until watchdog reset
-
- HAL_FLASH_Lock();
- eeprom_initialized = true;
- }
-}
-
-void eeprom_write_byte(uint8_t *pos, unsigned char value) {
- uint16_t eeprom_address = (unsigned) pos;
-
- eeprom_init();
-
- HAL_FLASH_Unlock();
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
-
- if (EE_WriteVariable(eeprom_address, (uint16_t) value) != EE_OK)
- for (;;) HAL_Delay(1); // Spin forever until watchdog reset
-
- HAL_FLASH_Lock();
-}
-
-uint8_t eeprom_read_byte(uint8_t *pos) {
- uint16_t data = 0xFF;
- uint16_t eeprom_address = (unsigned)pos;
-
- eeprom_init();
-
- if (EE_ReadVariable(eeprom_address, &data) != EE_OK) {
- return (unsigned char)data;
- }
- return (unsigned char)data;
-}
-
-void eeprom_read_block(void *__dst, const void *__src, size_t __n) {
- uint16_t data = 0xFF;
- uint16_t eeprom_address = (unsigned) __src;
-
- eeprom_init();
-
- for (uint8_t c = 0; c < __n; c++) {
- EE_ReadVariable(eeprom_address+c, &data);
- *((uint8_t*)__dst + c) = data;
- }
-}
-
-void eeprom_update_block(const void *__src, void *__dst, size_t __n) {
-
-}
-
-#endif // EEPROM_SETTINGS && (!I2C_EEPROM && !SPI_EEPROM)
-#endif // STM32GENERIC && STM32F4
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL.cpp b/Marlin/src/HAL/HAL_STM32F4/HAL.cpp
deleted file mode 100644
index 5840a525b6..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/HAL.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- *
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
- * Copyright (c) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#if defined(STM32GENERIC) && defined(STM32F4)
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-
-//#include
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-uint16_t HAL_adc_result;
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-/* VGPV Done with defines
-// disable interrupts
-void cli(void) { noInterrupts(); }
-
-// enable interrupts
-void sei(void) { interrupts(); }
-*/
-
-void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
-
-uint8_t HAL_get_reset_source(void) {
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
-
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) return RST_SOFTWARE;
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET) return RST_EXTERNAL;
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET) return RST_POWER_ON;
- return 0;
-}
-
-void _delay_ms(const int delay_ms) { delay(delay_ms); }
-
-extern "C" {
- extern unsigned int _ebss; // end of bss section
-}
-
-// return free memory between end of heap (or end bss) and whatever is current
-
-/*
-#include "wirish/syscalls.c"
-//extern caddr_t _sbrk(int incr);
-#ifndef CONFIG_HEAP_END
-extern char _lm_heap_end;
-#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
-#endif
-
-extern "C" {
- static int freeMemory() {
- char top = 't';
- return &top - reinterpret_cast(sbrk(0));
- }
- int freeMemory() {
- int free_memory;
- int heap_end = (int)_sbrk(0);
- free_memory = ((int)&free_memory) - ((int)heap_end);
- return free_memory;
- }
-}
-*/
-
-// --------------------------------------------------------------------------
-// ADC
-// --------------------------------------------------------------------------
-
-void HAL_adc_start_conversion(const uint8_t adc_pin) {
- HAL_adc_result = analogRead(adc_pin);
-}
-
-uint16_t HAL_adc_get_result(void) {
- return HAL_adc_result;
-}
-
-#endif // // STM32GENERIC && STM32F4
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL.h b/Marlin/src/HAL/HAL_STM32F4/HAL.h
deleted file mode 100644
index 4f621e348a..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/HAL.h
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- *
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
- * Copyright (c) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-#define CPU_32_BIT
-
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "../shared/Marduino.h"
-#include "../shared/math_32bit.h"
-#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F4.h"
-#include "watchdog_STM32F4.h"
-#include "HAL_timers_STM32F4.h"
-
-#include "../../inc/MarlinConfigPre.h"
-
-#include
-
-#ifdef USBCON
- #include
-#endif
-
-// --------------------------------------------------------------------------
-// Defines
-// --------------------------------------------------------------------------
-
-//Serial override
-//extern HalSerial usb_serial;
-
-#if SERIAL_PORT == 0
- #error "Serial port 0 does not exist"
-#endif
-
-#if !WITHIN(SERIAL_PORT, -1, 6)
- #error "SERIAL_PORT must be from -1 to 6"
-#endif
-#if SERIAL_PORT == -1
- #define MYSERIAL0 SerialUSB
-#elif SERIAL_PORT == 1
- #define MYSERIAL0 SerialUART1
-#elif SERIAL_PORT == 2
- #define MYSERIAL0 SerialUART2
-#elif SERIAL_PORT == 3
- #define MYSERIAL0 SerialUART3
-#elif SERIAL_PORT == 4
- #define MYSERIAL0 SerialUART4
-#elif SERIAL_PORT == 5
- #define MYSERIAL0 SerialUART5
-#elif SERIAL_PORT == 6
- #define MYSERIAL0 SerialUART6
-#endif
-
-#ifdef SERIAL_PORT_2
- #if SERIAL_PORT_2 == 0
- #error "Serial port 0 does not exist"
- #endif
-
- #if !WITHIN(SERIAL_PORT_2, -1, 6)
- #error "SERIAL_PORT_2 must be from -1 to 6"
- #elif SERIAL_PORT_2 == SERIAL_PORT
- #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
- #endif
- #define NUM_SERIAL 2
- #if SERIAL_PORT_2 == -1
- #define MYSERIAL1 SerialUSB
- #elif SERIAL_PORT_2 == 1
- #define MYSERIAL1 SerialUART1
- #elif SERIAL_PORT_2 == 2
- #define MYSERIAL1 SerialUART2
- #elif SERIAL_PORT_2 == 3
- #define MYSERIAL1 SerialUART3
- #elif SERIAL_PORT_2 == 4
- #define MYSERIAL1 SerialUART4
- #elif SERIAL_PORT_2 == 5
- #define MYSERIAL1 SerialUART5
- #elif SERIAL_PORT_2 == 6
- #define MYSERIAL1 SerialUART6
- #endif
-#else
- #define NUM_SERIAL 1
-#endif
-
-#undef _BV
-#define _BV(b) (1 << (b))
-
-/**
- * TODO: review this to return 1 for pins that are not analog input
- */
-#ifndef analogInputToDigitalPin
- #define analogInputToDigitalPin(p) (p)
-#endif
-
-#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
-#define CRITICAL_SECTION_END if (!primask) __enable_irq()
-#define ISRS_ENABLED() (!__get_PRIMASK())
-#define ENABLE_ISRS() __enable_irq()
-#define DISABLE_ISRS() __disable_irq()
-#define cli() __disable_irq()
-#define sei() __enable_irq()
-
-// On AVR this is in math.h?
-#define square(x) ((x)*(x))
-
-#ifndef strncpy_P
- #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
-#endif
-
-// Fix bug in pgm_read_ptr
-#undef pgm_read_ptr
-#define pgm_read_ptr(addr) (*(addr))
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-typedef int8_t pin_t;
-
-#define HAL_SERVO_LIB libServo
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-/** result of last ADC conversion */
-extern uint16_t HAL_adc_result;
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-// Memory related
-#define __bss_end __bss_end__
-
-/** clear reset reason */
-void HAL_clear_reset_source (void);
-
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
-
-void _delay_ms(const int delay);
-
-/*
-extern "C" {
- int freeMemory(void);
-}
-*/
-
-extern "C" char* _sbrk(int incr);
-
-/*
-static int freeMemory() {
- volatile int top;
- top = (int)((char*)&top - reinterpret_cast(_sbrk(0)));
- return top;
-}
-*/
-
-static int freeMemory() {
- volatile char top;
- return &top - reinterpret_cast(_sbrk(0));
-}
-
-//
-// SPI: Extended functions which take a channel number (hardware SPI only)
-//
-
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
-
-//
-// EEPROM
-//
-
-/**
- * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
- * Wire library should work for i2c EEPROMs.
- */
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
-
-//
-// ADC
-//
-
-#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
-
-inline void HAL_adc_init(void) {}
-
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
-#define HAL_READ_ADC() HAL_adc_result
-#define HAL_ADC_READY() true
-
-void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
-
-#define GET_PIN_MAP_PIN(index) index
-#define GET_PIN_MAP_INDEX(pin) pin
-#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
-
-#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
-#define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp
deleted file mode 100644
index 4783736b20..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- *
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#if defined(STM32GENERIC) && defined(STM32F4)
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-
-#include "HAL_timers_STM32F4.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-#define NUM_HARDWARE_TIMERS 2
-#define STEP_TIMER_IRQ_ID TIM5_IRQn
-#define TEMP_TIMER_IRQ_ID TIM7_IRQn
-
-//#define PRESCALER 1
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-stm32f4_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-bool timers_initialized[NUM_HARDWARE_TIMERS] = {false};
-
-void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
-
- if (!timers_initialized[timer_num]) {
- constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
- temp_prescaler = TEMP_TIMER_PRESCALE - 1;
- switch (timer_num) {
- case STEP_TIMER_NUM:
- // STEPPER TIMER TIM5 - use a 32bit timer
- #ifdef STM32GENERIC
- __HAL_RCC_TIM5_CLK_ENABLE();
- TimerHandle[timer_num].handle.Instance = TIM5;
- TimerHandle[timer_num].handle.Init.Prescaler = step_prescaler;
- TimerHandle[timer_num].handle.Init.CounterMode = TIM_COUNTERMODE_UP;
- TimerHandle[timer_num].handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- TimerHandle[timer_num].callback = (uint32_t)TC5_Handler;
- #else
- TimerHandle[timer_num].timer = TIM5;
- TimerHandle[timer_num].irqHandle = TC5_Handler;
- TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
- #endif
- HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 1, 0);
- break;
-
- case TEMP_TIMER_NUM:
- // TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM)
- #ifdef STM32GENERIC
- __HAL_RCC_TIM7_CLK_ENABLE();
- TimerHandle[timer_num].handle.Instance = TIM7;
- TimerHandle[timer_num].handle.Init.Prescaler = temp_prescaler;
- TimerHandle[timer_num].handle.Init.CounterMode = TIM_COUNTERMODE_UP;
- TimerHandle[timer_num].handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- TimerHandle[timer_num].callback = (uint32_t)TC7_Handler;
- #else
- TimerHandle[timer_num].timer = TIM7;
- TimerHandle[timer_num].irqHandle = TC7_Handler;
- TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
- #endif
- HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0);
- break;
- }
- timers_initialized[timer_num] = true;
- }
-
- #ifdef STM32GENERIC
- TimerHandle[timer_num].handle.Init.Period = (((HAL_TIMER_RATE) / TimerHandle[timer_num].handle.Init.Prescaler) / frequency) - 1;
- if (HAL_TIM_Base_Init(&TimerHandle[timer_num].handle) == HAL_OK)
- HAL_TIM_Base_Start_IT(&TimerHandle[timer_num].handle);
- #endif
-}
-
-#ifdef STM32GENERIC
- extern "C" void TIM5_IRQHandler() {
- ((void(*)(void))TimerHandle[0].callback)();
- }
- extern "C" void TIM7_IRQHandler() {
- ((void(*)(void))TimerHandle[1].callback)();
- }
-#endif
-
-void HAL_timer_enable_interrupt(const uint8_t timer_num) {
- switch (timer_num) {
- case STEP_TIMER_NUM: HAL_NVIC_EnableIRQ(STEP_TIMER_IRQ_ID); break;
- case TEMP_TIMER_NUM: HAL_NVIC_EnableIRQ(TEMP_TIMER_IRQ_ID); break;
- }
-}
-
-void HAL_timer_disable_interrupt(const uint8_t timer_num) {
- switch (timer_num) {
- case STEP_TIMER_NUM: HAL_NVIC_DisableIRQ(STEP_TIMER_IRQ_ID); break;
- case TEMP_TIMER_NUM: HAL_NVIC_DisableIRQ(TEMP_TIMER_IRQ_ID); break;
- }
- // We NEED memory barriers to ensure Interrupts are actually disabled!
- // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
- __DSB();
- __ISB();
-}
-
-bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
- switch (timer_num) {
- case STEP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)STEP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)STEP_TIMER_IRQ_ID) & (uint32_t)0x1F));
- case TEMP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) & (uint32_t)0x1F));
- }
- return false;
-}
-
-#endif // STM32GENERIC && STM32F4
diff --git a/Marlin/src/HAL/HAL_STM32F4/SanityCheck.h b/Marlin/src/HAL/HAL_STM32F4/SanityCheck.h
deleted file mode 100644
index 441daf9257..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/SanityCheck.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-/**
- * Test Re-ARM specific configuration values for errors at compile-time.
- */
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
- #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
- #elif SPINDLE_LASER_POWERUP_DELAY < 1
- #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-#if ENABLED(EMERGENCY_PARSER)
- #error "EMERGENCY_PARSER is not yet implemented for STM32F4. Disable EMERGENCY_PARSER to continue."
-#endif
-
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
-#endif
diff --git a/Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h b/Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h
deleted file mode 100644
index 1d548ca29e..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Fast I/O interfaces for STM32F4
- * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
- */
-
-#undef _BV
-#define _BV(b) (1 << (b))
-
-#define READ(IO) digitalRead(IO)
-#define WRITE(IO,V) digitalWrite(IO,V)
-#define WRITE_VAR(IO,V) WRITE(IO,V)
-
-#define _GET_MODE(IO)
-#define _SET_MODE(IO,M) pinMode(IO, M)
-#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
-
-#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
-
-#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
-#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
-#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
-#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
-#define SET_PWM(IO) pinMode(IO, PWM)
-
-#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
-
-#define IS_INPUT(IO)
-#define IS_OUTPUT(IO)
-
-#define PWM_PIN(P) true
-
-// digitalRead/Write wrappers
-#define extDigitalRead(IO) digitalRead(IO)
-#define extDigitalWrite(IO,V) digitalWrite(IO,V)
-
-//
-// Pins Definitions
-//
-#define PORTA 0
-#define PORTB 1
-#define PORTC 2
-#define PORTD 3
-#define PORTE 4
-
-#define _STM32_PIN(_PORT,_PIN) ((PORT##_PORT * 16) + _PIN)
-
-#define PA0 _STM32_PIN(A, 0)
-#define PA1 _STM32_PIN(A, 1)
-#define PA2 _STM32_PIN(A, 2)
-#define PA3 _STM32_PIN(A, 3)
-#define PA4 _STM32_PIN(A, 4)
-#define PA5 _STM32_PIN(A, 5)
-#define PA6 _STM32_PIN(A, 6)
-#define PA7 _STM32_PIN(A, 7)
-#define PA8 _STM32_PIN(A, 8)
-#define PA9 _STM32_PIN(A, 9)
-#define PA10 _STM32_PIN(A, 10)
-#define PA11 _STM32_PIN(A, 11)
-#define PA12 _STM32_PIN(A, 12)
-#define PA13 _STM32_PIN(A, 13)
-#define PA14 _STM32_PIN(A, 14)
-#define PA15 _STM32_PIN(A, 15)
-
-#define PB0 _STM32_PIN(B, 0)
-#define PB1 _STM32_PIN(B, 1)
-#define PB2 _STM32_PIN(B, 2)
-#define PB3 _STM32_PIN(B, 3)
-#define PB4 _STM32_PIN(B, 4)
-#define PB5 _STM32_PIN(B, 5)
-#define PB6 _STM32_PIN(B, 6)
-#define PB7 _STM32_PIN(B, 7)
-#define PB8 _STM32_PIN(B, 8)
-#define PB9 _STM32_PIN(B, 9)
-#define PB10 _STM32_PIN(B, 10)
-#define PB11 _STM32_PIN(B, 11)
-#define PB12 _STM32_PIN(B, 12)
-#define PB13 _STM32_PIN(B, 13)
-#define PB14 _STM32_PIN(B, 14)
-#define PB15 _STM32_PIN(B, 15)
-
-#define PC0 _STM32_PIN(C, 0)
-#define PC1 _STM32_PIN(C, 1)
-#define PC2 _STM32_PIN(C, 2)
-#define PC3 _STM32_PIN(C, 3)
-#define PC4 _STM32_PIN(C, 4)
-#define PC5 _STM32_PIN(C, 5)
-#define PC6 _STM32_PIN(C, 6)
-#define PC7 _STM32_PIN(C, 7)
-#define PC8 _STM32_PIN(C, 8)
-#define PC9 _STM32_PIN(C, 9)
-#define PC10 _STM32_PIN(C, 10)
-#define PC11 _STM32_PIN(C, 11)
-#define PC12 _STM32_PIN(C, 12)
-#define PC13 _STM32_PIN(C, 13)
-#define PC14 _STM32_PIN(C, 14)
-#define PC15 _STM32_PIN(C, 15)
-
-#define PD0 _STM32_PIN(D, 0)
-#define PD1 _STM32_PIN(D, 1)
-#define PD2 _STM32_PIN(D, 2)
-#define PD3 _STM32_PIN(D, 3)
-#define PD4 _STM32_PIN(D, 4)
-#define PD5 _STM32_PIN(D, 5)
-#define PD6 _STM32_PIN(D, 6)
-#define PD7 _STM32_PIN(D, 7)
-#define PD8 _STM32_PIN(D, 8)
-#define PD9 _STM32_PIN(D, 9)
-#define PD10 _STM32_PIN(D, 10)
-#define PD11 _STM32_PIN(D, 11)
-#define PD12 _STM32_PIN(D, 12)
-#define PD13 _STM32_PIN(D, 13)
-#define PD14 _STM32_PIN(D, 14)
-#define PD15 _STM32_PIN(D, 15)
-
-#define PE0 _STM32_PIN(E, 0)
-#define PE1 _STM32_PIN(E, 1)
-#define PE2 _STM32_PIN(E, 2)
-#define PE3 _STM32_PIN(E, 3)
-#define PE4 _STM32_PIN(E, 4)
-#define PE5 _STM32_PIN(E, 5)
-#define PE6 _STM32_PIN(E, 6)
-#define PE7 _STM32_PIN(E, 7)
-#define PE8 _STM32_PIN(E, 8)
-#define PE9 _STM32_PIN(E, 9)
-#define PE10 _STM32_PIN(E, 10)
-#define PE11 _STM32_PIN(E, 11)
-#define PE12 _STM32_PIN(E, 12)
-#define PE13 _STM32_PIN(E, 13)
-#define PE14 _STM32_PIN(E, 14)
-#define PE15 _STM32_PIN(E, 15)
diff --git a/Marlin/src/HAL/HAL_STM32F4/pinsDebug.h b/Marlin/src/HAL/HAL_STM32F4/pinsDebug.h
deleted file mode 100644
index e5022f79a4..0000000000
--- a/Marlin/src/HAL/HAL_STM32F4/pinsDebug.h
+++ /dev/null
@@ -1 +0,0 @@
-#error Debug pins is not supported on this Platform!
diff --git a/Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.h b/Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.h
deleted file mode 100644
index 8cffdbef77..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/******************************************************************************
- * @file eeprom_emul.h
- * @author MCD Application Team
- * @version V1.2.6
- * @date 04-November-2016
- * @brief This file contains all the functions prototypes for the EEPROM
- * emulation firmware library.
- ******************************************************************************
- * @attention
- *
- * © Copyright © 2016 STMicroelectronics International N.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions are met:
- *
- * 1. Redistribution of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of other
- * contributors to this software may be used to endorse or promote products
- * derived from this software without specific written permission.
- * 4. This software, including modifications and/or derivative works of this
- * software, must execute solely and exclusively on microcontroller or
- * microprocessor devices manufactured by or for STMicroelectronics.
- * 5. Redistribution and use of this software other than as permitted under
- * this license is void and will automatically terminate your rights under
- * this license.
- *
- * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
- * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
- * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *****************************************************************************/
-#pragma once
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-#include "../../../inc/MarlinConfig.h"
-#include "../HAL.h"
-
-/* Exported constants --------------------------------------------------------*/
-/* EEPROM emulation firmware error codes */
-#define EE_OK (uint32_t)HAL_OK
-#define EE_ERROR (uint32_t)HAL_ERROR
-#define EE_BUSY (uint32_t)HAL_BUSY
-#define EE_TIMEOUT (uint32_t)HAL_TIMEOUT
-
-/* Define the size of the sectors to be used */
-#define PAGE_SIZE (uint32_t)0x4000 /* Page size = 16KByte */
-
-/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
- be done by word */
-#define VOLTAGE_RANGE (uint8_t)VOLTAGE_RANGE_3
-
-/* EEPROM start address in Flash */
-#define EEPROM_START_ADDRESS ((uint32_t)0x08100000) /* EEPROM emulation start address:
- from sector2 : after 16KByte of used
- Flash memory */
-
-/* Pages 0 and 1 base and end addresses */
-#define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
-#define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
-#define PAGE0_ID FLASH_SECTOR_1
-
-#define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x4000))
-#define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
-#define PAGE1_ID FLASH_SECTOR_2
-
-/* Used Flash pages for EEPROM emulation */
-#define PAGE0 ((uint16_t)0x0000)
-#define PAGE1 ((uint16_t)0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
-
-/* No valid page define */
-#define NO_VALID_PAGE ((uint16_t)0x00AB)
-
-/* Page status definitions */
-#define ERASED ((uint16_t)0xFFFF) /* Page is empty */
-#define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
-#define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
-
-/* Valid pages in read and write defines */
-#define READ_FROM_VALID_PAGE ((uint8_t)0x00)
-#define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
-
-/* Page full define */
-#define PAGE_FULL ((uint8_t)0x80)
-
-/* Variables' number */
-#define NB_OF_VAR ((uint16_t)4096)
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-uint16_t EE_Initialize(void);
-uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
-uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Marlin/src/HAL/HAL_STM32F7/EmulatedEeprom.cpp b/Marlin/src/HAL/HAL_STM32F7/EmulatedEeprom.cpp
deleted file mode 100644
index 7f9118ee9c..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/EmulatedEeprom.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#ifdef STM32F7
-
-/**
- * Description: functions for I2C connected external EEPROM.
- * Not platform dependent.
- */
-
-#include "../../inc/MarlinConfig.h"
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-#include "EEPROM_Emul/eeprom_emul.h"
-
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-static bool eeprom_initialized = false;
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-// FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to
-// FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F7
-#define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR
-
-// --------------------------------------------------------------------------
-// EEPROM
-// --------------------------------------------------------------------------
-
-
-void eeprom_init() {
- if (!eeprom_initialized) {
- HAL_FLASH_Unlock();
-
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
-
- /* EEPROM Init */
- if (EE_Initialize() != EE_OK)
- for (;;) HAL_Delay(1); // Spin forever until watchdog reset
-
- HAL_FLASH_Lock();
- eeprom_initialized = true;
- }
-}
-
-void eeprom_write_byte(uint8_t *pos, unsigned char value) {
- uint16_t eeprom_address = (unsigned) pos;
-
- eeprom_init();
-
- HAL_FLASH_Unlock();
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
-
- if (EE_WriteVariable(eeprom_address, (uint16_t) value) != EE_OK)
- for (;;) HAL_Delay(1); // Spin forever until watchdog reset
-
- HAL_FLASH_Lock();
-}
-
-uint8_t eeprom_read_byte(uint8_t *pos) {
- uint16_t data = 0xFF;
- uint16_t eeprom_address = (unsigned)pos;
-
- eeprom_init();
-
- if (EE_ReadVariable(eeprom_address, &data) != EE_OK) {
- return (unsigned char)data;
- }
- return (unsigned char)data;
-}
-
-void eeprom_read_block(void *__dst, const void *__src, size_t __n) {
- uint16_t data = 0xFF;
- uint16_t eeprom_address = (unsigned) __src;
-
- eeprom_init();
-
- for (uint8_t c = 0; c < __n; c++) {
- EE_ReadVariable(eeprom_address+c, &data);
- *((uint8_t*)__dst + c) = data;
- }
-}
-
-void eeprom_update_block(const void *__src, void *__dst, size_t __n) {
-
-}
-
-#endif // STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL.cpp b/Marlin/src/HAL/HAL_STM32F7/HAL.cpp
deleted file mode 100644
index 9f354f17e3..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/HAL.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- *
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
- * Copyright (c) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#ifdef STM32F7
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-
-//#include
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-uint16_t HAL_adc_result;
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-/* VGPV Done with defines
-// disable interrupts
-void cli(void) { noInterrupts(); }
-
-// enable interrupts
-void sei(void) { interrupts(); }
-*/
-
-void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
-
-uint8_t HAL_get_reset_source(void) {
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
- return RST_WATCHDOG;
-
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET)
- return RST_SOFTWARE;
-
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
- return RST_EXTERNAL;
-
- if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
- return RST_POWER_ON;
- return 0;
-}
-
-void _delay_ms(const int delay_ms) { delay(delay_ms); }
-
-extern "C" {
- extern unsigned int _ebss; // end of bss section
-}
-
-// return free memory between end of heap (or end bss) and whatever is current
-
-/*
-#include "wirish/syscalls.c"
-//extern caddr_t _sbrk(int incr);
-#ifndef CONFIG_HEAP_END
-extern char _lm_heap_end;
-#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
-#endif
-
-extern "C" {
- static int freeMemory() {
- char top = 't';
- return &top - reinterpret_cast(sbrk(0));
- }
- int freeMemory() {
- int free_memory;
- int heap_end = (int)_sbrk(0);
- free_memory = ((int)&free_memory) - ((int)heap_end);
- return free_memory;
- }
-}
-*/
-
-// --------------------------------------------------------------------------
-// ADC
-// --------------------------------------------------------------------------
-
-void HAL_adc_start_conversion(const uint8_t adc_pin) {
- HAL_adc_result = analogRead(adc_pin);
-}
-
-uint16_t HAL_adc_get_result(void) {
- return HAL_adc_result;
-}
-
-#endif // STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_spi_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32F7/HAL_spi_STM32F7.cpp
deleted file mode 100644
index 78b312470a..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_spi_STM32F7.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-/**
- * Software SPI functions originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
- */
-
-/**
- * Adapted to the STM32F7 HAL
- */
-
-#ifdef STM32F7
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-#include "../shared/HAL_SPI.h"
-#include "pins_arduino.h"
-#include "spi_pins.h"
-#include "../../core/macros.h"
-#include
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-static SPISettings spiConfig;
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-#if ENABLED(SOFTWARE_SPI)
- // --------------------------------------------------------------------------
- // Software SPI
- // --------------------------------------------------------------------------
- #error "Software SPI not supported for STM32F7. Use hardware SPI."
-
-#else
-
-// --------------------------------------------------------------------------
-// Hardware SPI
-// --------------------------------------------------------------------------
-
-/**
- * VGPV SPI speed start and F_CPU/2, by default 72/2 = 36Mhz
- */
-
-/**
- * @brief Begin SPI port setup
- *
- * @return Nothing
- *
- * @details Only configures SS pin since libmaple creates and initialize the SPI object
- */
-void spiBegin(void) {
- #if !PIN_EXISTS(SS)
- #error SS_PIN not defined!
- #endif
-
- SET_OUTPUT(SS_PIN);
- WRITE(SS_PIN, HIGH);
-}
-
-/** Configure SPI for specified SPI speed */
-void spiInit(uint8_t spiRate) {
- // Use datarates Marlin uses
- uint32_t clock;
- switch (spiRate) {
- case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000
- case SPI_HALF_SPEED: clock = 5000000; break;
- case SPI_QUARTER_SPEED: clock = 2500000; break;
- case SPI_EIGHTH_SPEED: clock = 1250000; break;
- case SPI_SPEED_5: clock = 625000; break;
- case SPI_SPEED_6: clock = 300000; break;
- default:
- clock = 4000000; // Default from the SPI libarary
- }
- spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
- SPI.begin();
-}
-
-/**
- * @brief Receives a single byte from the SPI port.
- *
- * @return Byte received
- *
- * @details
- */
-uint8_t spiRec(void) {
- SPI.beginTransaction(spiConfig);
- uint8_t returnByte = SPI.transfer(0xFF);
- SPI.endTransaction();
- return returnByte;
-}
-
-/**
- * @brief Receives a number of bytes from the SPI port to a buffer
- *
- * @param buf Pointer to starting address of buffer to write to.
- * @param nbyte Number of bytes to receive.
- * @return Nothing
- *
- * @details Uses DMA
- */
-void spiRead(uint8_t* buf, uint16_t nbyte) {
- SPI.beginTransaction(spiConfig);
- SPI.dmaTransfer(0, const_cast(buf), nbyte);
- SPI.endTransaction();
-}
-
-/**
- * @brief Sends a single byte on SPI port
- *
- * @param b Byte to send
- *
- * @details
- */
-void spiSend(uint8_t b) {
- SPI.beginTransaction(spiConfig);
- SPI.transfer(b);
- SPI.endTransaction();
-}
-
-/**
- * @brief Write token and then write from 512 byte buffer to SPI (for SD card)
- *
- * @param buf Pointer with buffer start address
- * @return Nothing
- *
- * @details Use DMA
- */
-void spiSendBlock(uint8_t token, const uint8_t* buf) {
- SPI.beginTransaction(spiConfig);
- SPI.transfer(token);
- SPI.dmaSend(const_cast(buf), 512);
- SPI.endTransaction();
-}
-
-#endif // SOFTWARE_SPI
-
-#endif // STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32F7/SanityCheck.h b/Marlin/src/HAL/HAL_STM32F7/SanityCheck.h
deleted file mode 100644
index 8ba1f870c2..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/SanityCheck.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-/**
- * Test Re-ARM specific configuration values for errors at compile-time.
- */
-#if ENABLED(SPINDLE_LASER_ENABLE)
- #if !PIN_EXISTS(SPINDLE_LASER_ENA)
- #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENA_PIN."
- #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
- #error "SPINDLE_DIR_PIN not defined."
- #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
- #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
- #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
- #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
- #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
- #elif SPINDLE_LASER_POWERUP_DELAY < 1
- #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
- #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
- #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
- #elif !defined(SPINDLE_LASER_PWM_INVERT)
- #error "SPINDLE_LASER_PWM_INVERT missing."
- #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
- #error "SPINDLE_LASER_PWM equation constant(s) missing."
- #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
- #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
- #elif PIN_EXISTS(E5_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E5_AUTO_FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by E5_AUTO_FAN_PIN."
- #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
- #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
- #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
- #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
- #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
- #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
- #endif
- #endif
-#endif // SPINDLE_LASER_ENABLE
-
-#if ENABLED(EMERGENCY_PARSER)
- #error "EMERGENCY_PARSER is not yet implemented for STM32F7. Disable EMERGENCY_PARSER to continue."
-#endif
-
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
-#endif
diff --git a/Marlin/src/HAL/HAL_STM32F7/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32F7/endstop_interrupts.h
deleted file mode 100644
index 23eca4bab7..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/endstop_interrupts.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-#include "../../module/endstops.h"
-
-// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
-
-void setup_endstop_interrupts(void) {
- #if HAS_X_MAX
- attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_X_MIN
- attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MAX
- attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MIN
- attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MAX
- attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN
- attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MAX
- attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MIN
- attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MAX
- attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MIN
- attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
- #endif
-}
diff --git a/Marlin/src/HAL/HAL_STM32F7/pinsDebug.h b/Marlin/src/HAL/HAL_STM32F7/pinsDebug.h
deleted file mode 100644
index e5022f79a4..0000000000
--- a/Marlin/src/HAL/HAL_STM32F7/pinsDebug.h
+++ /dev/null
@@ -1 +0,0 @@
-#error Debug pins is not supported on this Platform!
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp
new file mode 100644
index 0000000000..5e6ae09bf1
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp
@@ -0,0 +1,122 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
+
+/**
+ * Description: Functions for a Flash emulated EEPROM
+ * Not platform dependent.
+ */
+
+// Include configs and pins to get all EEPROM flags
+#include "../../inc/MarlinConfig.h"
+
+#ifdef STM32F7
+ #define HAS_EMULATED_EEPROM 1
+#else
+ #define HAS_EMULATED_EEPROM NONE(I2C_EEPROM, SPI_EEPROM)
+#endif
+
+#if HAS_EMULATED_EEPROM && ENABLED(EEPROM_SETTINGS)
+
+// ------------------------
+// Includes
+// ------------------------
+
+#include "HAL.h"
+#include "eeprom_emul.h"
+
+// ------------------------
+// Local defines
+// ------------------------
+
+// FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to
+// FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F4/7
+
+#ifdef STM32F7
+ #define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR
+#else
+ //#define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR
+#endif
+
+// ------------------------
+// Private Variables
+// ------------------------
+
+static bool eeprom_initialized = false;
+
+// ------------------------
+// Public functions
+// ------------------------
+
+void eeprom_init() {
+ if (!eeprom_initialized) {
+ HAL_FLASH_Unlock();
+
+ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
+
+ /* EEPROM Init */
+ if (EE_Initialize() != EE_OK)
+ for (;;) HAL_Delay(1); // Spin forever until watchdog reset
+
+ HAL_FLASH_Lock();
+ eeprom_initialized = true;
+ }
+}
+
+void eeprom_write_byte(uint8_t *pos, unsigned char value) {
+ eeprom_init();
+
+ HAL_FLASH_Unlock();
+ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
+
+ uint16_t eeprom_address = unsigned(pos);
+ if (EE_WriteVariable(eeprom_address, uint16_t(value)) != EE_OK)
+ for (;;) HAL_Delay(1); // Spin forever until watchdog reset
+
+ HAL_FLASH_Lock();
+}
+
+uint8_t eeprom_read_byte(uint8_t *pos) {
+ eeprom_init();
+
+ uint16_t data = 0xFF;
+ uint16_t eeprom_address = unsigned(pos);
+ (void)EE_ReadVariable(eeprom_address, &data); // Data unchanged on error
+
+ return uint8_t(data);
+}
+
+void eeprom_read_block(void *__dst, const void *__src, size_t __n) {
+ eeprom_init();
+
+ uint16_t data = 0xFF;
+ uint16_t eeprom_address = unsigned(__src);
+ for (uint8_t c = 0; c < __n; c++) {
+ EE_ReadVariable(eeprom_address+c, &data);
+ *((uint8_t*)__dst + c) = data;
+ }
+}
+
+void eeprom_update_block(const void *__src, void *__dst, size_t __n) {
+
+}
+
+#endif // EEPROM_SETTINGS
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.cpp
new file mode 100644
index 0000000000..7ed6e2c10f
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.cpp
@@ -0,0 +1,96 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
+ * Copyright (c) 2017 Victor Perez
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
+
+#include "HAL.h"
+
+//#include
+
+// ------------------------
+// Public Variables
+// ------------------------
+
+uint16_t HAL_adc_result;
+
+// ------------------------
+// Public functions
+// ------------------------
+
+/* VGPV Done with defines
+// disable interrupts
+void cli() { noInterrupts(); }
+
+// enable interrupts
+void sei() { interrupts(); }
+*/
+
+void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
+
+uint8_t HAL_get_reset_source() {
+ if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
+ if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) return RST_SOFTWARE;
+ if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET) return RST_EXTERNAL;
+ if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET) return RST_POWER_ON;
+ return 0;
+}
+
+void _delay_ms(const int delay_ms) { delay(delay_ms); }
+
+extern "C" {
+ extern unsigned int _ebss; // end of bss section
+}
+
+// return free memory between end of heap (or end bss) and whatever is current
+
+/*
+#include "wirish/syscalls.c"
+//extern caddr_t _sbrk(int incr);
+#ifndef CONFIG_HEAP_END
+extern char _lm_heap_end;
+#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
+#endif
+
+extern "C" {
+ static int freeMemory() {
+ char top = 't';
+ return &top - reinterpret_cast(sbrk(0));
+ }
+ int freeMemory() {
+ int free_memory;
+ int heap_end = (int)_sbrk(0);
+ free_memory = ((int)&free_memory) - ((int)heap_end);
+ return free_memory;
+ }
+}
+*/
+
+// ------------------------
+// ADC
+// ------------------------
+
+void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
+
+uint16_t HAL_adc_get_result() { return HAL_adc_result; }
+
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL.h b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
similarity index 69%
rename from Marlin/src/HAL/HAL_STM32F7/HAL.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
index 729547e94e..d4ca01e022 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2017 Victor Perez
@@ -24,34 +24,34 @@
#define CPU_32_BIT
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include
-
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F7.h"
-#include "watchdog_STM32F7.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "HAL_timers_STM32F7.h"
+#include "timers.h"
#include "../../inc/MarlinConfigPre.h"
-// --------------------------------------------------------------------------
+#include
+
+#if defined(STM32F4) && USBCON
+ #include
+#endif
+
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//Serial override
//extern HalSerial usb_serial;
+#if defined(STM32F4) && SERIAL_PORT == 0
+ #error "Serial port 0 does not exist"
+#endif
+
#if !WITHIN(SERIAL_PORT, -1, 6)
#error "SERIAL_PORT must be from -1 to 6"
#endif
@@ -72,6 +72,9 @@
#endif
#ifdef SERIAL_PORT_2
+ #if defined(STM32F4) && SERIAL_PORT_2 == 0
+ #error "Serial port 0 does not exist"
+ #endif
#if !WITHIN(SERIAL_PORT_2, -1, 6)
#error "SERIAL_PORT_2 must be from -1 to 6"
#elif SERIAL_PORT_2 == SERIAL_PORT
@@ -97,8 +100,6 @@
#define NUM_SERIAL 1
#endif
-#define _BV(b) (1 << (b))
-
/**
* TODO: review this to return 1 for pins that are not analog input
*/
@@ -125,86 +126,99 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef int8_t pin_t;
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
+#ifdef STM32F4
+ #define HAL_SERVO_LIB libServo
+#endif
-/** result of last ADC conversion */
+// ------------------------
+// Public Variables
+// ------------------------
+
+// Result of last ADC conversion
extern uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// Memory related
#define __bss_end __bss_end__
-/** clear reset reason */
-void HAL_clear_reset_source (void);
+inline void HAL_init() {}
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
+// Clear reset reason
+void HAL_clear_reset_source();
+
+// Reset reason
+uint8_t HAL_get_reset_source();
void _delay_ms(const int delay);
/*
extern "C" {
- int freeMemory(void);
+ int freeMemory();
}
*/
extern "C" char* _sbrk(int incr);
+
/*
-static int freeMemory() {
+int freeMemory() {
volatile int top;
top = (int)((char*)&top - reinterpret_cast(_sbrk(0)));
return top;
}
*/
-static int freeMemory() {
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+
+static inline int freeMemory() {
volatile char top;
return &top - reinterpret_cast(_sbrk(0));
}
-// SPI: Extended functions which take a channel number (hardware SPI only)
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
-
+#pragma GCC diagnostic pop
+//
// EEPROM
+//
/**
- * TODO: Write all this eeprom stuff. Can emulate eeprom in flash as last resort.
- * Wire library should work for i2c eeproms.
+ * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
+ * Wire library should work for i2c EEPROMs.
*/
void eeprom_write_byte(uint8_t *pos, unsigned char value);
uint8_t eeprom_read_byte(uint8_t *pos);
void eeprom_read_block (void *__dst, const void *__src, size_t __n);
void eeprom_update_block (const void *__src, void *__dst, size_t __n);
+//
// ADC
+//
#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
-inline void HAL_adc_init(void) {}
+inline void HAL_adc_init() {}
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+
+#ifdef STM32F4
+ #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
+ #define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
similarity index 72%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
index 8365b8370b..2f85182e20 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,48 +23,42 @@
/**
* Software SPI functions originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
+ * Copyright (c) 2009 by William Greiman
*/
/**
- * Adapted to the STM32F4 HAL
+ * Adapted to the Marlin STM32F4/7 HAL
*/
-#if defined(STM32GENERIC) && defined(STM32F4)
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
+#include "../../inc/MarlinConfig.h"
-#include "HAL.h"
-#include "../shared/HAL_SPI.h"
-#include "pins_arduino.h"
-#include "spi_pins.h"
-#include "../../core/macros.h"
#include
+#include
+#include "../shared/HAL_SPI.h"
+#include "spi_pins.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
static SPISettings spiConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if ENABLED(SOFTWARE_SPI)
-
- // --------------------------------------------------------------------------
+ // ------------------------
// Software SPI
- // --------------------------------------------------------------------------
- #error "Software SPI not supported for STM32F4. Use hardware SPI."
-
+ // ------------------------
+ #error "Software SPI not supported for STM32F4/7. Use Hardware SPI."
#else
-// --------------------------------------------------------------------------
+// ------------------------
// Hardware SPI
-// --------------------------------------------------------------------------
+// ------------------------
/**
* VGPV SPI speed start and F_CPU/2, by default 72/2 = 36Mhz
@@ -77,8 +71,8 @@ static SPISettings spiConfig;
*
* @details Only configures SS pin since libmaple creates and initialize the SPI object
*/
-void spiBegin(void) {
- #if !PIN_EXISTS(SS)
+void spiBegin() {
+ #if !defined(SS_PIN) || SS_PIN < 0
#error SS_PIN not defined!
#endif
@@ -109,7 +103,7 @@ void spiInit(uint8_t spiRate) {
*
* @details
*/
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
@@ -127,13 +121,11 @@ uint8_t spiRec(void) {
*/
void spiRead(uint8_t* buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig);
-
#ifdef STM32GENERIC
SPI.dmaTransfer(0, const_cast(buf), nbyte);
#else
SPI.transfer((uint8_t*)buf, nbyte);
#endif
-
SPI.endTransaction();
}
@@ -161,16 +153,13 @@ void spiSend(uint8_t b) {
void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.beginTransaction(spiConfig);
SPI.transfer(token);
-
#ifdef STM32GENERIC
SPI.dmaSend(const_cast(buf), 512);
#else
SPI.transfer((uint8_t*)buf, nullptr, 512);
#endif
-
SPI.endTransaction();
}
#endif // SOFTWARE_SPI
-
-#endif // STM32GENERIC && STM32F4
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/README.md b/Marlin/src/HAL/HAL_STM32_F4_F7/README.md
new file mode 100644
index 0000000000..3b5a9ab02e
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/README.md
@@ -0,0 +1,6 @@
+# This HAL is for...
+
+ - STM32F407 MCU with STM32Generic Arduino core by danieleff.
+ - STM32F765 board "The Borg" with STM32Generic.
+
+See the `README.md` files in HAL_STM32F4 and HAL_STM32F7 for the specifics of those hals.
diff --git a/Marlin/src/HAL/HAL_STM32F4/README.md b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/README.md
similarity index 100%
rename from Marlin/src/HAL/HAL_STM32F4/README.md
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/README.md
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp
new file mode 100644
index 0000000000..32219962ee
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.cpp
@@ -0,0 +1,117 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#if defined(STM32GENERIC) && defined(STM32F4)
+
+#include "../HAL.h"
+#include "timers.h"
+
+// ------------------------
+// Local defines
+// ------------------------
+
+#define NUM_HARDWARE_TIMERS 2
+#define STEP_TIMER_IRQ_ID TIM5_IRQn
+#define TEMP_TIMER_IRQ_ID TIM7_IRQn
+
+// ------------------------
+// Private Variables
+// ------------------------
+
+stm32_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
+
+// ------------------------
+// Public functions
+// ------------------------
+
+bool timers_initialized[NUM_HARDWARE_TIMERS] = {false};
+
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
+
+ if (!timers_initialized[timer_num]) {
+ constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
+ temp_prescaler = TEMP_TIMER_PRESCALE - 1;
+ switch (timer_num) {
+ case STEP_TIMER_NUM:
+ // STEPPER TIMER TIM5 - use a 32bit timer
+ __HAL_RCC_TIM5_CLK_ENABLE();
+ TimerHandle[timer_num].handle.Instance = TIM5;
+ TimerHandle[timer_num].handle.Init.Prescaler = step_prescaler;
+ TimerHandle[timer_num].handle.Init.CounterMode = TIM_COUNTERMODE_UP;
+ TimerHandle[timer_num].handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ TimerHandle[timer_num].callback = (uint32_t)TC5_Handler;
+ HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 1, 0);
+ break;
+
+ case TEMP_TIMER_NUM:
+ // TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM)
+ __HAL_RCC_TIM7_CLK_ENABLE();
+ TimerHandle[timer_num].handle.Instance = TIM7;
+ TimerHandle[timer_num].handle.Init.Prescaler = temp_prescaler;
+ TimerHandle[timer_num].handle.Init.CounterMode = TIM_COUNTERMODE_UP;
+ TimerHandle[timer_num].handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ TimerHandle[timer_num].callback = (uint32_t)TC7_Handler;
+ HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0);
+ break;
+ }
+ timers_initialized[timer_num] = true;
+ }
+
+ TimerHandle[timer_num].handle.Init.Period = (((HAL_TIMER_RATE) / TimerHandle[timer_num].handle.Init.Prescaler) / frequency) - 1;
+ if (HAL_TIM_Base_Init(&TimerHandle[timer_num].handle) == HAL_OK)
+ HAL_TIM_Base_Start_IT(&TimerHandle[timer_num].handle);
+}
+
+extern "C" void TIM5_IRQHandler() {
+ ((void(*)())TimerHandle[0].callback)();
+}
+extern "C" void TIM7_IRQHandler() {
+ ((void(*)())TimerHandle[1].callback)();
+}
+
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
+ switch (timer_num) {
+ case STEP_TIMER_NUM: HAL_NVIC_EnableIRQ(STEP_TIMER_IRQ_ID); break;
+ case TEMP_TIMER_NUM: HAL_NVIC_EnableIRQ(TEMP_TIMER_IRQ_ID); break;
+ }
+}
+
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
+ switch (timer_num) {
+ case STEP_TIMER_NUM: HAL_NVIC_DisableIRQ(STEP_TIMER_IRQ_ID); break;
+ case TEMP_TIMER_NUM: HAL_NVIC_DisableIRQ(TEMP_TIMER_IRQ_ID); break;
+ }
+ // We NEED memory barriers to ensure Interrupts are actually disabled!
+ // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
+ __DSB();
+ __ISB();
+}
+
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
+ switch (timer_num) {
+ case STEP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)STEP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)STEP_TIMER_IRQ_ID) & (uint32_t)0x1F));
+ case TEMP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) & (uint32_t)0x1F));
+ }
+ return false;
+}
+
+#endif // STM32GENERIC && STM32F4
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h
similarity index 81%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h
index a4c2ba6f44..726207fbcf 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2017 Victor Perez
*
@@ -21,15 +21,11 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -75,29 +71,29 @@
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
#ifdef STM32GENERIC
typedef struct {
TIM_HandleTypeDef handle;
uint32_t callback;
} tTimerConfig;
- typedef tTimerConfig stm32f4_timer_t;
+ typedef tTimerConfig stm32_timer_t;
#else
- typedef stimer_t stm32f4_timer_t;
+ typedef stimer_t stm32_timer_t;
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
-extern stm32f4_timer_t TimerHandle[];
+extern stm32_timer_t TimerHandle[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
void HAL_timer_enable_interrupt(const uint8_t timer_num);
diff --git a/Marlin/src/HAL/HAL_STM32F7/README.md b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/README.md
similarity index 75%
rename from Marlin/src/HAL/HAL_STM32F7/README.md
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/README.md
index 2fb39bf25a..23155b425e 100644
--- a/Marlin/src/HAL/HAL_STM32F7/README.md
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/README.md
@@ -4,7 +4,7 @@
https://github.com/danieleff/STM32GENERIC
-but i have not committed the changes needed for the Borg there yet, so please use:
+but I haven't committed the changes needed for the Borg there yet, so please use:
https://github.com/Spawn32/STM32GENERIC
@@ -15,9 +15,9 @@ Download the latest GNU ARM Embedded Toolchain:
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
-(The one in Arduino dosen't support STM32F7).
+(The one in Arduino doesn't support STM32F7).
-Change compiler.path in platform.txt to point to that you downloaded.
+Change compiler.path in platform.txt to point to the one you downloaded.
# This HAL is in development.
# Currently only tested on "The Borg".
@@ -25,4 +25,3 @@ Change compiler.path in platform.txt to point to that you downloaded.
You will also need the latest Arduino 1.9.0-beta or newer.
This HAL is a modified version of Chris Barr's Picoprint STM32F4 HAL, so shouldn't be to hard to get it to work on a F4.
-
diff --git a/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
index 99cadbde16..3117321ac7 100644
--- a/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
@@ -25,22 +25,22 @@
*
*/
-//#include
+#if defined(STM32GENERIC) && defined(STM32F7)
-#ifdef STM32F7
+#include "../../../inc/MarlinConfigPre.h"
+
+#if HAS_DRIVER(TMC2660)
#include
#include
#include "TMC2660.h"
-#include "HAL.h"
-#include "../../core/serial.h"
-#include "../../inc/MarlinConfig.h"
-#include "../../Marlin.h"
-#include "../../module/stepper_indirection.h"
-#include "../../module/printcounter.h"
-#include "../../libs/duration_t.h"
-#include "../../libs/hex_print_routines.h"
+#include "../../../inc/MarlinConfig.h"
+#include "../../../Marlin.h"
+#include "../../../module/stepper/indirection.h"
+#include "../../../module/printcounter.h"
+#include "../../../libs/duration_t.h"
+#include "../../../libs/hex_print_routines.h"
//some default values used in initialization
#define DEFAULT_MICROSTEPPING_VALUE 32
@@ -189,7 +189,6 @@ void TMC26XStepper::start() {
pinMode(step_pin, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(cs_pin, OUTPUT);
- //SET_OUTPUT(STEPPER_ENABLE_PIN);
extDigitalWrite(step_pin, LOW);
extDigitalWrite(dir_pin, LOW);
extDigitalWrite(cs_pin, HIGH);
@@ -227,7 +226,7 @@ void TMC26XStepper::setSpeed(uint16_t whatSpeed) {
this->next_step_time = this->last_step_time + this->step_delay;
}
-uint16_t TMC26XStepper::getSpeed(void) { return this->speed; }
+uint16_t TMC26XStepper::getSpeed() { return this->speed; }
/**
* Moves the motor steps_to_move steps.
@@ -247,7 +246,7 @@ char TMC26XStepper::step(int16_t steps_to_move) {
return -1;
}
-char TMC26XStepper::move(void) {
+char TMC26XStepper::move() {
// decrement the number of steps, moving one step each time:
if (this->steps_left > 0) {
uint32_t time = micros();
@@ -278,11 +277,11 @@ char TMC26XStepper::move(void) {
return 0;
}
-char TMC26XStepper::isMoving(void) { return this->steps_left > 0; }
+char TMC26XStepper::isMoving() { return this->steps_left > 0; }
-uint16_t TMC26XStepper::getStepsLeft(void) { return this->steps_left; }
+uint16_t TMC26XStepper::getStepsLeft() { return this->steps_left; }
-char TMC26XStepper::stop(void) {
+char TMC26XStepper::stop() {
//note to self if the motor is currently moving
char state = isMoving();
//stop the motor
@@ -314,10 +313,12 @@ void TMC26XStepper::setCurrent(uint16_t current) {
current_scaling = (byte)((resistor_value * mASetting * 32.0 / (0.165 * sq(1000.0))) - 0.5); //theoretically - 1.0 for better rounding it is 0.5
#ifdef TMC_DEBUG0 // crashes
SERIAL_ECHOPAIR("\nCS (Vsense=1): ",current_scaling);
- } else {
- SERIAL_ECHOPAIR("\nCS: ", current_scaling);
#endif
}
+ #ifdef TMC_DEBUG0 // crashes
+ else
+ SERIAL_ECHOPAIR("\nCS: ", current_scaling);
+ #endif
// do some sanity checks
NOMORE(current_scaling, 31);
@@ -333,7 +334,7 @@ void TMC26XStepper::setCurrent(uint16_t current) {
}
}
-uint16_t TMC26XStepper::getCurrent(void) {
+uint16_t TMC26XStepper::getCurrent() {
// Calculate the current according to the datasheet to be on the safe side.
// This is not the fastest but the most accurate and illustrative way.
float result = (float)(stallguard2_current_register_value & CURRENT_SCALING_PATTERN),
@@ -360,7 +361,7 @@ void TMC26XStepper::setStallGuardThreshold(char stallguard_threshold, char stall
if (started) send262(stallguard2_current_register_value);
}
-char TMC26XStepper::getStallGuardThreshold(void) {
+char TMC26XStepper::getStallGuardThreshold() {
uint32_t stallguard_threshold = stallguard2_current_register_value & STALL_GUARD_VALUE_PATTERN;
//shift it down to bit 0
stallguard_threshold >>= 8;
@@ -373,7 +374,7 @@ char TMC26XStepper::getStallGuardThreshold(void) {
return result;
}
-char TMC26XStepper::getStallGuardFilter(void) {
+char TMC26XStepper::getStallGuardFilter() {
if (stallguard2_current_register_value & STALL_GUARD_FILTER_ENABLED)
return -1;
return 0;
@@ -420,7 +421,7 @@ void TMC26XStepper::setMicrosteps(const int16_t in_steps) {
/**
* returns the effective number of microsteps at the moment
*/
-int16_t TMC26XStepper::getMicrosteps(void) { return microsteps; }
+int16_t TMC26XStepper::getMicrosteps() { return microsteps; }
/**
* constant_off_time: The off time setting controls the minimum chopper frequency.
@@ -622,7 +623,7 @@ void TMC26XStepper::setCoolStepEnabled(boolean enabled) {
if (started) send262(cool_step_register_value);
}
-boolean TMC26XStepper::isCoolStepEnabled(void) { return this->cool_step_enabled; }
+boolean TMC26XStepper::isCoolStepEnabled() { return this->cool_step_enabled; }
uint16_t TMC26XStepper::getCoolStepLowerSgThreshold() {
// We return our internally stored value - in order to provide the correct setting even if cool step is not enabled
@@ -630,19 +631,19 @@ uint16_t TMC26XStepper::getCoolStepLowerSgThreshold() {
}
uint16_t TMC26XStepper::getCoolStepUpperSgThreshold() {
- return (uint8_t)((cool_step_register_value & SE_MAX_PATTERN) >> 8) << 5;
+ return uint8_t((cool_step_register_value & SE_MAX_PATTERN) >> 8) << 5;
}
uint8_t TMC26XStepper::getCoolStepCurrentIncrementSize() {
- return (uint8_t)((cool_step_register_value & CURRENT_DOWN_STEP_SPEED_PATTERN) >> 13);
+ return uint8_t((cool_step_register_value & CURRENT_DOWN_STEP_SPEED_PATTERN) >> 13);
}
uint8_t TMC26XStepper::getCoolStepNumberOfSGReadings() {
- return (uint8_t)((cool_step_register_value & SE_CURRENT_STEP_WIDTH_PATTERN) >> 5);
+ return uint8_t((cool_step_register_value & SE_CURRENT_STEP_WIDTH_PATTERN) >> 5);
}
uint8_t TMC26XStepper::getCoolStepLowerCurrentLimit() {
- return (uint8_t)((cool_step_register_value & MINIMUM_CURRENT_FOURTH) >> 15);
+ return uint8_t((cool_step_register_value & MINIMUM_CURRENT_FOURTH) >> 15);
}
void TMC26XStepper::setEnabled(boolean enabled) {
@@ -683,7 +684,7 @@ void TMC26XStepper::readStatus(char read_value) {
send262(driver_configuration_register_value);
}
-int16_t TMC26XStepper::getMotorPosition(void) {
+int16_t TMC26XStepper::getMotorPosition() {
//we read it out even if we are not started yet - perhaps it is useful information for somebody
readStatus(TMC26X_READOUT_POSITION);
return getReadoutValue();
@@ -691,7 +692,7 @@ int16_t TMC26XStepper::getMotorPosition(void) {
//reads the StallGuard setting from last status
//returns -1 if StallGuard information is not present
-int16_t TMC26XStepper::getCurrentStallGuardReading(void) {
+int16_t TMC26XStepper::getCurrentStallGuardReading() {
//if we don't yet started there cannot be a StallGuard value
if (!started) return -1;
//not time optimal, but solution optiomal:
@@ -700,7 +701,7 @@ int16_t TMC26XStepper::getCurrentStallGuardReading(void) {
return getReadoutValue();
}
-uint8_t TMC26XStepper::getCurrentCSReading(void) {
+uint8_t TMC26XStepper::getCurrentCSReading() {
//if we don't yet started there cannot be a StallGuard value
if (!started) return 0;
//not time optimal, but solution optiomal:
@@ -709,7 +710,7 @@ uint8_t TMC26XStepper::getCurrentCSReading(void) {
return (getReadoutValue() & 0x1F);
}
-uint16_t TMC26XStepper::getCurrentCurrent(void) {
+uint16_t TMC26XStepper::getCurrentCurrent() {
float result = (float)getCurrentCSReading(),
resistor_value = (float)this->resistor,
voltage = (driver_configuration_register_value & VSENSE)? 0.165 : 0.31;
@@ -720,7 +721,7 @@ uint16_t TMC26XStepper::getCurrentCurrent(void) {
/**
* Return true if the StallGuard threshold has been reached
*/
-boolean TMC26XStepper::isStallGuardOverThreshold(void) {
+boolean TMC26XStepper::isStallGuardOverThreshold() {
if (!this->started) return false;
return (driver_status_result & STATUS_STALL_GUARD_STATUS);
}
@@ -731,7 +732,7 @@ boolean TMC26XStepper::isStallGuardOverThreshold(void) {
* OVER_TEMPERATURE_SHUTDOWN if the temperature is so hot that the driver is shut down
* Any of those levels are not too good.
*/
-char TMC26XStepper::getOverTemperature(void) {
+char TMC26XStepper::getOverTemperature() {
if (!this->started) return 0;
if (driver_status_result & STATUS_OVER_TEMPERATURE_SHUTDOWN)
@@ -744,44 +745,44 @@ char TMC26XStepper::getOverTemperature(void) {
}
// Is motor channel A shorted to ground
-boolean TMC26XStepper::isShortToGroundA(void) {
+boolean TMC26XStepper::isShortToGroundA() {
if (!this->started) return false;
return (driver_status_result & STATUS_SHORT_TO_GROUND_A);
}
// Is motor channel B shorted to ground
-boolean TMC26XStepper::isShortToGroundB(void) {
+boolean TMC26XStepper::isShortToGroundB() {
if (!this->started) return false;
return (driver_status_result & STATUS_SHORT_TO_GROUND_B);
}
// Is motor channel A connected
-boolean TMC26XStepper::isOpenLoadA(void) {
+boolean TMC26XStepper::isOpenLoadA() {
if (!this->started) return false;
return (driver_status_result & STATUS_OPEN_LOAD_A);
}
// Is motor channel B connected
-boolean TMC26XStepper::isOpenLoadB(void) {
+boolean TMC26XStepper::isOpenLoadB() {
if (!this->started) return false;
return (driver_status_result & STATUS_OPEN_LOAD_B);
}
// Is chopper inactive since 2^20 clock cycles - defaults to ~0,08s
-boolean TMC26XStepper::isStandStill(void) {
+boolean TMC26XStepper::isStandStill() {
if (!this->started) return false;
return (driver_status_result & STATUS_STAND_STILL);
}
//is chopper inactive since 2^20 clock cycles - defaults to ~0,08s
-boolean TMC26XStepper::isStallGuardReached(void) {
+boolean TMC26XStepper::isStallGuardReached() {
if (!this->started) return false;
return (driver_status_result & STATUS_STALL_GUARD_STATUS);
}
//reads the StallGuard setting from last status
//returns -1 if StallGuard information is not present
-int16_t TMC26XStepper::getReadoutValue(void) {
+int16_t TMC26XStepper::getReadoutValue() {
return (int)(driver_status_result >> 10);
}
@@ -793,7 +794,7 @@ boolean TMC26XStepper::isCurrentScalingHalfed() {
/**
* version() returns the version of the library:
*/
-int16_t TMC26XStepper::version(void) { return 1; }
+int16_t TMC26XStepper::version() { return 1; }
void TMC26XStepper::debugLastStatus() {
#ifdef TMC_DEBUG1
@@ -830,9 +831,8 @@ void TMC26XStepper::debugLastStatus() {
SERIAL_ECHOPAIR("\n Stall Guard value:", value);
}
else if (readout_config == READ_STALL_GUARD_AND_COOL_STEP) {
- int16_t stallGuard = value & 0xF, current = value & 0x1F0;
- SERIAL_ECHOPAIR("\n Approx Stall Guard: ", stallGuard);
- SERIAL_ECHOPAIR("\n Current level", current);
+ SERIAL_ECHOPAIR("\n Approx Stall Guard: ", value & 0xF);
+ SERIAL_ECHOPAIR("\n Current level", value & 0x1F0);
}
}
#endif
@@ -895,4 +895,6 @@ inline void TMC26XStepper::send262(uint32_t datagram) {
driver_status_result = i_datagram;
}
-#endif // STM32F7
+#endif // HAS_DRIVER(TMC2660)
+
+#endif // STM32GENERIC && STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32F7/TMC2660.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.h
similarity index 97%
rename from Marlin/src/HAL/HAL_STM32F7/TMC2660.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.h
index 1b44a4d5f5..f1d0133a3b 100644
--- a/Marlin/src/HAL/HAL_STM32F7/TMC2660.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.h
@@ -140,7 +140,6 @@ class TMC26XStepper {
*/
void un_start();
-
/*!
* \brief Set the rotation speed in RPM.
* \param whatSpeed the desired speed in RPM.
@@ -151,7 +150,7 @@ class TMC26XStepper {
* \brief Report the currently selected speed in RPM.
* \sa setSpeed()
*/
- uint16_t getSpeed(void);
+ uint16_t getSpeed();
/*!
* \brief Set the number of microsteps in 2^i values (rounded) up to 256
@@ -171,7 +170,7 @@ class TMC26XStepper {
*
* \sa setMicrosteps()
*/
- int16_t getMicrosteps(void);
+ int16_t getMicrosteps();
/*!
* \brief Initiate a movement with the given number of steps. Positive values move in one direction, negative in the other.
@@ -205,7 +204,7 @@ class TMC26XStepper {
* It is recommended to call this using a hardware timer to ensure regular invocation.
* \sa step()
*/
- char move(void);
+ char move();
/*!
* \brief Check whether the last movement command is done.
@@ -214,13 +213,13 @@ class TMC26XStepper {
* Used to determine if the motor is ready for new movements.
*\sa step(), move()
*/
- char isMoving(void);
+ char isMoving();
/*!
* \brief Get the number of steps left in the current movement.
* \return The number of steps left in the movement. Always positive.
*/
- uint16_t getStepsLeft(void);
+ uint16_t getStepsLeft();
/*!
* \brief Stop the motor immediately.
@@ -228,7 +227,7 @@ class TMC26XStepper {
*
* This method directly and abruptly stops the motor and may be used as an emergency stop.
*/
- char stop(void);
+ char stop();
/*!
* \brief Set and configure the classical Constant Off Timer Chopper
@@ -310,7 +309,7 @@ class TMC26XStepper {
* \return the maximum motor current in milli amps
* \sa getCurrentCurrent()
*/
- uint16_t getCurrent(void);
+ uint16_t getCurrent();
/*!
* \brief set the StallGuard threshold in order to get sensible StallGuard readings.
@@ -333,13 +332,13 @@ class TMC26XStepper {
* \brief reads out the StallGuard threshold
* \return a number between -64 and 63.
*/
- char getStallGuardThreshold(void);
+ char getStallGuardThreshold();
/*!
* \brief returns the current setting of the StallGuard filter
* \return 0 if not set, -1 if set
*/
- char getStallGuardFilter(void);
+ char getStallGuardFilter();
/*!
* \brief This method configures the CoolStep smart energy operation. You must have a proper StallGuard configuration for the motor situation (current, voltage, speed) in rder to use this feature.
@@ -412,7 +411,7 @@ class TMC26XStepper {
*
* Keep in mind that this routine reads and writes a value via SPI - so this may take a bit time.
*/
- int16_t getMotorPosition(void);
+ int16_t getMotorPosition();
/*!
* \brief Reads the current StallGuard value.
@@ -420,14 +419,14 @@ class TMC26XStepper {
* Keep in mind that this routine reads and writes a value via SPI - so this may take a bit time.
* \sa setStallGuardThreshold() for tuning the readout to sensible ranges.
*/
- int16_t getCurrentStallGuardReading(void);
+ int16_t getCurrentStallGuardReading();
/*!
* \brief Reads the current current setting value as fraction of the maximum current
* Returns values between 0 and 31, representing 1/32 to 32/32 (=1)
* \sa setCoolStepConfiguration()
*/
- uint8_t getCurrentCSReading(void);
+ uint8_t getCurrentCSReading();
/*!
@@ -443,7 +442,7 @@ class TMC26XStepper {
* may not be the fastest.
* \sa getCurrentCSReading(), getResistor(), isCurrentScalingHalfed(), getCurrent()
*/
- uint16_t getCurrentCurrent(void);
+ uint16_t getCurrentCurrent();
/*!
* \brief checks if there is a StallGuard warning in the last status
@@ -453,7 +452,7 @@ class TMC26XStepper {
*
* \sa setStallGuardThreshold() for tuning the readout to sensible ranges.
*/
- boolean isStallGuardOverThreshold(void);
+ boolean isStallGuardOverThreshold();
/*!
* \brief Return over temperature status of the last status readout
@@ -461,7 +460,7 @@ class TMC26XStepper {
* Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
* You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
*/
- char getOverTemperature(void);
+ char getOverTemperature();
/*!
* \brief Is motor channel A shorted to ground detected in the last status readout.
@@ -470,7 +469,7 @@ class TMC26XStepper {
* You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
*/
- boolean isShortToGroundA(void);
+ boolean isShortToGroundA();
/*!
* \brief Is motor channel B shorted to ground detected in the last status readout.
@@ -478,14 +477,14 @@ class TMC26XStepper {
* Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
* You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
*/
- boolean isShortToGroundB(void);
+ boolean isShortToGroundB();
/*!
* \brief iIs motor channel A connected according to the last statu readout.
* \return true is yes, false if not.
* Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
* You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
*/
- boolean isOpenLoadA(void);
+ boolean isOpenLoadA();
/*!
* \brief iIs motor channel A connected according to the last statu readout.
@@ -493,7 +492,7 @@ class TMC26XStepper {
* Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
* You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
*/
- boolean isOpenLoadB(void);
+ boolean isOpenLoadB();
/*!
* \brief Is chopper inactive since 2^20 clock cycles - defaults to ~0,08s
@@ -501,7 +500,7 @@ class TMC26XStepper {
* Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
* You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
*/
- boolean isStandStill(void);
+ boolean isStandStill();
/*!
* \brief checks if there is a StallGuard warning in the last status
@@ -514,7 +513,7 @@ class TMC26XStepper {
*
* \sa setStallGuardThreshold() for tuning the readout to sensible ranges.
*/
- boolean isStallGuardReached(void);
+ boolean isStallGuardReached();
/*!
*\brief enables or disables the motor driver bridges. If disabled the motor can run freely. If enabled not.
@@ -550,13 +549,13 @@ class TMC26XStepper {
* \brief Prints out all the information that can be found in the last status read out - it does not force a status readout.
* The result is printed via Serial
*/
- void debugLastStatus(void);
+ void debugLastStatus();
/*!
* \brief library version
* \return the version number as int.
*/
- int16_t version(void);
+ int16_t version();
private:
uint16_t steps_left; // The steps the motor has to do to complete the movement
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp
similarity index 67%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp
index 90131903e3..5a3b32ef5b 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -20,56 +20,30 @@
*
*/
-#ifdef STM32F7
+#if defined(STM32GENERIC) && defined(STM32F7)
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
+#include "../HAL.h"
+#include "timers.h"
-#include "HAL.h"
-
-#include "HAL_timers_STM32F7.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define NUM_HARDWARE_TIMERS 2
//#define PRESCALER 1
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
tTimerConfig timerConfig[NUM_HARDWARE_TIMERS];
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-
-bool timers_initialized[NUM_HARDWARE_TIMERS] = {false};
+bool timers_initialized[NUM_HARDWARE_TIMERS] = { false };
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
@@ -85,8 +59,9 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
timerConfig[0].IRQ_Id = TIM5_IRQn;
timerConfig[0].callback = (uint32_t)TC5_Handler;
HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0);
- SET_OUTPUT(STEPPER_ENABLE_PIN);
- WRITE(STEPPER_ENABLE_PIN);
+ #if PIN_EXISTS(STEPPER_ENABLE)
+ OUT_WRITE(STEPPER_ENABLE_PIN, HIGH);
+ #endif
break;
case TEMP_TIMER_NUM:
//TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM)
@@ -111,10 +86,10 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
//forward the interrupt
extern "C" void TIM5_IRQHandler() {
- ((void(*)(void))timerConfig[0].callback)();
+ ((void(*)())timerConfig[0].callback)();
}
extern "C" void TIM7_IRQHandler() {
- ((void(*)(void))timerConfig[1].callback)();
+ ((void(*)())timerConfig[1].callback)();
}
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
@@ -153,4 +128,4 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F);
}
-#endif // STM32F7
+#endif // STM32GENERIC && STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h
similarity index 79%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h
index 34e56a2059..38ecde30bb 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2017 Victor Perez
*
@@ -21,15 +21,11 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -61,17 +57,17 @@
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
#define TEMP_ISR_ENABLED() HAL_timer_interrupt_enabled(TEMP_TIMER_NUM)
-// TODO change this
+// TODO change this
extern void TC5_Handler();
extern void TC7_Handler();
#define HAL_STEP_TIMER_ISR() void TC5_Handler()
#define HAL_TEMP_TIMER_ISR() void TC7_Handler()
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
TIM_HandleTypeDef timerdef;
@@ -79,15 +75,15 @@ typedef struct {
uint32_t callback;
} tTimerConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
//extern const tTimerConfig timerConfig[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
void HAL_timer_enable_interrupt(const uint8_t timer_num);
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
similarity index 70%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
index 40fafc432c..b3aac77615 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,34 +21,34 @@
*
*/
-#ifdef STM32F7
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
-#include "HAL_Servo_STM32F7.h"
+#include "Servo.h"
int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- return Servo::attach(pin);
+ if (servoIndex >= MAX_SERVOS) return -1;
+ return super::attach(pin);
}
int8_t libServo::attach(const int pin, const int min, const int max) {
- return Servo::attach(pin, min, max);
+ return super::attach(pin, min, max);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
-#endif // HAS_SERVOS
-#endif // STM32F7
+#endif // HAS_SERVOS
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.h b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
similarity index 75%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
index 1b7ee40817..64fa05025c 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,16 +22,20 @@
*/
#pragma once
-#include <../../libraries/Servo/src/Servo.h>
+//#ifdef STM32F7
+// #include <../../libraries/Servo/src/Servo.h>
+//#else
+ #include
+//#endif
// Inherit and expand on the official library
class libServo : public Servo {
-public:
+ public:
int8_t attach(const int pin);
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
-private:
- uint16_t min_ticks;
- uint16_t max_ticks;
+ private:
+ typedef Servo super;
+ uint16_t min_ticks, max_ticks;
uint8_t servoIndex; // index into the channel data for this servo
};
diff --git a/Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/eeprom_emul.cpp
similarity index 74%
rename from Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/eeprom_emul.cpp
index 10b3219e9a..3358fa3df7 100644
--- a/Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/eeprom_emul.cpp
@@ -8,8 +8,8 @@
******************************************************************************
* @attention
*
- * © Copyright 2016 STMicroelectronics International N.V.
- * All rights reserved.
+ * Copyright © 2016 STMicroelectronics International N.V.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
@@ -47,14 +47,11 @@
/** @addtogroup EEPROM_Emulation
* @{
*/
-#ifdef STM32F7
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
/* Includes ------------------------------------------------------------------*/
#include "eeprom_emul.h"
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Global variable used to store variable value in read sequence */
@@ -65,83 +62,75 @@ uint16_t VirtAddVarTab[NB_OF_VAR];
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
-static HAL_StatusTypeDef EE_Format(void);
+static HAL_StatusTypeDef EE_Format();
static uint16_t EE_FindValidPage(uint8_t Operation);
static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data);
static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data);
static uint16_t EE_VerifyPageFullyErased(uint32_t Address);
-/**
+ /**
* @brief Restore the pages to a known good state in case of page's status
* corruption after a power loss.
* @param None.
* @retval - Flash error code: on write Flash error
* - FLASH_COMPLETE: on success
*/
-uint16_t EE_Initialize(void) {
- uint16_t PageStatus0 = 6, PageStatus1 = 6;
- uint16_t VarIdx = 0;
- uint16_t EepromStatus = 0, ReadStatus = 0;
- int16_t x = -1;
- HAL_StatusTypeDef FlashStatus;
- uint32_t SectorError = 0;
+uint16_t EE_Initialize() {
+ /* Get Page0 and Page1 status */
+ uint16_t PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS),
+ PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
+
FLASH_EraseInitTypeDef pEraseInit;
-
-
- /* Get Page0 status */
- PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS);
- /* Get Page1 status */
- PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
-
pEraseInit.TypeErase = TYPEERASE_SECTORS;
pEraseInit.Sector = PAGE0_ID;
pEraseInit.NbSectors = 1;
pEraseInit.VoltageRange = VOLTAGE_RANGE;
+ HAL_StatusTypeDef FlashStatus; // = HAL_OK
+
/* Check for invalid header states and repair if necessary */
+ uint32_t SectorError;
switch (PageStatus0) {
case ERASED:
if (PageStatus1 == VALID_PAGE) { /* Page0 erased, Page1 valid */
- /* Erase Page0 */
+ /* Erase Page0 */
if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
}
}
else if (PageStatus1 == RECEIVE_DATA) { /* Page0 erased, Page1 receive */
/* Erase Page0 */
if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
+ HAL_StatusTypeDef fStat = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
/* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ if (fStat != HAL_OK) return fStat;
}
/* Mark Page1 as valid */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE1_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE1_BASE_ADDRESS, VALID_PAGE);
}
else { /* First EEPROM access (Page0&1 are erased) or invalid state -> format EEPROM */
/* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return EE_Format();
}
break;
case RECEIVE_DATA:
if (PageStatus1 == VALID_PAGE) { /* Page0 receive, Page1 valid */
/* Transfer data from Page1 to Page0 */
- for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
+ int16_t x = -1;
+ for (uint16_t VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
if (( *(__IO uint16_t*)(PAGE0_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
x = VarIdx;
if (VarIdx != x) {
/* Read the last variables' updates */
- ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
+ uint16_t ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
/* In case variable corresponding to the virtual address was found */
if (ReadStatus != 0x1) {
/* Transfer the variable to the Page0 */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
+ uint16_t EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
/* If program operation was failed, a Flash error code is returned */
if (EepromStatus != HAL_OK) return EepromStatus;
}
@@ -156,9 +145,8 @@ uint16_t EE_Initialize(void) {
pEraseInit.VoltageRange = VOLTAGE_RANGE;
/* Erase Page1 */
if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
}
}
else if (PageStatus1 == ERASED) { /* Page0 receive, Page1 erased */
@@ -167,20 +155,18 @@ uint16_t EE_Initialize(void) {
pEraseInit.VoltageRange = VOLTAGE_RANGE;
/* Erase Page1 */
if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
+ HAL_StatusTypeDef fStat = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
/* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ if (fStat != HAL_OK) return fStat;
}
/* Mark Page0 as valid */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
}
else { /* Invalid state -> format eeprom */
/* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return EE_Format();
}
break;
@@ -204,17 +190,18 @@ uint16_t EE_Initialize(void) {
}
else { /* Page0 valid, Page1 receive */
/* Transfer data from Page0 to Page1 */
- for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
+ int16_t x = -1;
+ for (uint16_t VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
if ((*(__IO uint16_t*)(PAGE1_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
x = VarIdx;
if (VarIdx != x) {
/* Read the last variables' updates */
- ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
+ uint16_t ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
/* In case variable corresponding to the virtual address was found */
if (ReadStatus != 0x1) {
/* Transfer the variable to the Page1 */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
+ uint16_t EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
/* If program operation was failed, a Flash error code is returned */
if (EepromStatus != HAL_OK) return EepromStatus;
}
@@ -229,19 +216,16 @@ uint16_t EE_Initialize(void) {
pEraseInit.VoltageRange = VOLTAGE_RANGE;
/* Erase Page0 */
if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, simply return the result */
+ return HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
}
}
break;
default: /* Any other state -> format eeprom */
/* Erase both Page0 and Page1 and set Page0 as valid page */
- FlashStatus = EE_Format();
- /* If erase/program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
- break;
+ /* As the last operation, simply return the result */
+ return EE_Format();
}
return HAL_OK;
@@ -259,11 +243,10 @@ uint16_t EE_Initialize(void) {
*/
uint16_t EE_VerifyPageFullyErased(uint32_t Address) {
uint32_t ReadStatus = 1;
- uint16_t AddressValue = 0x5555;
/* Check each active page address starting from end */
while (Address <= PAGE0_END_ADDRESS) {
/* Get the current location content to be compared with virtual address */
- AddressValue = (*(__IO uint16_t*)Address);
+ uint16_t AddressValue = (*(__IO uint16_t*)Address);
/* Compare the read address with the virtual address */
if (AddressValue != ERASED) {
/* In case variable value is read, reset ReadStatus flag */
@@ -288,26 +271,22 @@ uint16_t EE_VerifyPageFullyErased(uint32_t Address) {
* - NO_VALID_PAGE: if no valid page was found.
*/
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data) {
- uint16_t ValidPage = PAGE0;
- uint16_t AddressValue = 0x5555, ReadStatus = 1;
- uint32_t Address = EEPROM_START_ADDRESS, PageStartAddress = EEPROM_START_ADDRESS;
+ uint16_t ReadStatus = 1;
/* Get active Page for read operation */
- ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
+ uint16_t ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
/* Check if there is no valid page */
if (ValidPage == NO_VALID_PAGE) return NO_VALID_PAGE;
- /* Get the valid Page start Address */
- PageStartAddress = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));
-
- /* Get the valid Page end Address */
- Address = (uint32_t)((EEPROM_START_ADDRESS - 2) + (uint32_t)((1 + ValidPage) * PAGE_SIZE));
+ /* Get the valid Page start and end Addresses */
+ uint32_t PageStartAddress = uint32_t(EEPROM_START_ADDRESS) + uint32_t(ValidPage * (PAGE_SIZE)),
+ Address = PageStartAddress + PAGE_SIZE - 2;
/* Check each active page address starting from end */
- while (Address > (PageStartAddress + 2)) {
+ while (Address > PageStartAddress + 2) {
/* Get the current location content to be compared with virtual address */
- AddressValue = (*(__IO uint16_t*)Address);
+ uint16_t AddressValue = (*(__IO uint16_t*)Address);
/* Compare the read address with the virtual address */
if (AddressValue == VirtAddress) {
@@ -352,17 +331,18 @@ uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data) {
* @retval Status of the last operation (Flash write or erase) done during
* EEPROM formating
*/
-static HAL_StatusTypeDef EE_Format(void) {
- HAL_StatusTypeDef FlashStatus = HAL_OK;
- uint32_t SectorError = 0;
+static HAL_StatusTypeDef EE_Format() {
FLASH_EraseInitTypeDef pEraseInit;
-
pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
pEraseInit.Sector = PAGE0_ID;
pEraseInit.NbSectors = 1;
pEraseInit.VoltageRange = VOLTAGE_RANGE;
+
+ HAL_StatusTypeDef FlashStatus; // = HAL_OK
+
/* Erase Page0 */
if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
+ uint32_t SectorError;
FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
/* If erase operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK) return FlashStatus;
@@ -375,9 +355,9 @@ static HAL_StatusTypeDef EE_Format(void) {
pEraseInit.Sector = PAGE1_ID;
/* Erase Page1 */
if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
- FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
- /* If erase operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
+ /* As the last operation, just return the result code */
+ uint32_t SectorError;
+ return HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
}
return HAL_OK;
@@ -393,26 +373,20 @@ static HAL_StatusTypeDef EE_Format(void) {
* of no valid page was found
*/
static uint16_t EE_FindValidPage(uint8_t Operation) {
- uint16_t PageStatus0 = 6, PageStatus1 = 6;
-
- /* Get Page0 actual status */
- PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS);
-
- /* Get Page1 actual status */
- PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
+ /* Get Page0 and Page1 actual status */
+ uint16_t PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS),
+ PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
/* Write or read operation */
switch (Operation) {
case WRITE_IN_VALID_PAGE: /* ---- Write operation ---- */
if (PageStatus1 == VALID_PAGE) {
/* Page0 receiving data */
- if (PageStatus0 == RECEIVE_DATA) return PAGE0; /* Page0 valid */
- else return PAGE1; /* Page1 valid */
+ return (PageStatus0 == RECEIVE_DATA) ? PAGE0 : PAGE1;
}
else if (PageStatus0 == VALID_PAGE) {
/* Page1 receiving data */
- if (PageStatus1 == RECEIVE_DATA) return PAGE1; /* Page1 valid */
- else return PAGE0; /* Page0 valid */
+ return (PageStatus1 == RECEIVE_DATA) ? PAGE1 : PAGE0;
}
else
return NO_VALID_PAGE; /* No valid Page */
@@ -441,34 +415,26 @@ static uint16_t EE_FindValidPage(uint8_t Operation) {
* - Flash error code: on write Flash error
*/
static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data) {
- HAL_StatusTypeDef FlashStatus = HAL_OK;
- uint16_t ValidPage = PAGE0;
- uint32_t Address = EEPROM_START_ADDRESS, PageEndAddress = EEPROM_START_ADDRESS+PAGE_SIZE;
-
/* Get valid Page for write operation */
- ValidPage = EE_FindValidPage(WRITE_IN_VALID_PAGE);
+ uint16_t ValidPage = EE_FindValidPage(WRITE_IN_VALID_PAGE);
/* Check if there is no valid page */
if (ValidPage == NO_VALID_PAGE) return NO_VALID_PAGE;
- /* Get the valid Page start Address */
- Address = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));
-
- /* Get the valid Page end Address */
- PageEndAddress = (uint32_t)((EEPROM_START_ADDRESS - 1) + (uint32_t)((ValidPage + 1) * PAGE_SIZE));
+ /* Get the valid Page start and end Addresses */
+ uint32_t Address = uint32_t(EEPROM_START_ADDRESS) + uint32_t(ValidPage * (PAGE_SIZE)),
+ PageEndAddress = Address + PAGE_SIZE - 1;
/* Check each active page address starting from begining */
while (Address < PageEndAddress) {
/* Verify if Address and Address+2 contents are 0xFFFFFFFF */
if ((*(__IO uint32_t*)Address) == 0xFFFFFFFF) {
/* Set variable data */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address, Data);
+ HAL_StatusTypeDef FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address, Data);
/* If program operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK) return FlashStatus;
- /* Set variable virtual address */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address + 2, VirtAddress);
- /* Return program operation status */
- return FlashStatus;
+ /* Set variable virtual address, return status */
+ return HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address + 2, VirtAddress);
}
else /* Next address location */
Address += 4;
@@ -490,16 +456,10 @@ static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Da
* - Flash error code: on write Flash error
*/
static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
- HAL_StatusTypeDef FlashStatus = HAL_OK;
- uint32_t NewPageAddress = EEPROM_START_ADDRESS;
- uint16_t OldPageId=0;
- uint16_t ValidPage = PAGE0, VarIdx = 0;
- uint16_t EepromStatus = 0, ReadStatus = 0;
- uint32_t SectorError = 0;
- FLASH_EraseInitTypeDef pEraseInit;
-
/* Get active Page for read operation */
- ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
+ uint16_t ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
+ uint32_t NewPageAddress = EEPROM_START_ADDRESS;
+ uint16_t OldPageId = 0;
if (ValidPage == PAGE1) { /* Page1 valid */
/* New page address where variable will be moved to */
@@ -517,20 +477,20 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
return NO_VALID_PAGE; /* No valid Page */
/* Set the new Page status to RECEIVE_DATA status */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, RECEIVE_DATA);
+ HAL_StatusTypeDef FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, RECEIVE_DATA);
/* If program operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK) return FlashStatus;
/* Write the variable passed as parameter in the new active page */
- EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
+ uint16_t EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
/* If program operation was failed, a Flash error code is returned */
if (EepromStatus != HAL_OK) return EepromStatus;
/* Transfer process: transfer variables from old to the new active page */
- for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
+ for (uint16_t VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
if (VirtAddVarTab[VarIdx] != VirtAddress) { /* Check each variable except the one passed as parameter */
/* Read the other last variable updates */
- ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
+ uint16_t ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
/* In case variable corresponding to the virtual address was found */
if (ReadStatus != 0x1) {
/* Transfer the variable to the new active page */
@@ -541,26 +501,24 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
}
}
+ FLASH_EraseInitTypeDef pEraseInit;
pEraseInit.TypeErase = TYPEERASE_SECTORS;
pEraseInit.Sector = OldPageId;
pEraseInit.NbSectors = 1;
pEraseInit.VoltageRange = VOLTAGE_RANGE;
/* Erase the old Page: Set old Page status to ERASED status */
+ uint32_t SectorError;
FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
/* If erase operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK) return FlashStatus;
/* Set new Page status to VALID_PAGE status */
- FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, VALID_PAGE);
- /* If program operation was failed, a Flash error code is returned */
- if (FlashStatus != HAL_OK) return FlashStatus;
-
- /* Return last operation flash status */
- return FlashStatus;
+ /* As the last operation, just return the result code */
+ return HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, VALID_PAGE);
}
-#endif // STM32F7
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
/**
* @}
diff --git a/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.h b/Marlin/src/HAL/HAL_STM32_F4_F7/eeprom_emul.h
similarity index 63%
rename from Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/eeprom_emul.h
index fe0da6387b..e4094f8e13 100644
--- a/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/eeprom_emul.h
@@ -8,7 +8,7 @@
******************************************************************************
* @attention
*
- * © Copyright � 2016 STMicroelectronics International N.V.
+ * Copyright © 2016 STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -45,65 +45,70 @@
******************************************************************************/
#pragma once
-// --------------------------------------------------------------------------
+// ------------------------
// Includes
-// --------------------------------------------------------------------------
-#include "../../../inc/MarlinConfig.h"
-#include "../HAL.h"
+// ------------------------
+
+#include "../../inc/MarlinConfig.h"
+#include "HAL.h"
/* Exported constants --------------------------------------------------------*/
/* EEPROM emulation firmware error codes */
-#define EE_OK (uint32_t)HAL_OK
-#define EE_ERROR (uint32_t)HAL_ERROR
-#define EE_BUSY (uint32_t)HAL_BUSY
-#define EE_TIMEOUT (uint32_t)HAL_TIMEOUT
+#define EE_OK uint32_t(HAL_OK)
+#define EE_ERROR uint32_t(HAL_ERROR)
+#define EE_BUSY uint32_t(HAL_BUSY)
+#define EE_TIMEOUT uint32_t(HAL_TIMEOUT)
/* Define the size of the sectors to be used */
-#define PAGE_SIZE (uint32_t)0x4000 /* Page size = 16KByte */
+#define PAGE_SIZE uint32_t(0x4000) /* Page size = 16KByte */
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
be done by word */
-#define VOLTAGE_RANGE (uint8_t)VOLTAGE_RANGE_3
+#define VOLTAGE_RANGE uint8_t(VOLTAGE_RANGE_3)
/* EEPROM start address in Flash */
-#define EEPROM_START_ADDRESS ((uint32_t)0x08078000) /* EEPROM emulation start address:
- after 480KByte of used Flash memory */
+#ifdef STM32F7
+ #define EEPROM_START_ADDRESS uint32_t(0x08100000) /* EEPROM emulation start address:
+ from sector2 : after 16KByte of used
+ Flash memory */
+#else
+ #define EEPROM_START_ADDRESS uint32_t(0x08078000) /* EEPROM emulation start address:
+ after 480KByte of used Flash memory */
+#endif
/* Pages 0 and 1 base and end addresses */
-#define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
-#define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
-#define PAGE0_ID FLASH_SECTOR_1
+#define PAGE0_BASE_ADDRESS uint32_t(EEPROM_START_ADDRESS + 0x0000)
+#define PAGE0_END_ADDRESS uint32_t(EEPROM_START_ADDRESS + PAGE_SIZE - 1)
+#define PAGE0_ID FLASH_SECTOR_1
-#define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x4000))
-#define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
-#define PAGE1_ID FLASH_SECTOR_2
+#define PAGE1_BASE_ADDRESS uint32_t(EEPROM_START_ADDRESS + 0x4000)
+#define PAGE1_END_ADDRESS uint32_t(EEPROM_START_ADDRESS + 2 * (PAGE_SIZE) - 1)
+#define PAGE1_ID FLASH_SECTOR_2
/* Used Flash pages for EEPROM emulation */
-#define PAGE0 ((uint16_t)0x0000)
-#define PAGE1 ((uint16_t)0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
+#define PAGE0 uint16_t(0x0000)
+#define PAGE1 uint16_t(0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
/* No valid page define */
-#define NO_VALID_PAGE ((uint16_t)0x00AB)
+#define NO_VALID_PAGE uint16_t(0x00AB)
/* Page status definitions */
-#define ERASED ((uint16_t)0xFFFF) /* Page is empty */
-#define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
-#define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
+#define ERASED uint16_t(0xFFFF) /* Page is empty */
+#define RECEIVE_DATA uint16_t(0xEEEE) /* Page is marked to receive data */
+#define VALID_PAGE uint16_t(0x0000) /* Page containing valid data */
/* Valid pages in read and write defines */
-#define READ_FROM_VALID_PAGE ((uint8_t)0x00)
-#define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
+#define READ_FROM_VALID_PAGE uint8_t(0x00)
+#define WRITE_IN_VALID_PAGE uint8_t(0x01)
/* Page full define */
-#define PAGE_FULL ((uint8_t)0x80)
+#define PAGE_FULL uint8_t(0x80)
/* Variables' number */
-#define NB_OF_VAR ((uint16_t)4096)
+#define NB_OF_VAR uint16_t(4096)
-/* Exported types ------------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
-uint16_t EE_Initialize(void);
+uint16_t EE_Initialize();
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
diff --git a/Marlin/src/HAL/HAL_STM32F4/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32_F4_F7/endstop_interrupts.h
similarity index 87%
rename from Marlin/src/HAL/HAL_STM32F4/endstop_interrupts.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/endstop_interrupts.h
index 23eca4bab7..d0aa731e89 100644
--- a/Marlin/src/HAL/HAL_STM32F4/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/endstop_interrupts.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,9 +25,9 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
-void setup_endstop_interrupts(void) {
+void setup_endstop_interrupts() {
#if HAS_X_MAX
attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
#endif
diff --git a/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h b/Marlin/src/HAL/HAL_STM32_F4_F7/fastio.h
similarity index 62%
rename from Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/fastio.h
index a1b3056d80..1e5ef2ef30 100644
--- a/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/fastio.h
@@ -1,10 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2017 Victor Perez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,15 +23,16 @@
#pragma once
/**
- * Fast I/O interfaces for STM32F7
+ * Fast I/O interfaces for STM32F4/7
* These use GPIO functions instead of Direct Port Manipulation, as on AVR.
*/
-#define _BV(b) (1 << (b))
+#ifndef PWM
+ #define PWM OUTPUT
+#endif
#define READ(IO) digitalRead(IO)
#define WRITE(IO,V) digitalWrite(IO,V)
-#define WRITE_VAR(IO,V) WRITE(IO,V)
#define _GET_MODE(IO)
#define _SET_MODE(IO,M) pinMode(IO, M)
@@ -67,123 +68,243 @@
#define PORTF 5
#define PORTG 6
-#define _STM32_PIN(_PORT,_PIN) ((PORT##_PORT * 16) + _PIN)
+#define _STM32_PIN(P,PN) ((PORT##P * 16) + PN)
+#undef PA0
#define PA0 _STM32_PIN(A, 0)
+#undef PA1
#define PA1 _STM32_PIN(A, 1)
+#undef PA2
#define PA2 _STM32_PIN(A, 2)
+#undef PA3
#define PA3 _STM32_PIN(A, 3)
+#undef PA4
#define PA4 _STM32_PIN(A, 4)
+#undef PA5
#define PA5 _STM32_PIN(A, 5)
+#undef PA6
#define PA6 _STM32_PIN(A, 6)
+#undef PA7
#define PA7 _STM32_PIN(A, 7)
+#undef PA8
#define PA8 _STM32_PIN(A, 8)
+#undef PA9
#define PA9 _STM32_PIN(A, 9)
+#undef PA10
#define PA10 _STM32_PIN(A, 10)
+#undef PA11
#define PA11 _STM32_PIN(A, 11)
+#undef PA12
#define PA12 _STM32_PIN(A, 12)
+#undef PA13
#define PA13 _STM32_PIN(A, 13)
+#undef PA14
#define PA14 _STM32_PIN(A, 14)
+#undef PA15
#define PA15 _STM32_PIN(A, 15)
+#undef PB0
#define PB0 _STM32_PIN(B, 0)
+#undef PB1
#define PB1 _STM32_PIN(B, 1)
+#undef PB2
#define PB2 _STM32_PIN(B, 2)
+#undef PB3
#define PB3 _STM32_PIN(B, 3)
+#undef PB4
#define PB4 _STM32_PIN(B, 4)
+#undef PB5
#define PB5 _STM32_PIN(B, 5)
+#undef PB6
#define PB6 _STM32_PIN(B, 6)
+#undef PB7
#define PB7 _STM32_PIN(B, 7)
+#undef PB8
#define PB8 _STM32_PIN(B, 8)
+#undef PB9
#define PB9 _STM32_PIN(B, 9)
+#undef PB10
#define PB10 _STM32_PIN(B, 10)
+#undef PB11
#define PB11 _STM32_PIN(B, 11)
+#undef PB12
#define PB12 _STM32_PIN(B, 12)
+#undef PB13
#define PB13 _STM32_PIN(B, 13)
+#undef PB14
#define PB14 _STM32_PIN(B, 14)
+#undef PB15
#define PB15 _STM32_PIN(B, 15)
+#undef PC0
#define PC0 _STM32_PIN(C, 0)
+#undef PC1
#define PC1 _STM32_PIN(C, 1)
+#undef PC2
#define PC2 _STM32_PIN(C, 2)
+#undef PC3
#define PC3 _STM32_PIN(C, 3)
+#undef PC4
#define PC4 _STM32_PIN(C, 4)
+#undef PC5
#define PC5 _STM32_PIN(C, 5)
+#undef PC6
#define PC6 _STM32_PIN(C, 6)
+#undef PC7
#define PC7 _STM32_PIN(C, 7)
+#undef PC8
#define PC8 _STM32_PIN(C, 8)
+#undef PC9
#define PC9 _STM32_PIN(C, 9)
+#undef PC10
#define PC10 _STM32_PIN(C, 10)
+#undef PC11
#define PC11 _STM32_PIN(C, 11)
+#undef PC12
#define PC12 _STM32_PIN(C, 12)
+#undef PC13
#define PC13 _STM32_PIN(C, 13)
+#undef PC14
#define PC14 _STM32_PIN(C, 14)
+#undef PC15
#define PC15 _STM32_PIN(C, 15)
+#undef PD0
#define PD0 _STM32_PIN(D, 0)
+#undef PD1
#define PD1 _STM32_PIN(D, 1)
+#undef PD2
#define PD2 _STM32_PIN(D, 2)
+#undef PD3
#define PD3 _STM32_PIN(D, 3)
+#undef PD4
#define PD4 _STM32_PIN(D, 4)
+#undef PD5
#define PD5 _STM32_PIN(D, 5)
+#undef PD6
#define PD6 _STM32_PIN(D, 6)
+#undef PD7
#define PD7 _STM32_PIN(D, 7)
+#undef PD8
#define PD8 _STM32_PIN(D, 8)
+#undef PD9
#define PD9 _STM32_PIN(D, 9)
+#undef PD10
#define PD10 _STM32_PIN(D, 10)
+#undef PD11
#define PD11 _STM32_PIN(D, 11)
+#undef PD12
#define PD12 _STM32_PIN(D, 12)
+#undef PD13
#define PD13 _STM32_PIN(D, 13)
+#undef PD14
#define PD14 _STM32_PIN(D, 14)
+#undef PD15
#define PD15 _STM32_PIN(D, 15)
+#undef PE0
#define PE0 _STM32_PIN(E, 0)
+#undef PE1
#define PE1 _STM32_PIN(E, 1)
+#undef PE2
#define PE2 _STM32_PIN(E, 2)
+#undef PE3
#define PE3 _STM32_PIN(E, 3)
+#undef PE4
#define PE4 _STM32_PIN(E, 4)
+#undef PE5
#define PE5 _STM32_PIN(E, 5)
+#undef PE6
#define PE6 _STM32_PIN(E, 6)
+#undef PE7
#define PE7 _STM32_PIN(E, 7)
+#undef PE8
#define PE8 _STM32_PIN(E, 8)
+#undef PE9
#define PE9 _STM32_PIN(E, 9)
+#undef PE10
#define PE10 _STM32_PIN(E, 10)
+#undef PE11
#define PE11 _STM32_PIN(E, 11)
+#undef PE12
#define PE12 _STM32_PIN(E, 12)
+#undef PE13
#define PE13 _STM32_PIN(E, 13)
+#undef PE14
#define PE14 _STM32_PIN(E, 14)
+#undef PE15
#define PE15 _STM32_PIN(E, 15)
-#define PF0 _STM32_PIN(F, 0)
-#define PF1 _STM32_PIN(F, 1)
-#define PF2 _STM32_PIN(F, 2)
-#define PF3 _STM32_PIN(F, 3)
-#define PF4 _STM32_PIN(F, 4)
-#define PF5 _STM32_PIN(F, 5)
-#define PF6 _STM32_PIN(F, 6)
-#define PF7 _STM32_PIN(F, 7)
-#define PF8 _STM32_PIN(F, 8)
-#define PF9 _STM32_PIN(F, 9)
-#define PF10 _STM32_PIN(F, 10)
-#define PF11 _STM32_PIN(F, 11)
-#define PF12 _STM32_PIN(F, 12)
-#define PF13 _STM32_PIN(F, 13)
-#define PF14 _STM32_PIN(F, 14)
-#define PF15 _STM32_PIN(F, 15)
+#ifdef STM32F7
-#define PG0 _STM32_PIN(G, 0)
-#define PG1 _STM32_PIN(G, 1)
-#define PG2 _STM32_PIN(G, 2)
-#define PG3 _STM32_PIN(G, 3)
-#define PG4 _STM32_PIN(G, 4)
-#define PG5 _STM32_PIN(G, 5)
-#define PG6 _STM32_PIN(G, 6)
-#define PG7 _STM32_PIN(G, 7)
-#define PG8 _STM32_PIN(G, 8)
-#define PG9 _STM32_PIN(G, 9)
-#define PG10 _STM32_PIN(G, 10)
-#define PG11 _STM32_PIN(G, 11)
-#define PG12 _STM32_PIN(G, 12)
-#define PG13 _STM32_PIN(G, 13)
-#define PG14 _STM32_PIN(G, 14)
-#define PG15 _STM32_PIN(G, 15)
+ #undef PORTF
+ #define PORTF 5
+ #undef PF0
+ #define PF0 _STM32_PIN(F, 0)
+ #undef PF1
+ #define PF1 _STM32_PIN(F, 1)
+ #undef PF2
+ #define PF2 _STM32_PIN(F, 2)
+ #undef PF3
+ #define PF3 _STM32_PIN(F, 3)
+ #undef PF4
+ #define PF4 _STM32_PIN(F, 4)
+ #undef PF5
+ #define PF5 _STM32_PIN(F, 5)
+ #undef PF6
+ #define PF6 _STM32_PIN(F, 6)
+ #undef PF7
+ #define PF7 _STM32_PIN(F, 7)
+ #undef PF8
+ #define PF8 _STM32_PIN(F, 8)
+ #undef PF9
+ #define PF9 _STM32_PIN(F, 9)
+ #undef PF10
+ #define PF10 _STM32_PIN(F, 10)
+ #undef PF11
+ #define PF11 _STM32_PIN(F, 11)
+ #undef PF12
+ #define PF12 _STM32_PIN(F, 12)
+ #undef PF13
+ #define PF13 _STM32_PIN(F, 13)
+ #undef PF14
+ #define PF14 _STM32_PIN(F, 14)
+ #undef PF15
+ #define PF15 _STM32_PIN(F, 15)
+
+ #undef PORTG
+ #define PORTG 6
+ #undef PG0
+ #define PG0 _STM32_PIN(G, 0)
+ #undef PG1
+ #define PG1 _STM32_PIN(G, 1)
+ #undef PG2
+ #define PG2 _STM32_PIN(G, 2)
+ #undef PG3
+ #define PG3 _STM32_PIN(G, 3)
+ #undef PG4
+ #define PG4 _STM32_PIN(G, 4)
+ #undef PG5
+ #define PG5 _STM32_PIN(G, 5)
+ #undef PG6
+ #define PG6 _STM32_PIN(G, 6)
+ #undef PG7
+ #define PG7 _STM32_PIN(G, 7)
+ #undef PG8
+ #define PG8 _STM32_PIN(G, 8)
+ #undef PG9
+ #define PG9 _STM32_PIN(G, 9)
+ #undef PG10
+ #define PG10 _STM32_PIN(G, 10)
+ #undef PG11
+ #define PG11 _STM32_PIN(G, 11)
+ #undef PG12
+ #define PG12 _STM32_PIN(G, 12)
+ #undef PG13
+ #define PG13 _STM32_PIN(G, 13)
+ #undef PG14
+ #define PG14 _STM32_PIN(G, 14)
+ #undef PG15
+ #define PG15 _STM32_PIN(G, 15)
+
+#endif // STM32GENERIC && STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h
new file mode 100644
index 0000000000..7b8d29aa7d
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h
@@ -0,0 +1,37 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+/**
+ * Test STM32F4/7-specific configuration values for errors at compile-time.
+ */
+//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
+// #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
+//#endif
+
+#if ENABLED(EMERGENCY_PARSER)
+ #error "EMERGENCY_PARSER is not yet implemented for STM32F4/7. Disable EMERGENCY_PARSER to continue."
+#endif
+
+#if ENABLED(FAST_PWM_FAN)
+ #error "FAST_PWM_FAN is not yet implemented for this platform."
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/persistent_store_eeprom.cpp
similarity index 88%
rename from Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/persistent_store_eeprom.cpp
index 4990213cfc..4bd86d225d 100644
--- a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/persistent_store_eeprom.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
@@ -21,7 +21,7 @@
*
*/
-#ifdef STM32F7
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfigPre.h"
@@ -52,10 +52,10 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false;
}
-bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc) {
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
uint8_t c = eeprom_read_byte((uint8_t*)pos);
- *value = c;
+ if (writing) *value = c;
crc16(crc, &c, 1);
pos++;
value++;
@@ -66,4 +66,4 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
size_t PersistentStore::capacity() { return E2END + 1; }
#endif // EEPROM_SETTINGS
-#endif // STM32F7
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/pinsDebug.h b/Marlin/src/HAL/HAL_STM32_F4_F7/pinsDebug.h
new file mode 100644
index 0000000000..342b875561
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/pinsDebug.h
@@ -0,0 +1,27 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#ifdef NUM_DIGITAL_PINS // Only in ST's Arduino core (STM32duino, STM32Core)
+ #include "../HAL_STM32/pinsDebug_STM32duino.h"
+#elif defined(BOARD_NR_GPIO_PINS) // Only in STM32GENERIC (Maple)
+ #include "../HAL_STM32/pinsDebug_STM32GENERIC.h"
+#else
+ #error "M43 Pins Debugging not supported for this board."
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F4/spi_pins.h b/Marlin/src/HAL/HAL_STM32_F4_F7/spi_pins.h
similarity index 93%
rename from Marlin/src/HAL/HAL_STM32F4/spi_pins.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/spi_pins.h
index e18e12278d..4aef289a77 100644
--- a/Marlin/src/HAL/HAL_STM32F4/spi_pins.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/spi_pins.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h
new file mode 100644
index 0000000000..cf33205bdd
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/timers.h
@@ -0,0 +1,28 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ * Copyright (c) 2017 Victor Perez
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#ifdef STM32F4
+ #include "STM32F4/timers.h"
+#else
+ #include "STM32F7/timers.h"
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp
similarity index 80%
rename from Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp
index fd2f309515..e51af618c9 100644
--- a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,13 +20,13 @@
*
*/
-#if defined(STM32GENERIC) && defined(STM32F4)
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfig.h"
#if ENABLED(USE_WATCHDOG)
- #include "watchdog_STM32F4.h"
+ #include "watchdog.h"
IWDG_HandleTypeDef hiwdg;
@@ -37,21 +37,20 @@
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
//Error_Handler();
}
- }
-
- void watchdog_reset() {
- /* Refresh IWDG: reload counter */
- if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
- /* Refresh Error */
- //Error_Handler();
- }
else {
- #if PIN_EXISTS(LED)
+ #if PIN_EXISTS(LED) && !ENABLED(PINS_DEBUGGING)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
}
-#endif // USE_WATCHDOG
+ void HAL_watchdog_refresh() {
+ /* Refresh IWDG: reload counter */
+ if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
+ /* Refresh Error */
+ //Error_Handler();
+ }
+ }
-#endif // STM32GENERIC && STM32F4
+#endif // USE_WATCHDOG
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
similarity index 84%
rename from Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
index 4076c2b03a..9e2a2dc21c 100644
--- a/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,4 +24,4 @@
extern IWDG_HandleTypeDef hiwdg;
void watchdog_init();
-void watchdog_reset();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
index fa80cd5ba9..2e15324e3b 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -44,10 +44,10 @@ static const uint8_t pin2sc1a[] = {
/*
// disable interrupts
- void cli(void) { noInterrupts(); }
+ void cli() { noInterrupts(); }
// enable interrupts
- void sei(void) { interrupts(); }
+ void sei() { interrupts(); }
*/
void HAL_adc_init() {
@@ -56,9 +56,9 @@ void HAL_adc_init() {
NVIC_ENABLE_IRQ(IRQ_FTM1);
}
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
switch (RCM_SRS0) {
case 128: return RST_POWER_ON; break;
case 64: return RST_EXTERNAL; break;
@@ -87,6 +87,6 @@ extern "C" {
void HAL_adc_start_conversion(const uint8_t adc_pin) { ADC0_SC1A = pin2sc1a[adc_pin]; }
-uint16_t HAL_adc_get_result(void) { return ADC0_RA; }
+uint16_t HAL_adc_get_result() { return ADC0_RA; }
#endif // __MK20DX256__
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.h b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.h
index dbc75540b3..e2df8df86b 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -19,24 +19,22 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Description: HAL for Teensy 3.5 and Teensy 3.6
*/
-#pragma once
-
#define CPU_32_BIT
#include "../shared/Marduino.h"
+#include "../shared/math_32bit.h"
+#include "../shared/HAL_SPI.h"
-#include "../math_32bit.h"
-#include "../HAL_SPI.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "fastio_Teensy.h"
-#include "watchdog_Teensy.h"
-
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
#include
@@ -89,28 +87,22 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
+inline void HAL_init() {}
+
// Clear the reset reason
-void HAL_clear_reset_source(void);
+void HAL_clear_reset_source();
// Get the reason for the reset
-uint8_t HAL_get_reset_source(void);
+uint8_t HAL_get_reset_source();
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
extern "C" {
- int freeMemory(void);
+ int freeMemory();
}
-
-// SPI: Extended functions which take a channel number (hardware SPI only)
-
-// Write single byte to specified SPI channel
-void spiSend(uint32_t chan, byte b);
-
-// Write buffer to specified SPI channel
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-
-// Read single byte from specified SPI channel
-uint8_t spiRec(uint32_t chan);
+#pragma GCC diagnostic pop
// ADC
@@ -123,7 +115,7 @@ void HAL_adc_init();
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/HAL_SPI.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/HAL_SPI.cpp
index 331703dc55..4236f02b0f 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/HAL_SPI.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,18 +34,16 @@ static SPISettings spiConfig;
*/
// Initialize SPI bus
-void spiBegin(void) {
+void spiBegin() {
#if !PIN_EXISTS(SS)
#error "SS_PIN not defined!"
#endif
- SET_OUTPUT(SS_PIN);
- WRITE(SS_PIN, HIGH);
+ OUT_WRITE(SS_PIN, HIGH);
SET_OUTPUT(SCK_PIN);
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);
- //#if DISABLED(SOFTWARE_SPI)
- #if 0
+ #if 0 && DISABLED(SOFTWARE_SPI)
// set SS high - may be chip select for another SPI device
#if SET_SPI_SS_HIGH
WRITE(SS_PIN, HIGH);
@@ -73,7 +71,7 @@ void spiInit(uint8_t spiRate) {
}
// SPI receive a byte
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
const uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
similarity index 64%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
index 24e84bb0d2..6451f6b172 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,29 +25,29 @@
#if HAS_SERVOS
-#include "HAL_Servo_Teensy.h"
+#include "Servo.h"
uint8_t servoPin[MAX_SERVOS] = { 0 };
-int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex]);
+int8_t libServo::attach(const int inPin) {
+ if (servoIndex >= MAX_SERVOS) return -1;
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex]);
}
-int8_t libServo::attach(const int pin, const int min, const int max) {
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex], min, max);
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex], inMin, inMax);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
similarity index 87%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
index 0b92a44efc..3eb7d39b22 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
@@ -1,10 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,6 +30,7 @@ class libServo : public Servo {
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
private:
+ typedef Servo super;
uint16_t min_ticks;
uint16_t max_ticks;
uint8_t servoIndex; // index into the channel data for this servo
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h b/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
index ad0235179b..221b721b35 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Endstop Interrupts
@@ -34,53 +35,43 @@
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
*/
-#pragma once
-
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
/**
* Endstop interrupts for Due based targets.
* On Due, all pins support external interrupt capability.
*/
-void setup_endstop_interrupts( void ) {
-
+void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
#if HAS_X_MAX
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
+ _ATTACH(X_MAX_PIN);
#endif
-
#if HAS_X_MIN
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#endif
-
#if HAS_Y_MAX
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#endif
-
#if HAS_Y_MIN
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#endif
-
#if HAS_Z_MAX
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#endif
-
#if HAS_Z_MIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#endif
-
#if HAS_Z2_MAX
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#endif
-
#if HAS_Z2_MIN
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#endif
-
#if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#endif
}
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/fastio_Teensy.h b/Marlin/src/HAL/HAL_TEENSY31_32/fastio.h
similarity index 94%
rename from Marlin/src/HAL/HAL_TEENSY35_36/fastio_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/fastio.h
index 5df7faffb9..d1b5f567d7 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/fastio_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -71,7 +71,6 @@
#define READ(IO) _READ(IO)
-#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
#define WRITE(IO,V) _WRITE(IO,V)
#define TOGGLE(IO) _TOGGLE(IO)
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/SanityCheck.h b/Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h
similarity index 88%
rename from Marlin/src/HAL/HAL_TEENSY31_32/SanityCheck.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h
index 9ecf5e35f5..389d27824e 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/SanityCheck.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Test TEENSY35_36 specific configuration values for errors at compile-time.
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/persistent_store_impl.cpp
index d746dc9730..6da102638f 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/persistent_store_impl.cpp
@@ -1,18 +1,33 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
#ifdef __MK20DX256__
#include "../../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS)
-#include "../persistent_store_api.h"
+#include "../shared/persistent_store_api.h"
-namespace HAL {
-namespace PersistentStore {
+bool PersistentStore::access_start() { return true; }
+bool PersistentStore::access_finish() { return true; }
-bool access_start() { return true; }
-bool access_finish() { return true; }
-
-bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value;
@@ -32,7 +47,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return false;
}
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c;
@@ -43,8 +58,5 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
return false;
}
-} // PersistentStore
-} // HAL
-
#endif // EEPROM_SETTINGS
#endif // __MK20DX256__
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h b/Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h
index cfc9a2d14e..8a0ab8f9a4 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
* along with this program. If not, see .
*
*/
-
#pragma once
#define SCK_PIN 13
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp
index 3a7870da6e..1ae4bcf4f0 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,14 +27,14 @@
#ifdef __MK20DX256__
#include "HAL.h"
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
-FORCE_INLINE static void __ISB(void) {
+FORCE_INLINE static void __ISB() {
__asm__ __volatile__("isb 0xF":::"memory");
}
@@ -42,7 +42,7 @@ FORCE_INLINE static void __ISB(void) {
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
-FORCE_INLINE static void __DSB(void) {
+FORCE_INLINE static void __DSB() {
__asm__ __volatile__("dsb 0xF":::"memory");
}
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h b/Marlin/src/HAL/HAL_TEENSY31_32/timers.h
similarity index 79%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/timers.h
index 04048798eb..6dff7701be 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/timers.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,23 +19,18 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Description: HAL for
* Teensy3.2 (__MK20DX256__)
*/
-#pragma once
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -47,8 +42,8 @@ typedef uint32_t hal_timer_t;
#define FTM0_TIMER_PRESCALE_BITS 0b011
#define FTM1_TIMER_PRESCALE_BITS 0b010
-#define FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
-#define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
+#define FTM0_TIMER_RATE (F_BUS / (FTM0_TIMER_PRESCALE)) // 60MHz / 8 = 7500kHz
+#define FTM1_TIMER_RATE (F_BUS / (FTM1_TIMER_PRESCALE)) // 60MHz / 4 = 15MHz
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
@@ -73,8 +68,8 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr(void) //void TC3_Handler()
-#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr(void) //void TC4_Handler()
+#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
+#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/watchdog.cpp
similarity index 86%
rename from Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/watchdog.cpp
index 07505140e8..d1313e1f5d 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
#if ENABLED(USE_WATCHDOG)
-#include "watchdog_Teensy.h"
+#include "watchdog.h"
void watchdog_init() {
WDOG_TOVALH = 0;
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h b/Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h
similarity index 85%
rename from Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h
index d0b7d030e9..861afcbc91 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
* along with this program. If not, see .
*
*/
-
#pragma once
#include "HAL.h"
@@ -28,7 +27,7 @@
void watchdog_init();
-inline void watchdog_reset() {
+inline void HAL_watchdog_refresh() {
// Watchdog refresh sequence
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
index c4d6b3cf54..5848944792 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -51,10 +51,10 @@ static const uint8_t pin2sc1a[] = {
/*
// disable interrupts
- void cli(void) { noInterrupts(); }
+ void cli() { noInterrupts(); }
// enable interrupts
- void sei(void) { interrupts(); }
+ void sei() { interrupts(); }
*/
void HAL_adc_init() {
@@ -64,9 +64,9 @@ void HAL_adc_init() {
NVIC_ENABLE_IRQ(IRQ_FTM1);
}
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
switch (RCM_SRS0) {
case 128: return RST_POWER_ON; break;
case 64: return RST_EXTERNAL; break;
@@ -109,7 +109,7 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
}
}
-uint16_t HAL_adc_get_result(void) {
+uint16_t HAL_adc_get_result() {
switch (HAL_adc_select) {
case 0: return ADC0_RA;
case 1: return ADC1_RA;
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.h b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.h
index 9ead7405a7..9fc4ff6633 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -27,18 +27,14 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_Teensy.h"
-#include "watchdog_Teensy.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
#include
#include
@@ -47,9 +43,9 @@
#define ST7920_DELAY_2 DELAY_NS(750)
#define ST7920_DELAY_3 DELAY_NS(750)
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
#define IS_TEENSY35 defined(__MK64FX512__)
@@ -97,25 +93,22 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
-/** clear reset reason */
-void HAL_clear_reset_source(void);
+inline void HAL_init() {}
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
+// Clear reset reason
+void HAL_clear_reset_source();
+
+// Reset reason
+uint8_t HAL_get_reset_source();
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
extern "C" {
- int freeMemory(void);
+ int freeMemory();
}
-
-// SPI: Extended functions which take a channel number (hardware SPI only)
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
+#pragma GCC diagnostic pop
// ADC
@@ -128,7 +121,7 @@ void HAL_adc_init();
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_SPI.cpp
similarity index 56%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/HAL_SPI.cpp
index 6220225a1d..44ab74cc9b 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_SPI.cpp
@@ -1,3 +1,24 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "HAL.h"
@@ -8,32 +29,27 @@
static SPISettings spiConfig;
-// Standard SPI functions
-/** Initialize SPI bus */
-void spiBegin(void) {
+void spiBegin() {
#if !PIN_EXISTS(SS)
#error SS_PIN not defined!
#endif
- SET_OUTPUT(SS_PIN);
- WRITE(SS_PIN, HIGH);
+ OUT_WRITE(SS_PIN, HIGH);
SET_OUTPUT(SCK_PIN);
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);
- //#if DISABLED(SOFTWARE_SPI)
- #if 0
+ #if 0 && DISABLED(SOFTWARE_SPI)
// set SS high - may be chip select for another SPI device
#if SET_SPI_SS_HIGH
WRITE(SS_PIN, HIGH);
- #endif // SET_SPI_SS_HIGH
+ #endif
// set a default rate
spiInit(SPI_HALF_SPEED); // 1
- #endif // SOFTWARE_SPI
+ #endif
}
-/** Configure SPI for specified SPI speed */
void spiInit(uint8_t spiRate) {
- // Use datarates Marlin uses
+ // Use Marlin data-rates
uint32_t clock;
switch (spiRate) {
case SPI_FULL_SPEED: clock = 10000000; break;
@@ -49,44 +65,39 @@ void spiInit(uint8_t spiRate) {
SPI.begin();
}
-//------------------------------------------------------------------------------
-/** SPI receive a byte */
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
return returnByte;
-// SPDR = 0xFF;
-// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
-// return SPDR;
+ //SPDR = 0xFF;
+ //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
+ //return SPDR;
}
-//------------------------------------------------------------------------------
-/** SPI read data */
+
void spiRead(uint8_t* buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig);
SPI.transfer(buf, nbyte);
SPI.endTransaction();
-//if (nbyte-- == 0) return;
-// SPDR = 0xFF;
-//for (uint16_t i = 0; i < nbyte; i++) {
-// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
-// buf[i] = SPDR;
-// SPDR = 0xFF;
-//}
-//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
-//buf[nbyte] = SPDR;
+ //if (nbyte-- == 0) return;
+ // SPDR = 0xFF;
+ //for (uint16_t i = 0; i < nbyte; i++) {
+ // while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
+ // buf[i] = SPDR;
+ // SPDR = 0xFF;
+ //}
+ //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
+ //buf[nbyte] = SPDR;
}
-//------------------------------------------------------------------------------
-/** SPI send a byte */
+
void spiSend(uint8_t b) {
SPI.beginTransaction(spiConfig);
SPI.transfer(b);
SPI.endTransaction();
-// SPDR = b;
-// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
+ //SPDR = b;
+ //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
}
-//------------------------------------------------------------------------------
-/** SPI send block */
+
void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.beginTransaction(spiConfig);
SPDR = token;
@@ -100,11 +111,9 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.endTransaction();
}
-
-/** Begin SPI transaction, set clock, bit order, data mode */
+// Begin SPI transaction, set clock, bit order, data mode
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
spiConfig = SPISettings(spiClock, bitOrder, dataMode);
-
SPI.beginTransaction(spiConfig);
}
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
deleted file mode 100644
index ff56036ccd..0000000000
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-
-#include "../../inc/MarlinConfig.h"
-
-#if HAS_SERVOS
-
-#include "HAL_Servo_Teensy.h"
-
-uint8_t servoPin[MAX_SERVOS] = { 0 };
-
-int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex]);
-}
-
-int8_t libServo::attach(const int pin, const int min, const int max) {
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex], min, max);
-}
-
-void libServo::move(const int value) {
- constexpr uint16_t servo_delay[] = SERVO_DELAY;
- static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
- #endif
- }
-}
-
-#endif // HAS_SERVOS
-
-#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
similarity index 59%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
index bfe03f5d90..d376b80a7d 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
@@ -1,10 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- * Copyright (C) 2017 Victor Perez
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,34 +19,39 @@
* along with this program. If not, see .
*
*/
-
-#if defined(STM32GENERIC) && defined(STM32F4)
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
-#include "HAL_Servo_STM32F4.h"
+#include "Servo.h"
-int8_t libServo::attach(const int pin) {
- return Servo::attach(pin);
+uint8_t servoPin[MAX_SERVOS] = { 0 };
+
+int8_t libServo::attach(const int inPin) {
+ if (servoIndex >= MAX_SERVOS) return -1;
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex]);
}
-int8_t libServo::attach(const int pin, const int min, const int max) {
- return Servo::attach(pin, min, max);
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex], inMin, inMax);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
+
#endif // HAS_SERVOS
-#endif // STM32GENERIC && STM32F4
+#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
similarity index 75%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
index d02cdc9f74..cafd323a38 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,14 +23,15 @@
#include
-// Inherit and expand on the official library
+// Inherit and expand on core Servo library
class libServo : public Servo {
public:
int8_t attach(const int pin);
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
private:
- uint16_t min_ticks;
- uint16_t max_ticks;
- uint8_t servoIndex; // index into the channel data for this servo
+ typedef Servo super;
+ uint16_t min_ticks;
+ uint16_t max_ticks;
+ uint8_t servoIndex; // Index into the channel data for this servo
};
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h b/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h
index 7327dc1a92..3862f2b5b8 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,44 +38,45 @@
#include "../../module/endstops.h"
// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstops.update(); }
+void endstop_ISR() { endstops.update(); }
/**
* Endstop interrupts for Due based targets.
* On Due, all pins support external interrupt capability.
*/
-void setup_endstop_interrupts( void ) {
+void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
#if HAS_X_MAX
- attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
+ _ATTACH(X_MAX_PIN);
#endif
#if HAS_X_MIN
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#endif
#if HAS_Y_MAX
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#endif
#if HAS_Y_MIN
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#endif
#if HAS_Z_MAX
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#endif
#if HAS_Z_MIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#endif
#if HAS_Z2_MAX
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#endif
#if HAS_Z2_MIN
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#endif
#if HAS_Z3_MAX
- attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#endif
#if HAS_Z3_MIN
- attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#endif
#if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#endif
}
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/fastio.h
similarity index 94%
rename from Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/fastio.h
index 96bbc93112..d1b5f567d7 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/fastio.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Fast I/O Routines for Teensy 3.5 and Teensy 3.6
@@ -26,8 +27,6 @@
* Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
*/
-#pragma once
-
#ifndef MASK
#define MASK(PIN) (1 << PIN)
#endif
@@ -72,7 +71,6 @@
#define READ(IO) _READ(IO)
-#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
#define WRITE(IO,V) _WRITE(IO,V)
#define TOGGLE(IO) _TOGGLE(IO)
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_LCD.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_LCD.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_adv.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_adv.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_post.h
new file mode 100644
index 0000000000..85f26f4016
--- /dev/null
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/inc/Conditionals_post.h
@@ -0,0 +1,22 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/SanityCheck.h b/Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h
similarity index 88%
rename from Marlin/src/HAL/HAL_TEENSY35_36/SanityCheck.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h
index 597a3638da..6a126b683e 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/SanityCheck.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Test TEENSY35_36 specific configuration values for errors at compile-time.
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp
index ad5ed361ae..17934f71a3 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
deleted file mode 100644
index 29b4653b3e..0000000000
--- a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-
-#include "../../inc/MarlinConfig.h"
-
-#if ENABLED(EEPROM_SETTINGS)
-
-#include "../shared/persistent_store_api.h"
-
-namespace HAL {
-namespace PersistentStore {
-
-bool access_start() { return true; }
-bool access_finish() { return true; }
-
-bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
- while (size--) {
- uint8_t * const p = (uint8_t * const)pos;
- uint8_t v = *value;
- // EEPROM has only ~100,000 write cycles,
- // so only write bytes that have changed!
- if (v != eeprom_read_byte(p)) {
- eeprom_write_byte(p, v);
- if (eeprom_read_byte(p) != v) {
- SERIAL_ECHO_MSG(MSG_ERR_EEPROM_WRITE);
- return true;
- }
- }
- crc16(crc, &v, 1);
- pos++;
- value++;
- };
- return false;
-}
-
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
- do {
- uint8_t c = eeprom_read_byte((uint8_t*)pos);
- if (writing) *value = c;
- crc16(crc, &c, 1);
- pos++;
- value++;
- } while (--size);
- return false;
-}
-
-} // PersistentStore
-} // HAL
-
-#endif // EEPROM_SETTINGS
-#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h b/Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h
index cb472aff01..db750cf6ec 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h
@@ -1,9 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,8 +16,7 @@
* along with this program. If not, see .
*
*/
-
-#ifndef HAL_PINSDEBUG_TEENSY_H
+#pragma once
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
@@ -106,5 +102,3 @@ bool HAL_pwm_status(int8_t pin) {
}
static void HAL_pwm_details(uint8_t pin) { /* TODO */ }
-
-#endif
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/spi_pins.h b/Marlin/src/HAL/HAL_TEENSY35_36/spi_pins.h
index 152d6b4c21..9c6a83e3f8 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/spi_pins.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/spi_pins.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp
index 471d823da5..6ee6118208 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@
*
*/
-
/**
* Teensy3.5 __MK64FX512__
* Teensy3.6 __MK66FX1M0__
@@ -29,14 +28,14 @@
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "HAL.h"
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
-FORCE_INLINE static void __ISB(void) {
+FORCE_INLINE static void __ISB() {
__asm__ __volatile__("isb 0xF":::"memory");
}
@@ -44,7 +43,7 @@ FORCE_INLINE static void __ISB(void) {
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
-FORCE_INLINE static void __DSB(void) {
+FORCE_INLINE static void __DSB() {
__asm__ __volatile__("dsb 0xF":::"memory");
}
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/timers.h
similarity index 85%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/timers.h
index fed256452a..8ae51107c7 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/timers.h
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
@@ -25,15 +25,11 @@
* Teensy3.6 (__MK66FX1M0__)
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -71,8 +67,8 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr(void) //void TC3_Handler()
-#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr(void) //void TC4_Handler()
+#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
+#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog.cpp
similarity index 87%
rename from Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/watchdog.cpp
index 46605473a1..f58217c750 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
#if ENABLED(USE_WATCHDOG)
-#include "watchdog_Teensy.h"
+#include "watchdog.h"
void watchdog_init() {
WDOG_TOVALH = 0;
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h
similarity index 84%
rename from Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h
index ba0916976c..7c27260906 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
void watchdog_init();
-inline void watchdog_reset() {
+inline void HAL_watchdog_refresh() {
// Watchdog refresh sequence
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
diff --git a/Marlin/src/HAL/platforms.h b/Marlin/src/HAL/platforms.h
index f5042b9fed..e3e7f52cfa 100644
--- a/Marlin/src/HAL/platforms.h
+++ b/Marlin/src/HAL/platforms.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,16 +33,16 @@
#define HAL_PLATFORM HAL_LPC1768
#elif defined(__STM32F1__) || defined(TARGET_STM32F1)
#define HAL_PLATFORM HAL_STM32F1
-#elif defined(STM32GENERIC) && defined(STM32F4)
- #define HAL_PLATFORM HAL_STM32F4
-#elif defined(STM32GENERIC) && defined(STM32F7)
- #define HAL_PLATFORM HAL_STM32F7
+#elif defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
+ #define HAL_PLATFORM HAL_STM32_F4_F7
#elif defined(ARDUINO_ARCH_STM32)
#define HAL_PLATFORM HAL_STM32
#elif defined(ARDUINO_ARCH_ESP32)
#define HAL_PLATFORM HAL_ESP32
#elif defined(__PLAT_LINUX__)
#define HAL_PLATFORM HAL_LINUX
+#elif defined(__SAMD51__)
+ #define HAL_PLATFORM HAL_SAMD51
#else
#error "Unsupported Platform!"
#endif
diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h
index bab7d7471e..b3f8f246fb 100644
--- a/Marlin/src/HAL/shared/Delay.h
+++ b/Marlin/src/HAL/shared/Delay.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,8 +29,8 @@
* DELAY_US(count): Delay execution in microseconds
*/
-#include "../../core/macros.h"
#include "../../core/millis_t.h"
+#include "../../core/macros.h"
#if defined(__arm__) || defined(__thumb__)
@@ -53,7 +53,7 @@
FORCE_INLINE static void DELAY_CYCLES(const uint32_t x) {
const uint32_t endCycles = getCycleCount() + x;
- while (PENDING(getCycleCount(), endCycles)) { }
+ while (PENDING(getCycleCount(), endCycles)) {}
}
#else
diff --git a/Marlin/src/HAL/shared/HAL_SPI.h b/Marlin/src/HAL/shared/HAL_SPI.h
index 43dd210076..d805207047 100644
--- a/Marlin/src/HAL/shared/HAL_SPI.h
+++ b/Marlin/src/HAL/shared/HAL_SPI.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,10 +22,11 @@
#pragma once
/**
- * HAL/HAL_SPI.h
+ * HAL/shared/HAL_SPI.h
* Core Marlin definitions for SPI, implemented in the HALs
*/
+#include "Marduino.h"
#include
/**
@@ -53,26 +54,40 @@
#define SPI_SPEED_5 5 // Set SCK rate to 1/32 of max rate
#define SPI_SPEED_6 6 // Set SCK rate to 1/64 of max rate
-#define SPI_LSBFIRST 0
-#define SPI_MSBFIRST 1
-
-#define SPI_DATAMODE_0 0x00
-#define SPI_DATAMODE_1 0x04
-#define SPI_DATAMODE_2 0x08
-#define SPI_DATAMODE_3 0x0C
-
+//
// Standard SPI functions
-/** Initialize SPI bus */
-void spiBegin(void);
-/** Configure SPI for specified SPI speed */
+//
+
+// Initialize SPI bus
+void spiBegin();
+
+// Configure SPI for specified SPI speed
void spiInit(uint8_t spiRate);
-/** Write single byte to SPI */
+
+// Write single byte to SPI
void spiSend(uint8_t b);
-/** Read single byte from SPI */
-uint8_t spiRec(void);
-/** Read from SPI into buffer */
+
+// Read single byte from SPI
+uint8_t spiRec();
+
+// Read from SPI into buffer
void spiRead(uint8_t* buf, uint16_t nbyte);
-/** Write token and then write from 512 byte buffer to SPI (for SD card) */
+
+// Write token and then write from 512 byte buffer to SPI (for SD card)
void spiSendBlock(uint8_t token, const uint8_t* buf);
-/** Begin SPI transaction, set clock, bit order, data mode */
+
+// Begin SPI transaction, set clock, bit order, data mode
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode);
+
+//
+// Extended SPI functions taking a channel number (Hardware SPI only)
+//
+
+// Write single byte to specified SPI channel
+void spiSend(uint32_t chan, byte b);
+
+// Write buffer to specified SPI channel
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
+
+// Read single byte from specified SPI channel
+uint8_t spiRec(uint32_t chan);
diff --git a/Marlin/src/HAL/shared/HAL_ST7920.h b/Marlin/src/HAL/shared/HAL_ST7920.h
index bdc2b8cbb2..de40ade5ab 100644
--- a/Marlin/src/HAL/shared/HAL_ST7920.h
+++ b/Marlin/src/HAL/shared/HAL_ST7920.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/shared/HAL_spi_L6470.cpp b/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
index ecd808fe46..936acc7ce8 100644
--- a/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
+++ b/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
/**
* Software L6470 SPI functions originally from Arduino Sd2Card Library
- * Copyright (C) 2009 by William Greiman
+ * Copyright (c) 2009 by William Greiman
*/
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/shared/Marduino.h b/Marlin/src/HAL/shared/Marduino.h
index 78bddecd40..a2de03a2b6 100644
--- a/Marlin/src/HAL/shared/Marduino.h
+++ b/Marlin/src/HAL/shared/Marduino.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,6 +29,9 @@
#undef M_PI // Redefined by all
#undef _BV // Redefined by some
#undef sq // Redefined by teensy3/wiring.h
+#undef SBI // Redefined by arduino/const_functions.h
+#undef CBI // Redefined by arduino/const_functions.h
+#undef UNUSED // Redefined by stm32f4xx_hal_def.h
#include // NOTE: If included earlier then this line is a NOOP
@@ -54,6 +57,13 @@
inline const char* strchr_P(const char *s, int c) { return strchr(s,c); }
//#define strchr_P(s,c) strchr(s,c)
#endif
+
+ #ifndef snprintf_P
+ #define snprintf_P snprintf
+ #endif
+ #ifndef vsnprintf_P
+ #define vsnprintf_P vsnprintf
+ #endif
#endif
// Restart causes
@@ -64,3 +74,12 @@
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
+
+#ifndef M_PI
+ #define M_PI 3.14159265358979323846f
+#endif
+
+// Remove compiler warning on an unused variable
+#ifndef UNUSED
+ #define UNUSED(x) ((void)(x))
+#endif
diff --git a/Marlin/src/HAL/shared/MarlinSerial.h b/Marlin/src/HAL/shared/MarlinSerial.h
index 89c501af47..afbd7d3443 100644
--- a/Marlin/src/HAL/shared/MarlinSerial.h
+++ b/Marlin/src/HAL/shared/MarlinSerial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.cpp b/Marlin/src/HAL/shared/backtrace/backtrace.cpp
index ba1b2326e9..fc265615d0 100644
--- a/Marlin/src/HAL/shared/backtrace/backtrace.cpp
+++ b/Marlin/src/HAL/shared/backtrace/backtrace.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -65,7 +65,7 @@ static const UnwindCallbacks UnwCallbacks = {
#endif
};
-void backtrace(void) {
+void backtrace() {
UnwindFrame btf;
uint32_t sp = 0, lr = 0, pc = 0;
@@ -95,6 +95,6 @@ void backtrace(void) {
#else // !__arm__ && !__thumb__
-void backtrace(void) {}
+void backtrace() {}
#endif
diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.h b/Marlin/src/HAL/shared/backtrace/backtrace.h
index 5e00bec94f..a2b8eae594 100644
--- a/Marlin/src/HAL/shared/backtrace/backtrace.h
+++ b/Marlin/src/HAL/shared/backtrace/backtrace.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,4 +22,4 @@
#pragma once
// Perform a backtrace to the serial port
-void backtrace(void);
+void backtrace();
diff --git a/Marlin/src/HAL/shared/backtrace/unwarm.cpp b/Marlin/src/HAL/shared/backtrace/unwarm.cpp
index fb4263a272..cdc9c06c61 100644
--- a/Marlin/src/HAL/shared/backtrace/unwarm.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwarm.cpp
@@ -78,7 +78,7 @@ void UnwInitState(UnwState * const state, /**< Pointer to structure to fill.
}
// Detect if function names are available
-static int __attribute__ ((noinline)) has_function_names(void) {
+static int __attribute__ ((noinline)) has_function_names() {
uint32_t flag_word = ((uint32_t*)(((uint32_t)(&has_function_names)) & (-4))) [-1];
return ((flag_word & 0xFF000000) == 0xFF000000) ? 1 : 0;
}
diff --git a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
index ebd53cc1d9..207cd56aa8 100644
--- a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
@@ -23,9 +23,9 @@ extern "C" const UnwTabEntry __exidx_start[];
extern "C" const UnwTabEntry __exidx_end[];
/* This prevents the linking of libgcc unwinder code */
-void __aeabi_unwind_cpp_pr0(void) {};
-void __aeabi_unwind_cpp_pr1(void) {};
-void __aeabi_unwind_cpp_pr2(void) {};
+void __aeabi_unwind_cpp_pr0() {};
+void __aeabi_unwind_cpp_pr1() {};
+void __aeabi_unwind_cpp_pr2() {};
static inline __attribute__((always_inline)) uint32_t prel31_to_addr(const uint32_t *prel31) {
uint32_t offset = (((uint32_t)(*prel31)) << 1) >> 1;
@@ -285,7 +285,7 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
return UNWIND_SUCCESS;
}
-static inline __attribute__((always_inline)) uint32_t read_psp(void) {
+static inline __attribute__((always_inline)) uint32_t read_psp() {
/* Read the current PSP and return its value as a pointer */
uint32_t psp;
diff --git a/Marlin/src/HAL/shared/backtrace/unwinder.cpp b/Marlin/src/HAL/shared/backtrace/unwinder.cpp
index bde5899435..e63af1ed25 100644
--- a/Marlin/src/HAL/shared/backtrace/unwinder.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwinder.cpp
@@ -27,7 +27,7 @@ extern "C" const UnwTabEntry __exidx_start[];
extern "C" const UnwTabEntry __exidx_end[];
// Detect if unwind information is present or not
-static int HasUnwindTableInfo(void) {
+static int HasUnwindTableInfo() {
// > 16 because there are default entries we can't supress
return ((char*)(&__exidx_end) - (char*)(&__exidx_start)) > 16 ? 1 : 0;
}
diff --git a/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp b/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
index 20f1a7bc0f..8cf31cadf5 100644
--- a/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
@@ -129,6 +129,17 @@
#define END_FLASH_ADDR 0x00140000
#endif
+#ifdef __SAMD51P20A__
+// For SAMD51x20, valid address ranges are
+// SRAM (0x20000000 - 0x20040000) (256kb)
+// FLASH (0x00000000 - 0x00100000) (1024kb)
+//
+#define START_SRAM_ADDR 0x20000000
+#define END_SRAM_ADDR 0x20040000
+#define START_FLASH_ADDR 0x00000000
+#define END_FLASH_ADDR 0x00100000
+#endif
+
static bool validate_addr(uint32_t addr) {
// Address must be in SRAM range
diff --git a/Marlin/src/HAL/shared/I2cEeprom.cpp b/Marlin/src/HAL/shared/eeprom_i2c.cpp
similarity index 62%
rename from Marlin/src/HAL/shared/I2cEeprom.cpp
rename to Marlin/src/HAL/shared/eeprom_i2c.cpp
index ef2ff8222f..2752b7d4cc 100644
--- a/Marlin/src/HAL/shared/I2cEeprom.cpp
+++ b/Marlin/src/HAL/shared/eeprom_i2c.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,57 +29,21 @@
#if ENABLED(I2C_EEPROM)
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include HAL_PATH(.., HAL.h)
+#include "../HAL.h"
#include
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
static uint8_t eeprom_device_address = 0x50;
-static void eeprom_init(void) {
- static bool eeprom_initialized = false;
- if (!eeprom_initialized) {
- Wire.begin();
- eeprom_initialized = true;
- }
+// ------------------------
+// Public functions
+// ------------------------
+
+static void eeprom_init() {
+ Wire.begin();
}
void eeprom_write_byte(uint8_t *pos, unsigned char value) {
@@ -127,7 +91,6 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
}
}
-
uint8_t eeprom_read_byte(uint8_t *pos) {
unsigned eeprom_address = (unsigned)pos;
@@ -141,7 +104,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
return Wire.available() ? Wire.read() : 0xFF;
}
-// maybe let's not read more than 30 or 32 bytes at a time!
+// Don't read more than 30..32 bytes at a time!
void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
eeprom_init();
diff --git a/Marlin/src/HAL/shared/SpiEeprom.cpp b/Marlin/src/HAL/shared/eeprom_spi.cpp
similarity index 94%
rename from Marlin/src/HAL/shared/SpiEeprom.cpp
rename to Marlin/src/HAL/shared/eeprom_spi.cpp
index 525c8c0a7d..35e7d9b0a9 100644
--- a/Marlin/src/HAL/shared/SpiEeprom.cpp
+++ b/Marlin/src/HAL/shared/eeprom_spi.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#if ENABLED(SPI_EEPROM)
-#include HAL_PATH(.., HAL.h)
+#include "../HAL.h"
#define CMD_WREN 6 // WREN
#define CMD_READ 2 // WRITE
@@ -115,5 +115,4 @@ void eeprom_update_block(const void* src, void* eeprom_address, size_t n) {
delay(7); // wait for page write to complete
}
-
-#endif // ENABLED(SPI_EEPROM)
+#endif // SPI_EEPROM
diff --git a/Marlin/src/HAL/shared/math_32bit.h b/Marlin/src/HAL/shared/math_32bit.h
index 34642b2999..a69992a655 100644
--- a/Marlin/src/HAL/shared/math_32bit.h
+++ b/Marlin/src/HAL/shared/math_32bit.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/HAL/shared/persistent_store_api.cpp b/Marlin/src/HAL/shared/persistent_store_api.cpp
index e7bd107cbe..9aed03a0c8 100644
--- a/Marlin/src/HAL/shared/persistent_store_api.cpp
+++ b/Marlin/src/HAL/shared/persistent_store_api.cpp
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
diff --git a/Marlin/src/HAL/shared/persistent_store_api.h b/Marlin/src/HAL/shared/persistent_store_api.h
index de9f1c1090..02013120a7 100644
--- a/Marlin/src/HAL/shared/persistent_store_api.h
+++ b/Marlin/src/HAL/shared/persistent_store_api.h
@@ -1,7 +1,7 @@
/**
* Marlin 3D Printer Firmware
*
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
@@ -25,6 +25,8 @@
#include
#include
+#include "../../libs/crc16.h"
+
class PersistentStore {
public:
static bool access_start();
diff --git a/Marlin/src/HAL/shared/servo.cpp b/Marlin/src/HAL/shared/servo.cpp
index 684fc320a8..b5975e58e7 100644
--- a/Marlin/src/HAL/shared/servo.cpp
+++ b/Marlin/src/HAL/shared/servo.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -53,16 +53,16 @@
#include "../../inc/MarlinConfig.h"
-#if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768) || defined(STM32F1) || defined(STM32F1xx) || defined(STM32F4) || defined(STM32F4xx) || defined(STM32F7xx) || defined(ARDUINO_ARCH_ESP32))
+#if SHARED_SERVOS
#include "servo.h"
#include "servo_private.h"
-ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures
-uint8_t ServoCount = 0; // the total number of attached servos
+ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures
+uint8_t ServoCount = 0; // the total number of attached servos
-#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo
-#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo
+#define SERVO_MIN(v) (MIN_PULSE_WIDTH - (v) * 4) // minimum value in uS for this servo
+#define SERVO_MAX(v) (MAX_PULSE_WIDTH - (v) * 4) // maximum value in uS for this servo
/************ static functions common to all instances ***********************/
@@ -79,55 +79,54 @@ static boolean isTimerActive(timer16_Sequence_t timer) {
Servo::Servo() {
if (ServoCount < MAX_SERVOS) {
- this->servoIndex = ServoCount++; // assign a servo index to this instance
- servo_info[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009
+ servoIndex = ServoCount++; // assign a servo index to this instance
+ servo_info[servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009
}
else
- this->servoIndex = INVALID_SERVO; // too many servos
+ servoIndex = INVALID_SERVO; // too many servos
}
-int8_t Servo::attach(const int pin) {
- return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
+int8_t Servo::attach(const int inPin) {
+ return attach(inPin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
}
-int8_t Servo::attach(const int pin, const int min, const int max) {
+int8_t Servo::attach(const int inPin, const int inMin, const int inMax) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
+ if (servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
- pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
+ if (inPin > 0) servo_info[servoIndex].Pin.nbr = inPin;
+ pinMode(servo_info[servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
- // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128
- this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
- this->max = (MAX_PULSE_WIDTH - max) / 4;
+ // TODO: min/max check: ABS(min - MIN_PULSE_WIDTH) / 4 < 128
+ min = (MIN_PULSE_WIDTH - inMin) / 4; //resolution of min/max is 4 uS
+ max = (MAX_PULSE_WIDTH - inMax) / 4;
// initialize the timer if it has not already been initialized
timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
if (!isTimerActive(timer)) initISR(timer);
- servo_info[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive
+ servo_info[servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive
- return this->servoIndex;
+ return servoIndex;
}
void Servo::detach() {
- servo_info[this->servoIndex].Pin.isActive = false;
+ servo_info[servoIndex].Pin.isActive = false;
timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
if (!isTimerActive(timer)) finISR(timer);
}
void Servo::write(int value) {
- if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
- value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
- }
- this->writeMicroseconds(value);
+ if (value < MIN_PULSE_WIDTH) // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
+ value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(min), SERVO_MAX(max));
+ writeMicroseconds(value);
}
void Servo::writeMicroseconds(int value) {
// calculate and store the values for the given channel
- byte channel = this->servoIndex;
+ byte channel = servoIndex;
if (channel < MAX_SERVOS) { // ensure channel is valid
// ensure pulse width is valid
- value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
+ value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
CRITICAL_SECTION_START;
@@ -137,24 +136,24 @@ void Servo::writeMicroseconds(int value) {
}
// return the value as degrees
-int Servo::read() { return map(this->readMicroseconds() + 1, SERVO_MIN(), SERVO_MAX(), 0, 180); }
+int Servo::read() { return map(readMicroseconds() + 1, SERVO_MIN(min), SERVO_MAX(max), 0, 180); }
int Servo::readMicroseconds() {
- return (this->servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[this->servoIndex].ticks) + TRIM_DURATION;
+ return (servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[servoIndex].ticks) + (TRIM_DURATION);
}
-bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
+bool Servo::attached() { return servo_info[servoIndex].Pin.isActive; }
void Servo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
-#endif // HAS_SERVOS
+#endif // SHARED_SERVOS
diff --git a/Marlin/src/HAL/shared/servo.h b/Marlin/src/HAL/shared/servo.h
index dea3e20d51..e4905b7295 100644
--- a/Marlin/src/HAL/shared/servo.h
+++ b/Marlin/src/HAL/shared/servo.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
@@ -66,29 +67,27 @@
* With DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY and detach.
*/
-#pragma once
-
#if IS_TEENSY32
- #include "../HAL_TEENSY31_32/HAL_Servo_Teensy.h"
+ #include "../HAL_TEENSY31_32/Servo.h"
#elif IS_TEENSY35 || IS_TEENSY36
- #include "../HAL_TEENSY35_36/HAL_Servo_Teensy.h"
+ #include "../HAL_TEENSY35_36/Servo.h"
#elif defined(TARGET_LPC1768)
- #include "../HAL_LPC1768/HAL_Servo_LPC1768.h"
+ #include "../HAL_LPC1768/Servo.h"
#elif defined(__STM32F1__) || defined(TARGET_STM32F1)
- #include "../HAL_STM32F1/HAL_Servo_STM32F1.h"
+ #include "../HAL_STM32F1/Servo.h"
#elif defined(STM32GENERIC) && defined(STM32F4)
- #include "../HAL_STM32F4/HAL_Servo_STM32F4.h"
+ #include "../HAL_STM32_F4_F7/Servo.h"
#elif defined(ARDUINO_ARCH_STM32)
- #include "../HAL_STM32/HAL_Servo_STM32.h"
+ #include "../HAL_STM32/Servo.h"
#elif defined(ARDUINO_ARCH_ESP32)
- #include "../HAL_ESP32/HAL_Servo_ESP32.h"
+ #include "../HAL_ESP32/Servo.h"
#else
#include
- #if defined(__AVR__) || defined(ARDUINO_ARCH_SAM)
+ #if defined(__AVR__) || defined(ARDUINO_ARCH_SAM) || defined(__SAMD51__)
// we're good to go
#else
- #error "This library only supports boards with an AVR or SAM3X processor."
+ #error "This library only supports boards with an AVR, SAM3X or SAMD51 processor."
#endif
#define Servo_VERSION 2 // software version of this library
diff --git a/Marlin/src/HAL/shared/servo_private.h b/Marlin/src/HAL/shared/servo_private.h
index 158759c455..1d4cdc7e3e 100644
--- a/Marlin/src/HAL/shared/servo_private.h
+++ b/Marlin/src/HAL/shared/servo_private.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,8 +47,10 @@
#include "../HAL_AVR/ServoTimers.h"
#elif defined(ARDUINO_ARCH_SAM)
#include "../HAL_DUE/ServoTimers.h"
+#elif defined(__SAMD51__)
+ #include "../HAL_SAMD51/ServoTimers.h"
#else
- #error "This library only supports boards with an AVR or SAM3X processor."
+ #error "This library only supports boards with an AVR, SAM3X or SAMD51 processor."
#endif
// Macros
@@ -64,10 +66,8 @@
#define INVALID_SERVO 255 // flag indicating an invalid servo index
// Convert microseconds to ticks and back (PRESCALER depends on architecture)
-#define usToTicks(_us) (clockCyclesPerMicrosecond() * (_us) / (PRESCALER))
-#define ticksToUs(_ticks) (unsigned(_ticks) * (PRESCALER) / clockCyclesPerMicrosecond())
-
-//#define NBR_TIMERS ((MAX_SERVOS) / (SERVOS_PER_TIMER))
+#define usToTicks(_us) (clockCyclesPerMicrosecond() * (_us) / (SERVO_TIMER_PRESCALER))
+#define ticksToUs(_ticks) (unsigned(_ticks) * (SERVO_TIMER_PRESCALER) / clockCyclesPerMicrosecond())
// convenience macros
#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo
@@ -78,7 +78,7 @@
// Types
typedef struct {
- uint8_t nbr : 6 ; // a pin number from 0 to 63
+ uint8_t nbr : 7 ; // a pin number from 0 to 127
uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false
} ServoPin_t;
diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp
index c1f87f55dc..f130221821 100644
--- a/Marlin/src/Marlin.cpp
+++ b/Marlin/src/Marlin.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -45,7 +45,7 @@
#include "HAL/shared/Delay.h"
-#include "module/stepper_indirection.h"
+#include "module/stepper/indirection.h"
#ifdef ARDUINO
#include
@@ -57,11 +57,15 @@
#include "gcode/parser.h"
#include "gcode/queue.h"
+#if ENABLED(TOUCH_BUTTONS)
+ #include "feature/touch/xpt2046.h"
+#endif
+
#if ENABLED(HOST_ACTION_COMMANDS)
#include "feature/host_actions.h"
#endif
-#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
+#if USE_BEEPER
#include "libs/buzzer.h"
#endif
@@ -73,10 +77,6 @@
#include "feature/mixing.h"
#endif
-#if ENABLED(BEZIER_CURVE_SUPPORT)
- #include "module/planner_bezier.h"
-#endif
-
#if ENABLED(MAX7219_DEBUG)
#include "feature/Max7219_Debug_LEDs.h"
#endif
@@ -89,12 +89,12 @@
#include "feature/bltouch.h"
#endif
-#if HAS_SERVOS
- #include "module/servo.h"
+#if ENABLED(POLL_JOG)
+ #include "feature/joystick.h"
#endif
-#if HAS_DIGIPOTSS
- #include
+#if HAS_SERVOS
+ #include "module/servo.h"
#endif
#if ENABLED(DAC_STEPPER_CURRENT)
@@ -110,10 +110,14 @@
#include "feature/I2CPositionEncoder.h"
#endif
-#if HAS_TRINAMIC
+#if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
#include "feature/tmc_util.h"
#endif
+#if HAS_CUTTER
+ #include "feature/spindle_laser.h"
+#endif
+
#if ENABLED(SDSUPPORT)
CardReader card;
#endif
@@ -157,7 +161,7 @@
#include "feature/fanmux.h"
#endif
-#if DO_SWITCH_EXTRUDER || ANY(SWITCHING_NOZZLE, PARKING_EXTRUDER, MAGNETIC_PARKING_EXTRUDER)
+#if DO_SWITCH_EXTRUDER || ANY(SWITCHING_NOZZLE, PARKING_EXTRUDER, MAGNETIC_PARKING_EXTRUDER, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
#include "module/tool_change.h"
#endif
@@ -169,20 +173,12 @@
#include "feature/prusa_MMU2/mmu2.h"
#endif
-#if ENABLED(EXTENSIBLE_UI)
- #include "lcd/extensible_ui/ui_api.h"
-#endif
-
#if HAS_DRIVER(L6470)
#include "libs/L6470/L6470_Marlin.h"
#endif
bool Running = true;
-#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
- TempUnit input_temp_units = TEMPUNIT_C;
-#endif
-
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
bool wait_for_heatup = true;
@@ -279,6 +275,10 @@ void quickstop_stepper() {
sync_plan_position();
}
+void enable_e_steppers() {
+ enable_E0(); enable_E1(); enable_E2(); enable_E3(); enable_E4(); enable_E5();
+}
+
void enable_all_steppers() {
#if ENABLED(AUTO_POWER_CONTROL)
powerManager.power_on();
@@ -286,21 +286,11 @@ void enable_all_steppers() {
enable_X();
enable_Y();
enable_Z();
- enable_E0();
- enable_E1();
- enable_E2();
- enable_E3();
- enable_E4();
- enable_E5();
+ enable_e_steppers();
}
void disable_e_steppers() {
- disable_E0();
- disable_E1();
- disable_E2();
- disable_E3();
- disable_E4();
- disable_E5();
+ disable_E0(); disable_E1(); disable_E2(); disable_E3(); disable_E4(); disable_E5();
}
void disable_e_stepper(const uint8_t e) {
@@ -321,71 +311,6 @@ void disable_all_steppers() {
disable_e_steppers();
}
-#if HAS_FILAMENT_SENSOR
-
- void event_filament_runout() {
-
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout.
- #endif
-
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onFilamentRunout(ExtUI::getActiveTool());
- #endif
-
- #if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS)
- const char tool = '0'
- #if NUM_RUNOUT_SENSORS > 1
- + active_extruder
- #endif
- ;
- #endif
-
- //action:out_of_filament
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
- host_action_prompt_end();
- host_action_prompt_begin(PSTR("FilamentRunout T"), false);
- SERIAL_CHAR(tool);
- SERIAL_EOL();
- host_action_prompt_show();
- #endif
-
- const bool run_runout_script = !runout.host_handling;
-
- #if ENABLED(HOST_ACTION_COMMANDS)
- if (run_runout_script
- && ( strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
- || strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- || strstr(FILAMENT_RUNOUT_SCRIPT, "M25")
- #endif
- )
- ) {
- host_action_paused(false);
- }
- else {
- // Legacy Repetier command for use until newer version supports standard dialog
- // To be removed later when pause command also triggers dialog
- #ifdef ACTION_ON_FILAMENT_RUNOUT
- host_action(PSTR(ACTION_ON_FILAMENT_RUNOUT " T"), false);
- SERIAL_CHAR(tool);
- SERIAL_EOL();
- #endif
-
- host_action_pause(false);
- }
- SERIAL_ECHOPGM(" " ACTION_REASON_ON_FILAMENT_RUNOUT " ");
- SERIAL_CHAR(tool);
- SERIAL_EOL();
- #endif // HOST_ACTION_COMMANDS
-
- if (run_runout_script)
- enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
- }
-
-#endif // HAS_FILAMENT_SENSOR
-
#if ENABLED(G29_RETRY_AND_RECOVER)
void event_probe_failure() {
@@ -399,13 +324,13 @@ void disable_all_steppers() {
#ifdef ACTION_ON_CANCEL
host_action_cancel();
#endif
- kill(PSTR(MSG_ERR_PROBING_FAILED));
+ kill(GET_TEXT(MSG_LCD_PROBING_FAILED));
#endif
}
void event_probe_recover() {
#if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"));
+ host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"), PSTR("Dismiss"));
#endif
#ifdef ACTION_ON_G29_RECOVER
host_action(PSTR(ACTION_ON_G29_RECOVER));
@@ -417,6 +342,20 @@ void disable_all_steppers() {
#endif
+/**
+ * Printing is active when the print job timer is running
+ */
+bool printingIsActive() {
+ return print_job_timer.isRunning() || IS_SD_PRINTING();
+}
+
+/**
+ * Printing is paused according to SD or host indicators
+ */
+bool printingIsPaused() {
+ return print_job_timer.isPaused() || IS_SD_PAUSED();
+}
+
/**
* Manage several activities:
* - Check for Filament Runout
@@ -437,7 +376,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
runout.run();
#endif
- if (commands_in_queue < BUFSIZE) get_available_commands();
+ if (queue.length < BUFSIZE) queue.get_available_commands();
const millis_t ms = millis();
@@ -514,19 +453,16 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
#endif
#if HAS_HOME
- // Check to see if we have to home, use poor man's debouncer
- // ---------------------------------------------------------
- static int homeDebounceCount = 0; // poor man's debouncing count
- const int HOME_DEBOUNCE_DELAY = 2500;
- if (!IS_SD_PRINTING() && !READ(HOME_PIN)) {
- if (!homeDebounceCount) {
- enqueue_and_echo_commands_P(PSTR("G28"));
+ // Handle a standalone HOME button
+ constexpr millis_t HOME_DEBOUNCE_DELAY = 1000UL;
+ static millis_t next_home_key_ms; // = 0
+ if (!IS_SD_PRINTING() && !READ(HOME_PIN)) { // HOME_PIN goes LOW when pressed
+ const millis_t ms = millis();
+ if (ELAPSED(ms, next_home_key_ms)) {
+ next_home_key_ms = ms + HOME_DEBOUNCE_DELAY;
LCD_MESSAGEPGM(MSG_AUTO_HOME);
+ queue.enqueue_now_P(PSTR("G28"));
}
- if (homeDebounceCount < HOME_DEBOUNCE_DELAY)
- homeDebounceCount++;
- else
- homeDebounceCount = 0;
}
#endif
@@ -546,28 +482,28 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
#if ENABLED(SWITCHING_EXTRUDER)
bool oldstatus;
switch (active_extruder) {
- default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
+ default: oldstatus = E0_ENABLE_READ(); enable_E0(); break;
#if E_STEPPERS > 1
- case 2: case 3: oldstatus = E1_ENABLE_READ; enable_E1(); break;
+ case 2: case 3: oldstatus = E1_ENABLE_READ(); enable_E1(); break;
#if E_STEPPERS > 2
- case 4: case 5: oldstatus = E2_ENABLE_READ; enable_E2(); break;
+ case 4: case 5: oldstatus = E2_ENABLE_READ(); enable_E2(); break;
#endif // E_STEPPERS > 2
#endif // E_STEPPERS > 1
}
#else // !SWITCHING_EXTRUDER
bool oldstatus;
switch (active_extruder) {
- default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
+ default: oldstatus = E0_ENABLE_READ(); enable_E0(); break;
#if E_STEPPERS > 1
- case 1: oldstatus = E1_ENABLE_READ; enable_E1(); break;
+ case 1: oldstatus = E1_ENABLE_READ(); enable_E1(); break;
#if E_STEPPERS > 2
- case 2: oldstatus = E2_ENABLE_READ; enable_E2(); break;
+ case 2: oldstatus = E2_ENABLE_READ(); enable_E2(); break;
#if E_STEPPERS > 3
- case 3: oldstatus = E3_ENABLE_READ; enable_E3(); break;
+ case 3: oldstatus = E3_ENABLE_READ(); enable_E3(); break;
#if E_STEPPERS > 4
- case 4: oldstatus = E4_ENABLE_READ; enable_E4(); break;
+ case 4: oldstatus = E4_ENABLE_READ(); enable_E4(); break;
#if E_STEPPERS > 5
- case 5: oldstatus = E5_ENABLE_READ; enable_E5(); break;
+ case 5: oldstatus = E5_ENABLE_READ(); enable_E5(); break;
#endif // E_STEPPERS > 5
#endif // E_STEPPERS > 4
#endif // E_STEPPERS > 3
@@ -576,10 +512,10 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
}
#endif // !SWITCHING_EXTRUDER
- const float olde = current_position[E_AXIS];
- current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
- planner.buffer_line(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
- current_position[E_AXIS] = olde;
+ const float olde = current_position.e;
+ current_position.e += EXTRUDER_RUNOUT_EXTRUDE;
+ line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED));
+ current_position.e = olde;
planner.set_e_position_mm(olde);
planner.synchronize();
@@ -623,7 +559,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
// travel moves have been received so enact them
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
- set_destination_from_current();
+ destination = current_position;
prepare_move_to_destination();
}
#endif
@@ -666,6 +602,21 @@ void idle(
bool no_stepper_sleep/*=false*/
#endif
) {
+ #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
+ recovery.outage();
+ #endif
+
+ #if ENABLED(SPI_ENDSTOPS)
+ if (endstops.tmc_spi_homing.any
+ #if ENABLED(IMPROVE_HOMING_RELIABILITY)
+ && ELAPSED(millis(), sg_guard_period)
+ #endif
+ ) {
+ for (uint8_t i = 4; i--;) // Read SGT 4 times per idle loop
+ if (endstops.tmc_spi_homing_check()) break;
+ }
+ #endif
+
#if ENABLED(MAX7219_DEBUG)
max7219.idle_tasks();
#endif
@@ -688,15 +639,18 @@ void idle(
print_job_timer.tick();
#endif
- #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
+ #if USE_BEEPER
buzzer.tick();
#endif
#if ENABLED(I2C_POSITION_ENCODERS)
static millis_t i2cpem_next_update_ms;
- if (planner.has_blocks_queued() && ELAPSED(millis(), i2cpem_next_update_ms)) {
- I2CPEM.update();
- i2cpem_next_update_ms = millis() + I2CPE_MIN_UPD_TIME_MS;
+ if (planner.has_blocks_queued()) {
+ const millis_t ms = millis();
+ if (ELAPSED(ms, i2cpem_next_update_ms)) {
+ I2CPEM.update();
+ i2cpem_next_update_ms = ms + I2CPE_MIN_UPD_TIME_MS;
+ }
}
#endif
@@ -722,31 +676,36 @@ void idle(
#if ENABLED(PRUSA_MMU2)
mmu2.mmu_loop();
#endif
+
+ #if ENABLED(POLL_JOG)
+ joystick.inject_jog_moves();
+ #endif
}
/**
* Kill all activity and lock the machine.
* After this the machine will need to be reset.
*/
-void kill(PGM_P const lcd_msg/*=nullptr*/) {
+void kill(PGM_P const lcd_error/*=nullptr*/, PGM_P const lcd_component/*=nullptr*/, const bool steppers_off/*=false*/) {
thermalManager.disable_all_heaters();
SERIAL_ERROR_MSG(MSG_ERR_KILLED);
#if HAS_DISPLAY
- ui.kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
+ ui.kill_screen(lcd_error ?: GET_TEXT(MSG_KILLED), lcd_component);
#else
- UNUSED(lcd_msg);
+ UNUSED(lcd_error);
+ UNUSED(lcd_component);
#endif
#ifdef ACTION_ON_KILL
host_action_kill();
#endif
- minkill();
+ minkill(steppers_off);
}
-void minkill() {
+void minkill(const bool steppers_off/*=false*/) {
// Wait a short time (allows messages to get out before shutting down.
for (int i = 1000; i--;) DELAY_US(600);
@@ -756,7 +715,11 @@ void minkill() {
// Wait to ensure all interrupts stopped
for (int i = 1000; i--;) DELAY_US(250);
- thermalManager.disable_all_heaters(); // turn off heaters again
+ // Reiterate heaters off
+ thermalManager.disable_all_heaters();
+
+ // Power off all steppers (for M112) or just the E steppers
+ steppers_off ? disable_all_steppers() : disable_e_steppers();
#if HAS_POWER_SWITCH
PSU_OFF();
@@ -769,29 +732,17 @@ void minkill() {
#if HAS_KILL
// Wait for kill to be released
- while (!READ(KILL_PIN)) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_reset();
- #endif
- }
+ while (!READ(KILL_PIN)) watchdog_refresh();
// Wait for kill to be pressed
- while (READ(KILL_PIN)) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_reset();
- #endif
- }
+ while (READ(KILL_PIN)) watchdog_refresh();
- void(*resetFunc)(void) = 0; // Declare resetFunc() at address 0
- resetFunc(); // Jump to address 0
+ void (*resetFunc)() = 0; // Declare resetFunc() at address 0
+ resetFunc(); // Jump to address 0
#else // !HAS_KILL
- for (;;) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_reset();
- #endif
- } // Wait for reset
+ for (;;) watchdog_refresh(); // Wait for reset
#endif // !HAS_KILL
}
@@ -809,7 +760,7 @@ void stop() {
#endif
if (IsRunning()) {
- Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart
+ queue.stop();
SERIAL_ERROR_MSG(MSG_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
safe_delay(350); // allow enough time for messages to get out before stopping
@@ -837,9 +788,7 @@ void stop() {
*/
void setup() {
- #ifdef HAL_INIT
- HAL_init();
- #endif
+ HAL_init();
#if HAS_DRIVER(L6470)
L6470.init(); // setup SPI and then init chips
@@ -871,8 +820,16 @@ void setup() {
runout.setup();
#endif
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ recovery.setup();
+ #endif
+
setup_killpin();
+ #if HAS_TMC220x
+ tmc_serial_begin();
+ #endif
+
setup_powerhold();
#if HAS_STEPPER_RESET
@@ -904,9 +861,6 @@ void setup() {
#endif
tmc_init_cs_pins();
#endif
- #if HAS_DRIVER(TMC2208)
- tmc2208_serial_begin();
- #endif
#ifdef BOARD_INIT
BOARD_INIT();
@@ -927,20 +881,25 @@ void setup() {
SERIAL_EOL();
#if defined(STRING_DISTRIBUTION_DATE) && defined(STRING_CONFIG_H_AUTHOR)
- SERIAL_ECHO_START();
- SERIAL_ECHOPGM(MSG_CONFIGURATION_VER);
- SERIAL_ECHOPGM(STRING_DISTRIBUTION_DATE);
- SERIAL_ECHOLNPGM(MSG_AUTHOR STRING_CONFIG_H_AUTHOR);
+ SERIAL_ECHO_MSG(
+ MSG_CONFIGURATION_VER
+ STRING_DISTRIBUTION_DATE
+ MSG_AUTHOR STRING_CONFIG_H_AUTHOR
+ );
SERIAL_ECHO_MSG("Compiled: " __DATE__);
#endif
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_FREE_MEMORY, freeMemory(), MSG_PLANNER_BUFFER_BYTES, (int)sizeof(block_t) * (BLOCK_BUFFER_SIZE));
- queue_setup();
-
// UI must be initialized before EEPROM
// (because EEPROM code calls the UI).
+
+ // Set up LEDs early
+ #if HAS_COLOR_LEDS
+ leds.setup();
+ #endif
+
ui.init();
ui.reset_status();
@@ -948,18 +907,21 @@ void setup() {
ui.show_bootscreen();
#endif
- #if ENABLED(SDIO_SUPPORT) && SD_DETECT_PIN == -1
- // Auto-mount the SD for EEPROM.dat emulation
- if (!card.isDetected()) card.initsd();
+ #if ENABLED(SDSUPPORT)
+ card.mount(); // Mount the SD card before settings.first_load
#endif
// Load data from EEPROM if available (or use defaults)
// This also updates variables in the planner, elsewhere
- (void)settings.load();
+ settings.first_load();
+
+ #if ENABLED(TOUCH_BUTTONS)
+ touch.init();
+ #endif
#if HAS_M206_COMMAND
// Initialize current position based on home_offset
- LOOP_XYZ(a) current_position[a] += home_offset[a];
+ current_position += home_offset;
#endif
// Vital to init stepper/planner equivalent for current_position
@@ -985,15 +947,15 @@ void setup() {
OUT_WRITE(PHOTOGRAPH_PIN, LOW);
#endif
- #if ENABLED(SPINDLE_LASER_ENABLE)
- OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ENABLE_INVERT); // init spindle to off
- #if SPINDLE_DIR_CHANGE
- OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // init rotation to clockwise (M3)
- #endif
- #if ENABLED(SPINDLE_LASER_PWM) && defined(SPINDLE_LASER_PWM_PIN) && SPINDLE_LASER_PWM_PIN >= 0
- SET_PWM(SPINDLE_LASER_PWM_PIN);
- analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // set to lowest speed
- #endif
+ #if HAS_CUTTER
+ cutter.init();
+ #endif
+
+ #if ENABLED(COOLANT_MIST)
+ OUT_WRITE(COOLANT_MIST_PIN, COOLANT_MIST_INVERT); // Init Mist Coolant OFF
+ #endif
+ #if ENABLED(COOLANT_FLOOD)
+ OUT_WRITE(COOLANT_FLOOD_PIN, COOLANT_FLOOD_INVERT); // Init Flood Coolant OFF
#endif
#if HAS_BED_PROBE
@@ -1032,10 +994,6 @@ void setup() {
OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // OFF
#endif
- #if HAS_COLOR_LEDS
- leds.setup();
- #endif
-
#if HAS_CASE_LIGHT
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
@@ -1092,6 +1050,10 @@ void setup() {
pe_solenoid_init();
#endif
+ #if ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
+ est_init();
+ #endif
+
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.check();
#endif
@@ -1104,10 +1066,18 @@ void setup() {
init_closedloop();
#endif
- #if ENABLED(SDSUPPORT) && DISABLED(ULTRA_LCD)
+ #ifdef STARTUP_COMMANDS
+ queue.inject_P(PSTR(STARTUP_COMMANDS));
+ #endif
+
+ #if ENABLED(INIT_SDCARD_ON_BOOT) && !HAS_SPI_LCD
card.beginautostart();
#endif
+ #if ENABLED(HOST_PROMPT_SUPPORT)
+ host_action_prompt_end();
+ #endif
+
#if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
test_tmc_connection(true, true, true, true);
#endif
@@ -1129,7 +1099,10 @@ void loop() {
for (;;) {
+ idle(); // Do an idle first so boot is slightly faster
+
#if ENABLED(SDSUPPORT)
+
card.checkautostart();
if (card.flag.abort_sd_printing) {
@@ -1138,24 +1111,25 @@ void loop() {
true
#endif
);
- clear_command_queue();
+ queue.clear();
quickstop_stepper();
print_job_timer.stop();
- thermalManager.disable_all_heaters();
+ #if DISABLED(SD_ABORT_NO_COOLDOWN)
+ thermalManager.disable_all_heaters();
+ #endif
thermalManager.zero_fan_speeds();
wait_for_heatup = false;
#if ENABLED(POWER_LOSS_RECOVERY)
card.removeJobRecoveryFile();
#endif
#ifdef EVENT_GCODE_SD_STOP
- enqueue_and_echo_commands_P(PSTR(EVENT_GCODE_SD_STOP));
+ queue.inject_P(PSTR(EVENT_GCODE_SD_STOP));
#endif
}
+
#endif // SDSUPPORT
- if (commands_in_queue < BUFSIZE) get_available_commands();
- advance_command_queue();
+ queue.advance();
endstops.event_handler();
- idle();
}
}
diff --git a/Marlin/src/Marlin.h b/Marlin/src/Marlin.h
index 0433a50c3c..391c453e01 100644
--- a/Marlin/src/Marlin.h
+++ b/Marlin/src/Marlin.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -316,13 +316,14 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
/**
* The axis order in all axis related arrays is X, Y, Z, E
*/
+void enable_e_steppers();
void enable_all_steppers();
void disable_e_stepper(const uint8_t e);
void disable_e_steppers();
void disable_all_steppers();
-void kill(PGM_P const lcd_msg=nullptr);
-void minkill();
+void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
+void minkill(const bool steppers_off=false);
void quickstop_stepper();
@@ -330,6 +331,9 @@ extern bool Running;
inline bool IsRunning() { return Running; }
inline bool IsStopped() { return !Running; }
+bool printingIsActive();
+bool printingIsPaused();
+
extern bool wait_for_heatup;
#if HAS_RESUME_CONTINUE
@@ -349,8 +353,8 @@ extern millis_t max_inactive_time, stepper_inactive_time;
#if HAS_POWER_SWITCH
extern bool powersupply_on;
- #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); powersupply_on = true; }while(0)
- #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); powersupply_on = false; }while(0)
+ #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_HIGH); powersupply_on = true; }while(0)
+ #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_HIGH); powersupply_on = false; }while(0)
#if ENABLED(AUTO_POWER_CONTROL)
#define PSU_ON() powerManager.power_on()
#define PSU_OFF() powerManager.power_off()
@@ -367,10 +371,6 @@ void protected_pin_err();
inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }
#endif
-#if HAS_FILAMENT_SENSOR
- void event_filament_runout();
-#endif
-
#if ENABLED(G29_RETRY_AND_RECOVER)
void event_probe_recover();
void event_probe_failure();
diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h
index 4a7fb642b9..939cf5f756 100644
--- a/Marlin/src/core/boards.h
+++ b/Marlin/src/core/boards.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,260 +21,304 @@
*/
#pragma once
+#include "macros.h"
+
#define BOARD_UNKNOWN -1
//
// RAMPS 1.3 / 1.4 - ATmega1280, ATmega2560
//
-#define BOARD_RAMPS_OLD 3 // MEGA/RAMPS up to 1.2
+#define BOARD_RAMPS_OLD 1000 // MEGA/RAMPS up to 1.2
-#define BOARD_RAMPS_13_EFB 33 // RAMPS 1.3 (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS_13_EEB 34 // RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS_13_EFF 35 // RAMPS 1.3 (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS_13_EEF 36 // RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS_13_SF 38 // RAMPS 1.3 (Power outputs: Spindle, Controller Fan)
+#define BOARD_RAMPS_13_EFB 1010 // RAMPS 1.3 (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS_13_EEB 1011 // RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS_13_EFF 1012 // RAMPS 1.3 (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS_13_EEF 1013 // RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS_13_SF 1014 // RAMPS 1.3 (Power outputs: Spindle, Controller Fan)
-#define BOARD_RAMPS_14_EFB 43 // RAMPS 1.4 (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS_14_EEB 44 // RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS_14_EFF 45 // RAMPS 1.4 (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS_14_EEF 46 // RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS_14_SF 48 // RAMPS 1.4 (Power outputs: Spindle, Controller Fan)
+#define BOARD_RAMPS_14_EFB 1020 // RAMPS 1.4 (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS_14_EEB 1021 // RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS_14_EFF 1022 // RAMPS 1.4 (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS_14_EEF 1023 // RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS_14_SF 1024 // RAMPS 1.4 (Power outputs: Spindle, Controller Fan)
-#define BOARD_RAMPS_PLUS_EFB 143 // RAMPS Plus 3DYMY (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS_PLUS_EEB 144 // RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS_PLUS_EFF 145 // RAMPS Plus 3DYMY (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS_PLUS_EEF 146 // RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS_PLUS_SF 148 // RAMPS Plus 3DYMY (Power outputs: Spindle, Controller Fan)
+#define BOARD_RAMPS_PLUS_EFB 1030 // RAMPS Plus 3DYMY (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS_PLUS_EEB 1031 // RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS_PLUS_EFF 1032 // RAMPS Plus 3DYMY (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS_PLUS_EEF 1033 // RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS_PLUS_SF 1034 // RAMPS Plus 3DYMY (Power outputs: Spindle, Controller Fan)
//
// RAMPS Derivatives - ATmega1280, ATmega2560
//
-#define BOARD_3DRAG 77 // 3Drag Controller
-#define BOARD_K8200 78 // Velleman K8200 Controller (derived from 3Drag Controller)
-#define BOARD_K8400 79 // Velleman K8400 Controller (derived from 3Drag Controller)
-#define BOARD_BAM_DICE 401 // 2PrintBeta BAM&DICE with STK drivers
-#define BOARD_BAM_DICE_DUE 402 // 2PrintBeta BAM&DICE Due with STK drivers
-#define BOARD_MKS_BASE 40 // MKS BASE v1.0
-#define BOARD_MKS_BASE_14 404 // MKS v1.4 A4982 stepper drivers
-#define BOARD_MKS_BASE_15 405 // MKS v1.5 with Allegro A4982 stepper drivers
-#define BOARD_MKS_BASE_HEROIC 41 // MKS BASE 1.0 with Heroic HR4982 stepper drivers
-#define BOARD_MKS_GEN_13 47 // MKS GEN v1.3 or 1.4
-#define BOARD_MKS_GEN_L 53 // MKS GEN L
-#define BOARD_KFB_2 136 // Bigtreetech or BIQU KFB2.0
-#define BOARD_ZRIB_V20 504 // zrib V2.0 control board (Chinese knock off RAMPS replica)
-#define BOARD_FELIX2 37 // Felix 2.0+ Electronics Board (RAMPS like)
-#define BOARD_RIGIDBOARD 42 // Invent-A-Part RigidBoard
-#define BOARD_RIGIDBOARD_V2 52 // Invent-A-Part RigidBoard V2
-#define BOARD_SAINSMART_2IN1 49 // Sainsmart 2-in-1 board
-#define BOARD_ULTIMAKER 7 // Ultimaker
-#define BOARD_ULTIMAKER_OLD 71 // Ultimaker (Older electronics. Pre 1.5.4. This is rare)
-#define BOARD_AZTEEG_X3 67 // Azteeg X3
-#define BOARD_AZTEEG_X3_PRO 68 // Azteeg X3 Pro
-#define BOARD_ULTIMAIN_2 72 // Ultimainboard 2.x (Uses TEMP_SENSOR 20)
-#define BOARD_RUMBA 80 // Rumba
-#define BOARD_RUMBA_RAISE3D 333 // Raise3D N series Rumba derivative
-#define BOARD_RL200 801 // Rapide Lite 200 (v1, low-cost RUMBA clone with drv)
-#define BOARD_FORMBOT_TREX2PLUS 95 // Formbot T-Rex 2 Plus
-#define BOARD_FORMBOT_TREX3 96 // Formbot T-Rex 3
-#define BOARD_FORMBOT_RAPTOR 97 // Formbot Raptor
-#define BOARD_FORMBOT_RAPTOR2 98 // Formbot Raptor 2
-#define BOARD_BQ_ZUM_MEGA_3D 503 // bq ZUM Mega 3D
-#define BOARD_MAKEBOARD_MINI 431 // MakeBoard Mini v2.1.2 is a control board sold by MicroMake
-#define BOARD_TRIGORILLA_13 343 // TriGorilla Anycubic version 1.3 based on RAMPS EFB
-#define BOARD_TRIGORILLA_14 443 // TriGorilla Anycubic version 1.4 based on RAMPS EFB
-#define BOARD_RAMPS_ENDER_4 243 // Creality: Ender-4, CR-8
-#define BOARD_RAMPS_CREALITY 244 // Creality: CR10S, CR20, CR-X
-#define BOARD_FYSETC_F6_13 541 // Fysetc F6
-#define BOARD_DUPLICATOR_I3_PLUS 31 // Wanhao Duplicator i3 Plus
-#define BOARD_VORON 441 // VORON Design
-#define BOARD_TRONXY_V3_1_0 442 // Tronxy TRONXY-V3-1.0
+#define BOARD_3DRAG 1100 // 3Drag Controller
+#define BOARD_K8200 1101 // Velleman K8200 Controller (derived from 3Drag Controller)
+#define BOARD_K8400 1102 // Velleman K8400 Controller (derived from 3Drag Controller)
+#define BOARD_BAM_DICE 1103 // 2PrintBeta BAM&DICE with STK drivers
+#define BOARD_BAM_DICE_DUE 1104 // 2PrintBeta BAM&DICE Due with STK drivers
+#define BOARD_MKS_BASE 1105 // MKS BASE v1.0
+#define BOARD_MKS_BASE_14 1106 // MKS v1.4 with A4982 stepper drivers
+#define BOARD_MKS_BASE_15 1107 // MKS v1.5 with Allegro A4982 stepper drivers
+#define BOARD_MKS_BASE_HEROIC 1108 // MKS BASE 1.0 with Heroic HR4982 stepper drivers
+#define BOARD_MKS_GEN_13 1109 // MKS GEN v1.3 or 1.4
+#define BOARD_MKS_GEN_L 1110 // MKS GEN L
+#define BOARD_KFB_2 1111 // Bigtreetech or BIQU KFB2.0
+#define BOARD_ZRIB_V20 1112 // zrib V2.0 control board (Chinese knock off RAMPS replica)
+#define BOARD_FELIX2 1113 // Felix 2.0+ Electronics Board (RAMPS like)
+#define BOARD_RIGIDBOARD 1114 // Invent-A-Part RigidBoard
+#define BOARD_RIGIDBOARD_V2 1115 // Invent-A-Part RigidBoard V2
+#define BOARD_SAINSMART_2IN1 1116 // Sainsmart 2-in-1 board
+#define BOARD_ULTIMAKER 1117 // Ultimaker
+#define BOARD_ULTIMAKER_OLD 1118 // Ultimaker (Older electronics. Pre 1.5.4. This is rare)
+#define BOARD_AZTEEG_X3 1119 // Azteeg X3
+#define BOARD_AZTEEG_X3_PRO 1120 // Azteeg X3 Pro
+#define BOARD_ULTIMAIN_2 1121 // Ultimainboard 2.x (Uses TEMP_SENSOR 20)
+#define BOARD_RUMBA 1122 // Rumba
+#define BOARD_RUMBA_RAISE3D 1123 // Raise3D N series Rumba derivative
+#define BOARD_RL200 1124 // Rapide Lite 200 (v1, low-cost RUMBA clone with drv)
+#define BOARD_FORMBOT_TREX2PLUS 1125 // Formbot T-Rex 2 Plus
+#define BOARD_FORMBOT_TREX3 1126 // Formbot T-Rex 3
+#define BOARD_FORMBOT_RAPTOR 1127 // Formbot Raptor
+#define BOARD_FORMBOT_RAPTOR2 1128 // Formbot Raptor 2
+#define BOARD_BQ_ZUM_MEGA_3D 1129 // bq ZUM Mega 3D
+#define BOARD_MAKEBOARD_MINI 1130 // MakeBoard Mini v2.1.2 is a control board sold by MicroMake
+#define BOARD_TRIGORILLA_13 1131 // TriGorilla Anycubic version 1.3-based on RAMPS EFB
+#define BOARD_TRIGORILLA_14 1132 // ... Ver 1.4
+#define BOARD_TRIGORILLA_14_11 1133 // ... Rev 1.1 (new servo pin order)
+#define BOARD_RAMPS_ENDER_4 1134 // Creality: Ender-4, CR-8
+#define BOARD_RAMPS_CREALITY 1135 // Creality: CR10S, CR20, CR-X
+#define BOARD_RAMPS_DAGOMA 1136 // Dagoma F5
+#define BOARD_FYSETC_F6_13 1137 // FYSETC F6
+#define BOARD_DUPLICATOR_I3_PLUS 1138 // Wanhao Duplicator i3 Plus
+#define BOARD_VORON 1139 // VORON Design
+#define BOARD_TRONXY_V3_1_0 1140 // Tronxy TRONXY-V3-1.0
+#define BOARD_Z_BOLT_X_SERIES 1141 // Z-Bolt X Series
+#define BOARD_TT_OSCAR 1142 // TT OSCAR
+#define BOARD_OVERLORD 1143 // Overlord/Overlord Pro
+#define BOARD_HJC2560C_REV1 1144 // ADIMLab Gantry v1
+#define BOARD_HJC2560C_REV2 1145 // ADIMLab Gantry v2
+
+//
+// RAMBo and derivatives
+//
+
+#define BOARD_RAMBO 1200 // Rambo
+#define BOARD_MINIRAMBO 1201 // Mini-Rambo
+#define BOARD_MINIRAMBO_10A 1202 // Mini-Rambo 1.0a
+#define BOARD_EINSY_RAMBO 1203 // Einsy Rambo
+#define BOARD_EINSY_RETRO 1204 // Einsy Retro
+#define BOARD_SCOOVO_X9H 1205 // abee Scoovo X9H
//
// Other ATmega1280, ATmega2560
//
-#define BOARD_CNCONTROLS_11 111 // Cartesio CN Controls V11
-#define BOARD_CNCONTROLS_12 112 // Cartesio CN Controls V12
-#define BOARD_CHEAPTRONIC 2 // Cheaptronic v1.0
-#define BOARD_CHEAPTRONIC_V2 21 // Cheaptronic v2.0
-#define BOARD_MIGHTYBOARD_REVE 200 // Makerbot Mightyboard Revision E
-#define BOARD_MEGATRONICS 70 // Megatronics
-#define BOARD_MEGATRONICS_2 701 // Megatronics v2.0
-#define BOARD_MEGATRONICS_3 703 // Megatronics v3.0
-#define BOARD_MEGATRONICS_31 704 // Megatronics v3.1
-#define BOARD_MEGATRONICS_32 705 // Megatronics v3.2
-#define BOARD_RAMBO 301 // Rambo
-#define BOARD_MINIRAMBO 302 // Mini-Rambo
-#define BOARD_MINIRAMBO_10A 303 // Mini-Rambo 1.0a
-#define BOARD_EINSY_RAMBO 304 // Einsy Rambo
-#define BOARD_EINSY_RETRO 305 // Einsy Retro
-#define BOARD_ELEFU_3 21 // Elefu Ra Board (v3)
-#define BOARD_LEAPFROG 999 // Leapfrog
-#define BOARD_MEGACONTROLLER 310 // Mega controller
-#define BOARD_SCOOVO_X9H 321 // abee Scoovo X9H
-#define BOARD_GT2560_REV_A 74 // Geeetech GT2560 Rev. A
-#define BOARD_GT2560_REV_A_PLUS 75 // Geeetech GT2560 Rev. A+ (with auto level probe)
-#define BOARD_GT2560_V3 76 // Geeetech GT2560 Rev B for A10(M/D)
-#define BOARD_GT2560_V3_MC2 73 // Geeetech GT2560 Rev B for Mecreator2
-#define BOARD_GT2560_V3_A20 86 // Geeetech GT2560 Rev B for A20(M/D)
-#define BOARD_EINSTART_S 666 // Einstart retrofit
+#define BOARD_CNCONTROLS_11 1300 // Cartesio CN Controls V11
+#define BOARD_CNCONTROLS_12 1301 // Cartesio CN Controls V12
+#define BOARD_CNCONTROLS_15 1302 // Cartesio CN Controls V15
+#define BOARD_CHEAPTRONIC 1303 // Cheaptronic v1.0
+#define BOARD_CHEAPTRONIC_V2 1304 // Cheaptronic v2.0
+#define BOARD_MIGHTYBOARD_REVE 1305 // Makerbot Mightyboard Revision E
+#define BOARD_MEGATRONICS 1306 // Megatronics
+#define BOARD_MEGATRONICS_2 1307 // Megatronics v2.0
+#define BOARD_MEGATRONICS_3 1308 // Megatronics v3.0
+#define BOARD_MEGATRONICS_31 1309 // Megatronics v3.1
+#define BOARD_MEGATRONICS_32 1310 // Megatronics v3.2
+#define BOARD_ELEFU_3 1311 // Elefu Ra Board (v3)
+#define BOARD_LEAPFROG 1312 // Leapfrog
+#define BOARD_MEGACONTROLLER 1313 // Mega controller
+#define BOARD_GT2560_REV_A 1314 // Geeetech GT2560 Rev. A
+#define BOARD_GT2560_REV_A_PLUS 1315 // Geeetech GT2560 Rev. A+ (with auto level probe)
+#define BOARD_GT2560_V3 1316 // Geeetech GT2560 Rev B for A10(M/D)
+#define BOARD_GT2560_V3_MC2 1317 // Geeetech GT2560 Rev B for Mecreator2
+#define BOARD_GT2560_V3_A20 1318 // Geeetech GT2560 Rev B for A20(M/D)
+#define BOARD_EINSTART_S 1319 // Einstart retrofit
+#define BOARD_WANHAO_ONEPLUS 1320 // Wanhao 0ne+ i3 Mini
//
// ATmega1281, ATmega2561
//
-#define BOARD_MINITRONICS 702 // Minitronics v1.0/1.1
-#define BOARD_SILVER_GATE 25 // Silvergate v1.0
+#define BOARD_MINITRONICS 1400 // Minitronics v1.0/1.1
+#define BOARD_SILVER_GATE 1401 // Silvergate v1.0
//
// Sanguinololu and Derivatives - ATmega644P, ATmega1284P
//
-#define BOARD_SANGUINOLOLU_11 6 // Sanguinololu < 1.2
-#define BOARD_SANGUINOLOLU_12 62 // Sanguinololu 1.2 and above
-#define BOARD_MELZI 63 // Melzi
-#define BOARD_MELZI_MAKR3D 66 // Melzi with ATmega1284 (MaKr3d version)
-#define BOARD_MELZI_CREALITY 89 // Melzi Creality3D board (for CR-10 etc)
-#define BOARD_MELZI_MALYAN 92 // Melzi Malyan M150 board
-#define BOARD_MELZI_TRONXY 505 // Tronxy X5S
-#define BOARD_STB_11 64 // STB V1.1
-#define BOARD_AZTEEG_X1 65 // Azteeg X1
-#define BOARD_ANET_10 69 // Anet 1.0 (Melzi clone)
+#define BOARD_SANGUINOLOLU_11 1500 // Sanguinololu < 1.2
+#define BOARD_SANGUINOLOLU_12 1501 // Sanguinololu 1.2 and above
+#define BOARD_MELZI 1502 // Melzi
+#define BOARD_MELZI_MAKR3D 1503 // Melzi with ATmega1284 (MaKr3d version)
+#define BOARD_MELZI_CREALITY 1504 // Melzi Creality3D board (for CR-10 etc)
+#define BOARD_MELZI_MALYAN 1505 // Melzi Malyan M150 board
+#define BOARD_MELZI_TRONXY 1506 // Tronxy X5S
+#define BOARD_STB_11 1507 // STB V1.1
+#define BOARD_AZTEEG_X1 1508 // Azteeg X1
+#define BOARD_ANET_10 1509 // Anet 1.0 (Melzi clone)
//
// Other ATmega644P, ATmega644, ATmega1284P
//
-#define BOARD_GEN3_MONOLITHIC 22 // Gen3 Monolithic Electronics
-#define BOARD_GEN3_PLUS 9 // Gen3+
-#define BOARD_GEN6 5 // Gen6
-#define BOARD_GEN6_DELUXE 51 // Gen6 deluxe
-#define BOARD_GEN7_CUSTOM 10 // Gen7 custom (Alfons3 Version) "https://github.com/Alfons3/Generation_7_Electronics"
-#define BOARD_GEN7_12 11 // Gen7 v1.1, v1.2
-#define BOARD_GEN7_13 12 // Gen7 v1.3
-#define BOARD_GEN7_14 13 // Gen7 v1.4
-#define BOARD_OMCA_A 90 // Alpha OMCA board
-#define BOARD_OMCA 91 // Final OMCA board
-#define BOARD_SETHI 20 // Sethi 3D_1
+#define BOARD_GEN3_MONOLITHIC 1600 // Gen3 Monolithic Electronics
+#define BOARD_GEN3_PLUS 1601 // Gen3+
+#define BOARD_GEN6 1602 // Gen6
+#define BOARD_GEN6_DELUXE 1603 // Gen6 deluxe
+#define BOARD_GEN7_CUSTOM 1604 // Gen7 custom (Alfons3 Version) "https://github.com/Alfons3/Generation_7_Electronics"
+#define BOARD_GEN7_12 1605 // Gen7 v1.1, v1.2
+#define BOARD_GEN7_13 1606 // Gen7 v1.3
+#define BOARD_GEN7_14 1607 // Gen7 v1.4
+#define BOARD_OMCA_A 1608 // Alpha OMCA board
+#define BOARD_OMCA 1609 // Final OMCA board
+#define BOARD_SETHI 1610 // Sethi 3D_1
//
// Teensyduino - AT90USB1286, AT90USB1286P
//
-#define BOARD_TEENSYLU 8 // Teensylu
-#define BOARD_PRINTRBOARD 81 // Printrboard (AT90USB1286)
-#define BOARD_PRINTRBOARD_REVF 811 // Printrboard Revision F (AT90USB1286)
-#define BOARD_BRAINWAVE 82 // Brainwave (AT90USB646)
-#define BOARD_BRAINWAVE_PRO 85 // Brainwave Pro (AT90USB1286)
-#define BOARD_SAV_MKI 83 // SAV Mk-I (AT90USB1286)
-#define BOARD_TEENSY2 84 // Teensy++2.0 (AT90USB1286)
-#define BOARD_5DPRINT 88 // 5DPrint D8 Driver Board
+#define BOARD_TEENSYLU 1700 // Teensylu
+#define BOARD_PRINTRBOARD 1701 // Printrboard (AT90USB1286)
+#define BOARD_PRINTRBOARD_REVF 1702 // Printrboard Revision F (AT90USB1286)
+#define BOARD_BRAINWAVE 1703 // Brainwave (AT90USB646)
+#define BOARD_BRAINWAVE_PRO 1704 // Brainwave Pro (AT90USB1286)
+#define BOARD_SAV_MKI 1705 // SAV Mk-I (AT90USB1286)
+#define BOARD_TEENSY2 1706 // Teensy++2.0 (AT90USB1286)
+#define BOARD_5DPRINT 1707 // 5DPrint D8 Driver Board
//
// LPC1768 ARM Cortex M3
//
-#define BOARD_RAMPS_14_RE_ARM_EFB 1743 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS_14_RE_ARM_EEB 1744 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS_14_RE_ARM_EFF 1745 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS_14_RE_ARM_EEF 1746 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS_14_RE_ARM_SF 1748 // Re-ARM with RAMPS 1.4 (Power outputs: Spindle, Controller Fan)
-#define BOARD_MKS_SBASE 1750 // MKS-Sbase (Power outputs: Hotend0, Hotend1, Bed, Fan)
-#define BOARD_AZSMZ_MINI 1751 // AZSMZ Mini
-#define BOARD_AZTEEG_X5_GT 1752 // Azteeg X5 GT (Power outputs: Hotend0, Hotend1, Bed, Fan)
-#define BOARD_BIQU_BQ111_A4 1753 // BIQU BQ111-A4 (Power outputs: Hotend, Fan, Bed)
-#define BOARD_SELENA_COMPACT 1754 // Selena Compact (Power outputs: Hotend0, Hotend1, Bed0, Bed1, Fan0, Fan1)
-#define BOARD_COHESION3D_REMIX 1755 // Cohesion3D ReMix
-#define BOARD_COHESION3D_MINI 1756 // Cohesion3D Mini
-#define BOARD_SMOOTHIEBOARD 1757 // Smoothieboard
-#define BOARD_AZTEEG_X5_MINI_WIFI 1758 // Azteeg X5 Mini Wifi (Power outputs: Hotend0, Bed, Fan)
-#define BOARD_BIQU_SKR_V1_1 1759 // BIQU SKR_V1.1 (Power outputs: Hotend0,Hotend1, Fan, Bed)
-#define BOARD_BIQU_B300_V1_0 1760 // BIQU B300_V1.0 (Power outputs: Hotend0, Fan, Bed, SPI Driver)
-#define BOARD_BIGTREE_SKR_V1_3 1761 // BIGTREE SKR_V1.3 (Power outputs: Hotend0, Hotend1, Fan, Bed)
-#define BOARD_AZTEEG_X5_MINI 1762 // Azteeg X5 Mini (Power outputs: Hotend0, Bed, Fan)
-#define BOARD_MKS_SGEN 1763 // MKS-SGen (Power outputs: Hotend0, Hotend1, Bed, Fan)
+#define BOARD_RAMPS_14_RE_ARM_EFB 2000 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS_14_RE_ARM_EEB 2001 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS_14_RE_ARM_EFF 2002 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS_14_RE_ARM_EEF 2003 // Re-ARM with RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS_14_RE_ARM_SF 2004 // Re-ARM with RAMPS 1.4 (Power outputs: Spindle, Controller Fan)
+#define BOARD_MKS_SBASE 2005 // MKS-Sbase (Power outputs: Hotend0, Hotend1, Bed, Fan)
+#define BOARD_AZSMZ_MINI 2006 // AZSMZ Mini
+#define BOARD_AZTEEG_X5_GT 2007 // Azteeg X5 GT (Power outputs: Hotend0, Hotend1, Bed, Fan)
+#define BOARD_BIQU_BQ111_A4 2008 // BIQU BQ111-A4 (Power outputs: Hotend, Fan, Bed)
+#define BOARD_SELENA_COMPACT 2009 // Selena Compact (Power outputs: Hotend0, Hotend1, Bed0, Bed1, Fan0, Fan1)
+#define BOARD_COHESION3D_REMIX 2010 // Cohesion3D ReMix
+#define BOARD_COHESION3D_MINI 2011 // Cohesion3D Mini
+#define BOARD_SMOOTHIEBOARD 2012 // Smoothieboard
+#define BOARD_AZTEEG_X5_MINI_WIFI 2013 // Azteeg X5 Mini Wifi (Power outputs: Hotend0, Bed, Fan)
+#define BOARD_BIGTREE_SKR_V1_1 2014 // BIGTREE SKR_V1.1 (Power outputs: Hotend0,Hotend1, Fan, Bed)
+#define BOARD_BIQU_B300_V1_0 2015 // BIQU B300_V1.0 (Power outputs: Hotend0, Fan, Bed, SPI Driver)
+#define BOARD_BIGTREE_SKR_V1_3 2016 // BIGTREE SKR_V1.3 (Power outputs: Hotend0, Hotend1, Fan, Bed)
+#define BOARD_AZTEEG_X5_MINI 2017 // Azteeg X5 Mini (Power outputs: Hotend0, Bed, Fan)
+#define BOARD_MKS_SGEN 2018 // MKS-SGen (Power outputs: Hotend0, Hotend1, Bed, Fan)
+#define BOARD_MKS_SGEN_L 2019 // MKS-SGen-L (Power outputs: Hotend0, Hotend1, Bed, Fan)
+#define BOARD_TH3D_EZBOARD 2020 // TH3D EZBoard v1.0
+#define BOARD_GMARSH_X6_REV1 2021 // GMARSH X6 board, revision 1 prototype
//
// SAM3X8E ARM Cortex M3
//
-#define BOARD_DUE3DOM 1411 // DUE3DOM for Arduino DUE
-#define BOARD_DUE3DOM_MINI 1412 // DUE3DOM MINI for Arduino DUE
-#define BOARD_RADDS 1502 // RADDS
-#define BOARD_RAMPS_FD_V1 1503 // RAMPS-FD v1
-#define BOARD_RAMPS_FD_V2 1504 // RAMPS-FD v2
-#define BOARD_RAMPS_SMART_EFB 1523 // RAMPS-SMART (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS_SMART_EEB 1524 // RAMPS-SMART (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS_SMART_EFF 1525 // RAMPS-SMART (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS_SMART_EEF 1526 // RAMPS-SMART (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS_SMART_SF 1528 // RAMPS-SMART (Power outputs: Spindle, Controller Fan)
-#define BOARD_RAMPS_DUO_EFB 1533 // RAMPS Duo (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS_DUO_EEB 1534 // RAMPS Duo (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS_DUO_EFF 1535 // RAMPS Duo (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS_DUO_EEF 1536 // RAMPS Duo (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS_DUO_SF 1538 // RAMPS Duo (Power outputs: Spindle, Controller Fan)
-#define BOARD_RAMPS4DUE_EFB 1543 // RAMPS4DUE (Power outputs: Hotend, Fan, Bed)
-#define BOARD_RAMPS4DUE_EEB 1544 // RAMPS4DUE (Power outputs: Hotend0, Hotend1, Bed)
-#define BOARD_RAMPS4DUE_EFF 1545 // RAMPS4DUE (Power outputs: Hotend, Fan0, Fan1)
-#define BOARD_RAMPS4DUE_EEF 1546 // RAMPS4DUE (Power outputs: Hotend0, Hotend1, Fan)
-#define BOARD_RAMPS4DUE_SF 1548 // RAMPS4DUE (Power outputs: Spindle, Controller Fan)
-#define BOARD_RURAMPS4D_11 1550 // RuRAMPS4Duo v1.1 (Power outputs: Hotend0, Hotend1, Hotend2, Fan0, Fan1, Bed)
-#define BOARD_RURAMPS4D_13 1551 // RuRAMPS4Duo v1.3 (Power outputs: Hotend0, Hotend1, Hotend2, Fan0, Fan1, Bed)
-#define BOARD_ULTRATRONICS_PRO 1560 // ReprapWorld Ultratronics Pro V1.0
-#define BOARD_ARCHIM1 1591 // UltiMachine Archim1 (with DRV8825 drivers)
-#define BOARD_ARCHIM2 1592 // UltiMachine Archim2 (with TMC2130 drivers)
-#define BOARD_ALLIGATOR 1602 // Alligator Board R2
+#define BOARD_DUE3DOM 3000 // DUE3DOM for Arduino DUE
+#define BOARD_DUE3DOM_MINI 3001 // DUE3DOM MINI for Arduino DUE
+#define BOARD_RADDS 3002 // RADDS
+#define BOARD_RAMPS_FD_V1 3003 // RAMPS-FD v1
+#define BOARD_RAMPS_FD_V2 3004 // RAMPS-FD v2
+#define BOARD_RAMPS_SMART_EFB 3005 // RAMPS-SMART (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS_SMART_EEB 3006 // RAMPS-SMART (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS_SMART_EFF 3007 // RAMPS-SMART (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS_SMART_EEF 3008 // RAMPS-SMART (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS_SMART_SF 3009 // RAMPS-SMART (Power outputs: Spindle, Controller Fan)
+#define BOARD_RAMPS_DUO_EFB 3010 // RAMPS Duo (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS_DUO_EEB 3011 // RAMPS Duo (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS_DUO_EFF 3012 // RAMPS Duo (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS_DUO_EEF 3013 // RAMPS Duo (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS_DUO_SF 3014 // RAMPS Duo (Power outputs: Spindle, Controller Fan)
+#define BOARD_RAMPS4DUE_EFB 3015 // RAMPS4DUE (Power outputs: Hotend, Fan, Bed)
+#define BOARD_RAMPS4DUE_EEB 3016 // RAMPS4DUE (Power outputs: Hotend0, Hotend1, Bed)
+#define BOARD_RAMPS4DUE_EFF 3017 // RAMPS4DUE (Power outputs: Hotend, Fan0, Fan1)
+#define BOARD_RAMPS4DUE_EEF 3018 // RAMPS4DUE (Power outputs: Hotend0, Hotend1, Fan)
+#define BOARD_RAMPS4DUE_SF 3019 // RAMPS4DUE (Power outputs: Spindle, Controller Fan)
+#define BOARD_RURAMPS4D_11 3020 // RuRAMPS4Duo v1.1 (Power outputs: Hotend0, Hotend1, Hotend2, Fan0, Fan1, Bed)
+#define BOARD_RURAMPS4D_13 3021 // RuRAMPS4Duo v1.3 (Power outputs: Hotend0, Hotend1, Hotend2, Fan0, Fan1, Bed)
+#define BOARD_ULTRATRONICS_PRO 3022 // ReprapWorld Ultratronics Pro V1.0
+#define BOARD_ARCHIM1 3023 // UltiMachine Archim1 (with DRV8825 drivers)
+#define BOARD_ARCHIM2 3024 // UltiMachine Archim2 (with TMC2130 drivers)
+#define BOARD_ALLIGATOR 3025 // Alligator Board R2
//
// SAM3X8C ARM Cortex M3
//
-#define BOARD_PRINTRBOARD_G2 1620 // PRINTRBOARD G2
-#define BOARD_ADSK 1610 // Arduino DUE Shield Kit (ADSK)
+#define BOARD_PRINTRBOARD_G2 3100 // PRINTRBOARD G2
+#define BOARD_ADSK 3101 // Arduino DUE Shield Kit (ADSK)
//
// STM32 ARM Cortex-M3
//
-#define BOARD_STM32F1R 1800 // STM32R Libmaple based STM32F1 controller
-#define BOARD_MALYAN_M200 1801 // STM32C8T6 Libmaple based stm32f1 controller
-#define BOARD_STM3R_MINI 1803 // STM32 Libmaple based stm32f1 controller
-#define BOARD_GTM32_PRO_VB 1805 // STM32f103VET6 controller
-#define BOARD_MORPHEUS 1806 // STM32F103C8/STM32F103CB Libmaple based stm32f1 controller
-#define BOARD_MKS_ROBIN 1808 // MKS Robin / STM32F103ZET6
+#define BOARD_STM32F103RE 4000 // STM32F103RE Libmaple-based STM32F1 controller
+#define BOARD_MALYAN_M200 4001 // STM32C8T6 Libmaple-based STM32F1 controller
+#define BOARD_STM3R_MINI 4002 // STM32F103RE Libmaple-based STM32F1 controller
+#define BOARD_GTM32_PRO_VB 4003 // STM32F103VET6 controller
+#define BOARD_MORPHEUS 4004 // STM32F103C8 / STM32F103CB Libmaple-based STM32F1 controller
+#define BOARD_CHITU3D 4005 // Chitu3D (STM32F103RET6)
+#define BOARD_MKS_ROBIN 4006 // MKS Robin (STM32F103ZET6)
+#define BOARD_MKS_ROBIN_MINI 4007 // MKS Robin Mini (STM32F103VET6)
+#define BOARD_MKS_ROBIN_NANO 4008 // MKS Robin Nano (STM32F103VET6)
+#define BOARD_MKS_ROBIN_LITE 4009 // MKS Robin Lite/Lite2 (STM32F103RCT6)
+#define BOARD_BIGTREE_SKR_MINI_V1_1 4010 // BigTreeTech SKR Mini v1.1 (STM32F103RC)
+#define BOARD_BIGTREE_SKR_MINI_E3 4011 // BigTreeTech SKR Mini E3 (STM32F103RC)
+#define BOARD_BIGTREE_SKR_E3_DIP 4012 // BigTreeTech SKR E3 DIP V1.0 (STM32F103RC)
+#define BOARD_BTT_SKR_MINI_E3_V1_2 4013 // BigTreeTech SKR Mini E3 V1.2 (STM32F103RC)
+#define BOARD_JGAURORA_A5S_A1 4014 // JGAurora A5S A1 (STM32F103ZET6)
+#define BOARD_FYSETC_AIO_II 4015 // FYSETC AIO_II
+#define BOARD_FYSETC_CHEETAH 4016 // FYSETC Cheetah
+#define BOARD_FYSETC_CHEETAH_V12 4017 // FYSETC Cheetah V1.2
+#define BOARD_LONGER3D_LK 4018 // Alfawise U20/U20+/U30 (Longer3D LK1/2) / STM32F103VET6
+
+//
+// ARM Cortex-M4F
+//
+
+#define BOARD_TEENSY31_32 4100 // Teensy3.1 and Teensy3.2
+#define BOARD_TEENSY35_36 4101 // Teensy3.5 and Teensy3.6
//
// STM32 ARM Cortex-M4F
//
-#define BOARD_TEENSY31_32 1552 // Teensy3.1 and Teensy3.2
-#define BOARD_TEENSY35_36 841 // Teensy3.5 and Teensy3.6
-#define BOARD_BEAST 1802 // STM32FxxxVxT6 Libmaple based stm32f4 controller
-#define BOARD_STM32F4 1804 // STM32 STM32GENERIC based STM32F4 controller
-#define BOARD_ARMED 1807 // Arm'ed STM32F4 based controller
-#define BOARD_RUMBA32 1809 // RUMBA32 STM32F4 based controller
-#define BOARD_BLACK_STM32F407VE 1810 // BLACK_STM32F407VE
-#define BOARD_BLACK_STM32F407ZE 1811 // BLACK_STM32F407ZE
-#define BOARD_STEVAL 1866 // STEVAL-3DP001V1 3D PRINTER BOARD
+#define BOARD_BEAST 4200 // STM32F4xxVxT6 Libmaple-based STM32F4 controller
+#define BOARD_STM32F4 4201 // STM32 STM32GENERIC-based STM32F4 controller
+#define BOARD_ARMED 4202 // Arm'ed STM32F4-based controller
+#define BOARD_RUMBA32 4203 // RUMBA32 STM32F4-based controller
+#define BOARD_BLACK_STM32F407VE 4204 // BLACK_STM32F407VE
+#define BOARD_BLACK_STM32F407ZE 4205 // BLACK_STM32F407ZE
+#define BOARD_STEVAL 4206 // STEVAL-3DP001V1 3D PRINTER BOARD
+#define BOARD_BIGTREE_SKR_PRO_V1_1 4207 // BigTreeTech SKR Pro v1.1 (STM32F407ZG)
+#define BOARD_BIGTREE_BTT002_V1_0 4208 // BigTreeTech BTT002 v1.0 (STM32F407VE)
+#define BOARD_LERDGE_K 4209 // Lerdge K (STM32F407ZG)
+#define BOARD_LERDGE_X 4210 // Lerdge X (STM32F407VE)
//
// ARM Cortex M7
//
-#define BOARD_THE_BORG 1860 // THE-BORG (Power outputs: Hotend0, Hotend1, Bed, Fan)
-#define BOARD_REMRAM_V1 1862 // RemRam v1
+#define BOARD_THE_BORG 5000 // THE-BORG (Power outputs: Hotend0, Hotend1, Bed, Fan)
+#define BOARD_REMRAM_V1 5001 // RemRam v1
//
// Espressif ESP32 WiFi
//
-#define BOARD_ESP32 1900
+#define BOARD_ESPRESSIF_ESP32 6000
//
// Simulations
//
-#define BOARD_LINUX_RAMPS 2000
+#define BOARD_LINUX_RAMPS 9999
-#define MB(board) (defined(BOARD_##board) && MOTHERBOARD==BOARD_##board)
+#define _MB_1(B) (defined(BOARD_##B) && MOTHERBOARD==BOARD_##B)
+#define MB(V...) DO(MB,||,V)
+
+#define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY)
diff --git a/Marlin/src/core/debug_out.h b/Marlin/src/core/debug_out.h
index c43c928a29..7eb93a7020 100644
--- a/Marlin/src/core/debug_out.h
+++ b/Marlin/src/core/debug_out.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*
*/
+#pragma once
//
// Serial aliases for debugging.
diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h
index a686ea584f..005ffb7da5 100644
--- a/Marlin/src/core/drivers.h
+++ b/Marlin/src/core/drivers.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,6 +37,8 @@
#define _TMC2160_STANDALONE 2161
#define _TMC2208 2208
#define _TMC2208_STANDALONE 0x00A
+#define _TMC2209 2209
+#define _TMC2209_STANDALONE 0x00D
#define _TMC26X 0x10B
#define _TMC26X_STANDALONE 0x00B
#define _TMC2660 2660
@@ -46,8 +48,8 @@
#define _TMC5160 5160
#define _TMC5160_STANDALONE 5161
-#define _ACTUAL(V) _CAT(_, V)
-#define _AXIS_DRIVER_TYPE(A,T) (defined(A##_DRIVER_TYPE) && _ACTUAL(A##_DRIVER_TYPE) == _CAT(_, T))
+#define _DRIVER_ID(V) _CAT(_, V)
+#define _AXIS_DRIVER_TYPE(A,T) (_DRIVER_ID(A##_DRIVER_TYPE) == _CAT(_, T))
#define AXIS_DRIVER_TYPE_X(T) _AXIS_DRIVER_TYPE(X,T)
#define AXIS_DRIVER_TYPE_Y(T) _AXIS_DRIVER_TYPE(Y,T)
@@ -65,25 +67,31 @@
#define AXIS_DRIVER_TYPE(A,T) AXIS_DRIVER_TYPE_##A(T)
+#define HAS_E_DRIVER(T) ( AXIS_DRIVER_TYPE_E0(T) || AXIS_DRIVER_TYPE_E1(T) \
+ || AXIS_DRIVER_TYPE_E2(T) || AXIS_DRIVER_TYPE_E3(T) \
+ || AXIS_DRIVER_TYPE_E4(T) || AXIS_DRIVER_TYPE_E5(T) )
+
#define HAS_DRIVER(T) ( AXIS_DRIVER_TYPE_X(T) || AXIS_DRIVER_TYPE_X2(T) \
|| AXIS_DRIVER_TYPE_Y(T) || AXIS_DRIVER_TYPE_Y2(T) \
|| AXIS_DRIVER_TYPE_Z(T) || AXIS_DRIVER_TYPE_Z2(T) || AXIS_DRIVER_TYPE_Z3(T) \
- || AXIS_DRIVER_TYPE_E0(T) || AXIS_DRIVER_TYPE_E1(T) \
- || AXIS_DRIVER_TYPE_E2(T) || AXIS_DRIVER_TYPE_E3(T) \
- || AXIS_DRIVER_TYPE_E4(T) || AXIS_DRIVER_TYPE_E5(T) )
+ || HAS_E_DRIVER(T) )
// Test for supported TMC drivers that require advanced configuration
// Does not match standalone configurations
#define HAS_TRINAMIC ( HAS_DRIVER(TMC2130) \
|| HAS_DRIVER(TMC2160) \
|| HAS_DRIVER(TMC2208) \
+ || HAS_DRIVER(TMC2209) \
|| HAS_DRIVER(TMC2660) \
|| HAS_DRIVER(TMC5130) \
|| HAS_DRIVER(TMC5160) )
+#define HAS_TMC220x (HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209))
+
#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \
|| AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) \
+ || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC2660) \
|| AXIS_DRIVER_TYPE(A,TMC5130) \
|| AXIS_DRIVER_TYPE(A,TMC5160) )
@@ -96,8 +104,12 @@
|| AXIS_DRIVER_TYPE(A,TMC5130) \
|| AXIS_DRIVER_TYPE(A,TMC5160) )
+#define AXIS_HAS_UART(A) ( AXIS_DRIVER_TYPE(A,TMC2208) \
+ || AXIS_DRIVER_TYPE(A,TMC2209) )
+
#define AXIS_HAS_STALLGUARD(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \
|| AXIS_DRIVER_TYPE(A,TMC2160) \
+ || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC2660) \
|| AXIS_DRIVER_TYPE(A,TMC5130) \
|| AXIS_DRIVER_TYPE(A,TMC5160) )
@@ -105,5 +117,15 @@
#define AXIS_HAS_STEALTHCHOP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \
|| AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) \
+ || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC5130) \
|| AXIS_DRIVER_TYPE(A,TMC5160) )
+
+//
+// Stretching 'drivers.h' to include LPC/SAMD51 SD options
+//
+#define _SDCARD_LCD 1
+#define _SDCARD_ONBOARD 2
+#define _SDCARD_CUSTOM_CABLE 3
+#define _SDCARD_ID(V) _CAT(_SDCARD_, V)
+#define SD_CONNECTION_IS(V) (_SDCARD_ID(SDCARD_CONNECTION) == _SDCARD_ID(V))
diff --git a/Marlin/src/core/enum.h b/Marlin/src/core/enum.h
deleted file mode 100644
index f2e0fe063b..0000000000
--- a/Marlin/src/core/enum.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Axis indices as enumerated constants
- *
- * - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
- * - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
- * - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
- */
-enum AxisEnum : unsigned char {
- X_AXIS = 0,
- A_AXIS = 0,
- Y_AXIS = 1,
- B_AXIS = 1,
- Z_AXIS = 2,
- C_AXIS = 2,
- E_AXIS = 3,
- X_HEAD = 4,
- Y_HEAD = 5,
- Z_HEAD = 6,
- E0_AXIS = 3,
- E1_AXIS = 4,
- E2_AXIS = 5,
- E3_AXIS = 6,
- E4_AXIS = 7,
- E5_AXIS = 8,
- ALL_AXES = 0xFE,
- NO_AXIS = 0xFF
-};
-
-#if HAS_DRIVER(L6470)
- enum L6470_driver_enum : unsigned char { X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5 };
-#endif
-
-#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
-#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
-#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
-#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
-
-#define LOOP_NA(VAR) LOOP_L_N(VAR, NUM_AXIS)
-#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
-#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
-#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
-#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
-#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
-#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
-
-typedef enum {
- LINEARUNIT_MM,
- LINEARUNIT_INCH
-} LinearUnit;
-
-typedef enum {
- TEMPUNIT_C,
- TEMPUNIT_K,
- TEMPUNIT_F
-} TempUnit;
diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h
index a8d214fba2..df3092fd99 100644
--- a/Marlin/src/core/language.h
+++ b/Marlin/src/core/language.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,7 +37,7 @@
// NOTE: IF YOU CHANGE LANGUAGE FILES OR MERGE A FILE WITH CHANGES
//
-// ==> ALWAYS TRY TO COMPILE MARLIN WITH/WITHOUT "ULTIPANEL" / "ULTRALCD" / "SDSUPPORT" #define IN "Configuration.h"
+// ==> ALWAYS TRY TO COMPILE MARLIN WITH/WITHOUT "ULTIPANEL" / "ULTRA_LCD" / "SDSUPPORT" #define IN "Configuration.h"
// ==> ALSO TRY ALL AVAILABLE LANGUAGE OPTIONS
// See also http://marlinfw.org/docs/development/lcd_language.html
@@ -46,9 +46,10 @@
// bg Bulgarian
// ca Catalan
// cz Czech
+// da Danish
// de German
// el Greek
-// el-gr Greek (Greece)
+// el_gr Greek (Greece)
// en English
// es Spanish
// eu Basque-Euskera
@@ -57,16 +58,17 @@
// gl Galician
// hr Croatian
// it Italian
-// jp-kana Japanese
+// jp_kana Japanese
// ko_KR Korean (South Korea)
// nl Dutch
// pl Polish
// pt Portuguese
-// pt-br Portuguese (Brazilian)
+// pt_br Portuguese (Brazilian)
// ru Russian
// sk Slovak
// tr Turkish
// uk Ukrainian
+// vi Vietnamese
// zh_CN Chinese (Simplified)
// zh_TW Chinese (Traditional)
@@ -89,12 +91,26 @@
#define MACHINE_UUID DEFAULT_MACHINE_UUID
#endif
-#ifdef BOARD_WEBSITE_URL
- #undef WEBSITE_URL
- #define WEBSITE_URL BOARD_WEBSITE_URL
-#endif
+#define MARLIN_WEBSITE_URL "http://marlinfw.org"
-#if HAS_GRAPHICAL_LCD
+//#if !defined(STRING_SPLASH_LINE3) && defined(WEBSITE_URL)
+// #define STRING_SPLASH_LINE3 WEBSITE_URL
+//#endif
+
+#if HAS_CHARACTER_LCD
+
+ // Custom characters defined in the first 8 characters of the LCD
+ #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string!
+ #define LCD_STR_DEGREE "\x01"
+ #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation
+ #define LCD_STR_UPLEVEL "\x03"
+ #define LCD_STR_REFRESH "\x04"
+ #define LCD_STR_FOLDER "\x05"
+ #define LCD_STR_FEEDRATE "\x06"
+ #define LCD_STR_CLOCK "\x07"
+ #define LCD_STR_ARROW_RIGHT ">" /* from the default character set */
+
+#else
//
// Custom characters from Marlin_symbols.fon which was merged into ISO10646-0-3.bdf
// \x00 intentionally skipped to avoid problems in strings
@@ -117,19 +133,6 @@
#define LCD_STR_FILAM_DIA "\xF8"
#define LCD_STR_FILAM_MUL "\xA4"
-#elif HAS_CHARACTER_LCD
-
- // Custom characters defined in the first 8 characters of the LCD
- #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string!
- #define LCD_STR_DEGREE "\x01"
- #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation
- #define LCD_STR_UPLEVEL "\x03"
- #define LCD_STR_REFRESH "\x04"
- #define LCD_STR_FOLDER "\x05"
- #define LCD_STR_FEEDRATE "\x06"
- #define LCD_STR_CLOCK "\x07"
- #define LCD_STR_ARROW_RIGHT ">" /* from the default character set */
-
#endif
// Common LCD messages
@@ -165,7 +168,6 @@
#define MSG_INVALID_E_STEPPER "Invalid E stepper"
#define MSG_E_STEPPER_NOT_SPECIFIED "E stepper not specified"
#define MSG_INVALID_SOLENOID "Invalid solenoid"
-#define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature"
#define MSG_M115_REPORT "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID
#define MSG_COUNT_X " Count X:"
#define MSG_COUNT_A " Count A:"
@@ -195,7 +197,7 @@
#define MSG_Z3_MAX "z3_max"
#define MSG_Z_PROBE "z_probe"
#define MSG_FILAMENT_RUNOUT_SENSOR "filament"
-#define MSG_PROBE_Z_OFFSET "Probe Z Offset"
+#define MSG_PROBE_OFFSET "Probe Offset"
#define MSG_SKEW_MIN "min_skew_factor: "
#define MSG_SKEW_MAX "max_skew_factor: "
#define MSG_ERR_MATERIAL_INDEX "M145 S out of range (0-1)"
@@ -240,10 +242,9 @@
#define MSG_ERR_COLD_EXTRUDE_STOP " cold extrusion prevented"
#define MSG_ERR_LONG_EXTRUDE_STOP " too long extrusion prevented"
#define MSG_ERR_HOTEND_TOO_COLD "Hotend too cold"
+#define MSG_ERR_Z_HOMING_SER "Home XY first"
+#define MSG_ERR_EEPROM_WRITE "Error writing to EEPROM!"
-#define MSG_FILAMENT_CHANGE_HEAT "Press button (or M108) to heat nozzle"
-#define MSG_FILAMENT_CHANGE_INSERT "Insert filament and press button (or M108)"
-#define MSG_FILAMENT_CHANGE_WAIT "Press button (or M108) to resume"
#define MSG_FILAMENT_CHANGE_HEAT_LCD "Press button to heat nozzle"
#define MSG_FILAMENT_CHANGE_INSERT_LCD "Insert filament and press button"
#define MSG_FILAMENT_CHANGE_WAIT_LCD "Press button to resume"
@@ -251,8 +252,6 @@
#define MSG_FILAMENT_CHANGE_INSERT_M108 "Insert filament and send M108"
#define MSG_FILAMENT_CHANGE_WAIT_M108 "Send M108 to resume"
-#define MSG_ERR_EEPROM_WRITE "Error writing to EEPROM!"
-
#define MSG_STOP_BLTOUCH "STOP called because of BLTouch error - restart with M999"
#define MSG_STOP_UNHOMED "STOP called because of unhomed error - restart with M999"
#define MSG_KILL_INACTIVE_TIME "KILL caused by too much inactive time - current command: "
@@ -295,6 +294,8 @@
#define MSG_T_THERMAL_RUNAWAY "Thermal Runaway"
#define MSG_T_MAXTEMP "MAXTEMP triggered"
#define MSG_T_MINTEMP "MINTEMP triggered"
+#define MSG_ERR_PROBING_FAILED "Probing Failed"
+#define MSG_ZPROBE_OUT_SER "Z Probe Past Bed"
// Debug
#define MSG_DEBUG_PREFIX "DEBUG:"
@@ -310,11 +311,9 @@
#define LANGUAGE_DATA_INCL_(M) STRINGIFY_(fontdata/langdata_##M.h)
#define LANGUAGE_DATA_INCL(M) LANGUAGE_DATA_INCL_(M)
-#define INCLUDE_LANGUAGE_DATA LANGUAGE_DATA_INCL(LCD_LANGUAGE)
#define LANGUAGE_INCL_(M) STRINGIFY_(../lcd/language/language_##M.h)
#define LANGUAGE_INCL(M) LANGUAGE_INCL_(M)
-#define INCLUDE_LANGUAGE LANGUAGE_INCL(LCD_LANGUAGE)
// Never translate these strings
#define MSG_X "X"
@@ -334,54 +333,61 @@
#define MSG_Y2 "Y2"
#define MSG_Z2 "Z2"
#define MSG_Z3 "Z3"
-#define MSG_H1 "1"
-#define MSG_H2 "2"
-#define MSG_H3 "3"
-#define MSG_H4 "4"
-#define MSG_H5 "5"
-#define MSG_H6 "6"
-#define MSG_LCD_N0 " 1"
-#define MSG_LCD_N1 " 2"
-#define MSG_LCD_N2 " 3"
-#define MSG_LCD_N3 " 4"
-#define MSG_LCD_N4 " 5"
-#define MSG_LCD_N5 " 6"
-#define MSG_E1 "E1"
-#define MSG_E2 "E2"
-#define MSG_E3 "E3"
-#define MSG_E4 "E4"
-#define MSG_E5 "E5"
-#define MSG_E6 "E6"
-#define MSG_MOVE_E1 "1"
-#define MSG_MOVE_E2 "2"
-#define MSG_MOVE_E3 "3"
-#define MSG_MOVE_E4 "4"
-#define MSG_MOVE_E5 "5"
-#define MSG_MOVE_E6 "6"
-#define MSG_DIAM_E1 " 1"
-#define MSG_DIAM_E2 " 2"
-#define MSG_DIAM_E3 " 3"
-#define MSG_DIAM_E4 " 4"
-#define MSG_DIAM_E5 " 5"
-#define MSG_DIAM_E6 " 6"
-#include INCLUDE_LANGUAGE
+#define LCD_STR_A MSG_A
+#define LCD_STR_B MSG_B
+#define LCD_STR_C MSG_C
+#define LCD_STR_E MSG_E
-#if DISABLED(DISPLAY_CHARSET_ISO10646_1) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_5) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_KANA) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_GREEK) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_CN) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_TR) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_PL) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_CZ) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_SK)
- #define DISPLAY_CHARSET_ISO10646_1 // use the better font on full graphic displays.
+/**
+ * Tool indexes for LCD display only
+ *
+ * By convention the LCD shows "E1" for the first extruder.
+ * However, internal to Marlin E0/T0 is the first tool, and
+ * most board silkscreens say "E0." Zero-based labels will
+ * make these indexes consistent but this defies expectation.
+ *
+ */
+#if ENABLED(NUMBER_TOOLS_FROM_0)
+ #define LCD_STR_N0 "0"
+ #define LCD_STR_N1 "1"
+ #define LCD_STR_N2 "2"
+ #define LCD_STR_N3 "3"
+ #define LCD_STR_N4 "4"
+ #define LCD_STR_N5 "5"
+#else
+ #define LCD_STR_N0 "1"
+ #define LCD_STR_N1 "2"
+ #define LCD_STR_N2 "3"
+ #define LCD_STR_N3 "4"
+ #define LCD_STR_N4 "5"
+ #define LCD_STR_N5 "6"
#endif
+#define LCD_STR_E0 "E" LCD_STR_N0
+#define LCD_STR_E1 "E" LCD_STR_N1
+#define LCD_STR_E2 "E" LCD_STR_N2
+#define LCD_STR_E3 "E" LCD_STR_N3
+#define LCD_STR_E4 "E" LCD_STR_N4
+#define LCD_STR_E5 "E" LCD_STR_N5
+
+#include "multi_language.h" // Allow multiple languages
+
#include "../lcd/language/language_en.h"
+#include LANGUAGE_INCL(LCD_LANGUAGE)
+#include LANGUAGE_INCL(LCD_LANGUAGE_2)
+#include LANGUAGE_INCL(LCD_LANGUAGE_3)
+#include LANGUAGE_INCL(LCD_LANGUAGE_4)
+#include LANGUAGE_INCL(LCD_LANGUAGE_5)
-#ifdef CUSTOM_USER_MENU_TITLE
- #undef MSG_USER_MENU
- #define MSG_USER_MENU CUSTOM_USER_MENU_TITLE
+#if NONE(DISPLAY_CHARSET_ISO10646_1, \
+ DISPLAY_CHARSET_ISO10646_5, \
+ DISPLAY_CHARSET_ISO10646_KANA, \
+ DISPLAY_CHARSET_ISO10646_GREEK, \
+ DISPLAY_CHARSET_ISO10646_CN, \
+ DISPLAY_CHARSET_ISO10646_TR, \
+ DISPLAY_CHARSET_ISO10646_PL, \
+ DISPLAY_CHARSET_ISO10646_CZ, \
+ DISPLAY_CHARSET_ISO10646_SK)
+ #define DISPLAY_CHARSET_ISO10646_1 // use the better font on full graphic displays.
#endif
diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h
index 3805c216fe..b93bae79f6 100644
--- a/Marlin/src/core/macros.h
+++ b/Marlin/src/core/macros.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,13 +21,11 @@
*/
#pragma once
-#include "minmax.h"
-
-#define NUM_AXIS 4
#define ABCE 4
#define XYZE 4
#define ABC 3
#define XYZ 3
+#define XY 2
#define _AXIS(A) (A##_AXIS)
@@ -47,6 +45,14 @@
#define _O2 __attribute__((optimize("O2")))
#define _O3 __attribute__((optimize("O3")))
+#ifndef UNUSED
+ #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+ #define UNUSED(X) (void)X
+ #else
+ #define UNUSED(x) ((void)(x))
+ #endif
+#endif
+
// Clock speed factors
#if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 on AVR
@@ -55,8 +61,12 @@
// Nanoseconds per cycle
#define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
-// Remove compiler warning on an unused variable
-#define UNUSED(X) (void)X
+// Macros to make sprintf_P read from PROGMEM (AVR extension)
+#ifdef __AVR__
+ #define S_FMT "%S"
+#else
+ #define S_FMT "%s"
+#endif
// Macros to make a string from a macro
#define STRINGIFY_(M) #M
@@ -68,20 +78,23 @@
// Macros for bit masks
#undef _BV
#define _BV(n) (1<<(n))
-#define TEST(n,b) !!((n)&_BV(b))
-#define SBI(n,b) (n |= _BV(b))
-#define CBI(n,b) (n &= ~_BV(b))
+#define TEST(n,b) (!!((n)&_BV(b)))
#define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
+#ifndef SBI
+ #define SBI(A,B) (A |= (1 << (B)))
+#endif
+
+#ifndef CBI
+ #define CBI(A,B) (A &= ~(1 << (B)))
+#endif
+
#define _BV32(b) (1UL << (b))
#define TEST32(n,b) !!((n)&_BV32(b))
#define SBI32(n,b) (n |= _BV32(b))
#define CBI32(n,b) (n &= ~_BV32(b))
-// Macros for maths shortcuts
-#undef M_PI
-#define M_PI 3.14159265358979323846f
-
+#define cu(x) ((x)*(x)*(x))
#define RADIANS(d) ((d)*float(M_PI)/180.0f)
#define DEGREES(r) ((r)*180.0f/float(M_PI))
#define HYPOT2(x,y) (sq(x)+sq(y))
@@ -97,14 +110,14 @@
// C++11 solution that is standards compliant.
template static inline constexpr void NOLESS(V& v, const N n) {
- if (v < n) v = n;
+ if (n > v) v = n;
}
template static inline constexpr void NOMORE(V& v, const N n) {
- if (v > n) v = n;
+ if (n < v) v = n;
}
template static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
- if (v < n1) v = n1;
- else if (v > n2) v = n2;
+ if (n1 > v) v = n1;
+ else if (n2 < v) v = n2;
}
#else
@@ -112,24 +125,24 @@
// Using GCC extensions, but Travis GCC version does not like it and gives
// "error: statement-expressions are not allowed outside functions nor in template-argument lists"
#define NOLESS(v, n) \
- do { \
+ do{ \
__typeof__(n) _n = (n); \
- if (v < _n) v = _n; \
- } while(0)
+ if (_n > v) v = _n; \
+ }while(0)
#define NOMORE(v, n) \
- do { \
+ do{ \
__typeof__(n) _n = (n); \
- if (v > _n) v = _n; \
- } while(0)
+ if (_n < v) v = _n; \
+ }while(0)
#define LIMIT(v, n1, n2) \
- do { \
+ do{ \
__typeof__(n1) _n1 = (n1); \
__typeof__(n2) _n2 = (n2); \
- if (v < _n1) v = _n1; \
- else if (v > _n2) v = _n2; \
- } while(0)
+ if (_n1 > v) v = _n1; \
+ else if (_n2 < v) v = _n2; \
+ }while(0)
#endif
@@ -188,19 +201,33 @@
#define ZERO(a) memset(a,0,sizeof(a))
#define COPY(a,b) do{ \
static_assert(sizeof(a[0]) == sizeof(b[0]), "COPY: '" STRINGIFY(a) "' and '" STRINGIFY(b) "' types (sizes) don't match!"); \
- memcpy(&a[0],&b[0],MIN(sizeof(a),sizeof(b))); \
+ memcpy(&a[0],&b[0],_MIN(sizeof(a),sizeof(b))); \
}while(0)
// Macros for initializing arrays
-#define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
-#define ARRAY_5(v1, v2, v3, v4, v5, ...) { v1, v2, v3, v4, v5 }
-#define ARRAY_4(v1, v2, v3, v4, ...) { v1, v2, v3, v4 }
-#define ARRAY_3(v1, v2, v3, ...) { v1, v2, v3 }
-#define ARRAY_2(v1, v2, ...) { v1, v2 }
-#define ARRAY_1(v1, ...) { v1 }
+#define LIST_16(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P
+#define LIST_15(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O
+#define LIST_14(A,B,C,D,E,F,G,H,I,J,K,L,M,N,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N
+#define LIST_13(A,B,C,D,E,F,G,H,I,J,K,L,M,...) A,B,C,D,E,F,G,H,I,J,K,L,M
+#define LIST_12(A,B,C,D,E,F,G,H,I,J,K,L,...) A,B,C,D,E,F,G,H,I,J,K,L
+#define LIST_11(A,B,C,D,E,F,G,H,I,J,K,...) A,B,C,D,E,F,G,H,I,J,K
+#define LIST_10(A,B,C,D,E,F,G,H,I,J,...) A,B,C,D,E,F,G,H,I,J
+#define LIST_9( A,B,C,D,E,F,G,H,I,...) A,B,C,D,E,F,G,H,I
+#define LIST_8( A,B,C,D,E,F,G,H,...) A,B,C,D,E,F,G,H
+#define LIST_7( A,B,C,D,E,F,G,...) A,B,C,D,E,F,G
+#define LIST_6( A,B,C,D,E,F,...) A,B,C,D,E,F
+#define LIST_5( A,B,C,D,E,...) A,B,C,D,E
+#define LIST_4( A,B,C,D,...) A,B,C,D
+#define LIST_3( A,B,C,...) A,B,C
+#define LIST_2( A,B,...) A,B
+#define LIST_1( A,...) A
-#define _ARRAY_N(N,V...) ARRAY_##N(V)
-#define ARRAY_N(N,V...) _ARRAY_N(N,V)
+#define _LIST_N(N,V...) LIST_##N(V)
+#define LIST_N(N,V...) _LIST_N(N,V)
+#define ARRAY_N(N,V...) { _LIST_N(N,V) }
+
+#define _JOIN_1(O) (O)
+#define JOIN_N(N,C,V...) (DO(JOIN,C,LIST_N(N,V)))
// Macros for adding
#define INC_0 1
@@ -228,9 +255,6 @@
#define DECREMENT_(n) DEC_##n
#define DECREMENT(n) DECREMENT_(n)
-#define MMM_TO_MMS(MM_M) ((MM_M)/60.0f)
-#define MMS_TO_MMM(MM_S) ((MM_S)*60.0f)
-
#define NOOP (void(0))
#define CEILING(x,y) (((x) + (y) - 1) / (y))
@@ -267,3 +291,58 @@
#else
#define I2C_ADDRESS(A) A
#endif
+
+// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
+#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
+#define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
+
+#ifdef __cplusplus
+
+ #ifndef _MINMAX_H_
+ #define _MINMAX_H_
+
+ extern "C++" {
+
+ // C++11 solution that is standards compliant. Return type is deduced automatically
+ template static inline constexpr auto _MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+ return lhs < rhs ? lhs : rhs;
+ }
+ template static inline constexpr auto _MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+ return lhs > rhs ? lhs : rhs;
+ }
+ template static inline constexpr const T _MIN(T V, Ts... Vs) { return _MIN(V, _MIN(Vs...)); }
+ template static inline constexpr const T _MAX(T V, Ts... Vs) { return _MAX(V, _MAX(Vs...)); }
+
+ }
+
+ #endif
+
+#else
+
+ #define MIN_2(a,b) ((a)<(b)?(a):(b))
+ #define MIN_3(a,V...) MIN_2(a,MIN_2(V))
+ #define MIN_4(a,V...) MIN_2(a,MIN_3(V))
+ #define MIN_5(a,V...) MIN_2(a,MIN_4(V))
+ #define MIN_6(a,V...) MIN_2(a,MIN_5(V))
+ #define MIN_7(a,V...) MIN_2(a,MIN_6(V))
+ #define MIN_8(a,V...) MIN_2(a,MIN_7(V))
+ #define MIN_9(a,V...) MIN_2(a,MIN_8(V))
+ #define MIN_10(a,V...) MIN_2(a,MIN_9(V))
+ #define __MIN_N(N,V...) MIN_##N(V)
+ #define _MIN_N(N,V...) __MIN_N(N,V)
+ #define _MIN(V...) _MIN_N(NUM_ARGS(V), V)
+
+ #define MAX_2(a,b) ((a)>(b)?(a):(b))
+ #define MAX_3(a,V...) MAX_2(a,MAX_2(V))
+ #define MAX_4(a,V...) MAX_2(a,MAX_3(V))
+ #define MAX_5(a,V...) MAX_2(a,MAX_4(V))
+ #define MAX_6(a,V...) MAX_2(a,MAX_5(V))
+ #define MAX_7(a,V...) MAX_2(a,MAX_6(V))
+ #define MAX_8(a,V...) MAX_2(a,MAX_7(V))
+ #define MAX_9(a,V...) MAX_2(a,MAX_8(V))
+ #define MAX_10(a,V...) MAX_2(a,MAX_9(V))
+ #define __MAX_N(N,V...) MAX_##N(V)
+ #define _MAX_N(N,V...) __MAX_N(N,V)
+ #define _MAX(V...) _MAX_N(NUM_ARGS(V), V)
+
+#endif
diff --git a/Marlin/src/core/millis_t.h b/Marlin/src/core/millis_t.h
index b2afeb83f0..7ff231f827 100644
--- a/Marlin/src/core/millis_t.h
+++ b/Marlin/src/core/millis_t.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/Marlin/src/core/minmax.h b/Marlin/src/core/minmax.h
deleted file mode 100644
index 0f29443adc..0000000000
--- a/Marlin/src/core/minmax.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-#undef MIN
-#undef MAX
-
-// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
-#define _NUM_ARGS(_0,_24_,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...) N
-#define NUM_ARGS(V...) _NUM_ARGS(0,V,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
-
-#ifdef __cplusplus
-
- #ifndef _MINMAX_H_
- #define _MINMAX_H_
-
- extern "C++" {
-
- // C++11 solution that is standards compliant. Return type is deduced automatically
- template static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
- return lhs < rhs ? lhs : rhs;
- }
- template static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
- return lhs > rhs ? lhs : rhs;
- }
- template static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
- template static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
-
- }
-
- #endif
-
-#else
-
- #define MIN_2(a,b) ((a)<(b)?(a):(b))
- #define MIN_3(a,...) MIN_2(a,MIN_2(__VA_ARGS__))
- #define MIN_4(a,...) MIN_2(a,MIN_3(__VA_ARGS__))
- #define MIN_5(a,...) MIN_2(a,MIN_4(__VA_ARGS__))
- #define MIN_6(a,...) MIN_2(a,MIN_5(__VA_ARGS__))
- #define MIN_7(a,...) MIN_2(a,MIN_6(__VA_ARGS__))
- #define MIN_8(a,...) MIN_2(a,MIN_7(__VA_ARGS__))
- #define MIN_9(a,...) MIN_2(a,MIN_8(__VA_ARGS__))
- #define MIN_10(a,...) MIN_2(a,MIN_9(__VA_ARGS__))
- #define __MIN_N(N, ...) MIN_##N(__VA_ARGS__)
- #define _MIN_N(N, ...) __MIN_N(N,__VA_ARGS__)
- #define MIN(...) _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
-
- #define MAX_2(a,b) ((a)>(b)?(a):(b))
- #define MAX_3(a,...) MAX_2(a,MAX_2(__VA_ARGS__))
- #define MAX_4(a,...) MAX_2(a,MAX_3(__VA_ARGS__))
- #define MAX_5(a,...) MAX_2(a,MAX_4(__VA_ARGS__))
- #define MAX_6(a,...) MAX_2(a,MAX_5(__VA_ARGS__))
- #define MAX_7(a,...) MAX_2(a,MAX_6(__VA_ARGS__))
- #define MAX_8(a,...) MAX_2(a,MAX_7(__VA_ARGS__))
- #define MAX_9(a,...) MAX_2(a,MAX_8(__VA_ARGS__))
- #define MAX_10(a,...) MAX_2(a,MAX_9(__VA_ARGS__))
- #define __MAX_N(N, ...) MAX_##N(__VA_ARGS__)
- #define _MAX_N(N, ...) __MAX_N(N,__VA_ARGS__)
- #define MAX(...) _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
-
-#endif
diff --git a/Marlin/src/core/multi_language.cpp b/Marlin/src/core/multi_language.cpp
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Marlin/src/core/multi_language.h b/Marlin/src/core/multi_language.h
new file mode 100644
index 0000000000..98020b1e8d
--- /dev/null
+++ b/Marlin/src/core/multi_language.h
@@ -0,0 +1,79 @@
+/********************
+ * multi_language.h *
+ ********************/
+
+/****************************************************************************
+ * Written By Marcio Teixeira 2019 - Aleph Objects, Inc. *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * To view a copy of the GNU General Public License, go to the following *
+ * location: . *
+ ****************************************************************************/
+#pragma once
+
+typedef const char Language_Str[];
+
+#if defined(LCD_LANGUAGE_5)
+ #define NUM_LANGUAGES 5
+#elif defined(LCD_LANGUAGE_4)
+ #define NUM_LANGUAGES 4
+#elif defined(LCD_LANGUAGE_3)
+ #define NUM_LANGUAGES 3
+#elif defined(LCD_LANGUAGE_2)
+ #define NUM_LANGUAGES 2
+#else
+ #define NUM_LANGUAGES 1
+#endif
+
+// Setting the unused languages equal to each other allows
+// the compiler to optimize away the conditionals
+
+#ifndef LCD_LANGUAGE_2
+ #define LCD_LANGUAGE_2 LCD_LANGUAGE
+#endif
+
+#ifndef LCD_LANGUAGE_3
+ #define LCD_LANGUAGE_3 LCD_LANGUAGE_2
+#endif
+
+#ifndef LCD_LANGUAGE_4
+ #define LCD_LANGUAGE_4 LCD_LANGUAGE_3
+#endif
+
+#ifndef LCD_LANGUAGE_5
+ #define LCD_LANGUAGE_5 LCD_LANGUAGE_4
+#endif
+
+#define _GET_LANG(LANG) Language_##LANG
+#define GET_LANG(LANG) _GET_LANG(LANG)
+
+#if NUM_LANGUAGES > 1
+ extern uint8_t lang;
+ #define GET_TEXT(MSG) ( \
+ lang == 0 ? GET_LANG(LCD_LANGUAGE)::MSG : \
+ lang == 1 ? GET_LANG(LCD_LANGUAGE_2)::MSG : \
+ lang == 2 ? GET_LANG(LCD_LANGUAGE_3)::MSG : \
+ lang == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
+ GET_LANG(LCD_LANGUAGE_5)::MSG \
+ )
+ #define MAX_LANG_CHARSIZE _MAX(GET_LANG(LCD_LANGUAGE)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_2)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_3)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_4)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_5)::CHARSIZE)
+#else
+ #define GET_TEXT(MSG) GET_LANG(LCD_LANGUAGE)::MSG
+ #define MAX_LANG_CHARSIZE GET_LANG(LCD_LANGUAGE)::CHARSIZE
+#endif
+#define GET_TEXT_F(MSG) (const __FlashStringHelper*)GET_TEXT(MSG)
+
+#define MSG_CONCAT(A,B) pgm_p_pair_t(GET_TEXT(A),GET_TEXT(B))
diff --git a/Marlin/src/core/serial.cpp b/Marlin/src/core/serial.cpp
index 5db5cc4f8e..2369c3acbf 100644
--- a/Marlin/src/core/serial.cpp
+++ b/Marlin/src/core/serial.cpp
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@
#include "serial.h"
#include "language.h"
-#include "enum.h"
uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
@@ -68,15 +67,8 @@ void print_bin(const uint16_t val) {
}
}
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z) {
+void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix/*=nullptr*/, PGM_P const suffix/*=nullptr*/) {
serialprintPGM(prefix);
- SERIAL_CHAR('(');
- SERIAL_ECHO(x);
- SERIAL_ECHOPAIR(", ", y, ", ", z);
- SERIAL_CHAR(')');
+ SERIAL_ECHOPAIR(" " MSG_X, x, " " MSG_Y, y, " " MSG_Z, z);
if (suffix) serialprintPGM(suffix); else SERIAL_EOL();
}
-
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]) {
- print_xyz(prefix, suffix, xyz[X_AXIS], xyz[Y_AXIS], xyz[Z_AXIS]);
-}
diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h
index 83543cd788..f4c2570ca7 100644
--- a/Marlin/src/core/serial.h
+++ b/Marlin/src/core/serial.h
@@ -1,9 +1,9 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,9 +21,7 @@
*/
#pragma once
-#include "../inc/MarlinConfigPre.h"
-#include "../core/minmax.h"
-#include HAL_PATH(../HAL, HAL.h)
+#include "../inc/MarlinConfig.h"
/**
* Define debug bit-masks
@@ -53,14 +51,16 @@ extern uint8_t marlin_debug_flags;
extern int8_t serial_port_index;
#define _PORT_REDIRECT(n,p) REMEMBER(n,serial_port_index,p)
#define _PORT_RESTORE(n) RESTORE(n)
- #define SERIAL_OUT(WHAT, ...) do{ \
- if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(__VA_ARGS__); \
- if ( serial_port_index) (void)MYSERIAL1.WHAT(__VA_ARGS__); \
+ #define SERIAL_OUT(WHAT, V...) do{ \
+ if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
+ if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
}while(0)
+ #define SERIAL_ASSERT(P) if(serial_port_index!=(P)){ debugger(); }
#else
#define _PORT_REDIRECT(n,p) NOOP
#define _PORT_RESTORE(n) NOOP
- #define SERIAL_OUT(WHAT, ...) (void)MYSERIAL0.WHAT(__VA_ARGS__)
+ #define SERIAL_OUT(WHAT, V...) (void)MYSERIAL0.WHAT(V)
+ #define SERIAL_ASSERT(P) NOOP
#endif
#define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
@@ -68,84 +68,113 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_CHAR(x) SERIAL_OUT(write, x)
#define SERIAL_ECHO(x) SERIAL_OUT(print, x)
-#define SERIAL_ECHO_F(...) SERIAL_OUT(print, __VA_ARGS__)
+#define SERIAL_ECHO_F(V...) SERIAL_OUT(print, V)
#define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
#define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
#define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
-#define SERIAL_PRINTF(...) SERIAL_OUT(printf, __VA_ARGS__)
+#define SERIAL_PRINTF(V...) SERIAL_OUT(printf, V)
#define SERIAL_FLUSH() SERIAL_OUT(flush)
-#if TX_BUFFER_SIZE > 0
+#ifdef __STM32F1__
+ #define SERIAL_FLUSHTX() SERIAL_OUT(flush)
+#elif TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX() SERIAL_OUT(flushTX)
#else
#define SERIAL_FLUSHTX()
#endif
// Print up to 12 pairs of values
-#define __SEP_N(N,...) _SEP_##N(__VA_ARGS__)
-#define _SEP_N(N,...) __SEP_N(N,__VA_ARGS__)
-#define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
-#define _SEP_2(PRE,V) serial_echopair_PGM(PSTR(PRE),V)
-#define _SEP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOPGM(c); }while(0)
-#define _SEP_4(a,b,...) do{ _SEP_2(a,b); _SEP_2(__VA_ARGS__); }while(0)
-#define _SEP_5(a,b,...) do{ _SEP_2(a,b); _SEP_3(__VA_ARGS__); }while(0)
-#define _SEP_6(a,b,...) do{ _SEP_2(a,b); _SEP_4(__VA_ARGS__); }while(0)
-#define _SEP_7(a,b,...) do{ _SEP_2(a,b); _SEP_5(__VA_ARGS__); }while(0)
-#define _SEP_8(a,b,...) do{ _SEP_2(a,b); _SEP_6(__VA_ARGS__); }while(0)
-#define _SEP_9(a,b,...) do{ _SEP_2(a,b); _SEP_7(__VA_ARGS__); }while(0)
-#define _SEP_10(a,b,...) do{ _SEP_2(a,b); _SEP_8(__VA_ARGS__); }while(0)
-#define _SEP_11(a,b,...) do{ _SEP_2(a,b); _SEP_9(__VA_ARGS__); }while(0)
-#define _SEP_12(a,b,...) do{ _SEP_2(a,b); _SEP_10(__VA_ARGS__); }while(0)
-#define _SEP_13(a,b,...) do{ _SEP_2(a,b); _SEP_11(__VA_ARGS__); }while(0)
-#define _SEP_14(a,b,...) do{ _SEP_2(a,b); _SEP_12(__VA_ARGS__); }while(0)
-#define _SEP_15(a,b,...) do{ _SEP_2(a,b); _SEP_13(__VA_ARGS__); }while(0)
-#define _SEP_16(a,b,...) do{ _SEP_2(a,b); _SEP_14(__VA_ARGS__); }while(0)
-#define _SEP_17(a,b,...) do{ _SEP_2(a,b); _SEP_15(__VA_ARGS__); }while(0)
-#define _SEP_18(a,b,...) do{ _SEP_2(a,b); _SEP_16(__VA_ARGS__); }while(0)
-#define _SEP_19(a,b,...) do{ _SEP_2(a,b); _SEP_17(__VA_ARGS__); }while(0)
-#define _SEP_20(a,b,...) do{ _SEP_2(a,b); _SEP_18(__VA_ARGS__); }while(0)
-#define _SEP_21(a,b,...) do{ _SEP_2(a,b); _SEP_19(__VA_ARGS__); }while(0)
-#define _SEP_22(a,b,...) do{ _SEP_2(a,b); _SEP_20(__VA_ARGS__); }while(0)
-#define _SEP_23(a,b,...) do{ _SEP_2(a,b); _SEP_21(__VA_ARGS__); }while(0)
-#define _SEP_24(a,b,...) do{ _SEP_2(a,b); _SEP_22(__VA_ARGS__); }while(0)
+#define __SEP_N(N,V...) _SEP_##N(V)
+#define _SEP_N(N,V...) __SEP_N(N,V)
+#define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
+#define _SEP_2(PRE,V) serial_echopair_PGM(PSTR(PRE),V)
+#define _SEP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOPGM(c); }while(0)
+#define _SEP_4(a,b,V...) do{ _SEP_2(a,b); _SEP_2(V); }while(0)
+#define _SEP_5(a,b,V...) do{ _SEP_2(a,b); _SEP_3(V); }while(0)
+#define _SEP_6(a,b,V...) do{ _SEP_2(a,b); _SEP_4(V); }while(0)
+#define _SEP_7(a,b,V...) do{ _SEP_2(a,b); _SEP_5(V); }while(0)
+#define _SEP_8(a,b,V...) do{ _SEP_2(a,b); _SEP_6(V); }while(0)
+#define _SEP_9(a,b,V...) do{ _SEP_2(a,b); _SEP_7(V); }while(0)
+#define _SEP_10(a,b,V...) do{ _SEP_2(a,b); _SEP_8(V); }while(0)
+#define _SEP_11(a,b,V...) do{ _SEP_2(a,b); _SEP_9(V); }while(0)
+#define _SEP_12(a,b,V...) do{ _SEP_2(a,b); _SEP_10(V); }while(0)
+#define _SEP_13(a,b,V...) do{ _SEP_2(a,b); _SEP_11(V); }while(0)
+#define _SEP_14(a,b,V...) do{ _SEP_2(a,b); _SEP_12(V); }while(0)
+#define _SEP_15(a,b,V...) do{ _SEP_2(a,b); _SEP_13(V); }while(0)
+#define _SEP_16(a,b,V...) do{ _SEP_2(a,b); _SEP_14(V); }while(0)
+#define _SEP_17(a,b,V...) do{ _SEP_2(a,b); _SEP_15(V); }while(0)
+#define _SEP_18(a,b,V...) do{ _SEP_2(a,b); _SEP_16(V); }while(0)
+#define _SEP_19(a,b,V...) do{ _SEP_2(a,b); _SEP_17(V); }while(0)
+#define _SEP_20(a,b,V...) do{ _SEP_2(a,b); _SEP_18(V); }while(0)
+#define _SEP_21(a,b,V...) do{ _SEP_2(a,b); _SEP_19(V); }while(0)
+#define _SEP_22(a,b,V...) do{ _SEP_2(a,b); _SEP_20(V); }while(0)
+#define _SEP_23(a,b,V...) do{ _SEP_2(a,b); _SEP_21(V); }while(0)
+#define _SEP_24(a,b,V...) do{ _SEP_2(a,b); _SEP_22(V); }while(0)
-#define SERIAL_ECHOPAIR(...) _SEP_N(NUM_ARGS(__VA_ARGS__),__VA_ARGS__)
+#define SERIAL_ECHOPAIR(V...) _SEP_N(NUM_ARGS(V),V)
// Print up to 12 pairs of values followed by newline
-#define __SELP_N(N,...) _SELP_##N(__VA_ARGS__)
-#define _SELP_N(N,...) __SELP_N(N,__VA_ARGS__)
-#define _SELP_1(PRE) SERIAL_ECHOLNPGM(PRE)
-#define _SELP_2(PRE,V) do{ serial_echopair_PGM(PSTR(PRE),V); SERIAL_EOL(); }while(0)
-#define _SELP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOLNPGM(c); }while(0)
-#define _SELP_4(a,b,...) do{ _SEP_2(a,b); _SELP_2(__VA_ARGS__); }while(0)
-#define _SELP_5(a,b,...) do{ _SEP_2(a,b); _SELP_3(__VA_ARGS__); }while(0)
-#define _SELP_6(a,b,...) do{ _SEP_2(a,b); _SELP_4(__VA_ARGS__); }while(0)
-#define _SELP_7(a,b,...) do{ _SEP_2(a,b); _SELP_5(__VA_ARGS__); }while(0)
-#define _SELP_8(a,b,...) do{ _SEP_2(a,b); _SELP_6(__VA_ARGS__); }while(0)
-#define _SELP_9(a,b,...) do{ _SEP_2(a,b); _SELP_7(__VA_ARGS__); }while(0)
-#define _SELP_10(a,b,...) do{ _SEP_2(a,b); _SELP_8(__VA_ARGS__); }while(0)
-#define _SELP_11(a,b,...) do{ _SEP_2(a,b); _SELP_9(__VA_ARGS__); }while(0)
-#define _SELP_12(a,b,...) do{ _SEP_2(a,b); _SELP_10(__VA_ARGS__); }while(0)
-#define _SELP_13(a,b,...) do{ _SEP_2(a,b); _SELP_11(__VA_ARGS__); }while(0)
-#define _SELP_14(a,b,...) do{ _SEP_2(a,b); _SELP_12(__VA_ARGS__); }while(0)
-#define _SELP_15(a,b,...) do{ _SEP_2(a,b); _SELP_13(__VA_ARGS__); }while(0)
-#define _SELP_16(a,b,...) do{ _SEP_2(a,b); _SELP_14(__VA_ARGS__); }while(0)
-#define _SELP_17(a,b,...) do{ _SEP_2(a,b); _SELP_15(__VA_ARGS__); }while(0)
-#define _SELP_18(a,b,...) do{ _SEP_2(a,b); _SELP_16(__VA_ARGS__); }while(0)
-#define _SELP_19(a,b,...) do{ _SEP_2(a,b); _SELP_17(__VA_ARGS__); }while(0)
-#define _SELP_20(a,b,...) do{ _SEP_2(a,b); _SELP_18(__VA_ARGS__); }while(0)
-#define _SELP_21(a,b,...) do{ _SEP_2(a,b); _SELP_19(__VA_ARGS__); }while(0)
-#define _SELP_22(a,b,...) do{ _SEP_2(a,b); _SELP_20(__VA_ARGS__); }while(0)
-#define _SELP_23(a,b,...) do{ _SEP_2(a,b); _SELP_21(__VA_ARGS__); }while(0)
-#define _SELP_24(a,b,...) do{ _SEP_2(a,b); _SELP_22(__VA_ARGS__); }while(0)
+#define __SELP_N(N,V...) _SELP_##N(V)
+#define _SELP_N(N,V...) __SELP_N(N,V)
+#define _SELP_1(PRE) SERIAL_ECHOLNPGM(PRE)
+#define _SELP_2(PRE,V) do{ serial_echopair_PGM(PSTR(PRE),V); SERIAL_EOL(); }while(0)
+#define _SELP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOLNPGM(c); }while(0)
+#define _SELP_4(a,b,V...) do{ _SEP_2(a,b); _SELP_2(V); }while(0)
+#define _SELP_5(a,b,V...) do{ _SEP_2(a,b); _SELP_3(V); }while(0)
+#define _SELP_6(a,b,V...) do{ _SEP_2(a,b); _SELP_4(V); }while(0)
+#define _SELP_7(a,b,V...) do{ _SEP_2(a,b); _SELP_5(V); }while(0)
+#define _SELP_8(a,b,V...) do{ _SEP_2(a,b); _SELP_6(V); }while(0)
+#define _SELP_9(a,b,V...) do{ _SEP_2(a,b); _SELP_7(V); }while(0)
+#define _SELP_10(a,b,V...) do{ _SEP_2(a,b); _SELP_8(V); }while(0)
+#define _SELP_11(a,b,V...) do{ _SEP_2(a,b); _SELP_9(V); }while(0)
+#define _SELP_12(a,b,V...) do{ _SEP_2(a,b); _SELP_10(V); }while(0)
+#define _SELP_13(a,b,V...) do{ _SEP_2(a,b); _SELP_11(V); }while(0)
+#define _SELP_14(a,b,V...) do{ _SEP_2(a,b); _SELP_12(V); }while(0)
+#define _SELP_15(a,b,V...) do{ _SEP_2(a,b); _SELP_13(V); }while(0)
+#define _SELP_16(a,b,V...) do{ _SEP_2(a,b); _SELP_14(V); }while(0)
+#define _SELP_17(a,b,V...) do{ _SEP_2(a,b); _SELP_15(V); }while(0)
+#define _SELP_18(a,b,V...) do{ _SEP_2(a,b); _SELP_16(V); }while(0)
+#define _SELP_19(a,b,V...) do{ _SEP_2(a,b); _SELP_17(V); }while(0)
+#define _SELP_20(a,b,V...) do{ _SEP_2(a,b); _SELP_18(V); }while(0)
+#define _SELP_21(a,b,V...) do{ _SEP_2(a,b); _SELP_19(V); }while(0)
+#define _SELP_22(a,b,V...) do{ _SEP_2(a,b); _SELP_20(V); }while(0)
+#define _SELP_23(a,b,V...) do{ _SEP_2(a,b); _SELP_21(V); }while(0)
+#define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0) // Use up two, pass the rest up
-#define SERIAL_ECHOLNPAIR(...) _SELP_N(NUM_ARGS(__VA_ARGS__),__VA_ARGS__)
+#define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
+
+// Print up to 20 comma-separated pairs of values
+#define __SLST_N(N,V...) _SLST_##N(V)
+#define _SLST_N(N,V...) __SLST_N(N,V)
+#define _SLST_1(a) SERIAL_ECHO(a)
+#define _SLST_2(a,b) do{ SERIAL_ECHO(a); SERIAL_ECHOPAIR(", ",b); }while(0)
+#define _SLST_3(a,b,c) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_1(c); }while(0)
+#define _SLST_4(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_2(V); }while(0)
+#define _SLST_5(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_3(V); }while(0)
+#define _SLST_6(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_4(V); }while(0)
+#define _SLST_7(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_5(V); }while(0)
+#define _SLST_8(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_6(V); }while(0)
+#define _SLST_9(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_7(V); }while(0)
+#define _SLST_10(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_8(V); }while(0)
+#define _SLST_11(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_9(V); }while(0)
+#define _SLST_12(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_10(V); }while(0)
+#define _SLST_13(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_11(V); }while(0)
+#define _SLST_14(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_12(V); }while(0)
+#define _SLST_15(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_13(V); }while(0)
+#define _SLST_16(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_14(V); }while(0)
+#define _SLST_17(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_15(V); }while(0)
+#define _SLST_18(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_16(V); }while(0)
+#define _SLST_19(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_17(V); }while(0)
+#define _SLST_20(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_18(V); }while(0) // Use up two, pass the rest up
+
+#define SERIAL_ECHOLIST(pre,V...) do{ SERIAL_ECHOPGM(pre); _SLST_N(NUM_ARGS(V),V); }while(0)
+#define SERIAL_ECHOLIST_N(N,V...) _SLST_N(N,LIST_N(N,V))
#define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
#define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
-#define SERIAL_ECHOPAIR_F(pre, ...) do{ SERIAL_ECHO(pre); SERIAL_ECHO_F(__VA_ARGS__); }while(0)
-#define SERIAL_ECHOLNPAIR_F(...) do{ SERIAL_ECHOPAIR_F(__VA_ARGS__); SERIAL_EOL(); }while(0)
+#define SERIAL_ECHOPAIR_F(S,V...) do{ SERIAL_ECHOPGM(S); SERIAL_ECHO_F(V); }while(0)
+#define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
#define SERIAL_ECHO_START() serial_echo_start()
#define SERIAL_ERROR_START() serial_error_start()
@@ -156,6 +185,8 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_ECHO_SP(C) serial_spaces(C)
+#define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
+
//
// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
//
@@ -182,7 +213,11 @@ void serial_spaces(uint8_t count);
void print_bin(const uint16_t val);
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z);
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]);
-#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); } while(0)
-#define SERIAL_XYZ(PREFIX,...) do { print_xyz(PSTR(PREFIX), nullptr, __VA_ARGS__); } while(0)
+void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr);
+
+inline void print_xyz(const xyz_pos_t &xyz, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr) {
+ print_xyz(xyz.x, xyz.y, xyz.z, prefix, suffix);
+}
+
+#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(VAR, PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n")); }while(0)
+#define SERIAL_XYZ(PREFIX,V...) do { print_xyz(V, PSTR(PREFIX), nullptr); }while(0)
diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h
new file mode 100644
index 0000000000..567b35c8b9
--- /dev/null
+++ b/Marlin/src/core/types.h
@@ -0,0 +1,486 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+#include
+
+#include "millis_t.h"
+
+//
+// Enumerated axis indices
+//
+// - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
+// - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
+// - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
+//
+enum AxisEnum : uint8_t {
+ X_AXIS = 0, A_AXIS = 0,
+ Y_AXIS = 1, B_AXIS = 1,
+ Z_AXIS = 2, C_AXIS = 2,
+ E_AXIS = 3,
+ X_HEAD = 4, Y_HEAD = 5, Z_HEAD = 6,
+ E0_AXIS = 3,
+ E1_AXIS = 4,
+ E2_AXIS = 5,
+ E3_AXIS = 6,
+ E4_AXIS = 7,
+ E5_AXIS = 8,
+ ALL_AXES = 0xFE, NO_AXIS = 0xFF
+};
+
+//
+// Loop over XYZE axes
+//
+
+#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
+#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
+#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
+#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
+
+#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
+#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
+#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
+#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
+#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
+#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
+
+//
+// Conditional type assignment magic. For example...
+//
+// typename IF<(MYOPT==12), int, float>::type myvar;
+//
+template
+struct IF { typedef R type; };
+template
+struct IF { typedef L type; };
+
+//
+// feedRate_t is just a humble float
+//
+typedef float feedRate_t;
+
+// Conversion macros
+#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f)
+#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f)
+#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage)
+
+//
+// Coordinates structures for XY, XYZ, XYZE...
+//
+
+// Helpers
+#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f)
+#define _ABS(N) ((N) < 0 ? -(N) : (N))
+#define _LS(N) (N = (T)(uint32_t(N) << v))
+#define _RS(N) (N = (T)(uint32_t(N) >> v))
+#define FI FORCE_INLINE
+
+// Forward declarations
+template struct XYval;
+template struct XYZval;
+template struct XYZEval;
+
+typedef struct XYval xy_bool_t;
+typedef struct XYZval xyz_bool_t;
+typedef struct XYZEval xyze_bool_t;
+
+typedef struct XYval xy_char_t;
+typedef struct XYZval xyz_char_t;
+typedef struct XYZEval xyze_char_t;
+
+typedef struct XYval xy_uchar_t;
+typedef struct XYZval xyz_uchar_t;
+typedef struct XYZEval xyze_uchar_t;
+
+typedef struct XYval xy_int8_t;
+typedef struct XYZval xyz_int8_t;
+typedef struct XYZEval xyze_int8_t;
+
+typedef struct XYval xy_uint8_t;
+typedef struct XYZval xyz_uint8_t;
+typedef struct XYZEval xyze_uint8_t;
+
+typedef struct XYval xy_int_t;
+typedef struct XYZval xyz_int_t;
+typedef struct XYZEval xyze_int_t;
+
+typedef struct XYval xy_uint_t;
+typedef struct XYZval xyz_uint_t;
+typedef struct XYZEval xyze_uint_t;
+
+typedef struct XYval xy_long_t;
+typedef struct XYZval xyz_long_t;
+typedef struct XYZEval xyze_long_t;
+
+typedef struct XYval