diff --git a/.circleci/config.yml b/.circleci/config.yml
index 73fe1f0a373e..cb8c31b22b52 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -54,10 +54,9 @@ jobs:
generate_version ./Marlin/src/inc
cat ./Marlin/src/inc/_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 STM32F103R"
restore_configs
- echo use_example_configs STM32F10
- use_example_configs STM32F10
+ echo use_example_configs STM32/STM32F103R
+ use_example_configs STM32/STM32F103R
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 000000000000..946acca2d7f4
--- /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 58b4894f6797..ecfb36f0d580 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
/**
@@ -905,19 +1060,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
*
@@ -984,29 +1147,106 @@
#define STATUS_HOTEND_INVERTED // Show solid nozzle bitmaps when heating (Requires STATUS_HOTEND_ANIM)
#define STATUS_HOTEND_ANIM // Use a second bitmap to indicate hotend heating
#define STATUS_BED_ANIM // Use a second bitmap to indicate bed heating
+ #define STATUS_CHAMBER_ANIM // Use a second bitmap to indicate chamber heating
//#define STATUS_ALT_BED_BITMAP // Use the alternative bed bitmap
//#define STATUS_ALT_FAN_BITMAP // Use the alternative fan bitmap
//#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
//#define MARLIN_BRICKOUT
//#define MARLIN_INVADERS
//#define MARLIN_SNAKE
+ //#define GAMES_EASTER_EGG // Add extra blank lines above the "Games" sub-menu
#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
+
+ // Enable UTF8 rendering capabilities.
+ //#define TOUCH_UI_USE_UTF8
+ #if ENABLED(TOUCH_UI_USE_UTF8)
+ #define TOUCH_UI_UTF8_WESTERN_CHARSET
+ #endif
+
+ // When labels do not fit buttons, use smaller font
+ #define TOUCH_UI_FIT_TEXT
+
+ // Runtime language selection (otherwise LCD_LANGUAGE)
+ //#define TOUCH_UI_LANGUAGE_MENU
+
+ // Use a numeric passcode for "Screen lock" keypad.
+ // (recommended for smaller displays)
+ //#define TOUCH_UI_PASSCODE
+#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
-// The hardware watchdog should reset the microcontroller disabling all outputs,
-// in case the firmware gets stuck and doesn't do temperature regulation.
+/**
+ * The watchdog hardware timer will do a reset and disable all outputs
+ * if the firmware gets too overloaded to read the temperature sensors.
+ *
+ * If you find that watchdog reboot causes your AVR board to hang forever,
+ * enable WATCHDOG_RESET_MANUAL to use a custom timer instead of WDTO.
+ * NOTE: This method is less reliable as it can only catch hangups while
+ * interrupts are enabled.
+ */
#define USE_WATCHDOG
-
#if ENABLED(USE_WATCHDOG)
- // If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on.
- // The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset.
- // However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled.
//#define WATCHDOG_RESET_MANUAL
#endif
@@ -1030,7 +1270,7 @@
#if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING)
#define DOUBLECLICK_MAX_INTERVAL 1250 // Maximum interval between clicks, in milliseconds.
// Note: Extra time may be added to mitigate controller latency.
- #define BABYSTEP_ALWAYS_AVAILABLE // Allow babystepping at all times (not just during movement).
+ //#define BABYSTEP_ALWAYS_AVAILABLE // Allow babystepping at all times (not just during movement).
//#define MOVE_Z_WHEN_IDLE // Jump to the move Z menu on doubleclick when printer is idle.
#if ENABLED(MOVE_Z_WHEN_IDLE)
#define MOVE_Z_IDLE_MULTIPLICATOR 1 // Multiply 1mm by this factor for the move step size.
@@ -1106,7 +1346,7 @@
//
#define ARC_SUPPORT // Disable this feature to save ~3226 bytes
#if ENABLED(ARC_SUPPORT)
- #define MM_PER_ARC_SEGMENT .15 // Length of each arc segment
+ #define MM_PER_ARC_SEGMENT .3 // Length of each arc segment
#define MIN_ARC_SEGMENTS 24 // Minimum number of segments in a complete circle
#define N_ARC_CORRECTION 25 // Number of interpolated segments between corrections
//#define ARC_P_CIRCLES // Enable the 'P' parameter to specify complete circles
@@ -1133,7 +1373,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
@@ -1145,12 +1385,14 @@
*
* 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)
* 0 : Smallest possible width the MCU can produce, compatible with TMC2xxx drivers
- * 1 : Minimum for A4988, A5984, and LV8729 stepper drivers
+ * 0 : Minimum 500ns for LV8729, adjusted in stepper.h
+ * 1 : Minimum for A4988 and A5984 stepper drivers
* 2 : Minimum for DRV8825 stepper drivers
* 3 : Minimum for TB6600 stepper drivers
* 30 : Minimum for TB6560 stepper drivers
@@ -1165,8 +1407,8 @@
* 500000 : Maximum for A4988 stepper driver
* 400000 : Maximum for TMC2xxx stepper drivers
* 250000 : Maximum for DRV8825 stepper driver
+ * 200000 : Maximum for LV8729 stepper driver
* 150000 : Maximum for TB6600 stepper driver
- * 130000 : Maximum for LV8729 stepper driver
* 15000 : Maximum for TB6560 stepper driver
*
* Override the default value based on the driver type set in Configuration.h.
@@ -1219,6 +1461,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.
@@ -1276,19 +1521,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
- #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 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 // (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
@@ -1301,6 +1546,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
@@ -1358,6 +1604,7 @@
// Filament can be extruded repeatedly from the Filament Change menu
// until extrusion is consistent, and to purge old filament.
#define ADVANCED_PAUSE_RESUME_PRIME 0 // (mm) Extra distance to prime nozzle after returning from park.
+ //#define ADVANCED_PAUSE_FANS_PAUSE // Turn off print-cooling fans while the machine is paused.
// Filament Unload does a Retract, Delay, and Purge first:
#define FILAMENT_UNLOAD_RETRACT_LENGTH 13 // (mm) Unload initial retract length.
@@ -1492,78 +1739,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 0 // 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 0
#endif
#if AXIS_IS_TMC(Y)
#define Y_CURRENT 800
#define Y_MICROSTEPS 16
#define Y_RSENSE 0.11
+ #define Y_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(Y2)
#define Y2_CURRENT 800
#define Y2_MICROSTEPS 16
#define Y2_RSENSE 0.11
+ #define Y2_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(Z)
#define Z_CURRENT 800
#define Z_MICROSTEPS 16
#define Z_RSENSE 0.11
+ #define Z_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(Z2)
#define Z2_CURRENT 800
#define Z2_MICROSTEPS 16
#define Z2_RSENSE 0.11
+ #define Z2_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(Z3)
#define Z3_CURRENT 800
#define Z3_MICROSTEPS 16
#define Z3_RSENSE 0.11
+ #define Z3_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(E0)
#define E0_CURRENT 800
#define E0_MICROSTEPS 16
#define E0_RSENSE 0.11
+ #define E0_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(E1)
#define E1_CURRENT 800
#define E1_MICROSTEPS 16
#define E1_RSENSE 0.11
+ #define E1_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(E2)
#define E2_CURRENT 800
#define E2_MICROSTEPS 16
#define E2_RSENSE 0.11
+ #define E2_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(E3)
#define E3_CURRENT 800
#define E3_MICROSTEPS 16
#define E3_RSENSE 0.11
+ #define E3_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(E4)
#define E4_CURRENT 800
#define E4_MICROSTEPS 16
#define E4_RSENSE 0.11
+ #define E4_CHAIN_POS 0
#endif
#if AXIS_IS_TMC(E5)
#define E5_CURRENT 800
#define E5_MICROSTEPS 16
#define E5_RSENSE 0.11
+ #define E5_CHAIN_POS 0
#endif
/**
@@ -1585,7 +1845,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.
@@ -1595,6 +1854,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
*
@@ -1604,7 +1889,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.
*/
@@ -1630,7 +1915,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:
@@ -1648,7 +1933,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.
@@ -1671,19 +1956,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.
@@ -1691,14 +1986,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.
@@ -1945,36 +2250,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_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
-
- /**
- * 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
+//#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
+
+ #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)
+ */
+ #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 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
/**
@@ -2028,6 +2350,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
*/
@@ -2082,6 +2411,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
*
@@ -2139,10 +2475,6 @@
//#define HOST_PROMPT_SUPPORT
#endif
-//===========================================================================
-//====================== I2C Position Encoder Settings ======================
-//===========================================================================
-
/**
* I2C position encoders for closed loop control.
* Developed by Chris Barr at Aus3D.
@@ -2205,7 +2537,7 @@
//#define I2CPE_ERR_THRESH_ABORT 100.0 // Threshold size for error (in mm) error on any given
// axis after which the printer will abort. Comment out to
- // disable abort behaviour.
+ // disable abort behavior.
#define I2CPE_TIME_TRUSTED 10000 // After an encoder fault, there must be no further fault
// for this amount of time (in ms) before the encoder
@@ -2223,6 +2555,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
*
@@ -2241,6 +2589,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
@@ -2265,7 +2614,7 @@
//#define NANODLP_Z_SYNC
#if ENABLED(NANODLP_Z_SYNC)
//#define NANODLP_ALL_AXIS // Enables "Z_move_comp" output on any axis move.
- // Default behaviour is limited to Z axis only.
+ // Default behavior is limited to Z axis only.
#endif
/**
diff --git a/Marlin/Makefile b/Marlin/Makefile
index a62bccd42073..d765fc19da99 100644
--- a/Marlin/Makefile
+++ b/Marlin/Makefile
@@ -122,180 +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),801)
+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),442)
+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),73)
+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),76)
+else ifeq ($(HARDWARE_MOTHERBOARD),1317)
# Geeetech GT2560 Rev B for A20(M/D)
-else ifeq ($(HARDWARE_MOTHERBOARD),86)
+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
#
@@ -303,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
@@ -348,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
@@ -401,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
@@ -587,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)
@@ -658,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}
diff --git a/Marlin/Marlin.ino b/Marlin/Marlin.ino
index 842b2a14b923..ae5bca1dfed1 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/src/HAL/HAL_STM32F4/watchdog_STM32F4.h b/Marlin/src/HAL/HAL.h
similarity index 79%
rename from Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h
rename to Marlin/src/HAL/HAL.h
index 4076c2b03a9f..f3946902c8d5 100644
--- a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h
+++ b/Marlin/src/HAL/HAL.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,7 +21,6 @@
*/
#pragma once
-extern IWDG_HandleTypeDef hiwdg;
+#include "platforms.h"
-void watchdog_init();
-void watchdog_reset();
+#include HAL_PATH(.,HAL.h)
diff --git a/Marlin/src/HAL/HAL_AVR/HAL.cpp b/Marlin/src/HAL/HAL_AVR/HAL.cpp
index 2bfbccdf2dd1..4a10f73dcfab 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL.cpp
@@ -1,71 +1,56 @@
-/* **************************************************************************
-
- Marlin 3D Printer Firmware
- 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
- 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 .
-
-****************************************************************************/
+/**
+ * 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 __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 b5b63dc5d146..9c34dc1f543b 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,34 +18,29 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include
-
-#include
-
-#include
-#include
-#include
-#include
-#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
@@ -60,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;
@@ -105,20 +101,25 @@ typedef int8_t pin_t;
#endif
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
+
+void HAL_init();
-//void cli(void);
+//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
@@ -198,9 +199,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 */ \
@@ -267,13 +268,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 */ \
@@ -333,7 +334,7 @@ void TIMER0_COMPB_vect (void) { \
: \
); \
} \
-void TIMER0_COMPB_vect_bottom(void)
+void TIMER0_COMPB_vect_bottom()
// ADC
#ifdef DIDR2
@@ -342,7 +343,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 79%
rename from Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
index a3fe161251ab..68e21aae537f 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)
-
- //------------------------------------------------------------------------------
+ // ------------------------
// 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,32 @@ 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
+
+ // ------------------------
+ // Software SPI
+ // ------------------------
- /** nop to tune soft SPI timing */
+ // nop to tune soft SPI timing
#define nop asm volatile ("\tnop\n")
- /** Set SPI rate */
+ // Set SPI rate
void spiInit(uint8_t spiRate) {
UNUSED(spiRate); // nothing to do
}
- /** 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) {
UNUSED(spiBeginTransaction); // nothing to do
}
- /** 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 +219,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 +246,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
+#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 9bc224bd2b78..3502aa6b0c36 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 5ada120c6da4..7560d880e314 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 68bfdc16a01b..000000000000
--- 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 95%
rename from Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/Servo.cpp
index e3d2194bf7f5..58e220cbafbe 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
@@ -58,8 +58,8 @@
#if HAS_SERVOS
#include
-#include
+#include "../shared/Marduino.h"
#include "../shared/servo.h"
#include "../shared/servo_private.h"
@@ -95,29 +95,29 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform
// Interrupt handlers for Arduino
- #if ENABLED(_useTimer1)
+ #ifdef _useTimer1
SIGNAL(TIMER1_COMPA_vect) { handle_interrupts(_timer1, &TCNT1, &OCR1A); }
#endif
- #if ENABLED(_useTimer3)
+ #ifdef _useTimer3
SIGNAL(TIMER3_COMPA_vect) { handle_interrupts(_timer3, &TCNT3, &OCR3A); }
#endif
- #if ENABLED(_useTimer4)
+ #ifdef _useTimer4
SIGNAL(TIMER4_COMPA_vect) { handle_interrupts(_timer4, &TCNT4, &OCR4A); }
#endif
- #if ENABLED(_useTimer5)
+ #ifdef _useTimer5
SIGNAL(TIMER5_COMPA_vect) { handle_interrupts(_timer5, &TCNT5, &OCR5A); }
#endif
#else // WIRING
// Interrupt handlers for Wiring
- #if ENABLED(_useTimer1)
+ #ifdef _useTimer1
void Timer1Service() { handle_interrupts(_timer1, &TCNT1, &OCR1A); }
#endif
- #if ENABLED(_useTimer3)
+ #ifdef _useTimer3
void Timer3Service() { handle_interrupts(_timer3, &TCNT3, &OCR3A); }
#endif
@@ -126,7 +126,7 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
/****************** end of static functions ******************************/
void initISR(timer16_Sequence_t timer) {
- #if ENABLED(_useTimer1)
+ #ifdef _useTimer1
if (timer == _timer1) {
TCCR1A = 0; // normal counting mode
TCCR1B = _BV(CS11); // set prescaler of 8
@@ -145,7 +145,7 @@ void initISR(timer16_Sequence_t timer) {
}
#endif
- #if ENABLED(_useTimer3)
+ #ifdef _useTimer3
if (timer == _timer3) {
TCCR3A = 0; // normal counting mode
TCCR3B = _BV(CS31); // set prescaler of 8
@@ -163,7 +163,7 @@ void initISR(timer16_Sequence_t timer) {
}
#endif
- #if ENABLED(_useTimer4)
+ #ifdef _useTimer4
if (timer == _timer4) {
TCCR4A = 0; // normal counting mode
TCCR4B = _BV(CS41); // set prescaler of 8
@@ -173,7 +173,7 @@ void initISR(timer16_Sequence_t timer) {
}
#endif
- #if ENABLED(_useTimer5)
+ #ifdef _useTimer5
if (timer == _timer5) {
TCCR5A = 0; // normal counting mode
TCCR5B = _BV(CS51); // set prescaler of 8
diff --git a/Marlin/src/HAL/HAL_AVR/ServoTimers.h b/Marlin/src/HAL/HAL_AVR/ServoTimers.h
index b63b69c82e96..4991caefe6fd 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__)
@@ -75,16 +75,16 @@
#endif
typedef enum {
- #if ENABLED(_useTimer1)
+ #ifdef _useTimer1
_timer1,
#endif
- #if ENABLED(_useTimer3)
+ #ifdef _useTimer3
_timer3,
#endif
- #if ENABLED(_useTimer4)
+ #ifdef _useTimer4
_timer4,
#endif
- #if ENABLED(_useTimer5)
+ #ifdef _useTimer5
_timer5,
#endif
_Nbr_16timers
diff --git a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
index c06670394221..b80fee610d59 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)
@@ -54,7 +54,7 @@ void endstop_ISR(void) { endstops.update(); }
#undef digitalPinToPCICR
#define digitalPinToPCICR(p) ( WITHIN(p, 10, 15) || \
WITHIN(p, 50, 53) || \
- WITHIN(p, 62, 69) ? &PCICR : (uint8_t*)0 )
+ WITHIN(p, 62, 69) ? &PCICR : nullptr )
#undef digitalPinToPCICRbit
#define digitalPinToPCICRbit(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
WITHIN(p, 14, 15) ? 1 : \
@@ -64,7 +64,7 @@ void endstop_ISR(void) { endstops.update(); }
#define digitalPinToPCMSK(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
WITHIN(p, 14, 15) ? &PCMSK1 : \
WITHIN(p, 62, 69) ? &PCMSK2 : \
- (uint8_t *)0 )
+ nullptr )
#undef digitalPinToPCMSKbit
#define digitalPinToPCMSKbit(p) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
(p) == 14 || (p) == 51 ? 2 : \
@@ -78,9 +78,11 @@ void endstop_ISR(void) { endstops.update(); }
// Install Pin change interrupt for a pin. Can be called multiple times.
void pciSetup(const int8_t pin) {
- SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin)); // enable pin
- SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
- SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
+ if (digitalPinToPCMSK(pin) != nullptr) {
+ SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin)); // enable pin
+ SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
+ SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
+ }
}
// Handlers for pin change interrupts
@@ -100,154 +102,125 @@ 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) != NULL, "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) != NULL, "X_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "Y_MAX_PIN is not interrupt-capable");
+ 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) != NULL, "Y_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "Z_MAX_PIN is not interrupt-capable");
+ 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) != NULL, "Z_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "X2_MAX_PIN is not interrupt-capable");
+ 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) != NULL, "X2_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "Y2_MAX_PIN is not interrupt-capable");
+ 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) != NULL, "Y2_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "Z2_MAX_PIN is not interrupt-capable");
+ 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) != NULL, "Z2_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "Z3_MAX_PIN is not interrupt-capable");
+ 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) != NULL, "Z3_MIN_PIN is not interrupt-capable");
+ 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) != NULL, "Z_MIN_PROBE_PIN is not interrupt-capable");
+ static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN), "Z_MIN_PROBE_PIN is not interrupt-capable");
pciSetup(Z_MIN_PROBE_PIN);
#endif
#endif
diff --git a/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp b/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
index b38a4acea228..282b70de7131 100644
--- a/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
+++ b/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
@@ -1,250 +1,282 @@
-#ifdef __AVR__
-
-#include "../../inc/MarlinConfigPre.h"
/**
- * get_pwm_timer
- * Grabs timer information and registers of the provided pin
- * returns Timer struct containing this information
- * Used by set_pwm_frequency, set_pwm_duty
+ * 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 __AVR__
+
+#include "../../inc/MarlinConfigPre.h"
#if ENABLED(FAST_PWM_FAN)
+
#include "HAL.h"
- struct Timer {
- volatile uint8_t* TCCRnQ[3]; // max 3 TCCR registers per timer
- volatile uint16_t* OCRnQ[3]; // max 3 OCR registers per timer
- volatile uint16_t* ICRn; // max 1 ICR register per timer
- uint8_t n; // the timer number [0->5]
- uint8_t q; // the timer output [0->2] (A->C)
- };
+struct Timer {
+ volatile uint8_t* TCCRnQ[3]; // max 3 TCCR registers per timer
+ volatile uint16_t* OCRnQ[3]; // max 3 OCR registers per timer
+ volatile uint16_t* ICRn; // max 1 ICR register per timer
+ uint8_t n; // the timer number [0->5]
+ uint8_t q; // the timer output [0->2] (A->C)
+};
- Timer get_pwm_timer(pin_t pin) {
- uint8_t q = 0;
- switch (digitalPinToTimer(pin)) {
- // Protect reserved timers (TIMER0 & TIMER1)
- #ifdef TCCR0A
- #if !AVR_AT90USB1286_FAMILY
- case TIMER0A:
- #endif
- case TIMER0B:
- #endif
- #ifdef TCCR1A
- case TIMER1A: case TIMER1B:
+/**
+ * get_pwm_timer
+ * Get the timer information and register of the provided pin.
+ * Return a Timer struct containing this information.
+ * Used by set_pwm_frequency, set_pwm_duty
+ */
+Timer get_pwm_timer(const pin_t pin) {
+ uint8_t q = 0;
+ switch (digitalPinToTimer(pin)) {
+ // Protect reserved timers (TIMER0 & TIMER1)
+ #ifdef TCCR0A
+ #if !AVR_AT90USB1286_FAMILY
+ case TIMER0A:
#endif
- break;
- #if defined(TCCR2) || defined(TCCR2A)
- #ifdef TCCR2
- case TIMER2: {
+ case TIMER0B:
+ #endif
+ #ifdef TCCR1A
+ case TIMER1A: case TIMER1B:
+ #endif
+ break;
+ #if defined(TCCR2) || defined(TCCR2A)
+ #ifdef TCCR2
+ case TIMER2: {
+ Timer timer = {
+ /*TCCRnQ*/ { &TCCR2, nullptr, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2, nullptr, nullptr },
+ /*ICRn*/ nullptr,
+ /*n, q*/ 2, 0
+ };
+ }
+ #elif defined(TCCR2A)
+ #if ENABLED(USE_OCR2A_AS_TOP)
+ case TIMER2A: break; // protect TIMER2A
+ case TIMER2B: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2, NULL, NULL},
- /*OCRnQ*/ { (uint16_t*)&OCR2, NULL, NULL},
- /*ICRn*/ NULL,
- /*n, q*/ 2, 0
+ /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
+ /*ICRn*/ nullptr,
+ /*n, q*/ 2, 1
};
+ return timer;
+ }
+ #else
+ case TIMER2B: ++q;
+ case TIMER2A: {
+ Timer timer = {
+ /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
+ /*ICRn*/ nullptr,
+ 2, q
+ };
+ return timer;
}
- #elif defined TCCR2A
- #if ENABLED(USE_OCR2A_AS_TOP)
- case TIMER2A: break; // protect TIMER2A
- case TIMER2B: {
- Timer timer = {
- /*TCCRnQ*/ { &TCCR2A, &TCCR2B, NULL},
- /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, NULL},
- /*ICRn*/ NULL,
- /*n, q*/ 2, 1
- };
- return timer;
- }
- #else
- case TIMER2B: ++q;
- case TIMER2A: {
- Timer timer = {
- /*TCCRnQ*/ { &TCCR2A, &TCCR2B, NULL},
- /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, NULL},
- /*ICRn*/ NULL,
- 2, q
- };
- return timer;
- }
- #endif
#endif
#endif
- #ifdef TCCR3A
- case TIMER3C: ++q;
- case TIMER3B: ++q;
- case TIMER3A: {
- Timer timer = {
- /*TCCRnQ*/ { &TCCR3A, &TCCR3B, &TCCR3C},
- /*OCRnQ*/ { &OCR3A, &OCR3B, &OCR3C},
- /*ICRn*/ &ICR3,
- /*n, q*/ 3, q
- };
- return timer;
- }
- #endif
- #ifdef TCCR4A
- case TIMER4C: ++q;
- case TIMER4B: ++q;
- case TIMER4A: {
- Timer timer = {
- /*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C},
- /*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C},
- /*ICRn*/ &ICR4,
- /*n, q*/ 4, q
- };
- return timer;
- }
- #endif
- #ifdef TCCR5A
- case TIMER5C: ++q;
- case TIMER5B: ++q;
- case TIMER5A: {
- Timer timer = {
- /*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C},
- /*OCRnQ*/ { &OCR5A, &OCR5B, &OCR5C },
- /*ICRn*/ &ICR5,
- /*n, q*/ 5, q
- };
- return timer;
- }
- #endif
- }
- Timer timer = {
- /*TCCRnQ*/ { NULL, NULL, NULL},
- /*OCRnQ*/ { NULL, NULL, NULL},
- /*ICRn*/ NULL,
- 0, 0
- };
- return timer;
+ #endif
+ #ifdef OCR3C
+ case TIMER3C: ++q;
+ case TIMER3B: ++q;
+ case TIMER3A: {
+ Timer timer = {
+ /*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
+ };
+ return timer;
+ }
+ #endif
+ #ifdef TCCR4A
+ case TIMER4C: ++q;
+ case TIMER4B: ++q;
+ case TIMER4A: {
+ Timer timer = {
+ /*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C },
+ /*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C },
+ /*ICRn*/ &ICR4,
+ /*n, q*/ 4, q
+ };
+ return timer;
+ }
+ #endif
+ #ifdef TCCR5A
+ case TIMER5C: ++q;
+ case TIMER5B: ++q;
+ case TIMER5A: {
+ Timer timer = {
+ /*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C },
+ /*OCRnQ*/ { &OCR5A, &OCR5B, &OCR5C },
+ /*ICRn*/ &ICR5,
+ /*n, q*/ 5, q
+ };
+ return timer;
+ }
+ #endif
}
+ Timer timer = {
+ /*TCCRnQ*/ { nullptr, nullptr, nullptr },
+ /*OCRnQ*/ { nullptr, nullptr, nullptr },
+ /*ICRn*/ nullptr,
+ 0, 0
+ };
+ return timer;
+}
- void set_pwm_frequency(const pin_t pin, int f_desired) {
- Timer timer = get_pwm_timer(pin);
- if (timer.n == 0) return; // Don't proceed if protected timer or not recognised
- uint16_t size;
- if (timer.n == 2) size = 255; else size = 65535;
+void set_pwm_frequency(const pin_t pin, int f_desired) {
+ Timer timer = get_pwm_timer(pin);
+ if (timer.n == 0) return; // Don't proceed if protected timer or not recognised
+ uint16_t size;
+ if (timer.n == 2) size = 255; else size = 65535;
- uint16_t res = 255; // resolution (TOP value)
- uint8_t j = 0; // prescaler index
- uint8_t wgm = 1; // waveform generation mode
+ uint16_t res = 255; // resolution (TOP value)
+ uint8_t j = 0; // prescaler index
+ uint8_t wgm = 1; // waveform generation mode
- // Calculating the prescaler and resolution to use to achieve closest frequency
- if (f_desired != 0) {
- int f = (F_CPU) / (2 * 1024 * size) + 1; // Initialize frequency as lowest (non-zero) achievable
- uint16_t prescaler[] = { 0, 1, 8, /*TIMER2 ONLY*/32, 64, /*TIMER2 ONLY*/128, 256, 1024 };
+ // Calculating the prescaler and resolution to use to achieve closest frequency
+ if (f_desired != 0) {
+ int f = (F_CPU) / (2 * 1024 * size) + 1; // Initialize frequency as lowest (non-zero) achievable
+ uint16_t prescaler[] = { 0, 1, 8, /*TIMER2 ONLY*/32, 64, /*TIMER2 ONLY*/128, 256, 1024 };
- // loop over prescaler values
- for (uint8_t i = 1; i < 8; i++) {
- uint16_t res_temp_fast = 255, res_temp_phase_correct = 255;
- if (timer.n == 2) {
- // No resolution calculation for TIMER2 unless enabled USE_OCR2A_AS_TOP
- #if ENABLED(USE_OCR2A_AS_TOP)
- const uint16_t rtf = (F_CPU) / (prescaler[i] * f_desired);
- res_temp_fast = rtf - 1;
- res_temp_phase_correct = rtf / 2;
- #endif
- }
- else {
- // Skip TIMER2 specific prescalers when not TIMER2
- if (i == 3 || i == 5) continue;
+ // loop over prescaler values
+ for (uint8_t i = 1; i < 8; i++) {
+ uint16_t res_temp_fast = 255, res_temp_phase_correct = 255;
+ if (timer.n == 2) {
+ // No resolution calculation for TIMER2 unless enabled USE_OCR2A_AS_TOP
+ #if ENABLED(USE_OCR2A_AS_TOP)
const uint16_t rtf = (F_CPU) / (prescaler[i] * f_desired);
res_temp_fast = rtf - 1;
res_temp_phase_correct = rtf / 2;
- }
+ #endif
+ }
+ else {
+ // Skip TIMER2 specific prescalers when not TIMER2
+ if (i == 3 || i == 5) continue;
+ const uint16_t rtf = (F_CPU) / (prescaler[i] * f_desired);
+ res_temp_fast = rtf - 1;
+ res_temp_phase_correct = rtf / 2;
+ }
- LIMIT(res_temp_fast, 1u, size);
- LIMIT(res_temp_phase_correct, 1u, size);
- // Calculate frequencies of test prescaler and resolution values
- const int f_temp_fast = (F_CPU) / (prescaler[i] * (1 + res_temp_fast)),
- f_temp_phase_correct = (F_CPU) / (2 * prescaler[i] * res_temp_phase_correct),
- f_diff = ABS(f - f_desired),
- f_fast_diff = ABS(f_temp_fast - f_desired),
- f_phase_diff = ABS(f_temp_phase_correct - f_desired);
-
- // If FAST values are closest to desired f
- if (f_fast_diff < f_diff && f_fast_diff <= f_phase_diff) {
- // Remember this combination
- f = f_temp_fast;
- res = res_temp_fast;
- j = i;
- // Set the Wave Generation Mode to FAST PWM
- if (timer.n == 2) {
- wgm = (
- #if ENABLED(USE_OCR2A_AS_TOP)
- WGM2_FAST_PWM_OCR2A
- #else
- WGM2_FAST_PWM
- #endif
- );
- }
- else wgm = WGM_FAST_PWM_ICRn;
+ LIMIT(res_temp_fast, 1u, size);
+ LIMIT(res_temp_phase_correct, 1u, size);
+ // Calculate frequencies of test prescaler and resolution values
+ const int f_temp_fast = (F_CPU) / (prescaler[i] * (1 + res_temp_fast)),
+ f_temp_phase_correct = (F_CPU) / (2 * prescaler[i] * res_temp_phase_correct),
+ f_diff = ABS(f - f_desired),
+ f_fast_diff = ABS(f_temp_fast - f_desired),
+ f_phase_diff = ABS(f_temp_phase_correct - f_desired);
+
+ // If FAST values are closest to desired f
+ if (f_fast_diff < f_diff && f_fast_diff <= f_phase_diff) {
+ // Remember this combination
+ f = f_temp_fast;
+ res = res_temp_fast;
+ j = i;
+ // Set the Wave Generation Mode to FAST PWM
+ if (timer.n == 2) {
+ wgm = (
+ #if ENABLED(USE_OCR2A_AS_TOP)
+ WGM2_FAST_PWM_OCR2A
+ #else
+ WGM2_FAST_PWM
+ #endif
+ );
}
- // If PHASE CORRECT values are closes to desired f
- else if (f_phase_diff < f_diff) {
- f = f_temp_phase_correct;
- res = res_temp_phase_correct;
- j = i;
- // Set the Wave Generation Mode to PWM PHASE CORRECT
- if (timer.n == 2) {
- wgm = (
- #if ENABLED(USE_OCR2A_AS_TOP)
- WGM2_PWM_PC_OCR2A
- #else
- WGM2_PWM_PC
- #endif
- );
- }
- else wgm = WGM_PWM_PC_ICRn;
+ else wgm = WGM_FAST_PWM_ICRn;
+ }
+ // If PHASE CORRECT values are closes to desired f
+ else if (f_phase_diff < f_diff) {
+ f = f_temp_phase_correct;
+ res = res_temp_phase_correct;
+ j = i;
+ // Set the Wave Generation Mode to PWM PHASE CORRECT
+ if (timer.n == 2) {
+ wgm = (
+ #if ENABLED(USE_OCR2A_AS_TOP)
+ WGM2_PWM_PC_OCR2A
+ #else
+ WGM2_PWM_PC
+ #endif
+ );
}
+ else wgm = WGM_PWM_PC_ICRn;
}
}
- _SET_WGMnQ(timer.TCCRnQ, wgm);
- _SET_CSn(timer.TCCRnQ, j);
-
- if (timer.n == 2) {
- #if ENABLED(USE_OCR2A_AS_TOP)
- _SET_OCRnQ(timer.OCRnQ, 0, res); // Set OCR2A value (TOP) = res
- #endif
- }
- else
- _SET_ICRn(timer.ICRn, res); // Set ICRn value (TOP) = res
}
+ _SET_WGMnQ(timer.TCCRnQ, wgm);
+ _SET_CSn(timer.TCCRnQ, j);
- void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
- // If v is 0 or v_size (max), digitalWrite to LOW or HIGH.
- // Note that digitalWrite also disables pwm output for us (sets COM bit to 0)
- if (v == 0)
- digitalWrite(pin, invert);
- else if (v == v_size)
- digitalWrite(pin, !invert);
- else {
- Timer timer = get_pwm_timer(pin);
- if (timer.n == 0) return; // Don't proceed if protected timer or not recognised
- // Set compare output mode to CLEAR -> SET or SET -> CLEAR (if inverted)
- _SET_COMnQ(timer.TCCRnQ, (timer.q
- #ifdef TCCR2
- + (timer.q == 2) // COM20 is on bit 4 of TCCR2, thus requires q + 1 in the macro
- #endif
- ), COM_CLEAR_SET + invert
- );
+ if (timer.n == 2) {
+ #if ENABLED(USE_OCR2A_AS_TOP)
+ _SET_OCRnQ(timer.OCRnQ, 0, res); // Set OCR2A value (TOP) = res
+ #endif
+ }
+ else
+ _SET_ICRn(timer.ICRn, res); // Set ICRn value (TOP) = res
+}
- uint16_t top;
- if (timer.n == 2) { // if TIMER2
- top = (
- #if ENABLED(USE_OCR2A_AS_TOP)
- *timer.OCRnQ[0] // top = OCR2A
- #else
- 255 // top = 0xFF (max)
- #endif
- );
- }
- else
- top = *timer.ICRn; // top = ICRn
+void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
+ // If v is 0 or v_size (max), digitalWrite to LOW or HIGH.
+ // Note that digitalWrite also disables pwm output for us (sets COM bit to 0)
+ if (v == 0)
+ digitalWrite(pin, invert);
+ else if (v == v_size)
+ digitalWrite(pin, !invert);
+ else {
+ Timer timer = get_pwm_timer(pin);
+ if (timer.n == 0) return; // Don't proceed if protected timer or not recognised
+ // Set compare output mode to CLEAR -> SET or SET -> CLEAR (if inverted)
+ _SET_COMnQ(timer.TCCRnQ, (timer.q
+ #ifdef TCCR2
+ + (timer.q == 2) // COM20 is on bit 4 of TCCR2, thus requires q + 1 in the macro
+ #endif
+ ), COM_CLEAR_SET + invert
+ );
- _SET_OCRnQ(timer.OCRnQ, timer.q, v * float(top / v_size)); // Scale 8/16-bit v to top value
+ uint16_t top;
+ if (timer.n == 2) { // if TIMER2
+ top = (
+ #if ENABLED(USE_OCR2A_AS_TOP)
+ *timer.OCRnQ[0] // top = OCR2A
+ #else
+ 255 // top = 0xFF (max)
+ #endif
+ );
}
+ else
+ top = *timer.ICRn; // top = ICRn
+
+ _SET_OCRnQ(timer.OCRnQ, timer.q, v * float(top / v_size)); // Scale 8/16-bit v to top value
}
+}
#endif // FAST_PWM_FAN
#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 63fbe4d96990..f0f7688f1b06 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,11 +26,11 @@
#ifdef __AVR__
-#include "fastio_AVR.h"
+#include "fastio.h"
#ifdef FASTIO_EXT_START
-#include
+#include "../shared/Marduino.h"
#define _IS_EXT(P) WITHIN(P, FASTIO_EXT_START, FASTIO_EXT_END)
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h b/Marlin/src/HAL/HAL_AVR/fastio.h
similarity index 94%
rename from Marlin/src/HAL/HAL_AVR/fastio_AVR.h
rename to Marlin/src/HAL/HAL_AVR/fastio.h
index a843f1ae753d..501a7cdf0616 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
@@ -81,9 +80,8 @@
#define _SET_INPUT(IO) CBI(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _SET_OUTPUT(IO) SBI(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
-#define _IS_INPUT(IO) !TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
+#define _IS_INPUT(IO) !TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _IS_OUTPUT(IO) TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
-#define _HAS_TIMER(IO) DIO ## IO ## _PWM
// digitalRead/Write wrappers
#ifdef FASTIO_EXT_START
@@ -106,7 +104,6 @@
#define IS_INPUT(IO) _IS_INPUT(IO)
#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
-#define HAS_TIMER(IO) _HAS_TIMER(IO)
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
@@ -275,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
*/
@@ -288,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
@@ -338,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
@@ -353,5 +354,3 @@ enum ClockSource2 : char {
#else
#error "unknown CPU"
#endif
-
-#define USEABLE_HARDWARE_PWM(P) (PWM_PIN(P) && !PWM_CHK(P))
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_1280.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
similarity index 83%
rename from Marlin/src/HAL/HAL_AVR/fastio_1280.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
index 1e3c44a4f50c..62de534d5371 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
@@ -71,13 +71,13 @@
#define DIO0_RPORT PINE
#define DIO0_WPORT PORTE
#define DIO0_DDR DDRE
-#define DIO0_PWM NULL
+#define DIO0_PWM nullptr
#define DIO1_PIN PINE1
#define DIO1_RPORT PINE
#define DIO1_WPORT PORTE
#define DIO1_DDR DDRE
-#define DIO1_PWM NULL
+#define DIO1_PWM nullptr
#define DIO2_PIN PINE4
#define DIO2_RPORT PINE
@@ -137,13 +137,13 @@
#define DIO11_RPORT PINB
#define DIO11_WPORT PORTB
#define DIO11_DDR DDRB
-#define DIO11_PWM NULL
+#define DIO11_PWM nullptr
#define DIO12_PIN PINB6
#define DIO12_RPORT PINB
#define DIO12_WPORT PORTB
#define DIO12_DDR DDRB
-#define DIO12_PWM NULL
+#define DIO12_PWM nullptr
#define DIO13_PIN PINB7
#define DIO13_RPORT PINB
@@ -155,181 +155,181 @@
#define DIO14_RPORT PINJ
#define DIO14_WPORT PORTJ
#define DIO14_DDR DDRJ
-#define DIO14_PWM NULL
+#define DIO14_PWM nullptr
#define DIO15_PIN PINJ0
#define DIO15_RPORT PINJ
#define DIO15_WPORT PORTJ
#define DIO15_DDR DDRJ
-#define DIO15_PWM NULL
+#define DIO15_PWM nullptr
#define DIO16_PIN PINH1
#define DIO16_RPORT PINH
#define DIO16_WPORT PORTH
#define DIO16_DDR DDRH
-#define DIO16_PWM NULL
+#define DIO16_PWM nullptr
#define DIO17_PIN PINH0
#define DIO17_RPORT PINH
#define DIO17_WPORT PORTH
#define DIO17_DDR DDRH
-#define DIO17_PWM NULL
+#define DIO17_PWM nullptr
#define DIO18_PIN PIND3
#define DIO18_RPORT PIND
#define DIO18_WPORT PORTD
#define DIO18_DDR DDRD
-#define DIO18_PWM NULL
+#define DIO18_PWM nullptr
#define DIO19_PIN PIND2
#define DIO19_RPORT PIND
#define DIO19_WPORT PORTD
#define DIO19_DDR DDRD
-#define DIO19_PWM NULL
+#define DIO19_PWM nullptr
#define DIO20_PIN PIND1
#define DIO20_RPORT PIND
#define DIO20_WPORT PORTD
#define DIO20_DDR DDRD
-#define DIO20_PWM NULL
+#define DIO20_PWM nullptr
#define DIO21_PIN PIND0
#define DIO21_RPORT PIND
#define DIO21_WPORT PORTD
#define DIO21_DDR DDRD
-#define DIO21_PWM NULL
+#define DIO21_PWM nullptr
#define DIO22_PIN PINA0
#define DIO22_RPORT PINA
#define DIO22_WPORT PORTA
#define DIO22_DDR DDRA
-#define DIO22_PWM NULL
+#define DIO22_PWM nullptr
#define DIO23_PIN PINA1
#define DIO23_RPORT PINA
#define DIO23_WPORT PORTA
#define DIO23_DDR DDRA
-#define DIO23_PWM NULL
+#define DIO23_PWM nullptr
#define DIO24_PIN PINA2
#define DIO24_RPORT PINA
#define DIO24_WPORT PORTA
#define DIO24_DDR DDRA
-#define DIO24_PWM NULL
+#define DIO24_PWM nullptr
#define DIO25_PIN PINA3
#define DIO25_RPORT PINA
#define DIO25_WPORT PORTA
#define DIO25_DDR DDRA
-#define DIO25_PWM NULL
+#define DIO25_PWM nullptr
#define DIO26_PIN PINA4
#define DIO26_RPORT PINA
#define DIO26_WPORT PORTA
#define DIO26_DDR DDRA
-#define DIO26_PWM NULL
+#define DIO26_PWM nullptr
#define DIO27_PIN PINA5
#define DIO27_RPORT PINA
#define DIO27_WPORT PORTA
#define DIO27_DDR DDRA
-#define DIO27_PWM NULL
+#define DIO27_PWM nullptr
#define DIO28_PIN PINA6
#define DIO28_RPORT PINA
#define DIO28_WPORT PORTA
#define DIO28_DDR DDRA
-#define DIO28_PWM NULL
+#define DIO28_PWM nullptr
#define DIO29_PIN PINA7
#define DIO29_RPORT PINA
#define DIO29_WPORT PORTA
#define DIO29_DDR DDRA
-#define DIO29_PWM NULL
+#define DIO29_PWM nullptr
#define DIO30_PIN PINC7
#define DIO30_RPORT PINC
#define DIO30_WPORT PORTC
#define DIO30_DDR DDRC
-#define DIO30_PWM NULL
+#define DIO30_PWM nullptr
#define DIO31_PIN PINC6
#define DIO31_RPORT PINC
#define DIO31_WPORT PORTC
#define DIO31_DDR DDRC
-#define DIO31_PWM NULL
+#define DIO31_PWM nullptr
#define DIO32_PIN PINC5
#define DIO32_RPORT PINC
#define DIO32_WPORT PORTC
#define DIO32_DDR DDRC
-#define DIO32_PWM NULL
+#define DIO32_PWM nullptr
#define DIO33_PIN PINC4
#define DIO33_RPORT PINC
#define DIO33_WPORT PORTC
#define DIO33_DDR DDRC
-#define DIO33_PWM NULL
+#define DIO33_PWM nullptr
#define DIO34_PIN PINC3
#define DIO34_RPORT PINC
#define DIO34_WPORT PORTC
#define DIO34_DDR DDRC
-#define DIO34_PWM NULL
+#define DIO34_PWM nullptr
#define DIO35_PIN PINC2
#define DIO35_RPORT PINC
#define DIO35_WPORT PORTC
#define DIO35_DDR DDRC
-#define DIO35_PWM NULL
+#define DIO35_PWM nullptr
#define DIO36_PIN PINC1
#define DIO36_RPORT PINC
#define DIO36_WPORT PORTC
#define DIO36_DDR DDRC
-#define DIO36_PWM NULL
+#define DIO36_PWM nullptr
#define DIO37_PIN PINC0
#define DIO37_RPORT PINC
#define DIO37_WPORT PORTC
#define DIO37_DDR DDRC
-#define DIO37_PWM NULL
+#define DIO37_PWM nullptr
#define DIO38_PIN PIND7
#define DIO38_RPORT PIND
#define DIO38_WPORT PORTD
#define DIO38_DDR DDRD
-#define DIO38_PWM NULL
+#define DIO38_PWM nullptr
#define DIO39_PIN PING2
#define DIO39_RPORT PING
#define DIO39_WPORT PORTG
#define DIO39_DDR DDRG
-#define DIO39_PWM NULL
+#define DIO39_PWM nullptr
#define DIO40_PIN PING1
#define DIO40_RPORT PING
#define DIO40_WPORT PORTG
#define DIO40_DDR DDRG
-#define DIO40_PWM NULL
+#define DIO40_PWM nullptr
#define DIO41_PIN PING0
#define DIO41_RPORT PING
#define DIO41_WPORT PORTG
#define DIO41_DDR DDRG
-#define DIO41_PWM NULL
+#define DIO41_PWM nullptr
#define DIO42_PIN PINL7
#define DIO42_RPORT PINL
#define DIO42_WPORT PORTL
#define DIO42_DDR DDRL
-#define DIO42_PWM NULL
+#define DIO42_PWM nullptr
#define DIO43_PIN PINL6
#define DIO43_RPORT PINL
#define DIO43_WPORT PORTL
#define DIO43_DDR DDRL
-#define DIO43_PWM NULL
+#define DIO43_PWM nullptr
#define DIO44_PIN PINL5
#define DIO44_RPORT PINL
@@ -353,139 +353,139 @@
#define DIO47_RPORT PINL
#define DIO47_WPORT PORTL
#define DIO47_DDR DDRL
-#define DIO47_PWM NULL
+#define DIO47_PWM nullptr
#define DIO48_PIN PINL1
#define DIO48_RPORT PINL
#define DIO48_WPORT PORTL
#define DIO48_DDR DDRL
-#define DIO48_PWM NULL
+#define DIO48_PWM nullptr
#define DIO49_PIN PINL0
#define DIO49_RPORT PINL
#define DIO49_WPORT PORTL
#define DIO49_DDR DDRL
-#define DIO49_PWM NULL
+#define DIO49_PWM nullptr
#define DIO50_PIN PINB3
#define DIO50_RPORT PINB
#define DIO50_WPORT PORTB
#define DIO50_DDR DDRB
-#define DIO50_PWM NULL
+#define DIO50_PWM nullptr
#define DIO51_PIN PINB2
#define DIO51_RPORT PINB
#define DIO51_WPORT PORTB
#define DIO51_DDR DDRB
-#define DIO51_PWM NULL
+#define DIO51_PWM nullptr
#define DIO52_PIN PINB1
#define DIO52_RPORT PINB
#define DIO52_WPORT PORTB
#define DIO52_DDR DDRB
-#define DIO52_PWM NULL
+#define DIO52_PWM nullptr
#define DIO53_PIN PINB0
#define DIO53_RPORT PINB
#define DIO53_WPORT PORTB
#define DIO53_DDR DDRB
-#define DIO53_PWM NULL
+#define DIO53_PWM nullptr
#define DIO54_PIN PINF0
#define DIO54_RPORT PINF
#define DIO54_WPORT PORTF
#define DIO54_DDR DDRF
-#define DIO54_PWM NULL
+#define DIO54_PWM nullptr
#define DIO55_PIN PINF1
#define DIO55_RPORT PINF
#define DIO55_WPORT PORTF
#define DIO55_DDR DDRF
-#define DIO55_PWM NULL
+#define DIO55_PWM nullptr
#define DIO56_PIN PINF2
#define DIO56_RPORT PINF
#define DIO56_WPORT PORTF
#define DIO56_DDR DDRF
-#define DIO56_PWM NULL
+#define DIO56_PWM nullptr
#define DIO57_PIN PINF3
#define DIO57_RPORT PINF
#define DIO57_WPORT PORTF
#define DIO57_DDR DDRF
-#define DIO57_PWM NULL
+#define DIO57_PWM nullptr
#define DIO58_PIN PINF4
#define DIO58_RPORT PINF
#define DIO58_WPORT PORTF
#define DIO58_DDR DDRF
-#define DIO58_PWM NULL
+#define DIO58_PWM nullptr
#define DIO59_PIN PINF5
#define DIO59_RPORT PINF
#define DIO59_WPORT PORTF
#define DIO59_DDR DDRF
-#define DIO59_PWM NULL
+#define DIO59_PWM nullptr
#define DIO60_PIN PINF6
#define DIO60_RPORT PINF
#define DIO60_WPORT PORTF
#define DIO60_DDR DDRF
-#define DIO60_PWM NULL
+#define DIO60_PWM nullptr
#define DIO61_PIN PINF7
#define DIO61_RPORT PINF
#define DIO61_WPORT PORTF
#define DIO61_DDR DDRF
-#define DIO61_PWM NULL
+#define DIO61_PWM nullptr
#define DIO62_PIN PINK0
#define DIO62_RPORT PINK
#define DIO62_WPORT PORTK
#define DIO62_DDR DDRK
-#define DIO62_PWM NULL
+#define DIO62_PWM nullptr
#define DIO63_PIN PINK1
#define DIO63_RPORT PINK
#define DIO63_WPORT PORTK
#define DIO63_DDR DDRK
-#define DIO63_PWM NULL
+#define DIO63_PWM nullptr
#define DIO64_PIN PINK2
#define DIO64_RPORT PINK
#define DIO64_WPORT PORTK
#define DIO64_DDR DDRK
-#define DIO64_PWM NULL
+#define DIO64_PWM nullptr
#define DIO65_PIN PINK3
#define DIO65_RPORT PINK
#define DIO65_WPORT PORTK
#define DIO65_DDR DDRK
-#define DIO65_PWM NULL
+#define DIO65_PWM nullptr
#define DIO66_PIN PINK4
#define DIO66_RPORT PINK
#define DIO66_WPORT PORTK
#define DIO66_DDR DDRK
-#define DIO66_PWM NULL
+#define DIO66_PWM nullptr
#define DIO67_PIN PINK5
#define DIO67_RPORT PINK
#define DIO67_WPORT PORTK
#define DIO67_DDR DDRK
-#define DIO67_PWM NULL
+#define DIO67_PWM nullptr
#define DIO68_PIN PINK6
#define DIO68_RPORT PINK
#define DIO68_WPORT PORTK
#define DIO68_DDR DDRK
-#define DIO68_PWM NULL
+#define DIO68_PWM nullptr
#define DIO69_PIN PINK7
#define DIO69_RPORT PINK
#define DIO69_WPORT PORTK
#define DIO69_DDR DDRK
-#define DIO69_PWM NULL
+#define DIO69_PWM nullptr
//#define FASTIO_EXT_START 70
//#define FASTIO_EXT_END 85
@@ -494,171 +494,171 @@
#define DIO70_RPORT PING
#define DIO70_WPORT PORTG
#define DIO70_DDR DDRG
-#define DIO70_PWM NULL
+#define DIO70_PWM nullptr
#define DIO71_PIN PING3
#define DIO71_RPORT PING
#define DIO71_WPORT PORTG
#define DIO71_DDR DDRG
-#define DIO71_PWM NULL
+#define DIO71_PWM nullptr
#define DIO72_PIN PINJ2
#define DIO72_RPORT PINJ
#define DIO72_WPORT PORTJ
#define DIO72_DDR DDRJ
-#define DIO72_PWM NULL
+#define DIO72_PWM nullptr
#define DIO73_PIN PINJ3
#define DIO73_RPORT PINJ
#define DIO73_WPORT PORTJ
#define DIO73_DDR DDRJ
-#define DIO73_PWM NULL
+#define DIO73_PWM nullptr
#define DIO74_PIN PINJ7
#define DIO74_RPORT PINJ
#define DIO74_WPORT PORTJ
#define DIO74_DDR DDRJ
-#define DIO74_PWM NULL
+#define DIO74_PWM nullptr
#define DIO75_PIN PINJ4
#define DIO75_RPORT PINJ
#define DIO75_WPORT PORTJ
#define DIO75_DDR DDRJ
-#define DIO75_PWM NULL
+#define DIO75_PWM nullptr
#define DIO76_PIN PINJ5
#define DIO76_RPORT PINJ
#define DIO76_WPORT PORTJ
#define DIO76_DDR DDRJ
-#define DIO76_PWM NULL
+#define DIO76_PWM nullptr
#define DIO77_PIN PINJ6
#define DIO77_RPORT PINJ
#define DIO77_WPORT PORTJ
#define DIO77_DDR DDRJ
-#define DIO77_PWM NULL
+#define DIO77_PWM nullptr
#define DIO78_PIN PINE2
#define DIO78_RPORT PINE
#define DIO78_WPORT PORTE
#define DIO78_DDR DDRE
-#define DIO78_PWM NULL
+#define DIO78_PWM nullptr
#define DIO79_PIN PINE6
#define DIO79_RPORT PINE
#define DIO79_WPORT PORTE
#define DIO79_DDR DDRE
-#define DIO79_PWM NULL
+#define DIO79_PWM nullptr
#define DIO80_PIN PINE7
#define DIO80_RPORT PINE
#define DIO80_WPORT PORTE
#define DIO80_DDR DDRE
-#define DIO80_PWM NULL
+#define DIO80_PWM nullptr
#define DIO81_PIN PIND4
#define DIO81_RPORT PIND
#define DIO81_WPORT PORTD
#define DIO81_DDR DDRD
-#define DIO81_PWM NULL
+#define DIO81_PWM nullptr
#define DIO82_PIN PIND5
#define DIO82_RPORT PIND
#define DIO82_WPORT PORTD
#define DIO82_DDR DDRD
-#define DIO82_PWM NULL
+#define DIO82_PWM nullptr
#define DIO83_PIN PIND6
#define DIO83_RPORT PIND
#define DIO83_WPORT PORTD
#define DIO83_DDR DDRD
-#define DIO83_PWM NULL
+#define DIO83_PWM nullptr
#define DIO84_PIN PINH2
#define DIO84_RPORT PINH
#define DIO84_WPORT PORTH
#define DIO84_DDR DDRH
-#define DIO84_PWM NULL
+#define DIO84_PWM nullptr
#define DIO85_PIN PINH7
#define DIO85_RPORT PINH
#define DIO85_WPORT PORTH
#define DIO85_DDR DDRH
-#define DIO85_PWM NULL
+#define DIO85_PWM nullptr
#undef PA0
#define PA0_PIN PINA0
#define PA0_RPORT PINA
#define PA0_WPORT PORTA
#define PA0_DDR DDRA
-#define PA0_PWM NULL
+#define PA0_PWM nullptr
#undef PA1
#define PA1_PIN PINA1
#define PA1_RPORT PINA
#define PA1_WPORT PORTA
#define PA1_DDR DDRA
-#define PA1_PWM NULL
+#define PA1_PWM nullptr
#undef PA2
#define PA2_PIN PINA2
#define PA2_RPORT PINA
#define PA2_WPORT PORTA
#define PA2_DDR DDRA
-#define PA2_PWM NULL
+#define PA2_PWM nullptr
#undef PA3
#define PA3_PIN PINA3
#define PA3_RPORT PINA
#define PA3_WPORT PORTA
#define PA3_DDR DDRA
-#define PA3_PWM NULL
+#define PA3_PWM nullptr
#undef PA4
#define PA4_PIN PINA4
#define PA4_RPORT PINA
#define PA4_WPORT PORTA
#define PA4_DDR DDRA
-#define PA4_PWM NULL
+#define PA4_PWM nullptr
#undef PA5
#define PA5_PIN PINA5
#define PA5_RPORT PINA
#define PA5_WPORT PORTA
#define PA5_DDR DDRA
-#define PA5_PWM NULL
+#define PA5_PWM nullptr
#undef PA6
#define PA6_PIN PINA6
#define PA6_RPORT PINA
#define PA6_WPORT PORTA
#define PA6_DDR DDRA
-#define PA6_PWM NULL
+#define PA6_PWM nullptr
#undef PA7
#define PA7_PIN PINA7
#define PA7_RPORT PINA
#define PA7_WPORT PORTA
#define PA7_DDR DDRA
-#define PA7_PWM NULL
+#define PA7_PWM nullptr
#undef PB0
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
#define PB0_DDR DDRB
-#define PB0_PWM NULL
+#define PB0_PWM nullptr
#undef PB1
#define PB1_PIN PINB1
#define PB1_RPORT PINB
#define PB1_WPORT PORTB
#define PB1_DDR DDRB
-#define PB1_PWM NULL
+#define PB1_PWM nullptr
#undef PB2
#define PB2_PIN PINB2
#define PB2_RPORT PINB
#define PB2_WPORT PORTB
#define PB2_DDR DDRB
-#define PB2_PWM NULL
+#define PB2_PWM nullptr
#undef PB3
#define PB3_PIN PINB3
#define PB3_RPORT PINB
#define PB3_WPORT PORTB
#define PB3_DDR DDRB
-#define PB3_PWM NULL
+#define PB3_PWM nullptr
#undef PB4
#define PB4_PIN PINB4
#define PB4_RPORT PINB
@@ -670,13 +670,13 @@
#define PB5_RPORT PINB
#define PB5_WPORT PORTB
#define PB5_DDR DDRB
-#define PB5_PWM NULL
+#define PB5_PWM nullptr
#undef PB6
#define PB6_PIN PINB6
#define PB6_RPORT PINB
#define PB6_WPORT PORTB
#define PB6_DDR DDRB
-#define PB6_PWM NULL
+#define PB6_PWM nullptr
#undef PB7
#define PB7_PIN PINB7
#define PB7_RPORT PINB
@@ -689,117 +689,117 @@
#define PC0_RPORT PINC
#define PC0_WPORT PORTC
#define PC0_DDR DDRC
-#define PC0_PWM NULL
+#define PC0_PWM nullptr
#undef PC1
#define PC1_PIN PINC1
#define PC1_RPORT PINC
#define PC1_WPORT PORTC
#define PC1_DDR DDRC
-#define PC1_PWM NULL
+#define PC1_PWM nullptr
#undef PC2
#define PC2_PIN PINC2
#define PC2_RPORT PINC
#define PC2_WPORT PORTC
#define PC2_DDR DDRC
-#define PC2_PWM NULL
+#define PC2_PWM nullptr
#undef PC3
#define PC3_PIN PINC3
#define PC3_RPORT PINC
#define PC3_WPORT PORTC
#define PC3_DDR DDRC
-#define PC3_PWM NULL
+#define PC3_PWM nullptr
#undef PC4
#define PC4_PIN PINC4
#define PC4_RPORT PINC
#define PC4_WPORT PORTC
#define PC4_DDR DDRC
-#define PC4_PWM NULL
+#define PC4_PWM nullptr
#undef PC5
#define PC5_PIN PINC5
#define PC5_RPORT PINC
#define PC5_WPORT PORTC
#define PC5_DDR DDRC
-#define PC5_PWM NULL
+#define PC5_PWM nullptr
#undef PC6
#define PC6_PIN PINC6
#define PC6_RPORT PINC
#define PC6_WPORT PORTC
#define PC6_DDR DDRC
-#define PC6_PWM NULL
+#define PC6_PWM nullptr
#undef PC7
#define PC7_PIN PINC7
#define PC7_RPORT PINC
#define PC7_WPORT PORTC
#define PC7_DDR DDRC
-#define PC7_PWM NULL
+#define PC7_PWM nullptr
#undef PD0
#define PD0_PIN PIND0
#define PD0_RPORT PIND
#define PD0_WPORT PORTD
#define PD0_DDR DDRD
-#define PD0_PWM NULL
+#define PD0_PWM nullptr
#undef PD1
#define PD1_PIN PIND1
#define PD1_RPORT PIND
#define PD1_WPORT PORTD
#define PD1_DDR DDRD
-#define PD1_PWM NULL
+#define PD1_PWM nullptr
#undef PD2
#define PD2_PIN PIND2
#define PD2_RPORT PIND
#define PD2_WPORT PORTD
#define PD2_DDR DDRD
-#define PD2_PWM NULL
+#define PD2_PWM nullptr
#undef PD3
#define PD3_PIN PIND3
#define PD3_RPORT PIND
#define PD3_WPORT PORTD
#define PD3_DDR DDRD
-#define PD3_PWM NULL
+#define PD3_PWM nullptr
#undef PD4
#define PD4_PIN PIND4
#define PD4_RPORT PIND
#define PD4_WPORT PORTD
#define PD4_DDR DDRD
-#define PD4_PWM NULL
+#define PD4_PWM nullptr
#undef PD5
#define PD5_PIN PIND5
#define PD5_RPORT PIND
#define PD5_WPORT PORTD
#define PD5_DDR DDRD
-#define PD5_PWM NULL
+#define PD5_PWM nullptr
#undef PD6
#define PD6_PIN PIND6
#define PD6_RPORT PIND
#define PD6_WPORT PORTD
#define PD6_DDR DDRD
-#define PD6_PWM NULL
+#define PD6_PWM nullptr
#undef PD7
#define PD7_PIN PIND7
#define PD7_RPORT PIND
#define PD7_WPORT PORTD
#define PD7_DDR DDRD
-#define PD7_PWM NULL
+#define PD7_PWM nullptr
#undef PE0
#define PE0_PIN PINE0
#define PE0_RPORT PINE
#define PE0_WPORT PORTE
#define PE0_DDR DDRE
-#define PE0_PWM NULL
+#define PE0_PWM nullptr
#undef PE1
#define PE1_PIN PINE1
#define PE1_RPORT PINE
#define PE1_WPORT PORTE
#define PE1_DDR DDRE
-#define PE1_PWM NULL
+#define PE1_PWM nullptr
#undef PE2
#define PE2_PIN PINE2
#define PE2_RPORT PINE
#define PE2_WPORT PORTE
#define PE2_DDR DDRE
-#define PE2_PWM NULL
+#define PE2_PWM nullptr
#undef PE3
#define PE3_PIN PINE3
#define PE3_RPORT PINE
@@ -823,93 +823,93 @@
#define PE6_RPORT PINE
#define PE6_WPORT PORTE
#define PE6_DDR DDRE
-#define PE6_PWM NULL
+#define PE6_PWM nullptr
#undef PE7
#define PE7_PIN PINE7
#define PE7_RPORT PINE
#define PE7_WPORT PORTE
#define PE7_DDR DDRE
-#define PE7_PWM NULL
+#define PE7_PWM nullptr
#undef PF0
#define PF0_PIN PINF0
#define PF0_RPORT PINF
#define PF0_WPORT PORTF
#define PF0_DDR DDRF
-#define PF0_PWM NULL
+#define PF0_PWM nullptr
#undef PF1
#define PF1_PIN PINF1
#define PF1_RPORT PINF
#define PF1_WPORT PORTF
#define PF1_DDR DDRF
-#define PF1_PWM NULL
+#define PF1_PWM nullptr
#undef PF2
#define PF2_PIN PINF2
#define PF2_RPORT PINF
#define PF2_WPORT PORTF
#define PF2_DDR DDRF
-#define PF2_PWM NULL
+#define PF2_PWM nullptr
#undef PF3
#define PF3_PIN PINF3
#define PF3_RPORT PINF
#define PF3_WPORT PORTF
#define PF3_DDR DDRF
-#define PF3_PWM NULL
+#define PF3_PWM nullptr
#undef PF4
#define PF4_PIN PINF4
#define PF4_RPORT PINF
#define PF4_WPORT PORTF
#define PF4_DDR DDRF
-#define PF4_PWM NULL
+#define PF4_PWM nullptr
#undef PF5
#define PF5_PIN PINF5
#define PF5_RPORT PINF
#define PF5_WPORT PORTF
#define PF5_DDR DDRF
-#define PF5_PWM NULL
+#define PF5_PWM nullptr
#undef PF6
#define PF6_PIN PINF6
#define PF6_RPORT PINF
#define PF6_WPORT PORTF
#define PF6_DDR DDRF
-#define PF6_PWM NULL
+#define PF6_PWM nullptr
#undef PF7
#define PF7_PIN PINF7
#define PF7_RPORT PINF
#define PF7_WPORT PORTF
#define PF7_DDR DDRF
-#define PF7_PWM NULL
+#define PF7_PWM nullptr
#undef PG0
#define PG0_PIN PING0
#define PG0_RPORT PING
#define PG0_WPORT PORTG
#define PG0_DDR DDRG
-#define PG0_PWM NULL
+#define PG0_PWM nullptr
#undef PG1
#define PG1_PIN PING1
#define PG1_RPORT PING
#define PG1_WPORT PORTG
#define PG1_DDR DDRG
-#define PG1_PWM NULL
+#define PG1_PWM nullptr
#undef PG2
#define PG2_PIN PING2
#define PG2_RPORT PING
#define PG2_WPORT PORTG
#define PG2_DDR DDRG
-#define PG2_PWM NULL
+#define PG2_PWM nullptr
#undef PG3
#define PG3_PIN PING3
#define PG3_RPORT PING
#define PG3_WPORT PORTG
#define PG3_DDR DDRG
-#define PG3_PWM NULL
+#define PG3_PWM nullptr
#undef PG4
#define PG4_PIN PING4
#define PG4_RPORT PING
#define PG4_WPORT PORTG
#define PG4_DDR DDRG
-#define PG4_PWM NULL
+#define PG4_PWM nullptr
#undef PG5
#define PG5_PIN PING5
#define PG5_RPORT PING
@@ -922,19 +922,19 @@
#define PH0_RPORT PINH
#define PH0_WPORT PORTH
#define PH0_DDR DDRH
-#define PH0_PWM NULL
+#define PH0_PWM nullptr
#undef PH1
#define PH1_PIN PINH1
#define PH1_RPORT PINH
#define PH1_WPORT PORTH
#define PH1_DDR DDRH
-#define PH1_PWM NULL
+#define PH1_PWM nullptr
#undef PH2
#define PH2_PIN PINH2
#define PH2_RPORT PINH
#define PH2_WPORT PORTH
#define PH2_DDR DDRH
-#define PH2_PWM NULL
+#define PH2_PWM nullptr
#undef PH3
#define PH3_PIN PINH3
#define PH3_RPORT PINH
@@ -964,124 +964,124 @@
#define PH7_RPORT PINH
#define PH7_WPORT PORTH
#define PH7_DDR DDRH
-#define PH7_PWM NULL
+#define PH7_PWM nullptr
#undef PJ0
#define PJ0_PIN PINJ0
#define PJ0_RPORT PINJ
#define PJ0_WPORT PORTJ
#define PJ0_DDR DDRJ
-#define PJ0_PWM NULL
+#define PJ0_PWM nullptr
#undef PJ1
#define PJ1_PIN PINJ1
#define PJ1_RPORT PINJ
#define PJ1_WPORT PORTJ
#define PJ1_DDR DDRJ
-#define PJ1_PWM NULL
+#define PJ1_PWM nullptr
#undef PJ2
#define PJ2_PIN PINJ2
#define PJ2_RPORT PINJ
#define PJ2_WPORT PORTJ
#define PJ2_DDR DDRJ
-#define PJ2_PWM NULL
+#define PJ2_PWM nullptr
#undef PJ3
#define PJ3_PIN PINJ3
#define PJ3_RPORT PINJ
#define PJ3_WPORT PORTJ
#define PJ3_DDR DDRJ
-#define PJ3_PWM NULL
+#define PJ3_PWM nullptr
#undef PJ4
#define PJ4_PIN PINJ4
#define PJ4_RPORT PINJ
#define PJ4_WPORT PORTJ
#define PJ4_DDR DDRJ
-#define PJ4_PWM NULL
+#define PJ4_PWM nullptr
#undef PJ5
#define PJ5_PIN PINJ5
#define PJ5_RPORT PINJ
#define PJ5_WPORT PORTJ
#define PJ5_DDR DDRJ
-#define PJ5_PWM NULL
+#define PJ5_PWM nullptr
#undef PJ6
#define PJ6_PIN PINJ6
#define PJ6_RPORT PINJ
#define PJ6_WPORT PORTJ
#define PJ6_DDR DDRJ
-#define PJ6_PWM NULL
+#define PJ6_PWM nullptr
#undef PJ7
#define PJ7_PIN PINJ7
#define PJ7_RPORT PINJ
#define PJ7_WPORT PORTJ
#define PJ7_DDR DDRJ
-#define PJ7_PWM NULL
+#define PJ7_PWM nullptr
#undef PK0
#define PK0_PIN PINK0
#define PK0_RPORT PINK
#define PK0_WPORT PORTK
#define PK0_DDR DDRK
-#define PK0_PWM NULL
+#define PK0_PWM nullptr
#undef PK1
#define PK1_PIN PINK1
#define PK1_RPORT PINK
#define PK1_WPORT PORTK
#define PK1_DDR DDRK
-#define PK1_PWM NULL
+#define PK1_PWM nullptr
#undef PK2
#define PK2_PIN PINK2
#define PK2_RPORT PINK
#define PK2_WPORT PORTK
#define PK2_DDR DDRK
-#define PK2_PWM NULL
+#define PK2_PWM nullptr
#undef PK3
#define PK3_PIN PINK3
#define PK3_RPORT PINK
#define PK3_WPORT PORTK
#define PK3_DDR DDRK
-#define PK3_PWM NULL
+#define PK3_PWM nullptr
#undef PK4
#define PK4_PIN PINK4
#define PK4_RPORT PINK
#define PK4_WPORT PORTK
#define PK4_DDR DDRK
-#define PK4_PWM NULL
+#define PK4_PWM nullptr
#undef PK5
#define PK5_PIN PINK5
#define PK5_RPORT PINK
#define PK5_WPORT PORTK
#define PK5_DDR DDRK
-#define PK5_PWM NULL
+#define PK5_PWM nullptr
#undef PK6
#define PK6_PIN PINK6
#define PK6_RPORT PINK
#define PK6_WPORT PORTK
#define PK6_DDR DDRK
-#define PK6_PWM NULL
+#define PK6_PWM nullptr
#undef PK7
#define PK7_PIN PINK7
#define PK7_RPORT PINK
#define PK7_WPORT PORTK
#define PK7_DDR DDRK
-#define PK7_PWM NULL
+#define PK7_PWM nullptr
#undef PL0
#define PL0_PIN PINL0
#define PL0_RPORT PINL
#define PL0_WPORT PORTL
#define PL0_DDR DDRL
-#define PL0_PWM NULL
+#define PL0_PWM nullptr
#undef PL1
#define PL1_PIN PINL1
#define PL1_RPORT PINL
#define PL1_WPORT PORTL
#define PL1_DDR DDRL
-#define PL1_PWM NULL
+#define PL1_PWM nullptr
#undef PL2
#define PL2_PIN PINL2
#define PL2_RPORT PINL
#define PL2_WPORT PORTL
#define PL2_DDR DDRL
-#define PL2_PWM NULL
+#define PL2_PWM nullptr
#undef PL3
#define PL3_PIN PINL3
#define PL3_RPORT PINL
@@ -1105,10 +1105,10 @@
#define PL6_RPORT PINL
#define PL6_WPORT PORTL
#define PL6_DDR DDRL
-#define PL6_PWM NULL
+#define PL6_PWM nullptr
#undef PL7
#define PL7_PIN PINL7
#define PL7_RPORT PINL
#define PL7_WPORT PORTL
#define PL7_DDR DDRL
-#define PL7_PWM NULL
+#define PL7_PWM nullptr
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_1281.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
similarity index 83%
rename from Marlin/src/HAL/HAL_AVR/fastio_1281.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
index 9707c7d54b4d..e3d2f12851b9 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
@@ -63,13 +63,13 @@
#define DIO0_RPORT PINE
#define DIO0_WPORT PORTE
#define DIO0_DDR DDRE
-#define DIO0_PWM NULL
+#define DIO0_PWM nullptr
#define DIO1_PIN PINE1
#define DIO1_RPORT PINE
#define DIO1_WPORT PORTE
#define DIO1_DDR DDRE
-#define DIO1_PWM NULL
+#define DIO1_PWM nullptr
#define DIO2_PIN PINE4
#define DIO2_RPORT PINE
@@ -123,339 +123,339 @@
#define DIO10_RPORT PINB
#define DIO10_WPORT PORTB
#define DIO10_DDR DDRB
-#define DIO10_PWM NULL
+#define DIO10_PWM nullptr
#define DIO11_PIN PINB2
#define DIO11_RPORT PINB
#define DIO11_WPORT PORTB
#define DIO11_DDR DDRB
-#define DIO11_PWM NULL
+#define DIO11_PWM nullptr
#define DIO12_PIN PINB3
#define DIO12_RPORT PINB
#define DIO12_WPORT PORTB
#define DIO12_DDR DDRB
-#define DIO12_PWM NULL
+#define DIO12_PWM nullptr
#define DIO13_PIN PINE2
#define DIO13_RPORT PINE
#define DIO13_WPORT PORTE
#define DIO13_DDR DDRE
-#define DIO13_PWM NULL
+#define DIO13_PWM nullptr
#define DIO14_PIN PINE6
#define DIO14_RPORT PINE
#define DIO14_WPORT PORTE
#define DIO14_DDR DDRE
-#define DIO14_PWM NULL
+#define DIO14_PWM nullptr
#define DIO15_PIN PINE7
#define DIO15_RPORT PINE
#define DIO15_WPORT PORTE
#define DIO15_DDR DDRE
-#define DIO15_PWM NULL
+#define DIO15_PWM nullptr
#define DIO16_PIN PINB0
#define DIO16_RPORT PINB
#define DIO16_WPORT PORTB
#define DIO16_DDR DDRB
-#define DIO16_PWM NULL
+#define DIO16_PWM nullptr
#define DIO17_PIN PIND0
#define DIO17_RPORT PIND
#define DIO17_WPORT PORTD
#define DIO17_DDR DDRD
-#define DIO17_PWM NULL
+#define DIO17_PWM nullptr
#define DIO18_PIN PIND1
#define DIO18_RPORT PIND
#define DIO18_WPORT PORTD
#define DIO18_DDR DDRD
-#define DIO18_PWM NULL
+#define DIO18_PWM nullptr
#define DIO19_PIN PIND2
#define DIO19_RPORT PIND
#define DIO19_WPORT PORTD
#define DIO19_DDR DDRD
-#define DIO19_PWM NULL
+#define DIO19_PWM nullptr
#define DIO20_PIN PIND3
#define DIO20_RPORT PIND
#define DIO20_WPORT PORTD
#define DIO20_DDR DDRD
-#define DIO20_PWM NULL
+#define DIO20_PWM nullptr
#define DIO21_PIN PIND4
#define DIO21_RPORT PIND
#define DIO21_WPORT PORTD
#define DIO21_DDR DDRD
-#define DIO21_PWM NULL
+#define DIO21_PWM nullptr
#define DIO22_PIN PIND5
#define DIO22_RPORT PIND
#define DIO22_WPORT PORTD
#define DIO22_DDR DDRD
-#define DIO22_PWM NULL
+#define DIO22_PWM nullptr
#define DIO23_PIN PIND6
#define DIO23_RPORT PIND
#define DIO23_WPORT PORTD
#define DIO23_DDR DDRD
-#define DIO23_PWM NULL
+#define DIO23_PWM nullptr
#define DIO24_PIN PIND7
#define DIO24_RPORT PIND
#define DIO24_WPORT PORTD
#define DIO24_DDR DDRD
-#define DIO24_PWM NULL
+#define DIO24_PWM nullptr
#define DIO25_PIN PING0
#define DIO25_RPORT PING
#define DIO25_WPORT PORTG
#define DIO25_DDR DDRG
-#define DIO25_PWM NULL
+#define DIO25_PWM nullptr
#define DIO26_PIN PING1
#define DIO26_RPORT PING
#define DIO26_WPORT PORTG
#define DIO26_DDR DDRG
-#define DIO26_PWM NULL
+#define DIO26_PWM nullptr
#define DIO27_PIN PING2
#define DIO27_RPORT PING
#define DIO27_WPORT PORTG
#define DIO27_DDR DDRG
-#define DIO27_PWM NULL
+#define DIO27_PWM nullptr
#define DIO28_PIN PING3
#define DIO28_RPORT PING
#define DIO28_WPORT PORTG
#define DIO28_DDR DDRG
-#define DIO28_PWM NULL
+#define DIO28_PWM nullptr
#define DIO29_PIN PING4
#define DIO29_RPORT PING
#define DIO29_WPORT PORTG
#define DIO29_DDR DDRG
-#define DIO29_PWM NULL
+#define DIO29_PWM nullptr
#define DIO30_PIN PINC0
#define DIO30_RPORT PINC
#define DIO30_WPORT PORTC
#define DIO30_DDR DDRC
-#define DIO30_PWM NULL
+#define DIO30_PWM nullptr
#define DIO31_PIN PINC1
#define DIO31_RPORT PINC
#define DIO31_WPORT PORTC
#define DIO31_DDR DDRC
-#define DIO31_PWM NULL
+#define DIO31_PWM nullptr
#define DIO32_PIN PINC2
#define DIO32_RPORT PINC
#define DIO32_WPORT PORTC
#define DIO32_DDR DDRC
-#define DIO32_PWM NULL
+#define DIO32_PWM nullptr
#define DIO33_PIN PINC3
#define DIO33_RPORT PINC
#define DIO33_WPORT PORTC
#define DIO33_DDR DDRC
-#define DIO33_PWM NULL
+#define DIO33_PWM nullptr
#define DIO34_PIN PINC4
#define DIO34_RPORT PINC
#define DIO34_WPORT PORTC
#define DIO34_DDR DDRC
-#define DIO34_PWM NULL
+#define DIO34_PWM nullptr
#define DIO35_PIN PINC5
#define DIO35_RPORT PINC
#define DIO35_WPORT PORTC
#define DIO35_DDR DDRC
-#define DIO35_PWM NULL
+#define DIO35_PWM nullptr
#define DIO36_PIN PINC6
#define DIO36_RPORT PINC
#define DIO36_WPORT PORTC
#define DIO36_DDR DDRC
-#define DIO36_PWM NULL
+#define DIO36_PWM nullptr
#define DIO37_PIN PINC7
#define DIO37_RPORT PINC
#define DIO37_WPORT PORTC
#define DIO37_DDR DDRC
-#define DIO37_PWM NULL
+#define DIO37_PWM nullptr
#define DIO38_PIN PINA0
#define DIO38_RPORT PINA
#define DIO38_WPORT PORTA
#define DIO38_DDR DDRA
-#define DIO38_PWM NULL
+#define DIO38_PWM nullptr
#define DIO39_PIN PINA1
#define DIO39_RPORT PINA
#define DIO39_WPORT PORTA
#define DIO39_DDR DDRA
-#define DIO39_PWM NULL
+#define DIO39_PWM nullptr
#define DIO40_PIN PINA2
#define DIO40_RPORT PINA
#define DIO40_WPORT PORTA
#define DIO40_DDR DDRA
-#define DIO40_PWM NULL
+#define DIO40_PWM nullptr
#define DIO41_PIN PINA3
#define DIO41_RPORT PINA
#define DIO41_WPORT PORTA
#define DIO41_DDR DDRA
-#define DIO41_PWM NULL
+#define DIO41_PWM nullptr
#define DIO42_PIN PINA4
#define DIO42_RPORT PINA
#define DIO42_WPORT PORTA
#define DIO42_DDR DDRA
-#define DIO42_PWM NULL
+#define DIO42_PWM nullptr
#define DIO43_PIN PINA5
#define DIO43_RPORT PINA
#define DIO43_WPORT PORTA
#define DIO43_DDR DDRA
-#define DIO43_PWM NULL
+#define DIO43_PWM nullptr
#define DIO44_PIN PINA6
#define DIO44_RPORT PINA
#define DIO44_WPORT PORTA
#define DIO44_DDR DDRA
-#define DIO44_PWM NULL
+#define DIO44_PWM nullptr
#define DIO45_PIN PINA7
#define DIO45_RPORT PINA
#define DIO45_WPORT PORTA
#define DIO45_DDR DDRA
-#define DIO45_PWM NULL
+#define DIO45_PWM nullptr
#define DIO46_PIN PINF0
#define DIO46_RPORT PINF
#define DIO46_WPORT PORTF
#define DIO46_DDR DDRF
-#define DIO46_PWM NULL
+#define DIO46_PWM nullptr
#define DIO47_PIN PINF1
#define DIO47_RPORT PINF
#define DIO47_WPORT PORTF
#define DIO47_DDR DDRF
-#define DIO47_PWM NULL
+#define DIO47_PWM nullptr
#define DIO48_PIN PINF2
#define DIO48_RPORT PINF
#define DIO48_WPORT PORTF
#define DIO48_DDR DDRF
-#define DIO48_PWM NULL
+#define DIO48_PWM nullptr
#define DIO49_PIN PINF3
#define DIO49_RPORT PINF
#define DIO49_WPORT PORTF
#define DIO49_DDR DDRF
-#define DIO49_PWM NULL
+#define DIO49_PWM nullptr
#define DIO50_PIN PINF4
#define DIO50_RPORT PINF
#define DIO50_WPORT PORTF
#define DIO50_DDR DDRF
-#define DIO50_PWM NULL
+#define DIO50_PWM nullptr
#define DIO51_PIN PINF5
#define DIO51_RPORT PINF
#define DIO51_WPORT PORTF
#define DIO51_DDR DDRF
-#define DIO51_PWM NULL
+#define DIO51_PWM nullptr
#define DIO52_PIN PINF6
#define DIO52_RPORT PINF
#define DIO52_WPORT PORTF
#define DIO52_DDR DDRF
-#define DIO52_PWM NULL
+#define DIO52_PWM nullptr
#define DIO53_PIN PINF7
#define DIO53_RPORT PINF
#define DIO53_WPORT PORTF
#define DIO53_DDR DDRF
-#define DIO53_PWM NULL
+#define DIO53_PWM nullptr
#undef PA0
#define PA0_PIN PINA0
#define PA0_RPORT PINA
#define PA0_WPORT PORTA
#define PA0_DDR DDRA
-#define PA0_PWM NULL
+#define PA0_PWM nullptr
#undef PA1
#define PA1_PIN PINA1
#define PA1_RPORT PINA
#define PA1_WPORT PORTA
#define PA1_DDR DDRA
-#define PA1_PWM NULL
+#define PA1_PWM nullptr
#undef PA2
#define PA2_PIN PINA2
#define PA2_RPORT PINA
#define PA2_WPORT PORTA
#define PA2_DDR DDRA
-#define PA2_PWM NULL
+#define PA2_PWM nullptr
#undef PA3
#define PA3_PIN PINA3
#define PA3_RPORT PINA
#define PA3_WPORT PORTA
#define PA3_DDR DDRA
-#define PA3_PWM NULL
+#define PA3_PWM nullptr
#undef PA4
#define PA4_PIN PINA4
#define PA4_RPORT PINA
#define PA4_WPORT PORTA
#define PA4_DDR DDRA
-#define PA4_PWM NULL
+#define PA4_PWM nullptr
#undef PA5
#define PA5_PIN PINA5
#define PA5_RPORT PINA
#define PA5_WPORT PORTA
#define PA5_DDR DDRA
-#define PA5_PWM NULL
+#define PA5_PWM nullptr
#undef PA6
#define PA6_PIN PINA6
#define PA6_RPORT PINA
#define PA6_WPORT PORTA
#define PA6_DDR DDRA
-#define PA6_PWM NULL
+#define PA6_PWM nullptr
#undef PA7
#define PA7_PIN PINA7
#define PA7_RPORT PINA
#define PA7_WPORT PORTA
#define PA7_DDR DDRA
-#define PA7_PWM NULL
+#define PA7_PWM nullptr
#undef PB0
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
#define PB0_DDR DDRB
-#define PB0_PWM NULL
+#define PB0_PWM nullptr
#undef PB1
#define PB1_PIN PINB1
#define PB1_RPORT PINB
#define PB1_WPORT PORTB
#define PB1_DDR DDRB
-#define PB1_PWM NULL
+#define PB1_PWM nullptr
#undef PB2
#define PB2_PIN PINB2
#define PB2_RPORT PINB
#define PB2_WPORT PORTB
#define PB2_DDR DDRB
-#define PB2_PWM NULL
+#define PB2_PWM nullptr
#undef PB3
#define PB3_PIN PINB3
#define PB3_RPORT PINB
#define PB3_WPORT PORTB
#define PB3_DDR DDRB
-#define PB3_PWM NULL
+#define PB3_PWM nullptr
#undef PB4
#define PB4_PIN PINB4
#define PB4_RPORT PINB
@@ -467,13 +467,13 @@
#define PB5_RPORT PINB
#define PB5_WPORT PORTB
#define PB5_DDR DDRB
-#define PB5_PWM NULL
+#define PB5_PWM nullptr
#undef PB6
#define PB6_PIN PINB6
#define PB6_RPORT PINB
#define PB6_WPORT PORTB
#define PB6_DDR DDRB
-#define PB6_PWM NULL
+#define PB6_PWM nullptr
#undef PB7
#define PB7_PIN PINB7
#define PB7_RPORT PINB
@@ -486,117 +486,117 @@
#define PC0_RPORT PINC
#define PC0_WPORT PORTC
#define PC0_DDR DDRC
-#define PC0_PWM NULL
+#define PC0_PWM nullptr
#undef PC1
#define PC1_PIN PINC1
#define PC1_RPORT PINC
#define PC1_WPORT PORTC
#define PC1_DDR DDRC
-#define PC1_PWM NULL
+#define PC1_PWM nullptr
#undef PC2
#define PC2_PIN PINC2
#define PC2_RPORT PINC
#define PC2_WPORT PORTC
#define PC2_DDR DDRC
-#define PC2_PWM NULL
+#define PC2_PWM nullptr
#undef PC3
#define PC3_PIN PINC3
#define PC3_RPORT PINC
#define PC3_WPORT PORTC
#define PC3_DDR DDRC
-#define PC3_PWM NULL
+#define PC3_PWM nullptr
#undef PC4
#define PC4_PIN PINC4
#define PC4_RPORT PINC
#define PC4_WPORT PORTC
#define PC4_DDR DDRC
-#define PC4_PWM NULL
+#define PC4_PWM nullptr
#undef PC5
#define PC5_PIN PINC5
#define PC5_RPORT PINC
#define PC5_WPORT PORTC
#define PC5_DDR DDRC
-#define PC5_PWM NULL
+#define PC5_PWM nullptr
#undef PC6
#define PC6_PIN PINC6
#define PC6_RPORT PINC
#define PC6_WPORT PORTC
#define PC6_DDR DDRC
-#define PC6_PWM NULL
+#define PC6_PWM nullptr
#undef PC7
#define PC7_PIN PINC7
#define PC7_RPORT PINC
#define PC7_WPORT PORTC
#define PC7_DDR DDRC
-#define PC7_PWM NULL
+#define PC7_PWM nullptr
#undef PD0
#define PD0_PIN PIND0
#define PD0_RPORT PIND
#define PD0_WPORT PORTD
#define PD0_DDR DDRD
-#define PD0_PWM NULL
+#define PD0_PWM nullptr
#undef PD1
#define PD1_PIN PIND1
#define PD1_RPORT PIND
#define PD1_WPORT PORTD
#define PD1_DDR DDRD
-#define PD1_PWM NULL
+#define PD1_PWM nullptr
#undef PD2
#define PD2_PIN PIND2
#define PD2_RPORT PIND
#define PD2_WPORT PORTD
#define PD2_DDR DDRD
-#define PD2_PWM NULL
+#define PD2_PWM nullptr
#undef PD3
#define PD3_PIN PIND3
#define PD3_RPORT PIND
#define PD3_WPORT PORTD
#define PD3_DDR DDRD
-#define PD3_PWM NULL
+#define PD3_PWM nullptr
#undef PD4
#define PD4_PIN PIND4
#define PD4_RPORT PIND
#define PD4_WPORT PORTD
#define PD4_DDR DDRD
-#define PD4_PWM NULL
+#define PD4_PWM nullptr
#undef PD5
#define PD5_PIN PIND5
#define PD5_RPORT PIND
#define PD5_WPORT PORTD
#define PD5_DDR DDRD
-#define PD5_PWM NULL
+#define PD5_PWM nullptr
#undef PD6
#define PD6_PIN PIND6
#define PD6_RPORT PIND
#define PD6_WPORT PORTD
#define PD6_DDR DDRD
-#define PD6_PWM NULL
+#define PD6_PWM nullptr
#undef PD7
#define PD7_PIN PIND7
#define PD7_RPORT PIND
#define PD7_WPORT PORTD
#define PD7_DDR DDRD
-#define PD7_PWM NULL
+#define PD7_PWM nullptr
#undef PE0
#define PE0_PIN PINE0
#define PE0_RPORT PINE
#define PE0_WPORT PORTE
#define PE0_DDR DDRE
-#define PE0_PWM NULL
+#define PE0_PWM nullptr
#undef PE1
#define PE1_PIN PINE1
#define PE1_RPORT PINE
#define PE1_WPORT PORTE
#define PE1_DDR DDRE
-#define PE1_PWM NULL
+#define PE1_PWM nullptr
#undef PE2
#define PE2_PIN PINE2
#define PE2_RPORT PINE
#define PE2_WPORT PORTE
#define PE2_DDR DDRE
-#define PE2_PWM NULL
+#define PE2_PWM nullptr
#undef PE3
#define PE3_PIN PINE3
#define PE3_RPORT PINE
@@ -620,93 +620,93 @@
#define PE6_RPORT PINE
#define PE6_WPORT PORTE
#define PE6_DDR DDRE
-#define PE6_PWM NULL
+#define PE6_PWM nullptr
#undef PE7
#define PE7_PIN PINE7
#define PE7_RPORT PINE
#define PE7_WPORT PORTE
#define PE7_DDR DDRE
-#define PE7_PWM NULL
+#define PE7_PWM nullptr
#undef PF0
#define PF0_PIN PINF0
#define PF0_RPORT PINF
#define PF0_WPORT PORTF
#define PF0_DDR DDRF
-#define PF0_PWM NULL
+#define PF0_PWM nullptr
#undef PF1
#define PF1_PIN PINF1
#define PF1_RPORT PINF
#define PF1_WPORT PORTF
#define PF1_DDR DDRF
-#define PF1_PWM NULL
+#define PF1_PWM nullptr
#undef PF2
#define PF2_PIN PINF2
#define PF2_RPORT PINF
#define PF2_WPORT PORTF
#define PF2_DDR DDRF
-#define PF2_PWM NULL
+#define PF2_PWM nullptr
#undef PF3
#define PF3_PIN PINF3
#define PF3_RPORT PINF
#define PF3_WPORT PORTF
#define PF3_DDR DDRF
-#define PF3_PWM NULL
+#define PF3_PWM nullptr
#undef PF4
#define PF4_PIN PINF4
#define PF4_RPORT PINF
#define PF4_WPORT PORTF
#define PF4_DDR DDRF
-#define PF4_PWM NULL
+#define PF4_PWM nullptr
#undef PF5
#define PF5_PIN PINF5
#define PF5_RPORT PINF
#define PF5_WPORT PORTF
#define PF5_DDR DDRF
-#define PF5_PWM NULL
+#define PF5_PWM nullptr
#undef PF6
#define PF6_PIN PINF6
#define PF6_RPORT PINF
#define PF6_WPORT PORTF
#define PF6_DDR DDRF
-#define PF6_PWM NULL
+#define PF6_PWM nullptr
#undef PF7
#define PF7_PIN PINF7
#define PF7_RPORT PINF
#define PF7_WPORT PORTF
#define PF7_DDR DDRF
-#define PF7_PWM NULL
+#define PF7_PWM nullptr
#undef PG0
#define PG0_PIN PING0
#define PG0_RPORT PING
#define PG0_WPORT PORTG
#define PG0_DDR DDRG
-#define PG0_PWM NULL
+#define PG0_PWM nullptr
#undef PG1
#define PG1_PIN PING1
#define PG1_RPORT PING
#define PG1_WPORT PORTG
#define PG1_DDR DDRG
-#define PG1_PWM NULL
+#define PG1_PWM nullptr
#undef PG2
#define PG2_PIN PING2
#define PG2_RPORT PING
#define PG2_WPORT PORTG
#define PG2_DDR DDRG
-#define PG2_PWM NULL
+#define PG2_PWM nullptr
#undef PG3
#define PG3_PIN PING3
#define PG3_RPORT PING
#define PG3_WPORT PORTG
#define PG3_DDR DDRG
-#define PG3_PWM NULL
+#define PG3_PWM nullptr
#undef PG4
#define PG4_PIN PING4
#define PG4_RPORT PING
#define PG4_WPORT PORTG
#define PG4_DDR DDRG
-#define PG4_PWM NULL
+#define PG4_PWM nullptr
#undef PG5
#define PG5_PIN PING5
#define PG5_RPORT PING
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_168.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
similarity index 84%
rename from Marlin/src/HAL/HAL_AVR/fastio_168.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
index 2964ef5a0b74..f6ee7a5d0016 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
@@ -60,19 +60,19 @@
#define DIO0_RPORT PIND
#define DIO0_WPORT PORTD
#define DIO0_DDR DDRD
-#define DIO0_PWM NULL
+#define DIO0_PWM nullptr
#define DIO1_PIN PIND1
#define DIO1_RPORT PIND
#define DIO1_WPORT PORTD
#define DIO1_DDR DDRD
-#define DIO1_PWM NULL
+#define DIO1_PWM nullptr
#define DIO2_PIN PIND2
#define DIO2_RPORT PIND
#define DIO2_WPORT PORTD
#define DIO2_DDR DDRD
-#define DIO2_PWM NULL
+#define DIO2_PWM nullptr
#define DIO3_PIN PIND3
#define DIO3_RPORT PIND
@@ -84,7 +84,7 @@
#define DIO4_RPORT PIND
#define DIO4_WPORT PORTD
#define DIO4_DDR DDRD
-#define DIO4_PWM NULL
+#define DIO4_PWM nullptr
#define DIO5_PIN PIND5
#define DIO5_RPORT PIND
@@ -102,25 +102,25 @@
#define DIO7_RPORT PIND
#define DIO7_WPORT PORTD
#define DIO7_DDR DDRD
-#define DIO7_PWM NULL
+#define DIO7_PWM nullptr
#define DIO8_PIN PINB0
#define DIO8_RPORT PINB
#define DIO8_WPORT PORTB
#define DIO8_DDR DDRB
-#define DIO8_PWM NULL
+#define DIO8_PWM nullptr
#define DIO9_PIN PINB1
#define DIO9_RPORT PINB
#define DIO9_WPORT PORTB
#define DIO9_DDR DDRB
-#define DIO9_PWM NULL
+#define DIO9_PWM nullptr
#define DIO10_PIN PINB2
#define DIO10_RPORT PINB
#define DIO10_WPORT PORTB
#define DIO10_DDR DDRB
-#define DIO10_PWM NULL
+#define DIO10_PWM nullptr
#define DIO11_PIN PINB3
#define DIO11_RPORT PINB
@@ -132,82 +132,82 @@
#define DIO12_RPORT PINB
#define DIO12_WPORT PORTB
#define DIO12_DDR DDRB
-#define DIO12_PWM NULL
+#define DIO12_PWM nullptr
#define DIO13_PIN PINB5
#define DIO13_RPORT PINB
#define DIO13_WPORT PORTB
#define DIO13_DDR DDRB
-#define DIO13_PWM NULL
+#define DIO13_PWM nullptr
#define DIO14_PIN PINC0
#define DIO14_RPORT PINC
#define DIO14_WPORT PORTC
#define DIO14_DDR DDRC
-#define DIO14_PWM NULL
+#define DIO14_PWM nullptr
#define DIO15_PIN PINC1
#define DIO15_RPORT PINC
#define DIO15_WPORT PORTC
#define DIO15_DDR DDRC
-#define DIO15_PWM NULL
+#define DIO15_PWM nullptr
#define DIO16_PIN PINC2
#define DIO16_RPORT PINC
#define DIO16_WPORT PORTC
#define DIO16_DDR DDRC
-#define DIO16_PWM NULL
+#define DIO16_PWM nullptr
#define DIO17_PIN PINC3
#define DIO17_RPORT PINC
#define DIO17_WPORT PORTC
#define DIO17_DDR DDRC
-#define DIO17_PWM NULL
+#define DIO17_PWM nullptr
#define DIO18_PIN PINC4
#define DIO18_RPORT PINC
#define DIO18_WPORT PORTC
#define DIO18_DDR DDRC
-#define DIO18_PWM NULL
+#define DIO18_PWM nullptr
#define DIO19_PIN PINC5
#define DIO19_RPORT PINC
#define DIO19_WPORT PORTC
#define DIO19_DDR DDRC
-#define DIO19_PWM NULL
+#define DIO19_PWM nullptr
#define DIO20_PIN PINC6
#define DIO20_RPORT PINC
#define DIO20_WPORT PORTC
#define DIO20_DDR DDRC
-#define DIO20_PWM NULL
+#define DIO20_PWM nullptr
#define DIO21_PIN PINC7
#define DIO21_RPORT PINC
#define DIO21_WPORT PORTC
#define DIO21_DDR DDRC
-#define DIO21_PWM NULL
+#define DIO21_PWM nullptr
#undef PB0
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
#define PB0_DDR DDRB
-#define PB0_PWM NULL
+#define PB0_PWM nullptr
#undef PB1
#define PB1_PIN PINB1
#define PB1_RPORT PINB
#define PB1_WPORT PORTB
#define PB1_DDR DDRB
-#define PB1_PWM NULL
+#define PB1_PWM nullptr
#undef PB2
#define PB2_PIN PINB2
#define PB2_RPORT PINB
#define PB2_WPORT PORTB
#define PB2_DDR DDRB
-#define PB2_PWM NULL
+#define PB2_PWM nullptr
#undef PB3
#define PB3_PIN PINB3
@@ -221,105 +221,105 @@
#define PB4_RPORT PINB
#define PB4_WPORT PORTB
#define PB4_DDR DDRB
-#define PB4_PWM NULL
+#define PB4_PWM nullptr
#undef PB5
#define PB5_PIN PINB5
#define PB5_RPORT PINB
#define PB5_WPORT PORTB
#define PB5_DDR DDRB
-#define PB5_PWM NULL
+#define PB5_PWM nullptr
#undef PB6
#define PB6_PIN PINB6
#define PB6_RPORT PINB
#define PB6_WPORT PORTB
#define PB6_DDR DDRB
-#define PB6_PWM NULL
+#define PB6_PWM nullptr
#undef PB7
#define PB7_PIN PINB7
#define PB7_RPORT PINB
#define PB7_WPORT PORTB
#define PB7_DDR DDRB
-#define PB7_PWM NULL
+#define PB7_PWM nullptr
#undef PC0
#define PC0_PIN PINC0
#define PC0_RPORT PINC
#define PC0_WPORT PORTC
#define PC0_DDR DDRC
-#define PC0_PWM NULL
+#define PC0_PWM nullptr
#undef PC1
#define PC1_PIN PINC1
#define PC1_RPORT PINC
#define PC1_WPORT PORTC
#define PC1_DDR DDRC
-#define PC1_PWM NULL
+#define PC1_PWM nullptr
#undef PC2
#define PC2_PIN PINC2
#define PC2_RPORT PINC
#define PC2_WPORT PORTC
#define PC2_DDR DDRC
-#define PC2_PWM NULL
+#define PC2_PWM nullptr
#undef PC3
#define PC3_PIN PINC3
#define PC3_RPORT PINC
#define PC3_WPORT PORTC
#define PC3_DDR DDRC
-#define PC3_PWM NULL
+#define PC3_PWM nullptr
#undef PC4
#define PC4_PIN PINC4
#define PC4_RPORT PINC
#define PC4_WPORT PORTC
#define PC4_DDR DDRC
-#define PC4_PWM NULL
+#define PC4_PWM nullptr
#undef PC5
#define PC5_PIN PINC5
#define PC5_RPORT PINC
#define PC5_WPORT PORTC
#define PC5_DDR DDRC
-#define PC5_PWM NULL
+#define PC5_PWM nullptr
#undef PC6
#define PC6_PIN PINC6
#define PC6_RPORT PINC
#define PC6_WPORT PORTC
#define PC6_DDR DDRC
-#define PC6_PWM NULL
+#define PC6_PWM nullptr
#undef PC7
#define PC7_PIN PINC7
#define PC7_RPORT PINC
#define PC7_WPORT PORTC
#define PC7_DDR DDRC
-#define PC7_PWM NULL
+#define PC7_PWM nullptr
#undef PD0
#define PD0_PIN PIND0
#define PD0_RPORT PIND
#define PD0_WPORT PORTD
#define PD0_DDR DDRD
-#define PD0_PWM NULL
+#define PD0_PWM nullptr
#undef PD1
#define PD1_PIN PIND1
#define PD1_RPORT PIND
#define PD1_WPORT PORTD
#define PD1_DDR DDRD
-#define PD1_PWM NULL
+#define PD1_PWM nullptr
#undef PD2
#define PD2_PIN PIND2
#define PD2_RPORT PIND
#define PD2_WPORT PORTD
#define PD2_DDR DDRD
-#define PD2_PWM NULL
+#define PD2_PWM nullptr
#undef PD3
#define PD3_PIN PIND3
@@ -333,7 +333,7 @@
#define PD4_RPORT PIND
#define PD4_WPORT PORTD
#define PD4_DDR DDRD
-#define PD4_PWM NULL
+#define PD4_PWM nullptr
#undef PD5
#define PD5_PIN PIND5
@@ -354,4 +354,4 @@
#define PD7_RPORT PIND
#define PD7_WPORT PORTD
#define PD7_DDR DDRD
-#define PD7_PWM NULL
+#define PD7_PWM nullptr
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_644.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
similarity index 83%
rename from Marlin/src/HAL/HAL_AVR/fastio_644.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
index bcd825d24c1b..180a3c4e3202 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
@@ -91,462 +91,462 @@
#define DIO0_RPORT PINB
#define DIO0_WPORT PORTB
#define DIO0_DDR DDRB
-#define DIO0_PWM NULL
+#define DIO0_PWM nullptr
#define DIO1_PIN PINB1
#define DIO1_RPORT PINB
#define DIO1_WPORT PORTB
#define DIO1_DDR DDRB
-#define DIO1_PWM NULL
+#define DIO1_PWM nullptr
#define DIO2_PIN PINB2
#define DIO2_RPORT PINB
#define DIO2_WPORT PORTB
#define DIO2_DDR DDRB
-#define DIO2_PWM NULL
+#define DIO2_PWM nullptr
#define DIO3_PIN PINB3
#define DIO3_RPORT PINB
#define DIO3_WPORT PORTB
#define DIO3_DDR DDRB
-#define DIO3_PWM OCR0A
+#define DIO3_PWM &OCR0A
#define DIO4_PIN PINB4
#define DIO4_RPORT PINB
#define DIO4_WPORT PORTB
#define DIO4_DDR DDRB
-#define DIO4_PWM OCR0B
+#define DIO4_PWM &OCR0B
#define DIO5_PIN PINB5
#define DIO5_RPORT PINB
#define DIO5_WPORT PORTB
#define DIO5_DDR DDRB
-#define DIO5_PWM NULL
+#define DIO5_PWM nullptr
#define DIO6_PIN PINB6
#define DIO6_RPORT PINB
#define DIO6_WPORT PORTB
#define DIO6_DDR DDRB
-#define DIO6_PWM NULL
+#define DIO6_PWM nullptr
#define DIO7_PIN PINB7
#define DIO7_RPORT PINB
#define DIO7_WPORT PORTB
#define DIO7_DDR DDRB
-#define DIO7_PWM NULL
+#define DIO7_PWM nullptr
#define DIO8_PIN PIND0
#define DIO8_RPORT PIND
#define DIO8_WPORT PORTD
#define DIO8_DDR DDRD
-#define DIO8_PWM NULL
+#define DIO8_PWM nullptr
#define DIO9_PIN PIND1
#define DIO9_RPORT PIND
#define DIO9_WPORT PORTD
#define DIO9_DDR DDRD
-#define DIO9_PWM NULL
+#define DIO9_PWM nullptr
#define DIO10_PIN PIND2
#define DIO10_RPORT PIND
#define DIO10_WPORT PORTD
#define DIO10_DDR DDRD
-#define DIO10_PWM NULL
+#define DIO10_PWM nullptr
#define DIO11_PIN PIND3
#define DIO11_RPORT PIND
#define DIO11_WPORT PORTD
#define DIO11_DDR DDRD
-#define DIO11_PWM NULL
+#define DIO11_PWM nullptr
#define DIO12_PIN PIND4
#define DIO12_RPORT PIND
#define DIO12_WPORT PORTD
#define DIO12_DDR DDRD
-#define DIO12_PWM OCR1B
+#define DIO12_PWM &OCR1B
#define DIO13_PIN PIND5
#define DIO13_RPORT PIND
#define DIO13_WPORT PORTD
#define DIO13_DDR DDRD
-#define DIO13_PWM OCR1A
+#define DIO13_PWM &OCR1A
#define DIO14_PIN PIND6
#define DIO14_RPORT PIND
#define DIO14_WPORT PORTD
#define DIO14_DDR DDRD
-#define DIO14_PWM OCR2B
+#define DIO14_PWM &OCR2B
#define DIO15_PIN PIND7
#define DIO15_RPORT PIND
#define DIO15_WPORT PORTD
#define DIO15_DDR DDRD
-#define DIO15_PWM OCR2A
+#define DIO15_PWM &OCR2A
#define DIO16_PIN PINC0
#define DIO16_RPORT PINC
#define DIO16_WPORT PORTC
#define DIO16_DDR DDRC
-#define DIO16_PWM NULL
+#define DIO16_PWM nullptr
#define DIO17_PIN PINC1
#define DIO17_RPORT PINC
#define DIO17_WPORT PORTC
#define DIO17_DDR DDRC
-#define DIO17_PWM NULL
+#define DIO17_PWM nullptr
#define DIO18_PIN PINC2
#define DIO18_RPORT PINC
#define DIO18_WPORT PORTC
#define DIO18_DDR DDRC
-#define DIO18_PWM NULL
+#define DIO18_PWM nullptr
#define DIO19_PIN PINC3
#define DIO19_RPORT PINC
#define DIO19_WPORT PORTC
#define DIO19_DDR DDRC
-#define DIO19_PWM NULL
+#define DIO19_PWM nullptr
#define DIO20_PIN PINC4
#define DIO20_RPORT PINC
#define DIO20_WPORT PORTC
#define DIO20_DDR DDRC
-#define DIO20_PWM NULL
+#define DIO20_PWM nullptr
#define DIO21_PIN PINC5
#define DIO21_RPORT PINC
#define DIO21_WPORT PORTC
#define DIO21_DDR DDRC
-#define DIO21_PWM NULL
+#define DIO21_PWM nullptr
#define DIO22_PIN PINC6
#define DIO22_RPORT PINC
#define DIO22_WPORT PORTC
#define DIO22_DDR DDRC
-#define DIO22_PWM NULL
+#define DIO22_PWM nullptr
#define DIO23_PIN PINC7
#define DIO23_RPORT PINC
#define DIO23_WPORT PORTC
#define DIO23_DDR DDRC
-#define DIO23_PWM NULL
+#define DIO23_PWM nullptr
#define DIO24_PIN PINA7
#define DIO24_RPORT PINA
#define DIO24_WPORT PORTA
#define DIO24_DDR DDRA
-#define DIO24_PWM NULL
+#define DIO24_PWM nullptr
#define DIO25_PIN PINA6
#define DIO25_RPORT PINA
#define DIO25_WPORT PORTA
#define DIO25_DDR DDRA
-#define DIO25_PWM NULL
+#define DIO25_PWM nullptr
#define DIO26_PIN PINA5
#define DIO26_RPORT PINA
#define DIO26_WPORT PORTA
#define DIO26_DDR DDRA
-#define DIO26_PWM NULL
+#define DIO26_PWM nullptr
#define DIO27_PIN PINA4
#define DIO27_RPORT PINA
#define DIO27_WPORT PORTA
#define DIO27_DDR DDRA
-#define DIO27_PWM NULL
+#define DIO27_PWM nullptr
#define DIO28_PIN PINA3
#define DIO28_RPORT PINA
#define DIO28_WPORT PORTA
#define DIO28_DDR DDRA
-#define DIO28_PWM NULL
+#define DIO28_PWM nullptr
#define DIO29_PIN PINA2
#define DIO29_RPORT PINA
#define DIO29_WPORT PORTA
#define DIO29_DDR DDRA
-#define DIO29_PWM NULL
+#define DIO29_PWM nullptr
#define DIO30_PIN PINA1
#define DIO30_RPORT PINA
#define DIO30_WPORT PORTA
#define DIO30_DDR DDRA
-#define DIO30_PWM NULL
+#define DIO30_PWM nullptr
#define DIO31_PIN PINA0
#define DIO31_RPORT PINA
#define DIO31_WPORT PORTA
#define DIO31_DDR DDRA
-#define DIO31_PWM NULL
+#define DIO31_PWM nullptr
#define AIO0_PIN PINA0
#define AIO0_RPORT PINA
#define AIO0_WPORT PORTA
#define AIO0_DDR DDRA
-#define AIO0_PWM NULL
+#define AIO0_PWM nullptr
#define AIO1_PIN PINA1
#define AIO1_RPORT PINA
#define AIO1_WPORT PORTA
#define AIO1_DDR DDRA
-#define AIO1_PWM NULL
+#define AIO1_PWM nullptr
#define AIO2_PIN PINA2
#define AIO2_RPORT PINA
#define AIO2_WPORT PORTA
#define AIO2_DDR DDRA
-#define AIO2_PWM NULL
+#define AIO2_PWM nullptr
#define AIO3_PIN PINA3
#define AIO3_RPORT PINA
#define AIO3_WPORT PORTA
#define AIO3_DDR DDRA
-#define AIO3_PWM NULL
+#define AIO3_PWM nullptr
#define AIO4_PIN PINA4
#define AIO4_RPORT PINA
#define AIO4_WPORT PORTA
#define AIO4_DDR DDRA
-#define AIO4_PWM NULL
+#define AIO4_PWM nullptr
#define AIO5_PIN PINA5
#define AIO5_RPORT PINA
#define AIO5_WPORT PORTA
#define AIO5_DDR DDRA
-#define AIO5_PWM NULL
+#define AIO5_PWM nullptr
#define AIO6_PIN PINA6
#define AIO6_RPORT PINA
#define AIO6_WPORT PORTA
#define AIO6_DDR DDRA
-#define AIO6_PWM NULL
+#define AIO6_PWM nullptr
#define AIO7_PIN PINA7
#define AIO7_RPORT PINA
#define AIO7_WPORT PORTA
#define AIO7_DDR DDRA
-#define AIO7_PWM NULL
+#define AIO7_PWM nullptr
#undef PA0
#define PA0_PIN PINA0
#define PA0_RPORT PINA
#define PA0_WPORT PORTA
#define PA0_DDR DDRA
-#define PA0_PWM NULL
+#define PA0_PWM nullptr
#undef PA1
#define PA1_PIN PINA1
#define PA1_RPORT PINA
#define PA1_WPORT PORTA
#define PA1_DDR DDRA
-#define PA1_PWM NULL
+#define PA1_PWM nullptr
#undef PA2
#define PA2_PIN PINA2
#define PA2_RPORT PINA
#define PA2_WPORT PORTA
#define PA2_DDR DDRA
-#define PA2_PWM NULL
+#define PA2_PWM nullptr
#undef PA3
#define PA3_PIN PINA3
#define PA3_RPORT PINA
#define PA3_WPORT PORTA
#define PA3_DDR DDRA
-#define PA3_PWM NULL
+#define PA3_PWM nullptr
#undef PA4
#define PA4_PIN PINA4
#define PA4_RPORT PINA
#define PA4_WPORT PORTA
#define PA4_DDR DDRA
-#define PA4_PWM NULL
+#define PA4_PWM nullptr
#undef PA5
#define PA5_PIN PINA5
#define PA5_RPORT PINA
#define PA5_WPORT PORTA
#define PA5_DDR DDRA
-#define PA5_PWM NULL
+#define PA5_PWM nullptr
#undef PA6
#define PA6_PIN PINA6
#define PA6_RPORT PINA
#define PA6_WPORT PORTA
#define PA6_DDR DDRA
-#define PA6_PWM NULL
+#define PA6_PWM nullptr
#undef PA7
#define PA7_PIN PINA7
#define PA7_RPORT PINA
#define PA7_WPORT PORTA
#define PA7_DDR DDRA
-#define PA7_PWM NULL
+#define PA7_PWM nullptr
#undef PB0
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
#define PB0_DDR DDRB
-#define PB0_PWM NULL
+#define PB0_PWM nullptr
#undef PB1
#define PB1_PIN PINB1
#define PB1_RPORT PINB
#define PB1_WPORT PORTB
#define PB1_DDR DDRB
-#define PB1_PWM NULL
+#define PB1_PWM nullptr
#undef PB2
#define PB2_PIN PINB2
#define PB2_RPORT PINB
#define PB2_WPORT PORTB
#define PB2_DDR DDRB
-#define PB2_PWM NULL
+#define PB2_PWM nullptr
#undef PB3
#define PB3_PIN PINB3
#define PB3_RPORT PINB
#define PB3_WPORT PORTB
#define PB3_DDR DDRB
-#define PB3_PWM OCR0A
+#define PB3_PWM &OCR0A
#undef PB4
#define PB4_PIN PINB4
#define PB4_RPORT PINB
#define PB4_WPORT PORTB
#define PB4_DDR DDRB
-#define PB4_PWM OCR0B
+#define PB4_PWM &OCR0B
#undef PB5
#define PB5_PIN PINB5
#define PB5_RPORT PINB
#define PB5_WPORT PORTB
#define PB5_DDR DDRB
-#define PB5_PWM NULL
+#define PB5_PWM nullptr
#undef PB6
#define PB6_PIN PINB6
#define PB6_RPORT PINB
#define PB6_WPORT PORTB
#define PB6_DDR DDRB
-#define PB6_PWM NULL
+#define PB6_PWM nullptr
#undef PB7
#define PB7_PIN PINB7
#define PB7_RPORT PINB
#define PB7_WPORT PORTB
#define PB7_DDR DDRB
-#define PB7_PWM NULL
+#define PB7_PWM nullptr
#undef PC0
#define PC0_PIN PINC0
#define PC0_RPORT PINC
#define PC0_WPORT PORTC
#define PC0_DDR DDRC
-#define PC0_PWM NULL
+#define PC0_PWM nullptr
#undef PC1
#define PC1_PIN PINC1
#define PC1_RPORT PINC
#define PC1_WPORT PORTC
#define PC1_DDR DDRC
-#define PC1_PWM NULL
+#define PC1_PWM nullptr
#undef PC2
#define PC2_PIN PINC2
#define PC2_RPORT PINC
#define PC2_WPORT PORTC
#define PC2_DDR DDRC
-#define PC2_PWM NULL
+#define PC2_PWM nullptr
#undef PC3
#define PC3_PIN PINC3
#define PC3_RPORT PINC
#define PC3_WPORT PORTC
#define PC3_DDR DDRC
-#define PC3_PWM NULL
+#define PC3_PWM nullptr
#undef PC4
#define PC4_PIN PINC4
#define PC4_RPORT PINC
#define PC4_WPORT PORTC
#define PC4_DDR DDRC
-#define PC4_PWM NULL
+#define PC4_PWM nullptr
#undef PC5
#define PC5_PIN PINC5
#define PC5_RPORT PINC
#define PC5_WPORT PORTC
#define PC5_DDR DDRC
-#define PC5_PWM NULL
+#define PC5_PWM nullptr
#undef PC6
#define PC6_PIN PINC6
#define PC6_RPORT PINC
#define PC6_WPORT PORTC
#define PC6_DDR DDRC
-#define PC6_PWM NULL
+#define PC6_PWM nullptr
#undef PC7
#define PC7_PIN PINC7
#define PC7_RPORT PINC
#define PC7_WPORT PORTC
#define PC7_DDR DDRC
-#define PC7_PWM NULL
+#define PC7_PWM nullptr
#undef PD0
#define PD0_PIN PIND0
#define PD0_RPORT PIND
#define PD0_WPORT PORTD
#define PD0_DDR DDRD
-#define PD0_PWM NULL
+#define PD0_PWM nullptr
#undef PD1
#define PD1_PIN PIND1
#define PD1_RPORT PIND
#define PD1_WPORT PORTD
#define PD1_DDR DDRD
-#define PD1_PWM NULL
+#define PD1_PWM nullptr
#undef PD2
#define PD2_PIN PIND2
#define PD2_RPORT PIND
#define PD2_WPORT PORTD
#define PD2_DDR DDRD
-#define PD2_PWM NULL
+#define PD2_PWM nullptr
#undef PD3
#define PD3_PIN PIND3
#define PD3_RPORT PIND
#define PD3_WPORT PORTD
#define PD3_DDR DDRD
-#define PD3_PWM NULL
+#define PD3_PWM nullptr
#undef PD4
#define PD4_PIN PIND4
#define PD4_RPORT PIND
#define PD4_WPORT PORTD
#define PD4_DDR DDRD
-#define PD4_PWM NULL
+#define PD4_PWM nullptr
#undef PD5
#define PD5_PIN PIND5
#define PD5_RPORT PIND
#define PD5_WPORT PORTD
#define PD5_DDR DDRD
-#define PD5_PWM NULL
+#define PD5_PWM nullptr
#undef PD6
#define PD6_PIN PIND6
#define PD6_RPORT PIND
#define PD6_WPORT PORTD
#define PD6_DDR DDRD
-#define PD6_PWM OCR2B
+#define PD6_PWM &OCR2B
#undef PD7
#define PD7_PIN PIND7
#define PD7_RPORT PIND
#define PD7_WPORT PORTD
#define PD7_DDR DDRD
-#define PD7_PWM OCR2A
+#define PD7_PWM &OCR2A
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
similarity index 81%
rename from Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
index 805c0daf73cb..3f17a2e26109 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 */
@@ -45,325 +45,325 @@
#define DIO0_PIN PIND0
#define DIO0_RPORT PIND
#define DIO0_WPORT PORTD
-#define DIO0_PWM NULL
+#define DIO0_PWM 0
#define DIO0_DDR DDRD
#define DIO1_PIN PIND1
#define DIO1_RPORT PIND
#define DIO1_WPORT PORTD
-#define DIO1_PWM NULL
+#define DIO1_PWM 0
#define DIO1_DDR DDRD
#define DIO2_PIN PIND2
#define DIO2_RPORT PIND
#define DIO2_WPORT PORTD
-#define DIO2_PWM NULL
+#define DIO2_PWM 0
#define DIO2_DDR DDRD
#define DIO3_PIN PIND3
#define DIO3_RPORT PIND
#define DIO3_WPORT PORTD
-#define DIO3_PWM NULL
+#define DIO3_PWM 0
#define DIO3_DDR DDRD
#define DIO4_PIN PIND4
#define DIO4_RPORT PIND
#define DIO4_WPORT PORTD
-#define DIO4_PWM NULL
+#define DIO4_PWM 0
#define DIO4_DDR DDRD
#define DIO5_PIN PIND5
#define DIO5_RPORT PIND
#define DIO5_WPORT PORTD
-#define DIO5_PWM NULL
+#define DIO5_PWM 0
#define DIO5_DDR DDRD
#define DIO6_PIN PIND6
#define DIO6_RPORT PIND
#define DIO6_WPORT PORTD
-#define DIO6_PWM NULL
+#define DIO6_PWM 0
#define DIO6_DDR DDRD
#define DIO7_PIN PIND7
#define DIO7_RPORT PIND
#define DIO7_WPORT PORTD
-#define DIO7_PWM NULL
+#define DIO7_PWM 0
#define DIO7_DDR DDRD
#define DIO8_PIN PINE0
#define DIO8_RPORT PINE
#define DIO8_WPORT PORTE
-#define DIO8_PWM NULL
+#define DIO8_PWM 0
#define DIO8_DDR DDRE
#define DIO9_PIN PINE1
#define DIO9_RPORT PINE
#define DIO9_WPORT PORTE
-#define DIO9_PWM NULL
+#define DIO9_PWM 0
#define DIO9_DDR DDRE
#define DIO10_PIN PINC0
#define DIO10_RPORT PINC
#define DIO10_WPORT PORTC
-#define DIO10_PWM NULL
+#define DIO10_PWM 0
#define DIO10_DDR DDRC
#define DIO11_PIN PINC1
#define DIO11_RPORT PINC
#define DIO11_WPORT PORTC
-#define DIO11_PWM NULL
+#define DIO11_PWM 0
#define DIO11_DDR DDRC
#define DIO12_PIN PINC2
#define DIO12_RPORT PINC
#define DIO12_WPORT PORTC
-#define DIO12_PWM NULL
+#define DIO12_PWM 0
#define DIO12_DDR DDRC
#define DIO13_PIN PINC3
#define DIO13_RPORT PINC
#define DIO13_WPORT PORTC
-#define DIO13_PWM NULL
+#define DIO13_PWM 0
#define DIO13_DDR DDRC
#define DIO14_PIN PINC4
#define DIO14_RPORT PINC
#define DIO14_WPORT PORTC
-#define DIO14_PWM NULL
+#define DIO14_PWM 0 // OC3C
#define DIO14_DDR DDRC
#define DIO15_PIN PINC5
#define DIO15_RPORT PINC
#define DIO15_WPORT PORTC
-#define DIO15_PWM NULL
+#define DIO15_PWM 0 // OC3B
#define DIO15_DDR DDRC
#define DIO16_PIN PINC6
#define DIO16_RPORT PINC
#define DIO16_WPORT PORTC
-#define DIO16_PWM NULL
+#define DIO16_PWM 0 // OC3A
#define DIO16_DDR DDRC
#define DIO17_PIN PINC7
#define DIO17_RPORT PINC
#define DIO17_WPORT PORTC
-#define DIO17_PWM NULL
+#define DIO17_PWM 0
#define DIO17_DDR DDRC
#define DIO18_PIN PINE6
#define DIO18_RPORT PINE
#define DIO18_WPORT PORTE
-#define DIO18_PWM NULL
+#define DIO18_PWM 0
#define DIO18_DDR DDRE
#define DIO19_PIN PINE7
#define DIO19_RPORT PINE
#define DIO19_WPORT PORTE
-#define DIO19_PWM NULL
+#define DIO19_PWM 0
#define DIO19_DDR DDRE
#define DIO20_PIN PINB0
#define DIO20_RPORT PINB
#define DIO20_WPORT PORTB
-#define DIO20_PWM NULL
+#define DIO20_PWM 0
#define DIO20_DDR DDRB
#define DIO21_PIN PINB1
#define DIO21_RPORT PINB
#define DIO21_WPORT PORTB
-#define DIO21_PWM NULL
+#define DIO21_PWM 0
#define DIO21_DDR DDRB
#define DIO22_PIN PINB2
#define DIO22_RPORT PINB
#define DIO22_WPORT PORTB
-#define DIO22_PWM NULL
+#define DIO22_PWM 0
#define DIO22_DDR DDRB
#define DIO23_PIN PINB3
#define DIO23_RPORT PINB
#define DIO23_WPORT PORTB
-#define DIO23_PWM NULL
+#define DIO23_PWM 0
#define DIO23_DDR DDRB
#define DIO24_PIN PINB4
#define DIO24_RPORT PINB
#define DIO24_WPORT PORTB
-#define DIO24_PWM NULL
+#define DIO24_PWM 0 // OC2A
#define DIO24_DDR DDRB
#define DIO25_PIN PINB5
#define DIO25_RPORT PINB
#define DIO25_WPORT PORTB
-#define DIO25_PWM NULL
+#define DIO25_PWM 0 // OC1A
#define DIO25_DDR DDRB
#define DIO26_PIN PINB6
#define DIO26_RPORT PINB
#define DIO26_WPORT PORTB
-#define DIO26_PWM NULL
+#define DIO26_PWM 0 // OC1B
#define DIO26_DDR DDRB
#define DIO27_PIN PINB7
#define DIO27_RPORT PINB
#define DIO27_WPORT PORTB
-#define DIO27_PWM NULL
+#define DIO27_PWM 0 // OC1C
#define DIO27_DDR DDRB
#define DIO28_PIN PINA0
#define DIO28_RPORT PINA
#define DIO28_WPORT PORTA
-#define DIO28_PWM NULL
+#define DIO28_PWM 0
#define DIO28_DDR DDRA
#define DIO29_PIN PINA1
#define DIO29_RPORT PINA
#define DIO29_WPORT PORTA
-#define DIO29_PWM NULL
+#define DIO29_PWM 0
#define DIO29_DDR DDRA
#define DIO30_PIN PINA2
#define DIO30_RPORT PINA
#define DIO30_WPORT PORTA
-#define DIO30_PWM NULL
+#define DIO30_PWM 0
#define DIO30_DDR DDRA
#define DIO31_PIN PINA3
#define DIO31_RPORT PINA
#define DIO31_WPORT PORTA
-#define DIO31_PWM NULL
+#define DIO31_PWM 0
#define DIO31_DDR DDRA
#define DIO32_PIN PINA4
#define DIO32_RPORT PINA
#define DIO32_WPORT PORTA
-#define DIO32_PWM NULL
+#define DIO32_PWM 0
#define DIO32_DDR DDRA
#define DIO33_PIN PINA5
#define DIO33_RPORT PINA
#define DIO33_WPORT PORTA
-#define DIO33_PWM NULL
+#define DIO33_PWM 0
#define DIO33_DDR DDRA
#define DIO34_PIN PINA6
#define DIO34_RPORT PINA
#define DIO34_WPORT PORTA
-#define DIO34_PWM NULL
+#define DIO34_PWM 0
#define DIO34_DDR DDRA
#define DIO35_PIN PINA7
#define DIO35_RPORT PINA
#define DIO35_WPORT PORTA
-#define DIO35_PWM NULL
+#define DIO35_PWM 0
#define DIO35_DDR DDRA
#define DIO36_PIN PINE4
#define DIO36_RPORT PINE
#define DIO36_WPORT PORTE
-#define DIO36_PWM NULL
+#define DIO36_PWM 0
#define DIO36_DDR DDRE
#define DIO37_PIN PINE5
#define DIO37_RPORT PINE
#define DIO37_WPORT PORTE
-#define DIO37_PWM NULL
+#define DIO37_PWM 0
#define DIO37_DDR DDRE
#define DIO38_PIN PINF0
#define DIO38_RPORT PINF
#define DIO38_WPORT PORTF
-#define DIO38_PWM NULL
+#define DIO38_PWM 0
#define DIO38_DDR DDRF
#define DIO39_PIN PINF1
#define DIO39_RPORT PINF
#define DIO39_WPORT PORTF
-#define DIO39_PWM NULL
+#define DIO39_PWM 0
#define DIO39_DDR DDRF
#define DIO40_PIN PINF2
#define DIO40_RPORT PINF
#define DIO40_WPORT PORTF
-#define DIO40_PWM NULL
+#define DIO40_PWM 0
#define DIO40_DDR DDRF
#define DIO41_PIN PINF3
#define DIO41_RPORT PINF
#define DIO41_WPORT PORTF
-#define DIO41_PWM NULL
+#define DIO41_PWM 0
#define DIO41_DDR DDRF
#define DIO42_PIN PINF4
#define DIO42_RPORT PINF
#define DIO42_WPORT PORTF
-#define DIO42_PWM NULL
+#define DIO42_PWM 0
#define DIO42_DDR DDRF
#define DIO43_PIN PINF5
#define DIO43_RPORT PINF
#define DIO43_WPORT PORTF
-#define DIO43_PWM NULL
+#define DIO43_PWM 0
#define DIO43_DDR DDRF
#define DIO44_PIN PINF6
#define DIO44_RPORT PINF
#define DIO44_WPORT PORTF
-#define DIO44_PWM NULL
+#define DIO44_PWM 0
#define DIO44_DDR DDRF
#define DIO45_PIN PINF7
#define DIO45_RPORT PINF
#define DIO45_WPORT PORTF
-#define DIO45_PWM NULL
+#define DIO45_PWM 0
#define DIO45_DDR DDRF
#define AIO0_PIN PINF0
#define AIO0_RPORT PINF
#define AIO0_WPORT PORTF
-#define AIO0_PWM NULL
+#define AIO0_PWM 0
#define AIO0_DDR DDRF
#define AIO1_PIN PINF1
#define AIO1_RPORT PINF
#define AIO1_WPORT PORTF
-#define AIO1_PWM NULL
+#define AIO1_PWM 0
#define AIO1_DDR DDRF
#define AIO2_PIN PINF2
#define AIO2_RPORT PINF
#define AIO2_WPORT PORTF
-#define AIO2_PWM NULL
+#define AIO2_PWM 0
#define AIO2_DDR DDRF
#define AIO3_PIN PINF3
#define AIO3_RPORT PINF
#define AIO3_WPORT PORTF
-#define AIO3_PWM NULL
+#define AIO3_PWM 0
#define AIO3_DDR DDRF
#define AIO4_PIN PINF4
#define AIO4_RPORT PINF
#define AIO4_WPORT PORTF
-#define AIO4_PWM NULL
+#define AIO4_PWM 0
#define AIO4_DDR DDRF
#define AIO5_PIN PINF5
#define AIO5_RPORT PINF
#define AIO5_WPORT PORTF
-#define AIO5_PWM NULL
+#define AIO5_PWM 0
#define AIO5_DDR DDRF
#define AIO6_PIN PINF6
#define AIO6_RPORT PINF
#define AIO6_WPORT PORTF
-#define AIO6_PWM NULL
+#define AIO6_PWM 0
#define AIO6_DDR DDRF
#define AIO7_PIN PINF7
#define AIO7_RPORT PINF
#define AIO7_WPORT PORTF
-#define AIO7_PWM NULL
+#define AIO7_PWM 0
#define AIO7_DDR DDRF
//-- Begin not supported by Teensyduino
@@ -371,13 +371,13 @@
#define DIO46_PIN PINE2
#define DIO46_RPORT PINE
#define DIO46_WPORT PORTE
-#define DIO46_PWM NULL
+#define DIO46_PWM 0
#define DIO46_DDR DDRE
#define DIO47_PIN PINE3
#define DIO47_RPORT PINE
#define DIO47_WPORT PORTE
-#define DIO47_PWM NULL
+#define DIO47_PWM 0
#define DIO47_DDR DDRE
#define TEENSY_E2 46
@@ -389,300 +389,300 @@
#define PA0_PIN PINA0
#define PA0_RPORT PINA
#define PA0_WPORT PORTA
-#define PA0_PWM NULL
+#define PA0_PWM 0
#define PA0_DDR DDRA
#undef PA1
#define PA1_PIN PINA1
#define PA1_RPORT PINA
#define PA1_WPORT PORTA
-#define PA1_PWM NULL
+#define PA1_PWM 0
#define PA1_DDR DDRA
#undef PA2
#define PA2_PIN PINA2
#define PA2_RPORT PINA
#define PA2_WPORT PORTA
-#define PA2_PWM NULL
+#define PA2_PWM 0
#define PA2_DDR DDRA
#undef PA3
#define PA3_PIN PINA3
#define PA3_RPORT PINA
#define PA3_WPORT PORTA
-#define PA3_PWM NULL
+#define PA3_PWM 0
#define PA3_DDR DDRA
#undef PA4
#define PA4_PIN PINA4
#define PA4_RPORT PINA
#define PA4_WPORT PORTA
-#define PA4_PWM NULL
+#define PA4_PWM 0
#define PA4_DDR DDRA
#undef PA5
#define PA5_PIN PINA5
#define PA5_RPORT PINA
#define PA5_WPORT PORTA
-#define PA5_PWM NULL
+#define PA5_PWM 0
#define PA5_DDR DDRA
#undef PA6
#define PA6_PIN PINA6
#define PA6_RPORT PINA
#define PA6_WPORT PORTA
-#define PA6_PWM NULL
+#define PA6_PWM 0
#define PA6_DDR DDRA
#undef PA7
#define PA7_PIN PINA7
#define PA7_RPORT PINA
#define PA7_WPORT PORTA
-#define PA7_PWM NULL
+#define PA7_PWM 0
#define PA7_DDR DDRA
#undef PB0
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
-#define PB0_PWM NULL
+#define PB0_PWM 0
#define PB0_DDR DDRB
#undef PB1
#define PB1_PIN PINB1
#define PB1_RPORT PINB
#define PB1_WPORT PORTB
-#define PB1_PWM NULL
+#define PB1_PWM 0
#define PB1_DDR DDRB
#undef PB2
#define PB2_PIN PINB2
#define PB2_RPORT PINB
#define PB2_WPORT PORTB
-#define PB2_PWM NULL
+#define PB2_PWM 0
#define PB2_DDR DDRB
#undef PB3
#define PB3_PIN PINB3
#define PB3_RPORT PINB
#define PB3_WPORT PORTB
-#define PB3_PWM NULL
+#define PB3_PWM 0
#define PB3_DDR DDRB
#undef PB4
#define PB4_PIN PINB4
#define PB4_RPORT PINB
#define PB4_WPORT PORTB
-#define PB4_PWM NULL
+#define PB4_PWM 0
#define PB4_DDR DDRB
#undef PB5
#define PB5_PIN PINB5
#define PB5_RPORT PINB
#define PB5_WPORT PORTB
-#define PB5_PWM NULL
+#define PB5_PWM 0
#define PB5_DDR DDRB
#undef PB6
#define PB6_PIN PINB6
#define PB6_RPORT PINB
#define PB6_WPORT PORTB
-#define PB6_PWM NULL
+#define PB6_PWM 0
#define PB6_DDR DDRB
#undef PB7
#define PB7_PIN PINB7
#define PB7_RPORT PINB
#define PB7_WPORT PORTB
-#define PB7_PWM NULL
+#define PB7_PWM 0
#define PB7_DDR DDRB
#undef PC0
#define PC0_PIN PINC0
#define PC0_RPORT PINC
#define PC0_WPORT PORTC
-#define PC0_PWM NULL
+#define PC0_PWM 0
#define PC0_DDR DDRC
#undef PC1
#define PC1_PIN PINC1
#define PC1_RPORT PINC
#define PC1_WPORT PORTC
-#define PC1_PWM NULL
+#define PC1_PWM 0
#define PC1_DDR DDRC
#undef PC2
#define PC2_PIN PINC2
#define PC2_RPORT PINC
#define PC2_WPORT PORTC
-#define PC2_PWM NULL
+#define PC2_PWM 0
#define PC2_DDR DDRC
#undef PC3
#define PC3_PIN PINC3
#define PC3_RPORT PINC
#define PC3_WPORT PORTC
-#define PC3_PWM NULL
+#define PC3_PWM 0
#define PC3_DDR DDRC
#undef PC4
#define PC4_PIN PINC4
#define PC4_RPORT PINC
#define PC4_WPORT PORTC
-#define PC4_PWM NULL
+#define PC4_PWM 0
#define PC4_DDR DDRC
#undef PC5
#define PC5_PIN PINC5
#define PC5_RPORT PINC
#define PC5_WPORT PORTC
-#define PC5_PWM NULL
+#define PC5_PWM 0
#define PC5_DDR DDRC
#undef PC6
#define PC6_PIN PINC6
#define PC6_RPORT PINC
#define PC6_WPORT PORTC
-#define PC6_PWM NULL
+#define PC6_PWM 0
#define PC6_DDR DDRC
#undef PC7
#define PC7_PIN PINC7
#define PC7_RPORT PINC
#define PC7_WPORT PORTC
-#define PC7_PWM NULL
+#define PC7_PWM 0
#define PC7_DDR DDRC
#undef PD0
#define PD0_PIN PIND0
#define PD0_RPORT PIND
#define PD0_WPORT PORTD
-#define PD0_PWM NULL
+#define PD0_PWM 0 // OC0B
#define PD0_DDR DDRD
#undef PD1
#define PD1_PIN PIND1
#define PD1_RPORT PIND
#define PD1_WPORT PORTD
-#define PD1_PWM NULL
+#define PD1_PWM 0 // OC2B
#define PD1_DDR DDRD
#undef PD2
#define PD2_PIN PIND2
#define PD2_RPORT PIND
#define PD2_WPORT PORTD
-#define PD2_PWM NULL
+#define PD2_PWM 0
#define PD2_DDR DDRD
#undef PD3
#define PD3_PIN PIND3
#define PD3_RPORT PIND
#define PD3_WPORT PORTD
-#define PD3_PWM NULL
+#define PD3_PWM 0
#define PD3_DDR DDRD
#undef PD4
#define PD4_PIN PIND4
#define PD4_RPORT PIND
#define PD4_WPORT PORTD
-#define PD4_PWM NULL
+#define PD4_PWM 0
#define PD4_DDR DDRD
#undef PD5
#define PD5_PIN PIND5
#define PD5_RPORT PIND
#define PD5_WPORT PORTD
-#define PD5_PWM NULL
+#define PD5_PWM 0
#define PD5_DDR DDRD
#undef PD6
#define PD6_PIN PIND6
#define PD6_RPORT PIND
#define PD6_WPORT PORTD
-#define PD6_PWM NULL
+#define PD6_PWM 0
#define PD6_DDR DDRD
#undef PD7
#define PD7_PIN PIND7
#define PD7_RPORT PIND
#define PD7_WPORT PORTD
-#define PD7_PWM NULL
+#define PD7_PWM 0
#define PD7_DDR DDRD
#undef PE0
#define PE0_PIN PINE0
#define PE0_RPORT PINE
#define PE0_WPORT PORTE
-#define PE0_PWM NULL
+#define PE0_PWM 0
#define PE0_DDR DDRE
#undef PE1
#define PE1_PIN PINE1
#define PE1_RPORT PINE
#define PE1_WPORT PORTE
-#define PE1_PWM NULL
+#define PE1_PWM 0
#define PE1_DDR DDRE
#undef PE2
#define PE2_PIN PINE2
#define PE2_RPORT PINE
#define PE2_WPORT PORTE
-#define PE2_PWM NULL
+#define PE2_PWM 0
#define PE2_DDR DDRE
#undef PE3
#define PE3_PIN PINE3
#define PE3_RPORT PINE
#define PE3_WPORT PORTE
-#define PE3_PWM NULL
+#define PE3_PWM 0
#define PE3_DDR DDRE
#undef PE4
#define PE4_PIN PINE4
#define PE4_RPORT PINE
#define PE4_WPORT PORTE
-#define PE4_PWM NULL
+#define PE4_PWM 0
#define PE4_DDR DDRE
#undef PE5
#define PE5_PIN PINE5
#define PE5_RPORT PINE
#define PE5_WPORT PORTE
-#define PE5_PWM NULL
+#define PE5_PWM 0
#define PE5_DDR DDRE
#undef PE6
#define PE6_PIN PINE6
#define PE6_RPORT PINE
#define PE6_WPORT PORTE
-#define PE6_PWM NULL
+#define PE6_PWM 0
#define PE6_DDR DDRE
#undef PE7
#define PE7_PIN PINE7
#define PE7_RPORT PINE
#define PE7_WPORT PORTE
-#define PE7_PWM NULL
+#define PE7_PWM 0
#define PE7_DDR DDRE
#undef PF0
#define PF0_PIN PINF0
#define PF0_RPORT PINF
#define PF0_WPORT PORTF
-#define PF0_PWM NULL
+#define PF0_PWM 0
#define PF0_DDR DDRF
#undef PF1
#define PF1_PIN PINF1
#define PF1_RPORT PINF
#define PF1_WPORT PORTF
-#define PF1_PWM NULL
+#define PF1_PWM 0
#define PF1_DDR DDRF
#undef PF2
#define PF2_PIN PINF2
#define PF2_RPORT PINF
#define PF2_WPORT PORTF
-#define PF2_PWM NULL
+#define PF2_PWM 0
#define PF2_DDR DDRF
#undef PF3
#define PF3_PIN PINF3
#define PF3_RPORT PINF
#define PF3_WPORT PORTF
-#define PF3_PWM NULL
+#define PF3_PWM 0
#define PF3_DDR DDRF
#undef PF4
#define PF4_PIN PINF4
#define PF4_RPORT PINF
#define PF4_WPORT PORTF
-#define PF4_PWM NULL
+#define PF4_PWM 0
#define PF4_DDR DDRF
#undef PF5
#define PF5_PIN PINF5
#define PF5_RPORT PINF
#define PF5_WPORT PORTF
-#define PF5_PWM NULL
+#define PF5_PWM 0
#define PF5_DDR DDRF
#undef PF6
#define PF6_PIN PINF6
#define PF6_RPORT PINF
#define PF6_WPORT PORTF
-#define PF6_PWM NULL
+#define PF6_PWM 0
#define PF6_DDR DDRF
#undef PF7
#define PF7_PIN PINF7
#define PF7_RPORT PINF
#define PF7_WPORT PORTF
-#define PF7_PWM NULL
+#define PF7_PWM 0
#define PF7_DDR DDRF
/**
- * some of the pin mapping functions of the Teensduino extension to the Arduino IDE
- * do not function the same as the other Arduino extensions
+ * Some of the pin mapping functions of the Teensduino extension to the Arduino IDE
+ * do not function the same as the other Arduino extensions.
*/
//digitalPinToTimer(pin) function works like Arduino but Timers are not defined
diff --git a/Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
new file mode 100644
index 000000000000..85f26f40162e
--- /dev/null
+++ b/Marlin/src/HAL/HAL_AVR/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_AVR/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_adv.h
new file mode 100644
index 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..93fadf20a58f
--- /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 8299b8bbd33f..d397cc4e9a5f 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 4c2f9ea4f1c5..116a8288e21d 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 8df4ffcf8734..fa7018094764 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
@@ -356,6 +353,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 +402,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 e97d694bb08d..4388430779dc 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 028c8f02a400..e5bb82f226b5 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 85d2d8f6e5a0..c7951acfa3c2 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
new file mode 100644
index 000000000000..bc08bc379b8c
--- /dev/null
+++ b/Marlin/src/HAL/HAL_AVR/u8g_com_HAL_AVR_sw_spi.cpp
@@ -0,0 +1,193 @@
+/**
+ * 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 .
+ *
+ */
+
+/**
+ * Based on u8g_com_st7920_hw_spi.c
+ *
+ * Universal 8bit Graphics Library
+ *
+ * Copyright (c) 2011, 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.
+ */
+
+#if defined(ARDUINO) && !defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_SAM)
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if HAS_GRAPHICAL_LCD
+
+#include "../shared/Marduino.h"
+#include "../shared/Delay.h"
+
+#include
+
+uint8_t u8g_bitData, u8g_bitNotData, u8g_bitClock, u8g_bitNotClock;
+volatile uint8_t *u8g_outData, *u8g_outClock;
+
+static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin) {
+ u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
+ u8g_outClock = portOutputRegister(digitalPinToPort(clockPin));
+ u8g_bitData = digitalPinToBitMask(dataPin);
+ u8g_bitClock = digitalPinToBitMask(clockPin);
+
+ u8g_bitNotClock = u8g_bitClock;
+ u8g_bitNotClock ^= 0xFF;
+
+ u8g_bitNotData = u8g_bitData;
+ u8g_bitNotData ^= 0xFF;
+}
+
+void u8g_spiSend_sw_AVR_mode_0(uint8_t val) {
+ uint8_t bitData = u8g_bitData,
+ bitNotData = u8g_bitNotData,
+ bitClock = u8g_bitClock,
+ bitNotClock = u8g_bitNotClock;
+ volatile uint8_t *outData = u8g_outData,
+ *outClock = u8g_outClock;
+ U8G_ATOMIC_START();
+ for (uint8_t i = 0; i < 8; i++) {
+ if (val & 0x80)
+ *outData |= bitData;
+ else
+ *outData &= bitNotData;
+ *outClock |= bitClock;
+ val <<= 1;
+ *outClock &= bitNotClock;
+ }
+ U8G_ATOMIC_END();
+}
+
+void u8g_spiSend_sw_AVR_mode_3(uint8_t val) {
+ uint8_t bitData = u8g_bitData,
+ bitNotData = u8g_bitNotData,
+ bitClock = u8g_bitClock,
+ bitNotClock = u8g_bitNotClock;
+ volatile uint8_t *outData = u8g_outData,
+ *outClock = u8g_outClock;
+ U8G_ATOMIC_START();
+ for (uint8_t i = 0; i < 8; i++) {
+ *outClock &= bitNotClock;
+ if (val & 0x80)
+ *outData |= bitData;
+ else
+ *outData &= bitNotData;
+ *outClock |= bitClock;
+ val <<= 1;
+ }
+ U8G_ATOMIC_END();
+}
+
+
+#if ENABLED(FYSETC_MINI_12864)
+ #define SPISEND_SW_AVR u8g_spiSend_sw_AVR_mode_3
+#else
+ #define SPISEND_SW_AVR u8g_spiSend_sw_AVR_mode_0
+#endif
+
+uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
+ switch (msg) {
+ case U8G_COM_MSG_INIT:
+ u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
+ u8g_com_arduino_assign_pin_output_high(u8g);
+ u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, 0);
+ u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, 0);
+ break;
+
+ case U8G_COM_MSG_STOP:
+ break;
+
+ case U8G_COM_MSG_RESET:
+ if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
+ break;
+
+ case U8G_COM_MSG_CHIP_SELECT:
+ #if ENABLED(FYSETC_MINI_12864) // 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
+ u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, 1); // Set SCK to mode 3 idle state before CS goes active
+ u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
+ }
+ else {
+ u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
+ u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, 0); // Set SCK to mode 0 idle state after CS goes inactive
+ }
+ #else
+ u8g_com_arduino_digital_write(u8g, U8G_PI_CS, !arg_val);
+ #endif
+ break;
+
+ case U8G_COM_MSG_WRITE_BYTE:
+ SPISEND_SW_AVR(arg_val);
+ break;
+
+ case U8G_COM_MSG_WRITE_SEQ: {
+ uint8_t *ptr = (uint8_t *)arg_ptr;
+ while (arg_val > 0) {
+ SPISEND_SW_AVR(*ptr++);
+ arg_val--;
+ }
+ }
+ break;
+
+ case U8G_COM_MSG_WRITE_SEQ_P: {
+ uint8_t *ptr = (uint8_t *)arg_ptr;
+ while (arg_val > 0) {
+ SPISEND_SW_AVR(u8g_pgm_read(ptr));
+ ptr++;
+ arg_val--;
+ }
+ }
+ break;
+
+ case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
+ u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
+ break;
+ }
+ return 1;
+}
+
+#endif // HAS_GRAPHICAL_LCD
+#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp b/Marlin/src/HAL/HAL_AVR/watchdog.cpp
similarity index 90%
rename from Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/watchdog.cpp
index 7c65a904f4af..63a503196631 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"
@@ -38,7 +38,7 @@ void watchdog_init() {
#define WDTO_NS WDTO_4S
#endif
#if ENABLED(WATCHDOG_RESET_MANUAL)
- // We enable the watchdog timer, but only for the interrupt.
+ // Enable the watchdog timer, but only for the interrupt.
// Take care, as this requires the correct order of operation, with interrupts disabled.
// See the datasheet of any AVR chip for details.
wdt_reset();
@@ -65,7 +65,7 @@ void watchdog_init() {
SERIAL_ERROR_MSG(MSG_WATCHDOG_FIRED);
minkill(); // interrupt-safe final kill and infinite loop
}
-#endif // WATCHDOG_RESET_MANUAL
+#endif
#endif // USE_WATCHDOG
#endif // __AVR__
diff --git a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.h b/Marlin/src/HAL/HAL_AVR/watchdog.h
similarity index 89%
rename from Marlin/src/HAL/HAL_AVR/watchdog_AVR.h
rename to Marlin/src/HAL/HAL_AVR/watchdog.h
index ed5150fe0893..5190d2c55af5 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
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 89206fa94c9b..20f10ce40530 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 99%
rename from Marlin/src/HAL/HAL_DUE/EepromEmulation_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp
index 21f1a8c9d40d..3d6e22f6d38f 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
+#include "../shared/Marduino.h"
+#include "../shared/persistent_store_api.h"
#define EEPROMSize 4096
#define PagesPerGroup 128
@@ -993,7 +993,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 cefe308e816d..735ccc631767 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;
@@ -122,15 +90,15 @@ int freeMemory() {
return (int)&free_memory - (heap_end ? 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 d430e6b649fb..2be95b683ad4 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
*
@@ -29,15 +29,14 @@
#define CPU_32_BIT
-#include
-
-#include
-
+#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)
@@ -59,8 +58,8 @@
#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))
@@ -69,26 +68,15 @@
#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)))
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 8
-#define RST_JTAG 16
-#define RST_SOFTWARE 32
-#define RST_BACKUP 64
-
typedef int8_t pin_t;
+#define SHARED_SERVOS HAS_SERVOS
#define HAL_SERVO_LIB Servo
//
@@ -100,22 +88,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 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)
-//
+void cli(); // Disable interrupts
+void sei(); // Enable interrupts
-// 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
@@ -136,21 +113,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_getAdcReading(uint8_t chan);
-void HAL_startAdcConversion(uint8_t chan);
-uint8_t HAL_pinToAdcChannel(int pin);
-uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
-//uint16_t HAL_getAdcSuperSample(uint8_t chan);
-void HAL_enable_AdcFreerun(void);
-//void HAL_disable_AdcFreerun(uint8_t chan);
+uint16_t HAL_adc_get_result();
//
// Pin Map
@@ -168,20 +138,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 5adc7fcf099a..f942ff808287 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.
@@ -437,7 +428,7 @@
static void spiTxBlockX(const uint8_t* buf, uint32_t todo) {
do {
- (void) spiTransferTx(*buf++);
+ (void)spiTransferTx(*buf++);
} while (--todo);
}
@@ -551,9 +542,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 92%
rename from Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
index 446eb2884dbd..b9f14823f68c 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,21 +34,21 @@
#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
practice, we need alignment to 256 bytes to make this work in all
cases */
__attribute__ ((aligned(256)))
-static DeviceVectors ram_tab = { NULL };
+static DeviceVectors ram_tab = { nullptr };
/**
* This function checks if the exception/interrupt table is already in SRAM or not.
* 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 71de4bf52e0b..87dd04962496 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 4be9c43f4775..7b88b6d43e14 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 9b03d46f284b..92806f15b405 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 @@ class MarlinSerial {
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 @@ class MarlinSerial {
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 91%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.cpp
index 7b1100dd9dfc..1bce07e53f04 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);
};
@@ -56,12 +56,13 @@ static int pending_char = -1;
// Public Methods
void MarlinSerialUSB::begin(const long baud_setting) {
+ UNUSED(baud_setting);
}
void MarlinSerialUSB::end() {
}
-int MarlinSerialUSB::peek(void) {
+int MarlinSerialUSB::peek() {
if (pending_char >= 0)
return pending_char;
@@ -82,7 +83,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 +107,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 +115,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 +186,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 5025b822843a..3d9d4bafaadb 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 @@ class MarlinSerialUSB {
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 @@ class MarlinSerialUSB {
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 86%
rename from Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/Servo.cpp
index 848d263b7081..f48fdf57966c 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
@@ -44,31 +44,31 @@
#if HAS_SERVOS
-#include
+#include "../shared/Marduino.h"
#include "../shared/servo.h"
#include "../shared/servo_private.h"
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 8d5d0fa583b1..c32c93825399 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
@@ -87,5 +87,21 @@
#define HANDLER_FOR_TIMER5 TC0_Handler
#endif
-//typedef enum { _timer1, _timer2, _timer3, _timer4, _timer5, _Nbr_16timers } timer16_Sequence_t;
-typedef enum { _timer3, _timer5, _Nbr_16timers } timer16_Sequence_t;
+typedef enum : unsigned char {
+ #ifdef _useTimer1
+ _timer1,
+ #endif
+ #ifdef _useTimer2
+ _timer2,
+ #endif
+ #ifdef _useTimer3
+ _timer3,
+ #endif
+ #ifdef _useTimer4
+ _timer4,
+ #endif
+ #ifdef _useTimer5
+ _timer5,
+ #endif
+ _Nbr_16timers
+} timer16_Sequence_t;
diff --git a/Marlin/src/HAL/HAL_DUE/Tone.cpp b/Marlin/src/HAL/HAL_DUE/Tone.cpp
index 292be1401fe6..2af97aac611f 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 ba7700150f5c..5e5a4e5fc185 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
-#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 75%
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 3cef880bcaba..47e56fddb084 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,52 +55,28 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
-#if HAS_GRAPHICAL_LCD
+#if ENABLED(U8GLIB_ST7920)
-#include
-#include
-#include "../shared/Delay.h"
+#include "../../shared/Delay.h"
-void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
- PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
- g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration); // OUTPUT
-}
+#include
-void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
- volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
- uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
- if (level) port->PIO_SODR = mask; else port->PIO_CODR = mask;
-}
+#include "u8g_com_HAL_DUE_sw_spi_shared.h"
-Pio *SCK_pPio, *MOSI_pPio;
-uint32_t SCK_dwMask, MOSI_dwMask;
-
-static void spiSend_sw_DUE(uint8_t val) { // 800KHz
- for (uint8_t i = 0; i < 8; i++) {
- if (val & 0x80)
- MOSI_pPio->PIO_SODR = MOSI_dwMask;
- else
- MOSI_pPio->PIO_CODR = MOSI_dwMask;
- DELAY_NS(48);
- SCK_pPio->PIO_SODR = SCK_dwMask;
- DELAY_NS(905); // 762 dead, 810 garbage, 858/0 900kHz, 905/1 825k, 953/1 800k, 1000/2 725KHz
- val <<= 1;
- SCK_pPio->PIO_CODR = SCK_dwMask;
- }
-}
+#define SPISEND_SW_DUE u8g_spiSend_sw_DUE_mode_0
static uint8_t rs_last_state = 255;
static void u8g_com_DUE_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
if (rs != rs_last_state) { // time to send a command/data byte
rs_last_state = rs;
- spiSend_sw_DUE(rs ? 0x0FA : 0x0F8); // Command or Data
+ SPISEND_SW_DUE(rs ? 0x0FA : 0x0F8); // Command or Data
DELAY_US(40); // give the controller some time to process the data: 20 is bad, 30 is OK, 40 is safe
}
- spiSend_sw_DUE(val & 0xF0);
- spiSend_sw_DUE(val << 4);
+ SPISEND_SW_DUE(val & 0xF0);
+ SPISEND_SW_DUE(val << 4);
}
uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
@@ -123,7 +99,7 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
u8g_Delay(5);
- u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
+ u8g->pin_list[U8G_PI_A0_STATE] = 0; /* initial RS state: command mode */
break;
case U8G_COM_MSG_STOP:
@@ -169,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
@@ -190,20 +166,20 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
}
void ST7920_set_cmd() {
- spiSend_sw_DUE(0xF8);
+ SPISEND_SW_DUE(0xF8);
DELAY_US(40);
}
void ST7920_set_dat() {
- spiSend_sw_DUE(0xFA);
+ SPISEND_SW_DUE(0xFA);
DELAY_US(40);
}
void ST7920_write_byte(const uint8_t val) {
- spiSend_sw_DUE(val & 0xF0);
- spiSend_sw_DUE(val << 4);
+ SPISEND_SW_DUE(val & 0xF0);
+ SPISEND_SW_DUE(val << 4);
}
#endif // LIGHTWEIGHT_UI
-#endif // HAS_GRAPHICAL_LCD
+#endif // U8GLIB_ST7920
#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
new file mode 100644
index 000000000000..e078bc420f57
--- /dev/null
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
@@ -0,0 +1,148 @@
+/**
+ * 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 .
+ *
+ */
+
+/**
+ * Based on u8g_com_std_sw_spi.c
+ *
+ * Universal 8bit Graphics Library
+ *
+ * Copyright (c) 2015, 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 ARDUINO_ARCH_SAM
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#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
+
+#if ENABLED(FYSETC_MINI_12864)
+ #define SPISEND_SW_DUE u8g_spiSend_sw_DUE_mode_3
+#else
+ #define SPISEND_SW_DUE u8g_spiSend_sw_DUE_mode_0
+#endif
+
+uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
+ switch (msg) {
+ case U8G_COM_MSG_INIT:
+ SCK_pPio = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].pPort;
+ SCK_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].ulPin;
+ MOSI_pPio = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].pPort;
+ MOSI_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].ulPin;
+ u8g_SetPIOutput_DUE(u8g, U8G_PI_SCK);
+ u8g_SetPIOutput_DUE(u8g, U8G_PI_MOSI);
+ u8g_SetPIOutput_DUE(u8g, U8G_PI_CS);
+ u8g_SetPIOutput_DUE(u8g, U8G_PI_A0);
+ if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPIOutput_DUE(u8g, U8G_PI_RESET);
+ u8g_SetPILevel_DUE(u8g, U8G_PI_SCK, 0);
+ u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 0);
+ break;
+
+ case U8G_COM_MSG_STOP:
+ break;
+
+ case U8G_COM_MSG_RESET:
+ if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel_DUE(u8g, U8G_PI_RESET, arg_val);
+ break;
+
+ case U8G_COM_MSG_CHIP_SELECT:
+ #if ENABLED(FYSETC_MINI_12864) // 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
+ u8g_SetPILevel_DUE(u8g, U8G_PI_SCK, 1); //set SCK to mode 3 idle state before CS goes active
+ u8g_SetPILevel_DUE(u8g, U8G_PI_CS, LOW);
+ }
+ else {
+ u8g_SetPILevel_DUE(u8g, U8G_PI_CS, HIGH);
+ u8g_SetPILevel_DUE(u8g, U8G_PI_SCK, 0); //set SCK to mode 0 idle state after CS goes inactive
+ }
+ #else
+ u8g_SetPILevel_DUE(u8g, U8G_PI_CS, !arg_val);
+ #endif
+ break;
+
+ case U8G_COM_MSG_WRITE_BYTE:
+ SPISEND_SW_DUE(arg_val);
+ break;
+
+ case U8G_COM_MSG_WRITE_SEQ: {
+ uint8_t *ptr = (uint8_t *)arg_ptr;
+ while (arg_val > 0) {
+ SPISEND_SW_DUE(*ptr++);
+ arg_val--;
+ }
+ }
+ break;
+
+ case U8G_COM_MSG_WRITE_SEQ_P: {
+ uint8_t *ptr = (uint8_t *)arg_ptr;
+ while (arg_val > 0) {
+ SPISEND_SW_DUE(u8g_pgm_read(ptr));
+ ptr++;
+ arg_val--;
+ }
+ }
+ break;
+
+ case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
+ u8g_SetPILevel_DUE(u8g, U8G_PI_A0, arg_val);
+ break;
+ }
+ return 1;
+}
+
+#endif // HAS_GRAPHICAL_LCD && !U8GLIB_ST7920
+#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
new file mode 100644
index 000000000000..d3609f60ef12
--- /dev/null
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
@@ -0,0 +1,112 @@
+/**
+ * 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 .
+ *
+ */
+
+/**
+ * Based on u8g_com_st7920_hw_spi.c
+ *
+ * Universal 8bit Graphics Library
+ *
+ * Copyright (c) 2011, 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 ARDUINO_ARCH_SAM
+
+#include "../../../inc/MarlinConfigPre.h"
+
+#if HAS_GRAPHICAL_LCD
+
+#include "../../shared/Delay.h"
+
+#include
+
+#include "u8g_com_HAL_DUE_sw_spi_shared.h"
+
+void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
+ PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
+ g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration); // OUTPUT
+}
+
+void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
+ volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
+ uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
+ if (level) port->PIO_SODR = mask; else port->PIO_CODR = mask;
+}
+
+Pio *SCK_pPio, *MOSI_pPio;
+uint32_t SCK_dwMask, MOSI_dwMask;
+
+void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
+ for (uint8_t i = 0; i < 8; i++) {
+ if (val & 0x80)
+ MOSI_pPio->PIO_SODR = MOSI_dwMask;
+ else
+ MOSI_pPio->PIO_CODR = MOSI_dwMask;
+ DELAY_NS(48);
+ SCK_pPio->PIO_SODR = SCK_dwMask;
+ DELAY_NS(905);
+ val <<= 1;
+ SCK_pPio->PIO_CODR = SCK_dwMask;
+ }
+}
+
+void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
+ for (uint8_t i = 0; i < 8; i++) {
+ SCK_pPio->PIO_CODR = SCK_dwMask;
+ DELAY_NS(50);
+ if (val & 0x80)
+ MOSI_pPio->PIO_SODR = MOSI_dwMask;
+ else
+ MOSI_pPio->PIO_CODR = MOSI_dwMask;
+ val <<= 1;
+ DELAY_NS(10);
+ SCK_pPio->PIO_SODR = SCK_dwMask;
+ DELAY_NS(70);
+ }
+}
+
+#endif // HAS_GRAPHICAL_LCD
+#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
new file mode 100644
index 000000000000..b83247415033
--- /dev/null
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.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
+
+#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);
+
+void u8g_spiSend_sw_DUE_mode_0(uint8_t val);
+void u8g_spiSend_sw_DUE_mode_3(uint8_t val);
+
+extern Pio *SCK_pPio, *MOSI_pPio;
+extern uint32_t SCK_dwMask, MOSI_dwMask;
diff --git a/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h b/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
index eb4833ecd6ef..daa2b3c15e9c 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 95%
rename from Marlin/src/HAL/HAL_DUE/fastio_Due.h
rename to Marlin/src/HAL/HAL_DUE/fastio.h
index 542469f65e75..a97a944e33f1 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
*/
@@ -46,7 +48,6 @@
// Due has 12 PWMs assigned to logical pins 2-13.
// 6, 7, 8 & 9 come from the PWM controller. The others come from the timers.
#define PWM_PIN(P) WITHIN(P, 2, 13)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#ifndef MASK
#define MASK(PIN) (1 << PIN)
@@ -63,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{ \
@@ -161,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)
@@ -180,8 +172,6 @@
#define IS_INPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) == 0)
// Check if pin is an output
#define IS_OUTPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) != 0)
-// Check if pin is a timer - Must be a constexpr
-#define HAS_TIMER(IO) ((IO) >= 2 && (IO) <= 13)
// Shorthand
#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
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 cfb064097e0a..4afd83ad4bdc 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 5cbeaceba987..4a84dfe64a7b 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 98%
rename from Marlin/src/HAL/HAL_DUE/G2_pins.h
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_pins.h
index a7f432846e37..e5ce834f45a9 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
@@ -248,7 +248,7 @@ const G2_PinDescription G2_g_APinDescription[] = {
{ PIOB, PIO_PB15A_CANRX1|PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
// END
- { NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }
+ { nullptr, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }
};
// This section replaces the FASTIO definitions of pins 34-41
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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 30a5d72b25c2..a8d51edfab04 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 4d788acae6c9..fc1baa22ac8b 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 9d8657705240..ed78f8adbb6b 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
@@ -28,7 +25,7 @@
* Translation of routines & variables used by pinsDebug.h
*/
-#include
+#include "../shared/Marduino.h"
/**
* Due/Marlin quirks
@@ -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 c805b0c1eaba..64ee17a9d864 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
@@ -26,19 +26,22 @@
*
* Available chip select pins for HW SPI are 4 10 52 77
*/
-#if (SDSS == 4) || (SDSS == 10) || (SDSS == 52) || (SDSS == 77)
- #if (SDSS == 4)
+#if SDSS == 4 || SDSS == 10 || SDSS == 52 || SDSS == 77 || SDSS == 87
+ #if SDSS == 4
#define SPI_PIN 87
#define SPI_CHAN 1
- #elif (SDSS == 10)
+ #elif SDSS == 10
#define SPI_PIN 77
#define SPI_CHAN 0
- #elif (SDSS == 52)
+ #elif SDSS == 52
#define SPI_PIN 86
#define SPI_CHAN 2
- #else
+ #elif SDSS == 77
#define SPI_PIN 77
#define SPI_CHAN 0
+ #else
+ #define SPI_PIN 87
+ #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 9d2233d9146c..57dd9f924f5e 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,37 +28,23 @@
#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
-#define PRESCALER 2
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TC0, 0, TC0_IRQn, 3}, // 0 - [servo timer5]
@@ -72,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 82%
rename from Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
rename to Marlin/src/HAL/HAL_DUE/timers.h
index a2676e0875ef..ba1eccb2f911 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
@@ -69,9 +65,9 @@ typedef uint32_t hal_timer_t;
#define HAL_TEMP_TIMER_ISR() void TC4_Handler()
#define HAL_TONE_TIMER_ISR() void TC6_Handler()
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
Tc *pTimerRegs;
@@ -80,15 +76,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 d9ecd3f0fef9..7719c129c307 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/ctrl_access.c b/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.c
index 0ec14e0b8f8d..7991857d6258 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.c
@@ -174,11 +174,11 @@ static xSemaphoreHandle ctrl_access_semphr = NULL;
//! LUN descriptor table.
static const struct
{
- Ctrl_status (*test_unit_ready)(void);
+ Ctrl_status (*test_unit_ready)();
Ctrl_status (*read_capacity)(U32 *);
bool (*unload)(bool);
- bool (*wr_protect)(void);
- bool (*removal)(void);
+ bool (*wr_protect)();
+ bool (*removal)();
#if ACCESS_USB == true
Ctrl_status (*usb_read_10)(U32, U16);
Ctrl_status (*usb_write_10)(U32, U16);
@@ -255,7 +255,7 @@ bool g_wr_protect;
#ifdef FREERTOS_USED
-bool ctrl_access_init(void)
+bool ctrl_access_init()
{
// If the handle to the protecting semaphore is not valid,
if (!ctrl_access_semphr)
@@ -275,7 +275,7 @@ bool ctrl_access_init(void)
*
* \return \c true if the access was successfully locked, else \c false.
*/
-static bool ctrl_access_lock(void)
+static bool ctrl_access_lock()
{
// If the semaphore could not be created, there is no backup solution.
if (!ctrl_access_semphr) return false;
@@ -289,7 +289,7 @@ static bool ctrl_access_lock(void)
#endif // FREERTOS_USED
-U8 get_nb_lun(void)
+U8 get_nb_lun()
{
#if MEM_USB == ENABLE
# ifndef Lun_usb_get_lun
@@ -310,7 +310,7 @@ U8 get_nb_lun(void)
}
-U8 get_cur_lun(void)
+U8 get_cur_lun()
{
return LUN_ID_0;
}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.h b/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.h
index af6c8ceb963e..823887623b64 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/ctrl_access.h
@@ -191,7 +191,7 @@ extern bool g_wr_protect;
*
* \return \c true if the locker was successfully initialized, else \c false.
*/
-extern bool ctrl_access_init(void);
+extern bool ctrl_access_init();
#endif // FREERTOS_USED
@@ -199,7 +199,7 @@ extern bool ctrl_access_init(void);
*
* \return Number of LUNs in the system.
*/
-extern U8 get_nb_lun(void);
+extern U8 get_nb_lun();
/*! \brief Returns the current LUN.
*
@@ -207,7 +207,7 @@ extern U8 get_nb_lun(void);
*
* \todo Implement.
*/
-extern U8 get_cur_lun(void);
+extern U8 get_cur_lun();
/*! \brief Tests the memory state and initializes the memory if required.
*
diff --git a/Marlin/src/HAL/HAL_DUE/usb/osc.h b/Marlin/src/HAL/HAL_DUE/usb/osc.h
index fe09d6fd3eec..3a9543507bb8 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 468e9ee45db7..7699f2724f7b 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,22 +27,23 @@ 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) {
+ UNUSED(unload);
return true;
}
-bool sd_mmc_spi_wr_protect(void) {
+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())
+bool sd_mmc_spi_removal() {
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return true;
return false;
}
@@ -61,7 +62,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 +99,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/sd_mmc_spi_mem.h b/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.h
index 6df82c146b75..f81ce7fdda91 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.h
@@ -78,7 +78,7 @@
//!
//! @brief This function initializes the hw/sw resources required to drive the SD_MMC_SPI.
//!/
-extern void sd_mmc_spi_mem_init(void);
+extern void sd_mmc_spi_mem_init();
//!
//! @brief This function tests the state of the SD_MMC memory and sends it to the Host.
@@ -91,7 +91,7 @@ extern void sd_mmc_spi_mem_init(void);
//! Media not present -> CTRL_NO_PRESENT
//! Media has changed -> CTRL_BUSY
//!/
-extern Ctrl_status sd_mmc_spi_test_unit_ready(void);
+extern Ctrl_status sd_mmc_spi_test_unit_ready();
//!
//! @brief This function gives the address of the last valid sector.
@@ -124,14 +124,14 @@ extern bool sd_mmc_spi_unload(bool unload);
//!
//! @return false -> the memory is not write-protected (always)
//!/
-extern bool sd_mmc_spi_wr_protect(void);
+extern bool sd_mmc_spi_wr_protect();
//!
//! @brief This function tells if the memory has been removed or not.
//!
//! @return false -> The memory isn't removed
//!
-extern bool sd_mmc_spi_removal(void);
+extern bool sd_mmc_spi_removal();
//---- ACCESS DATA FONCTIONS ----
diff --git a/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h b/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h
index e5e7603c9a9e..6fadb9f36caa 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/sysclk.c b/Marlin/src/HAL/HAL_DUE/usb/sysclk.c
index 899244dd88d0..1848b2d819cf 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/sysclk.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/sysclk.c
@@ -71,7 +71,7 @@ extern "C" {
* \param pll_id Source of the USB clock.
* \param div Actual clock divisor. Must be superior to 0.
*/
-void sysclk_enable_usb(void)
+void sysclk_enable_usb()
{
Assert(CONFIG_USBCLK_DIV > 0);
@@ -103,7 +103,7 @@ void sysclk_enable_usb(void)
*
* \note This implementation does not switch off the PLL, it just turns off the USB clock.
*/
-void sysclk_disable_usb(void)
+void sysclk_disable_usb()
{
pmc_disable_udpck();
}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/sysclk.h b/Marlin/src/HAL/HAL_DUE/usb/sysclk.h
index 48c99de2983e..51a311ce2960 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/sysclk.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/sysclk.h
@@ -213,8 +213,8 @@ extern "C" {
#endif
-extern void sysclk_enable_usb(void);
-extern void sysclk_disable_usb(void);
+extern void sysclk_enable_usb();
+extern void sysclk_disable_usb();
//! @}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udc.c b/Marlin/src/HAL/HAL_DUE/usb/udc.c
index 048a902d3b5e..dfc9933a2927 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udc.c
@@ -132,14 +132,14 @@ static uint8_t udc_string_product_name[] = USB_DEVICE_PRODUCT_NAME;
* define USB_DEVICE_GET_SERIAL_NAME_LENGTH.
*/
#if defined USB_DEVICE_GET_SERIAL_NAME_POINTER
- static const uint8_t *udc_get_string_serial_name(void)
+ static const uint8_t *udc_get_string_serial_name()
{
return (const uint8_t *)USB_DEVICE_GET_SERIAL_NAME_POINTER;
}
# define USB_DEVICE_SERIAL_NAME_SIZE \
USB_DEVICE_GET_SERIAL_NAME_LENGTH
#elif defined USB_DEVICE_SERIAL_NAME
- static const uint8_t *udc_get_string_serial_name(void)
+ static const uint8_t *udc_get_string_serial_name()
{
return (const uint8_t *)USB_DEVICE_SERIAL_NAME;
}
@@ -164,7 +164,7 @@ static UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc = {
};
//! @}
-usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void)
+usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc()
{
return udc_ptr_iface;
}
@@ -174,7 +174,7 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void)
*
* \return address after the last byte of USB Configuration descriptor
*/
-static usb_conf_desc_t UDC_DESC_STORAGE *udc_get_eof_conf(void)
+static usb_conf_desc_t UDC_DESC_STORAGE *udc_get_eof_conf()
{
return (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *)
udc_ptr_conf->desc +
@@ -360,14 +360,14 @@ static bool udc_iface_enable(uint8_t iface_num, uint8_t setting_num)
/*! \brief Start the USB Device stack
*/
-void udc_start(void)
+void udc_start()
{
udd_enable();
}
/*! \brief Stop the USB Device stack
*/
-void udc_stop(void)
+void udc_stop()
{
udd_disable();
udc_reset();
@@ -377,7 +377,7 @@ void udc_stop(void)
* \brief Reset the current configuration of the USB device,
* This routines can be called by UDD when a RESET on the USB line occurs.
*/
-void udc_reset(void)
+void udc_reset()
{
uint8_t iface_num;
@@ -404,7 +404,7 @@ void udc_reset(void)
#endif
}
-void udc_sof_notify(void)
+void udc_sof_notify()
{
uint8_t iface_num;
@@ -424,7 +424,7 @@ void udc_sof_notify(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_get_status(void)
+static bool udc_req_std_dev_get_status()
{
if (udd_g_ctrlreq.req.wLength != sizeof(udc_device_status)) {
return false;
@@ -441,7 +441,7 @@ static bool udc_req_std_dev_get_status(void)
*
* \return true if success
*/
-static bool udc_req_std_ep_get_status(void)
+static bool udc_req_std_ep_get_status()
{
static le16_t udc_ep_status;
@@ -463,7 +463,7 @@ static bool udc_req_std_ep_get_status(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_clear_feature(void)
+static bool udc_req_std_dev_clear_feature()
{
if (udd_g_ctrlreq.req.wLength) {
return false;
@@ -486,7 +486,7 @@ static bool udc_req_std_dev_clear_feature(void)
*
* \return true if success
*/
-static bool udc_req_std_ep_clear_feature(void)
+static bool udc_req_std_ep_clear_feature()
{
if (udd_g_ctrlreq.req.wLength) {
return false;
@@ -504,7 +504,7 @@ static bool udc_req_std_ep_clear_feature(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_set_feature(void)
+static bool udc_req_std_dev_set_feature()
{
if (udd_g_ctrlreq.req.wLength) {
return false;
@@ -567,7 +567,7 @@ static bool udc_req_std_dev_set_feature(void)
* \return true if success
*/
#if (0!=USB_DEVICE_MAX_EP)
-static bool udc_req_std_ep_set_feature(void)
+static bool udc_req_std_ep_set_feature()
{
if (udd_g_ctrlreq.req.wLength) {
return false;
@@ -584,7 +584,7 @@ static bool udc_req_std_ep_set_feature(void)
* \brief Change the address of device
* Callback called at the end of request set address
*/
-static void udc_valid_address(void)
+static void udc_valid_address()
{
udd_set_address(udd_g_ctrlreq.req.wValue & 0x7F);
}
@@ -594,7 +594,7 @@ static void udc_valid_address(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_set_address(void)
+static bool udc_req_std_dev_set_address()
{
if (udd_g_ctrlreq.req.wLength) {
return false;
@@ -611,7 +611,7 @@ static bool udc_req_std_dev_set_address(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_get_str_desc(void)
+static bool udc_req_std_dev_get_str_desc()
{
uint8_t i;
const uint8_t *str;
@@ -670,7 +670,7 @@ static bool udc_req_std_dev_get_str_desc(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_get_descriptor(void)
+static bool udc_req_std_dev_get_descriptor()
{
uint8_t conf_num;
@@ -787,7 +787,7 @@ static bool udc_req_std_dev_get_descriptor(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_get_configuration(void)
+static bool udc_req_std_dev_get_configuration()
{
if (udd_g_ctrlreq.req.wLength != 1) {
return false;
@@ -802,7 +802,7 @@ static bool udc_req_std_dev_get_configuration(void)
*
* \return true if success
*/
-static bool udc_req_std_dev_set_configuration(void)
+static bool udc_req_std_dev_set_configuration()
{
uint8_t iface_num;
@@ -867,7 +867,7 @@ static bool udc_req_std_dev_set_configuration(void)
*
* \return true if success
*/
-static bool udc_req_std_iface_get_setting(void)
+static bool udc_req_std_iface_get_setting()
{
uint8_t iface_num;
udi_api_t UDC_DESC_STORAGE *udi_api;
@@ -905,7 +905,7 @@ static bool udc_req_std_iface_get_setting(void)
*
* \return true if success
*/
-static bool udc_req_std_iface_set_setting(void)
+static bool udc_req_std_iface_set_setting()
{
uint8_t iface_num, setting_num;
@@ -933,7 +933,7 @@ static bool udc_req_std_iface_set_setting(void)
*
* \return true if the request is supported
*/
-static bool udc_reqstd(void)
+static bool udc_reqstd()
{
if (Udd_setup_is_in()) {
// GET Standard Requests
@@ -1027,7 +1027,7 @@ static bool udc_reqstd(void)
*
* \return true if the request is supported
*/
-static bool udc_req_iface(void)
+static bool udc_req_iface()
{
uint8_t iface_num;
udi_api_t UDC_DESC_STORAGE *udi_api;
@@ -1062,7 +1062,7 @@ static bool udc_req_iface(void)
*
* \return true if the request is supported
*/
-static bool udc_req_ep(void)
+static bool udc_req_ep()
{
uint8_t iface_num;
udi_api_t UDC_DESC_STORAGE *udi_api;
@@ -1101,7 +1101,7 @@ static bool udc_req_ep(void)
*
* \return true if the request is supported, else the request is stalled by UDD
*/
-bool udc_process_setup(void)
+bool udc_process_setup()
{
// By default no data (receive/send) and no callbacks registered
udd_g_ctrlreq.payload_size = 0;
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udc.h b/Marlin/src/HAL/HAL_DUE/usb/udc.h
index 885bdf04d651..3c1dd582ed59 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udc.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udc.h
@@ -172,18 +172,18 @@ extern "C" {
}
\endcode
*/
-static inline bool udc_include_vbus_monitoring(void)
+static inline bool udc_include_vbus_monitoring()
{
return udd_include_vbus_monitoring();
}
/*! \brief Start the USB Device stack
*/
-void udc_start(void);
+void udc_start();
/*! \brief Stop the USB Device stack
*/
-void udc_stop(void);
+void udc_stop();
/**
* \brief Attach device to the bus when possible
@@ -192,7 +192,7 @@ void udc_stop(void);
* then it will attach device when an acceptable Vbus
* level from the host is detected.
*/
-static inline void udc_attach(void)
+static inline void udc_attach()
{
udd_attach();
}
@@ -203,7 +203,7 @@ static inline void udc_attach(void)
*
* The driver must remove pull-up on USB line D- or D+.
*/
-static inline void udc_detach(void)
+static inline void udc_detach()
{
udd_detach();
}
@@ -212,7 +212,7 @@ static inline void udc_detach(void)
/*! \brief The USB driver sends a resume signal called \e "Upstream Resume"
* This is authorized only when the remote wakeup feature is enabled by host.
*/
-static inline void udc_remotewakeup(void)
+static inline void udc_remotewakeup()
{
udd_send_remotewakeup();
}
@@ -223,7 +223,7 @@ static inline void udc_remotewakeup(void)
*
* \return pointer on the current interface descriptor.
*/
-usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
+usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc();
//@}
@@ -334,7 +334,7 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
*
* Add to application C-file:
* \code
- void usb_init(void)
+ void usb_init()
{
udc_start();
}
@@ -551,23 +551,23 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
#define USB_DEVICE_ATTR \
(USB_CONFIG_ATTR_REMOTE_WAKEUP | USB_CONFIG_ATTR_..._POWERED)
#define UDC_REMOTEWAKEUP_ENABLE() my_callback_remotewakeup_enable()
- extern void my_callback_remotewakeup_enable(void);
+ extern void my_callback_remotewakeup_enable();
#define UDC_REMOTEWAKEUP_DISABLE() my_callback_remotewakeup_disable()
- extern void my_callback_remotewakeup_disable(void);
+ extern void my_callback_remotewakeup_disable();
\endcode
*
* Add to application C-file:
* \code
- void my_callback_remotewakeup_enable(void)
+ void my_callback_remotewakeup_enable()
{
// Enable application wakeup events (e.g. enable GPIO interrupt)
}
- void my_callback_remotewakeup_disable(void)
+ void my_callback_remotewakeup_disable()
{
// Disable application wakeup events (e.g. disable GPIO interrupt)
}
- void my_interrupt_event(void)
+ void my_interrupt_event()
{
udc_remotewakeup();
}
@@ -580,10 +580,10 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
#define USB_DEVICE_ATTR (USB_CONFIG_ATTR_REMOTE_WAKEUP | USB_CONFIG_ATTR_..._POWERED) \endcode
* - \code // Define callback called when the host enables the remotewakeup feature
#define UDC_REMOTEWAKEUP_ENABLE() my_callback_remotewakeup_enable()
- extern void my_callback_remotewakeup_enable(void); \endcode
+ extern void my_callback_remotewakeup_enable(); \endcode
* - \code // Define callback called when the host disables the remotewakeup feature
#define UDC_REMOTEWAKEUP_DISABLE() my_callback_remotewakeup_disable()
- extern void my_callback_remotewakeup_disable(void); \endcode
+ extern void my_callback_remotewakeup_disable(); \endcode
* -# Send a remote wakeup (USB upstream):
* - \code udc_remotewakeup(); \endcode
*/
@@ -605,18 +605,18 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
* \code
#define USB_DEVICE_ATTR (USB_CONFIG_ATTR_BUS_POWERED)
#define UDC_SUSPEND_EVENT() user_callback_suspend_action()
- extern void user_callback_suspend_action(void)
+ extern void user_callback_suspend_action()
#define UDC_RESUME_EVENT() user_callback_resume_action()
- extern void user_callback_resume_action(void)
+ extern void user_callback_resume_action()
\endcode
*
* Add to application C-file:
* \code
- void user_callback_suspend_action(void)
+ void user_callback_suspend_action()
{
// Disable hardware component to reduce power consumption
}
- void user_callback_resume_action(void)
+ void user_callback_resume_action()
{
// Re-enable hardware component
}
@@ -628,12 +628,12 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
#define USB_DEVICE_ATTR (USB_CONFIG_ATTR_BUS_POWERED) \endcode
* - \code // Define callback called when the host suspend the USB line
#define UDC_SUSPEND_EVENT() user_callback_suspend_action()
- extern void user_callback_suspend_action(void); \endcode
+ extern void user_callback_suspend_action(); \endcode
* - \code // Define callback called when the host or device resume the USB line
#define UDC_RESUME_EVENT() user_callback_resume_action()
- extern void user_callback_resume_action(void); \endcode
+ extern void user_callback_resume_action(); \endcode
* -# Reduce power consumption in suspend mode (max. 2.5mA on Vbus):
- * - \code void user_callback_suspend_action(void)
+ * - \code void user_callback_suspend_action()
{
turn_off_components();
} \endcode
@@ -664,7 +664,7 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
* \code
uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
- void init_build_usb_serial_number(void)
+ void init_build_usb_serial_number()
{
serial_number[0] = 'A';
serial_number[1] = 'B';
@@ -683,7 +683,7 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
* - \code
uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
- void init_build_usb_serial_number(void)
+ void init_build_usb_serial_number()
{
serial_number[0] = 'A';
serial_number[1] = 'B';
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udd.h b/Marlin/src/HAL/HAL_DUE/usb/udd.h
index 10807f43d79e..4d024dbc6341 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)();
//! 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)();
} 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)();
/**
* \brief End of transfer callback function type.
@@ -142,17 +142,17 @@ typedef void (*udd_callback_trans_t) (udd_ep_status_t status,
*
* \return true, if the VBUS monitoring is possible.
*/
-bool udd_include_vbus_monitoring(void);
+bool udd_include_vbus_monitoring();
/**
* \brief Enables the USB Device mode
*/
-void udd_enable(void);
+void udd_enable();
/**
* \brief Disables the USB Device mode
*/
-void udd_disable(void);
+void udd_disable();
/**
* \brief Attach device to the bus when possible
@@ -161,14 +161,14 @@ void udd_disable(void);
* then it will attach device when an acceptable Vbus
* level from the host is detected.
*/
-void udd_attach(void);
+void udd_attach();
/**
* \brief Detaches the device from the bus
*
* The driver must remove pull-up on USB line D- or D+.
*/
-void udd_detach(void);
+void udd_detach();
/**
* \brief Test whether the USB Device Controller is running at high
@@ -176,7 +176,7 @@ void udd_detach(void);
*
* \return \c true if the Device is running at high speed mode, otherwise \c false.
*/
-bool udd_is_high_speed(void);
+bool udd_is_high_speed();
/**
* \brief Changes the USB address of device
@@ -190,25 +190,25 @@ void udd_set_address(uint8_t address);
*
* \return USB address
*/
-uint8_t udd_getaddress(void);
+uint8_t udd_getaddress();
/**
* \brief Returns the current start of frame number
*
* \return current start of frame number.
*/
-uint16_t udd_get_frame_number(void);
+uint16_t udd_get_frame_number();
/**
* \brief Returns the current micro start of frame number
*
* \return current micro start of frame number required in high speed mode.
*/
-uint16_t udd_get_micro_frame_number(void);
+uint16_t udd_get_micro_frame_number();
/*! \brief The USB driver sends a resume signal called Upstream Resume
*/
-void udd_send_remotewakeup(void);
+void udd_send_remotewakeup();
/**
* \brief Load setup payload
@@ -346,10 +346,10 @@ void udd_ep_abort(udd_ep_id_t ep);
* The following functions allow the device to jump to a specific test mode required in high speed mode.
*/
//@{
-void udd_test_mode_j(void);
-void udd_test_mode_k(void);
-void udd_test_mode_se0_nak(void);
-void udd_test_mode_packet(void);
+void udd_test_mode_j();
+void udd_test_mode_k();
+void udd_test_mode_se0_nak();
+void udd_test_mode_packet();
//@}
@@ -370,21 +370,21 @@ void udd_test_mode_packet(void);
*
* \return \c 1 if the request is accepted, otherwise \c 0.
*/
-extern bool udc_process_setup(void);
+extern bool udc_process_setup();
/**
* \brief Reset the UDC
*
* The UDC must reset all configuration.
*/
-extern void udc_reset(void);
+extern void udc_reset();
/**
* \brief To signal that a SOF is occurred
*
* The UDC must send the signal to all UDIs enabled
*/
-extern void udc_sof_notify(void);
+extern void udc_sof_notify();
//@}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi.h b/Marlin/src/HAL/HAL_DUE/usb/udi.h
index 1fc7ae5d01a4..6a5b470f4c05 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)();
/**
* \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)();
/**
* \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)();
/**
* \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)();
/**
* \brief To signal that a SOF is occurred
*/
- void(*sof_notify) (void);
+ void (*sof_notify)();
} 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 e54ee570fa4b..430de6c01563 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
@@ -84,14 +84,14 @@
*
* @{
*/
-bool udi_cdc_comm_enable(void);
-void udi_cdc_comm_disable(void);
-bool udi_cdc_comm_setup(void);
-bool udi_cdc_data_enable(void);
-void udi_cdc_data_disable(void);
-bool udi_cdc_data_setup(void);
-uint8_t udi_cdc_getsetting(void);
-void udi_cdc_data_sof_notify(void);
+bool udi_cdc_comm_enable();
+void udi_cdc_comm_disable();
+bool udi_cdc_comm_setup();
+bool udi_cdc_data_enable();
+void udi_cdc_data_disable();
+bool udi_cdc_data_setup();
+uint8_t udi_cdc_getsetting();
+void udi_cdc_data_sof_notify();
UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm = {
.enable = udi_cdc_comm_enable,
.disable = udi_cdc_comm_disable,
@@ -130,14 +130,14 @@ UDC_DESC_STORAGE udi_api_t udi_api_cdc_data = {
*
* \return port number
*/
-static uint8_t udi_cdc_setup_to_port(void);
+static uint8_t udi_cdc_setup_to_port();
/**
* \brief Sends line coding to application
*
* Called after SETUP request when line coding data is received.
*/
-static void udi_cdc_line_coding_received(void);
+static void udi_cdc_line_coding_received();
/**
* \brief Records new state
@@ -267,7 +267,7 @@ static volatile bool udi_cdc_tx_both_buf_to_send[UDI_CDC_PORT_NB];
//@}
-bool udi_cdc_comm_enable(void)
+bool udi_cdc_comm_enable()
{
uint8_t port;
uint8_t iface_comm_num;
@@ -321,7 +321,7 @@ bool udi_cdc_comm_enable(void)
return true;
}
-bool udi_cdc_data_enable(void)
+bool udi_cdc_data_enable()
{
uint8_t port;
@@ -360,13 +360,13 @@ bool udi_cdc_data_enable(void)
return true;
}
-void udi_cdc_comm_disable(void)
+void udi_cdc_comm_disable()
{
Assert(udi_cdc_nb_comm_enabled != 0);
udi_cdc_nb_comm_enabled--;
}
-void udi_cdc_data_disable(void)
+void udi_cdc_data_disable()
{
uint8_t port;
@@ -377,7 +377,7 @@ void udi_cdc_data_disable(void)
udi_cdc_data_running = false;
}
-bool udi_cdc_comm_setup(void)
+bool udi_cdc_comm_setup()
{
uint8_t port = udi_cdc_setup_to_port();
@@ -433,17 +433,17 @@ bool udi_cdc_comm_setup(void)
return false; // request Not supported
}
-bool udi_cdc_data_setup(void)
+bool udi_cdc_data_setup()
{
return false; // request Not supported
}
-uint8_t udi_cdc_getsetting(void)
+uint8_t udi_cdc_getsetting()
{
return 0; // CDC don't have multiple alternate setting
}
-void udi_cdc_data_sof_notify(void)
+void udi_cdc_data_sof_notify()
{
static uint8_t port_notify = 0;
@@ -458,10 +458,10 @@ void udi_cdc_data_sof_notify(void)
}
-//-------------------------------------------------
+// ------------------------
//------- Internal routines to control serial line
-static uint8_t udi_cdc_setup_to_port(void)
+static uint8_t udi_cdc_setup_to_port()
{
uint8_t port;
@@ -479,7 +479,7 @@ static uint8_t udi_cdc_setup_to_port(void)
return port;
}
-static void udi_cdc_line_coding_received(void)
+static void udi_cdc_line_coding_received()
{
uint8_t port = udi_cdc_setup_to_port();
UNUSED(port);
@@ -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
@@ -797,17 +797,17 @@ void udi_cdc_ctrl_signal_dsr(bool b_set)
udi_cdc_ctrl_state_change(0, b_set, CDC_SERIAL_STATE_DSR);
}
-void udi_cdc_signal_framing_error(void)
+void udi_cdc_signal_framing_error()
{
udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_FRAMING);
}
-void udi_cdc_signal_parity_error(void)
+void udi_cdc_signal_parity_error()
{
udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_PARITY);
}
-void udi_cdc_signal_overrun(void)
+void udi_cdc_signal_overrun()
{
udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_OVERRUN);
}
@@ -853,7 +853,7 @@ iram_size_t udi_cdc_multi_get_nb_received_data(uint8_t port)
return nb_received;
}
-iram_size_t udi_cdc_get_nb_received_data(void)
+iram_size_t udi_cdc_get_nb_received_data()
{
return udi_cdc_multi_get_nb_received_data(0);
}
@@ -863,7 +863,7 @@ bool udi_cdc_multi_is_rx_ready(uint8_t port)
return (udi_cdc_multi_get_nb_received_data(port) > 0);
}
-bool udi_cdc_is_rx_ready(void)
+bool udi_cdc_is_rx_ready()
{
return udi_cdc_multi_is_rx_ready(0);
}
@@ -912,7 +912,7 @@ int udi_cdc_multi_getc(uint8_t port)
return rx_data;
}
-int udi_cdc_getc(void)
+int udi_cdc_getc()
{
return udi_cdc_multi_getc(0);
}
@@ -1041,7 +1041,7 @@ iram_size_t __attribute__((optimize("O0"))) udi_cdc_multi_get_free_tx_buffer(uin
return retval;
}
-iram_size_t udi_cdc_get_free_tx_buffer(void)
+iram_size_t udi_cdc_get_free_tx_buffer()
{
return udi_cdc_multi_get_free_tx_buffer(0);
}
@@ -1051,7 +1051,7 @@ bool udi_cdc_multi_is_tx_ready(uint8_t port)
return (udi_cdc_multi_get_free_tx_buffer(port) != 0);
}
-bool udi_cdc_is_tx_ready(void)
+bool udi_cdc_is_tx_ready()
{
return udi_cdc_multi_is_tx_ready(0);
}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
index 45c5cef5ae58..66da384e6cb2 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)
@@ -366,38 +366,38 @@ void udi_cdc_ctrl_signal_dsr(bool b_set);
/**
* \brief Notify a framing error
*/
-void udi_cdc_signal_framing_error(void);
+void udi_cdc_signal_framing_error();
/**
* \brief Notify a parity error
*/
-void udi_cdc_signal_parity_error(void);
+void udi_cdc_signal_parity_error();
/**
* \brief Notify a overrun
*/
-void udi_cdc_signal_overrun(void);
+void udi_cdc_signal_overrun();
/**
* \brief Gets the number of byte received
*
* \return the number of data available
*/
-iram_size_t udi_cdc_get_nb_received_data(void);
+iram_size_t udi_cdc_get_nb_received_data();
/**
* \brief This function checks if a character has been received on the CDC line
*
* \return \c 1 if a byte is ready to be read.
*/
-bool udi_cdc_is_rx_ready(void);
+bool udi_cdc_is_rx_ready();
/**
* \brief Waits and gets a value on CDC line
*
* \return value read on CDC line
*/
-int udi_cdc_getc(void);
+int udi_cdc_getc();
/**
* \brief Reads a RAM buffer on CDC line
@@ -425,7 +425,7 @@ iram_size_t udi_cdc_read_no_polling(void* buf, iram_size_t size);
*
* \return the number of free byte in TX buffer
*/
-iram_size_t udi_cdc_get_free_tx_buffer(void);
+iram_size_t udi_cdc_get_free_tx_buffer();
/**
* \brief This function checks if a new character sent is possible
@@ -433,7 +433,7 @@ iram_size_t udi_cdc_get_free_tx_buffer(void);
*
* \return \c 1 if a new character can be sent
*/
-bool udi_cdc_is_tx_ready(void);
+bool udi_cdc_is_tx_ready();
/**
* \brief Puts a byte on CDC line
@@ -611,9 +611,9 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
* Content of conf_usb.h:
* \code
#define UDI_CDC_ENABLE_EXT(port) my_callback_cdc_enable()
- extern bool my_callback_cdc_enable(void);
+ extern bool my_callback_cdc_enable();
#define UDI_CDC_DISABLE_EXT(port) my_callback_cdc_disable()
- extern void my_callback_cdc_disable(void);
+ extern void my_callback_cdc_disable();
#define UDI_CDC_LOW_RATE
#define UDI_CDC_DEFAULT_RATE 115200
@@ -627,17 +627,17 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
* Add to application C-file:
* \code
static bool my_flag_autorize_cdc_transfert = false;
- bool my_callback_cdc_enable(void)
+ bool my_callback_cdc_enable()
{
my_flag_autorize_cdc_transfert = true;
return true;
}
- void my_callback_cdc_disable(void)
+ void my_callback_cdc_disable()
{
my_flag_autorize_cdc_transfert = false;
}
- void task(void)
+ void task()
{
if (my_flag_autorize_cdc_transfert) {
udi_cdc_putc('A');
@@ -652,14 +652,14 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
* - \code #define USB_DEVICE_SERIAL_NAME "12...EF" // Disk SN for CDC \endcode
* \note The USB serial number is mandatory when a CDC interface is used.
* - \code #define UDI_CDC_ENABLE_EXT(port) my_callback_cdc_enable()
- extern bool my_callback_cdc_enable(void); \endcode
+ extern bool my_callback_cdc_enable(); \endcode
* \note After the device enumeration (detecting and identifying USB devices),
* the USB host starts the device configuration. When the USB CDC interface
* from the device is accepted by the host, the USB host enables this interface and the
* UDI_CDC_ENABLE_EXT() callback function is called and return true.
* Thus, when this event is received, the data transfer on CDC interface are authorized.
* - \code #define UDI_CDC_DISABLE_EXT(port) my_callback_cdc_disable()
- extern void my_callback_cdc_disable(void); \endcode
+ extern void my_callback_cdc_disable(); \endcode
* \note When the USB device is unplugged or is reset by the USB host, the USB
* interface is disabled and the UDI_CDC_DISABLE_EXT() callback function
* is called. Thus, the data transfer must be stopped on CDC interface.
@@ -673,7 +673,7 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
* \note Default configuration of communication port at startup.
* -# Send or wait data on CDC line:
* - \code // Waits and gets a value on CDC line
- int udi_cdc_getc(void);
+ int udi_cdc_getc();
// Reads a RAM buffer on CDC line
iram_size_t udi_cdc_read_buf(int* buf, iram_size_t size);
// Puts a byte on CDC line
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 b99d6111713a..cbd3eb00ae71 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_composite_desc.c b/Marlin/src/HAL/HAL_DUE/usb/udi_composite_desc.c
index 3c5f001a265c..07bdd1b9d692 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_composite_desc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_composite_desc.c
@@ -67,9 +67,9 @@ UDC_DESC_STORAGE usb_dev_desc_t udc_device_desc = {
.bLength = sizeof(usb_dev_desc_t),
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = LE16(USB_V2_0),
- .bDeviceClass = 0,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
+ .bDeviceClass = CDC_CLASS_MULTI,
+ .bDeviceSubClass = CDC_SUBCLASS_ACM,
+ .bDeviceProtocol = CDC_PROTOCOL_V25TER,
.bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
.idVendor = LE16(USB_DEVICE_VENDOR_ID),
.idProduct = LE16(USB_DEVICE_PRODUCT_ID),
@@ -101,9 +101,9 @@ UDC_DESC_STORAGE usb_dev_qual_desc_t udc_device_qual = {
.bLength = sizeof(usb_dev_qual_desc_t),
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,
.bcdUSB = LE16(USB_V2_0),
- .bDeviceClass = 0,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
+ .bDeviceClass = CDC_CLASS_MULTI,
+ .bDeviceSubClass = CDC_SUBCLASS_ACM,
+ .bDeviceProtocol = CDC_PROTOCOL_V25TER,
.bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
.bNumConfigurations = 1
};
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
index 97d3f2990b96..95b5e8a24844 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
@@ -71,10 +71,10 @@
*
* @{
*/
-bool udi_msc_enable(void);
-void udi_msc_disable(void);
-bool udi_msc_setup(void);
-uint8_t udi_msc_getsetting(void);
+bool udi_msc_enable();
+void udi_msc_disable();
+bool udi_msc_setup();
+uint8_t udi_msc_getsetting();
//! Global structure which contains standard UDI API for UDC
UDC_DESC_STORAGE udi_api_t udi_api_msc = {
@@ -151,12 +151,12 @@ volatile bool udi_msc_b_reset_trans = true;
/**
* \brief Stall CBW request
*/
-static void udi_msc_cbw_invalid(void);
+static void udi_msc_cbw_invalid();
/**
* \brief Stall CSW request
*/
-static void udi_msc_csw_invalid(void);
+static void udi_msc_csw_invalid();
/**
* \brief Links a callback and buffer on endpoint OUT reception
@@ -165,7 +165,7 @@ static void udi_msc_csw_invalid(void);
* - enable interface
* - at the end of previous command after sending the CSW
*/
-static void udi_msc_cbw_wait(void);
+static void udi_msc_cbw_wait();
/**
* \brief Callback called after CBW reception
@@ -228,7 +228,7 @@ static void udi_msc_data_sent(udd_ep_status_t status, iram_size_t nb_sent,
*
* Called at the end of SCSI command
*/
-static void udi_msc_csw_process(void);
+static void udi_msc_csw_process();
/**
* \brief Sends CSW
@@ -236,7 +236,7 @@ static void udi_msc_csw_process(void);
* Called by #udi_msc_csw_process()
* or UDD callback when endpoint halt is cleared
*/
-void udi_msc_csw_send(void);
+void udi_msc_csw_send();
/**
* \brief Callback called after CSW sent
@@ -259,7 +259,7 @@ static void udi_msc_csw_sent(udd_ep_status_t status, iram_size_t nb_sent,
/**
* \brief Reinitialize sense data.
*/
-static void udi_msc_clear_sense(void);
+static void udi_msc_clear_sense();
/**
* \brief Update sense data with new value to signal a fail
@@ -274,37 +274,37 @@ static void udi_msc_sense_fail(uint8_t sense_key, uint16_t add_sense,
/**
* \brief Update sense data with new value to signal success
*/
-static void udi_msc_sense_pass(void);
+static void udi_msc_sense_pass();
/**
* \brief Update sense data to signal that memory is not present
*/
-static void udi_msc_sense_fail_not_present(void);
+static void udi_msc_sense_fail_not_present();
/**
* \brief Update sense data to signal that memory is busy
*/
-static void udi_msc_sense_fail_busy_or_change(void);
+static void udi_msc_sense_fail_busy_or_change();
/**
* \brief Update sense data to signal a hardware error on memory
*/
-static void udi_msc_sense_fail_hardware(void);
+static void udi_msc_sense_fail_hardware();
/**
* \brief Update sense data to signal that memory is protected
*/
-static void udi_msc_sense_fail_protected(void);
+static void udi_msc_sense_fail_protected();
/**
* \brief Update sense data to signal that CDB fields are not valid
*/
-static void udi_msc_sense_fail_cdb_invalid(void);
+static void udi_msc_sense_fail_cdb_invalid();
/**
* \brief Update sense data to signal that command is not supported
*/
-static void udi_msc_sense_command_invalid(void);
+static void udi_msc_sense_command_invalid();
//@}
@@ -317,31 +317,31 @@ static void udi_msc_sense_command_invalid(void);
* \brief Process SPC Request Sense command
* Returns error information about last command
*/
-static void udi_msc_spc_requestsense(void);
+static void udi_msc_spc_requestsense();
/**
* \brief Process SPC Inquiry command
* Returns information (name,version) about disk
*/
-static void udi_msc_spc_inquiry(void);
+static void udi_msc_spc_inquiry();
/**
* \brief Checks state of disk
*
* \retval true if disk is ready, otherwise false and updates sense data
*/
-static bool udi_msc_spc_testunitready_global(void);
+static bool udi_msc_spc_testunitready_global();
/**
* \brief Process test unit ready command
* Returns state of logical unit
*/
-static void udi_msc_spc_testunitready(void);
+static void udi_msc_spc_testunitready();
/**
* \brief Process prevent allow medium removal command
*/
-static void udi_msc_spc_prevent_allow_medium_removal(void);
+static void udi_msc_spc_prevent_allow_medium_removal();
/**
* \brief Process mode sense command
@@ -354,12 +354,12 @@ static void udi_msc_spc_mode_sense(bool b_sense10);
/**
* \brief Process start stop command
*/
-static void udi_msc_sbc_start_stop(void);
+static void udi_msc_sbc_start_stop();
/**
* \brief Process read capacity command
*/
-static void udi_msc_sbc_read_capacity(void);
+static void udi_msc_sbc_read_capacity();
/**
* \brief Process read10 or write10 command
@@ -373,7 +373,7 @@ static void udi_msc_sbc_trans(bool b_read);
//@}
-bool udi_msc_enable(void)
+bool udi_msc_enable()
{
uint8_t lun;
udi_msc_b_trans_req = false;
@@ -398,7 +398,7 @@ bool udi_msc_enable(void)
}
-void udi_msc_disable(void)
+void udi_msc_disable()
{
udi_msc_b_trans_req = false;
udi_msc_b_ack_trans = true;
@@ -407,7 +407,7 @@ void udi_msc_disable(void)
}
-bool udi_msc_setup(void)
+bool udi_msc_setup()
{
if (Udd_setup_is_in()) {
// Requests Interface GET
@@ -451,16 +451,16 @@ bool udi_msc_setup(void)
return false; // Not supported request
}
-uint8_t udi_msc_getsetting(void)
+uint8_t udi_msc_getsetting()
{
return 0; // MSC don't have multiple alternate setting
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process CBW packet
-static void udi_msc_cbw_invalid(void)
+static void udi_msc_cbw_invalid()
{
if (!udi_msc_b_cbw_invalid)
return; // Don't re-stall endpoint if error reseted by setup
@@ -469,7 +469,7 @@ static void udi_msc_cbw_invalid(void)
udd_ep_wait_stall_clear(UDI_MSC_EP_OUT, udi_msc_cbw_invalid);
}
-static void udi_msc_csw_invalid(void)
+static void udi_msc_csw_invalid()
{
if (!udi_msc_b_cbw_invalid)
return; // Don't re-stall endpoint if error reseted by setup
@@ -478,7 +478,7 @@ static void udi_msc_csw_invalid(void)
udd_ep_wait_stall_clear(UDI_MSC_EP_IN, udi_msc_csw_invalid);
}
-static void udi_msc_cbw_wait(void)
+static void udi_msc_cbw_wait()
{
// Register buffer and callback on OUT endpoint
if (!udd_ep_run(UDI_MSC_EP_OUT, true,
@@ -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,10 +645,10 @@ 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)
+static void udi_msc_csw_process()
{
if (0 != udi_msc_csw.dCSWDataResidue) {
// Residue not NULL
@@ -665,7 +665,7 @@ static void udi_msc_csw_process(void)
}
-void udi_msc_csw_send(void)
+void udi_msc_csw_send()
{
// Sends CSW on IN endpoint
if (!udd_ep_run(UDI_MSC_EP_IN, false,
@@ -691,10 +691,10 @@ 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)
+static void udi_msc_clear_sense()
{
memset((uint8_t*)&udi_msc_sense, 0, sizeof(struct scsi_request_sense_data));
udi_msc_sense.valid_reponse_code = SCSI_SENSE_VALID | SCSI_SENSE_CURRENT;
@@ -715,52 +715,52 @@ static void udi_msc_sense_fail(uint8_t sense_key, uint16_t add_sense,
udi_msc_sense.AddSnsCodeQlfr = add_sense;
}
-static void udi_msc_sense_pass(void)
+static void udi_msc_sense_pass()
{
udi_msc_clear_sense();
udi_msc_csw.bCSWStatus = USB_CSW_STATUS_PASS;
}
-static void udi_msc_sense_fail_not_present(void)
+static void udi_msc_sense_fail_not_present()
{
udi_msc_sense_fail(SCSI_SK_NOT_READY, SCSI_ASC_MEDIUM_NOT_PRESENT, 0);
}
-static void udi_msc_sense_fail_busy_or_change(void)
+static void udi_msc_sense_fail_busy_or_change()
{
udi_msc_sense_fail(SCSI_SK_UNIT_ATTENTION,
SCSI_ASC_NOT_READY_TO_READY_CHANGE, 0);
}
-static void udi_msc_sense_fail_hardware(void)
+static void udi_msc_sense_fail_hardware()
{
udi_msc_sense_fail(SCSI_SK_HARDWARE_ERROR,
SCSI_ASC_NO_ADDITIONAL_SENSE_INFO, 0);
}
-static void udi_msc_sense_fail_protected(void)
+static void udi_msc_sense_fail_protected()
{
udi_msc_sense_fail(SCSI_SK_DATA_PROTECT, SCSI_ASC_WRITE_PROTECTED, 0);
}
-static void udi_msc_sense_fail_cdb_invalid(void)
+static void udi_msc_sense_fail_cdb_invalid()
{
udi_msc_sense_fail(SCSI_SK_ILLEGAL_REQUEST,
SCSI_ASC_INVALID_FIELD_IN_CDB, 0);
}
-static void udi_msc_sense_command_invalid(void)
+static void udi_msc_sense_command_invalid()
{
udi_msc_sense_fail(SCSI_SK_ILLEGAL_REQUEST,
SCSI_ASC_INVALID_COMMAND_OPERATION_CODE, 0);
}
-//---------------------------------------------
+// ------------------------
//------- Routines manage SCSI Commands
-static void udi_msc_spc_requestsense(void)
+static void udi_msc_spc_requestsense()
{
uint8_t length = udi_msc_cbw.CDB[4];
@@ -775,7 +775,7 @@ static void udi_msc_spc_requestsense(void)
}
-static void udi_msc_spc_inquiry(void)
+static void udi_msc_spc_inquiry()
{
uint8_t length, i;
UDC_DATA(4)
@@ -836,7 +836,7 @@ static void udi_msc_spc_inquiry(void)
}
-static bool udi_msc_spc_testunitready_global(void)
+static bool udi_msc_spc_testunitready_global()
{
switch (mem_test_unit_ready(udi_msc_cbw.bCBWLUN)) {
case CTRL_GOOD:
@@ -856,7 +856,7 @@ static bool udi_msc_spc_testunitready_global(void)
}
-static void udi_msc_spc_testunitready(void)
+static void udi_msc_spc_testunitready()
{
if (udi_msc_spc_testunitready_global()) {
// LUN ready, then update sense data with status pass
@@ -944,7 +944,7 @@ static void udi_msc_spc_mode_sense(bool b_sense10)
}
-static void udi_msc_spc_prevent_allow_medium_removal(void)
+static void udi_msc_spc_prevent_allow_medium_removal()
{
uint8_t prevent = udi_msc_cbw.CDB[4];
if (0 == prevent) {
@@ -956,7 +956,7 @@ static void udi_msc_spc_prevent_allow_medium_removal(void)
}
-static void udi_msc_sbc_start_stop(void)
+static void udi_msc_sbc_start_stop()
{
bool start = 0x1 & udi_msc_cbw.CDB[4];
bool loej = 0x2 & udi_msc_cbw.CDB[4];
@@ -968,7 +968,7 @@ static void udi_msc_sbc_start_stop(void)
}
-static void udi_msc_sbc_read_capacity(void)
+static void udi_msc_sbc_read_capacity()
{
UDC_BSS(4) static struct sbc_read_capacity10_data udi_msc_capacity;
@@ -1039,7 +1039,7 @@ static void udi_msc_sbc_trans(bool b_read)
}
-bool udi_msc_process_trans(void)
+bool udi_msc_process_trans()
{
Ctrl_status status;
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.h b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.h
index c632ee4aacee..e7271e4835c5 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.h
@@ -148,7 +148,7 @@ typedef struct {
*
* Routine called by the main loop
*/
-bool udi_msc_process_trans(void);
+bool udi_msc_process_trans();
/**
* \brief Transfers data to/from USB MSC endpoints
@@ -206,26 +206,26 @@ bool udi_msc_trans_block(bool b_read, uint8_t * block, iram_size_t block_size,
#define UDI_MSC_GLOBAL_PRODUCT_VERSION \
'1', '.', '0', '0'
#define UDI_MSC_ENABLE_EXT() my_callback_msc_enable()
- extern bool my_callback_msc_enable(void);
+ extern bool my_callback_msc_enable();
#define UDI_MSC_DISABLE_EXT() my_callback_msc_disable()
- extern void my_callback_msc_disable(void);
+ extern void my_callback_msc_disable();
#include "udi_msc_conf.h" // At the end of conf_usb.h file
\endcode
*
* Add to application C-file:
* \code
static bool my_flag_autorize_msc_transfert = false;
- bool my_callback_msc_enable(void)
+ bool my_callback_msc_enable()
{
my_flag_autorize_msc_transfert = true;
return true;
}
- void my_callback_msc_disable(void)
+ void my_callback_msc_disable()
{
my_flag_autorize_msc_transfert = false;
}
- void task(void)
+ void task()
{
udi_msc_process_trans();
}
@@ -244,7 +244,7 @@ bool udi_msc_trans_block(bool b_read, uint8_t * block, iram_size_t block_size,
* \note The USB MSC interface requires a vendor ID (8 ASCII characters)
* and a product version (4 ASCII characters).
* - \code #define UDI_MSC_ENABLE_EXT() my_callback_msc_enable()
- extern bool my_callback_msc_enable(void); \endcode
+ extern bool my_callback_msc_enable(); \endcode
* \note After the device enumeration (detecting and identifying USB devices),
* the USB host starts the device configuration. When the USB MSC interface
* from the device is accepted by the host, the USB host enables this interface and the
@@ -252,7 +252,7 @@ bool udi_msc_trans_block(bool b_read, uint8_t * block, iram_size_t block_size,
* Thus, when this event is received, the tasks which call
* udi_msc_process_trans() must be enabled.
* - \code #define UDI_MSC_DISABLE_EXT() my_callback_msc_disable()
- extern void my_callback_msc_disable(void); \endcode
+ extern void my_callback_msc_disable(); \endcode
* \note When the USB device is unplugged or is reset by the USB host, the USB
* interface is disabled and the UDI_MSC_DISABLE_EXT() callback function
* is called. Thus, it is recommended to disable the task which is called udi_msc_process_trans().
@@ -260,14 +260,14 @@ bool udi_msc_trans_block(bool b_read, uint8_t * block, iram_size_t block_size,
* which provides the memories interfaces. However, the memory data transfers
* must be done outside USB interrupt routine. This is done in the MSC process
* ("udi_msc_process_trans()") called by main loop:
- * - \code * void task(void) {
+ * - \code * void task() {
udi_msc_process_trans();
} \endcode
* -# The MSC speed depends on task periodicity. To get the best speed
* the notification callback "UDI_MSC_NOTIFY_TRANS_EXT" can be used to wakeup
* this task (Example, through a mutex):
* - \code #define UDI_MSC_NOTIFY_TRANS_EXT() msc_notify_trans()
- void msc_notify_trans(void) {
+ void msc_notify_trans() {
wakeup_my_task();
} \endcode
*
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 0dfcd5ac1ff5..ae569e2f5548 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
*/
@@ -356,41 +357,41 @@ static uint16_t udd_ctrl_payload_buf_cnt;
*
* Called after a USB line reset or when UDD is enabled
*/
-static void udd_reset_ep_ctrl(void);
+static void udd_reset_ep_ctrl();
/**
* \brief Reset control endpoint management
*
* Called after a USB line reset or at the end of SETUP request (after ZLP)
*/
-static void udd_ctrl_init(void);
+static void udd_ctrl_init();
//! \brief Managed reception of SETUP packet on control endpoint
-static void udd_ctrl_setup_received(void);
+static void udd_ctrl_setup_received();
//! \brief Managed reception of IN packet on control endpoint
-static void udd_ctrl_in_sent(void);
+static void udd_ctrl_in_sent();
//! \brief Managed reception of OUT packet on control endpoint
-static void udd_ctrl_out_received(void);
+static void udd_ctrl_out_received();
//! \brief Managed underflow event of IN packet on control endpoint
-static void udd_ctrl_underflow(void);
+static void udd_ctrl_underflow();
//! \brief Managed overflow event of OUT packet on control endpoint
-static void udd_ctrl_overflow(void);
+static void udd_ctrl_overflow();
//! \brief Managed stall event of IN/OUT packet on control endpoint
-static void udd_ctrl_stall_data(void);
+static void udd_ctrl_stall_data();
//! \brief Send a ZLP IN on control endpoint
-static void udd_ctrl_send_zlp_in(void);
+static void udd_ctrl_send_zlp_in();
//! \brief Send a ZLP OUT on control endpoint
-static void udd_ctrl_send_zlp_out(void);
+static void udd_ctrl_send_zlp_out();
//! \brief Call callback associated to setup request
-static void udd_ctrl_endofrequest(void);
+static void udd_ctrl_endofrequest();
/**
@@ -400,7 +401,7 @@ static void udd_ctrl_endofrequest(void);
*
* \return \c 1 if an event about control endpoint is occured, otherwise \c 0.
*/
-static bool udd_ctrl_interrupt(void);
+static bool udd_ctrl_interrupt();
//@}
@@ -447,10 +448,10 @@ typedef struct {
static udd_ep_job_t udd_ep_job[USB_DEVICE_MAX_EP];
//! \brief Reset all job table
-static void udd_ep_job_table_reset(void);
+static void udd_ep_job_table_reset();
//! \brief Abort all endpoint jobs on going
-static void udd_ep_job_table_kill(void);
+static void udd_ep_job_table_kill();
#ifdef UDD_EP_FIFO_SUPPORTED
/**
@@ -499,13 +500,13 @@ static void udd_ep_finish_job(udd_ep_job_t * ptr_job, bool b_abort, uint8_t ep_n
*
* \return \c 1 if an event about bulk/interrupt/isochronous endpoints has occured, otherwise \c 0.
*/
-static bool udd_ep_interrupt(void);
+static bool udd_ep_interrupt();
#endif // (0!=USB_DEVICE_MAX_EP)
//@}
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED GLOBAL EVENTS
/**
@@ -523,8 +524,8 @@ static bool udd_ep_interrupt(void);
* See Technical reference $3.8.3 Masking interrupt requests in peripheral modules.
*/
#ifdef UHD_ENABLE
-void udd_interrupt(void);
-void udd_interrupt(void)
+void udd_interrupt();
+void udd_interrupt()
#else
ISR(UDD_USB_INT_FUN)
#endif
@@ -642,13 +643,13 @@ ISR(UDD_USB_INT_FUN)
}
-bool udd_include_vbus_monitoring(void)
+bool udd_include_vbus_monitoring()
{
return true;
}
-void udd_enable(void)
+void udd_enable()
{
irqflags_t flags;
@@ -735,7 +736,7 @@ void udd_enable(void)
}
-void udd_disable(void)
+void udd_disable()
{
irqflags_t flags;
@@ -776,7 +777,7 @@ void udd_disable(void)
}
-void udd_attach(void)
+void udd_attach()
{
irqflags_t flags;
flags = cpu_irq_save();
@@ -817,7 +818,7 @@ void udd_attach(void)
}
-void udd_detach(void)
+void udd_detach()
{
otg_unfreeze_clock();
@@ -828,7 +829,7 @@ void udd_detach(void)
}
-bool udd_is_high_speed(void)
+bool udd_is_high_speed()
{
#ifdef USB_DEVICE_HS_SUPPORT
return !Is_udd_full_speed_mode();
@@ -846,23 +847,23 @@ void udd_set_address(uint8_t address)
}
-uint8_t udd_getaddress(void)
+uint8_t udd_getaddress()
{
return udd_get_configured_address();
}
-uint16_t udd_get_frame_number(void)
+uint16_t udd_get_frame_number()
{
return udd_frame_number();
}
-uint16_t udd_get_micro_frame_number(void)
+uint16_t udd_get_micro_frame_number()
{
return udd_micro_frame_number();
}
-void udd_send_remotewakeup(void)
+void udd_send_remotewakeup()
{
#ifndef UDD_NO_SLEEP_MGR
if (!udd_b_idle)
@@ -1241,27 +1242,27 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep,
#ifdef USB_DEVICE_HS_SUPPORT
-void udd_test_mode_j(void)
+void udd_test_mode_j()
{
udd_enable_hs_test_mode();
udd_enable_hs_test_mode_j();
}
-void udd_test_mode_k(void)
+void udd_test_mode_k()
{
udd_enable_hs_test_mode();
udd_enable_hs_test_mode_k();
}
-void udd_test_mode_se0_nak(void)
+void udd_test_mode_se0_nak()
{
udd_enable_hs_test_mode();
}
-void udd_test_mode_packet(void)
+void udd_test_mode_packet()
{
uint8_t i;
uint8_t *ptr_dest;
@@ -1306,10 +1307,10 @@ void udd_test_mode_packet(void)
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED THE CONTROL ENDPOINT
-static void udd_reset_ep_ctrl(void)
+static void udd_reset_ep_ctrl()
{
irqflags_t flags;
@@ -1333,7 +1334,7 @@ static void udd_reset_ep_ctrl(void)
cpu_irq_restore(flags);
}
-static void udd_ctrl_init(void)
+static void udd_ctrl_init()
{
irqflags_t flags;
flags = cpu_irq_save();
@@ -1356,7 +1357,7 @@ static void udd_ctrl_init(void)
}
-static void udd_ctrl_setup_received(void)
+static void udd_ctrl_setup_received()
{
irqflags_t flags;
uint8_t i;
@@ -1418,7 +1419,7 @@ static void udd_ctrl_setup_received(void)
}
-static void udd_ctrl_in_sent(void)
+static void udd_ctrl_in_sent()
{
static bool b_shortpacket = false;
uint16_t nb_remain;
@@ -1502,7 +1503,7 @@ static void udd_ctrl_in_sent(void)
}
-static void udd_ctrl_out_received(void)
+static void udd_ctrl_out_received()
{
irqflags_t flags;
uint8_t i;
@@ -1593,7 +1594,7 @@ static void udd_ctrl_out_received(void)
}
-static void udd_ctrl_underflow(void)
+static void udd_ctrl_underflow()
{
if (Is_udd_out_received(0))
return; // Underflow ignored if OUT data is received
@@ -1610,7 +1611,7 @@ static void udd_ctrl_underflow(void)
}
-static void udd_ctrl_overflow(void)
+static void udd_ctrl_overflow()
{
if (Is_udd_in_send(0))
return; // Overflow ignored if IN data is received
@@ -1626,7 +1627,7 @@ static void udd_ctrl_overflow(void)
}
-static void udd_ctrl_stall_data(void)
+static void udd_ctrl_stall_data()
{
// Stall all packets on IN & OUT control endpoint
udd_ep_control_state = UDD_EPCTRL_STALL_REQ;
@@ -1634,7 +1635,7 @@ static void udd_ctrl_stall_data(void)
}
-static void udd_ctrl_send_zlp_in(void)
+static void udd_ctrl_send_zlp_in()
{
irqflags_t flags;
@@ -1652,7 +1653,7 @@ static void udd_ctrl_send_zlp_in(void)
}
-static void udd_ctrl_send_zlp_out(void)
+static void udd_ctrl_send_zlp_out()
{
irqflags_t flags;
@@ -1668,7 +1669,7 @@ static void udd_ctrl_send_zlp_out(void)
}
-static void udd_ctrl_endofrequest(void)
+static void udd_ctrl_endofrequest()
{
// If a callback is registered then call it
if (udd_g_ctrlreq.callback) {
@@ -1677,7 +1678,7 @@ static void udd_ctrl_endofrequest(void)
}
-static bool udd_ctrl_interrupt(void)
+static bool udd_ctrl_interrupt()
{
if (!Is_udd_endpoint_interrupt(0)) {
@@ -1728,12 +1729,12 @@ static bool udd_ctrl_interrupt(void)
}
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED THE BULK/INTERRUPT/ISOCHRONOUS ENDPOINTS
#if (0 != USB_DEVICE_MAX_EP)
-static void udd_ep_job_table_reset(void)
+static void udd_ep_job_table_reset()
{
uint8_t i;
for (i = 0; i < USB_DEVICE_MAX_EP; i++) {
@@ -1743,7 +1744,7 @@ static void udd_ep_job_table_reset(void)
}
-static void udd_ep_job_table_kill(void)
+static void udd_ep_job_table_kill()
{
uint8_t i;
@@ -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;
@@ -1969,7 +1970,7 @@ static void udd_ep_out_received(udd_ep_id_t ep)
}
#endif // #ifdef UDD_EP_FIFO_SUPPORTED
-static bool udd_ep_interrupt(void)
+static bool udd_ep_interrupt()
{
udd_ep_id_t ep;
udd_ep_job_t *ptr_job;
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 1cd6914f8547..97877994bf66 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/uotghs_otg.h b/Marlin/src/HAL/HAL_DUE/usb/uotghs_otg.h
index 86c903b2c18f..13a66b226155 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/uotghs_otg.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/uotghs_otg.h
@@ -66,13 +66,13 @@ extern "C" {
*
* \return \c true if the ID pin management has been started, otherwise \c false.
*/
-bool otg_dual_enable(void);
+bool otg_dual_enable();
/**
* \brief Uninitialize the dual role
* This function is implemented in uotghs_host.c file.
*/
-void otg_dual_disable(void);
+void otg_dual_disable();
//! @name UOTGHS OTG ID pin management
diff --git a/Marlin/src/HAL/HAL_DUE/usb/usb_protocol_cdc.h b/Marlin/src/HAL/HAL_DUE/usb/usb_protocol_cdc.h
index 875e7e4dda96..49fc7387ef31 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/usb_protocol_cdc.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/usb_protocol_cdc.h
@@ -61,6 +61,8 @@
#define CDC_CLASS_DEVICE 0x02 //!< USB Communication Device Class
#define CDC_CLASS_COMM 0x02 //!< CDC Communication Class Interface
#define CDC_CLASS_DATA 0x0A //!< CDC Data Class Interface
+#define CDC_CLASS_MULTI 0xEF //!< CDC Multi-interface Function
+
//@}
//! \name USB CDC Subclass IDs
diff --git a/Marlin/src/HAL/HAL_DUE/usb/usb_task.c b/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
index c9de09c11347..7c95c99c07dd 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
@@ -56,7 +56,7 @@
static volatile bool main_b_cdc_enable = false;
static volatile bool main_b_dtr_active = false;
-void usb_task_idle(void) {
+void usb_task_idle() {
#if ENABLED(SDSUPPORT)
// Attend SD card access from the USB MSD -- Prioritize access to improve speed
int delay = 2;
@@ -70,19 +70,19 @@ void usb_task_idle(void) {
}
#if ENABLED(SDSUPPORT)
- bool usb_task_msc_enable(void) { return ((main_b_msc_enable = true)); }
- void usb_task_msc_disable(void) { main_b_msc_enable = false; }
- bool usb_task_msc_isenabled(void) { return main_b_msc_enable; }
+ bool usb_task_msc_enable() { return ((main_b_msc_enable = true)); }
+ void usb_task_msc_disable() { main_b_msc_enable = false; }
+ bool usb_task_msc_isenabled() { 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_isenabled(void) { return main_b_cdc_enable; }
+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() { 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;
@@ -121,7 +121,7 @@ void usb_task_cdc_set_dtr(const uint8_t port, const bool b_enable) {
}
}
-bool usb_task_cdc_dtr_active(void) { return main_b_dtr_active; }
+bool usb_task_cdc_dtr_active() { return main_b_dtr_active; }
/// Microsoft WCID descriptor
typedef struct USB_MicrosoftCompatibleDescriptor_Interface {
@@ -202,7 +202,7 @@ static USB_MicrosoftExtendedPropertiesDescriptor microsoft_extended_properties_d
** WCID configuration information
** Hooked into UDC via UDC_GET_EXTRA_STRING #define.
*/
-bool usb_task_extra_string(void) {
+bool usb_task_extra_string() {
static uint8_t udi_msft_magic[] = "MSFT100\xEE";
static uint8_t udi_cdc_name[] = "CDC interface";
#if ENABLED(SDSUPPORT)
@@ -262,7 +262,7 @@ bool usb_task_extra_string(void) {
/**************************************************************************************************
** Handle device requests that the ASF stack doesn't
*/
-bool usb_task_other_requests(void) {
+bool usb_task_other_requests() {
uint8_t* ptr = 0;
uint16_t size = 0;
@@ -297,7 +297,7 @@ bool usb_task_other_requests(void) {
return true;
}
-void usb_task_init(void) {
+void usb_task_init() {
uint16_t *ptr;
diff --git a/Marlin/src/HAL/HAL_DUE/usb/usb_task.h b/Marlin/src/HAL/HAL_DUE/usb/usb_task.h
index fad62fda504b..26e498348170 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/usb_task.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/usb_task.h
@@ -58,12 +58,12 @@ extern "C" {
*
* \retval true if MSC startup is ok
*/
-bool usb_task_msc_enable(void);
+bool usb_task_msc_enable();
/*! \brief Called by MSC interface
* Callback running when USB Host disable MSC interface
*/
-void usb_task_msc_disable(void);
+void usb_task_msc_disable();
/*! \brief Opens the communication port
* This is called by CDC interface when USB Host enable it.
@@ -84,25 +84,25 @@ void usb_task_cdc_set_dtr(const uint8_t port, const bool b_enable);
/*! \brief Check if MSC is enumerated and configured on the PC side
*/
-bool usb_task_msc_isenabled(void);
+bool usb_task_msc_isenabled();
/*! \brief Check if CDC is enumerated and configured on the PC side
*/
-bool usb_task_cdc_isenabled(void);
+bool usb_task_cdc_isenabled();
/*! \brief Check if CDC is actually OPEN by an application on the PC side
* assuming DTR signal means a program is listening to messages
*/
-bool usb_task_cdc_dtr_active(void);
+bool usb_task_cdc_dtr_active();
/*! \brief Called by UDC when USB Host request a extra string different
* of this specified in USB device descriptor
*/
-bool usb_task_extra_string(void);
+bool usb_task_extra_string();
/*! \brief Called by UDC when USB Host performs unknown requests
*/
-bool usb_task_other_requests(void);
+bool usb_task_other_requests();
/*! \brief Called by CDC interface
* Callback running when CDC device have received data
@@ -117,15 +117,15 @@ void usb_task_cdc_config(const uint8_t port, usb_cdc_line_coding_t *cfg);
/*! \brief The USB device interrupt
*/
-void USBD_ISR(void);
+void USBD_ISR();
/*! \brief USB task init
*/
-void usb_task_init(void);
+void usb_task_init();
/*! \brief USB task idle
*/
-void usb_task_idle(void);
+void usb_task_idle();
#ifdef __cplusplus
}
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 2bf8080b769b..1f51b75c18e1 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 89%
rename from Marlin/src/HAL/HAL_DUE/watchdog_Due.h
rename to Marlin/src/HAL/HAL_DUE/watchdog.h
index 07187bfe6b57..14832a9c3cdf 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
diff --git a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.cpp b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.cpp
index 6b1277b20493..544b1b3f6748 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 082fa7df0406..9fca4fcbea39 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 53966de55e56..9bf41c2e846d 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,17 +22,18 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
+#include "timers.h"
#include
#include
#include
#include "../../inc/MarlinConfigPre.h"
+#if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
+ #include "spiffs.h"
+#endif
+
#if ENABLED(WIFISUPPORT)
#include
#include "wifi.h"
@@ -41,98 +42,81 @@
#endif
#if ENABLED(WEBSUPPORT)
#include "web.h"
- #include "spiffs.h"
#endif
-#elif ENABLED(EEPROM_SETTINGS)
- #include "spiffs.h"
#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
-// --------------------------------------------------------------------------
+// ------------------------
+// Public functions
+// ------------------------
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
+void HAL_init() {
+ i2s_init();
+}
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
+void HAL_init_board() {
+ #if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
+ spiffs_init();
+ #endif
-void HAL_init(void) {
#if ENABLED(WIFISUPPORT)
wifi_init();
#if ENABLED(OTASUPPORT)
OTA_init();
#endif
#if ENABLED(WEBSUPPORT)
- spiffs_init();
web_init();
#endif
server.begin();
- #elif ENABLED(EEPROM_SETTINGS)
- spiffs_init();
#endif
-
- i2s_init();
}
-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);
-}
+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();
-}
+int freeMemory() { return ESP.getFreeHeap(); }
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
#define ADC1_CHANNEL(pin) ADC1_GPIO ## pin ## _CHANNEL
adc1_channel_t get_channel(int pin) {
@@ -144,45 +128,135 @@ adc1_channel_t get_channel(int pin) {
case 33: return ADC1_CHANNEL(33);
case 32: return ADC1_CHANNEL(32);
}
-
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);
- adc1_config_channel_atten(get_channel(39), ADC_ATTEN_11db);
- adc1_config_channel_atten(get_channel(36), ADC_ATTEN_11db);
- adc1_config_channel_atten(get_channel(35), ADC_ATTEN_11db);
- adc1_config_channel_atten(get_channel(34), ADC_ATTEN_11db);
- adc1_config_channel_atten(get_channel(33), ADC_ATTEN_11db);
- adc1_config_channel_atten(get_channel(32), ADC_ATTEN_11db);
+
+ // 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_set_attenuation(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_TEMP_ADC_1
+ adc1_set_attenuation(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_TEMP_ADC_2
+ adc1_set_attenuation(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_TEMP_ADC_3
+ adc1_set_attenuation(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_TEMP_ADC_4
+ adc1_set_attenuation(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_TEMP_ADC_5
+ adc1_set_attenuation(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_HEATED_BED
+ adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
+ #endif
+ #if HAS_TEMP_CHAMBER
+ adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
+ #endif
+ #if ENABLED(FILAMENT_WIDTH_SENSOR)
+ 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);
+
+ // Change the attenuation level based on the new reading
+ adc_atten_t atten;
+ if (mv < thresholds[ADC_ATTEN_DB_0] - 100)
+ adc1_set_attenuation(chan, ADC_ATTEN_DB_0);
+ else if (mv > thresholds[ADC_ATTEN_DB_0] - 50 && mv < thresholds[ADC_ATTEN_DB_2_5] - 100)
+ adc1_set_attenuation(chan, ADC_ATTEN_DB_2_5);
+ else if (mv > thresholds[ADC_ATTEN_DB_2_5] - 50 && mv < thresholds[ADC_ATTEN_DB_6] - 100)
+ adc1_set_attenuation(chan, ADC_ATTEN_DB_6);
+ else if (mv > thresholds[ADC_ATTEN_DB_6] - 50)
+ adc1_set_attenuation(chan, ADC_ATTEN_DB_11);
+
+ HAL_adc_result = mv * 1023.0 / 3300.0;
+}
- HAL_adc_result = mv*1023.0/3300.0;
+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;
+ }
+
+ 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;
}
-int pin_to_channel[40] = {};
-int cnt_channel = 1;
-void analogWrite(int pin, int value) {
- if (pin_to_channel[pin] == 0) {
- ledcAttachPin(pin, cnt_channel);
- ledcSetup(cnt_channel, 490, 8);
- ledcWrite(cnt_channel, value);
+// Handle PWM timer interrupt
+HAL_PWM_TIMER_ISR() {
+ HAL_timer_isr_prologue(PWM_TIMER_NUM);
+
+ static uint8_t count = 0;
- pin_to_channel[pin] = cnt_channel++;
+ 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);
}
- ledcWrite(pin_to_channel[pin], value);
+ // 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 16859263b2e0..0736ff3c590f 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,40 +24,24 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// these are going to be re-defined in Arduino.h
-#undef DISABLED
-#undef M_PI
-#undef _BV
-
-#include
-
-// revert back to the correct (old) definition
-#undef DISABLED
-#define DISABLED(V...) DO(DIS,&&,V)
-// re-define in case Arduino.h has been skipped due to earlier inclusion (i.e. in Marlin\src\HAL\HAL_ESP32\i2s.cpp)
-#define _BV(b) (1UL << (b))
-
+#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;
@@ -81,34 +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);
@@ -119,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
@@ -133,6 +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
-void HAL_idletask(void);
-void HAL_init(void);
+#define BOARD_INIT() HAL_init_board();
+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 d48b14d6103b..eba880b4fdfe 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/Servo.cpp b/Marlin/src/HAL/HAL_ESP32/Servo.cpp
new file mode 100644
index 000000000000..c6be4b1280f3
--- /dev/null
+++ b/Marlin/src/HAL/HAL_ESP32/Servo.cpp
@@ -0,0 +1,71 @@
+/**
+ * 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 ARDUINO_ARCH_ESP32
+
+#include "../../inc/MarlinConfig.h"
+
+#if HAS_SERVOS
+
+#include "Servo.h"
+
+// 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++;
+}
+
+int8_t Servo::attach(const int pin) {
+ if (this->channel >= CHANNEL_MAX_NUM) return -1;
+ if (pin > 0) this->pin = pin;
+
+ ledcSetup(this->channel, 50, 16); // channel X, 50 Hz, 16-bit depth
+ ledcAttachPin(this->pin, this->channel);
+ return true;
+}
+
+void Servo::detach() { ledcDetachPin(this->pin); }
+
+int Servo::read() { return this->degrees; }
+
+void Servo::write(int inDegrees) {
+ this->degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
+ int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
+ int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
+ ledcWrite(channel, duty);
+}
+
+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 ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
+ this->detach();
+ #endif
+ }
+}
+#endif // HAS_SERVOS
+
+#endif // ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/HAL_ESP32/Servo.h b/Marlin/src/HAL/HAL_ESP32/Servo.h
new file mode 100644
index 000000000000..7b73ef0f3c2c
--- /dev/null
+++ b/Marlin/src/HAL/HAL_ESP32/Servo.h
@@ -0,0 +1,49 @@
+/**
+ * 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
+
+class Servo {
+ static const int MIN_ANGLE = 0,
+ MAX_ANGLE = 180,
+ MIN_PULSE_WIDTH = 544, // Shortest pulse sent to a servo
+ MAX_PULSE_WIDTH = 2400, // Longest pulse sent to a servo
+ TAU_MSEC = 20,
+ TAU_USEC = (TAU_MSEC * 1000),
+ MAX_COMPARE = ((1 << 16) - 1), // 65535
+ CHANNEL_MAX_NUM = 16;
+
+public:
+ Servo();
+ int8_t attach(const int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
+ void detach();
+ void write(int degrees); // set angle
+ void move(const int degrees); // attach the servo, then move to value
+ int read(); // returns current pulse width as an angle between 0 and 180 degrees
+
+private:
+ static int channel_next_free;
+ int channel;
+ int pin;
+ int degrees;
+};
diff --git a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
index bdc804dacf24..9a38d3996a65 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
@@ -38,9 +38,9 @@ AsyncWebSocket ws("/ws"); // TODO Move inside the class.
RingBuffer::RingBuffer(ring_buffer_pos_t size)
: data(new uint8_t[size]),
+ size(size),
read_index(0),
- write_index(0),
- size(size)
+ write_index(0)
{}
RingBuffer::~RingBuffer() { delete[] data; }
@@ -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 610058755583..9590271b0102 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 @@ class RingBuffer {
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 @@ class WebSocketSerial: public Stream {
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 d4c8cbd4902a..31a3e4d6678f 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 87%
rename from Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/fastio.h
index b71ca784181f..1641116b9023 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,8 +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 USEABLE_HARDWARE_PWM(P) (!IS_I2S_EXPANDER_PIN(P) && PWM_PIN(P))
+#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 0345889e0767..1f7c508cf1c4 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,14 +21,11 @@
*/
#ifdef ARDUINO_ARCH_ESP32
-// replace that with the proper imports, then cleanup workarounds in Marlin\src\HAL\HAL_ESP32\HAL.h
-#include
-// revert back to the correct definition
-#undef DISABLED
-#define DISABLED(V...) DO(DIS,&&,V)
+#include "../../inc/MarlinConfigPre.h"
#include "i2s.h"
-#include "../../core/macros.h"
+
+#include "../shared/Marduino.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/i2s_struct.h"
@@ -59,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])
@@ -143,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();
@@ -187,22 +184,22 @@ int i2s_init() {
// Allocate the array of pointers to the buffers
dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT);
- if (dma.buffers == NULL) return -1;
+ if (dma.buffers == nullptr) return -1;
// Allocate each buffer that can be used by the DMA controller
for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
dma.buffers[buf_idx] = (uint32_t*) heap_caps_calloc(1, DMA_BUF_LEN, MALLOC_CAP_DMA);
- if (dma.buffers[buf_idx] == NULL) return -1;
+ if (dma.buffers[buf_idx] == nullptr) return -1;
}
// Allocate the array of DMA descriptors
dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT);
- if (dma.desc == NULL) return -1;
+ if (dma.desc == nullptr) return -1;
// Allocate each DMA descriptor that will be used by the DMA controller
for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
dma.desc[buf_idx] = (lldesc_t*) heap_caps_malloc(sizeof(lldesc_t), MALLOC_CAP_DMA);
- if (dma.desc[buf_idx] == NULL) return -1;
+ if (dma.desc[buf_idx] == nullptr) return -1;
}
// Initialize
@@ -257,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;
@@ -301,11 +304,11 @@ int i2s_init() {
// Allocate and Enable the I2S interrupt
intr_handle_t i2s_isr_handle;
- esp_intr_alloc(ETS_I2S0_INTR_SOURCE, 0, i2s_intr_handler_default, NULL, &i2s_isr_handle);
+ esp_intr_alloc(ETS_I2S0_INTR_SOURCE, 0, i2s_intr_handler_default, nullptr, &i2s_isr_handle);
esp_intr_enable(i2s_isr_handle);
// Create the task that will feed the buffer
- xTaskCreate(stepperTask, "StepperTask", 10000, NULL, 1, NULL);
+ xTaskCreate(stepperTask, "StepperTask", 10000, nullptr, 1, nullptr);
// Route the i2s pins to the appropriate GPIO
gpio_matrix_out_check(I2S_DATA, I2S0O_DATA_OUT23_IDX, 0, 0);
@@ -317,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 fbe7b2419ac3..971405a3430e 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
@@ -21,6 +21,8 @@
*/
#pragma once
+#include
+
// current value of the outputs provided over i2s
extern uint32_t i2s_port_data;
@@ -31,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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 f911d84ce099..9c62a353e780 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 40ec1ab8754b..98ea3b5eb7ea 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 80e04e123db1..7e89e93ce237 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 795edf678144..5227da356860 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
@@ -28,25 +28,38 @@
#include "../shared/persistent_store_api.h"
-#include "SPIFFS.h"
-#include "FS.h"
+#include
+#include
#include "spiffs.h"
#define HAL_ESP32_EEPROM_SIZE 4096
+#define HAL_ESP32_EEPROM_FILE_PATH "/eeprom.dat"
File eeprom_file;
bool PersistentStore::access_start() {
if (spiffs_initialized) {
- eeprom_file = SPIFFS.open("/eeprom.dat", "r+");
+ eeprom_file = SPIFFS.open(HAL_ESP32_EEPROM_FILE_PATH, "r+");
size_t file_size = eeprom_file.size();
if (file_size < HAL_ESP32_EEPROM_SIZE) {
- bool write_ok = eeprom_file.seek(file_size);
-
- while (write_ok && file_size < HAL_ESP32_EEPROM_SIZE) {
- write_ok = eeprom_file.write(0xFF) == 1;
- file_size++;
+ SERIAL_ECHO_MSG("SPIFFS EEPROM settings file " HAL_ESP32_EEPROM_FILE_PATH " is too small or did not exist, expanding.");
+ SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR(" file size: ", file_size, ", required size: ", HAL_ESP32_EEPROM_SIZE);
+
+ // mode r+ does not allow to expand the file (at least on ESP32 SPIFFS9, so we close, reopen "a", append, close, reopen "r+"
+ eeprom_file.close();
+
+ eeprom_file = SPIFFS.open(HAL_ESP32_EEPROM_FILE_PATH, "a");
+ for (size_t i = eeprom_file.size(); i < HAL_ESP32_EEPROM_SIZE; i++)
+ eeprom_file.write(0xFF);
+ eeprom_file.close();
+
+ eeprom_file = SPIFFS.open(HAL_ESP32_EEPROM_FILE_PATH, "r+");
+ file_size = eeprom_file.size();
+ if (file_size < HAL_ESP32_EEPROM_SIZE) {
+ SERIAL_ERROR_MSG("Failed to expand " HAL_ESP32_EEPROM_FILE_PATH " to required size. SPIFFS partition full?");
+ SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(" file size: ", file_size, ", required size: ", HAL_ESP32_EEPROM_SIZE);
+ SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(" SPIFFS used bytes: ", SPIFFS.usedBytes(), ", total bytes: ", SPIFFS.totalBytes());
}
}
return true;
diff --git a/Marlin/src/HAL/HAL_ESP32/servotimers.h b/Marlin/src/HAL/HAL_ESP32/servotimers.h
index 0604ca0a2595..85f26f40162e 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 4ef6d14ec311..03ab215224f3 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 c960f386d403..a3e1bd8a255f 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
@@ -28,16 +28,16 @@
#include "../../core/serial.h"
-#include "FS.h"
-#include "SPIFFS.h"
+#include
+#include
bool spiffs_initialized;
void spiffs_init() {
- if (SPIFFS.begin())
+ if (SPIFFS.begin(true)) // formatOnFail = true
spiffs_initialized = true;
else
- SERIAL_ECHO_MSG("SPIFFS mount failed");
+ SERIAL_ERROR_MSG("SPIFFS mount failed");
}
#endif // WEBSUPPORT
diff --git a/Marlin/src/HAL/HAL_ESP32/spiffs.h b/Marlin/src/HAL/HAL_ESP32/spiffs.h
index e1573340cda6..8a1ee2f1919f 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 63%
rename from Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/timers.cpp
index 39ca18fcea1c..79a79e37cdf2 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"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
+#include "timers.h"
-// --------------------------------------------------------------------------
+// ------------------------
// 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, NULL }, // 2
- { TIMER_GROUP_1, TIMER_1, 1, NULL }, // 3
+ { 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, NULL, NULL);
+ timer_isr_register(timer.group, timer.idx, timer_isr, (void*)timer_num, 0, nullptr);
timer_start(timer.group, timer.idx);
}
@@ -169,10 +143,8 @@ hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
*/
hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
const tTimerConfig timer = TimerConfig[timer_num];
-
uint64_t counter_value;
timer_get_counter_value(timer.group, timer.idx, &counter_value);
-
return counter_value;
}
@@ -181,7 +153,7 @@ hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
* @param timer_num timer number to enable interrupts on
*/
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
- const tTimerConfig timer = TimerConfig[timer_num];
+ //const tTimerConfig timer = TimerConfig[timer_num];
//timer_enable_intr(timer.group, timer.idx);
}
@@ -190,8 +162,8 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) {
* @param timer_num timer number to disable interrupts on
*/
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
- const tTimerConfig timer = TimerConfig[timer_num];
- // timer_disable_intr(timer.group, timer.idx);
+ //const tTimerConfig timer = TimerConfig[timer_num];
+ //timer_disable_intr(timer.group, timer.idx);
}
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h b/Marlin/src/HAL/HAL_ESP32/timers.h
similarity index 74%
rename from Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/timers.h
index 7fbaa5222dda..4b01f4ba7c45 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,16 +21,17 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "driver/timer.h"
-// --------------------------------------------------------------------------
+// Includes needed to get I2S_STEPPER_STREAM. Note that pins.h
+// is included in case this header is being included early.
+#include "../../inc/MarlinConfig.h"
+#include "../../pins/pins.h"
+
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -39,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
@@ -58,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
@@ -69,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)
-
-extern "C" void tempTC_Handler(void);
-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();
+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 b1c98cb55c05..d05e67c856a3 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 87%
rename from Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/watchdog.h
index 6ee92a73eca0..e5dd3b46d33f 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
diff --git a/Marlin/src/HAL/HAL_ESP32/web.cpp b/Marlin/src/HAL/HAL_ESP32/web.cpp
index cb06cfc7e442..c593fc024216 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 "SPIFFS.h"
#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 4173fd91b0f1..d1d91b9c0f03 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 9fb5459ae07a..19f1d8fb8541 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
@@ -22,6 +22,7 @@
#ifdef ARDUINO_ARCH_ESP32
+#include "../../core/serial.h"
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(WIFISUPPORT)
@@ -38,20 +39,28 @@ AsyncWebServer server(80);
#endif
void wifi_init() {
+
+ SERIAL_ECHO_MSG("Starting WiFi...");
+
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PWD);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
+ SERIAL_ERROR_MSG("Unable to connect to WiFi with SSID '" WIFI_SSID "', restarting.");
delay(5000);
ESP.restart();
}
delay(10);
-
- // Loop forever (watchdog kill) on failure
- if (!MDNS.begin(WIFI_HOSTNAME)) for(;;) delay(5000);
+ if (!MDNS.begin(WIFI_HOSTNAME)) {
+ SERIAL_ERROR_MSG("Unable to start mDNS with hostname '" WIFI_HOSTNAME "', restarting.");
+ delay(5000);
+ ESP.restart();
+ }
MDNS.addService("http", "tcp", 80);
+
+ SERIAL_ECHOLNPAIR("Successfully connected to WiFi with SSID '" WIFI_SSID "', hostname: '" WIFI_HOSTNAME "', IP address: ", WiFi.localIP().toString().c_str());
}
#endif // WIFISUPPORT
diff --git a/Marlin/src/HAL/HAL_ESP32/wifi.h b/Marlin/src/HAL/HAL_ESP32/wifi.h
index 7be40ef9006c..4cd656cb3399 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 3d2dd5cd8254..316f6b452a4b 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 1057fae99521..39d68a7a1083 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
@@ -47,23 +43,24 @@ uint8_t _getc();
//arduino: Print.h
#define DEC 10
#define HEX 16
-#define OCT 8
-#define BIN 2
+#define OCT 8
+#define BIN 2
//arduino: binary.h (weird defines)
#define B01 1
#define B10 2
#include "hardware/Clock.h"
-#include
-
+#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 "serial.h"
+#define SHARED_SERVOS HAS_SERVOS
+
extern HalSerial usb_serial;
#define MYSERIAL0 usb_serial
#define NUM_SERIAL 1
@@ -81,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)
@@ -98,10 +92,10 @@ 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();
/* ---------------- 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 0b4322512f41..000000000000
--- 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 408c96153d5c..7915d685eafa 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 8eae771a4fd6..5c2d6fcb7e3e 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
@@ -25,7 +25,7 @@
* Fast I/O Routines for X86_64
*/
-#include
+#include "../shared/Marduino.h"
#include
#define SET_DIR_INPUT(IO) Gpio::setDir(IO, 1)
@@ -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
@@ -80,21 +78,10 @@
/// check if pin is an output
#define _IS_OUTPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
-// hg42: HAS_TIMER is used only to check if it's a PWM pin
-// hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
-// hg42: instead use PWM bit from the #define
-
-/// check if pin is a timer
-#define _HAS_TIMER(IO) true // could be LPC1768_PIN_PWM(IO), but there
-// hg42: could be this:
-// #define _HAS_TIMER(IO) LPC1768_PIN_PWM(IO)
-// but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
-
/// Read a pin wrapper
#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
@@ -116,14 +103,9 @@
/// check if pin is an output wrapper
#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
-/// check if pin is a timer (wrapper)
-#define HAS_TIMER(IO) _HAS_TIMER(IO)
-
// Shorthand
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
-
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp b/Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp
index 961f5c5d984d..39dd3d1b3bf5 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 e3dafe250abf..e61051a0a389 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 0aeeb9c67431..aced7281728d 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 a53ad029c474..37f3bc7a4411 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 0e2f94c356b0..59da64d337a3 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
@@ -49,7 +49,7 @@ void Heater::update() {
last = now;
heat += (heater_state - heat) * (delta / 1000000000.0);
- if (heat < room_temp_raw) heat = room_temp_raw;
+ NOLESS(heat, room_temp_raw);
Gpio::pin_map[analogInputToDigitalPin(adc_pin)].value = 0xFFFF - (uint16_t)heat;
}
}
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Heater.h b/Marlin/src/HAL/HAL_LINUX/hardware/Heater.h
index 90e9da21dfbe..e0c250f62c75 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 8fc2dc95c58b..675afd4a2140 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 61cce9c106cc..afc21259710b 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 c50390d7369a..df133e9e1826 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 0e3b4b7503af..1e8e887de5d4 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 10f725ae6861..1c930cfce181 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
@@ -51,7 +51,7 @@ void Timer::init(uint32_t sig_id, uint32_t sim_freq, callback_fn* fn) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = Timer::handler;
sigemptyset(&sa.sa_mask);
- if (sigaction(SIGRTMIN, &sa, NULL) == -1) {
+ if (sigaction(SIGRTMIN, &sa, nullptr) == -1) {
return; // todo: handle error
}
@@ -74,7 +74,7 @@ void Timer::start(uint32_t frequency) {
}
void Timer::enable() {
- if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) {
+ if (sigprocmask(SIG_UNBLOCK, &mask, nullptr) == -1) {
return; // todo: handle error
}
active = true;
@@ -82,7 +82,7 @@ void Timer::enable() {
}
void Timer::disable() {
- if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
+ if (sigprocmask(SIG_SETMASK, &mask, nullptr) == -1) {
return; // todo: handle error
}
active = false;
@@ -102,7 +102,7 @@ void Timer::setCompare(uint32_t compare) {
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
- if (timer_settime(timerid, 0, &its, NULL) == -1) {
+ if (timer_settime(timerid, 0, &its, nullptr) == -1) {
printf("timer(%ld) failed, compare: %d(%ld)\n", getID(), compare, its.it_value.tv_nsec);
return; // todo: handle error
}
diff --git a/Marlin/src/HAL/HAL_LINUX/hardware/Timer.h b/Marlin/src/HAL/HAL_LINUX/hardware/Timer.h
index 6aadbcbcb136..740d8ef4e8ac 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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..776fa2f1393d
--- /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 60f14cc44fb1..13a8206e1b1c 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 dca18a676b60..a4ddb1b1ffc1 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 effc464c73c3..a24f0b3ed132 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 9b439de98589..268bdeeeca00 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 @@ class HalSerial {
HalSerial() { host_connected = true; }
- void begin(int32_t baud) {
- }
+ void begin(int32_t baud) { }
+
+ void end() { }
int peek() {
uint8_t value;
@@ -107,11 +108,11 @@ class HalSerial {
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 @@ class HalSerial {
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 @@ class HalSerial {
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 71aab05b1ed9..4231affba778 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,13 +104,13 @@ void simulation_loop() {
}
}
-int main(void) {
+int main() {
std::thread write_serial (write_serial_thread);
std::thread read_serial (read_serial_thread);
#if NUM_SERIAL > 0
MYSERIAL0.begin(BAUDRATE);
- SERIAL_PRINTF("x86_64 Initialised\n");
+ SERIAL_ECHOLNPGM("x86_64 Initialized");
SERIAL_FLUSHTX();
#endif
diff --git a/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
index 5e0b4a4f2898..c4965d90e3ad 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,19 +29,20 @@
#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() {
const char eeprom_erase_value = 0xFF;
FILE * eeprom_file = fopen(filename, "rb");
- if (eeprom_file == NULL) return false;
+ if (eeprom_file == nullptr) return false;
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);
@@ -54,13 +55,13 @@ bool PersistentStore::access_start() {
bool PersistentStore::access_finish() {
FILE * eeprom_file = fopen(filename, "wb");
- if (eeprom_file == NULL) return false;
+ if (eeprom_file == nullptr) return false;
fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file);
fclose(eeprom_file);
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 cead56c30ab4..a28d2b60b928 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 c0e0a0c710ce..2aba9a37db21 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 fe510ddcff55..fdd09b1c037b 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 f7b46725af03..f293d7f40884 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 9505fc568a5c..8022aabd264d 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 a70eb82b9893..a1ecac1cb5df 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,19 @@
#include "watchdog.h"
-void watchdog_init(void) {}
+void watchdog_init() {}
-void HAL_clear_reset_source(void) {}
+void HAL_clear_reset_source() {}
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
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; }
+ void HAL_clear_reset_source() {}
+ uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
#endif // USE_WATCHDOG
#endif // __PLAT_LINUX__
diff --git a/Marlin/src/HAL/HAL_LINUX/watchdog.h b/Marlin/src/HAL/HAL_LINUX/watchdog.h
index 26a9f499fd30..5bc06f04f17d 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
@@ -21,14 +21,9 @@
*/
#pragma once
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 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 watchdog_reset();
+void HAL_clear_reset_source();
+uint8_t HAL_get_reset_source();
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 998e56b6defc..fefee386e590 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 ac242ca4ab7a..b684145e99de 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
@@ -30,10 +30,10 @@
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) {
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL.h b/Marlin/src/HAL/HAL_LPC1768/HAL.h
index 12d73c6713ec..cf2576de2504 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,20 +34,20 @@ void HAL_init();
#include
#include
-extern "C" volatile millis_t _millis;
-
-#include
-#include
-#include
+extern "C" volatile uint32_t _millis;
+#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
#include "fastio.h"
-#include
#include "watchdog.h"
-#include "HAL_timers.h"
+#include "timers.h"
#include "MarlinSerial.h"
+#include
+#include
+#include
+
//
// Default graphical display delays
//
@@ -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 for the ADC readings to stabilize before they start causing thermal protection errors.
-#define THERMAL_PROTECTION_GRACE_PERIOD 500
-
// 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);
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL_SPI.cpp
similarity index 92%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
rename to Marlin/src/HAL/HAL_LPC1768/HAL_SPI.cpp
index 31dc9c4da04f..5652db988b9c 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 589c65e03e2c..a8778f7446b8 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 ca59a5b72193..1f282f64a3f2 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 @@ class MarlinSerial : public HardwareSerial {
{
}
+ 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 2338b34ee350..000000000000
--- 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/MarlinServo.h b/Marlin/src/HAL/HAL_LPC1768/Servo.h
similarity index 92%
rename from Marlin/src/HAL/HAL_LPC1768/MarlinServo.h
rename to Marlin/src/HAL/HAL_LPC1768/Servo.h
index 925e5a7e456d..8b511032cb9c 100644
--- a/Marlin/src/HAL/HAL_LPC1768/MarlinServo.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
@@ -50,7 +51,7 @@
#include
-class MarlinServo: public Servo {
+class libServo: public Servo {
public:
void move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
@@ -67,4 +68,4 @@ class MarlinServo: public Servo {
}
};
-#define HAL_SERVO_LIB MarlinServo
+#define HAL_SERVO_LIB libServo
diff --git a/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h b/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
index d853962e0cbe..53e4b1580998 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 5e3c2ae6cbf5..7af3a07eeae0 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
diff --git a/Marlin/src/HAL/HAL_LPC1768/fastio.h b/Marlin/src/HAL/HAL_LPC1768/fastio.h
index 49f8ec13c35c..a00a4946c165 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
@@ -33,10 +33,9 @@
* For TARGET LPC1768
*/
-#include
+#include "../shared/Marduino.h"
-#define PWM_PIN(P) true // all pins are PWM capable
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
+#define PWM_PIN(P) true // all pins are PWM capable
#define LPC_PIN(pin) gpio_pin(pin)
#define LPC_GPIO(port) gpio_port(port)
@@ -64,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
@@ -89,15 +86,10 @@
/// check if pin is an output
#define _IS_OUTPUT(IO) (gpio_get_dir(IO))
-/// check if pin is a timer
-/// all gpio pins are pwm capable, either interrupt or hardware pwm controlled
-#define _HAS_TIMER(IO) true
-
/// Read a pin wrapper
#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
@@ -119,9 +111,6 @@
/// check if pin is an output wrapper
#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
-/// check if pin is a timer (wrapper)
-#define HAS_TIMER(IO) _HAS_TIMER(IO)
-
// Shorthand
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..6223e006df45
--- /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 edffb1556e88..559759ea031f 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 ae088ed250df..3ad1aff01719 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 9fba04c03cc9..d7e4b0dc7a43 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 cc74eedc1bd9..ab5b184b4752 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 PIN_EXISTS(ONBOARD_SD_CS) && ONBOARD_SD_CS_PIN != SS_PIN
+ OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH);
#endif
- #if defined(ONBOARD_SD_CS) && ONBOARD_SD_CS > -1
- WRITE(ONBOARD_SD_CS, HIGH);
- SET_OUTPUT(ONBOARD_SD_CS);
+ #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,8 +149,8 @@ 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
@@ -127,7 +158,7 @@ void HAL_idletask(void) {
// the disk if Marlin has it mounted. Unfortuately 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 c3c6f672548f..cafa53b30e1f 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 4b02544e1ba0..dac7d7a3a93a 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 7f8bfe2f0270..2454dea19577 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 af3d7c92e704..e39f2d245307 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 c0a072851e1d..acf991a9d790 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 26427bbacc43..7bf7ff388051 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 85%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_timers.h
rename to Marlin/src/HAL/HAL_LPC1768/timers.h
index e90cdf2488aa..73ea728af17e 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) {
@@ -126,15 +122,15 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
FORCE_INLINE static void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
- case 0: NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
- case 1: NVIC_EnableIRQ(TIMER1_IRQn); // Enable interrupt handler
+ case 0: NVIC_EnableIRQ(TIMER0_IRQn); break; // Enable interrupt handler
+ case 1: NVIC_EnableIRQ(TIMER1_IRQn); break; // Enable interrupt handler
}
}
FORCE_INLINE static void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
- case 0: NVIC_DisableIRQ(TIMER0_IRQn); // Disable interrupt handler
- case 1: NVIC_DisableIRQ(TIMER1_IRQn); // Disable interrupt handler
+ case 0: NVIC_DisableIRQ(TIMER0_IRQn); break; // Disable interrupt handler
+ case 1: NVIC_DisableIRQ(TIMER1_IRQn); break; // Disable interrupt handler
}
// We NEED memory barriers to ensure Interrupts are actually disabled!
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 1e3cb04987a7..dc81396b092a 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 296858fa282a..9dd594cd9ef7 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 2deb09465709..1153329d8987 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 d329c1853799..8806e8747704 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 4c8708495f13..d441b7b4d06a 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 3c89d4e987b3..569706b483df 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 65de10dea748..057a1374450a 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 58631a1e1795..b624b24d35ac 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
@@ -109,7 +109,7 @@ uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_v
case U8G_COM_MSG_INIT:
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
//u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
- //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
+ //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* initial RS state: unknown mode */
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
u8g_com_ssd_I2C_start_sequence(u8g);
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 8b2cab7b0a95..0222c62280e1 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
@@ -178,7 +178,7 @@ uint8_t u8g_com_HAL_LPC1768_ssd_sw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_v
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
//u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
- //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
+ //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* initial RS state: unknown mode */
u8g_i2c_init_sw(u8g->pin_list[U8G_PI_I2C_OPTION]);
u8g_com_ssd_I2C_start_sequence_sw(u8g);
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 3a9ffa8e239a..ac289c1a209b 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 0931f7858adc..59414e896b1e 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
@@ -57,7 +57,7 @@
#include "../../../inc/MarlinConfigPre.h"
-#if HAS_GRAPHICAL_LCD
+#if ENABLED(U8GLIB_ST7920)
#include
#include "SoftwareSPI.h"
@@ -98,7 +98,7 @@ uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t ar
u8g_SetPILevel(u8g, U8G_PI_SCK, 0);
u8g_SetPILevel(u8g, U8G_PI_MOSI, 0);
- u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
+ u8g->pin_list[U8G_PI_A0_STATE] = 0; /* initial RS state: command mode */
break;
case U8G_COM_MSG_STOP:
@@ -141,6 +141,5 @@ uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t ar
return 1;
}
-#endif // HAS_GRAPHICAL_LCD
-
+#endif // U8GLIB_ST7920
#endif // TARGET_LPC1768
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 e851284ad55f..e243d4001367 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
@@ -57,19 +57,19 @@
#include "../../../inc/MarlinConfigPre.h"
-#if HAS_GRAPHICAL_LCD
+#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
-#include
#include "SoftwareSPI.h"
#undef SPI_SPEED
#define SPI_SPEED 2 // About 2 MHz
+#include
#include
#include
#include
-#include
+#include
uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
@@ -158,7 +158,19 @@ uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
break;
case U8G_COM_MSG_CHIP_SELECT:
- u8g_SetPILevel(u8g, U8G_PI_CS, !arg_val);
+ #if ENABLED(FYSETC_MINI_12864) // 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
+ u8g_SetPILevel(u8g, U8G_PI_SCK, 1); // Set SCK to mode 3 idle state before CS goes active
+ u8g_SetPILevel(u8g, U8G_PI_CS, LOW);
+ }
+ else {
+ u8g_SetPILevel(u8g, U8G_PI_CS, HIGH);
+ u8g_SetPILevel(u8g, U8G_PI_SCK, 0); // Set SCK to mode 0 idle state after CS goes inactive
+ }
+ #else
+ u8g_SetPILevel(u8g, U8G_PI_CS, !arg_val);
+ #endif
break;
case U8G_COM_MSG_WRITE_BYTE:
@@ -191,6 +203,5 @@ uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
return 1;
}
-#endif // HAS_GRAPHICAL_LCD
-
+#endif // HAS_GRAPHICAL_LCD && !U8GLIB_ST7920
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py b/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
index 59c5f5143643..44e0f09ad01a 100644
--- a/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
+++ b/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
@@ -3,6 +3,7 @@
# if target_filename is found then that drive is used
# else if target_drive is found then that drive is used
#
+from __future__ import print_function
target_filename = "FIRMWARE.CUR"
target_drive = "REARM"
@@ -12,11 +13,11 @@
current_OS = platform.system()
Import("env")
-def detect_error(e):
- print '\nUnable to find destination disk (' + e + ')\n' \
+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)\n' \
- 'or copy the firmware (.pioenvs/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n'
+ '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \
+ 'or copy the firmware (.pio/build/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n')
try:
if current_OS == 'Windows':
@@ -63,9 +64,9 @@ def detect_error(e):
env.Replace(
UPLOAD_PORT=upload_disk
)
- print 'upload disk: ', upload_disk
+ print('upload disk: ', upload_disk)
else:
- detect_error('Autodetect Error')
+ print_error('Autodetect Error')
elif current_OS == 'Linux':
#
@@ -100,9 +101,9 @@ def detect_error(e):
UPLOAD_FLAGS="-P$UPLOAD_PORT",
UPLOAD_PORT=upload_disk
)
- print 'upload disk: ', upload_disk
+ print('upload disk: ', upload_disk)
else:
- detect_error('Autodetect Error')
+ print_error('Autodetect Error')
elif current_OS == 'Darwin': # MAC
#
@@ -133,9 +134,9 @@ def detect_error(e):
env.Replace(
UPLOAD_PORT=upload_disk
)
- print '\nupload disk: ', upload_disk, '\n'
+ print('\nupload disk: ', upload_disk, '\n')
else:
- detect_error('Autodetect Error')
+ print_error('Autodetect Error')
except Exception as e:
- detect_error(str(e))
+ print_error(str(e))
diff --git a/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp b/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp
index d143bae7098b..c83931745aa3 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 4418cc2364e3..55e3628603ad 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,11 +56,11 @@ void watchdog_init(void) {
WDT_Start(WDT_TIMEOUT);
}
-void HAL_clear_reset_source(void) {
+void HAL_clear_reset_source() {
WDT_ClrTimeOutFlag();
}
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
return RST_POWER_ON;
}
@@ -74,10 +74,10 @@ void watchdog_reset() {
#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; }
+void watchdog_init() {}
+void watchdog_reset() {}
+void HAL_clear_reset_source() {}
+uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
#endif // USE_WATCHDOG
diff --git a/Marlin/src/HAL/HAL_LPC1768/watchdog.h b/Marlin/src/HAL/HAL_LPC1768/watchdog.h
index 26a9f499fd30..5bc06f04f17d 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
@@ -21,14 +21,9 @@
*/
#pragma once
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 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 watchdog_reset();
+void HAL_clear_reset_source();
+uint8_t HAL_get_reset_source();
diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL.cpp b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp
new file mode 100644
index 000000000000..d80dd17aab1c
--- /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 ? 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 000000000000..3489a4d285f9
--- /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 000000000000..bbd12912a2c1
--- /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 000000000000..2da4d8c07e00
--- /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 527325d6f4c7..0768d8a04eff 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 000000000000..d29d134c0056
--- /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 000000000000..dbae75042513
--- /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_SAMD51/ServoTimers.h b/Marlin/src/HAL/HAL_SAMD51/ServoTimers.h
new file mode 100644
index 000000000000..8b77d5b50334
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/ServoTimers.h
@@ -0,0 +1,39 @@
+/**
+ * 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 _useTimer1
+#define _useTimer2
+
+#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 000000000000..1f66e02e3129
--- /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 000000000000..ecd9acea44dc
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..0f27d8bf355c
--- /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 000000000000..e41dd85c8556
--- /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 000000000000..64f6929c00a7
--- /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 000000000000..3315fa08ac5f
--- /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 000000000000..63902c3c5e26
--- /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 000000000000..80c37d14af85
--- /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 000000000000..a60bcedd8a32
--- /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
+
+ watchdog_reset();
+
+ 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 000000000000..1c4e7542f238
--- /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 watchdog_reset() {
+ 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 881168a12922..e70d575788f8 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
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
+#endif
-// --------------------------------------------------------------------------
+// ------------------------
// 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,16 @@ 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);
}
-uint16_t HAL_adc_get_result(void) {
+uint16_t HAL_adc_get_result() {
return HAL_adc_result;
}
-#endif // ARDUINO_ARCH_STM32
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/HAL.h b/Marlin/src/HAL/HAL_STM32/HAL.h
index d08a49587f3c..e275290ce5ab 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,27 +24,24 @@
#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.h"
+#include "watchdog.h"
-#include
+#include "../../inc/MarlinConfigPre.h"
-#include "Arduino.h"
+#include
#ifdef USBCON
#include
#endif
-#include "../../inc/MarlinConfigPre.h"
-#include "../shared/math_32bit.h"
-#include "../shared/HAL_SPI.h"
-#include "fastio_STM32.h"
-#include "watchdog_STM32.h"
-
-// --------------------------------------------------------------------------
+// ------------------------
// 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,65 +124,50 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 8
-#define RST_JTAG 16
-#define RST_SOFTWARE 32
-#define RST_BACKUP 64
-
-// --------------------------------------------------------------------------
+// ------------------------
// 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
@@ -194,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
@@ -203,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
@@ -211,7 +193,7 @@ 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
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 86cdb578111c..45bd26d720b9 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 6c6ede24b48d..000000000000
--- 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 88%
rename from Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/Servo.cpp
index 1f22767e2784..93154f784762 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,12 +22,11 @@
*/
#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 };
@@ -55,4 +54,4 @@ void libServo::move(const int value) {
}
#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 87%
rename from Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h
rename to Marlin/src/HAL/HAL_STM32/Servo.h
index 6805c48a54a3..a782c130e42f 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
diff --git a/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
index 23eca4bab7db..d0aa731e890d 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 3ee075cf26e3..33685ceddac1 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 77%
rename from Marlin/src/HAL/HAL_STM32/fastio_STM32.h
rename to Marlin/src/HAL/HAL_STM32/fastio.h
index bd2edb449571..917ee3a1a630 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)
@@ -80,10 +79,8 @@ void FastIO_init(); // Must be called before using fast io macros
#define IS_INPUT(IO)
#define IS_OUTPUT(IO)
-#define HAS_TIMER(IO) digitalPinHasPWM(IO)
-#define PWM_PIN(P) HAS_TIMER(P)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
+#define PWM_PIN(P) digitalPinHasPWM(P)
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..9a1727bceb00
--- /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 a6c50f0f7de1..c94bce3b650e 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 000000000000..6ce63073c4a2
--- /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 ac8b00575436..4e27cee195d3 100644
--- a/Marlin/src/HAL/HAL_STM32/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_STM32/pinsDebug.h
@@ -1 +1,34 @@
-#error "Debug pins 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 000000000000..b1c256218596
--- /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 000000000000..9d9796eabecb
--- /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 000000000000..84278c391683
--- /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 ba325b48e4ad..f8c9546b6389 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 28d8d095c74b..51f84e657fa6 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
-// --------------------------------------------------------------------------
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "HAL.h"
-#include "HAL_timers_STM32.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
+#include "timers.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define NUM_HARDWARE_TIMERS 2
-//#define PRESCALER 1
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
-
-stm32f4_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
+// ------------------------
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
+stm32_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
-// --------------------------------------------------------------------------
+// ------------------------
// 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 e92da9a5c8b0..aefe880b4e63 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 76%
rename from Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/watchdog.cpp
index e47de649536f..8963d55cfc88 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() {
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 86%
rename from Marlin/src/HAL/HAL_STM32/watchdog_STM32.h
rename to Marlin/src/HAL/HAL_STM32/watchdog.h
index bd3598c0bbf8..f062d8a2e6f8 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
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
index 1534a35756da..e1f2e21ffd7b 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"
-// --------------------------------------------------------------------------
-// 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. Unfortuately 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,16 +293,20 @@ 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);
- adc.setDMA(HAL_adc_results, (uint16_t)ADC_PIN_COUNT, (uint32_t)(DMA_MINC_MODE | DMA_CIRC_MODE), (void (*)())NULL);
+ #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();
adc.startConversion();
@@ -279,6 +315,7 @@ void HAL_adc_init(void) {
void HAL_adc_start_conversion(const uint8_t adc_pin) {
TEMP_PINS pin_index;
switch (adc_pin) {
+ default: return;
#if HAS_TEMP_ADC_0
case TEMP_0_PIN: pin_index = TEMP_0; break;
#endif
@@ -303,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
@@ -310,8 +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 66c4cba59e77..f1017c82dfdb 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,45 +28,41 @@
#define CPU_32_BIT
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
+#include "../../core/macros.h"
+#include "../shared/Marduino.h"
+#include "../shared/math_32bit.h"
+#include "../shared/HAL_SPI.h"
+
+#include "fastio.h"
+#include "watchdog.h"
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
+#include "timers.h"
#include
#include
-#include
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "../shared/math_32bit.h"
-#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F1.h"
-#include "watchdog_STM32F1.h"
-
-#include "HAL_timers_STM32F1.h"
#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
@@ -119,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
@@ -131,7 +128,7 @@ void HAL_init();
#endif
#ifndef digitalPinHasPWM
- #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != NULL)
+ #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
#endif
#define CRITICAL_SECTION_START uint32_t primask = __get_primask(); (void)__iCliRetVal()
@@ -159,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()
@@ -185,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;
@@ -208,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));
@@ -218,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
//
@@ -248,29 +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();
-uint16_t HAL_adc_get_result(void);
-
-/* Todo: Confirm none of this is needed.
-uint16_t HAL_getAdcReading(uint8_t chan);
-
-void HAL_startAdcConversion(uint8_t chan);
-uint8_t HAL_pinToAdcChannel(int pin);
-
-uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
-//uint16_t HAL_getAdcSuperSample(uint8_t chan);
-
-void HAL_enable_AdcFreerun(void);
-//void HAL_disable_AdcFreerun(uint8_t chan);
-
-*/
+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
@@ -278,3 +253,6 @@ void HAL_enable_AdcFreerun(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 cbc6c7fe1a86..9f3f34239d4a 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 f8fc315ba059..000000000000
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp
+++ /dev/null
@@ -1,120 +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;
-
- this->pin = pin;
- this->minAngle = minAngle;
- this->maxAngle = maxAngle;
-
- timer_dev *tdev = PIN_MAP[this->pin].timer_device;
- uint8_t tchan = PIN_MAP[this->pin].timer_channel;
-
- pinMode(this->pin, PWM);
- pwmWrite(this->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);
-
- 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 7defdc8749ee..b5bd5141fbff 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 000000000000..bc10824c8b9f
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SPI.cpp
@@ -0,0 +1,726 @@
+/******************************************************************************
+ * 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) {
+ this->write(data);
+ return 1;
+}
+
+uint8_t SPIClass::send(uint8_t *buf, uint32_t len) {
+ this->write(buf, len);
+ return len;
+}
+
+uint8_t SPIClass::recv() {
+ return this->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 000000000000..20f22431f690
--- /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 clock, BitOrder bitOrder, uint8_t dataMode) {
+ if (__builtin_constant_p(clock))
+ init_AlwaysInline(clock, bitOrder, dataMode, DATA_SIZE_8BIT);
+ else
+ init_MightInline(clock, bitOrder, dataMode, DATA_SIZE_8BIT);
+ }
+ SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) {
+ if (__builtin_constant_p(clock))
+ init_AlwaysInline(clock, bitOrder, dataMode, dataSize);
+ else
+ init_MightInline(clock, bitOrder, dataMode, dataSize);
+ }
+ SPISettings(uint32_t clock) {
+ if (__builtin_constant_p(clock))
+ init_AlwaysInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ else
+ init_MightInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+ SPISettings() {
+ init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+private:
+ void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) {
+ init_AlwaysInline(clock, bitOrder, dataMode, dataSize);
+ }
+ void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) __attribute__((__always_inline__)) {
+ this->clock = clock;
+ this->bitOrder = bitOrder;
+ this->dataMode = dataMode;
+ this->dataSize = dataSize;
+ }
+ 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 c1470ca51ea3..000000000000
--- 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 000000000000..9db978637dca
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/Servo.cpp
@@ -0,0 +1,232 @@
+/**
+ * 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), 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)))
+
+void libServo::servoWrite(uint8_t pin, uint16_t duty_cycle) {
+ #ifdef SERVO0_TIMER_NUM
+ if (this->servoIndex == 0) {
+ this->pwmSetDuty(duty_cycle);
+ return;
+ }
+ #endif
+
+ timer_dev *tdev = PIN_MAP[pin].timer_device;
+ uint8_t tchan = PIN_MAP[pin].timer_channel;
+ if (tdev) timer_set_compare(tdev, tchan, duty_cycle);
+}
+
+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 (pin >= BOARD_NR_GPIO_PINS) return false;
+
+ this->minAngle = minAngle;
+ this->maxAngle = maxAngle;
+ this->angle = -1;
+
+ #ifdef SERVO0_TIMER_NUM
+ if (this->servoIndex == 0 && this->setupSoftPWM(pin)) {
+ this->pin = pin; // set attached()
+ return true;
+ }
+ #endif
+
+ if (!PWM_PIN(pin)) return false;
+
+ timer_dev *tdev = PIN_MAP[pin].timer_device;
+ //uint8_t tchan = PIN_MAP[pin].timer_channel;
+
+ SET_PWM(pin);
+ servoWrite(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;
+ this->angle = -1;
+ servoWrite(this->pin, 0);
+ return true;
+}
+
+int32_t libServo::read() const {
+ if (this->attached()) {
+ #ifdef SERVO0_TIMER_NUM
+ if (this->servoIndex == 0) return this->angle;
+ #endif
+ 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()) {
+ this->angle = constrain(value, this->minAngle, this->maxAngle);
+ servoWrite(this->pin, US_TO_COMPARE(ANGLE_TO_US(this->angle)));
+ safe_delay(servo_delay[this->servoIndex]);
+ #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
+ this->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 pin) {
+ timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
+ if (!tdev) return false;
+ #ifdef SERVO0_PWM_OD
+ OUT_WRITE_OD(pin, 1);
+ #else
+ OUT_WRITE(pin, 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(this->pin, 1); // off
+ #else
+ OUT_WRITE(this->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 pin) { 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 82%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/Servo.h
index ac83f086ee5f..f97ca7486bbe 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
@@ -46,8 +46,15 @@ class libServo {
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 000000000000..99772a03c209
--- /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 000000000000..0692b7e9f303
--- /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 ce5a06674185..6310740fe0d8 100644
--- a/Marlin/src/HAL/HAL_STM32F1/STM32F1_flag_script.py
+++ b/Marlin/src/HAL/HAL_STM32F1/build_flags.py
@@ -4,12 +4,10 @@
#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 64%
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 1d2153d20852..9d569772faed 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
*/
-#if defined(ARDUINO_ARCH_STM32F1) && (defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY))
+#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 != NULL)
+ 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
@@ -226,14 +236,19 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
gpio_set_mode(GPIOD, 9, GPIO_AF_OUTPUT_PP); // FSMC_D14
gpio_set_mode(GPIOD, 10, GPIO_AF_OUTPUT_PP); // FSMC_D15
- gpio_set_mode(GPIOD, 4, GPIO_AF_OUTPUT_PP); // FSMC_NOE
- gpio_set_mode(GPIOD, 5, GPIO_AF_OUTPUT_PP); // FSMC_NWE
+ gpio_set_mode(GPIOD, 4, GPIO_AF_OUTPUT_PP); // FSMC_NOE
+ gpio_set_mode(GPIOD, 5, GPIO_AF_OUTPUT_PP); // FSMC_NWE
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
- 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;
+ #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)
+ FSMC_NOR_PSRAM1_BASE->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
+ FSMC_NOR_PSRAM1_BASE->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
+ #endif
afio_remap(AFIO_REMAP_FSMC_NADV);
@@ -245,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
@@ -262,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);
-#endif // ARDUINO_ARCH_STM32F1 && (STM32_HIGH_DENSITY || STM32_XL_DENSITY)
+ 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 000000000000..753a5d5e708d
--- /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 85437c511ddc..d043b3b8dbf7 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 000000000000..463d951c1eab
--- /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 3994b3268a41..000000000000
--- a/Marlin/src/HAL/HAL_STM32F1/fastio_STM32F1.h
+++ /dev/null
@@ -1,58 +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 OUT_WRITE(IO,V) do{ _SET_OUTPUT(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 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 HAS_TIMER(IO) (PIN_MAP[IO].timer_device != NULL)
-
-#define PWM_PIN(P) HAS_TIMER(P)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
-
-// 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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..f356c0da0784
--- /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 000000000000..c39f4ce0ed5d
--- /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 000000000000..81e430fa2adb
--- /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 000000000000..9f06ca5fdbf4
--- /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 000000000000..6e9432896d8c
--- /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 000000000000..ec73162ba17f
--- /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 b67c76c4c104..babcdeaee31a 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 aa03474d2bb9..8097a284870c 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 2b184cdc4cea..38d5803f5810 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.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]
- * 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
+ * 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
@@ -23,47 +22,67 @@
/**
* 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"
-#include "../../sd/cardreader.h"
+#ifndef E2END
+ #define E2END 0xFFF // 4KB
+#endif
+#define HAL_EEPROM_SIZE (E2END + 1)
-#define HAL_STM32F1_EEPROM_SIZE 4096
-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];
-char eeprom_filename[] = "eeprom.dat";
+#if ENABLED(SDSUPPORT)
-bool PersistentStore::access_start() {
- if (!card.isDetected()) return false;
- int16_t bytes_read = 0;
- constexpr char eeprom_zero = 0xFF;
- card.openFile(eeprom_filename, true);
- bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
- if (bytes_read < 0) return false;
- for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
- HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
- card.closefile();
- return true;
-}
+ #include "../../sd/cardreader.h"
-bool PersistentStore::access_finish() {
- if (!card.isDetected()) return false;
- card.openFile(eeprom_filename, false);
- int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
- card.closefile();
- return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
-}
+ #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; // false aborts the save
+
+ 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 SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
+
+#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;
@@ -71,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);
}
@@ -79,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 e5022f79a482..a8b632870aa9 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 88%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/sdio.cpp
index d7aa3ccd2084..c1cab57a9e9f 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
@@ -21,13 +21,19 @@
*
*/
-#if defined(ARDUINO_ARCH_STM32F1) && (defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY))
+#ifdef ARDUINO_ARCH_STM32F1
-#include "HAL_sdio_STM32F1.h"
+#include
+
+#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
+
+#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
+
+#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;
@@ -36,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. */
@@ -101,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;
}
@@ -120,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;
@@ -159,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); }
@@ -204,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);
@@ -224,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)) {
@@ -236,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)) {
@@ -264,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)) {
@@ -276,4 +284,5 @@ bool SDIO_GetCmdResp7(void) {
return true;
}
-#endif // ARDUINO_ARCH_STM32F1 && (STM32_HIGH_DENSITY || STM32_XL_DENSITY)
+#endif // STM32_HIGH_DENSITY || STM32_XL_DENSITY
+#endif // ARDUINO_ARCH_STM32F1
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/sdio.h
similarity index 87%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/sdio.h
index 86c1355456c9..ca0aced69581 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,17 +21,14 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
+#include "../shared/Marduino.h"
-#include "Arduino.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. */
@@ -105,9 +102,9 @@
#define SDIO_CLOCK 18000000 /* 18 MHz */
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
uint32_t CardType; // Card Type
@@ -120,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);
@@ -142,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 97005a309eb2..edea89cc7d3b 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 8b235c004a89..a21dc12c12cd 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 "HAL.h"
-#include "HAL_timers_STM32F1.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
+#include "timers.h"
-// --------------------------------------------------------------------------
+// ------------------------
// 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_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_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,11 +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;
}
}
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/timers.h
similarity index 72%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/timers.h
index b17d8a44d3b6..69793f430239 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,12 @@
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
/**
* TODO: Check and confirm what timer we will use for each Temps and stepper driving.
@@ -45,7 +41,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,8 +51,13 @@ 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
+#define SERVO0_TIMER_NUM 1 // SERVO0 or BLTOUCH
+
+#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 +86,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);
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-/*
-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 +120,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 85%
rename from Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
index 0cbfb7fa5e3a..5696939f3065 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)
+ #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 91%
rename from Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/watchdog.h
index db62d4448b85..4f3a8deb0d3b 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
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 8bae46777d3d..000000000000
--- 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 1f3d753448a4..000000000000
--- 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 5840a525b66a..000000000000
--- 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_timers_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp
deleted file mode 100644
index 4783736b20d2..000000000000
--- 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 441daf925731..000000000000
--- 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 bac5bdabca81..000000000000
--- a/Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h
+++ /dev/null
@@ -1,156 +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 HAS_TIMER(IO) true
-
-#define PWM_PIN(P) HAS_TIMER(P)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
-
-// 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 e5022f79a482..000000000000
--- 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 8cffdbef7779..000000000000
--- 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 7f9118ee9cae..000000000000
--- 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 9f354f17e32c..000000000000
--- 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.h b/Marlin/src/HAL/HAL_STM32F7/HAL.h
deleted file mode 100644
index db7aa0391a00..000000000000
--- a/Marlin/src/HAL/HAL_STM32F7/HAL.h
+++ /dev/null
@@ -1,233 +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
-
-#include "Arduino.h"
-
-#include "../shared/math_32bit.h"
-#include "../shared/HAL_SPI.h"
-
-#include "fastio_STM32F7.h"
-#include "watchdog_STM32F7.h"
-
-#include "HAL_timers_STM32F7.h"
-
-
-// --------------------------------------------------------------------------
-// Defines
-// --------------------------------------------------------------------------
-
-//Serial override
-//extern HalSerial usb_serial;
-
-#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 !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
-
-#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))
-
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 8
-#define RST_JTAG 16
-#define RST_SOFTWARE 32
-#define RST_BACKUP 64
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-typedef int8_t pin_t;
-
-// --------------------------------------------------------------------------
-// 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);
-
-/* Todo: Confirm none of this is needed.
-uint16_t HAL_getAdcReading(uint8_t chan);
-
-void HAL_startAdcConversion(uint8_t chan);
-uint8_t HAL_pinToAdcChannel(int pin);
-
-uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
-//uint16_t HAL_getAdcSuperSample(uint8_t chan);
-
-void HAL_enable_AdcFreerun(void);
-//void HAL_disable_AdcFreerun(uint8_t chan);
-
-*/
-
-#define GET_PIN_MAP_PIN(index) index
-#define GET_PIN_MAP_INDEX(pin) pin
-#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
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 78b312470a6f..000000000000
--- 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 8ba1f870c20e..000000000000
--- 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 23eca4bab7db..000000000000
--- 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 e5022f79a482..000000000000
--- 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_STM32F7/watchdog_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.cpp
deleted file mode 100644
index 659e4448f35f..000000000000
--- a/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.cpp
+++ /dev/null
@@ -1,52 +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 .
- *
- */
-
-#ifdef STM32F7
-
-#include "../../inc/MarlinConfig.h"
-
-#if ENABLED(USE_WATCHDOG)
-
- #include "watchdog_STM32F7.h"
-
- IWDG_HandleTypeDef hiwdg;
-
- void watchdog_init() {
- hiwdg.Instance = IWDG;
- hiwdg.Init.Prescaler = IWDG_PRESCALER_32; //32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
- hiwdg.Init.Reload = 4095; //4095 counts = 4 seconds at 1024Hz
- 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();
- }
- }
-
-#endif // USE_WATCHDOG
-
-#endif // STM32F7
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 000000000000..5e6ae09bf10a
--- /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 000000000000..7ed6e2c10ff2
--- /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_STM32F4/HAL.h b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
similarity index 63%
rename from Marlin/src/HAL/HAL_STM32F4/HAL.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
index c41fe05f60a7..1effe2d7524f 100644
--- a/Marlin/src/HAL/HAL_STM32F4/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,37 +24,31 @@
#define CPU_32_BIT
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
+#include "../shared/Marduino.h"
+#include "../shared/math_32bit.h"
+#include "../shared/HAL_SPI.h"
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
+#include "fastio.h"
+#include "watchdog.h"
-#include
+#include "timers.h"
-#include "Arduino.h"
+#include "../../inc/MarlinConfigPre.h"
-#ifdef USBCON
+#include
+
+#if defined(STM32F4) && USBCON
#include
#endif
-#include "../shared/math_32bit.h"
-#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F4.h"
-#include "watchdog_STM32F4.h"
-
-#include "HAL_timers_STM32F4.h"
-
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//Serial override
//extern HalSerial usb_serial;
-#if SERIAL_PORT == 0
+#if defined(STM32F4) && SERIAL_PORT == 0
#error "Serial port 0 does not exist"
#endif
@@ -78,10 +72,9 @@
#endif
#ifdef SERIAL_PORT_2
- #if SERIAL_PORT_2 == 0
+ #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
@@ -107,9 +100,6 @@
#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
*/
@@ -136,75 +126,65 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 8
-#define RST_JTAG 16
-#define RST_SOFTWARE 32
-#define RST_BACKUP 64
-
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef int8_t pin_t;
-#define HAL_SERVO_LIB libServo
+#ifdef STM32F4
+ #define HAL_SERVO_LIB libServo
+#endif
-// --------------------------------------------------------------------------
+// ------------------------
// 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__
-/** 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
@@ -225,33 +205,20 @@ 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
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-
-uint16_t HAL_adc_get_result(void);
-
-/* Todo: Confirm none of this is needed.
-uint16_t HAL_getAdcReading(uint8_t chan);
-
-void HAL_startAdcConversion(uint8_t chan);
-uint8_t HAL_pinToAdcChannel(int pin);
-
-uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
-//uint16_t HAL_getAdcSuperSample(uint8_t chan);
-
-void HAL_enable_AdcFreerun(void);
-//void HAL_disable_AdcFreerun(uint8_t chan);
-
-*/
+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 JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
-#define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
+#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 71%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
index 6c3926db6530..2f85182e2033 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
+#include
#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 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, (uint8_t*)0, 512);
+ 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 000000000000..3b5a9ab02e21
--- /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 000000000000..32219962ee75
--- /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 a4c2ba6f44b3..726207fbcfc6 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 2fb39bf25af3..23155b425e31 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 92%
rename from Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
index 33418bb98162..3117321ac710 100644
--- a/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
@@ -25,23 +25,22 @@
*
*/
-//#include "Arduino.h"
+#if defined(STM32GENERIC) && defined(STM32F7)
-#ifdef STM32F7
+#include "../../../inc/MarlinConfigPre.h"
+
+#if HAS_DRIVER(TMC2660)
#include
#include
#include "TMC2660.h"
-#include "../../HAL/HAL_STM32F7/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
@@ -190,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);
@@ -222,14 +220,13 @@ void TMC26XStepper::setSpeed(uint16_t whatSpeed) {
this->speed = whatSpeed;
this->step_delay = 60UL * sq(1000UL) / ((uint32_t)this->number_of_steps * (uint32_t)whatSpeed * (uint32_t)this->microsteps);
#ifdef TMC_DEBUG0 // crashes
- //SERIAL_PRINTF("Step delay in micros: ");
SERIAL_ECHOPAIR("\nStep delay in micros: ", this->step_delay);
#endif
// Update the next step time
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.
@@ -249,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();
@@ -280,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
@@ -315,13 +312,13 @@ void TMC26XStepper::setCurrent(uint16_t current) {
// and recalculate the current setting
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_PRINTF("CS (Vsense=1): ");
SERIAL_ECHOPAIR("\nCS (Vsense=1): ",current_scaling);
- } else {
- //SERIAL_PRINTF("CS: ");
- 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);
@@ -337,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),
@@ -364,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;
@@ -377,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;
@@ -405,7 +402,6 @@ void TMC26XStepper::setMicrosteps(const int16_t in_steps) {
microsteps = _BV(8 - setting_pattern);
#ifdef TMC_DEBUG0 // crashes
- //SERIAL_PRINTF("Microstepping: ");
SERIAL_ECHOPAIR("\n Microstepping: ", microsteps);
#endif
@@ -425,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.
@@ -612,7 +608,6 @@ void TMC26XStepper::setCoolStepConfiguration(
| (((uint32_t)lower_current_limit) << 15)
| COOL_STEP_REGISTER; // Register signature
- //SERIAL_PRINTFln(cool_step_register_value,HEX);
if (started) send262(cool_step_register_value);
}
@@ -628,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
@@ -636,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) {
@@ -689,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();
@@ -697,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:
@@ -706,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:
@@ -715,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;
@@ -726,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);
}
@@ -737,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)
@@ -750,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);
}
@@ -799,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,19 +825,14 @@ void TMC26XStepper::debugLastStatus() {
uint32_t readout_config = driver_configuration_register_value & READ_SELECTION_PATTERN;
const int16_t value = getReadoutValue();
if (readout_config == READ_MICROSTEP_POSTION) {
- //SERIAL_PRINTF("Microstep position phase A: ");
SERIAL_ECHOPAIR("\n Microstep position phase A: ", value);
}
else if (readout_config == READ_STALL_GUARD_READING) {
- //SERIAL_PRINTF("Stall Guard value:");
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_PRINTF("Approx Stall Guard: ");
- SERIAL_ECHOPAIR("\n Approx Stall Guard: ", stallGuard);
- //SERIAL_PRINTF("Current level");
- SERIAL_ECHOPAIR("\n Current level", current);
+ SERIAL_ECHOPAIR("\n Approx Stall Guard: ", value & 0xF);
+ SERIAL_ECHOPAIR("\n Current level", value & 0x1F0);
}
}
#endif
@@ -905,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 1b44a4d5f54f..f1d0133a3b14 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 90131903e381..5a3b32ef5bce 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 34e56a20599b..38ecde30bb94 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 83%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
index 40fafc432cd0..736ddd45e432 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,13 +21,13 @@
*
*/
-#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;
@@ -49,6 +49,6 @@ void libServo::move(const int value) {
#endif
}
}
-#endif // HAS_SERVOS
-#endif // STM32F7
+#endif // HAS_SERVOS
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
similarity index 78%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
index 0b92a44efc2f..c839c6a145ee 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.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,7 +22,11 @@
*/
#pragma once
-#include
+//#ifdef STM32F7
+// #include <../../libraries/Servo/src/Servo.h>
+//#else
+ #include
+//#endif
// Inherit and expand on the official library
class libServo : public Servo {
@@ -31,7 +35,6 @@ class libServo : public Servo {
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;
+ 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 10b3219e9ab4..3358fa3df713 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;
- FLASH_EraseInitTypeDef pEraseInit;
-
-
- /* Get Page0 status */
- PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS);
- /* Get Page1 status */
- PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
+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;
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 fe0da6387b7c..e4094f8e134a 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 23eca4bab7db..d0aa731e890d 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 61%
rename from Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/fastio.h
index 50b071ff303d..1e5ef2ef3085 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)
@@ -49,10 +50,8 @@
#define IS_INPUT(IO)
#define IS_OUTPUT(IO)
-#define HAS_TIMER(IO) true
-#define PWM_PIN(P) HAS_TIMER(P)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
+#define PWM_PIN(P) true
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
@@ -69,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)
-
-#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)
+#ifdef STM32F7
+
+ #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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..7b8d29aa7dcf
--- /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 4990213cfc54..4bd86d225d4f 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 000000000000..342b875561b5
--- /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 e18e12278d8e..4aef289a7761 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 000000000000..cf33205bddab
--- /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 81%
rename from Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp
index fd2f309515c8..e078d7a1048c 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,6 +37,11 @@
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
//Error_Handler();
}
+ else {
+ #if PIN_EXISTS(LED) && !ENABLED(PINS_DEBUGGING)
+ TOGGLE(LED_PIN); // heartbeat indicator
+ #endif
+ }
}
void watchdog_reset() {
@@ -45,13 +50,7 @@
/* Refresh Error */
//Error_Handler();
}
- else {
- #if PIN_EXISTS(LED)
- TOGGLE(LED_PIN); // heartbeat indicator
- #endif
- }
}
#endif // USE_WATCHDOG
-
-#endif // STM32GENERIC && STM32F4
+#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 87%
rename from Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
index 4076c2b03a9f..cc02fda24f41 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
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
index fa80cd5ba99b..2e15324e3bbd 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 81b011b186d9..4813d60d6906 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,31 +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
-// _BV is re-defined in Arduino.h
-#undef _BV
-
-#include
+#include "../shared/Marduino.h"
+#include "../shared/math_32bit.h"
+#include "../shared/HAL_SPI.h"
-// Redefine sq macro defined by teensy3/wiring.h
-#undef sq
-#define sq(x) ((x)*(x))
+#include "fastio.h"
+#include "watchdog.h"
-#include "../math_32bit.h"
-#include "../HAL_SPI.h"
-
-#include "fastio_Teensy.h"
-#include "watchdog_Teensy.h"
-
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
#include
@@ -96,36 +87,22 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 8
-#define RST_JTAG 16
-#define RST_SOFTWARE 32
-#define RST_BACKUP 64
+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
@@ -135,24 +112,10 @@ void HAL_adc_init();
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
-#define HAL_ANALOG_SELECT(pin) NOOP;
+#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_getAdcReading(uint8_t chan);
-
-void HAL_startAdcConversion(uint8_t chan);
-uint8_t HAL_pinToAdcChannel(int pin);
-
-uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
-//uint16_t HAL_getAdcSuperSample(uint8_t chan);
-
-void HAL_enable_AdcFreerun(void);
-//void HAL_disable_AdcFreerun(uint8_t chan);
-*/
+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 331703dc55cc..4236f02b0f43 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/HAL_Servo_Teensy.cpp
deleted file mode 100644
index 7864ee715f03..000000000000
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifdef __MK20DX256__
-
-#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 // __MK20DX256__
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
similarity index 72%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
index bfe03f5d905e..7af900b149a2 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/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,21 +19,25 @@
* along with this program. If not, see .
*
*/
-
-#if defined(STM32GENERIC) && defined(STM32F4)
+#ifdef __MK20DX256__
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
-#include "HAL_Servo_STM32F4.h"
+#include "Servo.h"
+
+uint8_t servoPin[MAX_SERVOS] = { 0 };
int8_t libServo::attach(const int pin) {
- return Servo::attach(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) {
- return Servo::attach(pin, min, max);
+ if (pin > 0) servoPin[this->servoIndex] = pin;
+ return Servo::attach(servoPin[this->servoIndex], min, max);
}
void libServo::move(const int value) {
@@ -48,6 +51,7 @@ void libServo::move(const int value) {
#endif
}
}
+
#endif // HAS_SERVOS
-#endif // STM32GENERIC && STM32F4
+#endif // __MK20DX256__
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
similarity index 90%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
index d02cdc9f7468..e096dc60c8ed 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/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_TEENSY31_32/endstop_interrupts.h b/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
index ad0235179b1f..221b721b356a 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 93%
rename from Marlin/src/HAL/HAL_TEENSY35_36/fastio_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/fastio.h
index b9ddd957c141..d1b5f567d750 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)
@@ -90,7 +89,6 @@
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define PWM_PIN(P) digitalPinHasPWM(P)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
/**
* Ports, functions, and pins
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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 9ecf5e35f525..389d27824eef 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 d746dc9730a5..6da102638f63 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/pinsDebug.h b/Marlin/src/HAL/HAL_TEENSY31_32/pinsDebug.h
index 47b99ae317bf..d4a91ce801c2 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/pinsDebug.h
@@ -1 +1 @@
-#error "Debug pins is not supported on the Teensy 3.1 / 3.2 Platform!"
+#error "PINS_DEBUGGING is not yet supported for Teensy 3.1 / 3.2!"
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h b/Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h
index cfc9a2d14e60..8a0ab8f9a494 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 fccba9e6ac57..1ae4bcf4f027 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
@@ -20,7 +20,6 @@
*
*/
-
/**
* Teensy3.2 __MK20DX256__
*/
@@ -28,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");
}
@@ -43,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 57%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/timers.h
index 79a854126ecd..6dff7701be3c 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/timers.h
@@ -1,40 +1,36 @@
-/* **************************************************************************
-
- 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 .
-****************************************************************************/
+/**
+ * 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
/**
* Description: HAL for
* Teensy3.2 (__MK20DX256__)
*/
-#pragma once
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -46,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)
@@ -72,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 07505140e84a..d1313e1f5deb 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 88%
rename from Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h
index d0b7d030e90e..ceb041b45715 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"
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
index c4d6b3cf5496..584894479229 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 99fc31aff537..e218174ad3d2 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,26 +27,14 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-// _BV is re-defined in Arduino.h
-#undef _BV
-
-#include
-
-// Redefine sq macro defined by teensy3/wiring.h
-#undef sq
-#define sq(x) ((x)*(x))
-
+#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
@@ -55,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__)
@@ -105,33 +93,22 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
-#define RST_POWER_ON 1
-#define RST_EXTERNAL 2
-#define RST_BROWN_OUT 4
-#define RST_WATCHDOG 8
-#define RST_JTAG 16
-#define RST_SOFTWARE 32
-#define RST_BACKUP 64
+inline 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();
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
@@ -141,24 +118,10 @@ void HAL_adc_init();
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
-#define HAL_ANALOG_SELECT(pin) NOOP;
+#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_getAdcReading(uint8_t chan);
-
- void HAL_startAdcConversion(uint8_t chan);
- uint8_t HAL_pinToAdcChannel(int pin);
-
- uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
- //uint16_t HAL_getAdcSuperSample(uint8_t chan);
-
- void HAL_enable_AdcFreerun(void);
- //void HAL_disable_AdcFreerun(uint8_t chan);
-*/
+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 6220225a1d1a..44ab74cc9bf6 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/Servo.cpp
similarity index 96%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
index ff56036ccd7a..faf72e9d1e33 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
@@ -4,7 +4,7 @@
#if HAS_SERVOS
-#include "HAL_Servo_Teensy.h"
+#include "Servo.h"
uint8_t servoPin[MAX_SERVOS] = { 0 };
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
similarity index 79%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
index 687aaa39ec5d..4b97dbffbbbe 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/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
@@ -19,12 +19,11 @@
* along with this program. If not, see .
*
*/
-
#pragma once
#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);
@@ -33,5 +32,5 @@ class libServo : public Servo {
private:
uint16_t min_ticks;
uint16_t max_ticks;
- uint8_t servoIndex; // index into the channel data for this servo
+ 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 7327dc1a92ca..3862f2b5b897 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 93%
rename from Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/fastio.h
index 928cd758e74e..d1b5f567d750 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)
@@ -91,7 +89,6 @@
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define PWM_PIN(P) digitalPinHasPWM(P)
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
/**
* Ports, functions, and pins
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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 000000000000..85f26f40162e
--- /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 597a3638dae8..6a126b683ebc 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 ad5ed361ae2b..17934f71a327 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 29b4653b3eac..000000000000
--- 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 cb472aff01eb..db750cf6ec85 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 152d6b4c2197..9c6a83e3f8bd 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 471d823da5c4..6ee61182080b 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 fed256452a71..8ae51107c74b 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 46605473a1d0..f58217c75054 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 88%
rename from Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h
index ba0916976ceb..d2efaab37217 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
diff --git a/Marlin/src/HAL/platforms.h b/Marlin/src/HAL/platforms.h
index f5042b9fed03..e3e7f52cfaec 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 bab7d7471ea9..1c2ee47c29e7 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__)
diff --git a/Marlin/src/HAL/shared/HAL_SPI.h b/Marlin/src/HAL/shared/HAL_SPI.h
index 43dd2100767b..d805207047da 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
+//
+// Standard SPI functions
+//
-#define SPI_DATAMODE_0 0x00
-#define SPI_DATAMODE_1 0x04
-#define SPI_DATAMODE_2 0x08
-#define SPI_DATAMODE_3 0x0C
+// Initialize SPI bus
+void spiBegin();
-// Standard SPI functions
-/** Initialize SPI bus */
-void spiBegin(void);
-/** Configure SPI for specified SPI speed */
+// 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 9af1286c7a5d..de40ade5abb7 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
@@ -33,4 +33,4 @@
void ST7920_set_cmd();
void ST7920_set_dat();
void ST7920_write_byte(const uint8_t data);
-#endif
\ No newline at end of file
+#endif
diff --git a/Marlin/src/HAL/shared/HAL_spi_L6470.cpp b/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
index ecd808fe46ee..936acc7ce899 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
new file mode 100644
index 000000000000..a2de03a2b6e4
--- /dev/null
+++ b/Marlin/src/HAL/shared/Marduino.h
@@ -0,0 +1,85 @@
+/**
+ * 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
+
+/**
+ * HAL/shared/Marduino.h
+ */
+
+#undef DISABLED // Redefined by ESP32
+#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
+
+#undef DISABLED
+#define DISABLED(V...) DO(DIS,&&,V)
+
+#undef _BV
+#define _BV(b) (1UL << (b))
+
+#undef sq
+#define sq(x) ((x)*(x))
+
+#ifndef SBI
+ #define SBI(A,B) (A |= (1 << (B)))
+#endif
+
+#ifndef CBI
+ #define CBI(A,B) (A &= ~(1 << (B)))
+#endif
+
+#ifndef __AVR__
+ #ifndef strchr_P // Some platforms define a macro (DUE, teensy35)
+ 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
+#define RST_POWER_ON 1
+#define RST_EXTERNAL 2
+#define RST_BROWN_OUT 4
+#define RST_WATCHDOG 8
+#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 89c501af479e..afbd7d3443aa 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 ba1b2326e9a7..fc265615d043 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 5e00bec94fd9..a2b8eae59412 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 e1740fc248aa..cdc9c06c615e 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;
}
@@ -93,7 +93,7 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) {
UnwReport entry;
// We found two acceptable values.
- entry.name = NULL;
+ entry.name = nullptr;
entry.address = addr & 0xFFFFFFFE; // Remove Thumb bit
entry.function = 0;
diff --git a/Marlin/src/HAL/shared/backtrace/unwarm_arm.cpp b/Marlin/src/HAL/shared/backtrace/unwarm_arm.cpp
index 3c9c5aaeec76..0ec9bd56af7d 100644
--- a/Marlin/src/HAL/shared/backtrace/unwarm_arm.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwarm_arm.cpp
@@ -124,13 +124,11 @@ UnwResult UnwStartArm(UnwState * const state) {
/* MRS */
else if ((instr & 0xFFBF0FFF) == 0xE10F0000) {
+ uint8_t rd = (instr & 0x0000F000) >> 12;
#ifdef UNW_DEBUG
const bool R = !!(instr & 0x00400000);
- #else
- constexpr bool R = false;
+ UnwPrintd4("MRS r%d,%s\t; r%d invalidated", rd, R ? "SPSR" : "CPSR", rd);
#endif
- uint8_t rd = (instr & 0x0000F000) >> 12;
- UnwPrintd4("MRS r%d,%s\t; r%d invalidated", rd, R ? "SPSR" : "CPSR", rd);
/* Status registers untracked */
state->regData[rd].o = REG_VAL_INVALID;
diff --git a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
index db49dcad7f83..207cd56aa82e 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;
@@ -47,17 +47,17 @@ static const UnwTabEntry *UnwTabSearchIndex(const UnwTabEntry *start, const UnwT
}
/*
- * Get the function name or NULL if not found
+ * Get the function name or nullptr if not found
*/
static const char *UnwTabGetFunctionName(const UnwindCallbacks *cb, uint32_t address) {
uint32_t flag_word = 0;
if (!cb->readW(address-4,&flag_word))
- return NULL;
+ return nullptr;
if ((flag_word & 0xFF000000) == 0xFF000000) {
return (const char *)(address - 4 - (flag_word & 0x00FFFFFF));
}
- return NULL;
+ return nullptr;
}
/**
@@ -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 bde58994355b..e63af1ed25a8 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 179bc1417bdc..8cf31cadf556 100644
--- a/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
@@ -52,8 +52,8 @@
#define END_FLASH_ADDR 0x00020000
#endif
-#ifdef __STM32F1__
-// For STM32F103ZET6/STM32F103VET6
+#if defined(__STM32F1__) || defined(STM32F1xx) || defined(STM32F0xx)
+// For STM32F103ZET6/STM32F103VET6/STM32F0xx
// SRAM (0x20000000 - 0x20010000) (64kb)
// FLASH (0x00000000 - 0x00080000) (512kb)
//
@@ -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 64%
rename from Marlin/src/HAL/shared/I2cEeprom.cpp
rename to Marlin/src/HAL/shared/eeprom_i2c.cpp
index ef2ff8222fee..9c9d48f2df89 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,52 +29,20 @@
#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
-// --------------------------------------------------------------------------
+static uint8_t eeprom_device_address = 0x50;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-static uint8_t eeprom_device_address = 0x50;
-
-static void eeprom_init(void) {
+static void eeprom_init() {
static bool eeprom_initialized = false;
if (!eeprom_initialized) {
Wire.begin();
@@ -127,7 +95,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 +108,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 525c8c0a7dbd..35e7d9b0a952 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 34642b29990d..a69992a655e4 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 e7bd107cbe48..9aed03a0c8a1 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 de9f1c109090..02013120a72a 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