diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 73fe1f0a373e..000000000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,275 +0,0 @@
-# Python CircleCI 2.0 configuration file
-#
-# Check https://circleci.com/docs/2.0/language-python/ for more details
-#
-version: 2
-jobs:
- build:
- docker:
- # specify the version you desire here
- # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- - image: circleci/python:2.7.13
-
- # Specify service dependencies here if necessary
- # CircleCI maintains a library of pre-built images
- # documented at https://circleci.com/docs/2.0/circleci-images/
- # - image: circleci/postgres:9.4
- environment:
- TEST_PLATFORM: "-e megaatmega2560"
-
- working_directory: ~/Marlin
-
- steps:
- - checkout
-
- - restore_cache:
- paths:
- - ~/.platformio
- - ~/Marlin/.piolibdeps
- keys:
- - v1-dependencies-{{ checksum "~/Marlin/platformio.ini" }}
- # fallback to using the latest cache if no exact match is found
- - v1-dependencies-
-
- - run:
- name: install dependencies
- command: |
- sudo pip install -U platformio
-
- # run tests!
- - run:
- name: run tests
- command: |
- #
- #
- # Fetch the tag information for the current branch
- ls -la
- git fetch origin --tags
- #
- # Publish the buildroot script folder
- chmod +x buildroot/bin/*
- export PATH=`pwd`/buildroot/bin/:${PATH}
-
- # Generate custom version include
- 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
- #
-
- env_backup
-
- #################################
- # Build all sample configurations
- #################################
-
- echo testing megaatmega2560 targets...
- export TEST_PLATFORM="-e megaatmega2560"
- echo use_example_configs adafruit/ST7565
- use_example_configs adafruit/ST7565
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs BQ/Hephestos
- use_example_configs BQ/Hephestos
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs BQ/Hephestos_2
- use_example_configs BQ/Hephestos_2
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs BQ/WITBOX
- use_example_configs BQ/WITBOX
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs AliExpress/CL-260
- use_example_configs AliExpress/CL-260
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- #echo use_example_configs Cartesio
- #use_example_configs Cartesio
- #build_marlin_pio ./ ${TEST_PLATFORM}
- #restore_configs
- echo use_example_configs delta/FLSUN/auto_calibrate
- use_example_configs delta/FLSUN/auto_calibrate
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs delta/FLSUN/kossel_mini
- use_example_configs delta/FLSUN/kossel_mini
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs delta/generic
- use_example_configs delta/generic
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs delta/kossel_mini
- use_example_configs delta/kossel_mini
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs delta/kossel_xl
- use_example_configs delta/kossel_xl
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Felix
- use_example_configs Felix
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Felix/DUAL
- use_example_configs Felix/DUAL
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs FolgerTech/i3-2020
- use_example_configs FolgerTech/i3-2020
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs gCreate/gMax1.5+
- use_example_configs gCreate/gMax1.5+
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Geeetech/GT2560
- use_example_configs Geeetech/GT2560
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- #echo use_example_configs Geeetech/I3_Pro_X-GT2560
- #use_example_configs Geeetech/I3_Pro_X-GT2560
- #build_marlin_pio ./ ${TEST_PLATFORM}
- #restore_configs
- echo use_example_configs Infitary/i3-M508
- use_example_configs Infitary/i3-M508
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- use_example_configs Malyan/M200
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Micromake/C1/basic
- use_example_configs Micromake/C1/basic
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Micromake/C1/enhanced
- use_example_configs Micromake/C1/enhanced
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs RepRapWorld/Megatronics
- use_example_configs RepRapWorld/Megatronics
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs RigidBot
- use_example_configs RigidBot
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs SCARA
- use_example_configs SCARA
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Velleman/K8200
- use_example_configs Velleman/K8200
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Velleman/K8400/Dual-head
- use_example_configs Velleman/K8400/Dual-head
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Velleman/K8400
- use_example_configs Velleman/K8400
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Wanhao/Duplicator6
- use_example_configs Wanhao/Duplicator6
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- # Requires manual load of https://github.com/stawel/SlowSoftI2CMaster
- #use_example_configs wt150
- #build_marlin_pio ./ ${TEST_PLATFORM}
- #restore_configs
- echo testing melzi targets...
- export TEST_PLATFORM="-e melzi"
- echo use_example_configs Anet/A6
- use_example_configs Anet/A6
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Anet/A8
- use_example_configs Anet/A8
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Creality/CR-10
- use_example_configs Creality/CR-10
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Malyan/M150
- use_example_configs Malyan/M150
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs Sanguinololu
- use_example_configs Sanguinololu
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs TinyBoy2
- use_example_configs TinyBoy2
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
-
- echo testing rambo targets...
- export TEST_PLATFORM="-e rambo"
- echo use_example_configs AlephObjects/TAZ4
- use_example_configs AlephObjects/TAZ4
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
-
- echo testing at90usb1286_* targets...
- export TEST_PLATFORM="-e at90usb1286_dfu"
- #echo se_example_configs delta/kossel_pro
- #use_example_configs delta/kossel_pro
- #build_marlin_pio ./ ${TEST_PLATFORM}
- #restore_configs
- echo use_example_configs makibox
- use_example_configs makibox
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
-
- echo testing sanguino_atmega644p targets...
- export TEST_PLATFORM="-e sanguino_atmega644p"
- echo use_example_configs tvrrug/Round2
- use_example_configs tvrrug/Round2
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
-
- echo testing LPC1768 targets...
- export TEST_PLATFORM="-e LPC1768"
- echo use_example_configs Mks/Sbase
- use_example_configs Mks/Sbase
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo testing STM32F1 targets...
- export TEST_PLATFORM="-e STM32F1"
- restore_configs
- echo use_example_configs STM32F10
- use_example_configs STM32F10
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
- echo use_example_configs stm32f103ret6
- use_example_configs stm32f103ret6
- build_marlin_pio ./ ${TEST_PLATFORM}
- restore_configs
-
- echo testing DUE targets...
- export TEST_PLATFORM="-e DUE"
- #echo use_example_configs UltiMachine/Archim2
- #use_example_configs UltiMachine/Archim2
- #build_marlin_pio ./ ${TEST_PLATFORM}
- #restore_configs
-
- #
- # Remove temp files from dependencies tree prior to caching
- rm -rf ~/Marlin/.piolibdeps/_tmp_*
-
- #
- # Restore the environment
- #
- env_restore
-
- - save_cache:
- paths:
- - ~/.platformio
- - ~/Marlin/.piolibdeps
- key: v1-dependencies-{{ checksum "~/Marlin/platformio.ini" }}
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 d67fb817cad3..ecfb36f0d580 100644
--- a/.github/issue_template.md
+++ b/.github/issue_template.md
@@ -2,7 +2,7 @@
Have you read Marlin's Code of Conduct? By filing an Issue, you are expected to comply with it, including treating everyone with respect: https://github.com/MarlinFirmware/Marlin/blob/bugfix-2.0.x/.github/code_of_conduct.md
-Do you want to ask a question? Are you looking for support? Please don't post here. Instead please use the Marlin Firmware forum at http://forums.reprap.org/list.php?415 or the Marlin Facebook Group https://www.facebook.com/groups/1049718498464482/.
+Do you want to ask a question? Are you looking for support? Please don't post here. Instead please use the Marlin Firmware forum at http://forums.reprap.org/list.php?415 or the Marlin Facebook Group https://www.facebook.com/groups/1049718498464482/ or the Marlin Discord Server https://discord.gg/n5NJ59y.
Before filing an issue be sure to test the 1.1 and/or 2.0 "bugfix" branches to see whether the issue is already addressed.
diff --git a/.travis.yml b/.travis.yml
index c869f027a8fb..f9841e8916cd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,39 +1,61 @@
-dist: xenial
-sudo: require
+dist: bionic
+sudo: false
language: python
python:
- - "2.7"
+ - "3.7"
notifications:
email: false
-# Cache PlatformIO packages using Travis CI container-based infrastructure
-sudo: false
-cache:
- pip: true
- directories:
- - "~/.platformio"
-
env:
- - TEST_PLATFORM="megaatmega2560"
+ # Base Environments
- TEST_PLATFORM="DUE"
+ - TEST_PLATFORM="esp32"
+ - TEST_PLATFORM="linux_native"
+ - TEST_PLATFORM="megaatmega2560"
+ - TEST_PLATFORM="teensy31"
+ - TEST_PLATFORM="teensy35"
+
+ # Extended AVR Environments
+ - TEST_PLATFORM="FYSETC_F6_13"
+ - TEST_PLATFORM="megaatmega1280"
+ - TEST_PLATFORM="rambo"
+ - TEST_PLATFORM="sanguino_atmega1284p"
+ - TEST_PLATFORM="sanguino_atmega644p"
+
+ # Extended STM32 Environments
+ - TEST_PLATFORM="STM32F103RC_bigtree"
+ - TEST_PLATFORM="STM32F103RC_bigtree_USB"
+ - TEST_PLATFORM="STM32F103RE_bigtree"
+ - TEST_PLATFORM="STM32F103RE_bigtree_USB"
+ - TEST_PLATFORM="STM32F103RC_fysetc"
+ - TEST_PLATFORM="jgaurora_a5s_a1"
+ - TEST_PLATFORM="STM32F103VE_longer"
+ - TEST_PLATFORM="STM32F407VE_black"
+ - TEST_PLATFORM="BIGTREE_SKR_PRO"
+ - TEST_PLATFORM="mks_robin"
+ - TEST_PLATFORM="ARMED"
+
+ # STM32 with non-STM framework. both broken for now. they should use HAL_STM32 which is working.
+ #- TEST_PLATFORM="STM32F4"
+ #- TEST_PLATFORM="STM32F7"
+
+ # Put lengthy tests last
- TEST_PLATFORM="LPC1768"
- TEST_PLATFORM="LPC1769"
- - TEST_PLATFORM="STM32F1"
- - TEST_PLATFORM="teensy35"
- - TEST_PLATFORM="linux_native"
- - TEST_PLATFORM="esp32"
-addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- packages:
- - g++-7
+ # Non-working environment tests
+ #- TEST_PLATFORM="BIGTREE_BTT002" this board isn't released yet. we need pinout to be sure about what we do
+ #- TEST_PLATFORM="at90usb1286_cdc"
+ #- TEST_PLATFORM="at90usb1286_dfu"
+ #- TEST_PLATFORM="STM32F103CB_malyan"
+ #- TEST_PLATFORM="mks_robin_lite"
+ #- TEST_PLATFORM="mks_robin_mini"
+ #- TEST_PLATFORM="mks_robin_nano"
+ #- TEST_PLATFORM="SAMD51_grandcentral_m4"
before_install:
- - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90
#
# Fetch the tag information for the current branch
- git fetch origin --tags
@@ -55,8 +77,8 @@ before_script:
- cd ${TRAVIS_BUILD_DIR}
#
# Generate custom version include
- - generate_version ${TRAVIS_BUILD_DIR}/Marlin/src/inc
- - cat ${TRAVIS_BUILD_DIR}/Marlin/src/inc/_Version.h
+ - generate_version ${TRAVIS_BUILD_DIR}/Marlin/
+ - cat ${TRAVIS_BUILD_DIR}/Marlin/Version.h
#
script:
- run_tests ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index c2ff9b061068..c862dbe057ef 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -70,13 +70,9 @@
// @section info
-// User-specified version info of this build to display in [Pronterface, etc] terminal window during
-// startup. Implementation of an idea by Prof Braino to inform user that any changes made to this
-// build by the user have been successfully uploaded into firmware.
-#define STRING_CONFIG_H_AUTHOR "(Ben Hess, Ender-3)" // Who made the changes.
-#define SHOW_BOOTSCREEN
-#define STRING_SPLASH_LINE1 SHORT_BUILD_VERSION // will be shown during bootup in line 1
-#define STRING_SPLASH_LINE2 WEBSITE_URL // will be shown during bootup in line 2
+// Author info of this build printed to the host during boot and M115
+#define STRING_CONFIG_H_AUTHOR "(none, default config)" // Who made the changes.
+//#define CUSTOM_VERSION_FILE Version.h // Path from the root directory (no quotes)
/**
* *** VENDORS PLEASE READ ***
@@ -89,11 +85,14 @@
* respectfully request that you retain the unmodified Marlin boot screen.
*/
-// Enable to show the bitmap in Marlin/_Bootscreen.h on startup.
-#define SHOW_CUSTOM_BOOTSCREEN
+// Show the Marlin bootscreen on startup. ** ENABLE FOR PRODUCTION **
+#define SHOW_BOOTSCREEN
+
+// Show the bitmap in Marlin/_Bootscreen.h on startup.
+//#define SHOW_CUSTOM_BOOTSCREEN
-// Enable to show the bitmap in Marlin/_Statusscreen.h on the status screen.
-#define CUSTOM_STATUS_SCREEN_IMAGE
+// Show the bitmap in Marlin/_Statusscreen.h on the status screen.
+//#define CUSTOM_STATUS_SCREEN_IMAGE
// @section machine
@@ -129,8 +128,7 @@
// Enable the Bluetooth serial interface on AT90USB devices
//#define BLUETOOTH
-// The following define selects which electronics board you have.
-// Please choose the name from boards.h that matches your setup
+// Choose the name from boards.h that matches your setup
#ifndef MOTHERBOARD
#define MOTHERBOARD BOARD_BIGTREE_SKR_V1_3
#endif
@@ -139,8 +137,8 @@
// Displayed in the LCD "Ready" message
#define CUSTOM_MACHINE_NAME "Ender-3"
-// Define this to set a unique identifier for this printer, (Used by some programs to differentiate between machines)
-// You can use an online service to generate a random UUID. (eg http://www.uuidgenerator.net/version4)
+// Printer's unique ID, used by some programs to differentiate between machines.
+// Choose your own or use a service like http://www.uuidgenerator.net/version4
//#define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
// @section extruder
@@ -277,7 +275,14 @@
#define SWITCHING_TOOLHEAD_SERVO_ANGLES { 0, 180 } // (degrees) Angles for Lock, Unlock
#elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
#define SWITCHING_TOOLHEAD_Y_RELEASE 5 // (mm) Security distance Y axis
- #define SWITCHING_TOOLHEAD_X_SECURITY -35 // (mm) Security distance X axis
+ #define SWITCHING_TOOLHEAD_X_SECURITY { 90, 150 } // (mm) Security distance X axis (T0,T1)
+ //#define PRIME_BEFORE_REMOVE // Prime the nozzle before release from the dock
+ #if ENABLED(PRIME_BEFORE_REMOVE)
+ #define SWITCHING_TOOLHEAD_PRIME_MM 20 // (mm) Extruder prime length
+ #define SWITCHING_TOOLHEAD_RETRACT_MM 10 // (mm) Retract after priming length
+ #define SWITCHING_TOOLHEAD_PRIME_FEEDRATE 300 // (mm/m) Extruder prime feedrate
+ #define SWITCHING_TOOLHEAD_RETRACT_FEEDRATE 2400 // (mm/m) Extruder retract feedrate
+ #endif
#elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
#define SWITCHING_TOOLHEAD_Z_HOP 2 // (mm) Z raise for switching
#endif
@@ -321,13 +326,14 @@
//#define PSU_NAME "Power Supply"
#if ENABLED(PSU_CONTROL)
- #define PSU_ACTIVE_HIGH false // Set 'false' for ATX (1), 'true' for X-Box (2)
+ #define PSU_ACTIVE_HIGH false // Set 'false' for ATX, 'true' for X-Box
- //#define PS_DEFAULT_OFF // Keep power off until enabled directly with M80
+ //#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
+ //#define PSU_POWERUP_DELAY 100 // (ms) Delay for the PSU to warm up to full power
- //#define AUTO_POWER_CONTROL // Enable automatic control of the PS_ON pin
+ //#define AUTO_POWER_CONTROL // Enable automatic control of the PS_ON pin
#if ENABLED(AUTO_POWER_CONTROL)
- #define AUTO_POWER_FANS // Turn on PSU if fans need power
+ #define AUTO_POWER_FANS // Turn on PSU if fans need power
#define AUTO_POWER_E_FANS
#define AUTO_POWER_CONTROLLERFAN
#define AUTO_POWER_CHAMBER_FAN
@@ -348,17 +354,20 @@
*
* Temperature sensors available:
*
+ * -5 : PT100 / PT1000 with MAX31865 (only for sensors 0-1)
+ * -3 : thermocouple with MAX31855 (only for sensors 0-1)
+ * -2 : thermocouple with MAX6675 (only for sensors 0-1)
* -4 : thermocouple with AD8495
- * -3 : thermocouple with MAX31855 (only for sensor 0)
- * -2 : thermocouple with MAX6675 (only for sensor 0)
* -1 : thermocouple with AD595
* 0 : not used
* 1 : 100k thermistor - best choice for EPCOS 100k (4.7k pullup)
+ * 331 : (3.3V scaled thermistor 1 table)
* 2 : 200k thermistor - ATC Semitec 204GT-2 (4.7k pullup)
* 3 : Mendel-parts thermistor (4.7k pullup)
* 4 : 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !!
* 5 : 100K thermistor - ATC Semitec 104GT-2/104NT-4-R025H42G (Used in ParCan & J-Head) (4.7k pullup)
* 501 : 100K Zonestar (Tronxy X3A) Thermistor
+ * 512 : 100k RPW-Ultra hotend thermistor (4.7k pullup)
* 6 : 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup)
* 7 : 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup)
* 71 : 100k Honeywell thermistor 135-104LAF-J01 (4.7k pullup)
@@ -370,13 +379,15 @@
* 13 : 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE"
* 15 : 100k thermistor calibration for JGAurora A5 hotend
* 18 : ATC Semitec 204GT-2 (4.7k pullup) Dagoma.Fr - MKS_Base_DKU001327
- * 20 : the PT100 circuit found in the Ultimainboard V2.x
+ * 20 : Pt100 with circuit in the Ultimainboard V2.x
+ * 201 : Pt100 with circuit in Overlord, similar to Ultimainboard V2.x
* 60 : 100k Maker's Tool Works Kapton Bed Thermistor beta=3950
* 61 : 100k Formbot / Vivedino 3950 350C thermistor 4.7k pullup
* 66 : 4.7M High Temperature thermistor from Dyze Design
* 67 : 450C thermistor from SliceEngineering
* 70 : the 100K thermistor found in the bq Hephestos 2
* 75 : 100k Generic Silicon Heat Pad with NTC 100K MGB18-104F39050L32 thermistor
+ * 99 : 100k thermistor with a 10K pull-up resistor (found on some Wanhao i3 machines)
*
* 1k ohm pullup tables - This is atypical, and requires changing out the 4.7k pullup for 1k.
* (but gives greater accuracy and more stable PID)
@@ -394,8 +405,6 @@
* Use these for Testing or Development purposes. NEVER for production machine.
* 998 : Dummy Table that ALWAYS reads 25°C or the temperature defined below.
* 999 : Dummy Table that ALWAYS reads 100°C or the temperature defined below.
- *
- * :{ '0':"Not used", '1':"100k / 4.7k - EPCOS", '2':"200k / 4.7k - ATC Semitec 204GT-2", '3':"Mendel-parts / 4.7k", '4':"10k !! do not use for a hotend. Bad resolution at high temp. !!", '5':"100K / 4.7k - ATC Semitec 104GT-2 (Used in ParCan & J-Head)", '501':"100K Zonestar (Tronxy X3A)", '6':"100k / 4.7k EPCOS - Not as accurate as Table 1", '7':"100k / 4.7k Honeywell 135-104LAG-J01", '8':"100k / 4.7k 0603 SMD Vishay NTCS0603E3104FXT", '9':"100k / 4.7k GE Sensing AL03006-58.2K-97-G1", '10':"100k / 4.7k RS 198-961", '11':"100k / 4.7k beta 3950 1%", '12':"100k / 4.7k 0603 SMD Vishay NTCS0603E3104FXT (calibrated for Makibox hot bed)", '13':"100k Hisens 3950 1% up to 300°C for hotend 'Simple ONE ' & hotend 'All In ONE'", '18':"ATC Semitec 204GT-2 (4.7k pullup) Dagoma.Fr - MKS_Base_DKU001327" '20':"PT100 (Ultimainboard V2.x)", '51':"100k / 1k - EPCOS", '52':"200k / 1k - ATC Semitec 204GT-2", '55':"100k / 1k - ATC Semitec 104GT-2 (Used in ParCan & J-Head)", '60':"100k Maker's Tool Works Kapton Bed Thermistor beta=3950", '61':"100k Formbot / Vivedino 3950 350C thermistor 4.7k pullup", '66':"Dyze Design 4.7M High Temperature thermistor", '67':"Slice Engineering 450C High Temperature thermistor", '70':"the 100K thermistor found in the bq Hephestos 2", '71':"100k / 4.7k Honeywell 135-104LAF-J01", '147':"Pt100 / 4.7k", '1047':"Pt1000 / 4.7k", '110':"Pt100 / 1k (non-standard)", '1010':"Pt1000 / 1k (non standard)", '-4':"Thermocouple + AD8495", '-3':"Thermocouple + MAX31855 (only for sensor 0)", '-2':"Thermocouple + MAX6675 (only for sensor 0)", '-1':"Thermocouple + AD595", '998':"Dummy 1", '999':"Dummy 2", '1000':"Custom thermistor params" }
*/
#define TEMP_SENSOR_0 1
#define TEMP_SENSOR_1 0
@@ -518,7 +527,7 @@
#define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current
#if ENABLED(PIDTEMPBED)
-
+ //#define MIN_BED_POWER 0
//#define PID_BED_DEBUG // Sends debug data to the serial port.
//120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
@@ -712,25 +721,35 @@
/**
* Default Axis Steps Per Unit (steps/mm)
* Override with M92
- * X, Y, Z, E0 [, E1[, E2[, E3[, E4[, E5]]]]]
+ * X, Y, Z, E0 [, E1[, E2...]]
*/
#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 400, 93 }
/**
* Default Max Feed Rate (mm/s)
* Override with M203
- * X, Y, Z, E0 [, E1[, E2[, E3[, E4[, E5]]]]]
+ * X, Y, Z, E0 [, E1[, E2...]]
*/
#define DEFAULT_MAX_FEEDRATE { 500, 500, 5, 25 }
+//#define LIMITED_MAX_FR_EDITING // Limit edit via M203 or LCD to DEFAULT_MAX_FEEDRATE * 2
+#if ENABLED(LIMITED_MAX_FR_EDITING)
+ #define MAX_FEEDRATE_EDIT_VALUES { 600, 600, 10, 50 } // ...or, set your own edit limits
+#endif
+
/**
* Default Max Acceleration (change/s) change = mm/s
* (Maximum start speed for accelerated moves)
* Override with M201
- * X, Y, Z, E0 [, E1[, E2[, E3[, E4[, E5]]]]]
+ * X, Y, Z, E0 [, E1[, E2...]]
*/
#define DEFAULT_MAX_ACCELERATION { 500, 500, 100, 5000 }
+//#define LIMITED_MAX_ACCEL_EDITING // Limit edit via M201 or LCD to DEFAULT_MAX_ACCELERATION * 2
+#if ENABLED(LIMITED_MAX_ACCEL_EDITING)
+ #define MAX_ACCEL_EDIT_VALUES { 6000, 6000, 200, 20000 } // ...or, set your own edit limits
+#endif
+
/**
* Default Acceleration (change/s) change = mm/s
* Override with M204
@@ -744,35 +763,38 @@
#define DEFAULT_TRAVEL_ACCELERATION 500 // X, Y, Z acceleration for travel (non printing) moves
/**
- * Junction Deviation
- *
- * Use Junction Deviation instead of traditional Jerk Limiting
- *
- * See:
- * https://reprap.org/forum/read.php?1,739819
- * http://blog.kyneticcnc.com/2018/10/computing-junction-deviation-for-marlin.html
- */
-//#define JUNCTION_DEVIATION
-#if ENABLED(JUNCTION_DEVIATION)
- #define JUNCTION_DEVIATION_MM 0.02 // (mm) Distance from real junction edge
-#endif
-
-/**
- * Default Jerk (mm/s)
+ * Default Jerk limits (mm/s)
* Override with M205 X Y Z E
*
* "Jerk" specifies the minimum speed change that requires acceleration.
* When changing speed and direction, if the difference is less than the
* value set here, it may happen instantaneously.
*/
-#if DISABLED(JUNCTION_DEVIATION)
+//#define CLASSIC_JERK
+#if ENABLED(CLASSIC_JERK)
#define DEFAULT_XJERK 10.0
#define DEFAULT_YJERK 10.0
#define DEFAULT_ZJERK 0.3
+
+ //#define LIMITED_JERK_EDITING // Limit edit via M205 or LCD to DEFAULT_aJERK * 2
+ #if ENABLED(LIMITED_JERK_EDITING)
+ #define MAX_JERK_EDIT_VALUES { 20, 20, 0.6, 10 } // ...or, set your own edit limits
+ #endif
#endif
#define DEFAULT_EJERK 5.0 // May be used by Linear Advance
+/**
+ * Junction Deviation Factor
+ *
+ * See:
+ * https://reprap.org/forum/read.php?1,739819
+ * http://blog.kyneticcnc.com/2018/10/computing-junction-deviation-for-marlin.html
+ */
+#if DISABLED(CLASSIC_JERK)
+ #define JUNCTION_DEVIATION_MM 0.013 // (mm) Distance from real junction edge
+#endif
+
/**
* S-Curve Acceleration
*
@@ -887,11 +909,10 @@
/**
* Z Probe to nozzle (X,Y) offset, relative to (0, 0).
- * X and Y offsets must be integers.
*
* In the following example the X and Y offsets are both positive:
- * #define X_PROBE_OFFSET_FROM_EXTRUDER 10
- * #define Y_PROBE_OFFSET_FROM_EXTRUDER 10
+ *
+ * #define NOZZLE_TO_PROBE_OFFSET { 10, 10, 0 }
*
* +-- BACK ---+
* | |
@@ -903,10 +924,10 @@
* | |
* O-- FRONT --+
* (0,0)
+ *
+ * Specify a Probe position as { X, Y, Z }
*/
-#define X_PROBE_OFFSET_FROM_EXTRUDER -44 // X offset: -left +right [of the nozzle]
-#define Y_PROBE_OFFSET_FROM_EXTRUDER -14 // Y offset: -front +behind [the nozzle]
-#define Z_PROBE_OFFSET_FROM_EXTRUDER 0 // Z offset: -below +above [the nozzle]
+#define NOZZLE_TO_PROBE_OFFSET { -44, -14, 0 }
// Certain types of probes need to stay away from edges
#define MIN_PROBE_EDGE 10
@@ -941,7 +962,7 @@
*
* Use these settings to specify the distance (mm) to raise the probe (or
* lower the bed). The values set here apply over and above any (negative)
- * probe Z Offset set with Z_PROBE_OFFSET_FROM_EXTRUDER, M851, or the LCD.
+ * probe Z Offset set with NOZZLE_TO_PROBE_OFFSET, M851, or the LCD.
* Only integer values >= 1 are valid here.
*
* Example: `M851 Z-5` with a CLEARANCE of 4 => 9mm from bed to nozzle.
@@ -1199,12 +1220,6 @@
#define GRID_MAX_POINTS_X 5
#define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X
- // Set the boundaries for probing (where the probe can reach).
- //#define LEFT_PROBE_BED_POSITION MIN_PROBE_EDGE
- //#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE - (MIN_PROBE_EDGE))
- //#define FRONT_PROBE_BED_POSITION MIN_PROBE_EDGE
- //#define BACK_PROBE_BED_POSITION (Y_BED_SIZE - (MIN_PROBE_EDGE))
-
// Probe along the Y axis, advancing X after each column
//#define PROBE_Y_FIRST
@@ -1258,19 +1273,6 @@
#endif // BED_LEVELING
-/**
- * Points to probe for all 3-point Leveling procedures.
- * Override if the automatically selected points are inadequate.
- */
-#if EITHER(AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_UBL)
- //#define PROBE_PT_1_X 15
- //#define PROBE_PT_1_Y 180
- //#define PROBE_PT_2_X 15
- //#define PROBE_PT_2_Y 20
- //#define PROBE_PT_3_X 170
- //#define PROBE_PT_3_Y 20
-#endif
-
/**
* Add a bed leveling sub-menu for ABL or MBL.
* Include a guided procedure if manual probing is enabled.
@@ -1515,7 +1517,7 @@
#define NOZZLE_CLEAN_TRIANGLES 3
// Specify positions as { X, Y, Z }
- #define NOZZLE_CLEAN_START_POINT { 30, 30, (Z_MIN_POS + 1)}
+ #define NOZZLE_CLEAN_START_POINT { 30, 30, (Z_MIN_POS + 1) }
#define NOZZLE_CLEAN_END_POINT { 100, 60, (Z_MIN_POS + 1) }
// Circular pattern radius
@@ -1525,8 +1527,11 @@
// Middle point of circle
#define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT
- // Moves the nozzle to the initial position
+ // Move the nozzle to the initial position after cleaning
#define NOZZLE_CLEAN_GOBACK
+
+ // Enable for a purge/clean station that's always at the gantry height (thus no Z move)
+ //#define NOZZLE_CLEAN_NO_Z
#endif
/**
@@ -1571,10 +1576,10 @@
*
* Select the language to display on the LCD. These languages are available:
*
- * en, an, bg, ca, cz, da, de, el, el-gr, es, eu, fi, fr, gl, hr, it,
- * jp-kana, ko_KR, nl, pl, pt, pt-br, ru, sk, tr, uk, zh_CN, zh_TW, test
+ * en, an, bg, ca, cz, da, de, el, el_gr, es, eu, fi, fr, gl, hr, it, jp_kana,
+ * ko_KR, nl, pl, pt, pt_br, ru, sk, tr, uk, vi, zh_CN, zh_TW, test
*
- * :{ 'en':'English', 'an':'Aragonese', 'bg':'Bulgarian', 'ca':'Catalan', 'cz':'Czech', 'da':'Danish', 'de':'German', 'el':'Greek', 'el-gr':'Greek (Greece)', 'es':'Spanish', 'eu':'Basque-Euskera', 'fi':'Finnish', 'fr':'French', 'gl':'Galician', 'hr':'Croatian', 'it':'Italian', 'jp-kana':'Japanese', 'ko_KR':'Korean (South Korea)', 'nl':'Dutch', 'pl':'Polish', 'pt':'Portuguese', 'pt-br':'Portuguese (Brazilian)', 'ru':'Russian', 'sk':'Slovak', 'tr':'Turkish', 'uk':'Ukrainian', 'zh_CN':'Chinese (Simplified)', 'zh_TW':'Chinese (Traditional)', 'test':'TEST' }
+ * :{ 'en':'English', 'an':'Aragonese', 'bg':'Bulgarian', 'ca':'Catalan', 'cz':'Czech', 'da':'Danish', 'de':'German', 'el':'Greek', 'el_gr':'Greek (Greece)', 'es':'Spanish', 'eu':'Basque-Euskera', 'fi':'Finnish', 'fr':'French', 'gl':'Galician', 'hr':'Croatian', 'it':'Italian', 'jp_kana':'Japanese', 'ko_KR':'Korean (South Korea)', 'nl':'Dutch', 'pl':'Polish', 'pt':'Portuguese', 'pt_br':'Portuguese (Brazilian)', 'ru':'Russian', 'sk':'Slovak', 'tr':'Turkish', 'uk':'Ukrainian', 'vi':'Vietnamese', 'zh_CN':'Chinese (Simplified)', 'zh_TW':'Chinese (Traditional)', 'test':'TEST' }
*/
#define LCD_LANGUAGE en
@@ -1683,6 +1688,14 @@
//
//#define REVERSE_MENU_DIRECTION
+//
+// This option reverses the encoder direction for Select Screen.
+//
+// If CLOCKWISE normally moves LEFT this makes it go RIGHT.
+// If CLOCKWISE normally moves RIGHT this makes it go LEFT.
+//
+//#define REVERSE_SELECT_DIRECTION
+
//
// Individual Axis Homing
//
@@ -1910,31 +1923,12 @@
//
//#define LCD_FOR_MELZI
-//
-// SSD1306 OLED full graphics generic display
-//
-//#define U8GLIB_SSD1306
-
-//
-// SAV OLEd LCD module support using either SSD1306 or SH1106 based LCD modules
-//
-//#define SAV_3DGLCD
-#if ENABLED(SAV_3DGLCD)
- //#define U8GLIB_SSD1306
- #define U8GLIB_SH1106
-#endif
-
//
// Original Ulticontroller from Ultimaker 2 printer with SSD1309 I2C display and encoder
// https://github.com/Ultimaker/Ultimaker2/tree/master/1249_Ulticontroller_Board_(x1)
//
//#define ULTI_CONTROLLER
-//
-// TinyBoy2 128x64 OLED / Encoder Panel
-//
-//#define OLED_PANEL_TINYBOY2
-
//
// MKS MINI12864 with graphic controller and SD support
// https://reprap.org/wiki/MKS_MINI_12864
@@ -1968,6 +1962,41 @@
//
//#define ANET_FULL_GRAPHICS_LCD
+//
+// AZSMZ 12864 LCD with SD
+// https://www.aliexpress.com/item/32837222770.html
+//
+//#define AZSMZ_12864
+
+//
+// Silvergate GLCD controller
+// http://github.com/android444/Silvergate
+//
+//#define SILVER_GATE_GLCD_CONTROLLER
+
+//=============================================================================
+//============================== OLED Displays ==============================
+//=============================================================================
+
+//
+// SSD1306 OLED full graphics generic display
+//
+//#define U8GLIB_SSD1306
+
+//
+// SAV OLEd LCD module support using either SSD1306 or SH1106 based LCD modules
+//
+//#define SAV_3DGLCD
+#if ENABLED(SAV_3DGLCD)
+ #define U8GLIB_SSD1306
+ //#define U8GLIB_SH1106
+#endif
+
+//
+// TinyBoy2 128x64 OLED / Encoder Panel
+//
+//#define OLED_PANEL_TINYBOY2
+
//
// MKS OLED 1.3" 128 × 64 FULL GRAPHICS CONTROLLER
// http://reprap.org/wiki/MKS_12864OLED
@@ -1978,16 +2007,14 @@
//#define MKS_12864OLED_SSD1306 // Uses the SSD1306 controller
//
-// AZSMZ 12864 LCD with SD
-// https://www.aliexpress.com/store/product/3D-printer-smart-controller-SMART-RAMPS-OR-RAMPS-1-4-LCD-12864-LCD-control-panel-green/2179173_32213636460.html
+// Einstart S OLED SSD1306
//
-//#define AZSMZ_12864
+//#define U8GLIB_SH1106_EINSTART
//
-// Silvergate GLCD controller
-// http://github.com/android444/Silvergate
+// Overlord OLED display/controller with i2c buzzer and LEDs
//
-//#define SILVER_GATE_GLCD_CONTROLLER
+//#define OVERLORD_OLED
//=============================================================================
//========================== Extensible UI Displays ===========================
@@ -2003,6 +2030,12 @@
//
//#define MALYAN_LCD
+//
+// Touch UI for FTDI EVE (FT800/FT810) displays
+// See Configuration_adv.h for all configuration options.
+//
+//#define TOUCH_UI_FTDI_EVE
+
//
// Third-party or vendor-customized controller interfaces.
// Sources should be installed in 'src/lcd/extensible_ui'.
@@ -2014,27 +2047,34 @@
//=============================================================================
//
-// MKS Robin 320x240 color display
+// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.)
//
-//#define MKS_ROBIN_TFT
+//#define FSMC_GRAPHICAL_TFT
//=============================================================================
//============================ Other Controllers ============================
//=============================================================================
//
-// CONTROLLER TYPE: Keypad / Add-on
+// ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
//
+//#define TOUCH_BUTTONS
+#if ENABLED(TOUCH_BUTTONS)
+ #define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
+ #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
+
+ #define XPT2046_X_CALIBRATION 12316
+ #define XPT2046_Y_CALIBRATION -8981
+ #define XPT2046_X_OFFSET -43
+ #define XPT2046_Y_OFFSET 257
+#endif
//
// RepRapWorld REPRAPWORLD_KEYPAD v1.1
// http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626
//
-// REPRAPWORLD_KEYPAD_MOVE_STEP sets how much should the robot move when a key
-// is pressed, a value of 10.0 means 10mm per click.
-//
//#define REPRAPWORLD_KEYPAD
-//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0
+//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 // (mm) Distance to move per key-press
//=============================================================================
//=============================== Extra Features ==============================
@@ -2120,8 +2160,10 @@
//#define NEOPIXEL_LED
#if ENABLED(NEOPIXEL_LED)
#define NEOPIXEL_TYPE NEO_GRBW // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h)
- #define NEOPIXEL_PIN 4 // LED driving pin
- #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip
+ #define NEOPIXEL_PIN 4 // LED driving pin
+ //#define NEOPIXEL2_TYPE NEOPIXEL_TYPE
+ //#define NEOPIXEL2_PIN 5
+ #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used
#define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once.
#define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255)
//#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup
@@ -2160,7 +2202,7 @@
*/
//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command
-// Delay (in milliseconds) before the next move will start, to give the servo time to reach its target angle.
+// (ms) Delay before the next move will start, to give the servo time to reach its target angle.
// 300ms is a good value but you can try less delay.
// If the servo can't reach the requested position, increase it.
#define SERVO_DELAY { 300 }
diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index 1a968039410d..12fffc69ec25 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -197,6 +197,56 @@
#define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
#define LPQ_MAX_LEN 50
#endif
+
+ /**
+ * Add an experimental additional term to the heater power, proportional to the fan speed.
+ * A well-chosen Kf value should add just enough power to compensate for power-loss from the cooling fan.
+ * You can either just add a constant compensation with the DEFAULT_Kf value
+ * or follow the instruction below to get speed-dependent compensation.
+ *
+ * Constant compensation (use only with fanspeeds of 0% and 100%)
+ * ---------------------------------------------------------------------
+ * A good starting point for the Kf-value comes from the calculation:
+ * kf = (power_fan * eff_fan) / power_heater * 255
+ * where eff_fan is between 0.0 and 1.0, based on fan-efficiency and airflow to the nozzle / heater.
+ *
+ * Example:
+ * Heater: 40W, Fan: 0.1A * 24V = 2.4W, eff_fan = 0.8
+ * Kf = (2.4W * 0.8) / 40W * 255 = 12.24
+ *
+ * Fan-speed dependent compensation
+ * --------------------------------
+ * 1. To find a good Kf value, set the hotend temperature, wait for it to settle, and enable the fan (100%).
+ * Make sure PID_FAN_SCALING_LIN_FACTOR is 0 and PID_FAN_SCALING_ALTERNATIVE_DEFINITION is not enabled.
+ * If you see the temperature drop repeat the test, increasing the Kf value slowly, until the temperature
+ * drop goes away. If the temperature overshoots after enabling the fan, the Kf value is too big.
+ * 2. Note the Kf-value for fan-speed at 100%
+ * 3. Determine a good value for PID_FAN_SCALING_MIN_SPEED, which is around the speed, where the fan starts moving.
+ * 4. Repeat step 1. and 2. for this fan speed.
+ * 5. Enable PID_FAN_SCALING_ALTERNATIVE_DEFINITION and enter the two identified Kf-values in
+ * PID_FAN_SCALING_AT_FULL_SPEED and PID_FAN_SCALING_AT_MIN_SPEED. Enter the minimum speed in PID_FAN_SCALING_MIN_SPEED
+ */
+ //#define PID_FAN_SCALING
+ #if ENABLED(PID_FAN_SCALING)
+ //#define PID_FAN_SCALING_ALTERNATIVE_DEFINITION
+ #if ENABLED(PID_FAN_SCALING_ALTERNATIVE_DEFINITION)
+ // The alternative definition is used for an easier configuration.
+ // Just figure out Kf at fullspeed (255) and PID_FAN_SCALING_MIN_SPEED.
+ // DEFAULT_Kf and PID_FAN_SCALING_LIN_FACTOR are calculated accordingly.
+
+ #define PID_FAN_SCALING_AT_FULL_SPEED 13.0 //=PID_FAN_SCALING_LIN_FACTOR*255+DEFAULT_Kf
+ #define PID_FAN_SCALING_AT_MIN_SPEED 6.0 //=PID_FAN_SCALING_LIN_FACTOR*PID_FAN_SCALING_MIN_SPEED+DEFAULT_Kf
+ #define PID_FAN_SCALING_MIN_SPEED 10.0 // Minimum fan speed at which to enable PID_FAN_SCALING
+
+ #define DEFAULT_Kf (255.0*PID_FAN_SCALING_AT_MIN_SPEED-PID_FAN_SCALING_AT_FULL_SPEED*PID_FAN_SCALING_MIN_SPEED)/(255.0-PID_FAN_SCALING_MIN_SPEED)
+ #define PID_FAN_SCALING_LIN_FACTOR (PID_FAN_SCALING_AT_FULL_SPEED-DEFAULT_Kf)/255.0
+
+ #else
+ #define PID_FAN_SCALING_LIN_FACTOR (0) // Power loss due to cooling = Kf * (fan_speed)
+ #define DEFAULT_Kf 10 // A constant value added to the PID-tuner
+ #define PID_FAN_SCALING_MIN_SPEED 10 // Minimum fan speed at which to enable PID_FAN_SCALING
+ #endif
+ #endif
#endif
/**
@@ -214,7 +264,7 @@
#define AUTOTEMP_OLDWEIGHT 0.98
#endif
-// Show extra position information in M114
+// Show extra position information with 'M114 D'
//#define M114_DETAIL
// Show Temperature ADC value
@@ -279,9 +329,10 @@
*/
//#define USE_CONTROLLER_FAN
#if ENABLED(USE_CONTROLLER_FAN)
- //#define CONTROLLER_FAN_PIN -1 // Set a custom pin for the controller fan
- #define CONTROLLERFAN_SECS 60 // Duration in seconds for the fan to run after all motors are disabled
- #define CONTROLLERFAN_SPEED 255 // 255 == full speed
+ //#define CONTROLLER_FAN_PIN -1 // Set a custom pin for the controller fan
+ #define CONTROLLERFAN_SECS 60 // Duration in seconds for the fan to run after all motors are disabled
+ #define CONTROLLERFAN_SPEED 255 // 255 == full speed
+ //#define CONTROLLERFAN_SPEED_Z_ONLY 127 // Reduce noise on machines that keep Z enabled
#endif
// When first starting the main fan, run it at full speed for the
@@ -289,6 +340,9 @@
// before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu)
//#define FAN_KICKSTART_TIME 100
+// Some coolers may require a non-zero "off" state.
+//#define FAN_OFF_PWM 1
+
/**
* PWM Fan Scaling
*
@@ -378,6 +432,7 @@
#define INVERT_CASE_LIGHT false // Set true if Case Light is ON when pin is LOW
#define CASE_LIGHT_DEFAULT_ON true // Set default power-up state on
#define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // Set default power-up brightness (0-255, requires PWM pin)
+ //#define CASE_LIGHT_MAX_PWM 128 // Limit pwm
//#define CASE_LIGHT_MENU // Add Case Light options to the LCD menu
//#define CASE_LIGHT_NO_BRIGHTNESS // Disable brightness control. Enable for non-PWM lighting.
//#define CASE_LIGHT_USE_NEOPIXEL // Use Neopixel LED as case light, requires NEOPIXEL_LED.
@@ -601,25 +656,37 @@
//#define Z_STEPPER_AUTO_ALIGN
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
// Define probe X and Y positions for Z1, Z2 [, Z3]
- #define Z_STEPPER_ALIGN_X { 10, 150, 290 }
- #define Z_STEPPER_ALIGN_Y { 290, 10, 290 }
+ #define Z_STEPPER_ALIGN_XY { { 10, 290 }, { 150, 10 }, { 290, 290 } }
+
+ // Provide Z stepper positions for more rapid convergence in bed alignment.
+ // Currently requires triple stepper drivers.
+ //#define Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
+ #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
+ // Define Stepper XY positions for Z1, Z2, Z3 corresponding to
+ // the Z screw positions in the bed carriage.
+ // Define one position per Z stepper in stepper driver order.
+ #define Z_STEPPER_ALIGN_STEPPER_XY { { 210.7, 102.5 }, { 152.6, 220.0 }, { 94.5, 102.5 } }
+ #else
+ // Amplification factor. Used to scale the correction step up or down.
+ // In case the stepper (spindle) position is further out than the test point.
+ // Use a value > 1. NOTE: This may cause instability
+ #define Z_STEPPER_ALIGN_AMP 1.0
+ #endif
+
// Set number of iterations to align
#define Z_STEPPER_ALIGN_ITERATIONS 3
+
// Enable to restore leveling setup after operation
#define RESTORE_LEVELING_AFTER_G34
// On a 300mm bed a 5% grade would give a misalignment of ~1.5cm
#define G34_MAX_GRADE 5 // (%) Maximum incline G34 will handle
- // Use the amplification factor to de-/increase correction step.
- // In case the stepper (spindle) position is further out than the test point
- // Use a value > 1. NOTE: This may cause instability
- #define Z_STEPPER_ALIGN_AMP 1.0
// Stop criterion. If the accuracy is better than this stop iterating early
#define Z_STEPPER_ALIGN_ACC 0.02
#endif
-// @section machine
+// @section motion
#define AXIS_RELATIVE_MODES { false, false, false, false }
@@ -646,20 +713,8 @@
//#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated
-// @section lcd
-
-#if EITHER(ULTIPANEL, EXTENSIBLE_UI)
- #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 60 } // Feedrates for manual moves along X, Y, Z, E from panel
- #if ENABLED(ULTIPANEL)
- #define MANUAL_E_MOVES_RELATIVE // Display extruder move distance rather than "position"
- #define ULTIPANEL_FEEDMULTIPLY // Encoder sets the feedrate multiplier on the Status Screen
- #endif
-#endif
-
-// @section extras
-
-// minimum time in microseconds that a movement needs to take if the buffer is emptied.
-#define DEFAULT_MINSEGMENTTIME 20000
+// Minimum time that a segment needs to take if the buffer is emptied
+#define DEFAULT_MINSEGMENTTIME 20000 // (ms)
// If defined the movements slow down when the look ahead buffer is only half full
#define SLOWDOWN
@@ -737,8 +792,8 @@
//#define CALIBRATION_REPORTING
// The true location and dimension the cube/bolt/washer on the bed.
- #define CALIBRATION_OBJECT_CENTER { 264.0, -22.0, -2.0} // mm
- #define CALIBRATION_OBJECT_DIMENSIONS { 10.0, 10.0, 10.0} // mm
+ #define CALIBRATION_OBJECT_CENTER { 264.0, -22.0, -2.0 } // mm
+ #define CALIBRATION_OBJECT_DIMENSIONS { 10.0, 10.0, 10.0 } // mm
// Comment out any sides which are unreachable by the probe. For best
// auto-calibration results, all sides must be reachable.
@@ -834,6 +889,15 @@
// @section lcd
+#if EITHER(ULTIPANEL, EXTENSIBLE_UI)
+ #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 60 } // Feedrates for manual moves along X, Y, Z, E from panel
+ #define SHORT_MANUAL_Z_MOVE 0.025 // (mm) Smallest manual Z move (< 0.1mm)
+ #if ENABLED(ULTIPANEL)
+ #define MANUAL_E_MOVES_RELATIVE // Display extruder move distance rather than "position"
+ #define ULTIPANEL_FEEDMULTIPLY // Encoder sets the feedrate multiplier on the Status Screen
+ #endif
+#endif
+
// Change values more rapidly when the encoder is rotated faster
#define ENCODER_RATE_MULTIPLIER
#if ENABLED(ENCODER_RATE_MULTIPLIER)
@@ -848,8 +912,35 @@
#define FEEDRATE_CHANGE_BEEP_FREQUENCY 440
#endif
-// Include a page of printer information in the LCD Main Menu
-#define LCD_INFO_MENU
+#if HAS_LCD_MENU
+
+ // Include a page of printer information in the LCD Main Menu
+ #define LCD_INFO_MENU
+ #if ENABLED(LCD_INFO_MENU)
+ //#define LCD_PRINTER_INFO_IS_BOOTSCREEN // Show bootscreen(s) instead of Printer Info pages
+ #endif
+
+ // BACK menu items keep the highlight at the top
+ //#define TURBO_BACK_MENU_ITEM
+
+ /**
+ * LED Control Menu
+ * Add LED Control to the LCD menu
+ */
+ //#define LED_CONTROL_MENU
+ #if ENABLED(LED_CONTROL_MENU)
+ #define LED_COLOR_PRESETS // Enable the Preset Color menu option
+ #if ENABLED(LED_COLOR_PRESETS)
+ #define LED_USER_PRESET_RED 255 // User defined RED value
+ #define LED_USER_PRESET_GREEN 128 // User defined GREEN value
+ #define LED_USER_PRESET_BLUE 0 // User defined BLUE value
+ #define LED_USER_PRESET_WHITE 255 // User defined WHITE value
+ #define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity
+ //#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
+ #endif
+ #endif
+
+#endif // HAS_LCD_MENU
// Scroll a longer status message into view
#define STATUS_MESSAGE_SCROLLING
@@ -863,6 +954,18 @@
// Add an 'M73' G-code to set the current percentage
//#define LCD_SET_PROGRESS_MANUALLY
+// Show the E position (filament used) during printing
+//#define LCD_SHOW_E_TOTAL
+
+#if HAS_GRAPHICAL_LCD && HAS_PRINT_PROGRESS
+ //#define PRINT_PROGRESS_SHOW_DECIMALS // Show progress with decimal digits
+ //#define SHOW_REMAINING_TIME // Display estimated time to completion
+ #if ENABLED(SHOW_REMAINING_TIME)
+ //#define USE_M73_REMAINING_TIME // Use remaining time from M73 command instead of estimation
+ //#define ROTATE_PROGRESS_DISPLAY // Display (P)rogress, (E)lapsed, and (R)emaining time
+ #endif
+#endif
+
#if HAS_CHARACTER_LCD && HAS_PRINT_PROGRESS
//#define LCD_PROGRESS_BAR // Show a progress bar on HD44780 LCDs for SD printing
#if ENABLED(LCD_PROGRESS_BAR)
@@ -874,23 +977,6 @@
#endif
#endif
-/**
- * LED Control Menu
- * Enable this feature to add LED Control to the LCD menu
- */
-//#define LED_CONTROL_MENU
-#if ENABLED(LED_CONTROL_MENU)
- #define LED_COLOR_PRESETS // Enable the Preset Color menu option
- #if ENABLED(LED_COLOR_PRESETS)
- #define LED_USER_PRESET_RED 255 // User defined RED value
- #define LED_USER_PRESET_GREEN 128 // User defined GREEN value
- #define LED_USER_PRESET_BLUE 0 // User defined BLUE value
- #define LED_USER_PRESET_WHITE 255 // User defined WHITE value
- #define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity
- //#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
- #endif
-#endif // LED_CONTROL_MENU
-
#if ENABLED(SDSUPPORT)
// Some RAMPS and other boards don't detect when an SD card is inserted. You can work
@@ -923,8 +1009,11 @@
*/
//#define POWER_LOSS_RECOVERY
#if ENABLED(POWER_LOSS_RECOVERY)
+ //#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss
+ //#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS)
//#define POWER_LOSS_PIN 44 // Pin to detect power loss
//#define POWER_LOSS_STATE HIGH // State of pin indicating power loss
+ //#define POWER_LOSS_PULL // Set pullup / pulldown as appropriate
//#define POWER_LOSS_PURGE_LEN 20 // (mm) Length of filament to purge on resume
//#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail. Requires backup power.
@@ -1004,17 +1093,31 @@
* equivalent MAX3421E breakout board. The USB thumb drive will appear
* to Marlin as an SD card.
*
- * The MAX3421E must be assigned the same pins as the SD card reader, with
+ * The MAX3421E can be assigned the same pins as the SD card reader, with
* the following pin mapping:
*
* SCLK, MOSI, MISO --> 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
/**
@@ -1036,7 +1139,7 @@
// Add an optimized binary file transfer mode, initiated with 'M28 B1'
//#define BINARY_FILE_TRANSFER
- #ifdef TARGET_LPC1768
+ #if HAS_SDCARD_CONNECTION
/**
* Set this option to one of the following (or the board's defaults apply):
*
@@ -1129,14 +1232,114 @@
//#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
+//
+// Touch UI for the FTDI Embedded Video Engine (EVE)
+//
+#if ENABLED(TOUCH_UI_FTDI_EVE)
+ // Display board used
+ //#define LCD_FTDI_VM800B35A // FTDI 3.5" with FT800 (320x240)
+ //#define LCD_4DSYSTEMS_4DLCD_FT843 // 4D Systems 4.3" (480x272)
+ //#define LCD_HAOYU_FT800CB // Haoyu with 4.3" or 5" (480x272)
+ //#define LCD_HAOYU_FT810CB // Haoyu with 5" (800x480)
+ //#define LCD_ALEPHOBJECTS_CLCD_UI // Aleph Objects Color LCD UI
+
+ // Correct the resolution if not using the stock TFT panel.
+ //#define TOUCH_UI_320x240
+ //#define TOUCH_UI_480x272
+ //#define TOUCH_UI_800x480
+
+ // Mappings for boards with a standard RepRapDiscount Display connector
+ //#define AO_EXP1_PINMAP // AlephObjects CLCD UI EXP1 mapping
+ //#define AO_EXP2_PINMAP // AlephObjects CLCD UI EXP2 mapping
+ //#define CR10_TFT_PINMAP // Rudolph Riedel's CR10 pin mapping
+ //#define OTHER_PIN_LAYOUT // Define pins manually below
+ #if ENABLED(OTHER_PIN_LAYOUT)
+ // The pins for CS and MOD_RESET (PD) must be chosen.
+ #define CLCD_MOD_RESET 9
+ #define CLCD_SPI_CS 10
+
+ // If using software SPI, specify pins for SCLK, MOSI, MISO
+ //#define CLCD_USE_SOFT_SPI
+ #if ENABLED(CLCD_USE_SOFT_SPI)
+ #define CLCD_SOFT_SPI_MOSI 11
+ #define CLCD_SOFT_SPI_MISO 12
+ #define CLCD_SOFT_SPI_SCLK 13
+ #endif
+ #endif
+
+ // Display Orientation. An inverted (i.e. upside-down) display
+ // is supported on the FT800. The FT810 and beyond also support
+ // portrait and mirrored orientations.
+ //#define TOUCH_UI_INVERTED
+ //#define TOUCH_UI_PORTRAIT
+ //#define TOUCH_UI_MIRRORED
+
+ // UTF8 processing and rendering.
+ // Unsupported characters are shown as '?'.
+ //#define TOUCH_UI_USE_UTF8
+ #if ENABLED(TOUCH_UI_USE_UTF8)
+ // Western accents support. These accented characters use
+ // combined bitmaps and require relatively little storage.
+ #define TOUCH_UI_UTF8_WESTERN_CHARSET
+ #if ENABLED(TOUCH_UI_UTF8_WESTERN_CHARSET)
+ // Additional character groups. These characters require
+ // full bitmaps and take up considerable storage:
+ //#define TOUCH_UI_UTF8_SUPERSCRIPTS // ¹ ² ³
+ //#define TOUCH_UI_UTF8_COPYRIGHT // © ®
+ //#define TOUCH_UI_UTF8_GERMANIC // ß
+ //#define TOUCH_UI_UTF8_SCANDINAVIAN // Æ Ð Ø Þ æ ð ø þ
+ //#define TOUCH_UI_UTF8_PUNCTUATION // « » ¿ ¡
+ //#define TOUCH_UI_UTF8_CURRENCY // ¢ £ ¤ ¥
+ //#define TOUCH_UI_UTF8_ORDINALS // º ª
+ //#define TOUCH_UI_UTF8_MATHEMATICS // ± × ÷
+ //#define TOUCH_UI_UTF8_FRACTIONS // ¼ ½ ¾
+ //#define TOUCH_UI_UTF8_SYMBOLS // µ ¶ ¦ § ¬
+ #endif
+ #endif
+
+ // Use a smaller font when labels don't fit buttons
+ #define TOUCH_UI_FIT_TEXT
+
+ // Allow language selection from menu at run-time (otherwise use LCD_LANGUAGE)
+ //#define LCD_LANGUAGE_1 en
+ //#define LCD_LANGUAGE_2 fr
+ //#define LCD_LANGUAGE_3 de
+ //#define LCD_LANGUAGE_4 es
+ //#define LCD_LANGUAGE_5 it
+
+ // Use a numeric passcode for "Screen lock" keypad.
+ // (recommended for smaller displays)
+ //#define TOUCH_UI_PASSCODE
+
+ // Output extra debug info for Touch UI events
+ //#define TOUCH_UI_DEBUG
+
+ // Developer menu (accessed by touching "About Printer" copyright text)
+ //#define TOUCH_UI_DEVELOPER_MENU
+#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
/**
@@ -1167,7 +1370,8 @@
//#define BABYSTEP_WITHOUT_HOMING
//#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA!
#define BABYSTEP_INVERT_Z false // Change if Z babysteps should go the other way
- #define BABYSTEP_MULTIPLICATOR 10 // Babysteps are very small. Increase for faster motion.
+ #define BABYSTEP_MULTIPLICATOR_Z 10 // Babysteps are very small. Increase for faster motion.
+ #define BABYSTEP_MULTIPLICATOR_XY 10
#define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping.
#if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING)
@@ -1217,6 +1421,42 @@
// @section leveling
+/**
+ * Points to probe for all 3-point Leveling procedures.
+ * Override if the automatically selected points are inadequate.
+ */
+#if EITHER(AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_UBL)
+ //#define PROBE_PT_1_X 15
+ //#define PROBE_PT_1_Y 180
+ //#define PROBE_PT_2_X 15
+ //#define PROBE_PT_2_Y 20
+ //#define PROBE_PT_3_X 170
+ //#define PROBE_PT_3_Y 20
+#endif
+
+/**
+ * Override MIN_PROBE_EDGE for each side of the build plate
+ * Useful to get probe points to exact positions on targets or
+ * to allow leveling to avoid plate clamps on only specific
+ * sides of the bed.
+ *
+ * If you are replacing the prior *_PROBE_BED_POSITION options,
+ * LEFT and FRONT values in most cases will map directly over
+ * RIGHT and REAR would be the inverse such as
+ * (X/Y_BED_SIZE - RIGHT/BACK_PROBE_BED_POSITION)
+ *
+ * This will allow all positions to match at compilation, however
+ * should the probe position be modified with M851XY then the
+ * probe points will follow. This prevents any change from causing
+ * the probe to be unable to reach any points.
+ */
+#if PROBE_SELECTED && !IS_KINEMATIC
+ //#define MIN_PROBE_EDGE_LEFT MIN_PROBE_EDGE
+ //#define MIN_PROBE_EDGE_RIGHT MIN_PROBE_EDGE
+ //#define MIN_PROBE_EDGE_FRONT MIN_PROBE_EDGE
+ //#define MIN_PROBE_EDGE_BACK MIN_PROBE_EDGE
+#endif
+
#if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
// Override the mesh area if the automatic (max) area is too large
//#define MESH_MIN_X MESH_INSET
@@ -1277,7 +1517,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
@@ -1289,7 +1529,8 @@
*
* Override the default value based on the driver type set in Configuration.h.
*/
-//#define MINIMUM_STEPPER_DIR_DELAY 650
+//#define MINIMUM_STEPPER_POST_DIR_DELAY 650
+//#define MINIMUM_STEPPER_PRE_DIR_DELAY 650
/**
* Minimum stepper driver pulse width (in µs)
@@ -1364,6 +1605,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.
@@ -1421,19 +1665,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
@@ -1507,8 +1751,8 @@
//#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.
- #define FILAMENT_UNLOAD_DELAY 5000 // (ms) Delay for the filament to cool after retract.
+ #define FILAMENT_UNLOAD_PURGE_RETRACT 13 // (mm) Unload initial retract length.
+ #define FILAMENT_UNLOAD_PURGE_DELAY 5000 // (ms) Delay for the filament to cool after retract.
#define FILAMENT_UNLOAD_PURGE_LENGTH 8 // (mm) An unretract is done, then this length is purged.
#define PAUSE_PARK_NOZZLE_TIMEOUT 45 // (seconds) Time limit before the nozzle is turned off for safety.
@@ -1636,81 +1880,101 @@
#define INTERPOLATE true // Interpolate X/Y/Z_MICROSTEPS to 256
#if AXIS_IS_TMC(X)
- #define X_CURRENT 725 // (mA) RMS current. Multiply by 1.414 for peak current.
- #define X_MICROSTEPS 16 // 0..256
- #define X_RSENSE 0.11
+ #define X_CURRENT 725 // (mA) RMS current. Multiply by 1.414 for peak current.
+ #define X_CURRENT_HOME X_CURRENT // (mA) RMS current for sensorless homing
+ #define X_MICROSTEPS 16 // 0..256
+ #define X_RSENSE 0.11
+ #define X_CHAIN_POS -1 // <=0 : Not chained. 1 : MCU MOSI connected. 2 : Next in chain, ...
#endif
#if AXIS_IS_TMC(X2)
- #define X2_CURRENT 800
- #define X2_MICROSTEPS 16
- #define X2_RSENSE 0.11
+ #define X2_CURRENT 800
+ #define X2_CURRENT_HOME X2_CURRENT
+ #define X2_MICROSTEPS 16
+ #define X2_RSENSE 0.11
+ #define X2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Y)
- #define Y_CURRENT 725
- #define Y_MICROSTEPS 16
- #define Y_RSENSE 0.11
+ #define Y_CURRENT 725
+ #define Y_CURRENT_HOME Y_CURRENT
+ #define Y_MICROSTEPS 16
+ #define Y_RSENSE 0.11
+ #define Y_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Y2)
- #define Y2_CURRENT 800
- #define Y2_MICROSTEPS 16
- #define Y2_RSENSE 0.11
+ #define Y2_CURRENT 800
+ #define Y2_CURRENT_HOME Y2_CURRENT
+ #define Y2_MICROSTEPS 16
+ #define Y2_RSENSE 0.11
+ #define Y2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Z)
- #define Z_CURRENT 725
- #define Z_MICROSTEPS 16
- #define Z_RSENSE 0.11
+ #define Z_CURRENT 725
+ #define Z_CURRENT_HOME Z_CURRENT
+ #define Z_MICROSTEPS 16
+ #define Z_RSENSE 0.11
+ #define Z_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Z2)
- #define Z2_CURRENT 800
- #define Z2_MICROSTEPS 16
- #define Z2_RSENSE 0.11
+ #define Z2_CURRENT 800
+ #define Z2_CURRENT_HOME Z2_CURRENT
+ #define Z2_MICROSTEPS 16
+ #define Z2_RSENSE 0.11
+ #define Z2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(Z3)
- #define Z3_CURRENT 800
- #define Z3_MICROSTEPS 16
- #define Z3_RSENSE 0.11
+ #define Z3_CURRENT 800
+ #define Z3_CURRENT_HOME Z3_CURRENT
+ #define Z3_MICROSTEPS 16
+ #define Z3_RSENSE 0.11
+ #define Z3_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E0)
- #define E0_CURRENT 900
- #define E0_MICROSTEPS 16
- #define E0_RSENSE 0.11
+ #define E0_CURRENT 900
+ #define E0_MICROSTEPS 16
+ #define E0_RSENSE 0.11
+ #define E0_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E1)
- #define E1_CURRENT 800
- #define E1_MICROSTEPS 16
- #define E1_RSENSE 0.11
+ #define E1_CURRENT 800
+ #define E1_MICROSTEPS 16
+ #define E1_RSENSE 0.11
+ #define E1_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E2)
- #define E2_CURRENT 800
- #define E2_MICROSTEPS 16
- #define E2_RSENSE 0.11
+ #define E2_CURRENT 800
+ #define E2_MICROSTEPS 16
+ #define E2_RSENSE 0.11
+ #define E2_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E3)
- #define E3_CURRENT 800
- #define E3_MICROSTEPS 16
- #define E3_RSENSE 0.11
+ #define E3_CURRENT 800
+ #define E3_MICROSTEPS 16
+ #define E3_RSENSE 0.11
+ #define E3_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E4)
- #define E4_CURRENT 800
- #define E4_MICROSTEPS 16
- #define E4_RSENSE 0.11
+ #define E4_CURRENT 800
+ #define E4_MICROSTEPS 16
+ #define E4_RSENSE 0.11
+ #define E4_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E5)
- #define E5_CURRENT 800
- #define E5_MICROSTEPS 16
- #define E5_RSENSE 0.11
+ #define E5_CURRENT 800
+ #define E5_MICROSTEPS 16
+ #define E5_RSENSE 0.11
+ #define E5_CHAIN_POS -1
#endif
/**
@@ -1749,6 +2013,9 @@
* 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
@@ -1840,17 +2107,29 @@
#define E5_HYBRID_THRESHOLD 30
/**
+ * Use StallGuard2 to home / probe X, Y, Z.
+ *
* TMC2130, TMC2160, TMC2209, TMC2660, TMC5130, and TMC5160 only
- * Use StallGuard2 to sense an obstacle and trigger an endstop.
* 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.
+ *
+ * TMC2209 requires STEALTHCHOP enabled for SENSORLESS_HOMING
*/
//#define SENSORLESS_HOMING // StallGuard capable drivers only
@@ -1865,8 +2144,12 @@
#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 HOME_USING_SPREADCYCLE
+ //#define IMPROVE_HOMING_RELIABILITY
#endif
/**
@@ -1888,8 +2171,8 @@
*
* Example:
* #define TMC_ADV() { \
- * stepperX.diag0_temp_prewarn(1); \
- * stepperY.interpolate(0); \
+ * stepperX.diag0_otpw(1); \
+ * stepperY.intpol(0); \
* }
*/
#define TMC_ADV() { }
@@ -1920,7 +2203,7 @@
#define X_OVERCURRENT 2000 // (mA) Current where the driver detects an over current (VALID: 375 x (1 - 16) - 6A max - rounds down)
#define X_STALLCURRENT 1500 // (mA) Current where the driver detects a stall (VALID: 31.25 * (1-128) - 4A max - rounds down)
#define X_MAX_VOLTAGE 127 // 0-255, Maximum effective voltage seen by stepper
- #define X_CHAIN_POS 0 // Position in SPI chain, 0=Not in chain, 1=Nearest MOSI
+ #define X_CHAIN_POS -1 // Position in SPI chain. (<=0 : Not in chain. 1 : Nearest MOSI)
#endif
#if AXIS_DRIVER_TYPE_X2(L6470)
@@ -1928,7 +2211,7 @@
#define X2_OVERCURRENT 2000
#define X2_STALLCURRENT 1500
#define X2_MAX_VOLTAGE 127
- #define X2_CHAIN_POS 0
+ #define X2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Y(L6470)
@@ -1936,7 +2219,7 @@
#define Y_OVERCURRENT 2000
#define Y_STALLCURRENT 1500
#define Y_MAX_VOLTAGE 127
- #define Y_CHAIN_POS 0
+ #define Y_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Y2(L6470)
@@ -1944,7 +2227,7 @@
#define Y2_OVERCURRENT 2000
#define Y2_STALLCURRENT 1500
#define Y2_MAX_VOLTAGE 127
- #define Y2_CHAIN_POS 0
+ #define Y2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Z(L6470)
@@ -1952,7 +2235,7 @@
#define Z_OVERCURRENT 2000
#define Z_STALLCURRENT 1500
#define Z_MAX_VOLTAGE 127
- #define Z_CHAIN_POS 0
+ #define Z_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Z2(L6470)
@@ -1960,7 +2243,7 @@
#define Z2_OVERCURRENT 2000
#define Z2_STALLCURRENT 1500
#define Z2_MAX_VOLTAGE 127
- #define Z2_CHAIN_POS 0
+ #define Z2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_Z3(L6470)
@@ -1968,7 +2251,7 @@
#define Z3_OVERCURRENT 2000
#define Z3_STALLCURRENT 1500
#define Z3_MAX_VOLTAGE 127
- #define Z3_CHAIN_POS 0
+ #define Z3_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E0(L6470)
@@ -1976,7 +2259,7 @@
#define E0_OVERCURRENT 2000
#define E0_STALLCURRENT 1500
#define E0_MAX_VOLTAGE 127
- #define E0_CHAIN_POS 0
+ #define E0_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E1(L6470)
@@ -1984,7 +2267,7 @@
#define E1_OVERCURRENT 2000
#define E1_STALLCURRENT 1500
#define E1_MAX_VOLTAGE 127
- #define E1_CHAIN_POS 0
+ #define E1_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E2(L6470)
@@ -1992,7 +2275,7 @@
#define E2_OVERCURRENT 2000
#define E2_STALLCURRENT 1500
#define E2_MAX_VOLTAGE 127
- #define E2_CHAIN_POS 0
+ #define E2_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E3(L6470)
@@ -2000,7 +2283,7 @@
#define E3_OVERCURRENT 2000
#define E3_STALLCURRENT 1500
#define E3_MAX_VOLTAGE 127
- #define E3_CHAIN_POS 0
+ #define E3_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E4(L6470)
@@ -2008,7 +2291,7 @@
#define E4_OVERCURRENT 2000
#define E4_STALLCURRENT 1500
#define E4_MAX_VOLTAGE 127
- #define E4_CHAIN_POS 0
+ #define E4_CHAIN_POS -1
#endif
#if AXIS_DRIVER_TYPE_E5(L6470)
@@ -2016,7 +2299,7 @@
#define E5_OVERCURRENT 2000
#define E5_STALLCURRENT 1500
#define E5_MAX_VOLTAGE 127
- #define E5_CHAIN_POS 0
+ #define E5_CHAIN_POS -1
#endif
/**
@@ -2221,6 +2504,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
*/
@@ -2275,6 +2565,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
*
@@ -2332,9 +2629,12 @@
//#define HOST_PROMPT_SUPPORT
#endif
-//===========================================================================
-//====================== I2C Position Encoder Settings ======================
-//===========================================================================
+/**
+ * Cancel Objects
+ *
+ * Implement M486 to allow Marlin to skip objects
+ */
+//#define CANCEL_OBJECTS
/**
* I2C position encoders for closed loop control.
@@ -2416,6 +2716,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
*
@@ -2434,6 +2750,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
diff --git a/Marlin/Makefile b/Marlin/Makefile
index 222e60d62060..b0ada2616b5a 100644
--- a/Marlin/Makefile
+++ b/Marlin/Makefile
@@ -92,6 +92,9 @@ U8GLIB ?= 1
# this defines whether to include the Trinamic TMCStepper library
TMC ?= 1
+# this defines whether to include the AdaFruit NeoPixel library
+NEOPIXEL ?= 0
+
############
# Try to automatically determine whether RELOC_WORKAROUND is needed based
# on GCC versions:
@@ -237,7 +240,7 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1134)
else ifeq ($(HARDWARE_MOTHERBOARD),1135)
# Dagoma F5
else ifeq ($(HARDWARE_MOTHERBOARD),1136)
-# Fysetc F6
+# FYSETC F6
else ifeq ($(HARDWARE_MOTHERBOARD),1137)
# Duplicator i3 Plus
else ifeq ($(HARDWARE_MOTHERBOARD),1138)
@@ -247,69 +250,92 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1139)
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)
+# BIQU Tango V1
+else ifeq ($(HARDWARE_MOTHERBOARD),1146)
+# MKS GEN L V2
+else ifeq ($(HARDWARE_MOTHERBOARD),1147)
+
+#
+# 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),1200)
+else ifeq ($(HARDWARE_MOTHERBOARD),1300)
# Cartesio CN Controls V12
-else ifeq ($(HARDWARE_MOTHERBOARD),1201)
+else ifeq ($(HARDWARE_MOTHERBOARD),1301)
+# Cartesio CN Controls V15
+else ifeq ($(HARDWARE_MOTHERBOARD),1302)
# Cheaptronic v1.0
-else ifeq ($(HARDWARE_MOTHERBOARD),1202)
+else ifeq ($(HARDWARE_MOTHERBOARD),1303)
# Cheaptronic v2.0
-else ifeq ($(HARDWARE_MOTHERBOARD),1203)
+else ifeq ($(HARDWARE_MOTHERBOARD),1304)
# Makerbot Mightyboard Revision E
-else ifeq ($(HARDWARE_MOTHERBOARD),1204)
+else ifeq ($(HARDWARE_MOTHERBOARD),1305)
# Megatronics
-else ifeq ($(HARDWARE_MOTHERBOARD),1205)
+else ifeq ($(HARDWARE_MOTHERBOARD),1306)
# Megatronics v2.0
-else ifeq ($(HARDWARE_MOTHERBOARD),1206)
+else ifeq ($(HARDWARE_MOTHERBOARD),1307)
# Megatronics v3.0
-else ifeq ($(HARDWARE_MOTHERBOARD),1207)
+else ifeq ($(HARDWARE_MOTHERBOARD),1308)
# Megatronics v3.1
-else ifeq ($(HARDWARE_MOTHERBOARD),1208)
+else ifeq ($(HARDWARE_MOTHERBOARD),1309)
# Megatronics v3.2
-else ifeq ($(HARDWARE_MOTHERBOARD),1209)
-# Rambo
-else ifeq ($(HARDWARE_MOTHERBOARD),1210)
-# Mini-Rambo
-else ifeq ($(HARDWARE_MOTHERBOARD),1211)
-# Mini-Rambo 1.0a
-else ifeq ($(HARDWARE_MOTHERBOARD),1212)
-# Einsy Rambo
-else ifeq ($(HARDWARE_MOTHERBOARD),1213)
-# Einsy Retro
-else ifeq ($(HARDWARE_MOTHERBOARD),1214)
+else ifeq ($(HARDWARE_MOTHERBOARD),1310)
# Elefu Ra Board (v3)
-else ifeq ($(HARDWARE_MOTHERBOARD),1215)
+else ifeq ($(HARDWARE_MOTHERBOARD),1311)
# Leapfrog
-else ifeq ($(HARDWARE_MOTHERBOARD),1216)
+else ifeq ($(HARDWARE_MOTHERBOARD),1312)
# Mega controller
-else ifeq ($(HARDWARE_MOTHERBOARD),1217)
-# abee Scoovo X9H
-else ifeq ($(HARDWARE_MOTHERBOARD),1218)
+else ifeq ($(HARDWARE_MOTHERBOARD),1313)
# Geeetech GT2560 Rev B for Mecreator2
-else ifeq ($(HARDWARE_MOTHERBOARD),1219)
+else ifeq ($(HARDWARE_MOTHERBOARD),1314)
# Geeetech GT2560 Rev. A
-else ifeq ($(HARDWARE_MOTHERBOARD),1220)
+else ifeq ($(HARDWARE_MOTHERBOARD),1315)
# Geeetech GT2560 Rev. A+ (with auto level probe)
-else ifeq ($(HARDWARE_MOTHERBOARD),1221)
+else ifeq ($(HARDWARE_MOTHERBOARD),1316)
# Geeetech GT2560 Rev B for A10(M/D)
-else ifeq ($(HARDWARE_MOTHERBOARD),1222)
+else ifeq ($(HARDWARE_MOTHERBOARD),1317)
# Geeetech GT2560 Rev B for A20(M/D)
-else ifeq ($(HARDWARE_MOTHERBOARD),1223)
+else ifeq ($(HARDWARE_MOTHERBOARD),1318)
# Einstart retrofit
-else ifeq ($(HARDWARE_MOTHERBOARD),1224)
+else ifeq ($(HARDWARE_MOTHERBOARD),1319)
+# Wanhao 0ne+ i3 Mini
+else ifeq ($(HARDWARE_MOTHERBOARD),1320)
#
# ATmega1281, ATmega2561
#
-else ifeq ($(HARDWARE_MOTHERBOARD),1300)
+# Minitronics v1.0/1.1
+else ifeq ($(HARDWARE_MOTHERBOARD),1400)
MCU ?= atmega1281
-else ifeq ($(HARDWARE_MOTHERBOARD),1310)
+# Silvergate v1.0
+else ifeq ($(HARDWARE_MOTHERBOARD),1401)
MCU ?= atmega1281
#
@@ -317,43 +343,43 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1310)
#
# Sanguinololu < 1.2
-else ifeq ($(HARDWARE_MOTHERBOARD),1400)
+else ifeq ($(HARDWARE_MOTHERBOARD),1500)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Sanguinololu 1.2 and above
-else ifeq ($(HARDWARE_MOTHERBOARD),1401)
+else ifeq ($(HARDWARE_MOTHERBOARD),1501)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Melzi
-else ifeq ($(HARDWARE_MOTHERBOARD),1402)
+else ifeq ($(HARDWARE_MOTHERBOARD),1502)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Melzi with ATmega1284 (MaKr3d version)
-else ifeq ($(HARDWARE_MOTHERBOARD),1403)
+else ifeq ($(HARDWARE_MOTHERBOARD),1503)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Melzi Creality3D board (for CR-10 etc)
-else ifeq ($(HARDWARE_MOTHERBOARD),1404)
+else ifeq ($(HARDWARE_MOTHERBOARD),1504)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Melzi Malyan M150 board
-else ifeq ($(HARDWARE_MOTHERBOARD),1405)
+else ifeq ($(HARDWARE_MOTHERBOARD),1505)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Tronxy X5S
-else ifeq ($(HARDWARE_MOTHERBOARD),1406)
+else ifeq ($(HARDWARE_MOTHERBOARD),1506)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# STB V1.1
-else ifeq ($(HARDWARE_MOTHERBOARD),1407)
+else ifeq ($(HARDWARE_MOTHERBOARD),1507)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Azteeg X1
-else ifeq ($(HARDWARE_MOTHERBOARD),1408)
+else ifeq ($(HARDWARE_MOTHERBOARD),1508)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
# Anet 1.0 (Melzi clone)
-else ifeq ($(HARDWARE_MOTHERBOARD),1409)
+else ifeq ($(HARDWARE_MOTHERBOARD),1509)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
@@ -362,51 +388,51 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1409)
#
# Gen3 Monolithic Electronics
-else ifeq ($(HARDWARE_MOTHERBOARD),1500)
+else ifeq ($(HARDWARE_MOTHERBOARD),1600)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Gen3+
-else ifeq ($(HARDWARE_MOTHERBOARD),1501)
+else ifeq ($(HARDWARE_MOTHERBOARD),1601)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Gen6
-else ifeq ($(HARDWARE_MOTHERBOARD),1502)
+else ifeq ($(HARDWARE_MOTHERBOARD),1602)
HARDWARE_VARIANT ?= Gen6
MCU ?= atmega644p
# Gen6 deluxe
-else ifeq ($(HARDWARE_MOTHERBOARD),1503)
+else ifeq ($(HARDWARE_MOTHERBOARD),1603)
HARDWARE_VARIANT ?= Gen6
MCU ?= atmega644p
# Gen7 custom (Alfons3 Version)
-else ifeq ($(HARDWARE_MOTHERBOARD),1504)
+else ifeq ($(HARDWARE_MOTHERBOARD),1604)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega644
F_CPU ?= 20000000
# Gen7 v1.1, v1.2
-else ifeq ($(HARDWARE_MOTHERBOARD),1505)
+else ifeq ($(HARDWARE_MOTHERBOARD),1605)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega644p
F_CPU ?= 20000000
# Gen7 v1.3
-else ifeq ($(HARDWARE_MOTHERBOARD),1506)
+else ifeq ($(HARDWARE_MOTHERBOARD),1606)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega644p
F_CPU ?= 20000000
# Gen7 v1.4
-else ifeq ($(HARDWARE_MOTHERBOARD),1507)
+else ifeq ($(HARDWARE_MOTHERBOARD),1607)
HARDWARE_VARIANT ?= Gen7
MCU ?= atmega1284p
F_CPU ?= 20000000
# Alpha OMCA board
-else ifeq ($(HARDWARE_MOTHERBOARD),1508)
+else ifeq ($(HARDWARE_MOTHERBOARD),1608)
HARDWARE_VARIANT ?= SanguinoA
MCU ?= atmega644
# Final OMCA board
-else ifeq ($(HARDWARE_MOTHERBOARD),1509)
+else ifeq ($(HARDWARE_MOTHERBOARD),1609)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
# Sethi 3D_1
-else ifeq ($(HARDWARE_MOTHERBOARD),1510)
+else ifeq ($(HARDWARE_MOTHERBOARD),1610)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
@@ -415,35 +441,35 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1510)
#
# Teensylu
-else ifeq ($(HARDWARE_MOTHERBOARD),1600)
+else ifeq ($(HARDWARE_MOTHERBOARD),1700)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Printrboard (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),1601)
+else ifeq ($(HARDWARE_MOTHERBOARD),1701)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Printrboard Revision F (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),1602)
+else ifeq ($(HARDWARE_MOTHERBOARD),1702)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Brainwave (AT90USB646)
-else ifeq ($(HARDWARE_MOTHERBOARD),1603)
+else ifeq ($(HARDWARE_MOTHERBOARD),1703)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb646
# Brainwave Pro (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),1604)
+else ifeq ($(HARDWARE_MOTHERBOARD),1704)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# SAV Mk-I (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),1605)
+else ifeq ($(HARDWARE_MOTHERBOARD),1705)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# Teensy++2.0 (AT90USB1286)
-else ifeq ($(HARDWARE_MOTHERBOARD),1606)
+else ifeq ($(HARDWARE_MOTHERBOARD),1706)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
# 5DPrint D8 Driver Board
-else ifeq ($(HARDWARE_MOTHERBOARD),1607)
+else ifeq ($(HARDWARE_MOTHERBOARD),1707)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
@@ -674,7 +700,7 @@ CXXSTANDARD = -std=gnu++11
CDEBUG = -g$(DEBUG)
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 -fpack-struct -fno-exceptions \
+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/Version.h b/Marlin/Version.h
new file mode 100644
index 000000000000..d18176f27f74
--- /dev/null
+++ b/Marlin/Version.h
@@ -0,0 +1,76 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+////////////////////////////
+// VENDOR VERSION EXAMPLE //
+////////////////////////////
+
+/**
+ * Marlin release version identifier
+ */
+//#define SHORT_BUILD_VERSION "bugfix-2.0.x"
+
+/**
+ * Verbose version identifier which should contain a reference to the location
+ * from where the binary was downloaded or the source code was compiled.
+ */
+//#define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION " (Github)"
+
+/**
+ * The STRING_DISTRIBUTION_DATE represents when the binary file was built,
+ * here we define this default string as the date where the latest release
+ * version was tagged.
+ */
+//#define STRING_DISTRIBUTION_DATE "2019-07-10"
+
+/**
+ * Defines a generic printer name to be output to the LCD after booting Marlin.
+ */
+//#define MACHINE_NAME "3D Printer"
+
+/**
+ * The SOURCE_CODE_URL is the location where users will find the Marlin Source
+ * Code which is installed on the device. In most cases —unless the manufacturer
+ * has a distinct Github fork— the Source Code URL should just be the main
+ * Marlin repository.
+ */
+//#define SOURCE_CODE_URL "https://github.com/MarlinFirmware/Marlin"
+
+/**
+ * Default generic printer UUID.
+ */
+//#define DEFAULT_MACHINE_UUID "cede2a2f-41a2-4748-9b12-c55c62f367ff"
+
+/**
+ * The WEBSITE_URL is the location where users can get more information such as
+ * documentation about a specific Marlin release.
+ */
+//#define WEBSITE_URL "http://marlinfw.org"
+
+/**
+ * Set the vendor info the serial USB interface, if changable
+ * Currently only supported by DUE platform
+ */
+//#define USB_DEVICE_VENDOR_ID 0x0000
+//#define USB_DEVICE_PRODUCT_ID 0x0000
+//#define USB_DEVICE_MANUFACTURE_NAME WEBSITE_URL
diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h
new file mode 100644
index 000000000000..5ad13931106d
--- /dev/null
+++ b/Marlin/src/HAL/HAL.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
+
+#include "platforms.h"
+
+#include HAL_PATH(.,HAL.h)
+
+#define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
+
+inline void watchdog_refresh() {
+ #if ENABLED(USE_WATCHDOG)
+ HAL_watchdog_refresh();
+ #endif
+}
diff --git a/Marlin/src/HAL/HAL_AVR/HAL.cpp b/Marlin/src/HAL/HAL_AVR/HAL.cpp
index adc441cb61d7..4a10f73dcfab 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL.cpp
@@ -22,64 +22,33 @@
#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(void) {
+void HAL_init() {
// Init Servo Pins
- #if PIN_EXISTS(SERVO0)
- OUT_WRITE(SERVO0_PIN, LOW);
+ #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
+ #if HAS_SERVO_0
+ INIT_SERVO(0);
#endif
- #if PIN_EXISTS(SERVO1)
- OUT_WRITE(SERVO1_PIN, LOW);
+ #if HAS_SERVO_1
+ INIT_SERVO(1);
#endif
- #if PIN_EXISTS(SERVO2)
- OUT_WRITE(SERVO2_PIN, LOW);
+ #if HAS_SERVO_2
+ INIT_SERVO(2);
#endif
- #if PIN_EXISTS(SERVO3)
- OUT_WRITE(SERVO3_PIN, LOW);
+ #if HAS_SERVO_3
+ INIT_SERVO(3);
#endif
}
diff --git a/Marlin/src/HAL/HAL_AVR/HAL.h b/Marlin/src/HAL/HAL_AVR/HAL.h
index 38405e944159..e6d9683675d8 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL.h
+++ b/Marlin/src/HAL/HAL_AVR/HAL.h
@@ -18,33 +18,37 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include
-
#include "../shared/Marduino.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_AVR.h"
-#include "watchdog_AVR.h"
-#include "math_AVR.h"
+#include "fastio.h"
+#include "watchdog.h"
+#include "math.h"
#ifdef USBCON
- #include "HardwareSerial.h"
+ #include
#else
+ #define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion
#include "MarlinSerial.h"
#endif
+#include
#include
#include
#include
#include
#include
-// --------------------------------------------------------------------------
+#ifndef pgm_read_ptr
+ // Compatibility for avr-libc 1.8.0-4.1 included with Ubuntu for
+ // Windows Subsystem for Linux on Windows 10 as of 10/18/2019
+ #define pgm_read_ptr_far(address_long) (void*)__ELPM_word((uint32_t)(address_long))
+ #define pgm_read_ptr_near(address_short) (void*)__LPM_word((uint16_t)(address_short))
+ #define pgm_read_ptr(address_short) pgm_read_ptr_near(address_short)
+#endif
+
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//#define analogInputToDigitalPin(IO) IO
@@ -59,9 +63,9 @@
// 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
@@ -71,9 +75,9 @@ typedef int8_t pin_t;
#define SHARED_SERVOS HAS_SERVOS
#define HAL_SERVO_LIB Servo
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
//extern uint8_t MCUSR;
@@ -105,22 +109,25 @@ typedef int8_t pin_t;
#endif
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-void HAL_init(void);
+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
@@ -147,8 +154,7 @@ extern "C" {
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
-FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
- UNUSED(frequency);
+FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
switch (timer_num) {
case STEP_TIMER_NUM:
// waveform generation = 0100 = CTC
@@ -200,9 +206,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 */ \
@@ -269,13 +275,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 */ \
@@ -335,7 +341,7 @@ void TIMER0_COMPB_vect (void) { \
: \
); \
} \
-void TIMER0_COMPB_vect_bottom(void)
+void TIMER0_COMPB_vect_bottom()
// ADC
#ifdef DIDR2
@@ -344,7 +350,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
@@ -359,6 +365,7 @@ inline void HAL_adc_init(void) {
#define HAL_START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
#endif
+#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() ADC
#define HAL_ADC_READY() !TEST(ADCSRA, ADSC)
diff --git a/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp b/Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
similarity index 90%
rename from Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
index 54825237565f..7a0f7246ee13 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL_SPI.cpp
@@ -31,13 +31,9 @@
#ifdef __AVR__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
-void spiBegin(void) {
+void spiBegin() {
OUT_WRITE(SS_PIN, HIGH);
SET_OUTPUT(SCK_PIN);
SET_INPUT(MISO_PIN);
@@ -57,9 +53,9 @@ void spiBegin(void) {
#if NONE(SOFTWARE_SPI, FORCE_SOFT_SPI)
- //------------------------------------------------------------------------------
+ // ------------------------
// Hardware SPI
- //------------------------------------------------------------------------------
+ // ------------------------
// make sure SPCR rate is in expected bits
#if (SPR0 != 0 || SPR1 != 1)
@@ -85,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;
@@ -181,22 +177,17 @@ void spiBegin(void) {
#else // SOFTWARE_SPI || FORCE_SOFT_SPI
- //------------------------------------------------------------------------------
+ // ------------------------
// Software SPI
- //------------------------------------------------------------------------------
+ // ------------------------
// nop to tune soft SPI timing
#define nop asm volatile ("\tnop\n")
- // Set SPI rate
- void spiInit(uint8_t spiRate) {
- UNUSED(spiRate); // nothing to do
- }
+ void spiInit(uint8_t) { /* do nothing */ }
// Begin SPI transaction, set clock, bit order, data mode
- void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
- UNUSED(spiBeginTransaction); // nothing to do
- }
+ void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) { /* do nothing */ }
// Soft SPI receive byte
uint8_t spiRec() {
diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
index 57c1ed955022..3502aa6b0c36 100644
--- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
+++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
@@ -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 8849212d978d..7560d880e314 100644
--- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
+++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
@@ -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/servo_AVR.cpp b/Marlin/src/HAL/HAL_AVR/Servo.cpp
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/Servo.cpp
index 58e220cbafbe..33818edb96f9 100644
--- a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/Servo.cpp
@@ -131,7 +131,7 @@ void initISR(timer16_Sequence_t timer) {
TCCR1A = 0; // normal counting mode
TCCR1B = _BV(CS11); // set prescaler of 8
TCNT1 = 0; // clear the timer count
- #if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__)
+ #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
SBI(TIFR, OCF1A); // clear any pending interrupts;
SBI(TIMSK, OCIE1A); // enable the output compare interrupt
#else
diff --git a/Marlin/src/HAL/HAL_AVR/ServoTimers.h b/Marlin/src/HAL/HAL_AVR/ServoTimers.h
index 07d307029791..4991caefe6fd 100644
--- a/Marlin/src/HAL/HAL_AVR/ServoTimers.h
+++ b/Marlin/src/HAL/HAL_AVR/ServoTimers.h
@@ -53,8 +53,8 @@
* --------------------
*/
-#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
-#define PRESCALER 8 // timer prescaler
+#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
+#define SERVO_TIMER_PRESCALER 8 // timer prescaler
// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
diff --git a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
index 4446367d15d7..77fa581632ac 100644
--- a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
@@ -36,50 +36,65 @@
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
*/
-#include "../../core/macros.h"
#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)
*
- * These macros for the Arduino MEGA do not include the two connected pins on Port J (D13, D14).
+ * These macros for the Arduino MEGA do not include the two connected pins on Port J (D14, D15).
* So we extend them here because these are the normal pins for Y_MIN and Y_MAX on RAMPS.
* There are more PCI-enabled processor pins on Port J, but they are not connected to Arduino MEGA.
*/
#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
+
+ #define digitalPinHasPCICR(p) (WITHIN(p, 10, 15) || WITHIN(p, 50, 53) || WITHIN(p, 62, 69))
+
#undef digitalPinToPCICR
- #define digitalPinToPCICR(p) ( WITHIN(p, 10, 15) || \
- WITHIN(p, 50, 53) || \
- WITHIN(p, 62, 69) ? &PCICR : nullptr )
+ #define digitalPinToPCICR(p) (digitalPinHasPCICR(p) ? (&PCICR) : nullptr)
+
#undef digitalPinToPCICRbit
- #define digitalPinToPCICRbit(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
- WITHIN(p, 14, 15) ? 1 : \
- WITHIN(p, 62, 69) ? 2 : \
- 0 )
+ #define digitalPinToPCICRbit(p) (WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
+ WITHIN(p, 14, 15) ? 1 : \
+ WITHIN(p, 62, 69) ? 2 : \
+ 0)
+
#undef digitalPinToPCMSK
- #define digitalPinToPCMSK(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
- WITHIN(p, 14, 15) ? &PCMSK1 : \
- WITHIN(p, 62, 69) ? &PCMSK2 : \
- nullptr )
+ #define digitalPinToPCMSK(p) (WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? (&PCMSK0) : \
+ WITHIN(p, 14, 15) ? (&PCMSK1) : \
+ WITHIN(p, 62, 69) ? (&PCMSK2) : \
+ nullptr)
+
#undef digitalPinToPCMSKbit
- #define digitalPinToPCMSKbit(p) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
- (p) == 14 || (p) == 51 ? 2 : \
- (p) == 15 || (p) == 52 ? 1 : \
- (p) == 50 ? 3 : \
- (p) == 53 ? 0 : \
- WITHIN(p, 62, 69) ? ((p) - 62) : \
- 0 )
+ #define digitalPinToPCMSKbit(p) (WITHIN(p, 10, 13) ? ((p) - 6) : \
+ (p) == 14 || (p) == 51 ? 2 : \
+ (p) == 15 || (p) == 52 ? 1 : \
+ (p) == 50 ? 3 : \
+ (p) == 53 ? 0 : \
+ WITHIN(p, 62, 69) ? ((p) - 62) : \
+ 0)
+
+#elif defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__) || defined(__AVR_ATmega324A__) || \
+ defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega324PB__) || \
+ defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || \
+ defined(__AVR_ATmega1284P__)
+
+ #define digitalPinHasPCICR(p) WITHIN(p, 0, NUM_DIGITAL_PINS)
+
+#else
+
+ #error "Unsupported AVR variant!"
+
#endif
// Install Pin change interrupt for a pin. Can be called multiple times.
void pciSetup(const int8_t pin) {
- if (digitalPinToPCMSK(pin) != nullptr) {
+ if (digitalPinHasPCICR(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
@@ -103,154 +118,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), "X_MAX_PIN is not interrupt-capable"); // if pin has no pin change interrupt - error
- pciSetup(X_MAX_PIN); // assign it
+ static_assert(digitalPinHasPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable");
+ pciSetup(X_MAX_PIN);
#endif
#endif
-
#if HAS_X_MIN
#if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(X_MIN_PIN), "X_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(X_MIN_PIN), "X_MIN_PIN is not interrupt-capable");
pciSetup(X_MIN_PIN);
#endif
#endif
-
#if HAS_Y_MAX
#if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Y_MAX_PIN), "Y_MAX_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Y_MAX_PIN), "Y_MAX_PIN is not interrupt-capable");
pciSetup(Y_MAX_PIN);
#endif
#endif
-
#if HAS_Y_MIN
#if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Y_MIN_PIN), "Y_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Y_MIN_PIN), "Y_MIN_PIN is not interrupt-capable");
pciSetup(Y_MIN_PIN);
#endif
#endif
-
#if HAS_Z_MAX
#if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z_MAX_PIN), "Z_MAX_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Z_MAX_PIN), "Z_MAX_PIN is not interrupt-capable");
pciSetup(Z_MAX_PIN);
#endif
#endif
-
#if HAS_Z_MIN
#if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z_MIN_PIN), "Z_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Z_MIN_PIN), "Z_MIN_PIN is not interrupt-capable");
pciSetup(Z_MIN_PIN);
#endif
#endif
-
#if HAS_X2_MAX
#if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X2_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(X2_MAX_PIN), "X2_MAX_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(X2_MAX_PIN), "X2_MAX_PIN is not interrupt-capable");
pciSetup(X2_MAX_PIN);
#endif
#endif
-
#if HAS_X2_MIN
#if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(X2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(X2_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(X2_MIN_PIN), "X2_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(X2_MIN_PIN), "X2_MIN_PIN is not interrupt-capable");
pciSetup(X2_MIN_PIN);
#endif
#endif
-
#if HAS_Y2_MAX
#if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y2_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Y2_MAX_PIN), "Y2_MAX_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Y2_MAX_PIN), "Y2_MAX_PIN is not interrupt-capable");
pciSetup(Y2_MAX_PIN);
#endif
#endif
-
#if HAS_Y2_MIN
#if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Y2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Y2_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Y2_MIN_PIN), "Y2_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Y2_MIN_PIN), "Y2_MIN_PIN is not interrupt-capable");
pciSetup(Y2_MIN_PIN);
#endif
#endif
-
#if HAS_Z2_MAX
#if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z2_MAX_PIN), "Z2_MAX_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Z2_MAX_PIN), "Z2_MAX_PIN is not interrupt-capable");
pciSetup(Z2_MAX_PIN);
#endif
#endif
-
#if HAS_Z2_MIN
#if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z2_MIN_PIN), "Z2_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Z2_MIN_PIN), "Z2_MIN_PIN is not interrupt-capable");
pciSetup(Z2_MIN_PIN);
#endif
#endif
-
#if HAS_Z3_MAX
#if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z3_MAX_PIN), "Z3_MAX_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Z3_MAX_PIN), "Z3_MAX_PIN is not interrupt-capable");
pciSetup(Z3_MAX_PIN);
#endif
#endif
-
#if HAS_Z3_MIN
#if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z3_MIN_PIN), "Z3_MIN_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(Z3_MIN_PIN), "Z3_MIN_PIN is not interrupt-capable");
pciSetup(Z3_MIN_PIN);
#endif
#endif
-
#if HAS_Z_MIN_PROBE_PIN
#if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
- attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#else
- // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
- static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN), "Z_MIN_PROBE_PIN is not interrupt-capable");
+ static_assert(digitalPinHasPCICR(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 7923968fd2ee..4884ede63fbe 100644
--- a/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
+++ b/Marlin/src/HAL/HAL_AVR/fast_pwm.cpp
@@ -23,7 +23,7 @@
#include "../../inc/MarlinConfigPre.h"
-#if ENABLED(FAST_PWM_FAN)
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
#include "HAL.h"
@@ -59,19 +59,19 @@ Timer get_pwm_timer(const pin_t pin) {
#ifdef TCCR2
case TIMER2: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2, nullptr, nullptr},
- /*OCRnQ*/ { (uint16_t*)&OCR2, nullptr, nullptr},
+ /*TCCRnQ*/ { &TCCR2, nullptr, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2, nullptr, nullptr },
/*ICRn*/ nullptr,
/*n, q*/ 2, 0
};
}
- #elif defined TCCR2A
+ #elif defined(TCCR2A)
#if ENABLED(USE_OCR2A_AS_TOP)
case TIMER2A: break; // protect TIMER2A
case TIMER2B: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr},
- /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr},
+ /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
/*ICRn*/ nullptr,
/*n, q*/ 2, 1
};
@@ -81,8 +81,8 @@ Timer get_pwm_timer(const pin_t pin) {
case TIMER2B: ++q;
case TIMER2A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr},
- /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr},
+ /*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
+ /*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
/*ICRn*/ nullptr,
2, q
};
@@ -91,13 +91,24 @@ Timer get_pwm_timer(const pin_t pin) {
#endif
#endif
#endif
- #ifdef TCCR3A
+ #ifdef OCR3C
case TIMER3C: ++q;
case TIMER3B: ++q;
case TIMER3A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR3A, &TCCR3B, &TCCR3C},
- /*OCRnQ*/ { &OCR3A, &OCR3B, &OCR3C},
+ /*TCCRnQ*/ { &TCCR3A, &TCCR3B, &TCCR3C },
+ /*OCRnQ*/ { &OCR3A, &OCR3B, &OCR3C },
+ /*ICRn*/ &ICR3,
+ /*n, q*/ 3, q
+ };
+ return timer;
+ }
+ #elif defined(OCR3B)
+ case TIMER3B: ++q;
+ case TIMER3A: {
+ Timer timer = {
+ /*TCCRnQ*/ { &TCCR3A, &TCCR3B, nullptr },
+ /*OCRnQ*/ { &OCR3A, &OCR3B, nullptr },
/*ICRn*/ &ICR3,
/*n, q*/ 3, q
};
@@ -109,8 +120,8 @@ Timer get_pwm_timer(const pin_t pin) {
case TIMER4B: ++q;
case TIMER4A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C},
- /*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C},
+ /*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C },
+ /*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C },
/*ICRn*/ &ICR4,
/*n, q*/ 4, q
};
@@ -122,7 +133,7 @@ Timer get_pwm_timer(const pin_t pin) {
case TIMER5B: ++q;
case TIMER5A: {
Timer timer = {
- /*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C},
+ /*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C },
/*OCRnQ*/ { &OCR5A, &OCR5B, &OCR5C },
/*ICRn*/ &ICR5,
/*n, q*/ 5, q
@@ -132,8 +143,8 @@ Timer get_pwm_timer(const pin_t pin) {
#endif
}
Timer timer = {
- /*TCCRnQ*/ { nullptr, nullptr, nullptr},
- /*OCRnQ*/ { nullptr, nullptr, nullptr},
+ /*TCCRnQ*/ { nullptr, nullptr, nullptr },
+ /*OCRnQ*/ { nullptr, nullptr, nullptr },
/*ICRn*/ nullptr,
0, 0
};
@@ -267,5 +278,5 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
}
}
-#endif // FAST_PWM_FAN
+#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
#endif // __AVR__
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AVR.cpp b/Marlin/src/HAL/HAL_AVR/fastio.cpp
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/fastio.cpp
index 8f79555f691e..f0f7688f1b06 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/fastio.cpp
@@ -26,7 +26,7 @@
#ifdef __AVR__
-#include "fastio_AVR.h"
+#include "fastio.h"
#ifdef FASTIO_EXT_START
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h b/Marlin/src/HAL/HAL_AVR/fastio.h
similarity index 98%
rename from Marlin/src/HAL/HAL_AVR/fastio_AVR.h
rename to Marlin/src/HAL/HAL_AVR/fastio.h
index 1f2e820bdcfe..501a7cdf0616 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio.h
@@ -27,8 +27,6 @@
* Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
*/
-#include "../../core/macros.h"
-
#include
#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__))
@@ -41,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
@@ -274,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
*/
@@ -337,6 +337,8 @@ enum ClockSource2 : char {
#define PWM_CHK(P) (PWM_CHK_HEATER(P) || PWM_CHK_SERVO(P) || PWM_CHK_MOTOR_CURRENT(P) || PWM_CHK_FAN_A(P) || PWM_CHK_FAN_B(P))
+#endif // PWM_CHK is not used in Marlin
+
// define which hardware PWMs are available for the current CPU
// all timer 1 PWMS deleted from this list because they are never available
#if AVR_ATmega2560_FAMILY
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_1280.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_1280.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
index 84ceffcda04c..62de534d5371 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_1280.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1280.h
@@ -29,7 +29,7 @@
* Logical Pin : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 78 79 80 xx xx 84 85 71 70 xx xx xx xx xx 81 82 83 xx xx 72 72 75 76 77 74 xx xx xx xx xx
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
// change for your board
#define DEBUG_LED DIO21
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_1281.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_1281.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
index 153d1fd7d2e8..e3d2f12851b9 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_1281.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_1281.h
@@ -28,7 +28,7 @@
* Port: A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7 E0 E1 E2 E3 E4 E5 E6 E7 F0 F1 F2 F3 F4 F5 F6 F7 G0 G1 G2 G3 G4 G5
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
// change for your board
#define DEBUG_LED DIO46
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_168.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_168.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
index 7e5a1ec79510..f6ee7a5d0016 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_168.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_168.h
@@ -28,7 +28,7 @@
* Port: B0 B1 B2 B3 B4 B5 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
#define DEBUG_LED AIO5
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_644.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_644.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
index f62a0a35b4b3..180a3c4e3202 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_644.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_644.h
@@ -54,7 +54,7 @@
* +--------+
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
#define DEBUG_LED DIO0
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h b/Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h
rename to Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
index c7bf5f6b5a2f..3f17a2e26109 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio/fastio_AT90USB.h
@@ -29,7 +29,7 @@
* The logical pins 46 and 47 are not supported by Teensyduino, but are supported below as E2 and E3
*/
-#include "fastio_AVR.h"
+#include "../fastio.h"
// change for your board
#define DEBUG_LED DIO31 /* led D5 red */
diff --git a/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
similarity index 91%
rename from Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h
rename to Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
index cc02fda24f41..85f26f40162e 100644
--- a/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.h
+++ b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_LCD.h
@@ -20,8 +20,3 @@
*
*/
#pragma once
-
-extern IWDG_HandleTypeDef hiwdg;
-
-void watchdog_init();
-void watchdog_reset();
diff --git a/Marlin/src/HAL/HAL_AVR/inc/Conditionals_adv.h b/Marlin/src/HAL/HAL_AVR/inc/Conditionals_adv.h
new file mode 100644
index 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/SanityCheck.h b/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h
similarity index 100%
rename from Marlin/src/HAL/HAL_AVR/SanityCheck.h
rename to Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h
diff --git a/Marlin/src/HAL/HAL_AVR/math_AVR.h b/Marlin/src/HAL/HAL_AVR/math.h
similarity index 100%
rename from Marlin/src/HAL/HAL_AVR/math_AVR.h
rename to Marlin/src/HAL/HAL_AVR/math.h
diff --git a/Marlin/src/HAL/HAL_AVR/pinsDebug.h b/Marlin/src/HAL/HAL_AVR/pinsDebug.h
index 4737c3517a87..e4738e0332e9 100644
--- a/Marlin/src/HAL/HAL_AVR/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_AVR/pinsDebug.h
@@ -227,18 +227,9 @@ static void print_is_also_tied() { SERIAL_ECHOPGM(" is also tied to this pin");
void com_print(uint8_t N, uint8_t Z) {
const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
SERIAL_ECHOPGM(" COM");
- SERIAL_CHAR(N + '0');
- switch (Z) {
- case 'A':
- SERIAL_ECHOPAIR("A: ", ((*TCCRA & (_BV(7) | _BV(6))) >> 6));
- break;
- case 'B':
- SERIAL_ECHOPAIR("B: ", ((*TCCRA & (_BV(5) | _BV(4))) >> 4));
- break;
- case 'C':
- SERIAL_ECHOPAIR("C: ", ((*TCCRA & (_BV(3) | _BV(2))) >> 2));
- break;
- }
+ SERIAL_CHAR('0' + N);
+ SERIAL_CHAR('A' + Z);
+ SERIAL_ECHOPAIR(": ", int((*TCCRA >> (6 - Z * 2)) & 0x03));
}
void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N - WGM bit layout
@@ -353,6 +344,8 @@ static void pwm_details(uint8_t pin) {
timer_prefix(0, 'A', 3);
#endif
}
+ #else
+ UNUSED(print_is_also_tied);
#endif
} // pwm_details
@@ -400,4 +393,4 @@ static void pwm_details(uint8_t pin) {
#endif
-#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer);} while (0)
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
diff --git a/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h b/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
index 2a2a7bce8a86..e5bb82f226b5 100644
--- a/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
+++ b/Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
@@ -47,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
@@ -140,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
@@ -234,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/watchdog_AVR.cpp b/Marlin/src/HAL/HAL_AVR/watchdog.cpp
similarity index 99%
rename from Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
rename to Marlin/src/HAL/HAL_AVR/watchdog.cpp
index 3ea44e7dce76..63a503196631 100644
--- a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/watchdog.cpp
@@ -26,7 +26,7 @@
#if ENABLED(USE_WATCHDOG)
-#include "watchdog_AVR.h"
+#include "watchdog.h"
#include "../../Marlin.h"
diff --git a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.h b/Marlin/src/HAL/HAL_AVR/watchdog.h
similarity index 95%
rename from Marlin/src/HAL/HAL_AVR/watchdog_AVR.h
rename to Marlin/src/HAL/HAL_AVR/watchdog.h
index 5190d2c55af5..efd725d7d7a3 100644
--- a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/watchdog.h
@@ -28,4 +28,4 @@ void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or AVR will go into emergency procedures.
-inline void watchdog_reset() { wdt_reset(); }
+inline void HAL_watchdog_refresh() { wdt_reset(); }
diff --git a/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp b/Marlin/src/HAL/HAL_DUE/DebugMonitor.cpp
similarity index 95%
rename from Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/DebugMonitor.cpp
index 3b68faac1523..20f10ce40530 100644
--- a/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/DebugMonitor.cpp
@@ -42,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 );
@@ -235,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")
@@ -248,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")
@@ -261,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")
@@ -274,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")
@@ -287,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")
@@ -300,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")
@@ -314,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")
@@ -327,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 73421c3a37d2..c7b7007053ac 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) && NONE(I2C_EEPROM, SPI_EEPROM)
#include "../shared/Marduino.h"
+#include "../shared/persistent_store_api.h"
#define EEPROMSize 4096
#define PagesPerGroup 128
@@ -922,8 +922,7 @@ static void ee_Init() {
if (!ee_IsPageClean(grp * PagesPerGroup + page)) {
#ifdef EE_EMU_DEBUG
SERIAL_ECHO_START();
- SERIAL_ECHOPAIR("EEPROM Page ",page);
- SERIAL_ECHOLNPAIR(" not clean on group ",grp);
+ SERIAL_ECHOLNPAIR("EEPROM Page ", page, " not clean on group ", grp);
SERIAL_FLUSH();
#endif
ee_PageErase(grp * PagesPerGroup + page);
@@ -944,7 +943,7 @@ static void ee_Init() {
#ifdef EE_EMU_DEBUG
SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Active page: ",curPage);
+ SERIAL_ECHOLNPAIR("EEPROM Active page: ", curPage);
SERIAL_FLUSH();
#endif
@@ -953,8 +952,7 @@ static void ee_Init() {
if (!ee_IsPageClean(curGroup * PagesPerGroup + page)) {
#ifdef EE_EMU_DEBUG
SERIAL_ECHO_START();
- SERIAL_ECHOPAIR("EEPROM Page ",page);
- SERIAL_ECHOLNPAIR(" not clean on active group ",curGroup);
+ SERIAL_ECHOLNPAIR("EEPROM Page ", page, " not clean on active group ", curGroup);
SERIAL_FLUSH();
ee_Dump(curGroup * PagesPerGroup + page, getFlashStorage(curGroup * PagesPerGroup + page));
#endif
@@ -993,7 +991,7 @@ void eeprom_read_block(void* __dst, const void* __src, size_t __n) {
}
}
-void eeprom_flush(void) {
+void eeprom_flush() {
ee_Flush();
}
diff --git a/Marlin/src/HAL/HAL_DUE/HAL.cpp b/Marlin/src/HAL/HAL_DUE/HAL.cpp
index dfe42f6ca307..130779896d3c 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL.cpp
+++ b/Marlin/src/HAL/HAL_DUE/HAL.cpp
@@ -25,56 +25,24 @@
#ifdef ARDUINO_ARCH_SAM
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include
#include "usb/usb_task.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// HAL initialization task
-void HAL_init(void) {
+void HAL_init() {
// Initialize the USB stack
#if ENABLED(SDSUPPORT)
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
@@ -83,20 +51,20 @@ void HAL_init(void) {
}
// HAL idle task
-void HAL_idletask(void) {
+void HAL_idletask() {
// Perform USB stack housekeeping
usb_task_idle();
}
// Disable interrupts
-void cli(void) { noInterrupts(); }
+void cli() { noInterrupts(); }
// Enable interrupts
-void sei(void) { interrupts(); }
+void sei() { interrupts(); }
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
-uint8_t HAL_get_reset_source(void) {
+uint8_t HAL_get_reset_source() {
switch ((RSTC->RSTC_SR >> 8) & 0x07) {
case 0: return RST_POWER_ON;
case 1: return RST_BACKUP;
@@ -119,18 +87,18 @@ extern "C" {
// Return free memory between end of heap (or end bss) and whatever is current
int freeMemory() {
int free_memory, heap_end = (int)_sbrk(0);
- return (int)&free_memory - (heap_end ? heap_end : (int)&_ebss);
+ return (int)&free_memory - (heap_end ?: (int)&_ebss);
}
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_adc_start_conversion(const uint8_t adc_pin) {
HAL_adc_result = analogRead(adc_pin);
}
-uint16_t HAL_adc_get_result(void) {
+uint16_t HAL_adc_get_result() {
// nop
return HAL_adc_result;
}
diff --git a/Marlin/src/HAL/HAL_DUE/HAL.h b/Marlin/src/HAL/HAL_DUE/HAL.h
index 943076973428..64cff24665c2 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL.h
+++ b/Marlin/src/HAL/HAL_DUE/HAL.h
@@ -32,34 +32,51 @@
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_Due.h"
-#include "watchdog_Due.h"
-#include "HAL_timers_Due.h"
+#include "fastio.h"
+#include "watchdog.h"
+#include "timers.h"
#include
-// Serial ports
-#if !WITHIN(SERIAL_PORT, -1, 3)
- #error "SERIAL_PORT must be from -1 to 3"
+// Define MYSERIAL0/1 before MarlinSerial includes!
+#if SERIAL_PORT == -1
+ #define MYSERIAL0 customizedSerial1
+#elif SERIAL_PORT == 0
+ #define MYSERIAL0 Serial
+#elif SERIAL_PORT == 1
+ #define MYSERIAL0 Serial1
+#elif SERIAL_PORT == 2
+ #define MYSERIAL0 Serial2
+#elif SERIAL_PORT == 3
+ #define MYSERIAL0 Serial3
+#else
+ #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
-// MYSERIAL0 required before MarlinSerial includes!
-#define MYSERIAL0 customizedSerial1
-
#ifdef SERIAL_PORT_2
- #if !WITHIN(SERIAL_PORT_2, -1, 3)
- #error "SERIAL_PORT_2 must be from -1 to 3"
- #elif SERIAL_PORT_2 == SERIAL_PORT
- #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
+ #if SERIAL_PORT_2 == SERIAL_PORT
+ #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration."
+ #endif
+ #if SERIAL_PORT_2 == -1
+ #define MYSERIAL1 customizedSerial2
+ #elif SERIAL_PORT_2 == 0
+ #define MYSERIAL1 Serial
+ #elif SERIAL_PORT_2 == 1
+ #define MYSERIAL1 Serial1
+ #elif SERIAL_PORT_2 == 2
+ #define MYSERIAL1 Serial2
+ #elif SERIAL_PORT_2 == 3
+ #define MYSERIAL1 Serial3
+ #else
+ #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif
#define NUM_SERIAL 2
- #define MYSERIAL1 customizedSerial2
#else
#define NUM_SERIAL 1
#endif
-#include "MarlinSerial_Due.h"
-#include "MarlinSerialUSB_Due.h"
+#include "MarlinSerial.h"
+#include "MarlinSerialUSB.h"
// On AVR this is in math.h?
#define square(x) ((x)*(x))
@@ -68,10 +85,6 @@
#define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
#endif
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
// Fix bug in pgm_read_ptr
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*((void**)(addr)))
@@ -92,22 +105,11 @@ typedef int8_t pin_t;
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()
-void cli(void); // Disable interrupts
-void sei(void); // Enable interrupts
+void cli(); // Disable interrupts
+void sei(); // Enable interrupts
-void HAL_clear_reset_source(void); // clear reset reason
-uint8_t HAL_get_reset_source(void); // get reset reason
-
-//
-// SPI: Extended functions taking a channel number (Hardware SPI only)
-//
-
-// Write single byte to specified SPI channel
-void spiSend(uint32_t chan, byte b);
-// Write buffer to specified SPI channel
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-// Read single byte from specified SPI channel
-uint8_t spiRec(uint32_t chan);
+void HAL_clear_reset_source(); // clear reset reason
+uint8_t HAL_get_reset_source(); // get reset reason
//
// EEPROM
@@ -128,14 +130,15 @@ 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_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
//
// Pin Map
@@ -153,19 +156,23 @@ void noTone(const pin_t _pin);
// Enable hooks into idle and setup for HAL
#define HAL_IDLETASK 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 97%
rename from Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/HAL_SPI.cpp
index 82eae9b01e0d..35763a5ec713 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/HAL_SPI.cpp
@@ -37,27 +37,18 @@
#ifdef ARDUINO_ARCH_SAM
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include "../shared/Delay.h"
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if EITHER(DUE_SOFTWARE_SPI, FORCE_SOFT_SPI)
- // --------------------------------------------------------------------------
- // software SPI
- // --------------------------------------------------------------------------
+ // ------------------------
+ // Software SPI
+ // ------------------------
// Make sure GCC optimizes this file.
// Note that this line triggers a bug in GCC which is fixed by casting.
@@ -160,13 +151,12 @@
(((uint32_t)(addr) & 0xF0000000) + 0x02000000 + ((uint32_t)(addr)&0xFFFFF)*32 + (bit)*4)
// run at ~8 .. ~10Mhz - Rx version (Tx line not altered)
- static uint8_t spiTransferRx0(uint8_t bout) { // using Mode 0
+ static uint8_t spiTransferRx0(uint8_t) { // using Mode 0
uint32_t bin = 0;
uint32_t work = 0;
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(MISO_PIN))+0x3C, PIN_SHIFT(MISO_PIN)); /* PDSR of port in bitband area */
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SCK_PIN)) + 0x30; /* SODR of port */
uint32_t SCK_MASK = PIN_MASK(SCK_PIN);
- UNUSED(bout);
/* The software SPI routine */
__asm__ __volatile__(
@@ -437,7 +427,7 @@
static void spiTxBlockX(const uint8_t* buf, uint32_t todo) {
do {
- (void) spiTransferTx(*buf++);
+ (void)spiTransferTx(*buf++);
} while (--todo);
}
@@ -551,9 +541,9 @@
// slave selects controlled by SPI controller
// doesn't support changing SPI speeds for SD card
- // --------------------------------------------------------------------------
+ // ------------------------
// hardware SPI
- // --------------------------------------------------------------------------
+ // ------------------------
static bool spiInitialized = false;
void spiInit(uint8_t spiRate) {
diff --git a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp b/Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
similarity index 97%
rename from Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
index c92736f69edc..b9f14823f68c 100644
--- a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
@@ -34,7 +34,7 @@
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "InterruptVectors_Due.h"
+#include "InterruptVectors.h"
/* The relocated Exception/Interrupt Table - According to the ARM
reference manual, alignment to 128 bytes should suffice, but in
@@ -48,7 +48,7 @@ static DeviceVectors ram_tab = { nullptr };
* If it is not, then it copies the ROM table to the SRAM and relocates the table
* by reprogramming the NVIC registers
*/
-static pfnISR_Handler* get_relocated_table_addr(void) {
+static pfnISR_Handler* get_relocated_table_addr() {
// Get the address of the interrupt/exception table
uint32_t isrtab = SCB->VTOR;
diff --git a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.h b/Marlin/src/HAL/HAL_DUE/InterruptVectors.h
similarity index 97%
rename from Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.h
rename to Marlin/src/HAL/HAL_DUE/InterruptVectors.h
index 592fb2f4cf5f..87dd04962496 100644
--- a/Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/InterruptVectors.h
@@ -37,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 98%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/MarlinSerial.cpp
index db5c93d8b451..7b88b6d43e14 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial.cpp
@@ -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 96%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h
rename to Marlin/src/HAL/HAL_DUE/MarlinSerial.h
index 1ba8d82df8f2..92806f15b405 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial.h
@@ -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 92%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.cpp
index 58cc8460029d..f7f48d5f4246 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.cpp
@@ -31,7 +31,7 @@
#if SERIAL_PORT == -1
-#include "MarlinSerialUSB_Due.h"
+#include "MarlinSerialUSB.h"
#if ENABLED(EMERGENCY_PARSER)
#include "../../feature/emergency_parser.h"
@@ -39,11 +39,11 @@
// Imports from Atmel USB Stack/CDC implementation
extern "C" {
- bool usb_task_cdc_isenabled(void);
- bool usb_task_cdc_dtr_active(void);
- bool udi_cdc_is_rx_ready(void);
- int udi_cdc_getc(void);
- bool udi_cdc_is_tx_ready(void);
+ bool usb_task_cdc_isenabled();
+ bool usb_task_cdc_dtr_active();
+ bool udi_cdc_is_rx_ready();
+ int udi_cdc_getc();
+ bool udi_cdc_is_tx_ready();
int udi_cdc_putc(int value);
};
@@ -55,14 +55,11 @@ static int pending_char = -1;
#endif
// Public Methods
-void MarlinSerialUSB::begin(const long baud_setting) {
- UNUSED(baud_setting);
-}
+void MarlinSerialUSB::begin(const long) {}
-void MarlinSerialUSB::end() {
-}
+void MarlinSerialUSB::end() {}
-int MarlinSerialUSB::peek(void) {
+int MarlinSerialUSB::peek() {
if (pending_char >= 0)
return pending_char;
@@ -83,7 +80,7 @@ int MarlinSerialUSB::peek(void) {
return pending_char;
}
-int MarlinSerialUSB::read(void) {
+int MarlinSerialUSB::read() {
if (pending_char >= 0) {
int ret = pending_char;
pending_char = -1;
@@ -107,7 +104,7 @@ int MarlinSerialUSB::read(void) {
return c;
}
-bool MarlinSerialUSB::available(void) {
+bool MarlinSerialUSB::available() {
/* If Pending chars */
return pending_char >= 0 ||
/* or USB CDC enumerated and configured on the PC side and some
@@ -115,8 +112,8 @@ bool MarlinSerialUSB::available(void) {
(usb_task_cdc_isenabled() && udi_cdc_is_rx_ready());
}
-void MarlinSerialUSB::flush(void) { }
-void MarlinSerialUSB::flushTX(void) { }
+void MarlinSerialUSB::flush() { }
+void MarlinSerialUSB::flushTX() { }
void MarlinSerialUSB::write(const uint8_t c) {
@@ -186,7 +183,7 @@ void MarlinSerialUSB::print(double n, int digits) {
printFloat(n, digits);
}
-void MarlinSerialUSB::println(void) {
+void MarlinSerialUSB::println() {
print('\r');
print('\n');
}
diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.h
similarity index 94%
rename from Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h
rename to Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.h
index cc63232f29a1..3d9d4bafaadb 100644
--- a/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/MarlinSerialUSB.h
@@ -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 89%
rename from Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/Servo.cpp
index 2dd9d4c45efc..f48fdf57966c 100644
--- a/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/Servo.cpp
@@ -50,25 +50,25 @@
static volatile int8_t Channel[_Nbr_16timers]; // counter for the servo being pulsed for each timer (or -1 if refresh interval)
-//------------------------------------------------------------------------------
+// ------------------------
/// Interrupt handler for the TC0 channel 1.
-//------------------------------------------------------------------------------
+// ------------------------
void Servo_Handler(timer16_Sequence_t timer, Tc *pTc, uint8_t channel);
#ifdef _useTimer1
- void HANDLER_FOR_TIMER1(void) { Servo_Handler(_timer1, TC_FOR_TIMER1, CHANNEL_FOR_TIMER1); }
+ void HANDLER_FOR_TIMER1() { Servo_Handler(_timer1, TC_FOR_TIMER1, CHANNEL_FOR_TIMER1); }
#endif
#ifdef _useTimer2
- void HANDLER_FOR_TIMER2(void) { Servo_Handler(_timer2, TC_FOR_TIMER2, CHANNEL_FOR_TIMER2); }
+ void HANDLER_FOR_TIMER2() { Servo_Handler(_timer2, TC_FOR_TIMER2, CHANNEL_FOR_TIMER2); }
#endif
#ifdef _useTimer3
- void HANDLER_FOR_TIMER3(void) { Servo_Handler(_timer3, TC_FOR_TIMER3, CHANNEL_FOR_TIMER3); }
+ void HANDLER_FOR_TIMER3() { Servo_Handler(_timer3, TC_FOR_TIMER3, CHANNEL_FOR_TIMER3); }
#endif
#ifdef _useTimer4
- void HANDLER_FOR_TIMER4(void) { Servo_Handler(_timer4, TC_FOR_TIMER4, CHANNEL_FOR_TIMER4); }
+ void HANDLER_FOR_TIMER4() { Servo_Handler(_timer4, TC_FOR_TIMER4, CHANNEL_FOR_TIMER4); }
#endif
#ifdef _useTimer5
- void HANDLER_FOR_TIMER5(void) { Servo_Handler(_timer5, TC_FOR_TIMER5, CHANNEL_FOR_TIMER5); }
+ void HANDLER_FOR_TIMER5() { Servo_Handler(_timer5, TC_FOR_TIMER5, CHANNEL_FOR_TIMER5); }
#endif
void Servo_Handler(timer16_Sequence_t timer, Tc *tc, uint8_t channel) {
@@ -137,7 +137,7 @@ void initISR(timer16_Sequence_t timer) {
#endif
}
-void finISR(timer16_Sequence_t timer) {
+void finISR(timer16_Sequence_t) {
#ifdef _useTimer1
TC_Stop(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1);
#endif
diff --git a/Marlin/src/HAL/HAL_DUE/ServoTimers.h b/Marlin/src/HAL/HAL_DUE/ServoTimers.h
index 84129ef2b619..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
diff --git a/Marlin/src/HAL/HAL_DUE/Tone.cpp b/Marlin/src/HAL/HAL_DUE/Tone.cpp
index f7549c4472ae..2af97aac611f 100644
--- a/Marlin/src/HAL/HAL_DUE/Tone.cpp
+++ b/Marlin/src/HAL/HAL_DUE/Tone.cpp
@@ -5,6 +5,8 @@
* Based on Sprinter and grbl.
* 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
* the Free Software Foundation, either version 3 of the License, or
@@ -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 65%
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 f90d24dae0bb..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
@@ -21,58 +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"
+#include "../../../Marlin.h"
void spiBegin();
void spiInit(uint8_t spiRate);
void spiSend(uint8_t b);
void spiSend(const uint8_t* buf, size_t n);
-#include "../shared/Marduino.h"
-#include "fastio_Due.h"
+#include "../../shared/Marduino.h"
+#include "../fastio.h"
void u8g_SetPIOutput_DUE_hw_spi(u8g_t *u8g, uint8_t pin_index) {
PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
similarity index 97%
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 8af460954aa5..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
@@ -55,11 +55,11 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
#if ENABLED(U8GLIB_ST7920)
-#include "../shared/Delay.h"
+#include "../../shared/Delay.h"
#include
@@ -145,8 +145,8 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
}
#if ENABLED(LIGHTWEIGHT_UI)
- #include "../../lcd/ultralcd.h"
- #include "../shared/HAL_ST7920.h"
+ #include "../../../lcd/ultralcd.h"
+ #include "../../shared/HAL_ST7920.h"
#define ST7920_CS_PIN LCD_PINS_RS
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
similarity index 97%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi.cpp
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
index c7929c5c140e..e078bc420f57 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi.cpp
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
@@ -55,7 +55,7 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
@@ -64,8 +64,8 @@
#include "u8g_com_HAL_DUE_sw_spi_shared.h"
-#include "../shared/Marduino.h"
-#include "../shared/Delay.h"
+#include "../../shared/Marduino.h"
+#include "../../shared/Delay.h"
#include
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
similarity index 98%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
index 673ef4fac266..d3609f60ef12 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
@@ -55,11 +55,11 @@
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
+#include "../../../inc/MarlinConfigPre.h"
#if HAS_GRAPHICAL_LCD
-#include "../shared/Delay.h"
+#include "../../shared/Delay.h"
#include
diff --git a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.h b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
similarity index 92%
rename from Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.h
rename to Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
index a7e2432d9840..b83247415033 100644
--- a/Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.h
+++ b/Marlin/src/HAL/HAL_DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
@@ -21,8 +21,9 @@
*/
#pragma once
-#include "../../inc/MarlinConfigPre.h"
-#include "../shared/Marduino.h"
+#include "../../../inc/MarlinConfigPre.h"
+#include "../../shared/Marduino.h"
+#include
void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index);
void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level);
diff --git a/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h b/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
index d97b8453cc1f..daa2b3c15e9c 100644
--- a/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_DUE/endstop_interrupts.h
@@ -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 99%
rename from Marlin/src/HAL/HAL_DUE/fastio_Due.h
rename to Marlin/src/HAL/HAL_DUE/fastio.h
index e44d1d1ee642..a97a944e33f1 100644
--- a/Marlin/src/HAL/HAL_DUE/fastio_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/fastio.h
@@ -39,6 +39,8 @@
#include
+#include "../../inc/MarlinConfigPre.h"
+
/**
* Utility functions
*/
@@ -68,14 +70,14 @@
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{ \
diff --git a/Marlin/src/HAL/HAL_DUE/G2_PWM.cpp b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.cpp
similarity index 99%
rename from Marlin/src/HAL/HAL_DUE/G2_PWM.cpp
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.cpp
index 1e08332a4e59..4afd83ad4bdc 100644
--- a/Marlin/src/HAL/HAL_DUE/G2_PWM.cpp
+++ b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.cpp
@@ -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 97%
rename from Marlin/src/HAL/HAL_DUE/G2_PWM.h
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.h
index 8086648bcffd..4a84dfe64a7b 100644
--- a/Marlin/src/HAL/HAL_DUE/G2_PWM.h
+++ b/Marlin/src/HAL/HAL_DUE/fastio/G2_PWM.h
@@ -26,8 +26,8 @@
* 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 100%
rename from Marlin/src/HAL/HAL_DUE/G2_pins.h
rename to Marlin/src/HAL/HAL_DUE/fastio/G2_pins.h
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 100%
rename from Marlin/src/HAL/HAL_DUE/SanityCheck.h
rename to Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h
diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
index 4814620b9e38..fc1baa22ac8b 100644
--- a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
@@ -29,11 +29,11 @@
#include "../../inc/MarlinConfig.h"
#include "../shared/persistent_store_api.h"
-#if NONE(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; }
diff --git a/Marlin/src/HAL/HAL_DUE/pinsDebug.h b/Marlin/src/HAL/HAL_DUE/pinsDebug.h
index 23677960f010..ed78f8adbb6b 100644
--- a/Marlin/src/HAL/HAL_DUE/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_DUE/pinsDebug.h
@@ -62,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/HAL_timers_Due.cpp b/Marlin/src/HAL/HAL_DUE/timers.cpp
similarity index 70%
rename from Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/timers.cpp
index df51c22d6016..6925f93498bb 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/timers.cpp
@@ -28,42 +28,29 @@
#ifdef ARDUINO_ARCH_SAM
-// --------------------------------------------------------------------------
+// ------------------------
// Includes
-// --------------------------------------------------------------------------
+// ------------------------
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "HAL_timers_Due.h"
+#include "timers.h"
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define NUM_HARDWARE_TIMERS 9
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TC0, 0, TC0_IRQn, 3}, // 0 - [servo timer5]
{ TC0, 1, TC1_IRQn, 0}, // 1
{ TC0, 2, TC2_IRQn, 2}, // 2 - stepper
- { TC1, 0, TC3_IRQn, 0}, // 3
+ { TC1, 0, TC3_IRQn, 0}, // 3 - stepper for BOARD_ARCHIM1
{ TC1, 1, TC4_IRQn, 15}, // 4 - temperature
{ TC1, 2, TC5_IRQn, 3}, // 5 - [servo timer3]
{ TC2, 0, TC6_IRQn, 14}, // 6 - tone
@@ -71,17 +58,9 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TC2, 2, TC8_IRQn, 0}, // 8
};
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
/*
Timer_clock1: Prescaler 2 -> 42MHz
diff --git a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h b/Marlin/src/HAL/HAL_DUE/timers.h
similarity index 82%
rename from Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
rename to Marlin/src/HAL/HAL_DUE/timers.h
index 2c758f3a1195..b7b2cf7341e0 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/timers.h
@@ -26,15 +26,11 @@
* For ARDUINO_ARCH_SAM
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -43,7 +39,9 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
+#ifndef STEP_TIMER_NUM
#define STEP_TIMER_NUM 2 // index of timer to use for stepper
+#endif
#define TEMP_TIMER_NUM 4 // index of timer to use for temperature
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
@@ -65,13 +63,15 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() void TC2_Handler()
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() void TC2_Handler()
+#endif
#define HAL_TEMP_TIMER_ISR() void TC4_Handler()
#define HAL_TONE_TIMER_ISR() void TC6_Handler()
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
Tc *pTimerRegs;
@@ -80,15 +80,15 @@ typedef struct {
uint8_t priority;
} tTimerConfig;
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
extern const tTimerConfig TimerConfig[];
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
diff --git a/Marlin/src/HAL/HAL_DUE/usb/compiler.h b/Marlin/src/HAL/HAL_DUE/usb/compiler.h
index d9ecd3f0fef9..33df080e2f89 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,9 +443,9 @@ typedef struct
#define DISABLE 0
#define ENABLE 1
#ifndef __cplusplus
-#if !defined(__bool_true_false_are_defined)
-#define false 0
-#define true 1
+#ifndef __bool_true_false_are_defined
+#define false (1==0)
+#define true (1==1)
#endif
#endif
#ifndef PASS
@@ -998,14 +998,14 @@ typedef U8 Byte; //!< 8-bit unsigned integer.
#endif // #ifndef __ASSEMBLY__
-#if defined(__ICCARM__)
+#ifdef __ICCARM__
#define SHORTENUM __packed
#elif defined(__GNUC__)
#define SHORTENUM __attribute__((packed))
#endif
/* No operation */
-#if defined(__ICCARM__)
+#ifdef __ICCARM__
#define nop() __no_operation()
#elif defined(__GNUC__)
#define nop() (__NOP())
diff --git a/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h b/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h
index 6934494e57de..8d5924d375e8 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/conf_usb.h
@@ -48,9 +48,7 @@
#define _CONF_USB_H_
#undef UNUSED /* To avoid a macro clash as macros.h already defines it */
-#include "../../../core/macros.h" /* For ENABLED()/DISABLED() */
-#include "../../../core/boards.h" /* For MB() */
-#include "../../../../Configuration.h" /* For CUSTOM_MACHINE_NAME definition - We just need the name, no C++ allowed! */
+#include "../../../inc/MarlinConfigPre.h"
#include "compiler.h"
/**
@@ -59,8 +57,6 @@
*/
//! Device definition (mandatory)
-#define USB_DEVICE_VENDOR_ID 0x03EB /* ATMEL VID */
-#define USB_DEVICE_PRODUCT_ID 0x2424 /* MSC / CDC */
#define USB_DEVICE_MAJOR_VERSION 1
#define USB_DEVICE_MINOR_VERSION 0
#define USB_DEVICE_POWER 100 // Consumption on Vbus line (mA)
@@ -70,15 +66,6 @@
// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED)
// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
-//! USB Device string definitions (Optional)
-#define USB_DEVICE_MANUFACTURE_NAME "marlinfw.org"
-#ifdef CUSTOM_MACHINE_NAME
- #define USB_DEVICE_PRODUCT_NAME CUSTOM_MACHINE_NAME
-#else
- #define USB_DEVICE_PRODUCT_NAME "3D Printer"
-#endif
-#define USB_DEVICE_SERIAL_NAME "123985739853"
-
/**
* Device speeds support
* Low speed not supported by CDC and MSC
diff --git a/Marlin/src/HAL/HAL_DUE/usb/osc.h b/Marlin/src/HAL/HAL_DUE/usb/osc.h
index 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 6f777d8f9e85..ea2936359d81 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,14 @@ 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() {
+ #ifdef DISABLE_DUE_SD_MMC
+ return CTRL_NO_PRESENT;
+ #endif
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
return CTRL_GOOD;
}
@@ -27,25 +30,18 @@ Ctrl_status sd_mmc_spi_test_unit_ready(void) {
// NOTE: This function is defined as returning the address of the last block
// in the card, which is cardSize() - 1
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1;
return CTRL_GOOD;
}
-bool sd_mmc_spi_unload(bool unload) {
- UNUSED(unload);
- return true;
-}
+bool sd_mmc_spi_unload(bool) { return true; }
-bool sd_mmc_spi_wr_protect(void) {
- return false;
-}
+bool sd_mmc_spi_wr_protect() { return false; }
-bool sd_mmc_spi_removal(void) {
- if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected())
- return true;
- return false;
+bool sd_mmc_spi_removal() {
+ return (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted());
}
#if ACCESS_USB == true
@@ -62,7 +58,10 @@ 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())
+ #ifdef DISABLE_DUE_SD_MMC
+ return CTRL_NO_PRESENT;
+ #endif
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC
@@ -99,7 +98,10 @@ 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())
+ #ifdef DISABLE_DUE_SD_MMC
+ return CTRL_NO_PRESENT;
+ #endif
+ if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC
diff --git a/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h b/Marlin/src/HAL/HAL_DUE/usb/spc_protocol.h
index 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/udd.h b/Marlin/src/HAL/HAL_DUE/usb/udd.h
index 10807f43d79e..c87763de23fa 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udd.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udd.h
@@ -94,11 +94,11 @@ typedef struct {
uint16_t payload_size;
//! Callback called after reception of ZLP from setup request
- void (*callback) (void);
+ void (*callback)(void);
//! Callback called when the buffer given (.payload) is full or empty.
//! This one return false to abort data transfer, or true with a new buffer in .payload.
- bool(*over_under_run) (void);
+ bool (*over_under_run)(void);
} udd_ctrl_request_t;
extern udd_ctrl_request_t udd_g_ctrlreq;
@@ -123,7 +123,7 @@ extern udd_ctrl_request_t udd_g_ctrlreq;
* Registered by routine udd_ep_wait_stall_clear()
* Callback called when endpoint stall is cleared.
*/
-typedef void (*udd_callback_halt_cleared_t) (void);
+typedef void (*udd_callback_halt_cleared_t)(void);
/**
* \brief End of transfer callback function type.
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi.h b/Marlin/src/HAL/HAL_DUE/usb/udi.h
index 1fc7ae5d01a4..709908cad947 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi.h
@@ -82,7 +82,7 @@ typedef struct {
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
- bool(*enable) (void);
+ bool (*enable)(void);
/**
* \brief Disable the interface.
@@ -95,7 +95,7 @@ typedef struct {
* - the device is detached from the host (i.e. Vbus is no
* longer present)
*/
- void (*disable) (void);
+ void (*disable)(void);
/**
* \brief Handle a control request directed at an interface.
@@ -108,7 +108,7 @@ typedef struct {
*
* \return \c 1 if this interface supports the SETUP request, otherwise \c 0.
*/
- bool(*setup) (void);
+ bool (*setup)(void);
/**
* \brief Returns the current setting of the selected interface.
@@ -117,12 +117,12 @@ typedef struct {
*
* \return alternate setting of selected interface
*/
- uint8_t(*getsetting) (void);
+ uint8_t (*getsetting)(void);
/**
* \brief To signal that a SOF is occurred
*/
- void(*sof_notify) (void);
+ void (*sof_notify)(void);
} udi_api_t;
//@}
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
index e54ee570fa4b..60c9546ce236 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.c
@@ -458,7 +458,7 @@ void udi_cdc_data_sof_notify(void)
}
-//-------------------------------------------------
+// ------------------------
//------- Internal routines to control serial line
static uint8_t udi_cdc_setup_to_port(void)
@@ -579,7 +579,7 @@ static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n,
}
-//-------------------------------------------------
+// ------------------------
//------- Internal routines to process data transfer
@@ -781,7 +781,7 @@ static void udi_cdc_tx_send(uint8_t port)
}
-//---------------------------------------------
+// ------------------------
//------- Application interface
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
index 45c5cef5ae58..526419c86002 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc.h
@@ -55,7 +55,7 @@
#include "udi.h"
// Check the number of port
-#ifndef UDI_CDC_PORT_NB
+#ifndef UDI_CDC_PORT_NB
# define UDI_CDC_PORT_NB 1
#endif
#if (UDI_CDC_PORT_NB < 1) || (UDI_CDC_PORT_NB > 7)
diff --git a/Marlin/src/HAL/HAL_DUE/usb/udi_cdc_conf.h b/Marlin/src/HAL/HAL_DUE/usb/udi_cdc_conf.h
index 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_msc.c b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
index 97d3f2990b96..627bca0d4f5a 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/udi_msc.c
@@ -457,7 +457,7 @@ uint8_t udi_msc_getsetting(void)
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process CBW packet
static void udi_msc_cbw_invalid(void)
@@ -613,7 +613,7 @@ static bool udi_msc_cbw_validate(uint32_t alloc_len, uint8_t dir_flag)
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process small data packet
static void udi_msc_data_send(uint8_t * buffer, uint8_t buf_size)
@@ -645,7 +645,7 @@ static void udi_msc_data_sent(udd_ep_status_t status, iram_size_t nb_sent,
}
-//---------------------------------------------
+// ------------------------
//------- Routines to process CSW packet
static void udi_msc_csw_process(void)
@@ -691,7 +691,7 @@ static void udi_msc_csw_sent(udd_ep_status_t status, iram_size_t nb_sent,
}
-//---------------------------------------------
+// ------------------------
//------- Routines manage sense data
static void udi_msc_clear_sense(void)
@@ -757,7 +757,7 @@ static void udi_msc_sense_command_invalid(void)
}
-//---------------------------------------------
+// ------------------------
//------- Routines manage SCSI Commands
static void udi_msc_spc_requestsense(void)
diff --git a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c
index 6512abffb553..9bac29276c75 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c
@@ -40,6 +40,7 @@
* \asf_license_stop
*
*/
+
/*
* Support and FAQ: visit Atmel Support
*/
@@ -505,7 +506,7 @@ static bool udd_ep_interrupt(void);
//@}
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED GLOBAL EVENTS
/**
@@ -1306,7 +1307,7 @@ void udd_test_mode_packet(void)
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED THE CONTROL ENDPOINT
static void udd_reset_ep_ctrl(void)
@@ -1728,7 +1729,7 @@ static bool udd_ctrl_interrupt(void)
}
-//--------------------------------------------------------
+// ------------------------
//--- INTERNAL ROUTINES TO MANAGED THE BULK/INTERRUPT/ISOCHRONOUS ENDPOINTS
#if (0 != USB_DEVICE_MAX_EP)
@@ -1904,7 +1905,7 @@ static void udd_ep_in_sent(udd_ep_id_t ep)
ptr_src = &ptr_job->buf[ptr_job->buf_cnt];
nb_remain = ptr_job->buf_size - ptr_job->buf_cnt;
// Fill a bank even if no data (ZLP)
- nb_data = _MIN(nb_remain, pkt_size);
+ nb_data = min(nb_remain, pkt_size);
// Modify job information
ptr_job->buf_cnt += nb_data;
ptr_job->buf_load = nb_data;
diff --git a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h
index 9e1793f9ba0b..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/usb_task.c b/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
index b735858018df..29d02faef703 100644
--- a/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
+++ b/Marlin/src/HAL/HAL_DUE/usb/usb_task.c
@@ -45,11 +45,12 @@
#ifdef ARDUINO_ARCH_SAM
-#include "conf_usb.h"
-#include "udc.h"
#include
#include
+#include "conf_usb.h"
+#include "udc.h"
+
#if ENABLED(SDSUPPORT)
static volatile bool main_b_msc_enable = false;
#endif
diff --git a/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp b/Marlin/src/HAL/HAL_DUE/watchdog.cpp
similarity index 97%
rename from Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
rename to Marlin/src/HAL/HAL_DUE/watchdog.cpp
index f1df75eaa6f5..1f51b75c18e1 100644
--- a/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/watchdog.cpp
@@ -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 95%
rename from Marlin/src/HAL/HAL_DUE/watchdog_Due.h
rename to Marlin/src/HAL/HAL_DUE/watchdog.h
index 14832a9c3cdf..6e70adef81a4 100644
--- a/Marlin/src/HAL/HAL_DUE/watchdog_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/watchdog.h
@@ -30,4 +30,4 @@ void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or AVR will go into emergency procedures.
-inline void watchdog_reset() { watchdogReset(); }
+inline void HAL_watchdog_refresh() { watchdogReset(); }
diff --git a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h
index 66bdbd7aaea0..9fca4fcbea39 100644
--- a/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h
+++ b/Marlin/src/HAL/HAL_ESP32/FlushableHardwareSerial.h
@@ -29,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 299aee46fe37..81567eeede8f 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/HAL.cpp
@@ -22,11 +22,8 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
+#include "timers.h"
#include
#include
#include
@@ -48,55 +45,44 @@
#endif
#endif
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
+// ------------------------
+// Externs
+// ------------------------
portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
+// ------------------------
#define V_REF 1100
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
-esp_adc_cal_characteristics_t characteristics;
+esp_adc_cal_characteristics_t characteristics[ADC_ATTEN_MAX];
+adc_atten_t attenuations[ADC1_CHANNEL_MAX] = {};
+uint32_t thresholds[ADC_ATTEN_MAX];
+volatile int numPWMUsed = 0,
+ pwmPins[MAX_PWM_PINS],
+ pwmValues[MAX_PWM_PINS];
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-void HAL_init(void) {
+void HAL_init() {
i2s_init();
}
-void HAL_init_board(void) {
+void HAL_init_board() {
#if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
spiffs_init();
#endif
@@ -113,24 +99,24 @@ void HAL_init_board(void) {
#endif
}
-void HAL_idletask(void) {
+void HAL_idletask() {
#if ENABLED(OTASUPPORT)
OTA_handle();
#endif
}
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
-uint8_t HAL_get_reset_source(void) { return rtc_get_reset_reason(1); }
+uint8_t HAL_get_reset_source() { return rtc_get_reset_reason(1); }
void _delay_ms(int delay_ms) { delay(delay_ms); }
// return free memory between end of heap (or end bss) and whatever is current
int freeMemory() { return ESP.getFreeHeap(); }
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
#define ADC1_CHANNEL(pin) ADC1_GPIO ## pin ## _CHANNEL
adc1_channel_t get_channel(int pin) {
@@ -145,68 +131,134 @@ adc1_channel_t get_channel(int pin) {
return ADC1_CHANNEL_MAX;
}
+void adc1_set_attenuation(adc1_channel_t chan, adc_atten_t atten) {
+ if (attenuations[chan] != atten) {
+ adc1_config_channel_atten(chan, atten);
+ attenuations[chan] = atten;
+ }
+}
+
void HAL_adc_init() {
// Configure ADC
adc1_config_width(ADC_WIDTH_12Bit);
// Configure channels only if used as (re-)configuring a pin for ADC that is used elsewhere might have adverse effects
#if HAS_TEMP_ADC_0
- adc1_config_channel_atten(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_1
- adc1_config_channel_atten(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_2
- adc1_config_channel_atten(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_3
- adc1_config_channel_atten(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_4
- adc1_config_channel_atten(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_ADC_5
- adc1_config_channel_atten(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
#endif
#if HAS_HEATED_BED
- adc1_config_channel_atten(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
#endif
#if HAS_TEMP_CHAMBER
- adc1_config_channel_atten(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
- adc1_config_channel_atten(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
+ adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
#endif
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.
// That's why we're not setting it up here.
- // Calculate ADC characteristics i.e. gain and offset factors
- esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, V_REF, &characteristics);
+ // Calculate ADC characteristics (i.e., gain and offset factors for each attenuation level)
+ for (int i = 0; i < ADC_ATTEN_MAX; i++) {
+ esp_adc_cal_characterize(ADC_UNIT_1, (adc_atten_t)i, ADC_WIDTH_BIT_12, V_REF, &characteristics[i]);
+
+ // Change attenuation 100mV below the calibrated threshold
+ thresholds[i] = esp_adc_cal_raw_to_voltage(4095, &characteristics[i]);
+ }
}
void HAL_adc_start_conversion(uint8_t adc_pin) {
+ const adc1_channel_t chan = get_channel(adc_pin);
uint32_t mv;
- esp_adc_cal_get_voltage((adc_channel_t)get_channel(adc_pin), &characteristics, &mv);
-
- HAL_adc_result = mv*1023.0/3300.0;
+ esp_adc_cal_get_voltage((adc_channel_t)chan, &characteristics[attenuations[chan]], &mv);
+ HAL_adc_result = mv * 1023.0 / 3300.0;
+
+ // Change the attenuation level based on the new reading
+ adc_atten_t atten;
+ if (mv < thresholds[ADC_ATTEN_DB_0] - 100)
+ atten = ADC_ATTEN_DB_0;
+ else if (mv > thresholds[ADC_ATTEN_DB_0] - 50 && mv < thresholds[ADC_ATTEN_DB_2_5] - 100)
+ atten = ADC_ATTEN_DB_2_5;
+ else if (mv > thresholds[ADC_ATTEN_DB_2_5] - 50 && mv < thresholds[ADC_ATTEN_DB_6] - 100)
+ atten = ADC_ATTEN_DB_6;
+ else if (mv > thresholds[ADC_ATTEN_DB_6] - 50)
+ atten = ADC_ATTEN_DB_11;
+ else return;
+
+ adc1_set_attenuation(chan, atten);
}
void analogWrite(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);
- if (!PWM_PIN(pin)) return;
+ ++numPWMUsed;
+ }
+
+ // Use 7bit internal value - add 1 to have 100% high at 255
+ pwmValues[idx] = (value + 1) / 2;
+}
- static int cnt_channel = 1,
- pin_to_channel[40] = {};
- if (pin_to_channel[pin] == 0) {
- ledcAttachPin(pin, cnt_channel);
- ledcSetup(cnt_channel, 490, 8);
- ledcWrite(cnt_channel, value);
+// Handle PWM timer interrupt
+HAL_PWM_TIMER_ISR() {
+ HAL_timer_isr_prologue(PWM_TIMER_NUM);
- pin_to_channel[pin] = cnt_channel++;
+ static uint8_t count = 0;
+
+ for (int i = 0; i < numPWMUsed; ++i) {
+ if (count == 0) // Start of interval
+ WRITE(pwmPins[i], pwmValues[i] ? HIGH : LOW);
+ else if (pwmValues[i] == count) // End of duration
+ WRITE(pwmPins[i], LOW);
}
- 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 0fc1d71bc40c..df9a5648c8bd 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL.h
+++ b/Marlin/src/HAL/HAL_ESP32/HAL.h
@@ -24,28 +24,24 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_ESP32.h"
-#include "watchdog_ESP32.h"
+#include "fastio.h"
+#include "watchdog.h"
#include "i2s.h"
-#include "HAL_timers_ESP32.h"
+#include "timers.h"
#include "WebSocketSerial.h"
#include "FlushableHardwareSerial.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
extern portMUX_TYPE spinlock;
@@ -69,34 +65,37 @@ 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(pin_t pin, int value);
@@ -109,9 +108,10 @@ 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_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
@@ -124,6 +124,6 @@ void HAL_adc_start_conversion(uint8_t adc_pin);
// Enable hooks into idle and setup for HAL
#define HAL_IDLETASK 1
#define BOARD_INIT() HAL_init_board();
-void HAL_idletask(void);
-void HAL_init(void);
-void HAL_init_board(void);
+void HAL_idletask();
+void HAL_init();
+void HAL_init_board();
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/HAL_SPI.cpp
similarity index 77%
rename from Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/HAL_SPI.cpp
index 67d7e25972a1..eba880b4fdfe 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/HAL_SPI.cpp
@@ -23,39 +23,36 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "HAL.h"
#include "../shared/HAL_SPI.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)
@@ -83,7 +80,7 @@ void spiInit(uint8_t spiRate) {
SPI.begin();
}
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/Servo.cpp
similarity index 70%
rename from Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/Servo.cpp
index e702539ca92d..3c3b8fa704bf 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/Servo.cpp
@@ -25,32 +25,32 @@
#if HAS_SERVOS
-#include "HAL_Servo_ESP32.h"
+#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++;
+ channel = channel_next_free++;
}
-int8_t Servo::attach(const int pin) {
- if (this->channel >= CHANNEL_MAX_NUM) return -1;
- if (pin > 0) this->pin = pin;
+int8_t Servo::attach(const int inPin) {
+ if (channel >= CHANNEL_MAX_NUM) return -1;
+ if (pin > 0) pin = inPin;
- ledcSetup(this->channel, 50, 16); // channel X, 50 Hz, 16-bit depth
- ledcAttachPin(this->pin, this->channel);
+ ledcSetup(channel, 50, 16); // channel X, 50 Hz, 16-bit depth
+ ledcAttachPin(pin, channel);
return true;
}
-void Servo::detach() { ledcDetachPin(this->pin); }
+void Servo::detach() { ledcDetachPin(pin); }
-int Servo::read() { return this->degrees; }
+int Servo::read() { return degrees; }
-void Servo::write(int degrees) {
- this->degrees = constrain(degrees, MIN_ANGLE, MAX_ANGLE);
- int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
+void Servo::write(int inDegrees) {
+ degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
+ int us = map(degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
ledcWrite(channel, duty);
}
@@ -58,11 +58,11 @@ void Servo::write(int degrees) {
void Servo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->channel]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[channel]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.h b/Marlin/src/HAL/HAL_ESP32/Servo.h
similarity index 100%
rename from Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/Servo.h
diff --git a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
index ce2692e2d200..9a38d3996a65 100644
--- a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.cpp
@@ -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 6470f941d147..85436d151b7b 100644
--- a/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.h
+++ b/Marlin/src/HAL/HAL_ESP32/WebSocketSerial.h
@@ -23,7 +23,7 @@
#include "../../inc/MarlinConfig.h"
-#include "Stream.h"
+#include
#ifndef RX_BUFFER_SIZE
#define RX_BUFFER_SIZE 128
@@ -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 9e5fc8a66510..31a3e4d6678f 100644
--- a/Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h
@@ -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 94%
rename from Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/fastio.h
index 364777409587..1641116b9023 100644
--- a/Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/fastio.h
@@ -66,7 +66,7 @@
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
// PWM outputs
-#define PWM_PIN(P) (P < 34) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
+#define PWM_PIN(P) (P < 34 || P > 127) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
// Toggle pin value
#define TOGGLE(IO) WRITE(IO, !READ(IO))
diff --git a/Marlin/src/HAL/HAL_ESP32/i2s.cpp b/Marlin/src/HAL/HAL_ESP32/i2s.cpp
index 557714f870f8..33a503455c82 100644
--- a/Marlin/src/HAL/HAL_ESP32/i2s.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/i2s.cpp
@@ -26,10 +26,10 @@
#include "i2s.h"
#include "../shared/Marduino.h"
-#include "driver/periph_ctrl.h"
-#include "rom/lldesc.h"
-#include "soc/i2s_struct.h"
-#include "freertos/queue.h"
+#include
+#include
+#include
+#include
#include "../../module/stepper.h"
#define DMA_BUF_COUNT 8 // number of DMA buffers to store data
@@ -56,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])
@@ -140,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();
@@ -254,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;
@@ -314,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/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 100%
rename from Marlin/src/HAL/HAL_ESP32/SanityCheck.h
rename to Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h
diff --git a/Marlin/src/HAL/HAL_ESP32/ota.cpp b/Marlin/src/HAL/HAL_ESP32/ota.cpp
index 98ea3b5eb7ea..377856f8d8b6 100644
--- a/Marlin/src/HAL/HAL_ESP32/ota.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/ota.cpp
@@ -27,7 +27,7 @@
#include
#include
#include
-#include "driver/timer.h"
+#include
void OTA_init() {
ArduinoOTA
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/timers.cpp
similarity index 66%
rename from Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/timers.cpp
index fb95e36e2770..543889760e04 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/timers.cpp
@@ -22,86 +22,61 @@
#ifdef ARDUINO_ARCH_ESP32
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-#include "esp_types.h"
-#include "soc/timer_group_struct.h"
-#include "driver/periph_ctrl.h"
-#include "driver/timer.h"
+#include
+#include
+#include
+#include
#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, nullptr }, // 2
+ { TIMER_GROUP_1, TIMER_0, PWM_TIMER_PRESCALE, pwmTC_Handler }, // 2 - PWM
{ TIMER_GROUP_1, TIMER_1, 1, nullptr }, // 3
};
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-void IRAM_ATTR timer_group0_isr(void *para) {
- const int timer_idx = (int)para;
+void IRAM_ATTR timer_isr(void *para) {
+ const tTimerConfig& timer = TimerConfig[(int)para];
// Retrieve the interrupt status and the counter value
// from the timer that reported the interrupt
- uint32_t intr_status = TIMERG0.int_st_timers.val;
- TIMERG0.hw_timer[timer_idx].update = 1;
+ uint32_t intr_status = TG[timer.group]->int_st_timers.val;
+ TG[timer.group]->hw_timer[timer.idx].update = 1;
// Clear the interrupt
- if (intr_status & BIT(timer_idx)) {
- switch (timer_idx) {
- case TIMER_0: TIMERG0.int_clr_timers.t0 = 1; break;
- case TIMER_1: TIMERG0.int_clr_timers.t1 = 1; break;
+ if (intr_status & BIT(timer.idx)) {
+ switch (timer.idx) {
+ case TIMER_0: TG[timer.group]->int_clr_timers.t0 = 1; break;
+ case TIMER_1: TG[timer.group]->int_clr_timers.t1 = 1; break;
+ case TIMER_MAX: break;
}
}
- const tTimerConfig timer = TimerConfig[timer_idx];
timer.fn();
// After the alarm has been triggered
// Enable it again so it gets triggered the next time
- TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
+ TG[timer.group]->hw_timer[timer.idx].config.alarm_en = TIMER_ALARM_EN;
}
/**
@@ -131,8 +106,7 @@ void HAL_timer_start(const uint8_t timer_num, uint32_t frequency) {
timer_enable_intr(timer.group, timer.idx);
- // TODO need to deal with timer_group1_isr
- timer_isr_register(timer.group, timer.idx, timer_group0_isr, (void*)timer.idx, 0, nullptr);
+ timer_isr_register(timer.group, timer.idx, timer_isr, (void*)timer_num, 0, nullptr);
timer_start(timer.group, timer.idx);
}
diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h b/Marlin/src/HAL/HAL_ESP32/timers.h
similarity index 74%
rename from Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/timers.h
index 1a05c04a084f..e6e3495bea7b 100644
--- a/Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/timers.h
@@ -21,21 +21,17 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-#include "driver/timer.h"
+#include
// 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
@@ -44,6 +40,7 @@ typedef uint64_t hal_timer_t;
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
+#define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
@@ -54,8 +51,8 @@ typedef uint64_t hal_timer_t;
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs // wrong would be 0.25
#else
#define STEPPER_TIMER_PRESCALE 40
- #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer, 2MHz
- #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
+ #define STEPPER_TIMER_RATE ((HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE)) // frequency of stepper timer, 2MHz
+ #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
#endif
#define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
@@ -63,6 +60,14 @@ typedef uint64_t hal_timer_t;
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
+#define PWM_TIMER_PRESCALE 10
+#if ENABLED(FAST_PWM_FAN)
+ #define PWM_TIMER_FREQUENCY FAST_PWM_FAN_FREQUENCY
+#else
+ #define PWM_TIMER_FREQUENCY (50*128) // 50Hz and 7bit resolution
+#endif
+#define MAX_PWM_PINS 32 // Number of PWM pin-slots
+
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
@@ -74,33 +79,34 @@ typedef uint64_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler(void)
-#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler(void)
-
-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 92%
rename from Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.cpp
rename to Marlin/src/HAL/HAL_ESP32/watchdog.cpp
index cbd5d989cd3f..d05e67c856a3 100644
--- a/Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/watchdog.cpp
@@ -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 96%
rename from Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h
rename to Marlin/src/HAL/HAL_ESP32/watchdog.h
index e5dd3b46d33f..6647ecefe660 100644
--- a/Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h
+++ b/Marlin/src/HAL/HAL_ESP32/watchdog.h
@@ -25,4 +25,4 @@
void watchdog_init();
// Reset watchdog.
-inline void watchdog_reset() { }
+inline void HAL_watchdog_refresh() {}
diff --git a/Marlin/src/HAL/HAL_ESP32/web.cpp b/Marlin/src/HAL/HAL_ESP32/web.cpp
index b2bb03d714d9..c593fc024216 100644
--- a/Marlin/src/HAL/HAL_ESP32/web.cpp
+++ b/Marlin/src/HAL/HAL_ESP32/web.cpp
@@ -22,16 +22,18 @@
#ifdef ARDUINO_ARCH_ESP32
+#include
+#undef DISABLED // esp32-hal-gpio.h
+
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(WEBSUPPORT)
-#include
#include "wifi.h"
AsyncEventSource events("/events"); // event source (Server-Sent events)
-void onNotFound(AsyncWebServerRequest *request){
+void onNotFound(AsyncWebServerRequest *request) {
request->send(404);
}
diff --git a/Marlin/src/HAL/HAL_LINUX/HAL.cpp b/Marlin/src/HAL/HAL_LINUX/HAL.cpp
index 854d7247f65b..316f6b452a4b 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/HAL.cpp
@@ -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 a87e40039433..37b3b479bcdf 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL.h
+++ b/Marlin/src/HAL/HAL_LINUX/HAL.h
@@ -23,10 +23,6 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#define F_CPU 100000000
#define SystemCoreClock F_CPU
#include
@@ -60,7 +56,7 @@ uint8_t _getc();
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "HAL_timers.h"
+#include "timers.h"
#include "serial.h"
#define SHARED_SERVOS HAS_SERVOS
@@ -82,29 +78,29 @@ extern HalSerial usb_serial;
#define ENABLE_ISRS()
#define DISABLE_ISRS()
-inline void HAL_init(void) { }
+inline void HAL_init() {}
// Utility functions
-int freeMemory(void);
-
-// 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 push
+#pragma GCC diagnostic ignored "-Wunused-function"
+int freeMemory();
+#pragma GCC diagnostic pop
// ADC
#define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin)
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
-void HAL_adc_init(void);
+void HAL_adc_init();
void HAL_adc_enable_channel(int pin);
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
+
+// Reset source
+inline void HAL_clear_reset_source(void) {}
+inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
/* ---------------- Delay in cycles */
FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
diff --git a/Marlin/src/HAL/HAL_LINUX/arduino.cpp b/Marlin/src/HAL/HAL_LINUX/arduino.cpp
index a7e451ebcc1d..88128dd91a17 100644
--- a/Marlin/src/HAL/HAL_LINUX/arduino.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/arduino.cpp
@@ -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/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/SanityCheck.h b/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h
similarity index 100%
rename from Marlin/src/HAL/HAL_LINUX/SanityCheck.h
rename to Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h
diff --git a/Marlin/src/HAL/HAL_LINUX/include/Arduino.h b/Marlin/src/HAL/HAL_LINUX/include/Arduino.h
index f73a9c91613e..13a8206e1b1c 100644
--- a/Marlin/src/HAL/HAL_LINUX/include/Arduino.h
+++ b/Marlin/src/HAL/HAL_LINUX/include/Arduino.h
@@ -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/serial.h b/Marlin/src/HAL/HAL_LINUX/include/serial.h
index dd57d997497f..c6da82ad5a3f 100644
--- a/Marlin/src/HAL/HAL_LINUX/include/serial.h
+++ b/Marlin/src/HAL/HAL_LINUX/include/serial.h
@@ -83,8 +83,9 @@ class HalSerial {
HalSerial() { host_connected = true; }
- void begin(int32_t baud) {
- }
+ void begin(int32_t) {}
+
+ 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 01b0eee34ddd..4231affba778 100644
--- a/Marlin/src/HAL/HAL_LINUX/main.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/main.cpp
@@ -104,7 +104,7 @@ void simulation_loop() {
}
}
-int main(void) {
+int main() {
std::thread write_serial (write_serial_thread);
std::thread read_serial (read_serial_thread);
diff --git a/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
index aba664d9f983..c4965d90e3ad 100644
--- a/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
@@ -29,7 +29,8 @@
#include "../shared/persistent_store_api.h"
#include
-uint8_t buffer[E2END];
+#define LINUX_EEPROM_SIZE (E2END + 1)
+uint8_t buffer[LINUX_EEPROM_SIZE];
char filename[] = "eeprom.dat";
bool PersistentStore::access_start() {
@@ -40,8 +41,8 @@ bool PersistentStore::access_start() {
fseek(eeprom_file, 0L, SEEK_END);
std::size_t file_size = ftell(eeprom_file);
- if (file_size < E2END) {
- memset(buffer + file_size, eeprom_erase_value, E2END - file_size);
+ if (file_size < LINUX_EEPROM_SIZE) {
+ memset(buffer + file_size, eeprom_erase_value, LINUX_EEPROM_SIZE - file_size);
}
else {
fseek(eeprom_file, 0L, SEEK_SET);
@@ -60,7 +61,7 @@ bool PersistentStore::access_finish() {
return true;
}
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
std::size_t bytes_written = 0;
for (std::size_t i = 0; i < size; i++) {
diff --git a/Marlin/src/HAL/HAL_LINUX/pinsDebug.h b/Marlin/src/HAL/HAL_LINUX/pinsDebug.h
index be4765a5718d..a28d2b60b928 100644
--- a/Marlin/src/HAL/HAL_LINUX/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_LINUX/pinsDebug.h
@@ -32,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/spi_pins.h b/Marlin/src/HAL/HAL_LINUX/spi_pins.h
index 5b6f88ac6d7d..fdd09b1c037b 100644
--- a/Marlin/src/HAL/HAL_LINUX/spi_pins.h
+++ b/Marlin/src/HAL/HAL_LINUX/spi_pins.h
@@ -24,9 +24,9 @@
#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 97%
rename from Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp
rename to Marlin/src/HAL/HAL_LINUX/timers.cpp
index 48c033d87eef..f293d7f40884 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/timers.cpp
@@ -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 90%
rename from Marlin/src/HAL/HAL_LINUX/HAL_timers.h
rename to Marlin/src/HAL/HAL_LINUX/timers.h
index b7d0f9b2da36..8022aabd264d 100644
--- a/Marlin/src/HAL/HAL_LINUX/HAL_timers.h
+++ b/Marlin/src/HAL/HAL_LINUX/timers.h
@@ -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 f96a05e5b89c..6338ea3b1d7b 100644
--- a/Marlin/src/HAL/HAL_LINUX/watchdog.cpp
+++ b/Marlin/src/HAL/HAL_LINUX/watchdog.cpp
@@ -28,19 +28,9 @@
#include "watchdog.h"
-void watchdog_init(void) {}
+void watchdog_init() {}
+void HAL_watchdog_refresh() {}
-void HAL_clear_reset_source(void) {}
-
-uint8_t HAL_get_reset_source(void) {
- return RST_POWER_ON;
-}
-
-void watchdog_reset() {}
-
-#else
- void HAL_clear_reset_source(void) {}
- uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
-#endif // USE_WATCHDOG
+#endif
#endif // __PLAT_LINUX__
diff --git a/Marlin/src/HAL/HAL_LINUX/watchdog.h b/Marlin/src/HAL/HAL_LINUX/watchdog.h
index 04ce17fe9d52..51d30c8437a1 100644
--- a/Marlin/src/HAL/HAL_LINUX/watchdog.h
+++ b/Marlin/src/HAL/HAL_LINUX/watchdog.h
@@ -23,7 +23,5 @@
#define WDT_TIMEOUT 4000000 // 4 second timeout
-void watchdog_init(void);
-void watchdog_reset(void);
-void HAL_clear_reset_source(void);
-uint8_t HAL_get_reset_source(void);
+void watchdog_init();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_LPC1768/DebugMonitor_LPC1768.cpp b/Marlin/src/HAL/HAL_LPC1768/DebugMonitor.cpp
similarity index 94%
rename from Marlin/src/HAL/HAL_LPC1768/DebugMonitor_LPC1768.cpp
rename to Marlin/src/HAL/HAL_LPC1768/DebugMonitor.cpp
index 0196253df21a..fefee386e590 100644
--- a/Marlin/src/HAL/HAL_LPC1768/DebugMonitor_LPC1768.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/DebugMonitor.cpp
@@ -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 aed7a7855c26..4da55c2f3d53 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
@@ -26,14 +26,20 @@
#include "../shared/Delay.h"
#include "../../../gcode/parser.h"
+#if ENABLED(USE_WATCHDOG)
+ #include "watchdog.h"
+#endif
+
+uint32_t HAL_adc_reading = 0;
+
// U8glib required functions
extern "C" void u8g_xMicroDelay(uint16_t val) {
DELAY_US(val);
}
-extern "C" void u8g_MicroDelay(void) {
+extern "C" void u8g_MicroDelay() {
u8g_xMicroDelay(1);
}
-extern "C" void u8g_10MicroDelay(void) {
+extern "C" void u8g_10MicroDelay() {
u8g_xMicroDelay(10);
}
extern "C" void u8g_Delay(uint16_t val) {
@@ -57,7 +63,7 @@ int freeMemory() {
// return dval if not found or not a valid pin.
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval) {
const uint16_t val = (uint16_t)parser.intval(code, -1), port = val / 100, pin = val % 100;
- const int16_t ind = (port < ((NUM_DIGITAL_PINS) >> 5) && pin < 32) ? GET_PIN_MAP_INDEX((port << 5) | pin) : -2;
+ const int16_t ind = (port < ((NUM_DIGITAL_PINS) >> 5) && pin < 32) ? ((port << 5) | pin) : -2;
return ind > -1 ? ind : dval;
}
@@ -65,4 +71,17 @@ void flashFirmware(int16_t value) {
NVIC_SystemReset();
}
+void HAL_clear_reset_source(void) {
+ #if ENABLED(USE_WATCHDOG)
+ watchdog_clear_timeout_flag();
+ #endif
+}
+
+uint8_t HAL_get_reset_source(void) {
+ #if ENABLED(USE_WATCHDOG)
+ if (watchdog_timed_out()) return RST_WATCHDOG;
+ #endif
+ return RST_POWER_ON;
+}
+
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL.h b/Marlin/src/HAL/HAL_LPC1768/HAL.h
index 32765bd0ea5a..1648905453e7 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL.h
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL.h
@@ -28,20 +28,20 @@
#define CPU_32_BIT
-void HAL_init(void);
+void HAL_init();
#include
#include
#include
-extern "C" volatile millis_t _millis;
+extern "C" volatile uint32_t _millis;
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "HAL_timers.h"
+#include "timers.h"
#include "MarlinSerial.h"
#include
@@ -111,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
@@ -133,21 +125,49 @@ 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
// Memory usage per ADC channel (bytes): 4 (32 Bytes for 8 channels)
+#define HAL_ADC_RESOLUTION 12 // 15 bit maximum, raw temperature is stored as int16_t
+#define HAL_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL
+
using FilteredADC = LPC176x::ADC;
-#define HAL_adc_init() FilteredADC::init()
+extern uint32_t HAL_adc_reading;
+[[gnu::always_inline]] inline void HAL_start_adc(const pin_t pin) {
+ HAL_adc_reading = FilteredADC::read(pin) >> (16 - HAL_ADC_RESOLUTION); // returns 16bit value, reduce to required bits
+}
+[[gnu::always_inline]] inline uint16_t HAL_read_adc() {
+ return HAL_adc_reading;
+}
+
+#define HAL_adc_init()
#define HAL_ANALOG_SELECT(pin) FilteredADC::enable_channel(pin)
-#define HAL_START_ADC(pin) FilteredADC::start_conversion(pin)
-#define HAL_READ_ADC() FilteredADC::get_result()
-#define HAL_ADC_READY() FilteredADC::finished_conversion()
-
-// A grace period to allow ADC readings to stabilize, preventing false alarms
-#define THERMAL_PROTECTION_GRACE_PERIOD 1000
+#define HAL_START_ADC(pin) HAL_start_adc(pin)
+#define HAL_READ_ADC() HAL_read_adc()
+#define HAL_ADC_READY() (true)
+
+// Test whether the pin is valid
+constexpr bool VALID_PIN(const pin_t pin) {
+ return LPC176x::pin_is_valid(pin);
+}
+
+// Get the analog index for a digital pin
+constexpr int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t pin) {
+ return (LPC176x::pin_is_valid(pin) && LPC176x::pin_has_adc(pin)) ? pin : -1;
+}
+
+// Return the index of a pin number
+constexpr int16_t GET_PIN_MAP_INDEX(const pin_t pin) {
+ return LPC176x::pin_index(pin);
+}
+
+// Get the pin number at the given index
+constexpr pin_t GET_PIN_MAP_PIN(const int16_t index) {
+ return LPC176x::pin_index(index);
+}
// Parse a G-code word into a pin index
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
@@ -155,7 +175,7 @@ int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
#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);
@@ -175,3 +195,7 @@ void set_pwm_frequency(const pin_t pin, int f_desired);
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
*/
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
+
+// Reset source
+void HAL_clear_reset_source(void);
+uint8_t HAL_get_reset_source(void);
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL_SPI.cpp
similarity index 91%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
rename to Marlin/src/HAL/HAL_LPC1768/HAL_SPI.cpp
index 78f1672dcc41..5f32c7874d02 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL_SPI.cpp
@@ -49,18 +49,14 @@
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
#if ENABLED(LPC_SOFTWARE_SPI)
- #include "SoftwareSPI.h"
+ #include
// Software SPI
@@ -129,18 +125,18 @@
PinCfg.Funcnum = 2;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
- PinCfg.Pinnum = LPC1768_PIN_PIN(SCK_PIN);
- PinCfg.Portnum = LPC1768_PIN_PORT(SCK_PIN);
+ PinCfg.Pinnum = LPC176x::pin_bit(SCK_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(SCK_PIN);
PINSEL_ConfigPin(&PinCfg);
SET_OUTPUT(SCK_PIN);
- PinCfg.Pinnum = LPC1768_PIN_PIN(MISO_PIN);
- PinCfg.Portnum = LPC1768_PIN_PORT(MISO_PIN);
+ PinCfg.Pinnum = LPC176x::pin_bit(MISO_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(MISO_PIN);
PINSEL_ConfigPin(&PinCfg);
SET_INPUT(MISO_PIN);
- PinCfg.Pinnum = LPC1768_PIN_PIN(MOSI_PIN);
- PinCfg.Portnum = LPC1768_PIN_PORT(MOSI_PIN);
+ PinCfg.Pinnum = LPC176x::pin_bit(MOSI_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(MOSI_PIN);
PINSEL_ConfigPin(&PinCfg);
SET_OUTPUT(MOSI_PIN);
// divide PCLK by 2 for SSP0
diff --git a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp
index 2379300512a8..a8778f7446b8 100644
--- a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.cpp
@@ -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 4807356d739d..80506855384b 100644
--- a/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.h
+++ b/Marlin/src/HAL/HAL_LPC1768/MarlinSerial.h
@@ -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/HAL_Servo_LPC1768.h b/Marlin/src/HAL/HAL_LPC1768/Servo.h
similarity index 91%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_Servo_LPC1768.h
rename to Marlin/src/HAL/HAL_LPC1768/Servo.h
index 8b511032cb9c..1bbf84c73e99 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_Servo_LPC1768.h
+++ b/Marlin/src/HAL/HAL_LPC1768/Servo.h
@@ -57,11 +57,11 @@ class libServo: public Servo {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(servo_info[this->servoIndex].Pin.nbr) >= 0) { // try to reattach
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]); // delay to allow servo to reach position
+ if (attach(servo_info[servoIndex].Pin.nbr) >= 0) { // try to reattach
+ write(value);
+ safe_delay(servo_delay[servoIndex]); // delay to allow servo to reach position
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h b/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
index a1d9aba167aa..f1d4fc754f3e 100644
--- a/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h
@@ -38,73 +38,76 @@
#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() {
+ #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
+ #define LPC1768_PIN_INTERRUPT_M(pin) ((pin >> 0x5 & 0x7) == 0 || (pin >> 0x5 & 0x7) == 2)
-void setup_endstop_interrupts(void) {
#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 7af3a07eeae0..6c7de9bb1d5e 100644
--- a/Marlin/src/HAL/HAL_LPC1768/fast_pwm.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/fast_pwm.cpp
@@ -24,17 +24,17 @@
#include "../../inc/MarlinConfigPre.h"
-#if ENABLED(FAST_PWM_FAN)
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
#include
void set_pwm_frequency(const pin_t pin, int f_desired) {
- pwm_set_frequency(pin, f_desired);
+ LPC176x::pwm_set_frequency(pin, f_desired);
}
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
- pwm_write_ratio(pin, invert ? 1.0f - (float)v / v_size : (float)v / v_size);
+ LPC176x::pwm_write_ratio(pin, invert ? 1.0f - (float)v / v_size : (float)v / v_size);
}
-#endif // FAST_PWM_FAN
+#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/fastio.h b/Marlin/src/HAL/HAL_LPC1768/fastio.h
index a00a4946c165..8b90ec20d30c 100644
--- a/Marlin/src/HAL/HAL_LPC1768/fastio.h
+++ b/Marlin/src/HAL/HAL_LPC1768/fastio.h
@@ -37,19 +37,19 @@
#define PWM_PIN(P) true // all pins are PWM capable
-#define LPC_PIN(pin) gpio_pin(pin)
-#define LPC_GPIO(port) gpio_port(port)
+#define LPC_PIN(pin) LPC176x::gpio_pin(pin)
+#define LPC_GPIO(port) LPC176x::gpio_port(port)
-#define SET_DIR_INPUT(IO) gpio_set_input(IO)
-#define SET_DIR_OUTPUT(IO) gpio_set_output(IO)
+#define SET_DIR_INPUT(IO) LPC176x::gpio_set_input(IO)
+#define SET_DIR_OUTPUT(IO) LPC176x::gpio_set_output(IO)
#define SET_MODE(IO, mode) pinMode(IO, mode)
-#define WRITE_PIN_SET(IO) gpio_set(IO)
-#define WRITE_PIN_CLR(IO) gpio_clear(IO)
+#define WRITE_PIN_SET(IO) LPC176x::gpio_set(IO)
+#define WRITE_PIN_CLR(IO) LPC176x::gpio_clear(IO)
-#define READ_PIN(IO) gpio_get(IO)
-#define WRITE_PIN(IO,V) gpio_set(IO, V)
+#define READ_PIN(IO) LPC176x::gpio_get(IO)
+#define WRITE_PIN(IO,V) LPC176x::gpio_set(IO, V)
/**
* Magic I/O routines
@@ -81,10 +81,10 @@
#define _PULLDOWN(IO,V) pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
/// check if pin is an input
-#define _IS_INPUT(IO) (!gpio_get_dir(IO))
+#define _IS_INPUT(IO) (!LPC176x::gpio_get_dir(IO))
/// check if pin is an output
-#define _IS_OUTPUT(IO) (gpio_get_dir(IO))
+#define _IS_OUTPUT(IO) (LPC176x::gpio_get_dir(IO))
/// Read a pin wrapper
#define READ(IO) _READ(IO)
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..17cbf20ef076
--- /dev/null
+++ b/Marlin/src/HAL/HAL_LPC1768/inc/SanityCheck.h
@@ -0,0 +1,70 @@
+/**
+ * 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
+
+#if PIO_PLATFORM_VERSION < 1001
+ #error "nxplpc-arduino-lpc176x package is out of date, Please update the PlatformIO platforms, frameworks and libraries. You may need to remove the platform and let it reinstall automatically."
+#endif
+#if PIO_FRAMEWORK_VERSION < 2002
+ #error "framework-arduino-lpc176x package is out of date, Please update the PlatformIO platforms, frameworks and libraries."
+#endif
+
+/**
+ * Detect an old pins file by checking for old ADC pins values.
+ */
+#define _OLD_TEMP_PIN(P) PIN_EXISTS(P) && _CAT(P,_PIN) <= 7 && _CAT(P,_PIN) != 2 && _CAT(P,_PIN) != 3
+#if _OLD_TEMP_PIN(TEMP_BED)
+ #error "TEMP_BED_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#elif _OLD_TEMP_PIN(TEMP_0)
+ #error "TEMP_0_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#elif _OLD_TEMP_PIN(TEMP_1)
+ #error "TEMP_1_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#elif _OLD_TEMP_PIN(TEMP_2)
+ #error "TEMP_2_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#elif _OLD_TEMP_PIN(TEMP_3)
+ #error "TEMP_3_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#elif _OLD_TEMP_PIN(TEMP_4)
+ #error "TEMP_4_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#elif _OLD_TEMP_PIN(TEMP_5)
+ #error "TEMP_5_PIN must be defined using the Pn_nn or Pn_nn_An format. (See the included pins files)."
+#endif
+#undef _OLD_TEMP_PIN
+
+/**
+ * Because PWM hardware channels all share the same frequency, along with the
+ * fallback software channels, FAST_PWM_FAN is incompatible with Servos.
+ */
+#if NUM_SERVOS > 0 && ENABLED(FAST_PWM_FAN)
+ #error "BLTOUCH and Servos are incompatible with FAST_PWM_FAN on LPC176x boards."
+#endif
+
+/**
+ * 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/digipot_mcp4451_I2C_routines.c b/Marlin/src/HAL/HAL_LPC1768/include/digipot_mcp4451_I2C_routines.c
index 28c1e01792e3..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
@@ -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 13712e2ae0ba..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
@@ -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 3f22b0d36d3f..b20841bdeb9c 100644
--- a/Marlin/src/HAL/HAL_LPC1768/main.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/main.cpp
@@ -38,17 +38,15 @@ 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(void) {
+void HAL_init() {
// Init LEDs
#if PIN_EXISTS(LED)
@@ -75,17 +73,18 @@ void HAL_init(void) {
#endif
// Init Servo Pins
- #if PIN_EXISTS(SERVO0)
- OUT_WRITE(SERVO0_PIN, LOW);
+ #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
+ #if HAS_SERVO_0
+ INIT_SERVO(0);
#endif
- #if PIN_EXISTS(SERVO1)
- OUT_WRITE(SERVO1_PIN, LOW);
+ #if HAS_SERVO_1
+ INIT_SERVO(1);
#endif
- #if PIN_EXISTS(SERVO2)
- OUT_WRITE(SERVO2_PIN, LOW);
+ #if HAS_SERVO_2
+ INIT_SERVO(2);
#endif
- #if PIN_EXISTS(SERVO3)
- OUT_WRITE(SERVO3_PIN, LOW);
+ #if HAS_SERVO_3
+ INIT_SERVO(3);
#endif
//debug_frmwrk_init();
@@ -99,6 +98,26 @@ void HAL_init(void) {
OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH);
#endif
+ #ifdef LPC1768_ENABLE_CLKOUT_12M
+ /**
+ * CLKOUTCFG register
+ * bit 8 (CLKOUT_EN) = enables CLKOUT signal. Disabled for now to prevent glitch when enabling GPIO.
+ * bits 7:4 (CLKOUTDIV) = set to 0 for divider setting of /1
+ * bits 3:0 (CLKOUTSEL) = set to 1 to select main crystal oscillator as CLKOUT source
+ */
+ LPC_SC->CLKOUTCFG = (0<<8)|(0<<4)|(1<<0);
+ // set P1.27 pin to function 01 (CLKOUT)
+ PINSEL_CFG_Type PinCfg;
+ PinCfg.Portnum = 1;
+ PinCfg.Pinnum = 27;
+ PinCfg.Funcnum = 1; // function 01 (CLKOUT)
+ PinCfg.OpenDrain = 0; // not open drain
+ PinCfg.Pinmode = 2; // no pull-up/pull-down
+ PINSEL_ConfigPin(&PinCfg);
+ // now set CLKOUT_EN bit
+ LPC_SC->CLKOUTCFG |= (1<<8);
+ #endif
+
USB_Init(); // USB Initialization
USB_Connect(FALSE); // USB clear connection
delay(1000); // Give OS time to notice
@@ -130,16 +149,16 @@ void HAL_init(void) {
}
// HAL idle task
-void HAL_idletask(void) {
+void HAL_idletask() {
#if ENABLED(SHARED_SD_CARD)
// If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
// this will not reliably detect delete operations. To be safe we will lock
- // the disk if Marlin has it mounted. Unfortuately there is currently no way
+ // the disk if Marlin has it mounted. Unfortunately there is currently no way
// to unmount the disk from the LCD menu.
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
- if (card.isDetected())
+ if (card.isMounted())
MSC_Aquire_Lock();
else
MSC_Release_Lock();
diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
index dac7d7a3a93a..3de02022eb65 100644
--- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
@@ -46,7 +46,7 @@
#if ENABLED(FLASH_EEPROM_EMULATION)
extern "C" {
- #include "lpc17xx_iap.h"
+ #include
}
#define SECTOR_START(sector) ((sector < 16) ? (sector * 0x1000) : ((sector - 14) * 0x8000))
diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
index b12076904103..2454dea19577 100644
--- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
@@ -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 d14b14385c22..133cd11be26e 100644
--- a/Marlin/src/HAL/HAL_LPC1768/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_LPC1768/pinsDebug.h
@@ -32,54 +32,22 @@
#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"), LPC176x::pin_port(p), LPC176x::pin_bit(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
-// uses pin index
#ifndef M43_NEVER_TOUCH
- #define M43_NEVER_TOUCH(Q) ((Q) == 29 || (Q) == 30 || (Q) == 73) // USB pins
+ #define M43_NEVER_TOUCH(Q) ((Q) == P0_29 || (Q) == P0_30 || (Q) == P2_09) // USB pins
#endif
-// active ADC function/mode/code values for PINSEL registers
-constexpr int8_t ADC_pin_mode(pin_t pin) {
- return (LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 2 ? 2 :
- LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 3 ? 2 :
- LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 23 ? 1 :
- LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 24 ? 1 :
- LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 25 ? 1 :
- LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 26 ? 1 :
- LPC1768_PIN_PORT(pin) == 1 && LPC1768_PIN_PIN(pin) == 30 ? 3 :
- LPC1768_PIN_PORT(pin) == 1 && LPC1768_PIN_PIN(pin) == 31 ? 3 : -1);
-}
-
-int8_t get_pin_mode(pin_t pin) {
- if (!VALID_PIN(pin)) return -1;
- uint8_t pin_port = LPC1768_PIN_PORT(pin);
- uint8_t pin_port_pin = LPC1768_PIN_PIN(pin);
- //get appropriate PINSEL register
- volatile uint32_t * pinsel_reg = (pin_port == 0 && pin_port_pin <= 15) ? &LPC_PINCON->PINSEL0 :
- (pin_port == 0) ? &LPC_PINCON->PINSEL1 :
- (pin_port == 1 && pin_port_pin <= 15) ? &LPC_PINCON->PINSEL2 :
- pin_port == 1 ? &LPC_PINCON->PINSEL3 :
- pin_port == 2 ? &LPC_PINCON->PINSEL4 :
- pin_port == 3 ? &LPC_PINCON->PINSEL7 : &LPC_PINCON->PINSEL9;
- uint8_t pinsel_start_bit = pin_port_pin > 15 ? 2 * (pin_port_pin - 16) : 2 * pin_port_pin;
- int8_t pin_mode = (int8_t) ((*pinsel_reg >> pinsel_start_bit) & 0x3);
- return pin_mode;
-}
-
-bool GET_PINMODE(pin_t pin) {
- int8_t pin_mode = get_pin_mode(pin);
- if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
+bool GET_PINMODE(const pin_t pin) {
+ if (!LPC176x::pin_is_valid(pin) || LPC176x::pin_adc_enabled(pin)) // found an invalid pin or active analog pin
return false;
- uint32_t * FIO_reg[5] PROGMEM = {(uint32_t*) 0x2009C000,(uint32_t*) 0x2009C020,(uint32_t*) 0x2009C040,(uint32_t*) 0x2009C060,(uint32_t*) 0x2009C080};
- return ((*FIO_reg[LPC1768_PIN_PORT(pin)] >> LPC1768_PIN_PIN(pin) & 1) != 0); //input/output state
+ return LPC176x::gpio_direction(pin);
}
-bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
- return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
+bool GET_ARRAY_IS_DIGITAL(const pin_t pin) {
+ return (!LPC176x::pin_has_adc(pin) || !LPC176x::pin_adc_enabled(pin));
}
diff --git a/Marlin/src/HAL/HAL_LPC1768/spi_pins.h b/Marlin/src/HAL/HAL_LPC1768/spi_pins.h
index 2e17abd31c7c..acf991a9d790 100644
--- a/Marlin/src/HAL/HAL_LPC1768/spi_pins.h
+++ b/Marlin/src/HAL/HAL_LPC1768/spi_pins.h
@@ -25,7 +25,7 @@
#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 97%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp
rename to Marlin/src/HAL/HAL_LPC1768/timers.cpp
index 2274630ca88b..7bf7ff388051 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/timers.cpp
@@ -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 89%
rename from Marlin/src/HAL/HAL_LPC1768/HAL_timers.h
rename to Marlin/src/HAL/HAL_LPC1768/timers.h
index 1d68ee8478f9..5f4e06265eab 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h
+++ b/Marlin/src/HAL/HAL_LPC1768/timers.h
@@ -25,10 +25,6 @@
* HAL For LPC1768
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "../../core/macros.h"
@@ -51,19 +47,19 @@
#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;
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
-#define HAL_TIMER_RATE ((SystemCoreClock) / 4) // frequency of timers peripherals
+#define HAL_TIMER_RATE ((F_CPU) / 4) // frequency of timers peripherals
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
@@ -95,10 +91,10 @@ typedef uint32_t hal_timer_t;
#define STEP_TIMER _HAL_TIMER(STEP_TIMER_NUM)
#define TEMP_TIMER _HAL_TIMER(TEMP_TIMER_NUM)
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
-void HAL_timer_init(void);
+// ------------------------
+void HAL_timer_init();
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.cpp
similarity index 96%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.cpp
index 41a19d430f84..9a95b1b66024 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_I2C_routines.cpp
@@ -25,6 +25,8 @@
#ifdef TARGET_LPC1768
+extern int millis();
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -35,6 +37,7 @@
#include "../../../core/millis_t.h"
+
//////////////////////////////////////////////////////////////////////////////////////
// These two routines are exact copies of the lpc17xx_i2c.c routines. Couldn't link to
@@ -151,19 +154,18 @@ void u8g_i2c_init(uint8_t clock_option) {
u8g_i2c_start(0); // send slave address and write bit
}
-volatile extern millis_t _millis;
uint8_t u8g_i2c_send_byte(uint8_t data) {
#define I2C_TIMEOUT 3
LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data
LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
- const millis_t timeout = _millis + I2C_TIMEOUT;
- while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && PENDING(_millis, timeout)); // wait for xmit to finish
+ const millis_t timeout = millis() + I2C_TIMEOUT;
+ while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && PENDING(millis(), timeout)); // wait for xmit to finish
// had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens
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 97%
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 11e05ba0d0b6..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
@@ -25,4 +25,4 @@ 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 100%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_defines.h
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_defines.h
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 95%
rename from Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_delay.h
rename to Marlin/src/HAL/HAL_LPC1768/u8g/LCD_delay.h
index f37773d21cbe..8806e8747704 100644
--- a/Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_delay.h
+++ b/Marlin/src/HAL/HAL_LPC1768/u8g/LCD_delay.h
@@ -35,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 100%
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
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 100%
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
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 e93ff8b08dce..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
@@ -138,7 +138,7 @@ uint8_t u8g_i2c_start_sw(uint8_t sla) { // assert start condition and then send
}
-void u8g_i2c_stop_sw(void) { }
+void u8g_i2c_stop_sw() { }
void u8g_i2c_init_sw(uint8_t clock_option) { u8g_i2c_start(0); } // send slave address and write bit
diff --git a/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
index 59414e896b1e..0a1bd84875cf 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
@@ -60,7 +60,7 @@
#if ENABLED(U8GLIB_ST7920)
#include
-#include "SoftwareSPI.h"
+#include
#include "../../shared/Delay.h"
#undef SPI_SPEED
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 e243d4001367..7b6557148ada 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
@@ -59,7 +59,7 @@
#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
-#include "SoftwareSPI.h"
+#include
#undef SPI_SPEED
#define SPI_SPEED 2 // About 2 MHz
@@ -75,25 +75,25 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
for (uint8_t i = 0; i < 8; i++) {
if (spi_speed == 0) {
- gpio_set(mosi_pin, !!(b & 0x80));
- gpio_set(sck_pin, HIGH);
+ LPC176x::gpio_set(mosi_pin, !!(b & 0x80));
+ LPC176x::gpio_set(sck_pin, HIGH);
b <<= 1;
- if (miso_pin >= 0 && gpio_get(miso_pin)) b |= 1;
- gpio_set(sck_pin, LOW);
+ if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
+ LPC176x::gpio_set(sck_pin, LOW);
}
else {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
- gpio_set(mosi_pin, state);
+ LPC176x::gpio_set(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
- gpio_set(sck_pin, HIGH);
+ LPC176x::gpio_set(sck_pin, HIGH);
b <<= 1;
- if (miso_pin >= 0 && gpio_get(miso_pin)) b |= 1;
+ if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
- gpio_set(sck_pin, LOW);
+ LPC176x::gpio_set(sck_pin, LOW);
}
}
@@ -105,23 +105,23 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
for (uint8_t i = 0; i < 8; i++) {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
if (spi_speed == 0) {
- gpio_set(sck_pin, LOW);
- gpio_set(mosi_pin, state);
- gpio_set(mosi_pin, state); // need some setup time
- gpio_set(sck_pin, HIGH);
+ LPC176x::gpio_set(sck_pin, LOW);
+ LPC176x::gpio_set(mosi_pin, state);
+ LPC176x::gpio_set(mosi_pin, state); // need some setup time
+ LPC176x::gpio_set(sck_pin, HIGH);
}
else {
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
- gpio_set(sck_pin, LOW);
+ LPC176x::gpio_set(sck_pin, LOW);
for (uint8_t j = 0; j < spi_speed; j++)
- gpio_set(mosi_pin, state);
+ LPC176x::gpio_set(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed; j++)
- gpio_set(sck_pin, HIGH);
+ LPC176x::gpio_set(sck_pin, HIGH);
}
b <<= 1;
- if (miso_pin >= 0 && gpio_get(miso_pin)) b |= 1;
+ if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
}
return b;
@@ -130,7 +130,7 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
static uint8_t SPI_speed = 0;
static void u8g_sw_spi_HAL_LPC1768_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) {
- #if ENABLED(FYSETC_MINI_12864)
+ #if EITHER(FYSETC_MINI_12864, MKS_MINI_12864)
swSpiTransfer_mode_3(val, SPI_speed, clockPin, -1, dataPin);
#else
swSpiTransfer_mode_0(val, SPI_speed, clockPin, -1, dataPin);
@@ -158,10 +158,10 @@ 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:
- #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
+ #if EITHER(FYSETC_MINI_12864, MKS_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 {
diff --git a/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py b/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
old mode 100644
new mode 100755
index 36242c96059d..b3ab59026eb4
--- a/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
+++ b/Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
@@ -17,7 +17,7 @@ def print_error(e):
print('\nUnable to find destination disk (' + e + ')\n' \
'Please select it in platformio.ini using the upload_port keyword ' \
'(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \
- 'or copy the firmware (.pioenvs/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n')
+ 'or copy the firmware (.pio/build/' + env.get('PIOENV') + '/firmware.bin) manually to the appropriate disk\n')
try:
if current_OS == 'Windows':
@@ -31,9 +31,11 @@ def print_error(e):
#
import subprocess
# typical result (string): 'Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
- driveStr = subprocess.check_output("fsutil fsinfo drives")
+ driveStr = str(subprocess.check_output("fsutil fsinfo drives"))
# typical result (string): 'C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ Y:\ Z:\'
- driveStr = driveStr.strip().lstrip('Drives: ')
+ # driveStr = driveStr.strip().lstrip('Drives: ') <- Doesn't work in other Languages as English. In German is "Drives:" = "Laufwerke:"
+ FirstFound = driveStr.find(':',0,-1) # Find the first ":" and
+ driveStr = driveStr[FirstFound + 1 : -1] # truncate to the rest
# typical result (array of stings): ['C:\\', 'D:\\', 'E:\\', 'F:\\',
# 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'Y:\\', 'Z:\\']
drives = driveStr.split()
@@ -44,7 +46,7 @@ def print_error(e):
for drive in drives:
final_drive_name = drive.strip().rstrip('\\') # typical result (string): 'C:'
try:
- volume_info = subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)
+ volume_info = str(subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT))
except Exception as e:
continue
else:
diff --git a/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp b/Marlin/src/HAL/HAL_LPC1768/usb_serial.cpp
index 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 e6729ff58fcc..6d0200e9f1e9 100644
--- a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
@@ -26,10 +26,10 @@
#if ENABLED(USE_WATCHDOG)
-#include "lpc17xx_wdt.h"
+#include
#include "watchdog.h"
-void watchdog_init(void) {
+void watchdog_init() {
#if ENABLED(WATCHDOG_RESET_MANUAL)
// We enable the watchdog timer, but only for the interrupt.
@@ -56,28 +56,16 @@ void watchdog_init(void) {
WDT_Start(WDT_TIMEOUT);
}
-void HAL_clear_reset_source(void) {
- WDT_ClrTimeOutFlag();
-}
-
-uint8_t HAL_get_reset_source(void) {
- if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
- return RST_POWER_ON;
-}
-
-void watchdog_reset() {
+void HAL_watchdog_refresh() {
WDT_Feed();
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
-#else
-
-void watchdog_init(void) {}
-void watchdog_reset(void) {}
-void HAL_clear_reset_source(void) {}
-uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
+// Timeout state
+bool watchdog_timed_out() { return TEST(WDT_ReadTimeOutFlag(), 0); }
+void watchdog_clear_timeout_flag() { WDT_ClrTimeOutFlag(); }
#endif // USE_WATCHDOG
diff --git a/Marlin/src/HAL/HAL_LPC1768/watchdog.h b/Marlin/src/HAL/HAL_LPC1768/watchdog.h
index 04ce17fe9d52..dd6617ea315a 100644
--- a/Marlin/src/HAL/HAL_LPC1768/watchdog.h
+++ b/Marlin/src/HAL/HAL_LPC1768/watchdog.h
@@ -23,7 +23,8 @@
#define WDT_TIMEOUT 4000000 // 4 second timeout
-void watchdog_init(void);
-void watchdog_reset(void);
-void HAL_clear_reset_source(void);
-uint8_t HAL_get_reset_source(void);
+void watchdog_init();
+void HAL_watchdog_refresh();
+
+bool watchdog_timed_out();
+void watchdog_clear_timeout_flag();
diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL.cpp b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp
new file mode 100644
index 000000000000..1c53042f8d5e
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp
@@ -0,0 +1,478 @@
+/**
+ * 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
+#include
+
+// ------------------------
+// Local defines
+// ------------------------
+
+#if HAS_TEMP_ADC_0
+ #define GET_TEMP_0_ADC() PIN_TO_ADC(TEMP_0_PIN)
+#else
+ #define GET_TEMP_0_ADC() -1
+#endif
+#if HAS_TEMP_ADC_1
+ #define GET_TEMP_1_ADC() PIN_TO_ADC(TEMP_1_PIN)
+#else
+ #define GET_TEMP_1_ADC() -1
+#endif
+#if HAS_TEMP_ADC_2
+ #define GET_TEMP_2_ADC() PIN_TO_ADC(TEMP_2_PIN)
+#else
+ #define GET_TEMP_2_ADC() -1
+#endif
+#if HAS_TEMP_ADC_3
+ #define GET_TEMP_3_ADC() PIN_TO_ADC(TEMP_3_PIN)
+#else
+ #define GET_TEMP_3_ADC() -1
+#endif
+#if HAS_TEMP_ADC_4
+ #define GET_TEMP_4_ADC() PIN_TO_ADC(TEMP_4_PIN)
+#else
+ #define GET_TEMP_4_ADC() -1
+#endif
+#if HAS_TEMP_ADC_5
+ #define GET_TEMP_5_ADC() PIN_TO_ADC(TEMP_5_PIN)
+#else
+ #define GET_TEMP_5_ADC() -1
+#endif
+#if HAS_TEMP_ADC_BED
+ #define GET_BED_ADC() PIN_TO_ADC(TEMP_BED_PIN)
+#else
+ #define GET_BED_ADC() -1
+#endif
+#if HAS_TEMP_ADC_CHAMBER
+ #define GET_CHAMBER_ADC() PIN_TO_ADC(TEMP_CHAMBER_PIN)
+#else
+ #define GET_CHAMBER_ADC() -1
+#endif
+#if ENABLED(FILAMENT_WIDTH_SENSOR)
+ #define GET_FILAMENT_WIDTH_ADC() PIN_TO_ADC(FILWIDTH_PIN)
+#else
+ #define GET_FILAMENT_WIDTH_ADC() -1
+#endif
+#if HAS_ADC_BUTTONS
+ #define GET_BUTTONS_ADC() PIN_TO_ADC(ADC_KEYPAD_PIN)
+#else
+ #define GET_BUTTONS_ADC() -1
+#endif
+
+#define IS_ADC_REQUIRED(n) (GET_TEMP_0_ADC() == n || GET_TEMP_1_ADC() == n || GET_TEMP_2_ADC() == n \
+ || GET_TEMP_3_ADC() == n || GET_TEMP_4_ADC() == n || GET_TEMP_5_ADC() == n \
+ || GET_BED_ADC() == n \
+ || GET_CHAMBER_ADC() == n \
+ || GET_FILAMENT_WIDTH_ADC() == n \
+ || GET_BUTTONS_ADC() == n)
+
+#define ADC0_IS_REQUIRED IS_ADC_REQUIRED(0)
+#define ADC1_IS_REQUIRED IS_ADC_REQUIRED(1)
+#define ADC_IS_REQUIRED (ADC0_IS_REQUIRED || ADC1_IS_REQUIRED)
+#if ADC0_IS_REQUIRED
+ #define FIRST_ADC 0
+#else
+ #define FIRST_ADC 1
+#endif
+#if ADC1_IS_REQUIRED
+ #define LAST_ADC 1
+#else
+ #define LAST_ADC 0
+#endif
+
+#define DMA_IS_REQUIRED ADC_IS_REQUIRED
+
+// ------------------------
+// Types
+// ------------------------
+
+#if DMA_IS_REQUIRED
+
+ // Struct must be 32 bits aligned because of DMA accesses but fields needs to be 8 bits packed
+ typedef struct __attribute__((aligned(4), packed)) {
+ ADC_INPUTCTRL_Type INPUTCTRL;
+ } HAL_DMA_DAC_Registers; // DMA transfered registers
+
+#endif
+
+// ------------------------
+// Private Variables
+// ------------------------
+
+uint16_t HAL_adc_result;
+
+#if ADC_IS_REQUIRED
+
+ // Pins used by ADC inputs. Order must be ADC0 inputs first then ADC1
+ const uint8_t adc_pins[] = {
+ // ADC0 pins
+ #if GET_TEMP_0_ADC() == 0
+ TEMP_0_PIN,
+ #endif
+ #if GET_TEMP_1_ADC() == 0
+ TEMP_1_PIN,
+ #endif
+ #if GET_TEMP_2_ADC() == 0
+ TEMP_2_PIN,
+ #endif
+ #if GET_TEMP_3_ADC() == 0
+ TEMP_3_PIN,
+ #endif
+ #if GET_TEMP_4_ADC() == 0
+ TEMP_4_PIN,
+ #endif
+ #if GET_TEMP_5_ADC() == 0
+ TEMP_5_PIN,
+ #endif
+ #if GET_BED_ADC() == 0
+ TEMP_BED_PIN,
+ #endif
+ #if GET_CHAMBER_ADC() == 0
+ TEMP_CHAMBER_PIN,
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 0
+ FILWIDTH_PIN,
+ #endif
+ #if GET_BUTTONS_ADC() == 0
+ ADC_KEYPAD_PIN,
+ #endif
+ // ADC1 pins
+ #if GET_TEMP_0_ADC() == 1
+ TEMP_0_PIN,
+ #endif
+ #if GET_TEMP_1_ADC() == 1
+ TEMP_1_PIN,
+ #endif
+ #if GET_TEMP_2_ADC() == 1
+ TEMP_2_PIN,
+ #endif
+ #if GET_TEMP_3_ADC() == 1
+ TEMP_3_PIN,
+ #endif
+ #if GET_TEMP_4_ADC() == 1
+ TEMP_4_PIN,
+ #endif
+ #if GET_TEMP_5_ADC() == 1
+ TEMP_5_PIN,
+ #endif
+ #if GET_BED_ADC() == 1
+ TEMP_BED_PIN,
+ #endif
+ #if GET_CHAMBER_ADC() == 1
+ TEMP_CHAMBER_PIN,
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 1
+ FILWIDTH_PIN,
+ #endif
+ #if GET_BUTTONS_ADC() == 1
+ ADC_KEYPAD_PIN,
+ #endif
+ };
+
+ uint16_t HAL_adc_results[COUNT(adc_pins)];
+
+ #if ADC0_IS_REQUIRED
+ Adafruit_ZeroDMA adc0DMAProgram,
+ adc0DMARead;
+
+ const HAL_DMA_DAC_Registers adc0_dma_regs_list[] = {
+ #if GET_TEMP_0_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_0_PIN) },
+ #endif
+ #if GET_TEMP_1_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_1_PIN) },
+ #endif
+ #if GET_TEMP_2_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_2_PIN) },
+ #endif
+ #if GET_TEMP_3_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_3_PIN) },
+ #endif
+ #if GET_TEMP_4_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_4_PIN) },
+ #endif
+ #if GET_TEMP_5_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_5_PIN) },
+ #endif
+ #if GET_BED_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_BED_PIN) },
+ #endif
+ #if GET_CHAMBER_ADC() == 0
+ { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 0
+ { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
+ #endif
+ #if GET_BUTTONS_ADC() == 0
+ { PIN_TO_INPUTCTRL(ADC_KEYPAD_PIN) },
+ #endif
+ };
+
+ #define ADC0_AINCOUNT COUNT(adc0_dma_regs_list)
+ #endif // ADC0_IS_REQUIRED
+
+ #if ADC1_IS_REQUIRED
+ Adafruit_ZeroDMA adc1DMAProgram,
+ adc1DMARead;
+
+ const HAL_DMA_DAC_Registers adc1_dma_regs_list[] = {
+ #if GET_TEMP_0_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_0_PIN) },
+ #endif
+ #if GET_TEMP_1_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_1_PIN) },
+ #endif
+ #if GET_TEMP_2_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_2_PIN) },
+ #endif
+ #if GET_TEMP_3_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_3_PIN) },
+ #endif
+ #if GET_TEMP_4_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_4_PIN) },
+ #endif
+ #if GET_TEMP_5_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_5_PIN) },
+ #endif
+ #if GET_BED_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_BED_PIN) },
+ #endif
+ #if GET_CHAMBER_ADC() == 1
+ { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
+ #endif
+ #if GET_FILAMENT_WIDTH_ADC() == 1
+ { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
+ #endif
+ #if GET_BUTTONS_ADC() == 1
+ { PIN_TO_INPUTCTRL(ADC_KEYPAD_PIN) },
+ #endif
+ };
+
+ #define ADC1_AINCOUNT COUNT(adc1_dma_regs_list)
+ #endif // ADC1_IS_REQUIRED
+
+#endif // ADC_IS_REQUIRED
+
+// ------------------------
+// Private functions
+// ------------------------
+
+#if DMA_IS_REQUIRED
+
+ void dma_init() {
+ DmacDescriptor *descriptor;
+
+ #if ADC0_IS_REQUIRED
+ adc0DMAProgram.setTrigger(ADC0_DMAC_ID_SEQ);
+ adc0DMAProgram.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc0DMAProgram.loop(true);
+ if (adc0DMAProgram.allocate() == DMA_STATUS_OK) {
+ descriptor = adc0DMAProgram.addDescriptor(
+ (void *)adc0_dma_regs_list, // SRC
+ (void *)&ADC0->DSEQDATA.reg, // DEST
+ sizeof(adc0_dma_regs_list) / 4, // CNT
+ DMA_BEAT_SIZE_WORD,
+ true, // SRCINC
+ false, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_SRC // STEPSEL
+ );
+ if (descriptor != nullptr)
+ descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
+ adc0DMAProgram.startJob();
+ }
+
+ adc0DMARead.setTrigger(ADC0_DMAC_ID_RESRDY);
+ adc0DMARead.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc0DMARead.loop(true);
+ if (adc0DMARead.allocate() == DMA_STATUS_OK) {
+ adc0DMARead.addDescriptor(
+ (void *)&ADC0->RESULT.reg, // SRC
+ &HAL_adc_results, // DEST
+ ADC0_AINCOUNT, // CNT
+ DMA_BEAT_SIZE_HWORD,
+ false, // SRCINC
+ true, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_DST // STEPSEL
+ );
+ adc0DMARead.startJob();
+ }
+ #endif
+ #if ADC1_IS_REQUIRED
+ adc1DMAProgram.setTrigger(ADC1_DMAC_ID_SEQ);
+ adc1DMAProgram.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc1DMAProgram.loop(true);
+ if (adc1DMAProgram.allocate() == DMA_STATUS_OK) {
+ descriptor = adc1DMAProgram.addDescriptor(
+ (void *)adc1_dma_regs_list, // SRC
+ (void *)&ADC1->DSEQDATA.reg, // DEST
+ sizeof(adc1_dma_regs_list) / 4, // CNT
+ DMA_BEAT_SIZE_WORD,
+ true, // SRCINC
+ false, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_SRC // STEPSEL
+ );
+ if (descriptor != nullptr)
+ descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
+ adc1DMAProgram.startJob();
+ }
+
+ adc1DMARead.setTrigger(ADC1_DMAC_ID_RESRDY);
+ adc1DMARead.setAction(DMA_TRIGGER_ACTON_BEAT);
+ adc1DMARead.loop(true);
+ if (adc1DMARead.allocate() == DMA_STATUS_OK) {
+ adc1DMARead.addDescriptor(
+ (void *)&ADC1->RESULT.reg, // SRC
+ &HAL_adc_results[ADC0_AINCOUNT], // DEST
+ ADC1_AINCOUNT, // CNT
+ DMA_BEAT_SIZE_HWORD,
+ false, // SRCINC
+ true, // DSTINC
+ DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
+ DMA_STEPSEL_DST // STEPSEL
+ );
+ adc1DMARead.startJob();
+ }
+ #endif
+
+ DMAC->PRICTRL0.bit.RRLVLEN0 = true; // Activate round robin for DMA channels required by ADCs
+ }
+
+#endif // DMA_IS_REQUIRED
+
+// ------------------------
+// Public functions
+// ------------------------
+
+// HAL initialization task
+void HAL_init() {
+ #if DMA_IS_REQUIRED
+ dma_init();
+ #endif
+ #if ENABLED(SDSUPPORT)
+ // SD_DETECT_PIN may be removed if NO_SD_HOST_DRIVE is not defined in Configuration_adv.h
+ #if SD_CONNECTION_IS(ONBOARD) && PIN_EXISTS(SD_DETECT)
+ SET_INPUT_PULLUP(SD_DETECT_PIN);
+ #endif
+ OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
+ #endif
+}
+
+// HAL idle task
+/*
+void HAL_idletask() {
+}
+*/
+
+void HAL_clear_reset_source() { }
+
+#pragma push_macro("WDT")
+#undef WDT // Required to be able to use '.bit.WDT'. Compiler wrongly replace struct field with WDT define
+uint8_t HAL_get_reset_source() {
+ RSTC_RCAUSE_Type resetCause;
+
+ resetCause.reg = REG_RSTC_RCAUSE;
+ if (resetCause.bit.POR) return RST_POWER_ON;
+ else if (resetCause.bit.EXT) return RST_EXTERNAL;
+ else if (resetCause.bit.BODCORE || resetCause.bit.BODVDD) return RST_BROWN_OUT;
+ else if (resetCause.bit.WDT) return RST_WATCHDOG;
+ else if (resetCause.bit.SYST || resetCause.bit.NVM) return RST_SOFTWARE;
+ else if (resetCause.bit.BACKUP) return RST_BACKUP;
+ return 0;
+}
+#pragma pop_macro("WDT")
+
+extern "C" {
+ void * _sbrk(int incr);
+
+ extern unsigned int __bss_end__; // end of bss section
+}
+
+// Return free memory between end of heap (or end bss) and whatever is current
+int freeMemory() {
+ int free_memory, heap_end = (int)_sbrk(0);
+ return (int)&free_memory - (heap_end ?: (int)&__bss_end__);
+}
+
+// ------------------------
+// ADC
+// ------------------------
+
+void HAL_adc_init() {
+ #if ADC_IS_REQUIRED
+ memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results)); // Fill result with invalid values
+
+ for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi)
+ pinPeripheral(adc_pins[pi], PIO_ANALOG);
+
+ for (uint8_t ai = FIRST_ADC; ai <= LAST_ADC; ++ai) {
+ Adc* adc = ((Adc*[])ADC_INSTS)[ai];
+
+ // ADC clock setup
+ GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN = false;
+ SYNC(GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN);
+ GCLK->PCHCTRL[ADC0_GCLK_ID + ai].reg = GCLK_PCHCTRL_GEN_GCLK1 | GCLK_PCHCTRL_CHEN; // 48MHz startup code programmed
+ SYNC(!GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN);
+ adc->CTRLA.bit.PRESCALER = ADC_CTRLA_PRESCALER_DIV32_Val; // 1.5MHZ adc clock
+
+ // ADC setup
+ // Preloaded data (fixed for all ADC instances hence not loaded by DMA)
+ adc->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val; // VRefA pin
+ SYNC(adc->SYNCBUSY.bit.REFCTRL);
+ adc->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_12BIT_Val;
+ SYNC(adc->SYNCBUSY.bit.CTRLB);
+ adc->SAMPCTRL.bit.SAMPLEN = (6 - 1); // Sampling clocks
+ adc->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_16 | ADC_AVGCTRL_ADJRES(4); // 16 Accumulated conversions and shift 4 to get oversampled 12 bits result
+ SYNC(adc->SYNCBUSY.bit.AVGCTRL);
+ // 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..dea84da5d1e8
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/HAL.h
@@ -0,0 +1,158 @@
+/**
+ * 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_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL
+#define HAL_ADC_RESOLUTION 12
+#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 85%
rename from Marlin/src/HAL/HAL_STM32F7/spi_pins.h
rename to Marlin/src/HAL/HAL_SAMD51/MarlinSerial_AGCM4.h
index 267cba6fd00b..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]
+ * 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..24340439669d
--- /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_STM32F7/watchdog_STM32F7.cpp b/Marlin/src/HAL/HAL_SAMD51/watchdog.cpp
similarity index 50%
rename from Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.cpp
rename to Marlin/src/HAL/HAL_SAMD51/watchdog.cpp
index 8b75454dadc5..69a6de4ef759 100644
--- a/Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.cpp
+++ b/Marlin/src/HAL/HAL_SAMD51/watchdog.cpp
@@ -1,9 +1,8 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
- * Based on Sprinter and grbl.
- * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,33 +19,35 @@
*
*/
-#ifdef STM32F7
+#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
#if ENABLED(USE_WATCHDOG)
- #include "watchdog_STM32F7.h"
-
- IWDG_HandleTypeDef hiwdg;
+ #include "watchdog.h"
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();
- }
- }
+ // The low-power oscillator used by the WDT runs at 32,768 Hz with
+ // a 1:32 prescale, thus 1024 Hz, though probably not super precise.
+
+ // Setup WDT clocks
+ MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
+ MCLK->APBAMASK.bit.WDT_ = true;
+ OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
+
+ WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config
+ SYNC(WDT->SYNCBUSY.bit.ENABLE);
+
+ WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt
+ WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096; // Set at least 4s period for chip reset
+
+ HAL_watchdog_refresh();
- void watchdog_reset() {
- /* Refresh IWDG: reload counter */
- if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
- /* Refresh Error */
- //Error_Handler();
- }
+ WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode
+ SYNC(WDT->SYNCBUSY.bit.ENABLE);
}
#endif // USE_WATCHDOG
-#endif // STM32F7
+#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..b626b0b06ae1
--- /dev/null
+++ b/Marlin/src/HAL/HAL_SAMD51/watchdog.h
@@ -0,0 +1,31 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+// Initialize watchdog with a 4 second interrupt time
+void watchdog_init();
+
+// Reset watchdog. MUST be called at least every 4 seconds after the
+// first watchdog_init or SAMD will go into emergency procedures.
+inline void HAL_watchdog_refresh() {
+ SYNC(WDT->SYNCBUSY.bit.CLEAR); // Test first if previous is 'ongoing' to save time waiting for command execution
+ WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
+}
diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp
index 8eb3c588f65c..4fbfa7298ca0 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL.cpp
+++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp
@@ -28,54 +28,35 @@
#include "../../inc/MarlinConfig.h"
#include "../shared/Delay.h"
-#if ENABLED(EEPROM_EMULATED_WITH_SRAM)
+#if (__cplusplus == 201703L) && defined(__has_include)
+ #define HAS_SWSERIAL __has_include()
+#else
+ #define HAS_SWSERIAL HAS_TMC220x
+#endif
+
+#if HAS_SWSERIAL
+ #include "SoftwareSerial.h"
+#endif
+
+#if ENABLED(SRAM_EEPROM_EMULATION)
#if STM32F7xx
- #include "stm32f7xx_ll_pwr.h"
+ #include
#elif STM32F4xx
- #include "stm32f4xx_ll_pwr.h"
+ #include
#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
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
-
+// ------------------------
// Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
@@ -89,7 +70,7 @@ uint16_t HAL_adc_result;
#endif
// HAL initialization task
-void HAL_init(void) {
+void HAL_init() {
FastIO_init();
#if ENABLED(SDSUPPORT)
@@ -100,7 +81,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();
@@ -111,11 +92,15 @@ void HAL_init(void) {
// Wait until backup regulator is initialized
while (!LL_PWR_IsActiveFlag_BRR());
#endif // EEPROM_EMULATED_SRAM
+
+ #if HAS_SWSERIAL
+ SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0);
+ #endif
}
-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;
@@ -129,16 +114,15 @@ extern "C" {
extern unsigned int _ebss; // end of bss section
}
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
-void HAL_adc_start_conversion(const uint8_t adc_pin) {
- HAL_adc_result = analogRead(adc_pin);
-}
+// TODO: Make sure this doesn't cause any delay
+void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
-uint16_t HAL_adc_get_result(void) {
- return HAL_adc_result;
-}
+uint16_t HAL_adc_get_result() { return HAL_adc_result; }
+
+void flashFirmware(int16_t) { NVIC_SystemReset(); }
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/HAL.h b/Marlin/src/HAL/HAL_STM32/HAL.h
index cb810d3f9f95..910d437bd6b5 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL.h
+++ b/Marlin/src/HAL/HAL_STM32/HAL.h
@@ -24,16 +24,12 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../core/macros.h"
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_STM32.h"
-#include "watchdog_STM32.h"
+#include "fastio.h"
+#include "watchdog.h"
#include "../../inc/MarlinConfigPre.h"
@@ -43,9 +39,9 @@
#include
#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#if SERIAL_PORT == 0
#error "Serial port 0 does not exist"
@@ -100,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
@@ -128,56 +124,50 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
-typedef int8_t pin_t;
+typedef int16_t pin_t;
#define HAL_SERVO_LIB libServo
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
-/** result of last ADC conversion */
+// result of last ADC conversion
extern uint16_t HAL_adc_result;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
// Memory related
#define __bss_end __bss_end__
// Enable hooks into setup for HAL
-void HAL_init(void);
+void HAL_init();
-/** clear reset reason */
-void HAL_clear_reset_source (void);
+// Clear reset reason
+void HAL_clear_reset_source();
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
+// Reset reason
+uint8_t HAL_get_reset_source();
void _delay_ms(const int delay);
extern "C" char* _sbrk(int incr);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+
static inline int freeMemory() {
volatile char top;
return &top - reinterpret_cast(_sbrk(0));
}
-//
-// SPI: Extended functions which take a channel number (hardware SPI only)
-//
-
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
+#pragma GCC diagnostic pop
//
// EEPROM
@@ -186,8 +176,8 @@ uint8_t spiRec(uint32_t chan);
// Wire library should work for i2c EEPROMs
void eeprom_write_byte(uint8_t *pos, unsigned char value);
uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
+void eeprom_read_block(void *__dst, const void *__src, size_t __n);
+void eeprom_update_block(const void *__src, void *__dst, size_t __n);
//
// ADC
@@ -195,16 +185,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_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+
+#define PLATFORM_M997_SUPPORT
+void flashFirmware(int16_t value);
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp b/Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp
similarity index 70%
rename from Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp
index cde28e7e145f..45bd26d720b9 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp
@@ -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,7 +59,7 @@ 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
@@ -77,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();
}
@@ -97,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();
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp b/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp
deleted file mode 100644
index f309b43f3afb..000000000000
--- a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp
+++ /dev/null
@@ -1,118 +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(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
-
-#include "HAL_timers_STM32.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// 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
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// 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]) {
- uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
- temp_prescaler = TEMP_TIMER_PRESCALE - 1;
- switch (timer_num) {
- case STEP_TIMER_NUM:
- // STEPPER TIMER - use a 32bit timer if possible
- TimerHandle[timer_num].timer = STEP_TIMER_DEV;
- TimerHandle[timer_num].irqHandle = Step_Handler;
- TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
- HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0);
- break;
-
- case TEMP_TIMER_NUM:
- // TEMP TIMER - any available 16bit Timer
- TimerHandle[timer_num].timer = TEMP_TIMER_DEV;
- TimerHandle[timer_num].irqHandle = Temp_Handler;
- TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
- HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0);
- break;
- }
- timers_initialized[timer_num] = true;
- }
-}
-
-void HAL_timer_enable_interrupt(const uint8_t timer_num) {
- const IRQn_Type IRQ_Id = IRQn_Type(getTimerIrq(TimerHandle[timer_num].timer));
- HAL_NVIC_EnableIRQ(IRQ_Id);
-}
-
-void HAL_timer_disable_interrupt(const uint8_t timer_num) {
- const IRQn_Type IRQ_Id = IRQn_Type(getTimerIrq(TimerHandle[timer_num].timer));
- HAL_NVIC_DisableIRQ(IRQ_Id);
-
- // 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) {
- const uint32_t IRQ_Id = getTimerIrq(TimerHandle[timer_num].timer);
- return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F);
-}
-
-#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp b/Marlin/src/HAL/HAL_STM32/Servo.cpp
similarity index 68%
rename from Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/Servo.cpp
index fa68c4834235..9af8ba618484 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/Servo.cpp
@@ -26,29 +26,34 @@
#if HAS_SERVOS
-#include "HAL_Servo_STM32.h"
+#include "Servo.h"
-uint8_t servoPin[MAX_SERVOS] = { 0 };
+static uint_fast8_t servoCount = 0;
+constexpr millis_t servoDelay[] = SERVO_DELAY;
+static_assert(COUNT(servoDelay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
+
+libServo::libServo()
+: delay(servoDelay[servoCount++])
+{}
int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex]);
+ if (servoCount >= MAX_SERVOS) return -1;
+ if (pin > 0) servo_pin = pin;
+ return super::attach(servo_pin);
}
int8_t libServo::attach(const int pin, const int min, const int max) {
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex], min, max);
+ if (servoCount >= MAX_SERVOS) return -1;
+ if (pin > 0) servo_pin = pin;
+ return super::attach(servo_pin, min, max);
}
void libServo::move(const int value) {
- constexpr uint16_t servo_delay[] = SERVO_DELAY;
- static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(delay);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h b/Marlin/src/HAL/HAL_STM32/Servo.h
similarity index 89%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h
rename to Marlin/src/HAL/HAL_STM32/Servo.h
index e096dc60c8ed..ec4b6be131d2 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h
+++ b/Marlin/src/HAL/HAL_STM32/Servo.h
@@ -4,6 +4,7 @@
*
* 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
@@ -26,11 +27,13 @@
// Inherit and expand on the official library
class libServo : public Servo {
public:
+ libServo();
int8_t attach(const int pin);
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
private:
- uint16_t min_ticks;
- uint16_t max_ticks;
- uint8_t servoIndex; // index into the channel data for this servo
+ typedef Servo super;
+
+ int servo_pin = 0;
+ millis_t delay = 0;
};
diff --git a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp
new file mode 100644
index 000000000000..2d2883f4ce3b
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.cpp
@@ -0,0 +1,395 @@
+/*
+ * SoftwareSerial.cpp (formerly NewSoftSerial.cpp)
+ *
+ * Multi-instance software serial library for Arduino/Wiring
+ * -- Interrupt-driven receive and other improvements by ladyada
+ * (http://ladyada.net)
+ * -- Tuning, circular buffer, derivation from class Print/Stream,
+ * multi-instance support, porting to 8MHz processors,
+ * various optimizations, PROGMEM delay tables, inverse logic and
+ * direct port writing by Mikal Hart (http://www.arduiniana.org)
+ * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
+ * -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
+ * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
+ * -- STM32 support by Armin van der Togt
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * The latest version of this library can always be found at
+ * http://arduiniana.org.
+ */
+
+//
+// Includes
+//
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+
+#include "SoftwareSerial.h"
+#include "timers.h"
+
+#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge).
+
+// defined in bit-periods
+#define HALFDUPLEX_SWITCH_DELAY 5
+// It's best to define TIMER_SERIAL in variant.h. If not defined, we choose one here
+// The order is based on (lack of) features and compare channels, we choose the simplest available
+// because we only need an update interrupt
+#if !defined(TIMER_SERIAL)
+#if defined (TIM18_BASE)
+#define TIMER_SERIAL TIM18
+#elif defined (TIM7_BASE)
+#define TIMER_SERIAL TIM7
+#elif defined (TIM6_BASE)
+#define TIMER_SERIAL TIM6
+#elif defined (TIM22_BASE)
+#define TIMER_SERIAL TIM22
+#elif defined (TIM21_BASE)
+#define TIMER_SERIAL TIM21
+#elif defined (TIM17_BASE)
+#define TIMER_SERIAL TIM17
+#elif defined (TIM16_BASE)
+#define TIMER_SERIAL TIM16
+#elif defined (TIM15_BASE)
+#define TIMER_SERIAL TIM15
+#elif defined (TIM14_BASE)
+#define TIMER_SERIAL TIM14
+#elif defined (TIM13_BASE)
+#define TIMER_SERIAL TIM13
+#elif defined (TIM11_BASE)
+#define TIMER_SERIAL TIM11
+#elif defined (TIM10_BASE)
+#define TIMER_SERIAL TIM10
+#elif defined (TIM12_BASE)
+#define TIMER_SERIAL TIM12
+#elif defined (TIM19_BASE)
+#define TIMER_SERIAL TIM19
+#elif defined (TIM9_BASE)
+#define TIMER_SERIAL TIM9
+#elif defined (TIM5_BASE)
+#define TIMER_SERIAL TIM5
+#elif defined (TIM4_BASE)
+#define TIMER_SERIAL TIM4
+#elif defined (TIM3_BASE)
+#define TIMER_SERIAL TIM3
+#elif defined (TIM2_BASE)
+#define TIMER_SERIAL TIM2
+#elif defined (TIM20_BASE)
+#define TIMER_SERIAL TIM20
+#elif defined (TIM8_BASE)
+#define TIMER_SERIAL TIM8
+#elif defined (TIM1_BASE)
+#define TIMER_SERIAL TIM1
+#else
+#error No suitable timer found for SoftwareSerial, define TIMER_SERIAL in variant.h
+#endif
+#endif
+//
+// Statics
+//
+HardwareTimer SoftwareSerial::timer(TIMER_SERIAL);
+const IRQn_Type SoftwareSerial::timer_interrupt_number = static_cast(getTimerUpIrq(TIMER_SERIAL));
+uint32_t SoftwareSerial::timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), TIM_IRQ_PRIO, TIM_IRQ_SUBPRIO);
+SoftwareSerial *SoftwareSerial::active_listener = nullptr;
+SoftwareSerial *volatile SoftwareSerial::active_out = nullptr;
+SoftwareSerial *volatile SoftwareSerial::active_in = nullptr;
+int32_t SoftwareSerial::tx_tick_cnt = 0; // OVERSAMPLE ticks needed for a bit
+int32_t volatile SoftwareSerial::rx_tick_cnt = 0; // OVERSAMPLE ticks needed for a bit
+uint32_t SoftwareSerial::tx_buffer = 0;
+int32_t SoftwareSerial::tx_bit_cnt = 0;
+uint32_t SoftwareSerial::rx_buffer = 0;
+int32_t SoftwareSerial::rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
+uint32_t SoftwareSerial::cur_speed = 0;
+
+void SoftwareSerial::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) {
+ timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preemptPriority, subPriority);
+}
+
+//
+// Private methods
+//
+
+void SoftwareSerial::setSpeed(uint32_t speed) {
+ if (speed != cur_speed) {
+ timer.pause();
+ if (speed != 0) {
+ // Disable the timer
+ uint32_t clock_rate, cmp_value;
+ // Get timer clock
+ clock_rate = timer.getTimerClkFreq();
+ int pre = 1;
+ // Calculate prescale an compare value
+ do {
+ cmp_value = clock_rate / (speed * OVERSAMPLE);
+ if (cmp_value >= UINT16_MAX) {
+ clock_rate /= 2;
+ pre *= 2;
+ }
+ } while (cmp_value >= UINT16_MAX);
+ timer.setPrescaleFactor(pre);
+ timer.setOverflow(cmp_value);
+ timer.setCount(0);
+ timer.attachInterrupt(&handleInterrupt);
+ timer.resume();
+ NVIC_SetPriority(timer_interrupt_number, timer_interrupt_priority);
+ }
+ else
+ timer.detachInterrupt();
+ cur_speed = speed;
+ }
+}
+
+// This function sets the current object as the "listening"
+// one and returns true if it replaces another
+bool SoftwareSerial::listen() {
+ if (active_listener != this) {
+ // wait for any transmit to complete as we may change speed
+ while (active_out);
+ active_listener->stopListening();
+ rx_tick_cnt = 1; // 1 : next interrupt will decrease rx_tick_cnt to 0 which means RX pin level will be considered.
+ rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
+ setSpeed(_speed);
+ active_listener = this;
+ if (!_half_duplex) active_in = this;
+ return true;
+ }
+ return false;
+}
+
+// Stop listening. Returns true if we were actually listening.
+bool SoftwareSerial::stopListening() {
+ if (active_listener == this) {
+ // wait for any output to complete
+ while (active_out);
+ if (_half_duplex) setRXTX(false);
+ active_listener = nullptr;
+ active_in = nullptr;
+ // turn off ints
+ setSpeed(0);
+ return true;
+ }
+ return false;
+}
+
+inline void SoftwareSerial::setTX() {
+ if (_inverse_logic)
+ LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber);
+ else
+ LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber);
+ pinMode(_transmitPin, OUTPUT);
+}
+
+inline void SoftwareSerial::setRX() {
+ pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
+}
+
+inline void SoftwareSerial::setRXTX(bool input) {
+ if (_half_duplex) {
+ if (input) {
+ if (active_in != this) {
+ setRX();
+ rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
+ rx_tick_cnt = 2; // 2 : next interrupt will be discarded. 2 interrupts required to consider RX pin level
+ active_in = this;
+ }
+ }
+ else {
+ if (active_in == this) {
+ setTX();
+ active_in = nullptr;
+ }
+ }
+ }
+}
+
+inline void SoftwareSerial::send() {
+ if (--tx_tick_cnt <= 0) { // if tx_tick_cnt > 0 interrupt is discarded. Only when tx_tick_cnt reaches 0 is TX pin set.
+ if (tx_bit_cnt++ < 10) { // tx_bit_cnt < 10 transmission is not finished (10 = 1 start +8 bits + 1 stop)
+ // Send data (including start and stop bits)
+ if (tx_buffer & 1)
+ LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber);
+ else
+ LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber);
+ tx_buffer >>= 1;
+ tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks to send next bit
+ }
+ else { // Transmission finished
+ tx_tick_cnt = 1;
+ if (_output_pending) {
+ active_out = nullptr;
+
+ // In half-duplex mode wait HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has
+ // been transmitted before allowing the switch to RX mode
+ }
+ else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) {
+ if (_half_duplex && active_listener == this) setRXTX(true);
+ active_out = nullptr;
+ }
+ }
+ }
+}
+
+//
+// The receive routine called by the interrupt handler
+//
+inline void SoftwareSerial::recv() {
+ if (--rx_tick_cnt <= 0) { // if rx_tick_cnt > 0 interrupt is discarded. Only when rx_tick_cnt reaches 0 is RX pin considered
+ bool inbit = LL_GPIO_IsInputPinSet(_receivePinPort, _receivePinNumber) ^ _inverse_logic;
+ if (rx_bit_cnt == -1) { // rx_bit_cnt = -1 : waiting for start bit
+ if (!inbit) {
+ // got start bit
+ rx_bit_cnt = 0; // rx_bit_cnt == 0 : start bit received
+ rx_tick_cnt = OVERSAMPLE + 1; // Wait 1 bit (OVERSAMPLE ticks) + 1 tick in order to sample RX pin in the middle of the edge (and not too close to the edge)
+ rx_buffer = 0;
+ }
+ else
+ rx_tick_cnt = 1; // Waiting for start bit, but wrong level. Wait for next Interrupt to check RX pin level
+ }
+ else if (rx_bit_cnt >= 8) { // rx_bit_cnt >= 8 : waiting for stop bit
+ if (inbit) {
+ // Stop-bit read complete. Add to buffer.
+ uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
+ if (next != _receive_buffer_head) {
+ // save new data in buffer: tail points to byte destination
+ _receive_buffer[_receive_buffer_tail] = rx_buffer; // save new byte
+ _receive_buffer_tail = next;
+ }
+ else // rx_bit_cnt = x with x = [0..7] correspond to new bit x received
+ _buffer_overflow = true;
+ }
+ // Full trame received. Restart waiting for start bit at next interrupt
+ rx_tick_cnt = 1;
+ rx_bit_cnt = -1;
+ }
+ else {
+ // data bits
+ rx_buffer >>= 1;
+ if (inbit) rx_buffer |= 0x80;
+ rx_bit_cnt++; // Prepare for next bit
+ rx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks before sampling next bit
+ }
+ }
+}
+
+//
+// Interrupt handling
+//
+
+/* static */
+inline void SoftwareSerial::handleInterrupt(HardwareTimer*) {
+ if (active_in) active_in->recv();
+ if (active_out) active_out->send();
+}
+
+//
+// Constructor
+//
+SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic /* = false */) :
+ _receivePin(receivePin),
+ _transmitPin(transmitPin),
+ _receivePinPort(digitalPinToPort(receivePin)),
+ _receivePinNumber(STM_LL_GPIO_PIN(digitalPinToPinName(receivePin))),
+ _transmitPinPort(digitalPinToPort(transmitPin)),
+ _transmitPinNumber(STM_LL_GPIO_PIN(digitalPinToPinName(transmitPin))),
+ _speed(0),
+ _buffer_overflow(false),
+ _inverse_logic(inverse_logic),
+ _half_duplex(receivePin == transmitPin),
+ _output_pending(0),
+ _receive_buffer_tail(0),
+ _receive_buffer_head(0)
+{
+ if ((receivePin < NUM_DIGITAL_PINS) || (transmitPin < NUM_DIGITAL_PINS)) {
+ /* Enable GPIO clock for tx and rx pin*/
+ set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin)));
+ set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin)));
+ }
+ else
+ _Error_Handler("ERROR: invalid pin number\n", -1);
+}
+
+//
+// Destructor
+//
+SoftwareSerial::~SoftwareSerial() { end(); }
+
+//
+// Public methods
+//
+
+void SoftwareSerial::begin(long speed) {
+ #ifdef FORCE_BAUD_RATE
+ speed = FORCE_BAUD_RATE;
+ #endif
+ _speed = speed;
+ if (!_half_duplex) {
+ setTX();
+ setRX();
+ listen();
+ }
+ else
+ setTX();
+}
+
+void SoftwareSerial::end() {
+ stopListening();
+}
+
+// Read data from buffer
+int SoftwareSerial::read() {
+ // Empty buffer?
+ if (_receive_buffer_head == _receive_buffer_tail) return -1;
+
+ // Read from "head"
+ uint8_t d = _receive_buffer[_receive_buffer_head]; // grab next byte
+ _receive_buffer_head = (_receive_buffer_head + 1) % _SS_MAX_RX_BUFF;
+ return d;
+}
+
+int SoftwareSerial::available() {
+ return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF;
+}
+
+size_t SoftwareSerial::write(uint8_t b) {
+ // wait for previous transmit to complete
+ _output_pending = 1;
+ while (active_out) { /* nada */ }
+ // add start and stop bits.
+ tx_buffer = b << 1 | 0x200;
+ if (_inverse_logic) tx_buffer = ~tx_buffer;
+ tx_bit_cnt = 0;
+ tx_tick_cnt = OVERSAMPLE;
+ setSpeed(_speed);
+ if (_half_duplex) setRXTX(false);
+ _output_pending = 0;
+ // make us active
+ active_out = this;
+ return 1;
+}
+
+void SoftwareSerial::flush() {
+ noInterrupts();
+ _receive_buffer_head = _receive_buffer_tail = 0;
+ interrupts();
+}
+
+int SoftwareSerial::peek() {
+ // Empty buffer?
+ if (_receive_buffer_head == _receive_buffer_tail) return -1;
+
+ // Read from "head"
+ return _receive_buffer[_receive_buffer_head];
+}
+
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h
new file mode 100644
index 000000000000..3799701cfe5b
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/SoftwareSerial.h
@@ -0,0 +1,119 @@
+/**
+ * SoftwareSerial.h (formerly NewSoftSerial.h)
+ *
+ * Multi-instance software serial library for Arduino/Wiring
+ * -- Interrupt-driven receive and other improvements by ladyada
+ * (http://ladyada.net)
+ * -- Tuning, circular buffer, derivation from class Print/Stream,
+ * multi-instance support, porting to 8MHz processors,
+ * various optimizations, PROGMEM delay tables, inverse logic and
+ * direct port writing by Mikal Hart (http://www.arduiniana.org)
+ * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
+ * -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
+ * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * The latest version of this library can always be found at
+ * http://arduiniana.org.
+ */
+
+#ifndef SOFTWARESERIAL_H
+#define SOFTWARESERIAL_H
+
+#include
+
+/******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+#define _SS_MAX_RX_BUFF 64 // RX buffer size
+
+class SoftwareSerial : public Stream {
+ private:
+ // per object data
+ uint16_t _receivePin;
+ uint16_t _transmitPin;
+ GPIO_TypeDef *_receivePinPort;
+ uint32_t _receivePinNumber;
+ GPIO_TypeDef *_transmitPinPort;
+ uint32_t _transmitPinNumber;
+ uint32_t _speed;
+
+ uint16_t _buffer_overflow: 1;
+ uint16_t _inverse_logic: 1;
+ uint16_t _half_duplex: 1;
+ uint16_t _output_pending: 1;
+
+ unsigned char _receive_buffer[_SS_MAX_RX_BUFF];
+ volatile uint8_t _receive_buffer_tail;
+ volatile uint8_t _receive_buffer_head;
+
+ uint32_t delta_start = 0;
+
+ // static data
+ static bool initialised;
+ static HardwareTimer timer;
+ static const IRQn_Type timer_interrupt_number;
+ static uint32_t timer_interrupt_priority;
+ static SoftwareSerial *active_listener;
+ static SoftwareSerial *volatile active_out;
+ static SoftwareSerial *volatile active_in;
+ static int32_t tx_tick_cnt;
+ static volatile int32_t rx_tick_cnt;
+ static uint32_t tx_buffer;
+ static int32_t tx_bit_cnt;
+ static uint32_t rx_buffer;
+ static int32_t rx_bit_cnt;
+ static uint32_t cur_speed;
+
+ // private methods
+ void send();
+ void recv();
+ void setTX();
+ void setRX();
+ void setSpeed(uint32_t speed);
+ void setRXTX(bool input);
+ static void handleInterrupt(HardwareTimer *timer);
+
+ public:
+ // public methods
+
+ SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic = false);
+ virtual ~SoftwareSerial();
+ void begin(long speed);
+ bool listen();
+ void end();
+ bool isListening() { return active_listener == this; }
+ bool stopListening();
+ bool overflow() {
+ bool ret = _buffer_overflow;
+ if (ret) _buffer_overflow = false;
+ return ret;
+ }
+ int peek();
+
+ virtual size_t write(uint8_t byte);
+ virtual int read();
+ virtual int available();
+ virtual void flush();
+ operator bool() { return true; }
+
+ static void setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority);
+
+ using Print::write;
+};
+
+#endif // SOFTWARESERIAL_H
diff --git a/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
index 86f6d68c59ca..d0aa731e890d 100644
--- a/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_STM32/endstop_interrupts.h
@@ -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 100%
rename from Marlin/src/HAL/HAL_STM32/fastio_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/fastio.cpp
diff --git a/Marlin/src/HAL/HAL_STM32/fastio_STM32.h b/Marlin/src/HAL/HAL_STM32/fastio.h
similarity index 85%
rename from Marlin/src/HAL/HAL_STM32/fastio_STM32.h
rename to Marlin/src/HAL/HAL_STM32/fastio.h
index fd97fd206c3a..917ee3a1a630 100644
--- a/Marlin/src/HAL/HAL_STM32/fastio_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/fastio.h
@@ -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
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/SanityCheck.h b/Marlin/src/HAL/HAL_STM32/inc/SanityCheck.h
similarity index 100%
rename from Marlin/src/HAL/HAL_STM32/SanityCheck.h
rename to Marlin/src/HAL/HAL_STM32/inc/SanityCheck.h
diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
index 1161db2cb9ce..c94bce3b650e 100644
--- a/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
@@ -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 NONE(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 NONE(EEPROM_EMULATED_WITH_SRAM, SPI_EEPROM, I2C_EEPROM)
+ #if ENABLED(FLASH_EEPROM_EMULATION)
eeprom_buffer_fill();
#endif
return true;
}
bool PersistentStore::access_finish() {
- #if NONE(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 NONE(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 // 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 3759c2d6c3f9..4e27cee195d3 100644
--- a/Marlin/src/HAL/HAL_STM32/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_STM32/pinsDebug.h
@@ -1 +1,34 @@
-#error "PINS_DEBUGGING is not yet supported for STM32!"
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#if !(defined(NUM_DIGITAL_PINS) || defined(BOARD_NR_GPIO_PINS))
+ #error "M43 not supported for this board"
+#endif
+
+// Strange - STM32F4 comes to HAL_STM32 rather than HAL_STM32F4 for these files
+#ifdef STM32F4
+ #ifdef NUM_DIGITAL_PINS // Only in ST's Arduino core (STM32duino, STM32Core)
+ #include "pinsDebug_STM32duino.h"
+ #elif defined(BOARD_NR_GPIO_PINS) // Only in STM32GENERIC (Maple)
+ #include "pinsDebug_STM32GENERIC.h"
+ #else
+ #error "M43 not supported for this board"
+ #endif
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32GENERIC.h b/Marlin/src/HAL/HAL_STM32/pinsDebug_STM32GENERIC.h
new file mode 100644
index 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/timers.cpp b/Marlin/src/HAL/HAL_STM32/timers.cpp
new file mode 100644
index 000000000000..c2a4cbdc0e2d
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32/timers.cpp
@@ -0,0 +1,139 @@
+/**
+ * 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(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+
+#include "HAL.h"
+
+#include "timers.h"
+
+// ------------------------
+// Local defines
+// ------------------------
+
+#define NUM_HARDWARE_TIMERS 2
+
+#define __TIMER_DEV(X) TIM##X
+#define _TIMER_DEV(X) __TIMER_DEV(X)
+#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER)
+#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER)
+
+// ------------------------
+// Private Variables
+// ------------------------
+
+HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL };
+bool timer_enabled[NUM_HARDWARE_TIMERS] = { false };
+
+// ------------------------
+// Public functions
+// ------------------------
+
+// frequency is in Hertz
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
+ if (!HAL_timer_initialized(timer_num)) {
+ switch (timer_num) {
+ case STEP_TIMER_NUM: // STEPPER TIMER - use a 32bit timer if possible
+ timer_instance[timer_num] = new HardwareTimer(STEP_TIMER_DEV);
+ /* Set the prescaler to the final desired value.
+ * This will change the effective ISR callback frequency but when
+ * HAL_timer_start(timer_num=0) is called in the core for the first time
+ * the real frequency isn't important as long as, after boot, the ISR
+ * gets called with the correct prescaler and count register. So here
+ * we set the prescaler to the correct, final value and ignore the frequency
+ * asked. We will call back the ISR in 1 second to start at full speed.
+ *
+ * The proper fix, however, would be a correct initialization OR a
+ * HAL_timer_change(const uint8_t timer_num, const uint32_t frequency)
+ * which changes the prescaler when an IRQ frequency change is needed
+ * (for example when steppers are turned on)
+ */
+ timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); //the -1 is done internally
+ timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE) /* /frequency */), TICK_FORMAT);
+ break;
+ case TEMP_TIMER_NUM: // TEMP TIMER - any available 16bit timer
+ timer_instance[timer_num] = new HardwareTimer(TEMP_TIMER_DEV);
+ // The prescale factor is computed automatically for HERTZ_FORMAT
+ timer_instance[timer_num]->setOverflow(frequency, HERTZ_FORMAT);
+ break;
+ }
+
+ HAL_timer_enable_interrupt(timer_num);
+
+ /*
+ * Initializes (and unfortunately starts) the timer.
+ * This is needed to set correct IRQ priority at the moment but causes
+ * no harm since every call to HAL_timer_start() is actually followed by
+ * a call to HAL_timer_enable_interrupt() which means that there isn't
+ * a case in which you want the timer to run without a callback.
+ */
+ timer_instance[timer_num]->resume(); // First call to resume() MUST follow the attachInterrupt()
+
+ // This is fixed in Arduino_Core_STM32 1.8.
+ // These calls can be removed and replaced with
+ // timer_instance[timer_num]->setInterruptPriority
+ switch (timer_num) {
+ case STEP_TIMER_NUM:
+ HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0);
+ break;
+ case TEMP_TIMER_NUM:
+ HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0);
+ break;
+ }
+ }
+}
+
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
+ if (HAL_timer_initialized(timer_num) && !timer_enabled[timer_num]) {
+ timer_enabled[timer_num] = true;
+ switch (timer_num) {
+ case STEP_TIMER_NUM:
+ timer_instance[timer_num]->attachInterrupt(Step_Handler);
+ break;
+ case TEMP_TIMER_NUM:
+ timer_instance[timer_num]->attachInterrupt(Temp_Handler);
+ break;
+ }
+ }
+}
+
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
+ if (HAL_timer_interrupt_enabled(timer_num)) {
+ timer_instance[timer_num]->detachInterrupt();
+ timer_enabled[timer_num] = false;
+ }
+}
+
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
+ return HAL_timer_initialized(timer_num) && timer_enabled[timer_num];
+}
+
+// Only for use within the HAL
+TIM_TypeDef * HAL_timer_device(const uint8_t timer_num) {
+ switch (timer_num) {
+ case STEP_TIMER_NUM: return STEP_TIMER_DEV;
+ case TEMP_TIMER_NUM: return TEMP_TIMER_DEV;
+ }
+ return nullptr;
+}
+
+#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 60%
rename from Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.h
rename to Marlin/src/HAL/HAL_STM32/timers.h
index 8cdea0a81e40..1d2c095f2bb8 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/timers.h
@@ -21,22 +21,19 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include "../../inc/MarlinConfig.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
#define hal_timer_t uint32_t
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit
+
#ifdef STM32F0xx
#define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals
@@ -70,27 +67,30 @@
#endif
#ifndef TEMP_TIMER
- #define TEMP_TIMER 7
+ #define TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used.
#endif
#endif
+#ifndef SWSERIAL_TIMER_IRQ_PRIO
+ #define SWSERIAL_TIMER_IRQ_PRIO 1
+#endif
+
#ifndef STEP_TIMER_IRQ_PRIO
- #define STEP_TIMER_IRQ_PRIO 1
+ #define STEP_TIMER_IRQ_PRIO 2
#endif
#ifndef TEMP_TIMER_IRQ_PRIO
- #define TEMP_TIMER_IRQ_PRIO 2
+ #define TEMP_TIMER_IRQ_PRIO 14 //14 = after hardware ISRs
#endif
#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 PULSE_TIMER_NUM STEP_TIMER_NUM
-#define TEMP_TIMER_RATE 72000 // 72 Khz
-#define TEMP_TIMER_PRESCALE ((HAL_TIMER_RATE)/(TEMP_TIMER_RATE))
-#define TEMP_TIMER_FREQUENCY 1000
+#define TEMP_TIMER_FREQUENCY 1000 //Temperature::isr() is expected to be called at around 1kHz
+//TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp
#define STEPPER_TIMER_RATE 2000000 // 2 Mhz
#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE))
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
@@ -99,17 +99,6 @@
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
-#define __TIMER_DEV(X) TIM##X
-#define _TIMER_DEV(X) __TIMER_DEV(X)
-#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER)
-#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER)
-
-#define __TIMER_CALLBACK(X) TIM##X##_IRQHandler
-#define _TIMER_CALLBACK(X) __TIMER_CALLBACK(X)
-
-#define STEP_TIMER_CALLBACK _TIMER_CALLBACK(STEP_TIMER)
-#define TEMP_TIMER_CALLBACK _TIMER_CALLBACK(TEMP_TIMER)
-
#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn
#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X)
@@ -123,44 +112,46 @@
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-extern void Step_Handler(stimer_t *htim);
-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;
+extern void Step_Handler(HardwareTimer *htim);
+extern void Temp_Handler(HardwareTimer *htim);
+#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim)
+#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim)
-// --------------------------------------------------------------------------
+// ------------------------
// Public Variables
-// --------------------------------------------------------------------------
+// ------------------------
-extern stm32f4_timer_t TimerHandle[];
+extern HardwareTimer *timer_instance[];
-// --------------------------------------------------------------------------
+// ------------------------
// 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);
void HAL_timer_disable_interrupt(const uint8_t timer_num);
bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
-FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) {
- return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle);
-}
+//TIM_TypeDef* HAL_timer_device(const uint8_t timer_num); no need to be public for now. not public = not used externally
-FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
- __HAL_TIM_SET_AUTORELOAD(&TimerHandle[timer_num].handle, compare);
- if (HAL_timer_get_count(timer_num) >= compare)
- TimerHandle[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt
+// FORCE_INLINE because these are used in performance-critical situations
+FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) {
+ return timer_instance[timer_num] != NULL;
+}
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
+ return HAL_timer_initialized(timer_num) ? timer_instance[timer_num]->getCount() : 0;
}
-FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
- return __HAL_TIM_GET_AUTORELOAD(&TimerHandle[timer_num].handle);
+// NOTE: Method name may be misleading.
+// STM32 has an Auto-Reload Register (ARR) as opposed to a "compare" register
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t overflow) {
+ if (HAL_timer_initialized(timer_num)) {
+ timer_instance[timer_num]->setOverflow(overflow + 1, TICK_FORMAT); // Value decremented by setOverflow()
+ // wiki: "force all registers (Autoreload, prescaler, compare) to be taken into account"
+ // So, if the new overflow value is less than the count it will trigger a rollover interrupt.
+ if (overflow < timer_instance[timer_num]->getCount()) // Added 'if' here because reports say it won't boot without it
+ timer_instance[timer_num]->refresh();
+ }
}
#define HAL_timer_isr_prologue(TIMER_NUM)
diff --git a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp b/Marlin/src/HAL/HAL_STM32/watchdog.cpp
similarity index 86%
rename from Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp
rename to Marlin/src/HAL/HAL_STM32/watchdog.cpp
index 6f8b070e7b32..4defadaa77d3 100644
--- a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp
+++ b/Marlin/src/HAL/HAL_STM32/watchdog.cpp
@@ -22,18 +22,20 @@
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-#include "../../inc/MarlinConfig.h"
+#include "../../inc/MarlinConfigPre.h"
#if ENABLED(USE_WATCHDOG)
- #include "watchdog_STM32.h"
+ #include "../../inc/MarlinConfig.h"
+
+ #include "watchdog.h"
#include
void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout
- void watchdog_reset() {
+ void HAL_watchdog_refresh() {
IWatchdog.reload();
- #if PIN_EXISTS(LED)
+ #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
diff --git a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.h b/Marlin/src/HAL/HAL_STM32/watchdog.h
similarity index 96%
rename from Marlin/src/HAL/HAL_STM32/watchdog_STM32.h
rename to Marlin/src/HAL/HAL_STM32/watchdog.h
index f062d8a2e6f8..6855016737d1 100644
--- a/Marlin/src/HAL/HAL_STM32/watchdog_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32/watchdog.h
@@ -22,4 +22,4 @@
#pragma once
void watchdog_init();
-void watchdog_reset();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
index 2bbbd8b48b50..9dcb77ae4f14 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp
@@ -27,22 +27,14 @@
#ifdef __STM32F1__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "HAL.h"
#include "../../inc/MarlinConfig.h"
+#include "HAL.h"
#include
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
#define __I
#define __IO volatile
@@ -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,18 @@ uint8_t adc_pins[] = {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
FILWIDTH_PIN,
#endif
+ #if ENABLED(ADC_KEYPAD)
+ ADC_KEYPAD_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,18 +163,26 @@ enum TEMP_PINS : char {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
FILWIDTH,
#endif
+ #if ENABLED(ADC_KEYPAD)
+ ADC_KEY,
+ #endif
+ #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 */
@@ -185,9 +195,9 @@ static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
SCB->AIRCR = reg_value;
}
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
//
// Leave PA11/PA12 intact if USBSerial is not used
@@ -197,37 +207,63 @@ static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
#if SERIAL_PORT > 0
#if SERIAL_PORT2
#if SERIAL_PORT2 > 0
- void board_setup_usb(void) {}
+ void board_setup_usb() {}
#endif
#else
- void board_setup_usb(void) {}
+ void board_setup_usb() {}
#endif
#endif
} }
#endif
-void HAL_init(void) {
+void HAL_init() {
NVIC_SetPriorityGrouping(0x3);
#if PIN_EXISTS(LED)
OUT_WRITE(LED_PIN, LOW);
#endif
+ #ifdef USE_USB_COMPOSITE
+ MSC_SD_init();
+ #endif
+ #if PIN_EXISTS(USB_CONNECT)
+ OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING); // USB clear connection
+ delay(1000); // Give OS time to notice
+ OUT_WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
+ #endif
+}
+
+// HAL idle task
+void HAL_idletask() {
+ #ifdef USE_USB_COMPOSITE
+ #if ENABLED(SHARED_SD_CARD)
+ // If Marlin is using the SD card we need to lock it to prevent access from
+ // a PC via USB.
+ // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
+ // this will not reliably detect delete operations. To be safe we will lock
+ // the disk if Marlin has it mounted. Unfortunately there is currently no way
+ // to unmount the disk from the LCD menu.
+ // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
+ /* copy from lpc1768 framework, should be fixed later for process SHARED_SD_CARD*/
+ #endif
+ // process USB mass storage device class loop
+ MarlinMSC.loop();
+ #endif
}
/* VGPV Done with defines
// disable interrupts
-void cli(void) { noInterrupts(); }
+void cli() { noInterrupts(); }
// enable interrupts
-void sei(void) { interrupts(); }
+void sei() { interrupts(); }
*/
-void HAL_clear_reset_source(void) { }
+void HAL_clear_reset_source() { }
/**
* TODO: Check this and change or remove.
* currently returns 1 that's equal to poweron reset.
*/
-uint8_t HAL_get_reset_source(void) { return 1; }
+uint8_t HAL_get_reset_source() { return 1; }
void _delay_ms(const int delay_ms) { delay(delay_ms); }
@@ -242,7 +278,7 @@ extern "C" {
// return free memory between end of heap (or end bss) and whatever is current
/*
-#include "wirish/syscalls.c"
+#include
//extern caddr_t _sbrk(int incr);
#ifndef CONFIG_HEAP_END
extern char _lm_heap_end;
@@ -263,15 +299,19 @@ extern "C" {
}
*/
-// --------------------------------------------------------------------------
+// ------------------------
// ADC
-// --------------------------------------------------------------------------
+// ------------------------
// Init the AD in continuous capture mode
-void HAL_adc_init(void) {
+void HAL_adc_init() {
// configure the ADC
adc.calibrate();
- adc.setSampleRate(ADC_SMPR_41_5); // ?
- adc.setPins(adc_pins, ADC_PIN_COUNT);
+ #if F_CPU > 72000000
+ adc.setSampleRate(ADC_SMPR_71_5); // 71.5 ADC cycles
+ #else
+ adc.setSampleRate(ADC_SMPR_41_5); // 41.5 ADC cycles
+ #endif
+ adc.setPins((uint8_t *)adc_pins, ADC_PIN_COUNT);
adc.setDMA(HAL_adc_results, (uint16_t)ADC_PIN_COUNT, (uint32_t)(DMA_MINC_MODE | DMA_CIRC_MODE), nullptr);
adc.setScanMode();
adc.setContinuous();
@@ -306,14 +346,26 @@ 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
+ #if ENABLED(ADC_KEYPAD)
+ case ADC_KEYPAD_PIN: pin_index = ADC_KEY; break;
+ #endif
}
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;
@@ -322,8 +374,10 @@ uint16_t analogRead(pin_t pin) {
// Wrapper to maple unprotected analogWrite
void analogWrite(pin_t pin, int pwm_val8) {
- if (PWM_PIN(pin) && IS_OUTPUT(pin))
+ 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 3f33e3ec1ab1..a88b72107e55 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL.h
+++ b/Marlin/src/HAL/HAL_STM32F1/HAL.h
@@ -28,43 +28,49 @@
#define CPU_32_BIT
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../core/macros.h"
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F1.h"
-#include "watchdog_STM32F1.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "HAL_timers_STM32F1.h"
+#include "timers.h"
#include
#include
#include "../../inc/MarlinConfigPre.h"
-// --------------------------------------------------------------------------
+#ifdef USE_USB_COMPOSITE
+ #include "msc_sd.h"
+#endif
+
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
+
+#ifndef STM32_FLASH_SIZE
+ #ifdef MCU_STM32F103RE
+ #define STM32_FLASH_SIZE 512
+ #else
+ #define STM32_FLASH_SIZE 256
+ #endif
+#endif
#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
@@ -118,7 +124,9 @@
#endif
// Set interrupt grouping for this MCU
-void HAL_init(void);
+void HAL_init();
+#define HAL_IDLETASK 1
+void HAL_idletask();
/**
* TODO: review this to return 1 for pins that are not analog input
@@ -156,22 +164,22 @@ void HAL_init(void);
#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()
@@ -182,21 +190,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;
@@ -205,9 +217,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));
@@ -215,17 +224,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
//
@@ -245,14 +243,15 @@ 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_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
uint16_t analogRead(pin_t pin); // need HAL_ANALOG_SELECT() first
void analogWrite(pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
@@ -263,3 +262,6 @@ void analogWrite(pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
#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 76%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/HAL_SPI.cpp
index a43a1b41945a..9f3f34239d4a 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/HAL_SPI.cpp
@@ -32,34 +32,25 @@
#ifdef __STM32F1__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../../inc/MarlinConfig.h"
#include
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// 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
@@ -73,10 +64,9 @@
* @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
- OUT_WRITE(SS_PIN, HIGH);
}
/**
@@ -88,15 +78,25 @@ 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
}
SPI.setModule(SPI_DEVICE);
SPI.begin();
@@ -112,8 +112,8 @@ void spiInit(uint8_t spiRate) {
*
* @details
*/
-uint8_t spiRec(void) {
- uint8_t returnByte = SPI.transfer(0xFF);
+uint8_t spiRec() {
+ uint8_t returnByte = SPI.transfer(ff);
return returnByte;
}
diff --git a/Marlin/src/HAL/HAL_STM32F1/SPI.cpp b/Marlin/src/HAL/HAL_STM32F1/SPI.cpp
new file mode 100644
index 000000000000..8eb8f9aa88c9
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SPI.cpp
@@ -0,0 +1,715 @@
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *****************************************************************************/
+
+/**
+ * @author Marti Bolivar
+ * @brief Wirish SPI implementation.
+ */
+
+#ifdef __STM32F1__
+
+#include
+
+#include
+#include
+#include
+
+#include
+#include
+
+/** Time in ms for DMA receive timeout */
+#define DMA_TIMEOUT 100
+
+#if CYCLES_PER_MICROSECOND != 72
+ #warning "Unexpected clock speed; SPI frequency calculation will be incorrect"
+#endif
+
+struct spi_pins { uint8_t nss, sck, miso, mosi; };
+
+static const spi_pins* dev_to_spi_pins(spi_dev *dev);
+static void configure_gpios(spi_dev *dev, bool as_master);
+static spi_baud_rate determine_baud_rate(spi_dev *dev, uint32_t freq);
+
+#if BOARD_NR_SPI >= 3 && !defined(STM32_HIGH_DENSITY)
+ #error "The SPI library is misconfigured: 3 SPI ports only available on high density STM32 devices"
+#endif
+
+static const spi_pins board_spi_pins[] __FLASH__ = {
+ #if BOARD_NR_SPI >= 1
+ { BOARD_SPI1_NSS_PIN,
+ BOARD_SPI1_SCK_PIN,
+ BOARD_SPI1_MISO_PIN,
+ BOARD_SPI1_MOSI_PIN },
+ #endif
+ #if BOARD_NR_SPI >= 2
+ { BOARD_SPI2_NSS_PIN,
+ BOARD_SPI2_SCK_PIN,
+ BOARD_SPI2_MISO_PIN,
+ BOARD_SPI2_MOSI_PIN },
+ #endif
+ #if BOARD_NR_SPI >= 3
+ { BOARD_SPI3_NSS_PIN,
+ BOARD_SPI3_SCK_PIN,
+ BOARD_SPI3_MISO_PIN,
+ BOARD_SPI3_MOSI_PIN },
+ #endif
+};
+
+#if BOARD_NR_SPI >= 1
+ static void *_spi1_this;
+#endif
+#if BOARD_NR_SPI >= 2
+ static void *_spi2_this;
+#endif
+#if BOARD_NR_SPI >= 3
+ static void *_spi3_this;
+#endif
+
+/**
+ * Constructor
+ */
+SPIClass::SPIClass(uint32_t spi_num) {
+ _currentSetting = &_settings[spi_num - 1]; // SPI channels are called 1 2 and 3 but the array is zero indexed
+
+ switch (spi_num) {
+ #if BOARD_NR_SPI >= 1
+ case 1:
+ _currentSetting->spi_d = SPI1;
+ _spi1_this = (void*)this;
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case 2:
+ _currentSetting->spi_d = SPI2;
+ _spi2_this = (void*)this;
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case 3:
+ _currentSetting->spi_d = SPI3;
+ _spi3_this = (void*)this;
+ break;
+ #endif
+ default: ASSERT(0);
+ }
+
+ // Init things specific to each SPI device
+ // clock divider setup is a bit of hack, and needs to be improved at a later date.
+ #if BOARD_NR_SPI >= 1
+ _settings[0].spi_d = SPI1;
+ _settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
+ _settings[0].spiDmaDev = DMA1;
+ _settings[0].spiTxDmaChannel = DMA_CH3;
+ _settings[0].spiRxDmaChannel = DMA_CH2;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ _settings[1].spi_d = SPI2;
+ _settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
+ _settings[1].spiDmaDev = DMA1;
+ _settings[1].spiTxDmaChannel = DMA_CH5;
+ _settings[1].spiRxDmaChannel = DMA_CH4;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ _settings[2].spi_d = SPI3;
+ _settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
+ _settings[2].spiDmaDev = DMA2;
+ _settings[2].spiTxDmaChannel = DMA_CH2;
+ _settings[2].spiRxDmaChannel = DMA_CH1;
+ #endif
+
+ // added for DMA callbacks.
+ _currentSetting->state = SPI_STATE_IDLE;
+}
+
+/**
+ * Set up/tear down
+ */
+void SPIClass::updateSettings() {
+ uint32_t flags = ((_currentSetting->bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB) | _currentSetting->dataSize | SPI_SW_SLAVE | SPI_SOFT_SS);
+ spi_master_enable(_currentSetting->spi_d, (spi_baud_rate)_currentSetting->clockDivider, (spi_mode)_currentSetting->dataMode, flags);
+}
+
+void SPIClass::begin() {
+ spi_init(_currentSetting->spi_d);
+ configure_gpios(_currentSetting->spi_d, 1);
+ updateSettings();
+ // added for DMA callbacks.
+ _currentSetting->state = SPI_STATE_READY;
+}
+
+void SPIClass::beginSlave() {
+ spi_init(_currentSetting->spi_d);
+ configure_gpios(_currentSetting->spi_d, 0);
+ uint32_t flags = ((_currentSetting->bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB) | _currentSetting->dataSize);
+ spi_slave_enable(_currentSetting->spi_d, (spi_mode)_currentSetting->dataMode, flags);
+ // added for DMA callbacks.
+ _currentSetting->state = SPI_STATE_READY;
+}
+
+void SPIClass::end() {
+ if (!spi_is_enabled(_currentSetting->spi_d)) return;
+
+ // Follows RM0008's sequence for disabling a SPI in master/slave
+ // full duplex mode.
+ while (spi_is_rx_nonempty(_currentSetting->spi_d)) {
+ // FIXME [0.1.0] remove this once you have an interrupt based driver
+ volatile uint16_t rx __attribute__((unused)) = spi_rx_reg(_currentSetting->spi_d);
+ }
+ waitSpiTxEnd(_currentSetting->spi_d);
+
+ spi_peripheral_disable(_currentSetting->spi_d);
+ // added for DMA callbacks.
+ // Need to add unsetting the callbacks for the DMA channels.
+ _currentSetting->state = SPI_STATE_IDLE;
+}
+
+/* Roger Clark added 3 functions */
+void SPIClass::setClockDivider(uint32_t clockDivider) {
+ _currentSetting->clockDivider = clockDivider;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_BR);
+ _currentSetting->spi_d->regs->CR1 = cr1 | (clockDivider & SPI_CR1_BR);
+}
+
+void SPIClass::setBitOrder(BitOrder bitOrder) {
+ _currentSetting->bitOrder = bitOrder;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_LSBFIRST);
+ if (bitOrder == LSBFIRST) cr1 |= SPI_CR1_LSBFIRST;
+ _currentSetting->spi_d->regs->CR1 = cr1;
+}
+
+/**
+ * Victor Perez. Added to test changing datasize from 8 to 16 bit modes on the fly.
+ * Input parameter should be SPI_CR1_DFF set to 0 or 1 on a 32bit word.
+ */
+void SPIClass::setDataSize(uint32_t datasize) {
+ _currentSetting->dataSize = datasize;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_DFF);
+ uint8_t en = spi_is_enabled(_currentSetting->spi_d);
+ spi_peripheral_disable(_currentSetting->spi_d);
+ _currentSetting->spi_d->regs->CR1 = cr1 | (datasize & SPI_CR1_DFF) | en;
+}
+
+void SPIClass::setDataMode(uint8_t dataMode) {
+ /**
+ * Notes:
+ * As far as we know the AVR numbers for dataMode match the numbers required by the STM32.
+ * From the AVR doc http://www.atmel.com/images/doc2585.pdf section 2.4
+ *
+ * SPI Mode CPOL CPHA Shift SCK-edge Capture SCK-edge
+ * 0 0 0 Falling Rising
+ * 1 0 1 Rising Falling
+ * 2 1 0 Rising Falling
+ * 3 1 1 Falling Rising
+ *
+ * On the STM32 it appears to be
+ *
+ * bit 1 - CPOL : Clock polarity
+ * (This bit should not be changed when communication is ongoing)
+ * 0 : CLK to 0 when idle
+ * 1 : CLK to 1 when idle
+ *
+ * bit 0 - CPHA : Clock phase
+ * (This bit should not be changed when communication is ongoing)
+ * 0 : The first clock transition is the first data capture edge
+ * 1 : The second clock transition is the first data capture edge
+ *
+ * If someone finds this is not the case or sees a logic error with this let me know ;-)
+ */
+ _currentSetting->dataMode = dataMode;
+ uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_CPOL|SPI_CR1_CPHA);
+ _currentSetting->spi_d->regs->CR1 = cr1 | (dataMode & (SPI_CR1_CPOL|SPI_CR1_CPHA));
+}
+
+void SPIClass::beginTransaction(uint8_t pin, SPISettings settings) {
+ setBitOrder(settings.bitOrder);
+ setDataMode(settings.dataMode);
+ setDataSize(settings.dataSize);
+ setClockDivider(determine_baud_rate(_currentSetting->spi_d, settings.clock));
+ begin();
+}
+
+void SPIClass::beginTransactionSlave(SPISettings settings) {
+ setBitOrder(settings.bitOrder);
+ setDataMode(settings.dataMode);
+ setDataSize(settings.dataSize);
+ beginSlave();
+}
+
+void SPIClass::endTransaction() { }
+
+/**
+ * I/O
+ */
+
+uint16_t SPIClass::read() {
+ while (!spi_is_rx_nonempty(_currentSetting->spi_d)) { /* nada */ }
+ return (uint16)spi_rx_reg(_currentSetting->spi_d);
+}
+
+void SPIClass::read(uint8_t *buf, uint32_t len) {
+ if (len == 0) return;
+ spi_rx_reg(_currentSetting->spi_d); // clear the RX buffer in case a byte is waiting on it.
+ spi_reg_map * regs = _currentSetting->spi_d->regs;
+ // start sequence: write byte 0
+ regs->DR = 0x00FF; // write the first byte
+ // main loop
+ while (--len) {
+ while(!(regs->SR & SPI_SR_TXE)) { /* nada */ } // wait for TXE flag
+ noInterrupts(); // go atomic level - avoid interrupts to surely get the previously received data
+ regs->DR = 0x00FF; // write the next data item to be transmitted into the SPI_DR register. This clears the TXE flag.
+ while (!(regs->SR & SPI_SR_RXNE)) { /* nada */ } // wait till data is available in the DR register
+ *buf++ = (uint8)(regs->DR); // read and store the received byte. This clears the RXNE flag.
+ interrupts(); // let systick do its job
+ }
+ // read remaining last byte
+ while (!(regs->SR & SPI_SR_RXNE)) { /* nada */ } // wait till data is available in the Rx register
+ *buf++ = (uint8)(regs->DR); // read and store the received byte
+}
+
+void SPIClass::write(uint16_t data) {
+ /* Added for 16bit data Victor Perez. Roger Clark
+ * Improved speed by just directly writing the single byte to the SPI data reg and wait for completion,
+ * by taking the Tx code from transfer(byte)
+ * This almost doubles the speed of this function.
+ */
+ spi_tx_reg(_currentSetting->spi_d, data); // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
+ waitSpiTxEnd(_currentSetting->spi_d);
+}
+
+void SPIClass::write16(uint16_t data) {
+ // Added by stevestrong: write two consecutive bytes in 8 bit mode (DFF=0)
+ spi_tx_reg(_currentSetting->spi_d, data>>8); // write high byte
+ while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // Wait until TXE=1
+ spi_tx_reg(_currentSetting->spi_d, data); // write low byte
+ waitSpiTxEnd(_currentSetting->spi_d);
+}
+
+void SPIClass::write(uint16_t data, uint32_t n) {
+ // Added by stevstrong: Repeatedly send same data by the specified number of times
+ spi_reg_map * regs = _currentSetting->spi_d->regs;
+ while (n--) {
+ regs->DR = data; // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
+ while (!(regs->SR & SPI_SR_TXE)) { /* nada */ } // wait till Tx empty
+ }
+ while (regs->SR & SPI_SR_BSY) { /* nada */ } // wait until BSY=0 before returning
+}
+
+void SPIClass::write(const void *data, uint32_t length) {
+ spi_dev * spi_d = _currentSetting->spi_d;
+ spi_tx(spi_d, data, length); // data can be array of bytes or words
+ waitSpiTxEnd(spi_d);
+}
+
+uint8_t SPIClass::transfer(uint8_t byte) const {
+ spi_dev * spi_d = _currentSetting->spi_d;
+ spi_rx_reg(spi_d); // read any previous data
+ spi_tx_reg(spi_d, byte); // Write the data item to be transmitted into the SPI_DR register
+ waitSpiTxEnd(spi_d);
+ return (uint8)spi_rx_reg(spi_d); // "... and read the last received data."
+}
+
+uint16_t SPIClass::transfer16(uint16_t data) const {
+ // Modified by stevestrong: write & read two consecutive bytes in 8 bit mode (DFF=0)
+ // This is more effective than two distinct byte transfers
+ spi_dev * spi_d = _currentSetting->spi_d;
+ spi_rx_reg(spi_d); // read any previous data
+ spi_tx_reg(spi_d, data>>8); // write high byte
+ waitSpiTxEnd(spi_d); // wait until TXE=1 and then wait until BSY=0
+ uint16_t ret = spi_rx_reg(spi_d)<<8; // read and shift high byte
+ spi_tx_reg(spi_d, data); // write low byte
+ waitSpiTxEnd(spi_d); // wait until TXE=1 and then wait until BSY=0
+ ret += spi_rx_reg(spi_d); // read low byte
+ return ret;
+}
+
+/**
+ * Roger Clark and Victor Perez, 2015
+ * Performs a DMA SPI transfer with at least a receive buffer.
+ * If a TX buffer is not provided, FF is sent over and over for the lenght of the transfer.
+ * On exit TX buffer is not modified, and RX buffer cotains the received data.
+ * Still in progress.
+ */
+void SPIClass::dmaTransferSet(const void *transmitBuf, void *receiveBuf) {
+ dma_init(_currentSetting->spiDmaDev);
+ //spi_rx_dma_enable(_currentSetting->spi_d);
+ //spi_tx_dma_enable(_currentSetting->spi_d);
+ dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, receiveBuf, dma_bit_size, (DMA_MINC_MODE | DMA_TRNS_CMPLT ));// receive buffer DMA
+ if (!transmitBuf) {
+ transmitBuf = &ff;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, (volatile void*)transmitBuf, dma_bit_size, (DMA_FROM_MEM));// Transmit FF repeatedly
+ }
+ else {
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, (volatile void*)transmitBuf, dma_bit_size, (DMA_MINC_MODE | DMA_FROM_MEM ));// Transmit buffer DMA
+ }
+ dma_set_priority(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, DMA_PRIORITY_LOW);
+ dma_set_priority(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, DMA_PRIORITY_VERY_HIGH);
+}
+
+uint8_t SPIClass::dmaTransferRepeat(uint16_t length) {
+ if (length == 0) return 0;
+ if (spi_is_rx_nonempty(_currentSetting->spi_d) == 1) spi_rx_reg(_currentSetting->spi_d);
+ _currentSetting->state = SPI_STATE_TRANSFER;
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, length);
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);// enable receive
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
+ spi_rx_dma_enable(_currentSetting->spi_d);
+ spi_tx_dma_enable(_currentSetting->spi_d);
+ if (_currentSetting->receiveCallback)
+ return 0;
+
+ //uint32_t m = millis();
+ uint8_t b = 0;
+ uint32_t m = millis();
+ while (!(dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)) {
+ // Avoid interrupts and just loop waiting for the flag to be set.
+ if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
+ }
+
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ spi_rx_dma_disable(_currentSetting->spi_d);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ _currentSetting->state = SPI_STATE_READY;
+ return b;
+}
+
+/**
+ * Roger Clark and Victor Perez, 2015
+ * Performs a DMA SPI transfer with at least a receive buffer.
+ * If a TX buffer is not provided, FF is sent over and over for the length of the transfer.
+ * On exit TX buffer is not modified, and RX buffer contains the received data.
+ * Still in progress.
+ */
+uint8_t SPIClass::dmaTransfer(const void *transmitBuf, void *receiveBuf, uint16_t length) {
+ dmaTransferSet(transmitBuf, receiveBuf);
+ return dmaTransferRepeat(length);
+}
+
+/**
+ * Roger Clark and Victor Perez, 2015
+ * Performs a DMA SPI send using a TX buffer.
+ * On exit TX buffer is not modified.
+ * Still in progress.
+ * 2016 - stevstrong - reworked to automatically detect bit size from SPI setting
+ */
+void SPIClass::dmaSendSet(const void * transmitBuf, bool minc) {
+ uint32_t flags = ( (DMA_MINC_MODE*minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
+ dma_init(_currentSetting->spiDmaDev);
+ dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, dma_bit_size,
+ (volatile void*)transmitBuf, dma_bit_size, flags);// Transmit buffer DMA
+ dma_set_priority(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, DMA_PRIORITY_LOW);
+}
+
+uint8_t SPIClass::dmaSendRepeat(uint16_t length) {
+ if (length == 0) return 0;
+
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
+ _currentSetting->state = SPI_STATE_TRANSMIT;
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel); // enable transmit
+ spi_tx_dma_enable(_currentSetting->spi_d);
+ if (_currentSetting->transmitCallback) return 0;
+
+ uint32_t m = millis();
+ uint8_t b = 0;
+ while (!(dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)) {
+ // Avoid interrupts and just loop waiting for the flag to be set.
+ if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
+ }
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ _currentSetting->state = SPI_STATE_READY;
+ return b;
+}
+
+uint8_t SPIClass::dmaSend(const void * transmitBuf, uint16_t length, bool minc) {
+ dmaSendSet(transmitBuf, minc);
+ return dmaSendRepeat(length);
+}
+
+uint8_t SPIClass::dmaSendAsync(const void * transmitBuf, uint16_t length, bool minc) {
+ uint8_t b = 0;
+
+ if (_currentSetting->state != SPI_STATE_READY) {
+ uint32_t m = millis();
+ while (!(dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)) {
+ //Avoid interrupts and just loop waiting for the flag to be set.
+ //delayMicroseconds(10);
+ if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
+ }
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ _currentSetting->state = SPI_STATE_READY;
+ }
+
+ if (length == 0) return 0;
+ uint32_t flags = ( (DMA_MINC_MODE*minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
+
+ dma_init(_currentSetting->spiDmaDev);
+ // TX
+ dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
+ dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR,
+ dma_bit_size, (volatile void*)transmitBuf, dma_bit_size, flags);// Transmit buffer DMA
+ dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
+ dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
+ spi_tx_dma_enable(_currentSetting->spi_d);
+
+ _currentSetting->state = SPI_STATE_TRANSMIT;
+ return b;
+}
+
+
+/**
+ * New functions added to manage callbacks.
+ * Victor Perez 2017
+ */
+void SPIClass::onReceive(void(*callback)()) {
+ _currentSetting->receiveCallback = callback;
+ if (callback) {
+ switch (_currentSetting->spi_d->clk_id) {
+ #if BOARD_NR_SPI >= 1
+ case RCC_SPI1:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi1EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case RCC_SPI2:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi2EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case RCC_SPI3:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi3EventCallback);
+ break;
+ #endif
+ default:
+ ASSERT(0);
+ }
+ }
+ else {
+ dma_detach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ }
+}
+
+void SPIClass::onTransmit(void(*callback)()) {
+ _currentSetting->transmitCallback = callback;
+ if (callback) {
+ switch (_currentSetting->spi_d->clk_id) {
+ #if BOARD_NR_SPI >= 1
+ case RCC_SPI1:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi1EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case RCC_SPI2:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi2EventCallback);
+ break;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case RCC_SPI3:
+ dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi3EventCallback);
+ break;
+ #endif
+ default:
+ ASSERT(0);
+ }
+ }
+ else {
+ dma_detach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ }
+}
+
+/**
+ * TODO: check if better to first call the customer code, next disable the DMA requests.
+ * Also see if we need to check whether callbacks are set or not, may be better to be checked
+ * during the initial setup and only set the callback to EventCallback if they are set.
+ */
+void SPIClass::EventCallback() {
+ waitSpiTxEnd(_currentSetting->spi_d);
+ switch (_currentSetting->state) {
+ case SPI_STATE_TRANSFER:
+ while (spi_is_rx_nonempty(_currentSetting->spi_d)) { /* nada */ }
+ _currentSetting->state = SPI_STATE_READY;
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ spi_rx_dma_disable(_currentSetting->spi_d);
+ //dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ //dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
+ if (_currentSetting->receiveCallback)
+ _currentSetting->receiveCallback();
+ break;
+ case SPI_STATE_TRANSMIT:
+ _currentSetting->state = SPI_STATE_READY;
+ spi_tx_dma_disable(_currentSetting->spi_d);
+ //dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
+ if (_currentSetting->transmitCallback)
+ _currentSetting->transmitCallback();
+ break;
+ default:
+ break;
+ }
+}
+
+void SPIClass::attachInterrupt() {
+ // Should be enableInterrupt()
+}
+
+void SPIClass::detachInterrupt() {
+ // Should be disableInterrupt()
+}
+
+/**
+ * Pin accessors
+ */
+
+uint8_t SPIClass::misoPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->miso;
+}
+
+uint8_t SPIClass::mosiPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->mosi;
+}
+
+uint8_t SPIClass::sckPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->sck;
+}
+
+uint8_t SPIClass::nssPin() {
+ return dev_to_spi_pins(_currentSetting->spi_d)->nss;
+}
+
+/**
+ * Deprecated functions
+ */
+uint8_t SPIClass::send(uint8_t data) { write(data); return 1; }
+uint8_t SPIClass::send(uint8_t *buf, uint32_t len) { write(buf, len); return len; }
+uint8_t SPIClass::recv() { return read(); }
+
+/**
+ * DMA call back functions, one per port.
+ */
+#if BOARD_NR_SPI >= 1
+ void SPIClass::_spi1EventCallback() {
+ reinterpret_cast(_spi1_this)->EventCallback();
+ }
+#endif
+#if BOARD_NR_SPI >= 2
+ void SPIClass::_spi2EventCallback() {
+ reinterpret_cast(_spi2_this)->EventCallback();
+ }
+#endif
+#if BOARD_NR_SPI >= 3
+ void SPIClass::_spi3EventCallback() {
+ reinterpret_cast(_spi3_this)->EventCallback();
+ }
+#endif
+
+/**
+ * Auxiliary functions
+ */
+static const spi_pins* dev_to_spi_pins(spi_dev *dev) {
+ switch (dev->clk_id) {
+ #if BOARD_NR_SPI >= 1
+ case RCC_SPI1: return board_spi_pins;
+ #endif
+ #if BOARD_NR_SPI >= 2
+ case RCC_SPI2: return board_spi_pins + 1;
+ #endif
+ #if BOARD_NR_SPI >= 3
+ case RCC_SPI3: return board_spi_pins + 2;
+ #endif
+ default: return NULL;
+ }
+}
+
+static void disable_pwm(const stm32_pin_info *i) {
+ if (i->timer_device)
+ timer_set_mode(i->timer_device, i->timer_channel, TIMER_DISABLED);
+}
+
+static void configure_gpios(spi_dev *dev, bool as_master) {
+ const spi_pins *pins = dev_to_spi_pins(dev);
+ if (!pins) return;
+
+ const stm32_pin_info *nssi = &PIN_MAP[pins->nss],
+ *scki = &PIN_MAP[pins->sck],
+ *misoi = &PIN_MAP[pins->miso],
+ *mosii = &PIN_MAP[pins->mosi];
+
+ disable_pwm(nssi);
+ disable_pwm(scki);
+ disable_pwm(misoi);
+ disable_pwm(mosii);
+
+ spi_config_gpios(dev, as_master, nssi->gpio_device, nssi->gpio_bit,
+ scki->gpio_device, scki->gpio_bit, misoi->gpio_bit,
+ mosii->gpio_bit);
+}
+
+static const spi_baud_rate baud_rates[8] __FLASH__ = {
+ SPI_BAUD_PCLK_DIV_2,
+ SPI_BAUD_PCLK_DIV_4,
+ SPI_BAUD_PCLK_DIV_8,
+ SPI_BAUD_PCLK_DIV_16,
+ SPI_BAUD_PCLK_DIV_32,
+ SPI_BAUD_PCLK_DIV_64,
+ SPI_BAUD_PCLK_DIV_128,
+ SPI_BAUD_PCLK_DIV_256,
+};
+
+/**
+ * Note: This assumes you're on a LeafLabs-style board
+ * (CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz).
+ */
+static spi_baud_rate determine_baud_rate(spi_dev *dev, uint32_t freq) {
+ uint32_t clock = 0;
+ switch (rcc_dev_clk(dev->clk_id)) {
+ case RCC_AHB:
+ case RCC_APB2: clock = STM32_PCLK2; break; // 72 Mhz
+ case RCC_APB1: clock = STM32_PCLK1; break; // 36 Mhz
+ }
+ clock >>= 1;
+
+ uint8_t i = 0;
+ while (i < 7 && freq < clock) { clock >>= 1; i++; }
+ return baud_rates[i];
+}
+
+SPIClass SPI(1);
+
+#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/SPI.h b/Marlin/src/HAL/HAL_STM32F1/SPI.h
new file mode 100644
index 000000000000..0162ac13bb17
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SPI.h
@@ -0,0 +1,417 @@
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *****************************************************************************/
+#pragma once
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+// SPI_HAS_TRANSACTION means SPI has
+// - beginTransaction()
+// - endTransaction()
+// - usingInterrupt()
+// - SPISetting(clock, bitOrder, dataMode)
+//#define SPI_HAS_TRANSACTION
+
+#define SPI_CLOCK_DIV2 SPI_BAUD_PCLK_DIV_2
+#define SPI_CLOCK_DIV4 SPI_BAUD_PCLK_DIV_4
+#define SPI_CLOCK_DIV8 SPI_BAUD_PCLK_DIV_8
+#define SPI_CLOCK_DIV16 SPI_BAUD_PCLK_DIV_16
+#define SPI_CLOCK_DIV32 SPI_BAUD_PCLK_DIV_32
+#define SPI_CLOCK_DIV64 SPI_BAUD_PCLK_DIV_64
+#define SPI_CLOCK_DIV128 SPI_BAUD_PCLK_DIV_128
+#define SPI_CLOCK_DIV256 SPI_BAUD_PCLK_DIV_256
+
+/*
+ * Roger Clark. 20150106
+ * Commented out redundant AVR defined
+ *
+#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
+#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
+#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
+
+// define SPI_AVR_EIMSK for AVR boards with external interrupt pins
+#ifdef EIMSK
+ #define SPI_AVR_EIMSK EIMSK
+#elif defined(GICR)
+ #define SPI_AVR_EIMSK GICR
+#elif defined(GIMSK)
+ #define SPI_AVR_EIMSK GIMSK
+#endif
+*/
+
+#ifndef STM32_LSBFIRST
+ #define STM32_LSBFIRST 0
+#endif
+#ifndef STM32_MSBFIRST
+ #define STM32_MSBFIRST 1
+#endif
+
+// PC13 or PA4
+#define BOARD_SPI_DEFAULT_SS PA4
+//#define BOARD_SPI_DEFAULT_SS PC13
+
+#define SPI_MODE0 SPI_MODE_0
+#define SPI_MODE1 SPI_MODE_1
+#define SPI_MODE2 SPI_MODE_2
+#define SPI_MODE3 SPI_MODE_3
+
+#define DATA_SIZE_8BIT SPI_CR1_DFF_8_BIT
+#define DATA_SIZE_16BIT SPI_CR1_DFF_16_BIT
+
+typedef enum {
+ SPI_STATE_IDLE,
+ SPI_STATE_READY,
+ SPI_STATE_RECEIVE,
+ SPI_STATE_TRANSMIT,
+ SPI_STATE_TRANSFER
+} spi_mode_t;
+
+class SPISettings {
+public:
+ SPISettings(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, DATA_SIZE_8BIT);
+ else
+ init_MightInline(inClock, inBitOrder, inDataMode, DATA_SIZE_8BIT);
+ }
+ SPISettings(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
+ else
+ init_MightInline(inClock, inBitOrder, inDataMode, inDataSize);
+ }
+ SPISettings(uint32_t inClock) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ else
+ init_MightInline(inClock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+ SPISettings() {
+ init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+private:
+ void init_MightInline(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
+ }
+ void init_AlwaysInline(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) __attribute__((__always_inline__)) {
+ clock = inClock;
+ bitOrder = inBitOrder;
+ dataMode = inDataMode;
+ dataSize = inDataSize;
+ }
+ uint32_t clock;
+ uint32_t dataSize;
+ uint32_t clockDivider;
+ BitOrder bitOrder;
+ uint8_t dataMode;
+ uint8_t _SSPin;
+ volatile spi_mode_t state;
+ spi_dev *spi_d;
+ dma_channel spiRxDmaChannel, spiTxDmaChannel;
+ dma_dev* spiDmaDev;
+ void (*receiveCallback)() = NULL;
+ void (*transmitCallback)() = NULL;
+
+ friend class SPIClass;
+};
+
+/*
+ * Kept for compat.
+ */
+static const uint8_t ff = 0xFF;
+
+/**
+ * @brief Wirish SPI interface.
+ *
+ * This implementation uses software slave management, so the caller
+ * is responsible for controlling the slave select line.
+ */
+class SPIClass {
+
+public:
+ /**
+ * @param spiPortNumber Number of the SPI port to manage.
+ */
+ SPIClass(uint32_t spiPortNumber);
+
+ /**
+ * @brief Equivalent to begin(SPI_1_125MHZ, MSBFIRST, 0).
+ */
+ void begin();
+
+ /**
+ * @brief Turn on a SPI port and set its GPIO pin modes for use as a slave.
+ *
+ * SPI port is enabled in full duplex mode, with software slave management.
+ *
+ * @param bitOrder Either LSBFIRST (little-endian) or MSBFIRST(big-endian)
+ * @param mode SPI mode to use
+ */
+ void beginSlave(uint32_t bitOrder, uint32_t mode);
+
+ /**
+ * @brief Equivalent to beginSlave(MSBFIRST, 0).
+ */
+ void beginSlave();
+
+ /**
+ * @brief Disables the SPI port, but leaves its GPIO pin modes unchanged.
+ */
+ void end();
+
+ void beginTransaction(SPISettings settings) { beginTransaction(BOARD_SPI_DEFAULT_SS, settings); }
+ void beginTransaction(uint8_t pin, SPISettings settings);
+ void endTransaction();
+
+ void beginTransactionSlave(SPISettings settings);
+
+ void setClockDivider(uint32_t clockDivider);
+ void setBitOrder(BitOrder bitOrder);
+ void setDataMode(uint8_t dataMode);
+
+ // SPI Configuration methods
+ void attachInterrupt();
+ void detachInterrupt();
+
+ /* Victor Perez. Added to change datasize from 8 to 16 bit modes on the fly.
+ * Input parameter should be SPI_CR1_DFF set to 0 or 1 on a 32bit word.
+ * Requires an added function spi_data_size on STM32F1 / cores / maple / libmaple / spi.c
+ */
+ void setDataSize(uint32_t ds);
+
+ /* Victor Perez 2017. Added to set and clear callback functions for callback
+ * on DMA transfer completion.
+ * onReceive used to set the callback in case of dmaTransfer (tx/rx), once rx is completed
+ * onTransmit used to set the callback in case of dmaSend (tx only). That function
+ * will NOT be called in case of TX/RX
+ */
+ void onReceive(void(*)());
+ void onTransmit(void(*)());
+
+ /*
+ * I/O
+ */
+
+ /**
+ * @brief Return the next unread byte/word.
+ *
+ * If there is no unread byte/word waiting, this function will block
+ * until one is received.
+ */
+ uint16_t read();
+
+ /**
+ * @brief Read length bytes, storing them into buffer.
+ * @param buffer Buffer to store received bytes into.
+ * @param length Number of bytes to store in buffer. This
+ * function will block until the desired number of
+ * bytes have been read.
+ */
+ void read(uint8_t *buffer, uint32_t length);
+
+ /**
+ * @brief Transmit one byte/word.
+ * @param data to transmit.
+ */
+ void write(uint16_t data);
+ void write16(uint16_t data); // write 2 bytes in 8 bit mode (DFF=0)
+
+ /**
+ * @brief Transmit one byte/word a specified number of times.
+ * @param data to transmit.
+ */
+ void write(uint16_t data, uint32_t n);
+
+ /**
+ * @brief Transmit multiple bytes/words.
+ * @param buffer Bytes/words to transmit.
+ * @param length Number of bytes/words in buffer to transmit.
+ */
+ void write(const void * buffer, uint32_t length);
+
+ /**
+ * @brief Transmit a byte, then return the next unread byte.
+ *
+ * This function transmits before receiving.
+ *
+ * @param data Byte to transmit.
+ * @return Next unread byte.
+ */
+ uint8_t transfer(uint8_t data) const;
+ uint16_t transfer16(uint16_t data) const;
+
+ /**
+ * @brief Sets up a DMA Transfer for "length" bytes.
+ * The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.
+ *
+ * This function transmits and receives to buffers.
+ *
+ * @param transmitBuf buffer Bytes to transmit. If passed as 0, it sends FF repeatedly for "length" bytes
+ * @param receiveBuf buffer Bytes to save received data.
+ * @param length Number of bytes in buffer to transmit.
+ */
+ uint8_t dmaTransfer(const void * transmitBuf, void * receiveBuf, uint16_t length);
+ void dmaTransferSet(const void *transmitBuf, void *receiveBuf);
+ uint8_t dmaTransferRepeat(uint16_t length);
+
+ /**
+ * @brief Sets up a DMA Transmit for SPI 8 or 16 bit transfer mode.
+ * The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.
+ *
+ * This function only transmits and does not care about the RX fifo.
+ *
+ * @param data buffer half words to transmit,
+ * @param length Number of bytes in buffer to transmit.
+ * @param minc Set to use Memory Increment mode, clear to use Circular mode.
+ */
+ uint8_t dmaSend(const void * transmitBuf, uint16_t length, bool minc = 1);
+ void dmaSendSet(const void * transmitBuf, bool minc);
+ uint8_t dmaSendRepeat(uint16_t length);
+
+ uint8_t dmaSendAsync(const void * transmitBuf, uint16_t length, bool minc = 1);
+ /*
+ * Pin accessors
+ */
+
+ /**
+ * @brief Return the number of the MISO (master in, slave out) pin
+ */
+ uint8_t misoPin();
+
+ /**
+ * @brief Return the number of the MOSI (master out, slave in) pin
+ */
+ uint8_t mosiPin();
+
+ /**
+ * @brief Return the number of the SCK (serial clock) pin
+ */
+ uint8_t sckPin();
+
+ /**
+ * @brief Return the number of the NSS (slave select) pin
+ */
+ uint8_t nssPin();
+
+ /* Escape hatch */
+
+ /**
+ * @brief Get a pointer to the underlying libmaple spi_dev for
+ * this HardwareSPI instance.
+ */
+ spi_dev* c_dev() { return _currentSetting->spi_d; }
+
+ spi_dev* dev() { return _currentSetting->spi_d; }
+
+ /**
+ * @brief Sets the number of the SPI peripheral to be used by
+ * this HardwareSPI instance.
+ *
+ * @param spi_num Number of the SPI port. 1-2 in low density devices
+ * or 1-3 in high density devices.
+ */
+ void setModule(int spi_num) {
+ _currentSetting = &_settings[spi_num - 1];// SPI channels are called 1 2 and 3 but the array is zero indexed
+ }
+
+ /* -- The following methods are deprecated --------------------------- */
+
+ /**
+ * @brief Deprecated.
+ *
+ * Use HardwareSPI::transfer() instead.
+ *
+ * @see HardwareSPI::transfer()
+ */
+ uint8_t send(uint8_t data);
+
+ /**
+ * @brief Deprecated.
+ *
+ * Use HardwareSPI::write() in combination with
+ * HardwareSPI::read() (or HardwareSPI::transfer()) instead.
+ *
+ * @see HardwareSPI::write()
+ * @see HardwareSPI::read()
+ * @see HardwareSPI::transfer()
+ */
+ uint8_t send(uint8_t *data, uint32_t length);
+
+ /**
+ * @brief Deprecated.
+ *
+ * Use HardwareSPI::read() instead.
+ *
+ * @see HardwareSPI::read()
+ */
+ uint8_t recv();
+
+private:
+
+ SPISettings _settings[BOARD_NR_SPI];
+ SPISettings *_currentSetting;
+
+ void updateSettings();
+
+ /*
+ * Functions added for DMA transfers with Callback.
+ * Experimental.
+ */
+
+ void EventCallback();
+
+ #if BOARD_NR_SPI >= 1
+ static void _spi1EventCallback();
+ #endif
+ #if BOARD_NR_SPI >= 2
+ static void _spi2EventCallback();
+ #endif
+ #if BOARD_NR_SPI >= 3
+ static void _spi3EventCallback();
+ #endif
+ /*
+ spi_dev *spi_d;
+ uint8_t _SSPin;
+ uint32_t clockDivider;
+ uint8_t dataMode;
+ BitOrder bitOrder;
+ */
+};
+
+/**
+ * @brief Wait until TXE (tx empty) flag is set and BSY (busy) flag unset.
+ */
+static inline void waitSpiTxEnd(spi_dev *spi_d) {
+ while (spi_is_tx_empty(spi_d) == 0) { /* nada */ } // wait until TXE=1
+ while (spi_is_busy(spi_d) != 0) { /* nada */ } // wait until BSY=0
+}
+
+extern SPIClass SPI;
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/Servo.cpp
similarity index 68%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/Servo.cpp
index 7fbc0f61d0f3..5dc21691544c 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/Servo.cpp
@@ -29,8 +29,8 @@
uint8_t ServoCount = 0;
-#include "HAL_Servo_STM32F1.h"
-#include "HAL_timers_STM32F1.h"
+#include "Servo.h"
+#include "timers.h"
//#include "Servo.h"
@@ -56,52 +56,50 @@ uint8_t ServoCount = 0;
#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) {
+#define US_TO_COMPARE(us) uint16_t(map((us), 0, TAU_USEC, 0, SERVO_OVERFLOW))
+#define COMPARE_TO_US(c) uint32_t(map((c), 0, SERVO_OVERFLOW, 0, TAU_USEC))
+#define ANGLE_TO_US(a) uint16_t(map((a), minAngle, maxAngle, SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW))
+#define US_TO_ANGLE(us) int16_t(map((us), SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW, minAngle, maxAngle))
+
+void libServo::servoWrite(uint8_t inPin, uint16_t duty_cycle) {
#ifdef SERVO0_TIMER_NUM
- if (this->servoIndex == 0) {
- this->pwmSetDuty(duty_cycle);
+ if (servoIndex == 0) {
+ pwmSetDuty(duty_cycle);
return;
}
#endif
- timer_dev *tdev = PIN_MAP[pin].timer_device;
- uint8_t tchan = PIN_MAP[pin].timer_channel;
+ timer_dev *tdev = PIN_MAP[inPin].timer_device;
+ uint8_t tchan = PIN_MAP[inPin].timer_channel;
if (tdev) timer_set_compare(tdev, tchan, duty_cycle);
}
libServo::libServo() {
- this->servoIndex = ServoCount < MAX_SERVOS ? ServoCount++ : INVALID_SERVO;
+ 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;
+bool libServo::attach(const int32_t inPin, const int32_t inMinAngle, const int32_t inMaxAngle) {
+ if (servoIndex >= MAX_SERVOS) return false;
+ if (inPin >= BOARD_NR_GPIO_PINS) return false;
- this->minAngle = minAngle;
- this->maxAngle = maxAngle;
- this->angle = -1;
+ minAngle = inMinAngle;
+ maxAngle = inMaxAngle;
+ angle = -1;
#ifdef SERVO0_TIMER_NUM
- if (this->servoIndex == 0 && this->setupSoftPWM(pin)) {
- this->pin = pin; // set attached()
+ if (servoIndex == 0 && setupSoftPWM(inPin)) {
+ pin = inPin; // set attached()
return true;
}
#endif
- if (!PWM_PIN(pin)) return false;
+ if (!PWM_PIN(inPin)) return false;
- timer_dev *tdev = PIN_MAP[pin].timer_device;
- //uint8_t tchan = PIN_MAP[pin].timer_channel;
+ timer_dev *tdev = PIN_MAP[inPin].timer_device;
+ //uint8_t tchan = PIN_MAP[inPin].timer_channel;
- SET_PWM(pin);
- servoWrite(pin, 0);
+ SET_PWM(inPin);
+ servoWrite(inPin, 0);
timer_pause(tdev);
timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
@@ -109,25 +107,24 @@ bool libServo::attach(const int32_t pin, const int32_t minAngle, const int32_t m
timer_generate_update(tdev);
timer_resume(tdev);
- this->pin = pin; // set attached()
-
+ pin = inPin; // set attached()
return true;
}
bool libServo::detach() {
- if (!this->attached()) return false;
- this->angle = -1;
- servoWrite(this->pin, 0);
+ if (!attached()) return false;
+ angle = -1;
+ servoWrite(pin, 0);
return true;
}
int32_t libServo::read() const {
- if (this->attached()) {
+ if (attached()) {
#ifdef SERVO0_TIMER_NUM
- if (this->servoIndex == 0) return this->angle;
+ if (servoIndex == 0) return angle;
#endif
- timer_dev *tdev = PIN_MAP[this->pin].timer_device;
- uint8_t tchan = PIN_MAP[this->pin].timer_channel;
+ timer_dev *tdev = PIN_MAP[pin].timer_device;
+ uint8_t tchan = PIN_MAP[pin].timer_channel;
return US_TO_ANGLE(COMPARE_TO_US(timer_get_compare(tdev, tchan)));
}
return 0;
@@ -137,18 +134,18 @@ 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 (attached()) {
+ angle = constrain(value, minAngle, maxAngle);
+ servoWrite(pin, US_TO_COMPARE(ANGLE_TO_US(angle)));
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
#ifdef SERVO0_TIMER_NUM
- extern "C" void Servo_IRQHandler(void) {
+ 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
@@ -169,13 +166,13 @@ void libServo::move(const int32_t value) {
}
}
- bool libServo::setupSoftPWM(const int32_t pin) {
+ bool libServo::setupSoftPWM(const int32_t inPin) {
timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
if (!tdev) return false;
#ifdef SERVO0_PWM_OD
- OUT_WRITE_OD(pin, 1);
+ OUT_WRITE_OD(inPin, 1);
#else
- OUT_WRITE(pin, 0);
+ OUT_WRITE(inPin, 0);
#endif
timer_pause(tdev);
@@ -206,9 +203,9 @@ void libServo::move(const int32_t value) {
timer_disable_irq(tdev, 1);
timer_disable_irq(tdev, 2);
#ifdef SERVO0_PWM_OD
- OUT_WRITE_OD(this->pin, 1); // off
+ OUT_WRITE_OD(pin, 1); // off
#else
- OUT_WRITE(this->pin, 0);
+ OUT_WRITE(pin, 0);
#endif
}
}
@@ -221,7 +218,7 @@ void libServo::move(const int32_t value) {
#else
- bool libServo::setupSoftPWM(const int32_t pin) { return false; }
+ bool libServo::setupSoftPWM(const int32_t inPin) { return false; }
void libServo::pwmSetDuty(const uint16_t duty_cycle) {}
void libServo::pauseSoftPWM() {}
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/Servo.h
similarity index 96%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/Servo.h
index f97ca7486bbe..92f4dd678d34 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/Servo.h
@@ -41,7 +41,7 @@ class libServo {
public:
libServo();
bool attach(const int32_t pin, const int32_t minAngle=SERVO_DEFAULT_MIN_ANGLE, const int32_t maxAngle=SERVO_DEFAULT_MAX_ANGLE);
- bool attached() const { return this->pin != NOT_ATTACHED; }
+ bool attached() const { return pin != NOT_ATTACHED; }
bool detach();
void move(const int32_t value);
int32_t read() const;
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..330d7d632d16
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/SoftwareSerial.h
@@ -0,0 +1,44 @@
+/**
+ * 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
+
+#ifndef HAVE_SW_SERIAL
+ #define SW_SERIAL_PLACEHOLDER 1
+#endif
+
+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
old mode 100644
new mode 100755
similarity index 97%
rename from Marlin/src/HAL/HAL_STM32F1/STM32F1_flag_script.py
rename to Marlin/src/HAL/HAL_STM32F1/build_flags.py
index 5bb2f18fb6b6..6310740fe0d8
--- a/Marlin/src/HAL/HAL_STM32F1/STM32F1_flag_script.py
+++ b/Marlin/src/HAL/HAL_STM32F1/build_flags.py
@@ -4,7 +4,6 @@
#dynamic build flags for generic compile options
if __name__ == "__main__":
args = " ".join([ "-std=gnu11",
- "-std=gnu++11",
"-Os",
"-mcpu=cortex-m3",
"-mthumb",
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 73%
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 4be4ae4dd437..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
@@ -26,18 +26,21 @@
* Communication interface for FSMC
*/
-#include "../../inc/MarlinConfig.h"
+#include "../../../inc/MarlinConfig.h"
#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs
#if HAS_GRAPHICAL_LCD
-#include "U8glib.h"
-#include "libmaple/fsmc.h"
-#include "libmaple/gpio.h"
-#include "boards.h"
+#include
+#include
+#include
+#include
+#include
-#define LCD_READ_ID 0x04 /* Read display identification information */
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
/* Timing configuration */
#define FSMC_ADDRESS_SETUP_TIME 15 // AddressSetupTime
@@ -47,6 +50,10 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs);
void LCD_IO_WriteData(uint16_t RegValue);
void LCD_IO_WriteReg(uint16_t Reg);
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
+#ifdef LCD_USE_DMA_FSMC
+ void LCD_IO_WriteMultiple(uint16_t data, uint32_t count);
+ void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
+#endif
static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
@@ -59,21 +66,25 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
static uint8_t isCommand;
switch (msg) {
- case U8G_COM_MSG_STOP:
- break;
+ case U8G_COM_MSG_STOP: break;
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_RESET);
+ #ifdef LCD_USE_DMA_FSMC
+ dma_init(FSMC_DMA_DEV);
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
+ #endif
+
LCD_IO_Init(u8g->pin_list[U8G_PI_CS], u8g->pin_list[U8G_PI_A0]);
- u8g_Delay(100);
+ u8g_Delay(50);
- if (arg_ptr != nullptr)
+ if (arg_ptr)
*((uint32_t *)arg_ptr) = LCD_IO_ReadData(LCD_READ_ID, 3);
-
isCommand = 0;
break;
- case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
+ case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
isCommand = arg_val == 0 ? 1 : 0;
break;
@@ -89,7 +100,6 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
break;
case U8G_COM_MSG_WRITE_SEQ:
-
for (uint8_t i = 0; i < arg_val; i += 2)
LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
break;
@@ -103,13 +113,13 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
#define __ASM __asm
#define __STATIC_INLINE static inline
-__attribute__((always_inline)) __STATIC_INLINE void __DSB(void) {
+__attribute__((always_inline)) __STATIC_INLINE void __DSB() {
__ASM volatile ("dsb 0xF":::"memory");
}
-#define FSMC_CS_NE1 PD7
+#define FSMC_CS_NE1 PD7
-#ifdef STM32_XL_DENSITY
+#if ENABLED(STM32_XL_DENSITY)
#define FSMC_CS_NE2 PG9
#define FSMC_CS_NE3 PG10
#define FSMC_CS_NE4 PG12
@@ -141,7 +151,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __DSB(void) {
#define FSMC_RS_A22 PE6
#define FSMC_RS_A23 PE2
-#ifdef STM32_XL_DENSITY
+#if ENABLED(STM32_XL_DENSITY)
#define FSMC_RS_A24 PG13
#define FSMC_RS_A25 PG14
#endif
@@ -163,7 +173,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
switch (cs) {
case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; break;
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; break;
case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; break;
case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; break;
@@ -174,7 +184,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
#define _ORADDR(N) controllerAddress |= (_BV32(N) - 2)
switch (rs) {
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
case FSMC_RS_A0: _ORADDR( 1); break;
case FSMC_RS_A1: _ORADDR( 2); break;
case FSMC_RS_A2: _ORADDR( 3); break;
@@ -200,7 +210,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
case FSMC_RS_A21: _ORADDR(22); break;
case FSMC_RS_A22: _ORADDR(23); break;
case FSMC_RS_A23: _ORADDR(24); break;
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
case FSMC_RS_A24: _ORADDR(25); break;
case FSMC_RS_A25: _ORADDR(26); break;
#endif
@@ -232,7 +242,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_CS_NEx
gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_RS_Ax
- #ifdef STM32_XL_DENSITY
+ #if ENABLED(STM32_XL_DENSITY)
FSMC_NOR_PSRAM4_BASE->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
FSMC_NOR_PSRAM4_BASE->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
#else // PSRAM1 for STM32F103V (high density)
@@ -257,7 +267,7 @@ void LCD_IO_WriteReg(uint16_t Reg) {
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
volatile uint32_t data;
- LCD->REG = (uint16_t)RegValue;
+ LCD->REG = RegValue;
__DSB();
data = LCD->RAM; // dummy read
@@ -267,9 +277,48 @@ uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
data <<= 8;
data |= (LCD->RAM & 0x00FF);
}
- return (uint32_t)data;
+ return uint32_t(data);
}
-#endif // HAS_GRAPHICAL_LCD
+#if ENABLED(LCD_USE_DMA_FSMC)
+
+void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) {
+ while (count > 0) {
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, &color, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, count > 65535 ? 65535 : count);
+ dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+
+ while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ count = count > 65535 ? count - 65535 : 0;
+ }
+}
+
+void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) {
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
+ dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+
+ while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+}
+
+void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) {
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
+ dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+ dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+}
+
+void LCD_IO_WaitSequence_Async() {
+ while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
+ dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
+}
+
+#endif // LCD_USE_DMA_FSMC
+
+#endif // HAS_GRAPHICAL_LCD
#endif // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN
diff --git a/Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_swspi.cpp b/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
similarity index 98%
rename from Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_swspi.cpp
rename to Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
index 51d1fac9d473..753a5d5e708d 100644
--- a/Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_swspi.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
@@ -18,11 +18,11 @@
*/
#ifdef __STM32F1__
-#include "../../inc/MarlinConfig.h"
+#include "../../../inc/MarlinConfig.h"
#if HAS_GRAPHICAL_LCD && ENABLED(FORCE_SOFT_SPI)
-#include "HAL.h"
+#include "../HAL.h"
#include
#undef SPI_SPEED
diff --git a/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h
index 830f0075c00b..d043b3b8dbf7 100644
--- a/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h
@@ -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..3aafb9de3960
--- /dev/null
+++ b/Marlin/src/HAL/HAL_STM32F1/fastio.h
@@ -0,0 +1,186 @@
+/**
+ * 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_INPUT_PULLDOWN(IO) _SET_MODE(IO, GPIO_INPUT_PD)
+#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 fe09de3ebbdf..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) << ((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)
-
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/SanityCheck.h b/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h
similarity index 86%
rename from Marlin/src/HAL/HAL_STM32F1/SanityCheck.h
rename to Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h
index f356c0da0784..69466a0a7731 100644
--- a/Marlin/src/HAL/HAL_STM32F1/SanityCheck.h
+++ b/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h
@@ -36,3 +36,8 @@
#if ENABLED(FAST_PWM_FAN)
#error "FAST_PWM_FAN is not yet implemented for this platform."
#endif
+
+#if !defined(HAVE_SW_SERIAL) && HAS_TMC220x
+ #warning "With TMC2208/9 consider using SoftwareSerialM with HAVE_SW_SERIAL and appropriate SS_TIMER."
+ #error "Missing SoftwareSerial implementation."
+#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..c5b4f34cd22d
--- /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_STM32F1/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
index b4ef57e1daa5..babcdeaee31a 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
@@ -26,7 +26,18 @@
#include "../shared/persistent_store_api.h"
-bool PersistentStore::access_start() { return true; }
+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) {
@@ -49,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 set/*=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 (set && value) *value = c;
+ if (writing && value) *value = c;
crc16(crc, &c, 1);
pos++;
value++;
diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
index 4e73d0564eb3..bbca1cb3912d 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
@@ -40,69 +40,73 @@
#include
// 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;
+#define EEPROM_SIZE (EEPROM_PAGE_SIZE * 2)
+#define ACCESS_FINISHED(TF) do{ FLASH_Lock(); eeprom_dirty = false; return TF; }while(0)
+
+static uint8_t ram_eeprom[EEPROM_SIZE] __attribute__((aligned(4))) = {0};
+static bool eeprom_dirty = false;
bool PersistentStore::access_start() {
- firstWrite = true;
+ const uint32_t* source = reinterpret_cast(EEPROM_PAGE0_BASE);
+ uint32_t* destination = reinterpret_cast(ram_eeprom);
+
+ static_assert(0 == EEPROM_SIZE % 4, "EEPROM_SIZE is corrupted. (Must be a multiple of 4.)"); // Ensure copying as uint32_t is safe
+ constexpr size_t eeprom_size_u32 = EEPROM_SIZE / 4;
+
+ for (size_t i = 0; i < eeprom_size_u32; ++i, ++destination, ++source)
+ *destination = *source;
+
+ eeprom_dirty = false;
return true;
}
bool PersistentStore::access_finish() {
- FLASH_Lock();
- firstWrite = false;
- return true;
-}
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
- FLASH_Status status;
+ if (eeprom_dirty) {
+ FLASH_Status status;
- if (firstWrite) {
+ // Instead of erasing all (both) pages, maybe in the loop we check what page we are in, and if the
+ // data has changed in that page. We then erase the first time we "detect" a change. In theory, if
+ // nothing changed in a page, we wouldn't need to erase/write it.
+ // Or, instead of checking at this point, turn eeprom_dirty into an array of bool the size of number
+ // of pages. Inside write_data, we set the flag to true at that time if something in that
+ // page changes...either way, something to look at later.
FLASH_Unlock();
+
status = FLASH_ErasePage(EEPROM_PAGE0_BASE);
- if (status != FLASH_COMPLETE) return true;
+ if (status != FLASH_COMPLETE) ACCESS_FINISHED(true);
status = FLASH_ErasePage(EEPROM_PAGE1_BASE);
- if (status != FLASH_COMPLETE) return true;
- firstWrite = false;
- }
+ if (status != FLASH_COMPLETE) ACCESS_FINISHED(true);
- // 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++;
- }
+ const uint16_t *source = reinterpret_cast(ram_eeprom);
+ for (size_t i = 0; i < EEPROM_SIZE; i += 2, ++source) {
+ if (FLASH_ProgramHalfWord(EEPROM_PAGE0_BASE + i, *source) != FLASH_COMPLETE)
+ ACCESS_FINISHED(false);
+ }
- // 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;
+ ACCESS_FINISHED(true);
}
+ return true;
+}
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ for (size_t i = 0; i < size; ++i) ram_eeprom[pos + i] = value[i];
+ eeprom_dirty = true;
crc16(crc, value, size);
- pos += size + odd;
- return false;
+ pos += size;
+ return false; // return true for any error
}
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);
- }
- pos += ((size + 1) & ~1); // i.e., size+(size&1), round up odd values
- return false;
+ const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos];
+ if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[pos + i];
+ crc16(crc, buff, size);
+ pos += size;
+ return false; // return true for any error
}
-size_t PersistentStore::capacity() { return E2END + 1; }
+size_t PersistentStore::capacity() { return EEPROM_SIZE; }
#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 32440935779e..38d5803f5810 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
@@ -22,6 +22,7 @@
/**
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
+ * Implementation of EEPROM settings in SD Card
*/
#ifdef __STM32F1__
@@ -33,11 +34,12 @@
#include "../shared/persistent_store_api.h"
#ifndef E2END
- #define E2END 4095
+ #define E2END 0xFFF // 4KB
#endif
-#define HAL_STM32F1_EEPROM_SIZE (E2END + 1)
+#define HAL_EEPROM_SIZE (E2END + 1)
-static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
+#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
+static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
#if ENABLED(SDSUPPORT)
@@ -46,30 +48,30 @@ static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
#define EEPROM_FILENAME "eeprom.dat"
bool PersistentStore::access_start() {
- if (!card.isDetected()) return false;
+ if (!card.isMounted()) return false;
SdFile file, root = card.getroot();
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
- return false;
+ return true; // false aborts the save
- int16_t bytes_read = file.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
+ int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
if (bytes_read < 0) return false;
- for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
- HAL_STM32F1_eeprom_content[bytes_read] = 0xFF;
+ for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
+ HAL_eeprom_data[bytes_read] = 0xFF;
file.close();
return true;
}
bool PersistentStore::access_finish() {
- if (!card.isDetected()) return false;
+ if (!card.isMounted()) return false;
SdFile file, root = card.getroot();
- int16_t bytes_written = 0;
+ int bytes_written = 0;
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
- bytes_written = file.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
+ bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
file.close();
}
- return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
+ return (bytes_written == HAL_EEPROM_SIZE);
}
#else // !SDSUPPORT
@@ -78,9 +80,9 @@ static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
#endif // !SDSUPPORT
-bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
for (size_t i = 0; i < size; i++)
- HAL_STM32F1_eeprom_content[pos + i] = value[i];
+ HAL_eeprom_data[pos + i] = value[i];
crc16(crc, value, size);
pos += size;
return false;
@@ -88,7 +90,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t si
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
for (size_t i = 0; i < size; i++) {
- uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
+ uint8_t c = HAL_eeprom_data[pos + i];
if (writing) value[i] = c;
crc16(crc, &c, 1);
}
@@ -96,7 +98,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return false;
}
-size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; }
+size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
#endif // EEPROM_SETTINGS
diff --git a/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h b/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h
index b7f75343a26b..a8b632870aa9 100644
--- a/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_STM32F1/pinsDebug.h
@@ -16,112 +16,12 @@
* along with this program. If not, see .
*
*/
-
-/**
- * Support routines for STM32F1
- */
-#ifdef __STM32F1__
-
-/**
- * Translation of routines & variables used by pinsDebug.h
- */
-#include "fastio_STM32F1.h"
-
-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 NAME_FORMAT(p) PSTR("%-##p##s")
-#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 20 // spaces 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)
+#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
-
-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(pin_t pin) {
- return VALID_PIN(pin) ? !IS_INPUT(pin) : false;
-}
-
-static inline bool GET_ARRAY_IS_DIGITAL(int16_t array_pin) {
- pin_t pin = GET_ARRAY_PIN(array_pin);
- bool isDigital = !IS_ANALOG(pin);
- #ifdef NUM_ANALOG_INPUTS
- if (!isDigital && PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS)
- isDigital = true;
- #endif
- return isDigital;
-}
-
-static inline void pwm_details(pin_t pin) {
- if (PWM_PIN(pin)) {
- char buffer[16], num = '?';
- timer_dev * const tdev = PIN_MAP[pin].timer_device;
- const uint8_t channel = PIN_MAP[pin].timer_channel;
- if (tdev == &timer1) num = '1';
- else if (tdev == &timer1) num = '1';
- else if (tdev == &timer2) num = '2';
- else if (tdev == &timer3) num = '3';
- else if (tdev == &timer4) num = '4';
- #ifdef STM32_HIGH_DENSITY
- else if (tdev == &timer5) num = '5';
- else if (tdev == &timer8) num = '8';
- #endif
- sprintf_P(buffer, PSTR(" TIM%c CH%c"), num, ('0' + channel));
- SERIAL_ECHO(buffer);
- }
-}
-
-static inline void print_port(pin_t pin) {
- char buffer[8];
- char port = 'A' + char(pin >> 4); // pin div 16
- /* seems not to be required for our devices
- gpio_dev* gp = PIN_MAP[pin].gpio_device;
- if (gp == &gpioa) port = 'A';
- else if (gp == &gpiob) port = 'B';
- else if (gp == &gpioc) port = 'C';
- else if (gp == &gpiod) port = 'D';
- #if STM32_NR_GPIO_PORTS > 4
- else if (gp == &gpioe) port = 'E';
- else if (gp == &gpiof) port = 'F';
- else if (gp == &gpiog) port = 'G';
- #endif
- */
- const int16_t gbit = PIN_MAP[pin].gpio_bit;
- sprintf_P(buffer, PSTR("P%c%hd "), port, gbit);
- if (gbit < 10) SERIAL_CHAR(' ');
- SERIAL_ECHO(buffer);
-}
-
-#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/sdio.cpp
similarity index 91%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/sdio.cpp
index 4f90b26e684f..c1cab57a9e9f 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/sdio.cpp
@@ -25,13 +25,15 @@
#include
+#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
+
#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
-#include "HAL_sdio_STM32F1.h"
+#include "sdio.h"
SDIO_CardInfoTypeDef SdCard;
-bool SDIO_Init(void) {
+bool SDIO_Init() {
uint32_t count = 0U;
SdCard.CardType = SdCard.CardVersion = SdCard.Class = SdCard.RelCardAdd = SdCard.BlockNbr = SdCard.BlockSize = SdCard.LogBlockNbr = SdCard.LogBlockSize = 0;
@@ -105,7 +107,7 @@ bool SDIO_ReadBlock_DMA(uint32_t blockAddress, uint8_t *data) {
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
if (SDIO->STA & SDIO_STA_RXDAVL) {
- while (SDIO->STA & SDIO_STA_RXDAVL) (void) SDIO->FIFO;
+ while (SDIO->STA & SDIO_STA_RXDAVL) (void)SDIO->FIFO;
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
return false;
}
@@ -124,6 +126,8 @@ bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
return false;
}
+uint32_t millis();
+
bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
if (blockAddress >= SdCard.LogBlockNbr) return false;
@@ -163,21 +167,21 @@ bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
return false;
}
-inline uint32_t SDIO_GetCardState(void) { return SDIO_CmdSendStatus(SdCard.RelCardAdd << 16U) ? (SDIO_GetResponse(SDIO_RESP1) >> 9U) & 0x0FU : SDIO_CARD_ERROR; }
+inline uint32_t SDIO_GetCardState() { return SDIO_CmdSendStatus(SdCard.RelCardAdd << 16U) ? (SDIO_GetResponse(SDIO_RESP1) >> 9U) & 0x0FU : SDIO_CARD_ERROR; }
-// --------------------------------------------------------------------------
+// ------------------------
// SD Commands and Responses
-// --------------------------------------------------------------------------
+// ------------------------
void SDIO_SendCommand(uint16_t command, uint32_t argument) { SDIO->ARG = argument; SDIO->CMD = (uint32_t)(SDIO_CMD_CPSMEN | command); }
-uint8_t SDIO_GetCommandResponse(void) { return (uint8_t)(SDIO->RESPCMD); }
+uint8_t SDIO_GetCommandResponse() { return (uint8_t)(SDIO->RESPCMD); }
uint32_t SDIO_GetResponse(uint32_t response) { return SDIO->RESP[response]; }
-bool SDIO_CmdGoIdleState(void) { SDIO_SendCommand(CMD0_GO_IDLE_STATE, 0); return SDIO_GetCmdError(); }
-bool SDIO_CmdSendCID(void) { SDIO_SendCommand(CMD2_ALL_SEND_CID, 0); return SDIO_GetCmdResp2(); }
+bool SDIO_CmdGoIdleState() { SDIO_SendCommand(CMD0_GO_IDLE_STATE, 0); return SDIO_GetCmdError(); }
+bool SDIO_CmdSendCID() { SDIO_SendCommand(CMD2_ALL_SEND_CID, 0); return SDIO_GetCmdResp2(); }
bool SDIO_CmdSetRelAdd(uint32_t *rca) { SDIO_SendCommand(CMD3_SET_REL_ADDR, 0); return SDIO_GetCmdResp6(SDMMC_CMD_SET_REL_ADDR, rca); }
bool SDIO_CmdSelDesel(uint32_t address) { SDIO_SendCommand(CMD7_SEL_DESEL_CARD, address); return SDIO_GetCmdResp1(SDMMC_CMD_SEL_DESEL_CARD); }
-bool SDIO_CmdOperCond(void) { SDIO_SendCommand(CMD8_HS_SEND_EXT_CSD, SDMMC_CHECK_PATTERN); return SDIO_GetCmdResp7(); }
+bool SDIO_CmdOperCond() { SDIO_SendCommand(CMD8_HS_SEND_EXT_CSD, SDMMC_CHECK_PATTERN); return SDIO_GetCmdResp7(); }
bool SDIO_CmdSendCSD(uint32_t argument) { SDIO_SendCommand(CMD9_SEND_CSD, argument); return SDIO_GetCmdResp2(); }
bool SDIO_CmdSendStatus(uint32_t argument) { SDIO_SendCommand(CMD13_SEND_STATUS, argument); return SDIO_GetCmdResp1(SDMMC_CMD_SEND_STATUS); }
bool SDIO_CmdReadSingleBlock(uint32_t address) { SDIO_SendCommand(CMD17_READ_SINGLE_BLOCK, address); return SDIO_GetCmdResp1(SDMMC_CMD_READ_SINGLE_BLOCK); }
@@ -208,7 +212,7 @@ bool SDIO_CmdAppSetClearCardDetect(uint32_t rsa) {
do { if (!--count) return false; } while (!SDIO_GET_FLAG(FLAGS)); \
}while(0)
-bool SDIO_GetCmdError(void) {
+bool SDIO_GetCmdError() {
SDIO_WAIT(SDIO_STA_CMDSENT);
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS);
@@ -228,7 +232,7 @@ bool SDIO_GetCmdResp1(uint8_t command) {
return (SDIO_GetResponse(SDIO_RESP1) & SDMMC_OCR_ERRORBITS) == SDMMC_ALLZERO;
}
-bool SDIO_GetCmdResp2(void) {
+bool SDIO_GetCmdResp2() {
SDIO_WAIT(SDIO_STA_CCRCFAIL | SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT);
if (SDIO_GET_FLAG(SDIO_STA_CCRCFAIL | SDIO_STA_CTIMEOUT)) {
@@ -240,7 +244,7 @@ bool SDIO_GetCmdResp2(void) {
return true;
}
-bool SDIO_GetCmdResp3(void) {
+bool SDIO_GetCmdResp3() {
SDIO_WAIT(SDIO_STA_CCRCFAIL | SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT);
if (SDIO_GET_FLAG(SDIO_STA_CTIMEOUT)) {
@@ -268,7 +272,7 @@ bool SDIO_GetCmdResp6(uint8_t command, uint32_t *rca) {
return true;
}
-bool SDIO_GetCmdResp7(void) {
+bool SDIO_GetCmdResp7() {
SDIO_WAIT(SDIO_STA_CCRCFAIL | SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT);
if (SDIO_GET_FLAG(SDIO_STA_CTIMEOUT)) {
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/sdio.h
similarity index 88%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/sdio.h
index 2d4eb5b87977..ca0aced69581 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_sdio_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/sdio.h
@@ -21,18 +21,14 @@
*/
#pragma once
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../shared/Marduino.h"
-#include "libmaple/sdio.h"
-#include "libmaple/dma.h"
+#include
+#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define SDMMC_CMD_GO_IDLE_STATE ((uint8_t)0) /* Resets the SD memory card. */
#define SDMMC_CMD_ALL_SEND_CID ((uint8_t)2) /* Asks any card connected to the host to send the CID numbers on the CMD line. */
@@ -106,9 +102,9 @@
#define SDIO_CLOCK 18000000 /* 18 MHz */
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef struct {
uint32_t CardType; // Card Type
@@ -121,17 +117,17 @@ typedef struct {
uint32_t LogBlockSize; // Logical block size in bytes
} SDIO_CardInfoTypeDef;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
-inline uint32_t SDIO_GetCardState(void);
+inline uint32_t SDIO_GetCardState();
-bool SDIO_CmdGoIdleState(void);
-bool SDIO_CmdSendCID(void);
+bool SDIO_CmdGoIdleState();
+bool SDIO_CmdSendCID();
bool SDIO_CmdSetRelAdd(uint32_t *rca);
bool SDIO_CmdSelDesel(uint32_t address);
-bool SDIO_CmdOperCond(void);
+bool SDIO_CmdOperCond();
bool SDIO_CmdSendCSD(uint32_t argument);
bool SDIO_CmdSendStatus(uint32_t argument);
bool SDIO_CmdReadSingleBlock(uint32_t address);
@@ -143,11 +139,11 @@ bool SDIO_CmdAppOperCommand(uint32_t sdType);
bool SDIO_CmdAppSetClearCardDetect(uint32_t rsa);
void SDIO_SendCommand(uint16_t command, uint32_t argument);
-uint8_t SDIO_GetCommandResponse(void);
+uint8_t SDIO_GetCommandResponse();
uint32_t SDIO_GetResponse(uint32_t response);
-bool SDIO_GetCmdError(void);
+bool SDIO_GetCmdError();
bool SDIO_GetCmdResp1(uint8_t command);
-bool SDIO_GetCmdResp2(void);
-bool SDIO_GetCmdResp3(void);
+bool SDIO_GetCmdResp2();
+bool SDIO_GetCmdResp3();
bool SDIO_GetCmdResp6(uint8_t command, uint32_t *rca);
-bool SDIO_GetCmdResp7(void);
+bool SDIO_GetCmdResp7();
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/timers.cpp
similarity index 76%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/timers.cpp
index 8d071dd9c002..051f0323c6bd 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/timers.cpp
@@ -26,45 +26,17 @@
#ifdef __STM32F1__
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
+#include "../../inc/MarlinConfig.h"
#include "HAL.h"
+#include "timers.h"
-#include "HAL_timers_STM32F1.h"
-
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
+// ------------------------
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
+// ------------------------
/**
* Timer_clock1: Prescaler 2 -> 36 MHz
@@ -110,7 +82,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
timer_set_prescaler(STEP_TIMER_DEV, (uint16_t)(STEPPER_TIMER_PRESCALE - 1));
timer_set_reload(STEP_TIMER_DEV, 0xFFFF);
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_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, STEP_TIMER_IRQ_PRIO);
@@ -123,7 +95,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
timer_set_count(TEMP_TIMER_DEV, 0);
timer_set_prescaler(TEMP_TIMER_DEV, (uint16_t)(TEMP_TIMER_PRESCALE - 1));
timer_set_reload(TEMP_TIMER_DEV, 0xFFFF);
- timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), ((F_CPU / TEMP_TIMER_PRESCALE) / frequency)));
+ timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (F_CPU) / (TEMP_TIMER_PRESCALE) / frequency));
timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler);
nvic_irq_set_priority(irq_num, TEMP_TIMER_IRQ_PRIO);
timer_generate_update(TEMP_TIMER_DEV);
diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/timers.h
similarity index 81%
rename from Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/timers.h
index 39241bcb8a6b..d5d02a3dc65c 100644
--- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/timers.h
@@ -25,16 +25,13 @@
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
#include
+#include "../../core/boards.h"
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
/**
* TODO: Check and confirm what timer we will use for each Temps and stepper driving.
@@ -50,6 +47,20 @@ typedef uint16_t hal_timer_t;
#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
+/**
+ * Note: Timers may be used by platforms and libraries
+ *
+ * FAN PWMs:
+ * With FAN_SOFT_PWM disabled the Temperature class uses
+ * FANx_PIN timers to generate FAN PWM signals.
+ *
+ * Speaker:
+ * When SPEAKER is enabled, one timer is allocated by maple/tone.cpp.
+ * - If BEEPER_PIN has a timer channel (and USE_PIN_TIMER is
+ * defined in tone.cpp) it uses the pin's own timer.
+ * - Otherwise it uses Timer 8 on boards with STM32_HIGH_DENSITY
+ * or Timer 4 on other boards.
+ */
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
#define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
#else
@@ -58,7 +69,17 @@ typedef uint16_t hal_timer_t;
#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
+
+#if MB(BTT_SKR_MINI_E3_V1_0, BIGTREE_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE)
+ // SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
+ #ifdef STM32_HIGH_DENSITY
+ #define SERVO0_TIMER_NUM 8 // tone.cpp uses Timer 4
+ #else
+ #define SERVO0_TIMER_NUM 3 // tone.cpp uses Timer 8
+ #endif
+#else
+ #define SERVO0_TIMER_NUM 1 // SERVO0 or BLTOUCH
+#endif
#define STEP_TIMER_IRQ_PRIO 1
#define TEMP_TIMER_IRQ_PRIO 2
@@ -90,27 +111,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);
diff --git a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp
rename to Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
index 69dca326806f..17f5aa9725b7 100644
--- a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp
@@ -31,16 +31,16 @@
#if ENABLED(USE_WATCHDOG)
#include
-#include "watchdog_STM32F1.h"
+#include "watchdog.h"
-void watchdog_reset() {
+void HAL_watchdog_refresh() {
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
iwdg_feed();
}
-void watchdogSetup(void) {
+void watchdogSetup() {
// do whatever. don't remove this function.
}
@@ -51,10 +51,9 @@ void watchdogSetup(void) {
*
* @details The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and 625 reload value (counts down to 0)
*/
-void watchdog_init(void) {
+void watchdog_init() {
//iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD);
}
#endif // USE_WATCHDOG
-
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h b/Marlin/src/HAL/HAL_STM32F1/watchdog.h
similarity index 98%
rename from Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h
rename to Marlin/src/HAL/HAL_STM32F1/watchdog.h
index 4f3a8deb0d3b..21f97dd7a159 100644
--- a/Marlin/src/HAL/HAL_STM32F1/watchdog_STM32F1.h
+++ b/Marlin/src/HAL/HAL_STM32F1/watchdog.h
@@ -41,4 +41,4 @@ void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or STM32F1 will reset.
-void watchdog_reset();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.cpp b/Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.cpp
deleted file mode 100644
index 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 5cd41bd30d62..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) && NONE(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 3fa2aa2250c7..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.h b/Marlin/src/HAL/HAL_STM32F4/HAL.h
deleted file mode 100644
index 44fb909598bb..000000000000
--- a/Marlin/src/HAL/HAL_STM32F4/HAL.h
+++ /dev/null
@@ -1,236 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- *
- * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
- * Copyright (c) 2017 Victor Perez
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-#define CPU_32_BIT
-
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include "../shared/Marduino.h"
-#include "../shared/math_32bit.h"
-#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F4.h"
-#include "watchdog_STM32F4.h"
-#include "HAL_timers_STM32F4.h"
-
-#include "../../inc/MarlinConfigPre.h"
-
-#include
-
-#ifdef USBCON
- #include
-#endif
-
-// --------------------------------------------------------------------------
-// Defines
-// --------------------------------------------------------------------------
-
-//Serial override
-//extern HalSerial usb_serial;
-
-#if SERIAL_PORT == 0
- #error "Serial port 0 does not exist"
-#endif
-
-#if !WITHIN(SERIAL_PORT, -1, 6)
- #error "SERIAL_PORT must be from -1 to 6"
-#endif
-#if SERIAL_PORT == -1
- #define MYSERIAL0 SerialUSB
-#elif SERIAL_PORT == 1
- #define MYSERIAL0 SerialUART1
-#elif SERIAL_PORT == 2
- #define MYSERIAL0 SerialUART2
-#elif SERIAL_PORT == 3
- #define MYSERIAL0 SerialUART3
-#elif SERIAL_PORT == 4
- #define MYSERIAL0 SerialUART4
-#elif SERIAL_PORT == 5
- #define MYSERIAL0 SerialUART5
-#elif SERIAL_PORT == 6
- #define MYSERIAL0 SerialUART6
-#endif
-
-#ifdef SERIAL_PORT_2
- #if SERIAL_PORT_2 == 0
- #error "Serial port 0 does not exist"
- #endif
-
- #if !WITHIN(SERIAL_PORT_2, -1, 6)
- #error "SERIAL_PORT_2 must be from -1 to 6"
- #elif SERIAL_PORT_2 == SERIAL_PORT
- #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
- #endif
- #define NUM_SERIAL 2
- #if SERIAL_PORT_2 == -1
- #define MYSERIAL1 SerialUSB
- #elif SERIAL_PORT_2 == 1
- #define MYSERIAL1 SerialUART1
- #elif SERIAL_PORT_2 == 2
- #define MYSERIAL1 SerialUART2
- #elif SERIAL_PORT_2 == 3
- #define MYSERIAL1 SerialUART3
- #elif SERIAL_PORT_2 == 4
- #define MYSERIAL1 SerialUART4
- #elif SERIAL_PORT_2 == 5
- #define MYSERIAL1 SerialUART5
- #elif SERIAL_PORT_2 == 6
- #define MYSERIAL1 SerialUART6
- #endif
-#else
- #define NUM_SERIAL 1
-#endif
-
-#undef _BV
-#define _BV(b) (1 << (b))
-
-/**
- * TODO: review this to return 1 for pins that are not analog input
- */
-#ifndef analogInputToDigitalPin
- #define analogInputToDigitalPin(p) (p)
-#endif
-
-#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
-#define CRITICAL_SECTION_END if (!primask) __enable_irq()
-#define ISRS_ENABLED() (!__get_PRIMASK())
-#define ENABLE_ISRS() __enable_irq()
-#define DISABLE_ISRS() __disable_irq()
-#define cli() __disable_irq()
-#define sei() __enable_irq()
-
-// On AVR this is in math.h?
-#define square(x) ((x)*(x))
-
-#ifndef strncpy_P
- #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
-#endif
-
-// Fix bug in pgm_read_ptr
-#undef pgm_read_ptr
-#define pgm_read_ptr(addr) (*(addr))
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-typedef int8_t pin_t;
-
-#define HAL_SERVO_LIB libServo
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-/** result of last ADC conversion */
-extern uint16_t HAL_adc_result;
-
-// --------------------------------------------------------------------------
-// Public functions
-// --------------------------------------------------------------------------
-
-// Memory related
-#define __bss_end __bss_end__
-
-inline void HAL_init(void) { }
-
-/** clear reset reason */
-void HAL_clear_reset_source (void);
-
-/** reset reason */
-uint8_t HAL_get_reset_source(void);
-
-void _delay_ms(const int delay);
-
-/*
-extern "C" {
- int freeMemory(void);
-}
-*/
-
-extern "C" char* _sbrk(int incr);
-
-/*
-static int freeMemory() {
- volatile int top;
- top = (int)((char*)&top - reinterpret_cast(_sbrk(0)));
- return top;
-}
-*/
-
-static int freeMemory() {
- volatile char top;
- return &top - reinterpret_cast(_sbrk(0));
-}
-
-//
-// SPI: Extended functions which take a channel number (hardware SPI only)
-//
-
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
-
-//
-// EEPROM
-//
-
-/**
- * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
- * Wire library should work for i2c EEPROMs.
- */
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
-
-//
-// ADC
-//
-
-#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
-
-inline void HAL_adc_init(void) {}
-
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
-#define HAL_READ_ADC() HAL_adc_result
-#define HAL_ADC_READY() true
-
-void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
-
-#define GET_PIN_MAP_PIN(index) index
-#define GET_PIN_MAP_INDEX(pin) pin
-#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
-
-#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
-#define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp
deleted file mode 100644
index 8f1d2603ee9b..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/fastio_STM32F4.h b/Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h
deleted file mode 100644
index a657d2c747c0..000000000000
--- a/Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h
+++ /dev/null
@@ -1,153 +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 _GET_MODE(IO)
-#define _SET_MODE(IO,M) pinMode(IO, M)
-#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
-
-#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
-
-#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
-#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
-#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
-#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
-#define SET_PWM(IO) pinMode(IO, PWM)
-
-#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
-
-#define IS_INPUT(IO)
-#define IS_OUTPUT(IO)
-
-#define PWM_PIN(P) true
-
-// digitalRead/Write wrappers
-#define extDigitalRead(IO) digitalRead(IO)
-#define extDigitalWrite(IO,V) digitalWrite(IO,V)
-
-//
-// Pins Definitions
-//
-#define PORTA 0
-#define PORTB 1
-#define PORTC 2
-#define PORTD 3
-#define PORTE 4
-
-#define _STM32_PIN(_PORT,_PIN) ((PORT##_PORT * 16) + _PIN)
-
-#define PA0 _STM32_PIN(A, 0)
-#define PA1 _STM32_PIN(A, 1)
-#define PA2 _STM32_PIN(A, 2)
-#define PA3 _STM32_PIN(A, 3)
-#define PA4 _STM32_PIN(A, 4)
-#define PA5 _STM32_PIN(A, 5)
-#define PA6 _STM32_PIN(A, 6)
-#define PA7 _STM32_PIN(A, 7)
-#define PA8 _STM32_PIN(A, 8)
-#define PA9 _STM32_PIN(A, 9)
-#define PA10 _STM32_PIN(A, 10)
-#define PA11 _STM32_PIN(A, 11)
-#define PA12 _STM32_PIN(A, 12)
-#define PA13 _STM32_PIN(A, 13)
-#define PA14 _STM32_PIN(A, 14)
-#define PA15 _STM32_PIN(A, 15)
-
-#define PB0 _STM32_PIN(B, 0)
-#define PB1 _STM32_PIN(B, 1)
-#define PB2 _STM32_PIN(B, 2)
-#define PB3 _STM32_PIN(B, 3)
-#define PB4 _STM32_PIN(B, 4)
-#define PB5 _STM32_PIN(B, 5)
-#define PB6 _STM32_PIN(B, 6)
-#define PB7 _STM32_PIN(B, 7)
-#define PB8 _STM32_PIN(B, 8)
-#define PB9 _STM32_PIN(B, 9)
-#define PB10 _STM32_PIN(B, 10)
-#define PB11 _STM32_PIN(B, 11)
-#define PB12 _STM32_PIN(B, 12)
-#define PB13 _STM32_PIN(B, 13)
-#define PB14 _STM32_PIN(B, 14)
-#define PB15 _STM32_PIN(B, 15)
-
-#define PC0 _STM32_PIN(C, 0)
-#define PC1 _STM32_PIN(C, 1)
-#define PC2 _STM32_PIN(C, 2)
-#define PC3 _STM32_PIN(C, 3)
-#define PC4 _STM32_PIN(C, 4)
-#define PC5 _STM32_PIN(C, 5)
-#define PC6 _STM32_PIN(C, 6)
-#define PC7 _STM32_PIN(C, 7)
-#define PC8 _STM32_PIN(C, 8)
-#define PC9 _STM32_PIN(C, 9)
-#define PC10 _STM32_PIN(C, 10)
-#define PC11 _STM32_PIN(C, 11)
-#define PC12 _STM32_PIN(C, 12)
-#define PC13 _STM32_PIN(C, 13)
-#define PC14 _STM32_PIN(C, 14)
-#define PC15 _STM32_PIN(C, 15)
-
-#define PD0 _STM32_PIN(D, 0)
-#define PD1 _STM32_PIN(D, 1)
-#define PD2 _STM32_PIN(D, 2)
-#define PD3 _STM32_PIN(D, 3)
-#define PD4 _STM32_PIN(D, 4)
-#define PD5 _STM32_PIN(D, 5)
-#define PD6 _STM32_PIN(D, 6)
-#define PD7 _STM32_PIN(D, 7)
-#define PD8 _STM32_PIN(D, 8)
-#define PD9 _STM32_PIN(D, 9)
-#define PD10 _STM32_PIN(D, 10)
-#define PD11 _STM32_PIN(D, 11)
-#define PD12 _STM32_PIN(D, 12)
-#define PD13 _STM32_PIN(D, 13)
-#define PD14 _STM32_PIN(D, 14)
-#define PD15 _STM32_PIN(D, 15)
-
-#define PE0 _STM32_PIN(E, 0)
-#define PE1 _STM32_PIN(E, 1)
-#define PE2 _STM32_PIN(E, 2)
-#define PE3 _STM32_PIN(E, 3)
-#define PE4 _STM32_PIN(E, 4)
-#define PE5 _STM32_PIN(E, 5)
-#define PE6 _STM32_PIN(E, 6)
-#define PE7 _STM32_PIN(E, 7)
-#define PE8 _STM32_PIN(E, 8)
-#define PE9 _STM32_PIN(E, 9)
-#define PE10 _STM32_PIN(E, 10)
-#define PE11 _STM32_PIN(E, 11)
-#define PE12 _STM32_PIN(E, 12)
-#define PE13 _STM32_PIN(E, 13)
-#define PE14 _STM32_PIN(E, 14)
-#define PE15 _STM32_PIN(E, 15)
diff --git a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp
deleted file mode 100644
index 811b1ed9f4ef..000000000000
--- a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp
+++ /dev/null
@@ -1,69 +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) 2016 Victor Perez victor_pv@hotmail.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 "../shared/persistent_store_api.h"
-
-#include "../../inc/MarlinConfig.h"
-
-#if ENABLED(EEPROM_SETTINGS)
-
-bool PersistentStore::access_start() { return true; }
-bool PersistentStore::access_finish() { return true; }
-
-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;
- // 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 PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing) {
- do {
- uint8_t c = eeprom_read_byte((uint8_t*)pos);
- if (writing) *value = c;
- crc16(crc, &c, 1);
- pos++;
- value++;
- } while (--size);
- return false;
-}
-
-size_t PersistentStore::capacity() { return E2END + 1; }
-
-#endif // EEPROM_SETTINGS
-#endif // STM32GENERIC && STM32F4
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 a612b8953802..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 e266eabf4677..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_spi_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32F7/HAL_spi_STM32F7.cpp
deleted file mode 100644
index 294d90414e03..000000000000
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_spi_STM32F7.cpp
+++ /dev/null
@@ -1,164 +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
-#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
-
- OUT_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/endstop_interrupts.h b/Marlin/src/HAL/HAL_STM32F7/endstop_interrupts.h
deleted file mode 100644
index 86f6d68c59ca..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_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..e24483f642e2
--- /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
+//extern caddr_t _sbrk(int incr);
+#ifndef CONFIG_HEAP_END
+extern char _lm_heap_end;
+#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
+#endif
+
+extern "C" {
+ static int freeMemory() {
+ char top = 't';
+ return &top - reinterpret_cast(sbrk(0));
+ }
+ int freeMemory() {
+ int free_memory;
+ int heap_end = (int)_sbrk(0);
+ free_memory = ((int)&free_memory) - ((int)heap_end);
+ return free_memory;
+ }
+}
+*/
+
+// ------------------------
+// ADC
+// ------------------------
+
+void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
+
+uint16_t HAL_adc_get_result() { return HAL_adc_result; }
+
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL.h b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
similarity index 70%
rename from Marlin/src/HAL/HAL_STM32F7/HAL.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
index be99165111d0..0e44df4d1179 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
@@ -24,34 +24,33 @@
#define CPU_32_BIT
-#ifndef vsnprintf_P
- #define vsnprintf_P vsnprintf
-#endif
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include
+#include "../../inc/MarlinConfigPre.h"
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_STM32F7.h"
-#include "watchdog_STM32F7.h"
+#include "fastio.h"
+#include "timers.h"
+#include "watchdog.h"
-#include "HAL_timers_STM32F7.h"
+#include
-#include "../../inc/MarlinConfigPre.h"
+#if defined(STM32F4) && USBCON
+ #include
+#endif
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
//Serial override
//extern HalSerial usb_serial;
+#if defined(STM32F4) && SERIAL_PORT == 0
+ #error "Serial port 0 does not exist"
+#endif
+
#if !WITHIN(SERIAL_PORT, -1, 6)
#error "SERIAL_PORT must be from -1 to 6"
#endif
@@ -72,6 +71,9 @@
#endif
#ifdef SERIAL_PORT_2
+ #if defined(STM32F4) && SERIAL_PORT_2 == 0
+ #error "Serial port 0 does not exist"
+ #endif
#if !WITHIN(SERIAL_PORT_2, -1, 6)
#error "SERIAL_PORT_2 must be from -1 to 6"
#elif SERIAL_PORT_2 == SERIAL_PORT
@@ -97,8 +99,6 @@
#define NUM_SERIAL 1
#endif
-#define _BV(b) (1 << (b))
-
/**
* TODO: review this to return 1 for pins that are not analog input
*/
@@ -125,88 +125,100 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
-// --------------------------------------------------------------------------
+// ------------------------
// Types
-// --------------------------------------------------------------------------
+// ------------------------
typedef int8_t pin_t;
-// --------------------------------------------------------------------------
+#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__
-inline void HAL_init(void) { }
+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();
void _delay_ms(const int delay);
/*
extern "C" {
- int freeMemory(void);
+ int freeMemory();
}
*/
extern "C" char* _sbrk(int incr);
+
/*
-static int freeMemory() {
+int freeMemory() {
volatile int top;
top = (int)((char*)&top - reinterpret_cast(_sbrk(0)));
return top;
}
*/
-static int freeMemory() {
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+
+static inline int freeMemory() {
volatile char top;
return &top - reinterpret_cast(_sbrk(0));
}
-// SPI: Extended functions which take a channel number (hardware SPI only)
-/** Write single byte to specified SPI channel */
-void spiSend(uint32_t chan, byte b);
-/** Write buffer to specified SPI channel */
-void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
-/** Read single byte from specified SPI channel */
-uint8_t spiRec(uint32_t chan);
-
+#pragma GCC diagnostic pop
+//
// EEPROM
+//
/**
- * TODO: Write all this eeprom stuff. Can emulate eeprom in flash as last resort.
- * Wire library should work for i2c eeproms.
+ * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
+ * Wire library should work for i2c EEPROMs.
*/
void eeprom_write_byte(uint8_t *pos, unsigned char value);
uint8_t eeprom_read_byte(uint8_t *pos);
void eeprom_read_block (void *__dst, const void *__src, size_t __n);
void eeprom_update_block (const void *__src, void *__dst, size_t __n);
+//
// ADC
+//
#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
-inline void HAL_adc_init(void) {}
+inline void HAL_adc_init() {}
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+
+#ifdef STM32F4
+ #define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY)
+ #define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE)
+#endif
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
similarity index 76%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
index 315995c0166f..2f85182e2033 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/HAL_SPI.cpp
@@ -27,44 +27,38 @@
*/
/**
- * Adapted to the STM32F4 HAL
+ * Adapted to the Marlin STM32F4/7 HAL
*/
-#if defined(STM32GENERIC) && defined(STM32F4)
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
+#include "../../inc/MarlinConfig.h"
-#include "HAL.h"
-#include "../shared/HAL_SPI.h"
+#include
#include
+#include "../shared/HAL_SPI.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, 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 82%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h
index 30161bfc4c29..726207fbcfc6 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F4/timers.h
@@ -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 93%
rename from Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
index 99cadbde1687..3117321ac710 100644
--- a/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.cpp
@@ -25,22 +25,22 @@
*
*/
-//#include
+#if defined(STM32GENERIC) && defined(STM32F7)
-#ifdef STM32F7
+#include "../../../inc/MarlinConfigPre.h"
+
+#if HAS_DRIVER(TMC2660)
#include
#include
#include "TMC2660.h"
-#include "HAL.h"
-#include "../../core/serial.h"
-#include "../../inc/MarlinConfig.h"
-#include "../../Marlin.h"
-#include "../../module/stepper_indirection.h"
-#include "../../module/printcounter.h"
-#include "../../libs/duration_t.h"
-#include "../../libs/hex_print_routines.h"
+#include "../../../inc/MarlinConfig.h"
+#include "../../../Marlin.h"
+#include "../../../module/stepper/indirection.h"
+#include "../../../module/printcounter.h"
+#include "../../../libs/duration_t.h"
+#include "../../../libs/hex_print_routines.h"
//some default values used in initialization
#define DEFAULT_MICROSTEPPING_VALUE 32
@@ -189,7 +189,6 @@ void TMC26XStepper::start() {
pinMode(step_pin, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(cs_pin, OUTPUT);
- //SET_OUTPUT(STEPPER_ENABLE_PIN);
extDigitalWrite(step_pin, LOW);
extDigitalWrite(dir_pin, LOW);
extDigitalWrite(cs_pin, HIGH);
@@ -227,7 +226,7 @@ void TMC26XStepper::setSpeed(uint16_t whatSpeed) {
this->next_step_time = this->last_step_time + this->step_delay;
}
-uint16_t TMC26XStepper::getSpeed(void) { return this->speed; }
+uint16_t TMC26XStepper::getSpeed() { return this->speed; }
/**
* Moves the motor steps_to_move steps.
@@ -247,7 +246,7 @@ char TMC26XStepper::step(int16_t steps_to_move) {
return -1;
}
-char TMC26XStepper::move(void) {
+char TMC26XStepper::move() {
// decrement the number of steps, moving one step each time:
if (this->steps_left > 0) {
uint32_t time = micros();
@@ -278,11 +277,11 @@ char TMC26XStepper::move(void) {
return 0;
}
-char TMC26XStepper::isMoving(void) { return this->steps_left > 0; }
+char TMC26XStepper::isMoving() { return this->steps_left > 0; }
-uint16_t TMC26XStepper::getStepsLeft(void) { return this->steps_left; }
+uint16_t TMC26XStepper::getStepsLeft() { return this->steps_left; }
-char TMC26XStepper::stop(void) {
+char TMC26XStepper::stop() {
//note to self if the motor is currently moving
char state = isMoving();
//stop the motor
@@ -314,10 +313,12 @@ void TMC26XStepper::setCurrent(uint16_t current) {
current_scaling = (byte)((resistor_value * mASetting * 32.0 / (0.165 * sq(1000.0))) - 0.5); //theoretically - 1.0 for better rounding it is 0.5
#ifdef TMC_DEBUG0 // crashes
SERIAL_ECHOPAIR("\nCS (Vsense=1): ",current_scaling);
- } else {
- SERIAL_ECHOPAIR("\nCS: ", current_scaling);
#endif
}
+ #ifdef TMC_DEBUG0 // crashes
+ else
+ SERIAL_ECHOPAIR("\nCS: ", current_scaling);
+ #endif
// do some sanity checks
NOMORE(current_scaling, 31);
@@ -333,7 +334,7 @@ void TMC26XStepper::setCurrent(uint16_t current) {
}
}
-uint16_t TMC26XStepper::getCurrent(void) {
+uint16_t TMC26XStepper::getCurrent() {
// Calculate the current according to the datasheet to be on the safe side.
// This is not the fastest but the most accurate and illustrative way.
float result = (float)(stallguard2_current_register_value & CURRENT_SCALING_PATTERN),
@@ -360,7 +361,7 @@ void TMC26XStepper::setStallGuardThreshold(char stallguard_threshold, char stall
if (started) send262(stallguard2_current_register_value);
}
-char TMC26XStepper::getStallGuardThreshold(void) {
+char TMC26XStepper::getStallGuardThreshold() {
uint32_t stallguard_threshold = stallguard2_current_register_value & STALL_GUARD_VALUE_PATTERN;
//shift it down to bit 0
stallguard_threshold >>= 8;
@@ -373,7 +374,7 @@ char TMC26XStepper::getStallGuardThreshold(void) {
return result;
}
-char TMC26XStepper::getStallGuardFilter(void) {
+char TMC26XStepper::getStallGuardFilter() {
if (stallguard2_current_register_value & STALL_GUARD_FILTER_ENABLED)
return -1;
return 0;
@@ -420,7 +421,7 @@ void TMC26XStepper::setMicrosteps(const int16_t in_steps) {
/**
* returns the effective number of microsteps at the moment
*/
-int16_t TMC26XStepper::getMicrosteps(void) { return microsteps; }
+int16_t TMC26XStepper::getMicrosteps() { return microsteps; }
/**
* constant_off_time: The off time setting controls the minimum chopper frequency.
@@ -622,7 +623,7 @@ void TMC26XStepper::setCoolStepEnabled(boolean enabled) {
if (started) send262(cool_step_register_value);
}
-boolean TMC26XStepper::isCoolStepEnabled(void) { return this->cool_step_enabled; }
+boolean TMC26XStepper::isCoolStepEnabled() { return this->cool_step_enabled; }
uint16_t TMC26XStepper::getCoolStepLowerSgThreshold() {
// We return our internally stored value - in order to provide the correct setting even if cool step is not enabled
@@ -630,19 +631,19 @@ uint16_t TMC26XStepper::getCoolStepLowerSgThreshold() {
}
uint16_t TMC26XStepper::getCoolStepUpperSgThreshold() {
- return (uint8_t)((cool_step_register_value & SE_MAX_PATTERN) >> 8) << 5;
+ return uint8_t((cool_step_register_value & SE_MAX_PATTERN) >> 8) << 5;
}
uint8_t TMC26XStepper::getCoolStepCurrentIncrementSize() {
- return (uint8_t)((cool_step_register_value & CURRENT_DOWN_STEP_SPEED_PATTERN) >> 13);
+ return uint8_t((cool_step_register_value & CURRENT_DOWN_STEP_SPEED_PATTERN) >> 13);
}
uint8_t TMC26XStepper::getCoolStepNumberOfSGReadings() {
- return (uint8_t)((cool_step_register_value & SE_CURRENT_STEP_WIDTH_PATTERN) >> 5);
+ return uint8_t((cool_step_register_value & SE_CURRENT_STEP_WIDTH_PATTERN) >> 5);
}
uint8_t TMC26XStepper::getCoolStepLowerCurrentLimit() {
- return (uint8_t)((cool_step_register_value & MINIMUM_CURRENT_FOURTH) >> 15);
+ return uint8_t((cool_step_register_value & MINIMUM_CURRENT_FOURTH) >> 15);
}
void TMC26XStepper::setEnabled(boolean enabled) {
@@ -683,7 +684,7 @@ void TMC26XStepper::readStatus(char read_value) {
send262(driver_configuration_register_value);
}
-int16_t TMC26XStepper::getMotorPosition(void) {
+int16_t TMC26XStepper::getMotorPosition() {
//we read it out even if we are not started yet - perhaps it is useful information for somebody
readStatus(TMC26X_READOUT_POSITION);
return getReadoutValue();
@@ -691,7 +692,7 @@ int16_t TMC26XStepper::getMotorPosition(void) {
//reads the StallGuard setting from last status
//returns -1 if StallGuard information is not present
-int16_t TMC26XStepper::getCurrentStallGuardReading(void) {
+int16_t TMC26XStepper::getCurrentStallGuardReading() {
//if we don't yet started there cannot be a StallGuard value
if (!started) return -1;
//not time optimal, but solution optiomal:
@@ -700,7 +701,7 @@ int16_t TMC26XStepper::getCurrentStallGuardReading(void) {
return getReadoutValue();
}
-uint8_t TMC26XStepper::getCurrentCSReading(void) {
+uint8_t TMC26XStepper::getCurrentCSReading() {
//if we don't yet started there cannot be a StallGuard value
if (!started) return 0;
//not time optimal, but solution optiomal:
@@ -709,7 +710,7 @@ uint8_t TMC26XStepper::getCurrentCSReading(void) {
return (getReadoutValue() & 0x1F);
}
-uint16_t TMC26XStepper::getCurrentCurrent(void) {
+uint16_t TMC26XStepper::getCurrentCurrent() {
float result = (float)getCurrentCSReading(),
resistor_value = (float)this->resistor,
voltage = (driver_configuration_register_value & VSENSE)? 0.165 : 0.31;
@@ -720,7 +721,7 @@ uint16_t TMC26XStepper::getCurrentCurrent(void) {
/**
* Return true if the StallGuard threshold has been reached
*/
-boolean TMC26XStepper::isStallGuardOverThreshold(void) {
+boolean TMC26XStepper::isStallGuardOverThreshold() {
if (!this->started) return false;
return (driver_status_result & STATUS_STALL_GUARD_STATUS);
}
@@ -731,7 +732,7 @@ boolean TMC26XStepper::isStallGuardOverThreshold(void) {
* OVER_TEMPERATURE_SHUTDOWN if the temperature is so hot that the driver is shut down
* Any of those levels are not too good.
*/
-char TMC26XStepper::getOverTemperature(void) {
+char TMC26XStepper::getOverTemperature() {
if (!this->started) return 0;
if (driver_status_result & STATUS_OVER_TEMPERATURE_SHUTDOWN)
@@ -744,44 +745,44 @@ char TMC26XStepper::getOverTemperature(void) {
}
// Is motor channel A shorted to ground
-boolean TMC26XStepper::isShortToGroundA(void) {
+boolean TMC26XStepper::isShortToGroundA() {
if (!this->started) return false;
return (driver_status_result & STATUS_SHORT_TO_GROUND_A);
}
// Is motor channel B shorted to ground
-boolean TMC26XStepper::isShortToGroundB(void) {
+boolean TMC26XStepper::isShortToGroundB() {
if (!this->started) return false;
return (driver_status_result & STATUS_SHORT_TO_GROUND_B);
}
// Is motor channel A connected
-boolean TMC26XStepper::isOpenLoadA(void) {
+boolean TMC26XStepper::isOpenLoadA() {
if (!this->started) return false;
return (driver_status_result & STATUS_OPEN_LOAD_A);
}
// Is motor channel B connected
-boolean TMC26XStepper::isOpenLoadB(void) {
+boolean TMC26XStepper::isOpenLoadB() {
if (!this->started) return false;
return (driver_status_result & STATUS_OPEN_LOAD_B);
}
// Is chopper inactive since 2^20 clock cycles - defaults to ~0,08s
-boolean TMC26XStepper::isStandStill(void) {
+boolean TMC26XStepper::isStandStill() {
if (!this->started) return false;
return (driver_status_result & STATUS_STAND_STILL);
}
//is chopper inactive since 2^20 clock cycles - defaults to ~0,08s
-boolean TMC26XStepper::isStallGuardReached(void) {
+boolean TMC26XStepper::isStallGuardReached() {
if (!this->started) return false;
return (driver_status_result & STATUS_STALL_GUARD_STATUS);
}
//reads the StallGuard setting from last status
//returns -1 if StallGuard information is not present
-int16_t TMC26XStepper::getReadoutValue(void) {
+int16_t TMC26XStepper::getReadoutValue() {
return (int)(driver_status_result >> 10);
}
@@ -793,7 +794,7 @@ boolean TMC26XStepper::isCurrentScalingHalfed() {
/**
* version() returns the version of the library:
*/
-int16_t TMC26XStepper::version(void) { return 1; }
+int16_t TMC26XStepper::version() { return 1; }
void TMC26XStepper::debugLastStatus() {
#ifdef TMC_DEBUG1
@@ -830,9 +831,8 @@ void TMC26XStepper::debugLastStatus() {
SERIAL_ECHOPAIR("\n Stall Guard value:", value);
}
else if (readout_config == READ_STALL_GUARD_AND_COOL_STEP) {
- int16_t stallGuard = value & 0xF, current = value & 0x1F0;
- SERIAL_ECHOPAIR("\n Approx Stall Guard: ", stallGuard);
- SERIAL_ECHOPAIR("\n Current level", current);
+ SERIAL_ECHOPAIR("\n Approx Stall Guard: ", value & 0xF);
+ SERIAL_ECHOPAIR("\n Current level", value & 0x1F0);
}
}
#endif
@@ -895,4 +895,6 @@ inline void TMC26XStepper::send262(uint32_t datagram) {
driver_status_result = i_datagram;
}
-#endif // STM32F7
+#endif // HAS_DRIVER(TMC2660)
+
+#endif // STM32GENERIC && STM32F7
diff --git a/Marlin/src/HAL/HAL_STM32F7/TMC2660.h b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.h
similarity index 97%
rename from Marlin/src/HAL/HAL_STM32F7/TMC2660.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/TMC2660.h
index 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 69%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp
index df4d9c07d24f..5a3b32ef5bce 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.cpp
@@ -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 81%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h
index 01fb02d17866..38ecde30bb94 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/STM32F7/timers.h
@@ -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_STM32F4/HAL_Servo_STM32F4.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
similarity index 79%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
index d8545cc9e0e6..b3aac77615d4 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp
@@ -21,33 +21,34 @@
*
*/
-#if defined(STM32GENERIC) && defined(STM32F4)
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
-#include "HAL_Servo_STM32F4.h"
+#include "Servo.h"
int8_t libServo::attach(const int pin) {
- return Servo::attach(pin);
+ if (servoIndex >= MAX_SERVOS) return -1;
+ return super::attach(pin);
}
int8_t libServo::attach(const int pin, const int min, const int max) {
- return Servo::attach(pin, min, max);
+ return super::attach(pin, min, max);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
-#endif // HAS_SERVOS
-#endif // STM32GENERIC && STM32F4
+#endif // HAS_SERVOS
+#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
similarity index 90%
rename from Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
index a782c130e42f..64fa05025c7c 100644
--- a/Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/Servo.h
@@ -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,6 +35,7 @@ class libServo : public Servo {
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
private:
+ typedef Servo super;
uint16_t min_ticks, max_ticks;
uint8_t servoIndex; // index into the channel data for this servo
};
diff --git a/Marlin/src/HAL/HAL_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 95%
rename from Marlin/src/HAL/HAL_STM32F4/endstop_interrupts.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/endstop_interrupts.h
index 86f6d68c59ca..d0aa731e890d 100644
--- a/Marlin/src/HAL/HAL_STM32F4/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/endstop_interrupts.h
@@ -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 64%
rename from Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/fastio.h
index 81f363609fce..1e5ef2ef3085 100644
--- a/Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/fastio.h
@@ -23,11 +23,13 @@
#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)
@@ -66,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_STM32F7/SanityCheck.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h
similarity index 87%
rename from Marlin/src/HAL/HAL_STM32F7/SanityCheck.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h
index e292de4efe42..7b8d29aa7dcf 100644
--- a/Marlin/src/HAL/HAL_STM32F7/SanityCheck.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h
@@ -22,14 +22,14 @@
#pragma once
/**
- * Test STM32F7-specific configuration values for errors at compile-time.
+ * 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 STM32F7. Disable EMERGENCY_PARSER to continue."
+ #error "EMERGENCY_PARSER is not yet implemented for STM32F4/7. Disable EMERGENCY_PARSER to continue."
#endif
#if ENABLED(FAST_PWM_FAN)
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 91%
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 6d7d10323549..4bd86d225d4f 100644
--- a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/persistent_store_eeprom.cpp
@@ -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 100%
rename from Marlin/src/HAL/HAL_STM32F4/spi_pins.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/spi_pins.h
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 87%
rename from Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp
rename to Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp
index 51b3a8d62de0..900d1ef6a6fa 100644
--- a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp
@@ -20,13 +20,13 @@
*
*/
-#if defined(STM32GENERIC) && defined(STM32F4)
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfig.h"
#if ENABLED(USE_WATCHDOG)
- #include "watchdog_STM32F4.h"
+ #include "watchdog.h"
IWDG_HandleTypeDef hiwdg;
@@ -37,21 +37,20 @@
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
//Error_Handler();
}
+ else {
+ #if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
+ TOGGLE(LED_PIN); // heartbeat indicator
+ #endif
+ }
}
- void watchdog_reset() {
+ void HAL_watchdog_refresh() {
/* Refresh IWDG: reload counter */
if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
/* 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_STM32F4/watchdog_STM32F4.h b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
similarity index 96%
rename from Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h
rename to Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
index cc02fda24f41..9e2a2dc21c45 100644
--- a/Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.h
+++ b/Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h
@@ -24,4 +24,4 @@
extern IWDG_HandleTypeDef hiwdg;
void watchdog_init();
-void watchdog_reset();
+void HAL_watchdog_refresh();
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
index 56b609785869..2e15324e3bbd 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp
@@ -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 0dbfa284e54c..684afa58f466 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/HAL.h
@@ -19,24 +19,22 @@
* along with this program. If not, see .
*
*/
+#pragma once
/**
* Description: HAL for Teensy 3.5 and Teensy 3.6
*/
-#pragma once
-
#define CPU_32_BIT
#include "../shared/Marduino.h"
+#include "../shared/math_32bit.h"
+#include "../shared/HAL_SPI.h"
-#include "../math_32bit.h"
-#include "../HAL_SPI.h"
-
-#include "fastio_Teensy.h"
-#include "watchdog_Teensy.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
#include
@@ -89,43 +87,36 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
-inline void HAL_init(void) { }
+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
void HAL_adc_init();
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/HAL_SPI.cpp
similarity index 98%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/HAL_SPI.cpp
index f53658ec5572..4236f02b0f43 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/HAL_SPI.cpp
@@ -34,7 +34,7 @@ static SPISettings spiConfig;
*/
// Initialize SPI bus
-void spiBegin(void) {
+void spiBegin() {
#if !PIN_EXISTS(SS)
#error "SS_PIN not defined!"
#endif
@@ -71,7 +71,7 @@ void spiInit(uint8_t spiRate) {
}
// SPI receive a byte
-uint8_t spiRec(void) {
+uint8_t spiRec() {
SPI.beginTransaction(spiConfig);
const uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
similarity index 70%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
index 2ffd96e3e1bc..6451f6b1722e 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp
@@ -25,29 +25,29 @@
#if HAS_SERVOS
-#include "HAL_Servo_Teensy.h"
+#include "Servo.h"
uint8_t servoPin[MAX_SERVOS] = { 0 };
-int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex]);
+int8_t libServo::attach(const int inPin) {
+ if (servoIndex >= MAX_SERVOS) return -1;
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex]);
}
-int8_t libServo::attach(const int pin, const int min, const int max) {
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex], min, max);
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex], inMin, inMax);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
similarity index 97%
rename from Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
index 413c4995a5b3..3eb7d39b2217 100644
--- a/Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/Servo.h
@@ -4,7 +4,6 @@
*
* 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
@@ -31,6 +30,7 @@ class libServo : public Servo {
int8_t attach(const int pin, const int min, const int max);
void move(const int value);
private:
+ typedef Servo super;
uint16_t min_ticks;
uint16_t max_ticks;
uint8_t servoIndex; // index into the channel data for this servo
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h b/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
index 1af89e0f33fd..221b721b356a 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h
@@ -35,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 100%
rename from Marlin/src/HAL/HAL_TEENSY35_36/fastio_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/fastio.h
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 100%
rename from Marlin/src/HAL/HAL_TEENSY31_32/SanityCheck.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h
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/HAL_timers_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp
similarity index 92%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp
index ac0432564978..e4ccf33a4bb0 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/timers.cpp
@@ -27,14 +27,14 @@
#ifdef __MK20DX256__
#include "HAL.h"
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
-FORCE_INLINE static void __ISB(void) {
+FORCE_INLINE static void __ISB() {
__asm__ __volatile__("isb 0xF":::"memory");
}
@@ -42,7 +42,7 @@ FORCE_INLINE static void __ISB(void) {
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
-FORCE_INLINE static void __DSB(void) {
+FORCE_INLINE static void __DSB() {
__asm__ __volatile__("dsb 0xF":::"memory");
}
@@ -53,7 +53,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
FTM0_SC = 0x00; // Set this to zero before changing the modulus
FTM0_CNT = 0x0000; // Reset the count to zero
FTM0_MOD = 0xFFFF; // max modulus = 65535
- FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
+ FTM0_C0V = (FTM0_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value
FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
@@ -62,7 +62,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
FTM1_SC = 0x00; // Set this to zero before changing the modulus
FTM1_CNT = 0x0000; // Reset the count to zero
FTM1_MOD = 0xFFFF; // max modulus = 65535
- FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
+ FTM1_C0V = (FTM1_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value 65535
FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h b/Marlin/src/HAL/HAL_TEENSY31_32/timers.h
similarity index 82%
rename from Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/timers.h
index 8c9836d130cc..6dff7701be3c 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/timers.h
@@ -26,17 +26,11 @@
* Teensy3.2 (__MK20DX256__)
*/
-#pragma once
-
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
@@ -48,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)
@@ -74,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 97%
rename from Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY31_32/watchdog.cpp
index bf812d9a51d7..d1313e1f5deb 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/watchdog.cpp
@@ -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 96%
rename from Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h
index ceb041b45715..861afcbc9148 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h
@@ -27,7 +27,7 @@
void watchdog_init();
-inline void watchdog_reset() {
+inline void HAL_watchdog_refresh() {
// Watchdog refresh sequence
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
index 33541c03bf7e..584894479229 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp
@@ -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 f3a26eb5d810..97763bf205bf 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL.h
@@ -27,18 +27,14 @@
#define CPU_32_BIT
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
#include "../shared/Marduino.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
-#include "fastio_Teensy.h"
-#include "watchdog_Teensy.h"
+#include "fastio.h"
+#include "watchdog.h"
-#include "HAL_timers_Teensy.h"
+#include "timers.h"
#include
#include
@@ -47,9 +43,9 @@
#define ST7920_DELAY_2 DELAY_NS(750)
#define ST7920_DELAY_3 DELAY_NS(750)
-// --------------------------------------------------------------------------
+// ------------------------
// Defines
-// --------------------------------------------------------------------------
+// ------------------------
#define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
#define IS_TEENSY35 defined(__MK64FX512__)
@@ -97,40 +93,36 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
-inline void HAL_init(void) { }
+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
void HAL_adc_init();
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_start_conversion(const uint8_t adc_pin);
-uint16_t HAL_adc_get_result(void);
+uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_SPI.cpp
similarity index 98%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/HAL_SPI.cpp
index 35424625d5ed..44ab74cc9bf6 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_SPI.cpp
@@ -29,7 +29,7 @@
static SPISettings spiConfig;
-void spiBegin(void) {
+void spiBegin() {
#if !PIN_EXISTS(SS)
#error SS_PIN not defined!
#endif
@@ -65,7 +65,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_TEENSY35_36/HAL_Servo_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
deleted file mode 100644
index ff56036ccd7a..000000000000
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-
-#include "../../inc/MarlinConfig.h"
-
-#if HAS_SERVOS
-
-#include "HAL_Servo_Teensy.h"
-
-uint8_t servoPin[MAX_SERVOS] = { 0 };
-
-int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex]);
-}
-
-int8_t libServo::attach(const int pin, const int min, const int max) {
- if (pin > 0) servoPin[this->servoIndex] = pin;
- return Servo::attach(servoPin[this->servoIndex], min, max);
-}
-
-void libServo::move(const int value) {
- constexpr uint16_t servo_delay[] = SERVO_DELAY;
- static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
- #endif
- }
-}
-
-#endif // HAS_SERVOS
-
-#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
similarity index 66%
rename from Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
index 3be816ad34a2..d376b80a7df6 100644
--- a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp
@@ -4,7 +4,6 @@
*
* 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
@@ -20,35 +19,39 @@
* along with this program. If not, see .
*
*/
-
-#ifdef STM32F7
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
-#include "HAL_Servo_STM32F7.h"
+#include "Servo.h"
+
+uint8_t servoPin[MAX_SERVOS] = { 0 };
-int8_t libServo::attach(const int pin) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
- return Servo::attach(pin);
+int8_t libServo::attach(const int inPin) {
+ if (servoIndex >= MAX_SERVOS) return -1;
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex]);
}
-int8_t libServo::attach(const int pin, const int min, const int max) {
- return Servo::attach(pin, min, max);
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
+ if (inPin > 0) servoPin[servoIndex] = inPin;
+ return super::attach(servoPin[servoIndex], inMin, inMax);
}
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
+
#endif // HAS_SERVOS
-#endif // STM32F7
+#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
similarity index 88%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
index 4b97dbffbbbe..cafd323a3846 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/Servo.h
@@ -30,7 +30,8 @@ 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;
- uint8_t servoIndex; // Index into the channel data for this servo
+ typedef Servo super;
+ uint16_t min_ticks;
+ uint16_t max_ticks;
+ uint8_t servoIndex; // Index into the channel data for this servo
};
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h b/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h
index 137cb472eff3..3862f2b5b897 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h
@@ -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 99%
rename from Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/fastio.h
index 7bcd601b5863..d1b5f567d750 100644
--- a/Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/fastio.h
@@ -27,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
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 100%
rename from Marlin/src/HAL/HAL_TEENSY35_36/SanityCheck.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h
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 e6dcb2996cfe..db750cf6ec85 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h
@@ -16,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
@@ -103,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/HAL_timers_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp
similarity index 93%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp
index 8c01120cc786..6bbc16dcb55e 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/timers.cpp
@@ -28,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");
}
@@ -43,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");
}
@@ -54,7 +54,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
FTM0_SC = 0x00; // Set this to zero before changing the modulus
FTM0_CNT = 0x0000; // Reset the count to zero
FTM0_MOD = 0xFFFF; // max modulus = 65535
- FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
+ FTM0_C0V = (FTM0_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value
FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
@@ -63,7 +63,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
FTM1_SC = 0x00; // Set this to zero before changing the modulus
FTM1_CNT = 0x0000; // Reset the count to zero
FTM1_MOD = 0xFFFF; // max modulus = 65535
- FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
+ FTM1_C0V = (FTM1_TIMER_RATE) / frequency; // Initial FTM Channel 0 compare value 65535
FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/timers.h
similarity index 87%
rename from Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/timers.h
index 8263691947c9..8ae51107c74b 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/timers.h
@@ -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 97%
rename from Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
rename to Marlin/src/HAL/HAL_TEENSY35_36/watchdog.cpp
index 7924c0373063..f58217c75054 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog.cpp
@@ -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 96%
rename from Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
rename to Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h
index d2efaab37217..7c27260906c7 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h
@@ -23,7 +23,7 @@
void watchdog_init();
-inline void watchdog_reset() {
+inline void HAL_watchdog_refresh() {
// Watchdog refresh sequence
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
diff --git a/Marlin/src/HAL/platforms.h b/Marlin/src/HAL/platforms.h
index 48405f49f78b..e3e7f52cfaec 100644
--- a/Marlin/src/HAL/platforms.h
+++ b/Marlin/src/HAL/platforms.h
@@ -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 1bcfb9e8a65d..b1dafbb0f5d6 100644
--- a/Marlin/src/HAL/shared/Delay.h
+++ b/Marlin/src/HAL/shared/Delay.h
@@ -29,21 +29,22 @@
* 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__)
#if __CORTEX_M == 7
- // Cortex-M7 can use the cycle counter of the DWT unit
+ // Cortex-M3 through M7 can use the cycle counter of the DWT unit
// http://www.anthonyvh.com/2017/05/18/cortex_m-cycle_counter/
FORCE_INLINE static void enableCycleCounter() {
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
- // Unlock DWT.
- DWT->LAR = 0xC5ACCE55;
+ #if __CORTEX_M == 7
+ DWT->LAR = 0xC5ACCE55; // Unlock DWT on the M7
+ #endif
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
@@ -53,7 +54,7 @@
FORCE_INLINE static void DELAY_CYCLES(const uint32_t x) {
const uint32_t endCycles = getCycleCount() + x;
- while (PENDING(getCycleCount(), endCycles)) { }
+ while (PENDING(getCycleCount(), endCycles)) {}
}
#else
diff --git a/Marlin/src/HAL/shared/HAL_SPI.h b/Marlin/src/HAL/shared/HAL_SPI.h
index 16a58f673acc..d805207047da 100644
--- a/Marlin/src/HAL/shared/HAL_SPI.h
+++ b/Marlin/src/HAL/shared/HAL_SPI.h
@@ -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,18 +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
+//
// Standard SPI functions
-/** Initialize SPI bus */
-void spiBegin(void);
-/** Configure SPI for specified SPI speed */
+//
+
+// Initialize SPI bus
+void spiBegin();
+
+// Configure SPI for specified SPI speed
void spiInit(uint8_t spiRate);
-/** Write single byte to SPI */
+
+// Write single byte to SPI
void spiSend(uint8_t b);
-/** Read single byte from SPI */
-uint8_t spiRec(void);
-/** Read from SPI into buffer */
+
+// Read single byte from SPI
+uint8_t spiRec();
+
+// Read from SPI into buffer
void spiRead(uint8_t* buf, uint16_t nbyte);
-/** Write token and then write from 512 byte buffer to SPI (for SD card) */
+
+// Write token and then write from 512 byte buffer to SPI (for SD card)
void spiSendBlock(uint8_t token, const uint8_t* buf);
-/** Begin SPI transaction, set clock, bit order, data mode */
+
+// Begin SPI transaction, set clock, bit order, data mode
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode);
+
+//
+// Extended SPI functions taking a channel number (Hardware SPI only)
+//
+
+// Write single byte to specified SPI channel
+void spiSend(uint32_t chan, byte b);
+
+// Write buffer to specified SPI channel
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
+
+// Read single byte from specified SPI channel
+uint8_t spiRec(uint32_t chan);
diff --git a/Marlin/src/HAL/shared/Marduino.h b/Marlin/src/HAL/shared/Marduino.h
index d9440325f269..a2de03a2b6e4 100644
--- a/Marlin/src/HAL/shared/Marduino.h
+++ b/Marlin/src/HAL/shared/Marduino.h
@@ -29,6 +29,9 @@
#undef M_PI // Redefined by all
#undef _BV // Redefined by some
#undef sq // Redefined by teensy3/wiring.h
+#undef SBI // Redefined by arduino/const_functions.h
+#undef CBI // Redefined by arduino/const_functions.h
+#undef UNUSED // Redefined by stm32f4xx_hal_def.h
#include // NOTE: If included earlier then this line is a NOOP
@@ -54,6 +57,13 @@
inline const char* strchr_P(const char *s, int c) { return strchr(s,c); }
//#define strchr_P(s,c) strchr(s,c)
#endif
+
+ #ifndef snprintf_P
+ #define snprintf_P snprintf
+ #endif
+ #ifndef vsnprintf_P
+ #define vsnprintf_P vsnprintf
+ #endif
#endif
// Restart causes
@@ -68,3 +78,8 @@
#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/backtrace/backtrace.cpp b/Marlin/src/HAL/shared/backtrace/backtrace.cpp
index fc8abfa0e632..7a8377f789aa 100644
--- a/Marlin/src/HAL/shared/backtrace/backtrace.cpp
+++ b/Marlin/src/HAL/shared/backtrace/backtrace.cpp
@@ -20,10 +20,9 @@
*
*/
-#include "backtrace.h"
-
#if defined(__arm__) || defined(__thumb__)
+#include "backtrace.h"
#include "unwinder.h"
#include "unwmemaccess.h"
@@ -65,7 +64,7 @@ static const UnwindCallbacks UnwCallbacks = {
#endif
};
-void backtrace(void) {
+void backtrace() {
UnwindFrame btf;
uint32_t sp = 0, lr = 0, pc = 0;
@@ -95,6 +94,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 a3d7cc7e3dae..a2b8eae59412 100644
--- a/Marlin/src/HAL/shared/backtrace/backtrace.h
+++ b/Marlin/src/HAL/shared/backtrace/backtrace.h
@@ -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 fb4263a2728c..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;
}
diff --git a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
index ebd53cc1d9bb..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;
@@ -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 20f1a7bc0f23..8cf31cadf556 100644
--- a/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp
@@ -129,6 +129,17 @@
#define END_FLASH_ADDR 0x00140000
#endif
+#ifdef __SAMD51P20A__
+// For SAMD51x20, valid address ranges are
+// SRAM (0x20000000 - 0x20040000) (256kb)
+// FLASH (0x00000000 - 0x00100000) (1024kb)
+//
+#define START_SRAM_ADDR 0x20000000
+#define END_SRAM_ADDR 0x20040000
+#define START_FLASH_ADDR 0x00000000
+#define END_FLASH_ADDR 0x00100000
+#endif
+
static bool validate_addr(uint32_t addr) {
// Address must be in SRAM range
diff --git a/Marlin/src/HAL/shared/I2cEeprom.cpp b/Marlin/src/HAL/shared/eeprom_i2c.cpp
similarity index 64%
rename from Marlin/src/HAL/shared/I2cEeprom.cpp
rename to Marlin/src/HAL/shared/eeprom_i2c.cpp
index cc98ac183dc7..2752b7d4ccd5 100644
--- a/Marlin/src/HAL/shared/I2cEeprom.cpp
+++ b/Marlin/src/HAL/shared/eeprom_i2c.cpp
@@ -29,57 +29,21 @@
#if ENABLED(I2C_EEPROM)
-// --------------------------------------------------------------------------
-// Includes
-// --------------------------------------------------------------------------
-
-#include HAL_PATH(.., HAL.h)
+#include "../HAL.h"
#include
-// --------------------------------------------------------------------------
-// Externals
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Local defines
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Types
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Public Variables
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
+// ------------------------
// Private Variables
-// --------------------------------------------------------------------------
+// ------------------------
-// --------------------------------------------------------------------------
-// Function prototypes
-// --------------------------------------------------------------------------
-
-// --------------------------------------------------------------------------
-// Private functions
-// --------------------------------------------------------------------------
+static uint8_t eeprom_device_address = 0x50;
-// --------------------------------------------------------------------------
+// ------------------------
// Public functions
-// --------------------------------------------------------------------------
-
-static uint8_t eeprom_device_address = 0x50;
+// ------------------------
-static void eeprom_init(void) {
- static bool eeprom_initialized = false;
- if (!eeprom_initialized) {
- Wire.begin();
- eeprom_initialized = true;
- }
+static void eeprom_init() {
+ Wire.begin();
}
void eeprom_write_byte(uint8_t *pos, unsigned char value) {
@@ -127,7 +91,6 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
}
}
-
uint8_t eeprom_read_byte(uint8_t *pos) {
unsigned eeprom_address = (unsigned)pos;
@@ -141,7 +104,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
return Wire.available() ? Wire.read() : 0xFF;
}
-// maybe let's not read more than 30 or 32 bytes at a time!
+// Don't read more than 30..32 bytes at a time!
void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
eeprom_init();
diff --git a/Marlin/src/HAL/shared/SpiEeprom.cpp b/Marlin/src/HAL/shared/eeprom_spi.cpp
similarity index 99%
rename from Marlin/src/HAL/shared/SpiEeprom.cpp
rename to Marlin/src/HAL/shared/eeprom_spi.cpp
index cbdb4d29859d..35e7d9b0a952 100644
--- a/Marlin/src/HAL/shared/SpiEeprom.cpp
+++ b/Marlin/src/HAL/shared/eeprom_spi.cpp
@@ -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
diff --git a/Marlin/src/HAL/shared/servo.cpp b/Marlin/src/HAL/shared/servo.cpp
index af338536654f..b5975e58e708 100644
--- a/Marlin/src/HAL/shared/servo.cpp
+++ b/Marlin/src/HAL/shared/servo.cpp
@@ -58,11 +58,11 @@
#include "servo.h"
#include "servo_private.h"
-ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures
-uint8_t ServoCount = 0; // the total number of attached servos
+ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures
+uint8_t ServoCount = 0; // the total number of attached servos
-#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo
-#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo
+#define SERVO_MIN(v) (MIN_PULSE_WIDTH - (v) * 4) // minimum value in uS for this servo
+#define SERVO_MAX(v) (MAX_PULSE_WIDTH - (v) * 4) // maximum value in uS for this servo
/************ static functions common to all instances ***********************/
@@ -79,55 +79,54 @@ static boolean isTimerActive(timer16_Sequence_t timer) {
Servo::Servo() {
if (ServoCount < MAX_SERVOS) {
- this->servoIndex = ServoCount++; // assign a servo index to this instance
- servo_info[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009
+ servoIndex = ServoCount++; // assign a servo index to this instance
+ servo_info[servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009
}
else
- this->servoIndex = INVALID_SERVO; // too many servos
+ servoIndex = INVALID_SERVO; // too many servos
}
-int8_t Servo::attach(const int pin) {
- return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
+int8_t Servo::attach(const int inPin) {
+ return attach(inPin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
}
-int8_t Servo::attach(const int pin, const int min, const int max) {
+int8_t Servo::attach(const int inPin, const int inMin, const int inMax) {
- if (this->servoIndex >= MAX_SERVOS) return -1;
+ if (servoIndex >= MAX_SERVOS) return -1;
- if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
- pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
+ if (inPin > 0) servo_info[servoIndex].Pin.nbr = inPin;
+ pinMode(servo_info[servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
- // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128
- this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
- this->max = (MAX_PULSE_WIDTH - max) / 4;
+ // TODO: min/max check: ABS(min - MIN_PULSE_WIDTH) / 4 < 128
+ min = (MIN_PULSE_WIDTH - inMin) / 4; //resolution of min/max is 4 uS
+ max = (MAX_PULSE_WIDTH - inMax) / 4;
// initialize the timer if it has not already been initialized
timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
if (!isTimerActive(timer)) initISR(timer);
- servo_info[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive
+ servo_info[servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive
- return this->servoIndex;
+ return servoIndex;
}
void Servo::detach() {
- servo_info[this->servoIndex].Pin.isActive = false;
+ servo_info[servoIndex].Pin.isActive = false;
timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
if (!isTimerActive(timer)) finISR(timer);
}
void Servo::write(int value) {
- if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
- value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
- }
- this->writeMicroseconds(value);
+ if (value < MIN_PULSE_WIDTH) // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
+ value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(min), SERVO_MAX(max));
+ writeMicroseconds(value);
}
void Servo::writeMicroseconds(int value) {
// calculate and store the values for the given channel
- byte channel = this->servoIndex;
+ byte channel = servoIndex;
if (channel < MAX_SERVOS) { // ensure channel is valid
// ensure pulse width is valid
- value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
+ value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
CRITICAL_SECTION_START;
@@ -137,22 +136,22 @@ void Servo::writeMicroseconds(int value) {
}
// return the value as degrees
-int Servo::read() { return map(this->readMicroseconds() + 1, SERVO_MIN(), SERVO_MAX(), 0, 180); }
+int Servo::read() { return map(readMicroseconds() + 1, SERVO_MIN(min), SERVO_MAX(max), 0, 180); }
int Servo::readMicroseconds() {
- return (this->servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[this->servoIndex].ticks) + TRIM_DURATION;
+ return (servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[servoIndex].ticks) + (TRIM_DURATION);
}
-bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
+bool Servo::attached() { return servo_info[servoIndex].Pin.isActive; }
void Servo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
- if (this->attach(0) >= 0) {
- this->write(value);
- safe_delay(servo_delay[this->servoIndex]);
+ if (attach(0) >= 0) {
+ write(value);
+ safe_delay(servo_delay[servoIndex]);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- this->detach();
+ detach();
#endif
}
}
diff --git a/Marlin/src/HAL/shared/servo.h b/Marlin/src/HAL/shared/servo.h
index b6b2d13e98cb..e4905b7295c8 100644
--- a/Marlin/src/HAL/shared/servo.h
+++ b/Marlin/src/HAL/shared/servo.h
@@ -67,29 +67,27 @@
* With DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY and detach.
*/
-#pragma once
-
#if IS_TEENSY32
- #include "../HAL_TEENSY31_32/HAL_Servo_Teensy.h"
+ #include "../HAL_TEENSY31_32/Servo.h"
#elif IS_TEENSY35 || IS_TEENSY36
- #include "../HAL_TEENSY35_36/HAL_Servo_Teensy.h"
+ #include "../HAL_TEENSY35_36/Servo.h"
#elif defined(TARGET_LPC1768)
- #include "../HAL_LPC1768/HAL_Servo_LPC1768.h"
+ #include "../HAL_LPC1768/Servo.h"
#elif defined(__STM32F1__) || defined(TARGET_STM32F1)
- #include "../HAL_STM32F1/HAL_Servo_STM32F1.h"
+ #include "../HAL_STM32F1/Servo.h"
#elif defined(STM32GENERIC) && defined(STM32F4)
- #include "../HAL_STM32F4/HAL_Servo_STM32F4.h"
+ #include "../HAL_STM32_F4_F7/Servo.h"
#elif defined(ARDUINO_ARCH_STM32)
- #include "../HAL_STM32/HAL_Servo_STM32.h"
+ #include "../HAL_STM32/Servo.h"
#elif defined(ARDUINO_ARCH_ESP32)
- #include "../HAL_ESP32/HAL_Servo_ESP32.h"
+ #include "../HAL_ESP32/Servo.h"
#else
#include
- #if defined(__AVR__) || defined(ARDUINO_ARCH_SAM)
+ #if defined(__AVR__) || defined(ARDUINO_ARCH_SAM) || defined(__SAMD51__)
// we're good to go
#else
- #error "This library only supports boards with an AVR or SAM3X processor."
+ #error "This library only supports boards with an AVR, SAM3X or SAMD51 processor."
#endif
#define Servo_VERSION 2 // software version of this library
diff --git a/Marlin/src/HAL/shared/servo_private.h b/Marlin/src/HAL/shared/servo_private.h
index 12d4740525dd..1d4cdc7e3eb8 100644
--- a/Marlin/src/HAL/shared/servo_private.h
+++ b/Marlin/src/HAL/shared/servo_private.h
@@ -47,8 +47,10 @@
#include "../HAL_AVR/ServoTimers.h"
#elif defined(ARDUINO_ARCH_SAM)
#include "../HAL_DUE/ServoTimers.h"
+#elif defined(__SAMD51__)
+ #include "../HAL_SAMD51/ServoTimers.h"
#else
- #error "This library only supports boards with an AVR or SAM3X processor."
+ #error "This library only supports boards with an AVR, SAM3X or SAMD51 processor."
#endif
// Macros
@@ -64,10 +66,8 @@
#define INVALID_SERVO 255 // flag indicating an invalid servo index
// Convert microseconds to ticks and back (PRESCALER depends on architecture)
-#define usToTicks(_us) (clockCyclesPerMicrosecond() * (_us) / (PRESCALER))
-#define ticksToUs(_ticks) (unsigned(_ticks) * (PRESCALER) / clockCyclesPerMicrosecond())
-
-//#define NBR_TIMERS ((MAX_SERVOS) / (SERVOS_PER_TIMER))
+#define usToTicks(_us) (clockCyclesPerMicrosecond() * (_us) / (SERVO_TIMER_PRESCALER))
+#define ticksToUs(_ticks) (unsigned(_ticks) * (SERVO_TIMER_PRESCALER) / clockCyclesPerMicrosecond())
// convenience macros
#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo
@@ -78,7 +78,7 @@
// Types
typedef struct {
- uint8_t nbr : 6 ; // a pin number from 0 to 63
+ uint8_t nbr : 7 ; // a pin number from 0 to 127
uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false
} ServoPin_t;
diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp
index e73066fabfaf..a03d1f396359 100644
--- a/Marlin/src/Marlin.cpp
+++ b/Marlin/src/Marlin.cpp
@@ -45,7 +45,7 @@
#include "HAL/shared/Delay.h"
-#include "module/stepper_indirection.h"
+#include "module/stepper/indirection.h"
#ifdef ARDUINO
#include
@@ -57,11 +57,15 @@
#include "gcode/parser.h"
#include "gcode/queue.h"
+#if ENABLED(TOUCH_BUTTONS)
+ #include "feature/touch/xpt2046.h"
+#endif
+
#if ENABLED(HOST_ACTION_COMMANDS)
#include "feature/host_actions.h"
#endif
-#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
+#if USE_BEEPER
#include "libs/buzzer.h"
#endif
@@ -85,6 +89,10 @@
#include "feature/bltouch.h"
#endif
+#if ENABLED(POLL_JOG)
+ #include "feature/joystick.h"
+#endif
+
#if HAS_SERVOS
#include "module/servo.h"
#endif
@@ -102,7 +110,7 @@
#include "feature/I2CPositionEncoder.h"
#endif
-#if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
+#if HAS_TRINAMIC && DISABLED(PSU_DEFAULT_OFF)
#include "feature/tmc_util.h"
#endif
@@ -137,6 +145,10 @@
#include "feature/power_loss_recovery.h"
#endif
+#if ENABLED(CANCEL_OBJECTS)
+ #include "feature/cancel_object.h"
+#endif
+
#if HAS_FILAMENT_SENSOR
#include "feature/runout.h"
#endif
@@ -165,14 +177,20 @@
#include "feature/prusa_MMU2/mmu2.h"
#endif
-#if ENABLED(EXTENSIBLE_UI)
- #include "lcd/extensible_ui/ui_api.h"
-#endif
-
#if HAS_DRIVER(L6470)
#include "libs/L6470/L6470_Marlin.h"
#endif
+const char NUL_STR[] PROGMEM = "",
+ G28_STR[] PROGMEM = "G28",
+ M21_STR[] PROGMEM = "M21",
+ M23_STR[] PROGMEM = "M23 %s",
+ M24_STR[] PROGMEM = "M24",
+ SP_X_STR[] PROGMEM = " X",
+ SP_Y_STR[] PROGMEM = " Y",
+ SP_Z_STR[] PROGMEM = " Z",
+ SP_E_STR[] PROGMEM = " E";
+
bool Running = true;
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
@@ -213,10 +231,10 @@ void setup_killpin() {
void setup_powerhold() {
#if HAS_SUICIDE
- OUT_WRITE(SUICIDE_PIN, HIGH);
+ OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
#endif
- #if HAS_POWER_SWITCH
- #if ENABLED(PS_DEFAULT_OFF)
+ #if ENABLED(PSU_CONTROL)
+ #if ENABLED(PSU_DEFAULT_OFF)
powersupply_on = true; PSU_OFF();
#else
powersupply_on = false; PSU_ON();
@@ -271,6 +289,11 @@ void quickstop_stepper() {
sync_plan_position();
}
+void enable_e_steppers() {
+ #define _ENA_E(N) enable_E##N();
+ REPEAT(E_STEPPERS, _ENA_E)
+}
+
void enable_all_steppers() {
#if ENABLED(AUTO_POWER_CONTROL)
powerManager.power_on();
@@ -278,31 +301,18 @@ void enable_all_steppers() {
enable_X();
enable_Y();
enable_Z();
- enable_E0();
- enable_E1();
- enable_E2();
- enable_E3();
- enable_E4();
- enable_E5();
+ enable_e_steppers();
}
void disable_e_steppers() {
- disable_E0();
- disable_E1();
- disable_E2();
- disable_E3();
- disable_E4();
- disable_E5();
+ #define _DIS_E(N) disable_E##N();
+ REPEAT(E_STEPPERS, _DIS_E)
}
void disable_e_stepper(const uint8_t e) {
+ #define _CASE_DIS_E(N) case N: disable_E##N(); break;
switch (e) {
- case 0: disable_E0(); break;
- case 1: disable_E1(); break;
- case 2: disable_E2(); break;
- case 3: disable_E3(); break;
- case 4: disable_E4(); break;
- case 5: disable_E5(); break;
+ REPEAT(EXTRUDERS, _CASE_DIS_E)
}
}
@@ -313,71 +323,6 @@ void disable_all_steppers() {
disable_e_steppers();
}
-#if HAS_FILAMENT_SENSOR
-
- void event_filament_runout() {
-
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout.
- #endif
-
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onFilamentRunout(ExtUI::getActiveTool());
- #endif
-
- #if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS)
- const char tool = '0'
- #if NUM_RUNOUT_SENSORS > 1
- + active_extruder
- #endif
- ;
- #endif
-
- //action:out_of_filament
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
- host_action_prompt_end();
- host_action_prompt_begin(PSTR("FilamentRunout T"), false);
- SERIAL_CHAR(tool);
- SERIAL_EOL();
- host_action_prompt_show();
- #endif
-
- const bool run_runout_script = !runout.host_handling;
-
- #if ENABLED(HOST_ACTION_COMMANDS)
- if (run_runout_script
- && ( strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
- || strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- || strstr(FILAMENT_RUNOUT_SCRIPT, "M25")
- #endif
- )
- ) {
- host_action_paused(false);
- }
- else {
- // Legacy Repetier command for use until newer version supports standard dialog
- // To be removed later when pause command also triggers dialog
- #ifdef ACTION_ON_FILAMENT_RUNOUT
- host_action(PSTR(ACTION_ON_FILAMENT_RUNOUT " T"), false);
- SERIAL_CHAR(tool);
- SERIAL_EOL();
- #endif
-
- host_action_pause(false);
- }
- SERIAL_ECHOPGM(" " ACTION_REASON_ON_FILAMENT_RUNOUT " ");
- SERIAL_CHAR(tool);
- SERIAL_EOL();
- #endif // HOST_ACTION_COMMANDS
-
- if (run_runout_script)
- queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
- }
-
-#endif // HAS_FILAMENT_SENSOR
-
#if ENABLED(G29_RETRY_AND_RECOVER)
void event_probe_failure() {
@@ -391,13 +336,13 @@ void disable_all_steppers() {
#ifdef ACTION_ON_CANCEL
host_action_cancel();
#endif
- kill(PSTR(MSG_ERR_PROBING_FAILED));
+ kill(GET_TEXT(MSG_LCD_PROBING_FAILED));
#endif
}
void event_probe_recover() {
#if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"));
+ host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"), PSTR("Dismiss"));
#endif
#ifdef ACTION_ON_G29_RECOVER
host_action(PSTR(ACTION_ON_G29_RECOVER));
@@ -409,6 +354,67 @@ void disable_all_steppers() {
#endif
+#if ENABLED(ADVANCED_PAUSE_FEATURE)
+ #include "feature/pause.h"
+#else
+ constexpr bool did_pause_print = false;
+#endif
+
+/**
+ * Printing is active when the print job timer is running
+ */
+bool printingIsActive() {
+ return !did_pause_print && (print_job_timer.isRunning() || IS_SD_PRINTING());
+}
+
+/**
+ * Printing is paused according to SD or host indicators
+ */
+bool printingIsPaused() {
+ return did_pause_print || print_job_timer.isPaused() || IS_SD_PAUSED();
+}
+
+void startOrResumeJob() {
+ if (!printingIsPaused()) {
+ #if ENABLED(CANCEL_OBJECTS)
+ cancelable.reset();
+ #endif
+ #if ENABLED(LCD_SHOW_E_TOTAL)
+ e_move_accumulator = 0;
+ #endif
+ #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
+ ui.reset_remaining_time();
+ #endif
+ }
+ print_job_timer.start();
+}
+
+#if ENABLED(SDSUPPORT)
+
+ void abortSDPrinting() {
+ card.stopSDPrint(
+ #if SD_RESORT
+ true
+ #endif
+ );
+ queue.clear();
+ quickstop_stepper();
+ print_job_timer.stop();
+ #if DISABLED(SD_ABORT_NO_COOLDOWN)
+ thermalManager.disable_all_heaters();
+ #endif
+ thermalManager.zero_fan_speeds();
+ wait_for_heatup = false;
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ card.removeJobRecoveryFile();
+ #endif
+ #ifdef EVENT_GCODE_SD_STOP
+ queue.inject_P(PSTR(EVENT_GCODE_SD_STOP));
+ #endif
+ }
+
+#endif
+
/**
* Manage several activities:
* - Check for Filament Runout
@@ -514,7 +520,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
if (ELAPSED(ms, next_home_key_ms)) {
next_home_key_ms = ms + HOME_DEBOUNCE_DELAY;
LCD_MESSAGEPGM(MSG_AUTO_HOME);
- queue.enqueue_now_P(PSTR("G28"));
+ queue.enqueue_now_P(G28_STR);
}
}
#endif
@@ -535,40 +541,27 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
#if ENABLED(SWITCHING_EXTRUDER)
bool oldstatus;
switch (active_extruder) {
- default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
+ default: oldstatus = E0_ENABLE_READ(); enable_E0(); break;
#if E_STEPPERS > 1
- case 2: case 3: oldstatus = E1_ENABLE_READ; enable_E1(); break;
+ case 2: case 3: oldstatus = E1_ENABLE_READ(); enable_E1(); break;
#if E_STEPPERS > 2
- case 4: case 5: oldstatus = E2_ENABLE_READ; enable_E2(); break;
+ case 4: case 5: oldstatus = E2_ENABLE_READ(); enable_E2(); break;
#endif // E_STEPPERS > 2
#endif // E_STEPPERS > 1
}
#else // !SWITCHING_EXTRUDER
bool oldstatus;
switch (active_extruder) {
- default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
- #if E_STEPPERS > 1
- case 1: oldstatus = E1_ENABLE_READ; enable_E1(); break;
- #if E_STEPPERS > 2
- case 2: oldstatus = E2_ENABLE_READ; enable_E2(); break;
- #if E_STEPPERS > 3
- case 3: oldstatus = E3_ENABLE_READ; enable_E3(); break;
- #if E_STEPPERS > 4
- case 4: oldstatus = E4_ENABLE_READ; enable_E4(); break;
- #if E_STEPPERS > 5
- case 5: oldstatus = E5_ENABLE_READ; enable_E5(); break;
- #endif // E_STEPPERS > 5
- #endif // E_STEPPERS > 4
- #endif // E_STEPPERS > 3
- #endif // E_STEPPERS > 2
- #endif // E_STEPPERS > 1
+ default:
+ #define _CASE_EN(N) case N: oldstatus = E##N##_ENABLE_READ(); enable_E##N(); break;
+ REPEAT(E_STEPPERS, _CASE_EN);
}
- #endif // !SWITCHING_EXTRUDER
+ #endif
- const float olde = current_position[E_AXIS];
- current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
- planner.buffer_line(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
- current_position[E_AXIS] = olde;
+ const float olde = current_position.e;
+ current_position.e += EXTRUDER_RUNOUT_EXTRUDE;
+ line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED));
+ current_position.e = olde;
planner.set_e_position_mm(olde);
planner.synchronize();
@@ -584,22 +577,8 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
}
#else // !SWITCHING_EXTRUDER
switch (active_extruder) {
- case 0: E0_ENABLE_WRITE(oldstatus); break;
- #if E_STEPPERS > 1
- case 1: E1_ENABLE_WRITE(oldstatus); break;
- #if E_STEPPERS > 2
- case 2: E2_ENABLE_WRITE(oldstatus); break;
- #if E_STEPPERS > 3
- case 3: E3_ENABLE_WRITE(oldstatus); break;
- #if E_STEPPERS > 4
- case 4: E4_ENABLE_WRITE(oldstatus); break;
- #if E_STEPPERS > 5
- case 5: E5_ENABLE_WRITE(oldstatus); break;
- #endif // E_STEPPERS > 5
- #endif // E_STEPPERS > 4
- #endif // E_STEPPERS > 3
- #endif // E_STEPPERS > 2
- #endif // E_STEPPERS > 1
+ #define _CASE_RESTORE(N) case N: E##N##_ENABLE_WRITE(oldstatus); break;
+ REPEAT(E_STEPPERS, _CASE_RESTORE);
}
#endif // !SWITCHING_EXTRUDER
@@ -612,7 +591,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
// travel moves have been received so enact them
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
- set_destination_from_current();
+ destination = current_position;
prepare_move_to_destination();
}
#endif
@@ -622,7 +601,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
#endif
#if ENABLED(MONITOR_DRIVER_STATUS)
- monitor_tmc_driver();
+ monitor_tmc_drivers();
#endif
#if ENABLED(MONITOR_L6470_DRIVER_STATUS)
@@ -655,6 +634,21 @@ void idle(
bool no_stepper_sleep/*=false*/
#endif
) {
+ #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
+ recovery.outage();
+ #endif
+
+ #if ENABLED(SPI_ENDSTOPS)
+ if (endstops.tmc_spi_homing.any
+ #if ENABLED(IMPROVE_HOMING_RELIABILITY)
+ && ELAPSED(millis(), sg_guard_period)
+ #endif
+ ) {
+ for (uint8_t i = 4; i--;) // Read SGT 4 times per idle loop
+ if (endstops.tmc_spi_homing_check()) break;
+ }
+ #endif
+
#if ENABLED(MAX7219_DEBUG)
max7219.idle_tasks();
#endif
@@ -677,15 +671,18 @@ void idle(
print_job_timer.tick();
#endif
- #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
+ #if USE_BEEPER
buzzer.tick();
#endif
#if ENABLED(I2C_POSITION_ENCODERS)
static millis_t i2cpem_next_update_ms;
- if (planner.has_blocks_queued() && ELAPSED(millis(), i2cpem_next_update_ms)) {
- I2CPEM.update();
- i2cpem_next_update_ms = millis() + I2CPE_MIN_UPD_TIME_MS;
+ if (planner.has_blocks_queued()) {
+ const millis_t ms = millis();
+ if (ELAPSED(ms, i2cpem_next_update_ms)) {
+ I2CPEM.update();
+ i2cpem_next_update_ms = ms + I2CPE_MIN_UPD_TIME_MS;
+ }
}
#endif
@@ -711,31 +708,36 @@ void idle(
#if ENABLED(PRUSA_MMU2)
mmu2.mmu_loop();
#endif
+
+ #if ENABLED(POLL_JOG)
+ joystick.inject_jog_moves();
+ #endif
}
/**
* Kill all activity and lock the machine.
* After this the machine will need to be reset.
*/
-void kill(PGM_P const lcd_msg/*=nullptr*/) {
+void kill(PGM_P const lcd_error/*=nullptr*/, PGM_P const lcd_component/*=nullptr*/, const bool steppers_off/*=false*/) {
thermalManager.disable_all_heaters();
SERIAL_ERROR_MSG(MSG_ERR_KILLED);
#if HAS_DISPLAY
- ui.kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
+ ui.kill_screen(lcd_error ?: GET_TEXT(MSG_KILLED), lcd_component ?: NUL_STR);
#else
- UNUSED(lcd_msg);
+ UNUSED(lcd_error);
+ UNUSED(lcd_component);
#endif
#ifdef ACTION_ON_KILL
host_action_kill();
#endif
- minkill();
+ minkill(steppers_off);
}
-void minkill() {
+void minkill(const bool steppers_off/*=false*/) {
// Wait a short time (allows messages to get out before shutting down.
for (int i = 1000; i--;) DELAY_US(600);
@@ -745,9 +747,13 @@ void minkill() {
// Wait to ensure all interrupts stopped
for (int i = 1000; i--;) DELAY_US(250);
- thermalManager.disable_all_heaters(); // turn off heaters again
+ // Reiterate heaters off
+ thermalManager.disable_all_heaters();
- #if HAS_POWER_SWITCH
+ // Power off all steppers (for M112) or just the E steppers
+ steppers_off ? disable_all_steppers() : disable_e_steppers();
+
+ #if ENABLED(PSU_CONTROL)
PSU_OFF();
#endif
@@ -758,29 +764,17 @@ void minkill() {
#if HAS_KILL
// Wait for kill to be released
- while (!READ(KILL_PIN)) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_reset();
- #endif
- }
+ while (!READ(KILL_PIN)) watchdog_refresh();
// Wait for kill to be pressed
- while (READ(KILL_PIN)) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_reset();
- #endif
- }
+ while (READ(KILL_PIN)) watchdog_refresh();
- void(*resetFunc)(void) = 0; // Declare resetFunc() at address 0
- resetFunc(); // Jump to address 0
+ void (*resetFunc)() = 0; // Declare resetFunc() at address 0
+ resetFunc(); // Jump to address 0
#else // !HAS_KILL
- for (;;) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_reset();
- #endif
- } // Wait for reset
+ for (;;) watchdog_refresh(); // Wait for reset
#endif // !HAS_KILL
}
@@ -858,9 +852,13 @@ void setup() {
runout.setup();
#endif
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ recovery.setup();
+ #endif
+
setup_killpin();
- #if HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209)
+ #if HAS_TMC220x
tmc_serial_begin();
#endif
@@ -915,10 +913,11 @@ void setup() {
SERIAL_EOL();
#if defined(STRING_DISTRIBUTION_DATE) && defined(STRING_CONFIG_H_AUTHOR)
- SERIAL_ECHO_START();
- SERIAL_ECHOPGM(MSG_CONFIGURATION_VER);
- SERIAL_ECHOPGM(STRING_DISTRIBUTION_DATE);
- SERIAL_ECHOLNPGM(MSG_AUTHOR STRING_CONFIG_H_AUTHOR);
+ SERIAL_ECHO_MSG(
+ MSG_CONFIGURATION_VER
+ STRING_DISTRIBUTION_DATE
+ MSG_AUTHOR STRING_CONFIG_H_AUTHOR
+ );
SERIAL_ECHO_MSG("Compiled: " __DATE__);
#endif
@@ -927,25 +926,32 @@ void setup() {
// UI must be initialized before EEPROM
// (because EEPROM code calls the UI).
- ui.init();
- ui.reset_status();
+ // Set up LEDs early
+ #if HAS_COLOR_LEDS
+ leds.setup();
+ #endif
+
+ ui.init();
#if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN)
ui.show_bootscreen();
#endif
- #if ENABLED(SDIO_SUPPORT) && !PIN_EXISTS(SD_DETECT)
- // Auto-mount the SD for EEPROM.dat emulation
- if (!card.isDetected()) card.initsd();
+ #if ENABLED(SDSUPPORT)
+ card.mount(); // Mount the SD card before settings.first_load
#endif
// Load data from EEPROM if available (or use defaults)
// This also updates variables in the planner, elsewhere
- (void)settings.load();
+ settings.first_load();
+
+ #if ENABLED(TOUCH_BUTTONS)
+ touch.init();
+ #endif
#if HAS_M206_COMMAND
// Initialize current position based on home_offset
- LOOP_XYZ(a) current_position[a] += home_offset[a];
+ current_position += home_offset;
#endif
// Vital to init stepper/planner equivalent for current_position
@@ -955,6 +961,8 @@ void setup() {
print_job_timer.init(); // Initial setup of print job timer
+ ui.reset_status(); // Print startup message after print statistics are loaded
+
endstops.init(); // Init endstops and pullups
stepper.init(); // Init stepper. This enables interrupts!
@@ -1018,10 +1026,6 @@ void setup() {
OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // OFF
#endif
- #if HAS_COLOR_LEDS
- leds.setup();
- #endif
-
#if HAS_CASE_LIGHT
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
@@ -1094,11 +1098,19 @@ void setup() {
init_closedloop();
#endif
+ #ifdef STARTUP_COMMANDS
+ queue.inject_P(PSTR(STARTUP_COMMANDS));
+ #endif
+
#if ENABLED(INIT_SDCARD_ON_BOOT) && !HAS_SPI_LCD
card.beginautostart();
#endif
- #if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
+ #if ENABLED(HOST_PROMPT_SUPPORT)
+ host_action_prompt_end();
+ #endif
+
+ #if HAS_TRINAMIC && DISABLED(PSU_DEFAULT_OFF)
test_tmc_connection(true, true, true, true);
#endif
@@ -1119,37 +1131,15 @@ void loop() {
for (;;) {
- #if ENABLED(SDSUPPORT)
+ idle(); // Do an idle first so boot is slightly faster
+ #if ENABLED(SDSUPPORT)
card.checkautostart();
+ if (card.flag.abort_sd_printing) abortSDPrinting();
+ #endif
- if (card.flag.abort_sd_printing) {
- card.stopSDPrint(
- #if SD_RESORT
- true
- #endif
- );
- queue.clear();
- quickstop_stepper();
- print_job_timer.stop();
- #if DISABLED(SD_ABORT_NO_COOLDOWN)
- thermalManager.disable_all_heaters();
- #endif
- thermalManager.zero_fan_speeds();
- wait_for_heatup = false;
- #if ENABLED(POWER_LOSS_RECOVERY)
- card.removeJobRecoveryFile();
- #endif
- #ifdef EVENT_GCODE_SD_STOP
- queue.inject_P(PSTR(EVENT_GCODE_SD_STOP));
- #endif
- }
-
- #endif // SDSUPPORT
-
- if (queue.length < BUFSIZE) queue.get_available_commands();
queue.advance();
+
endstops.event_handler();
- idle();
}
}
diff --git a/Marlin/src/Marlin.h b/Marlin/src/Marlin.h
index cef5950b990b..8b44298a91bb 100644
--- a/Marlin/src/Marlin.h
+++ b/Marlin/src/Marlin.h
@@ -51,96 +51,96 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
//
#if AXIS_DRIVER_TYPE_X(L6470)
extern L6470 stepperX;
- #define X_enable NOOP
- #define X_disable stepperX.free()
+ #define X_enable() NOOP
+ #define X_disable() stepperX.free()
#elif HAS_X_ENABLE
- #define X_enable X_ENABLE_WRITE( X_ENABLE_ON)
- #define X_disable X_ENABLE_WRITE(!X_ENABLE_ON)
+ #define X_enable() X_ENABLE_WRITE( X_ENABLE_ON)
+ #define X_disable() X_ENABLE_WRITE(!X_ENABLE_ON)
#else
- #define X_enable NOOP
- #define X_disable NOOP
+ #define X_enable() NOOP
+ #define X_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_X2(L6470)
extern L6470 stepperX2;
- #define X2_enable NOOP
- #define X2_disable stepperX2.free()
+ #define X2_enable() NOOP
+ #define X2_disable() stepperX2.free()
#elif HAS_X2_ENABLE
- #define X2_enable X2_ENABLE_WRITE( X_ENABLE_ON)
- #define X2_disable X2_ENABLE_WRITE(!X_ENABLE_ON)
+ #define X2_enable() X2_ENABLE_WRITE( X_ENABLE_ON)
+ #define X2_disable() X2_ENABLE_WRITE(!X_ENABLE_ON)
#else
- #define X2_enable NOOP
- #define X2_disable NOOP
+ #define X2_enable() NOOP
+ #define X2_disable() NOOP
#endif
-#define enable_X() do{ X_enable; X2_enable; }while(0)
-#define disable_X() do{ X_disable; X2_disable; CBI(axis_known_position, X_AXIS); }while(0)
+#define enable_X() do{ X_enable(); X2_enable(); }while(0)
+#define disable_X() do{ X_disable(); X2_disable(); CBI(axis_known_position, X_AXIS); }while(0)
#if AXIS_DRIVER_TYPE_Y(L6470)
extern L6470 stepperY;
- #define Y_enable NOOP
- #define Y_disable stepperY.free()
+ #define Y_enable() NOOP
+ #define Y_disable() stepperY.free()
#elif HAS_Y_ENABLE
- #define Y_enable Y_ENABLE_WRITE( Y_ENABLE_ON)
- #define Y_disable Y_ENABLE_WRITE(!Y_ENABLE_ON)
+ #define Y_enable() Y_ENABLE_WRITE( Y_ENABLE_ON)
+ #define Y_disable() Y_ENABLE_WRITE(!Y_ENABLE_ON)
#else
- #define Y_enable NOOP
- #define Y_disable NOOP
+ #define Y_enable() NOOP
+ #define Y_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_Y2(L6470)
extern L6470 stepperY2;
- #define Y2_enable NOOP
- #define Y2_disable stepperY2.free()
+ #define Y2_enable() NOOP
+ #define Y2_disable() stepperY2.free()
#elif HAS_Y2_ENABLE
- #define Y2_enable Y2_ENABLE_WRITE( Y_ENABLE_ON)
- #define Y2_disable Y2_ENABLE_WRITE(!Y_ENABLE_ON)
+ #define Y2_enable() Y2_ENABLE_WRITE( Y_ENABLE_ON)
+ #define Y2_disable() Y2_ENABLE_WRITE(!Y_ENABLE_ON)
#else
- #define Y2_enable NOOP
- #define Y2_disable NOOP
+ #define Y2_enable() NOOP
+ #define Y2_disable() NOOP
#endif
-#define enable_Y() do{ Y_enable; Y2_enable; }while(0)
-#define disable_Y() do{ Y_disable; Y2_disable; CBI(axis_known_position, Y_AXIS); }while(0)
+#define enable_Y() do{ Y_enable(); Y2_enable(); }while(0)
+#define disable_Y() do{ Y_disable(); Y2_disable(); CBI(axis_known_position, Y_AXIS); }while(0)
#if AXIS_DRIVER_TYPE_Z(L6470)
extern L6470 stepperZ;
- #define Z_enable NOOP
- #define Z_disable stepperZ.free()
+ #define Z_enable() NOOP
+ #define Z_disable() stepperZ.free()
#elif HAS_Z_ENABLE
- #define Z_enable Z_ENABLE_WRITE( Z_ENABLE_ON)
- #define Z_disable Z_ENABLE_WRITE(!Z_ENABLE_ON)
+ #define Z_enable() Z_ENABLE_WRITE( Z_ENABLE_ON)
+ #define Z_disable() Z_ENABLE_WRITE(!Z_ENABLE_ON)
#else
- #define Z_enable NOOP
- #define Z_disable NOOP
+ #define Z_enable() NOOP
+ #define Z_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_Z2(L6470)
extern L6470 stepperZ2;
- #define Z2_enable NOOP
- #define Z2_disable stepperZ2.free()
+ #define Z2_enable() NOOP
+ #define Z2_disable() stepperZ2.free()
#elif HAS_Z2_ENABLE
- #define Z2_enable Z2_ENABLE_WRITE( Z_ENABLE_ON)
- #define Z2_disable Z2_ENABLE_WRITE(!Z_ENABLE_ON)
+ #define Z2_enable() Z2_ENABLE_WRITE( Z_ENABLE_ON)
+ #define Z2_disable() Z2_ENABLE_WRITE(!Z_ENABLE_ON)
#else
- #define Z2_enable NOOP
- #define Z2_disable NOOP
+ #define Z2_enable() NOOP
+ #define Z2_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_Z3(L6470)
extern L6470 stepperZ3;
- #define Z3_enable NOOP
- #define Z3_disable stepperZ3.free()
+ #define Z3_enable() NOOP
+ #define Z3_disable() stepperZ3.free()
#elif HAS_Z3_ENABLE
- #define Z3_enable Z3_ENABLE_WRITE( Z_ENABLE_ON)
- #define Z3_disable Z3_ENABLE_WRITE(!Z_ENABLE_ON)
+ #define Z3_enable() Z3_ENABLE_WRITE( Z_ENABLE_ON)
+ #define Z3_disable() Z3_ENABLE_WRITE(!Z_ENABLE_ON)
#else
- #define Z3_enable NOOP
- #define Z3_disable NOOP
+ #define Z3_enable() NOOP
+ #define Z3_disable() NOOP
#endif
-#define enable_Z() do{ Z_enable; Z2_enable; Z3_enable; }while(0)
-#define disable_Z() do{ Z_disable; Z2_disable; Z3_disable; CBI(axis_known_position, Z_AXIS); }while(0)
+#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
+#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
//
// Extruder Stepper enable / disable
@@ -149,74 +149,74 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
// define the individual enables/disables
#if AXIS_DRIVER_TYPE_E0(L6470)
extern L6470 stepperE0;
- #define E0_enable NOOP
- #define E0_disable do{ stepperE0.free(); CBI(axis_known_position, E_AXIS); }while(0)
+ #define E0_enable() NOOP
+ #define E0_disable() do{ stepperE0.free(); CBI(axis_known_position, E_AXIS); }while(0)
#elif HAS_E0_ENABLE
- #define E0_enable E0_ENABLE_WRITE( E_ENABLE_ON)
- #define E0_disable E0_ENABLE_WRITE(!E_ENABLE_ON)
+ #define E0_enable() E0_ENABLE_WRITE( E_ENABLE_ON)
+ #define E0_disable() E0_ENABLE_WRITE(!E_ENABLE_ON)
#else
- #define E0_enable NOOP
- #define E0_disable NOOP
+ #define E0_enable() NOOP
+ #define E0_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_E1(L6470)
extern L6470 stepperE1;
- #define E1_enable NOOP
- #define E1_disable do{ stepperE1.free(); CBI(axis_known_position, E_AXIS); }while(0)
+ #define E1_enable() NOOP
+ #define E1_disable() do{ stepperE1.free(); CBI(axis_known_position, E_AXIS); }while(0)
#elif E_STEPPERS > 1 && HAS_E1_ENABLE
- #define E1_enable E1_ENABLE_WRITE( E_ENABLE_ON)
- #define E1_disable E1_ENABLE_WRITE(!E_ENABLE_ON)
+ #define E1_enable() E1_ENABLE_WRITE( E_ENABLE_ON)
+ #define E1_disable() E1_ENABLE_WRITE(!E_ENABLE_ON)
#else
- #define E1_enable NOOP
- #define E1_disable NOOP
+ #define E1_enable() NOOP
+ #define E1_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_E2(L6470)
extern L6470 stepperE2;
- #define E2_enable NOOP
- #define E2_disable do{ stepperE2.free(); CBI(axis_known_position, E_AXIS); }while(0)
+ #define E2_enable() NOOP
+ #define E2_disable() do{ stepperE2.free(); CBI(axis_known_position, E_AXIS); }while(0)
#elif E_STEPPERS > 2 && HAS_E2_ENABLE
- #define E2_enable E2_ENABLE_WRITE( E_ENABLE_ON)
- #define E2_disable E2_ENABLE_WRITE(!E_ENABLE_ON)
+ #define E2_enable() E2_ENABLE_WRITE( E_ENABLE_ON)
+ #define E2_disable() E2_ENABLE_WRITE(!E_ENABLE_ON)
#else
- #define E2_enable NOOP
- #define E2_disable NOOP
+ #define E2_enable() NOOP
+ #define E2_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_E3(L6470)
extern L6470 stepperE3;
- #define E3_enable NOOP
- #define E3_disable do{ stepperE3.free(); CBI(axis_known_position, E_AXIS); }while(0)
+ #define E3_enable() NOOP
+ #define E3_disable() do{ stepperE3.free(); CBI(axis_known_position, E_AXIS); }while(0)
#elif E_STEPPERS > 3 && HAS_E3_ENABLE
- #define E3_enable E3_ENABLE_WRITE( E_ENABLE_ON)
- #define E3_disable E3_ENABLE_WRITE(!E_ENABLE_ON)
+ #define E3_enable() E3_ENABLE_WRITE( E_ENABLE_ON)
+ #define E3_disable() E3_ENABLE_WRITE(!E_ENABLE_ON)
#else
- #define E3_enable NOOP
- #define E3_disable NOOP
+ #define E3_enable() NOOP
+ #define E3_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_E4(L6470)
extern L6470 stepperE4;
- #define E4_enable NOOP
- #define E4_disable do{ stepperE4.free(); CBI(axis_known_position, E_AXIS); }while(0)
+ #define E4_enable() NOOP
+ #define E4_disable() do{ stepperE4.free(); CBI(axis_known_position, E_AXIS); }while(0)
#elif E_STEPPERS > 4 && HAS_E4_ENABLE
- #define E4_enable E4_ENABLE_WRITE( E_ENABLE_ON)
- #define E4_disable E4_ENABLE_WRITE(!E_ENABLE_ON)
+ #define E4_enable() E4_ENABLE_WRITE( E_ENABLE_ON)
+ #define E4_disable() E4_ENABLE_WRITE(!E_ENABLE_ON)
#else
- #define E4_enable NOOP
- #define E4_disable NOOP
+ #define E4_enable() NOOP
+ #define E4_disable() NOOP
#endif
#if AXIS_DRIVER_TYPE_E5(L6470)
extern L6470 stepperE5;
- #define E5_enable NOOP
- #define E5_disable do{ stepperE5.free(); CBI(axis_known_position, E_AXIS); }while(0)
+ #define E5_enable() NOOP
+ #define E5_disable() do{ stepperE5.free(); CBI(axis_known_position, E_AXIS); }while(0)
#elif E_STEPPERS > 5 && HAS_E5_ENABLE
- #define E5_enable E5_ENABLE_WRITE( E_ENABLE_ON)
- #define E5_disable E5_ENABLE_WRITE(!E_ENABLE_ON)
+ #define E5_enable() E5_ENABLE_WRITE( E_ENABLE_ON)
+ #define E5_disable() E5_ENABLE_WRITE(!E_ENABLE_ON)
#else
- #define E5_enable NOOP
- #define E5_disable NOOP
+ #define E5_enable() NOOP
+ #define E5_disable() NOOP
#endif
#if ENABLED(MIXING_EXTRUDER)
@@ -225,20 +225,20 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
* Mixing steppers synchronize their enable (and direction) together
*/
#if MIXING_STEPPERS > 5
- #define enable_E0() { E0_enable; E1_enable; E2_enable; E3_enable; E4_enable; E5_enable; }
- #define disable_E0() { E0_disable; E1_disable; E2_disable; E3_disable; E4_disable; E5_disable; }
+ #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); E3_enable(); E4_enable(); E5_enable(); }
+ #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); E3_disable(); E4_disable(); E5_disable(); }
#elif MIXING_STEPPERS > 4
- #define enable_E0() { E0_enable; E1_enable; E2_enable; E3_enable; E4_enable; }
- #define disable_E0() { E0_disable; E1_disable; E2_disable; E3_disable; E4_disable; }
+ #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); E3_enable(); E4_enable(); }
+ #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); E3_disable(); E4_disable(); }
#elif MIXING_STEPPERS > 3
- #define enable_E0() { E0_enable; E1_enable; E2_enable; E3_enable; }
- #define disable_E0() { E0_disable; E1_disable; E2_disable; E3_disable; }
+ #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); E3_enable(); }
+ #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); E3_disable(); }
#elif MIXING_STEPPERS > 2
- #define enable_E0() { E0_enable; E1_enable; E2_enable; }
- #define disable_E0() { E0_disable; E1_disable; E2_disable; }
+ #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); }
+ #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); }
#else
- #define enable_E0() { E0_enable; E1_enable; }
- #define disable_E0() { E0_disable; E1_disable; }
+ #define enable_E0() { E0_enable(); E1_enable(); }
+ #define disable_E0() { E0_disable(); E1_disable(); }
#endif
#define enable_E1() NOOP
#define disable_E1() NOOP
@@ -254,48 +254,48 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
#else // !MIXING_EXTRUDER
#if HAS_E0_ENABLE
- #define enable_E0() E0_enable
- #define disable_E0() E0_disable
+ #define enable_E0() E0_enable()
+ #define disable_E0() E0_disable()
#else
#define enable_E0() NOOP
#define disable_E0() NOOP
#endif
#if E_STEPPERS > 1 && HAS_E1_ENABLE
- #define enable_E1() E1_enable
- #define disable_E1() E1_disable
+ #define enable_E1() E1_enable()
+ #define disable_E1() E1_disable()
#else
#define enable_E1() NOOP
#define disable_E1() NOOP
#endif
#if E_STEPPERS > 2 && HAS_E2_ENABLE
- #define enable_E2() E2_enable
- #define disable_E2() E2_disable
+ #define enable_E2() E2_enable()
+ #define disable_E2() E2_disable()
#else
#define enable_E2() NOOP
#define disable_E2() NOOP
#endif
#if E_STEPPERS > 3 && HAS_E3_ENABLE
- #define enable_E3() E3_enable
- #define disable_E3() E3_disable
+ #define enable_E3() E3_enable()
+ #define disable_E3() E3_disable()
#else
#define enable_E3() NOOP
#define disable_E3() NOOP
#endif
#if E_STEPPERS > 4 && HAS_E4_ENABLE
- #define enable_E4() E4_enable
- #define disable_E4() E4_disable
+ #define enable_E4() E4_enable()
+ #define disable_E4() E4_disable()
#else
#define enable_E4() NOOP
#define disable_E4() NOOP
#endif
#if E_STEPPERS > 5 && HAS_E5_ENABLE
- #define enable_E5() E5_enable
- #define disable_E5() E5_disable
+ #define enable_E5() E5_enable()
+ #define disable_E5() E5_disable()
#else
#define enable_E5() NOOP
#define disable_E5() NOOP
@@ -316,13 +316,14 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
/**
* The axis order in all axis related arrays is X, Y, Z, E
*/
+void enable_e_steppers();
void enable_all_steppers();
void disable_e_stepper(const uint8_t e);
void disable_e_steppers();
void disable_all_steppers();
-void kill(PGM_P const lcd_msg=nullptr);
-void minkill();
+void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
+void minkill(const bool steppers_off=false);
void quickstop_stepper();
@@ -330,6 +331,10 @@ extern bool Running;
inline bool IsRunning() { return Running; }
inline bool IsStopped() { return !Running; }
+bool printingIsActive();
+bool printingIsPaused();
+void startOrResumeJob();
+
extern bool wait_for_heatup;
#if HAS_RESUME_CONTINUE
@@ -347,7 +352,7 @@ extern millis_t max_inactive_time, stepper_inactive_time;
extern uint8_t controllerfan_speed;
#endif
-#if HAS_POWER_SWITCH
+#if ENABLED(PSU_CONTROL)
extern bool powersupply_on;
#define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_HIGH); powersupply_on = true; }while(0)
#define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_HIGH); powersupply_on = false; }while(0)
@@ -364,14 +369,13 @@ bool pin_is_protected(const pin_t pin);
void protected_pin_err();
#if HAS_SUICIDE
- inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }
-#endif
-
-#if HAS_FILAMENT_SENSOR
- void event_filament_runout();
+ inline void suicide() { OUT_WRITE(SUICIDE_PIN, SUICIDE_PIN_INVERTING); }
#endif
#if ENABLED(G29_RETRY_AND_RECOVER)
void event_probe_recover();
void event_probe_failure();
#endif
+
+extern const char NUL_STR[], G28_STR[], M21_STR[], M23_STR[], M24_STR[],
+ SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[];
diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h
index c9c5d412fa91..5cdf2a4944fd 100644
--- a/Marlin/src/core/boards.h
+++ b/Marlin/src/core/boards.h
@@ -21,6 +21,8 @@
*/
#pragma once
+#include "macros.h"
+
#define BOARD_UNKNOWN -1
//
@@ -88,92 +90,105 @@
#define BOARD_RAMPS_ENDER_4 1134 // Creality: Ender-4, CR-8
#define BOARD_RAMPS_CREALITY 1135 // Creality: CR10S, CR20, CR-X
#define BOARD_RAMPS_DAGOMA 1136 // Dagoma F5
-#define BOARD_FYSETC_F6_13 1137 // Fysetc F6
+#define BOARD_FYSETC_F6_13 1137 // FYSETC F6
#define BOARD_DUPLICATOR_I3_PLUS 1138 // Wanhao Duplicator i3 Plus
#define BOARD_VORON 1139 // VORON Design
#define BOARD_TRONXY_V3_1_0 1140 // Tronxy TRONXY-V3-1.0
#define BOARD_Z_BOLT_X_SERIES 1141 // Z-Bolt X Series
+#define BOARD_TT_OSCAR 1142 // TT OSCAR
+#define BOARD_OVERLORD 1143 // Overlord/Overlord Pro
+#define BOARD_HJC2560C_REV1 1144 // ADIMLab Gantry v1
+#define BOARD_HJC2560C_REV2 1145 // ADIMLab Gantry v2
+#define BOARD_TANGO 1146 // BIQU Tango V1
+#define BOARD_MKS_GEN_L_V2 1147 // MKS GEN L V2
+
+//
+// RAMBo and derivatives
+//
+
+#define BOARD_RAMBO 1200 // Rambo
+#define BOARD_MINIRAMBO 1201 // Mini-Rambo
+#define BOARD_MINIRAMBO_10A 1202 // Mini-Rambo 1.0a
+#define BOARD_EINSY_RAMBO 1203 // Einsy Rambo
+#define BOARD_EINSY_RETRO 1204 // Einsy Retro
+#define BOARD_SCOOVO_X9H 1205 // abee Scoovo X9H
//
// Other ATmega1280, ATmega2560
//
-#define BOARD_CNCONTROLS_11 1200 // Cartesio CN Controls V11
-#define BOARD_CNCONTROLS_12 1201 // Cartesio CN Controls V12
-#define BOARD_CHEAPTRONIC 1202 // Cheaptronic v1.0
-#define BOARD_CHEAPTRONIC_V2 1203 // Cheaptronic v2.0
-#define BOARD_MIGHTYBOARD_REVE 1204 // Makerbot Mightyboard Revision E
-#define BOARD_MEGATRONICS 1205 // Megatronics
-#define BOARD_MEGATRONICS_2 1206 // Megatronics v2.0
-#define BOARD_MEGATRONICS_3 1207 // Megatronics v3.0
-#define BOARD_MEGATRONICS_31 1208 // Megatronics v3.1
-#define BOARD_MEGATRONICS_32 1209 // Megatronics v3.2
-#define BOARD_RAMBO 1210 // Rambo
-#define BOARD_MINIRAMBO 1211 // Mini-Rambo
-#define BOARD_MINIRAMBO_10A 1212 // Mini-Rambo 1.0a
-#define BOARD_EINSY_RAMBO 1213 // Einsy Rambo
-#define BOARD_EINSY_RETRO 1214 // Einsy Retro
-#define BOARD_ELEFU_3 1215 // Elefu Ra Board (v3)
-#define BOARD_LEAPFROG 1216 // Leapfrog
-#define BOARD_MEGACONTROLLER 1217 // Mega controller
-#define BOARD_SCOOVO_X9H 1218 // abee Scoovo X9H
-#define BOARD_GT2560_REV_A 1219 // Geeetech GT2560 Rev. A
-#define BOARD_GT2560_REV_A_PLUS 1220 // Geeetech GT2560 Rev. A+ (with auto level probe)
-#define BOARD_GT2560_V3 1221 // Geeetech GT2560 Rev B for A10(M/D)
-#define BOARD_GT2560_V3_MC2 1222 // Geeetech GT2560 Rev B for Mecreator2
-#define BOARD_GT2560_V3_A20 1223 // Geeetech GT2560 Rev B for A20(M/D)
-#define BOARD_EINSTART_S 1224 // Einstart retrofit
+#define BOARD_CNCONTROLS_11 1300 // Cartesio CN Controls V11
+#define BOARD_CNCONTROLS_12 1301 // Cartesio CN Controls V12
+#define BOARD_CNCONTROLS_15 1302 // Cartesio CN Controls V15
+#define BOARD_CHEAPTRONIC 1303 // Cheaptronic v1.0
+#define BOARD_CHEAPTRONIC_V2 1304 // Cheaptronic v2.0
+#define BOARD_MIGHTYBOARD_REVE 1305 // Makerbot Mightyboard Revision E
+#define BOARD_MEGATRONICS 1306 // Megatronics
+#define BOARD_MEGATRONICS_2 1307 // Megatronics v2.0
+#define BOARD_MEGATRONICS_3 1308 // Megatronics v3.0
+#define BOARD_MEGATRONICS_31 1309 // Megatronics v3.1
+#define BOARD_MEGATRONICS_32 1310 // Megatronics v3.2
+#define BOARD_ELEFU_3 1311 // Elefu Ra Board (v3)
+#define BOARD_LEAPFROG 1312 // Leapfrog
+#define BOARD_MEGACONTROLLER 1313 // Mega controller
+#define BOARD_GT2560_REV_A 1314 // Geeetech GT2560 Rev. A
+#define BOARD_GT2560_REV_A_PLUS 1315 // Geeetech GT2560 Rev. A+ (with auto level probe)
+#define BOARD_GT2560_V3 1316 // Geeetech GT2560 Rev B for A10(M/D)
+#define BOARD_GT2560_V3_MC2 1317 // Geeetech GT2560 Rev B for Mecreator2
+#define BOARD_GT2560_V3_A20 1318 // Geeetech GT2560 Rev B for A20(M/D)
+#define BOARD_EINSTART_S 1319 // Einstart retrofit
+#define BOARD_WANHAO_ONEPLUS 1320 // Wanhao 0ne+ i3 Mini
//
// ATmega1281, ATmega2561
//
-#define BOARD_MINITRONICS 1300 // Minitronics v1.0/1.1
-#define BOARD_SILVER_GATE 1301 // Silvergate v1.0
+#define BOARD_MINITRONICS 1400 // Minitronics v1.0/1.1
+#define BOARD_SILVER_GATE 1401 // Silvergate v1.0
//
// Sanguinololu and Derivatives - ATmega644P, ATmega1284P
//
-#define BOARD_SANGUINOLOLU_11 1400 // Sanguinololu < 1.2
-#define BOARD_SANGUINOLOLU_12 1401 // Sanguinololu 1.2 and above
-#define BOARD_MELZI 1402 // Melzi
-#define BOARD_MELZI_MAKR3D 1403 // Melzi with ATmega1284 (MaKr3d version)
-#define BOARD_MELZI_CREALITY 1404 // Melzi Creality3D board (for CR-10 etc)
-#define BOARD_MELZI_MALYAN 1405 // Melzi Malyan M150 board
-#define BOARD_MELZI_TRONXY 1406 // Tronxy X5S
-#define BOARD_STB_11 1407 // STB V1.1
-#define BOARD_AZTEEG_X1 1408 // Azteeg X1
-#define BOARD_ANET_10 1409 // Anet 1.0 (Melzi clone)
+#define BOARD_SANGUINOLOLU_11 1500 // Sanguinololu < 1.2
+#define BOARD_SANGUINOLOLU_12 1501 // Sanguinololu 1.2 and above
+#define BOARD_MELZI 1502 // Melzi
+#define BOARD_MELZI_MAKR3D 1503 // Melzi with ATmega1284 (MaKr3d version)
+#define BOARD_MELZI_CREALITY 1504 // Melzi Creality3D board (for CR-10 etc)
+#define BOARD_MELZI_MALYAN 1505 // Melzi Malyan M150 board
+#define BOARD_MELZI_TRONXY 1506 // Tronxy X5S
+#define BOARD_STB_11 1507 // STB V1.1
+#define BOARD_AZTEEG_X1 1508 // Azteeg X1
+#define BOARD_ANET_10 1509 // Anet 1.0 (Melzi clone)
//
// Other ATmega644P, ATmega644, ATmega1284P
//
-#define BOARD_GEN3_MONOLITHIC 1500 // Gen3 Monolithic Electronics
-#define BOARD_GEN3_PLUS 1501 // Gen3+
-#define BOARD_GEN6 1502 // Gen6
-#define BOARD_GEN6_DELUXE 1503 // Gen6 deluxe
-#define BOARD_GEN7_CUSTOM 1504 // Gen7 custom (Alfons3 Version) "https://github.com/Alfons3/Generation_7_Electronics"
-#define BOARD_GEN7_12 1505 // Gen7 v1.1, v1.2
-#define BOARD_GEN7_13 1506 // Gen7 v1.3
-#define BOARD_GEN7_14 1507 // Gen7 v1.4
-#define BOARD_OMCA_A 1508 // Alpha OMCA board
-#define BOARD_OMCA 1509 // Final OMCA board
-#define BOARD_SETHI 1510 // Sethi 3D_1
+#define BOARD_GEN3_MONOLITHIC 1600 // Gen3 Monolithic Electronics
+#define BOARD_GEN3_PLUS 1601 // Gen3+
+#define BOARD_GEN6 1602 // Gen6
+#define BOARD_GEN6_DELUXE 1603 // Gen6 deluxe
+#define BOARD_GEN7_CUSTOM 1604 // Gen7 custom (Alfons3 Version) "https://github.com/Alfons3/Generation_7_Electronics"
+#define BOARD_GEN7_12 1605 // Gen7 v1.1, v1.2
+#define BOARD_GEN7_13 1606 // Gen7 v1.3
+#define BOARD_GEN7_14 1607 // Gen7 v1.4
+#define BOARD_OMCA_A 1608 // Alpha OMCA board
+#define BOARD_OMCA 1609 // Final OMCA board
+#define BOARD_SETHI 1610 // Sethi 3D_1
//
// Teensyduino - AT90USB1286, AT90USB1286P
//
-#define BOARD_TEENSYLU 1600 // Teensylu
-#define BOARD_PRINTRBOARD 1601 // Printrboard (AT90USB1286)
-#define BOARD_PRINTRBOARD_REVF 1602 // Printrboard Revision F (AT90USB1286)
-#define BOARD_BRAINWAVE 1603 // Brainwave (AT90USB646)
-#define BOARD_BRAINWAVE_PRO 1604 // Brainwave Pro (AT90USB1286)
-#define BOARD_SAV_MKI 1605 // SAV Mk-I (AT90USB1286)
-#define BOARD_TEENSY2 1606 // Teensy++2.0 (AT90USB1286)
-#define BOARD_5DPRINT 1607 // 5DPrint D8 Driver Board
+#define BOARD_TEENSYLU 1700 // Teensylu
+#define BOARD_PRINTRBOARD 1701 // Printrboard (AT90USB1286)
+#define BOARD_PRINTRBOARD_REVF 1702 // Printrboard Revision F (AT90USB1286)
+#define BOARD_BRAINWAVE 1703 // Brainwave (AT90USB646)
+#define BOARD_BRAINWAVE_PRO 1704 // Brainwave Pro (AT90USB1286)
+#define BOARD_SAV_MKI 1705 // SAV Mk-I (AT90USB1286)
+#define BOARD_TEENSY2 1706 // Teensy++2.0 (AT90USB1286)
+#define BOARD_5DPRINT 1707 // 5DPrint D8 Driver Board
//
// LPC1768 ARM Cortex M3
@@ -193,13 +208,14 @@
#define BOARD_COHESION3D_MINI 2011 // Cohesion3D Mini
#define BOARD_SMOOTHIEBOARD 2012 // Smoothieboard
#define BOARD_AZTEEG_X5_MINI_WIFI 2013 // Azteeg X5 Mini Wifi (Power outputs: Hotend0, Bed, Fan)
-#define BOARD_BIQU_SKR_V1_1 2014 // BIQU SKR_V1.1 (Power outputs: Hotend0,Hotend1, Fan, Bed)
+#define BOARD_BIGTREE_SKR_V1_1 2014 // BIGTREE SKR_V1.1 (Power outputs: Hotend0,Hotend1, Fan, Bed)
#define BOARD_BIQU_B300_V1_0 2015 // BIQU B300_V1.0 (Power outputs: Hotend0, Fan, Bed, SPI Driver)
#define BOARD_BIGTREE_SKR_V1_3 2016 // BIGTREE SKR_V1.3 (Power outputs: Hotend0, Hotend1, Fan, Bed)
#define BOARD_AZTEEG_X5_MINI 2017 // Azteeg X5 Mini (Power outputs: Hotend0, Bed, Fan)
#define BOARD_MKS_SGEN 2018 // MKS-SGen (Power outputs: Hotend0, Hotend1, Bed, Fan)
#define BOARD_MKS_SGEN_L 2019 // MKS-SGen-L (Power outputs: Hotend0, Hotend1, Bed, Fan)
#define BOARD_TH3D_EZBOARD 2020 // TH3D EZBoard v1.0
+#define BOARD_GMARSH_X6_REV1 2021 // GMARSH X6 board, revision 1 prototype
//
// SAM3X8E ARM Cortex M3
@@ -243,33 +259,56 @@
// STM32 ARM Cortex-M3
//
-#define BOARD_STM32F1R 4000 // STM32R Libmaple-based STM32F1 controller
-#define BOARD_MALYAN_M200 4001 // STM32C8T6 Libmaple-based STM32F1 controller
-#define BOARD_STM3R_MINI 4002 // STM32 Libmaple-based STM32F1 controller
+#define BOARD_STM32F103RE 4000 // STM32F103RE Libmaple-based STM32F1 controller
+#define BOARD_MALYAN_M200 4001 // STM32C8T6 Libmaple-based STM32F1 controller
+#define BOARD_STM3R_MINI 4002 // STM32F103RE Libmaple-based STM32F1 controller
#define BOARD_GTM32_PRO_VB 4003 // STM32F103VET6 controller
#define BOARD_MORPHEUS 4004 // STM32F103C8 / STM32F103CB Libmaple-based STM32F1 controller
-#define BOARD_MKS_ROBIN 4005 // MKS Robin (STM32F103ZET6)
-#define BOARD_MKS_ROBIN_MINI 4006 // MKS Robin Mini (STM32F103VET6)
-#define BOARD_MKS_ROBIN_NANO 4007 // MKS Robin Nano (STM32F103VET6)
-#define BOARD_BIGTREE_SKR_MINI_V1_1 4008 // BigTreeTech SKR Mini v1.1 (STM32F103RC)
-#define BOARD_BIGTREE_SKR_MINI_E3 4009 // BigTreeTech SKR Mini E3 (STM32F103RC)
-#define BOARD_JGAURORA_A5S_A1 4010 // JGAurora A5S A1 (STM32F103ZET6)
-#define BOARD_FYSETC_AIO_II 4011 // FYSETC AIO_II
-#define BOARD_FYSETC_CHEETAH 4012 // FYSETC CHEETAH
+#define BOARD_CHITU3D 4005 // Chitu3D (STM32F103RET6)
+#define BOARD_MKS_ROBIN 4006 // MKS Robin (STM32F103ZET6)
+#define BOARD_MKS_ROBIN_MINI 4007 // MKS Robin Mini (STM32F103VET6)
+#define BOARD_MKS_ROBIN_NANO 4008 // MKS Robin Nano (STM32F103VET6)
+#define BOARD_MKS_ROBIN_LITE 4009 // MKS Robin Lite/Lite2 (STM32F103RCT6)
+#define BOARD_MKS_ROBIN_LITE3 4010 // MKS Robin Lite3 (STM32F103RCT6)
+#define BOARD_MKS_ROBIN_PRO 4011 // MKS Robin Pro (STM32F103ZET6)
+#define BOARD_BIGTREE_SKR_MINI_V1_1 4012 // BigTreeTech SKR Mini v1.1 (STM32F103RC)
+#define BOARD_BTT_SKR_MINI_E3_V1_0 4013 // BigTreeTech SKR Mini E3 (STM32F103RC)
+#define BOARD_BTT_SKR_MINI_E3_V1_2 4014 // BigTreeTech SKR Mini E3 V1.2 (STM32F103RC)
+#define BOARD_BIGTREE_SKR_E3_DIP 4015 // BigTreeTech SKR E3 DIP V1.0 (STM32F103RC / STM32F103RE)
+#define BOARD_JGAURORA_A5S_A1 4016 // JGAurora A5S A1 (STM32F103ZET6)
+#define BOARD_FYSETC_AIO_II 4017 // FYSETC AIO_II
+#define BOARD_FYSETC_CHEETAH 4018 // FYSETC Cheetah
+#define BOARD_FYSETC_CHEETAH_V12 4019 // FYSETC Cheetah V1.2
+#define BOARD_LONGER3D_LK 4020 // Alfawise U20/U20+/U30 (Longer3D LK1/2) / STM32F103VET6
+#define BOARD_GTM32_MINI 4021 // STM32F103VET6 controller
+#define BOARD_GTM32_MINI_A30 4022 // STM32F103VET6 controller
+#define BOARD_GTM32_REV_B 4023 // STM32F103VET6 controller
+
//
-// STM32 ARM Cortex-M4F
+// ARM Cortex-M4F
//
#define BOARD_TEENSY31_32 4100 // Teensy3.1 and Teensy3.2
#define BOARD_TEENSY35_36 4101 // Teensy3.5 and Teensy3.6
-#define BOARD_BEAST 4102 // STM32F4xxVxT6 Libmaple-based STM32F4 controller
-#define BOARD_STM32F4 4103 // STM32 STM32GENERIC-based STM32F4 controller
-#define BOARD_ARMED 4104 // Arm'ed STM32F4-based controller
-#define BOARD_RUMBA32 4105 // RUMBA32 STM32F4-based controller
-#define BOARD_BLACK_STM32F407VE 4106 // BLACK_STM32F407VE
-#define BOARD_BLACK_STM32F407ZE 4107 // BLACK_STM32F407ZE
-#define BOARD_STEVAL 4108 // STEVAL-3DP001V1 3D PRINTER BOARD
+
+//
+// STM32 ARM Cortex-M4F
+//
+
+#define BOARD_BEAST 4200 // STM32F4xxVxT6 Libmaple-based STM32F4 controller
+#define BOARD_GENERIC_STM32F4 4201 // STM32 STM32GENERIC-based STM32F4 controller
+#define BOARD_ARMED 4202 // Arm'ed STM32F4-based controller
+#define BOARD_RUMBA32 4203 // RUMBA32 STM32F4-based controller
+#define BOARD_BLACK_STM32F407VE 4204 // BLACK_STM32F407VE
+#define BOARD_BLACK_STM32F407ZE 4205 // BLACK_STM32F407ZE
+#define BOARD_STEVAL 4206 // STEVAL-3DP001V1 3D PRINTER BOARD
+#define BOARD_BIGTREE_SKR_PRO_V1_1 4207 // BigTreeTech SKR Pro v1.1 (STM32F407ZG)
+#define BOARD_BIGTREE_BTT002_V1_0 4208 // BigTreeTech BTT002 v1.0 (STM32F407VE)
+#define BOARD_LERDGE_K 4209 // Lerdge K (STM32F407ZG)
+#define BOARD_LERDGE_X 4210 // Lerdge X (STM32F407VE)
+#define BOARD_VAKE403D 4211 // VAkE 403D (STM32F446VET6)
+#define BOARD_FYSETC_S6 4212 // FYSETC S6 board
//
// ARM Cortex M7
@@ -281,7 +320,7 @@
//
// Espressif ESP32 WiFi
//
-#define BOARD_ESP32 6000
+#define BOARD_ESPRESSIF_ESP32 6000
//
// Simulations
@@ -289,4 +328,7 @@
#define BOARD_LINUX_RAMPS 9999
-#define MB(board) (defined(BOARD_##board) && MOTHERBOARD==BOARD_##board)
+#define _MB_1(B) (defined(BOARD_##B) && MOTHERBOARD==BOARD_##B)
+#define MB(V...) DO(MB,||,V)
+
+#define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY)
diff --git a/Marlin/src/core/debug_out.h b/Marlin/src/core/debug_out.h
index 7eb93a702001..07bdad7ff2c1 100644
--- a/Marlin/src/core/debug_out.h
+++ b/Marlin/src/core/debug_out.h
@@ -19,7 +19,6 @@
* along with this program. If not, see .
*
*/
-#pragma once
//
// Serial aliases for debugging.
@@ -37,9 +36,13 @@
#undef DEBUG_ECHOPGM
#undef DEBUG_ECHOLNPGM
#undef DEBUG_ECHOPAIR
+#undef DEBUG_ECHOPAIR_P
#undef DEBUG_ECHOPAIR_F
+#undef DEBUG_ECHOPAIR_F_P
#undef DEBUG_ECHOLNPAIR
+#undef DEBUG_ECHOLNPAIR_P
#undef DEBUG_ECHOLNPAIR_F
+#undef DEBUG_ECHOLNPAIR_F_P
#undef DEBUG_ECHO_MSG
#undef DEBUG_ERROR_MSG
#undef DEBUG_EOL
@@ -58,9 +61,13 @@
#define DEBUG_ECHOPGM SERIAL_ECHOPGM
#define DEBUG_ECHOLNPGM SERIAL_ECHOLNPGM
#define DEBUG_ECHOPAIR SERIAL_ECHOPAIR
+ #define DEBUG_ECHOPAIR_P SERIAL_ECHOPAIR_P
#define DEBUG_ECHOPAIR_F SERIAL_ECHOPAIR_F
+ #define DEBUG_ECHOPAIR_F_P SERIAL_ECHOPAIR_F_P
#define DEBUG_ECHOLNPAIR SERIAL_ECHOLNPAIR
+ #define DEBUG_ECHOLNPAIR_P SERIAL_ECHOLNPAIR_P
#define DEBUG_ECHOLNPAIR_F SERIAL_ECHOLNPAIR_F
+ #define DEBUG_ECHOLNPAIR_F_P SERIAL_ECHOLNPAIR_F_P
#define DEBUG_ECHO_MSG SERIAL_ECHO_MSG
#define DEBUG_ERROR_MSG SERIAL_ERROR_MSG
#define DEBUG_EOL SERIAL_EOL
@@ -68,25 +75,29 @@
#define DEBUG_XYZ SERIAL_XYZ
#define DEBUG_DELAY(ms) serial_delay(ms)
#else
- #define DEBUG_PRINT_P(P) NOOP
- #define DEBUG_ECHO_START() NOOP
- #define DEBUG_ERROR_START() NOOP
- #define DEBUG_CHAR(...) NOOP
- #define DEBUG_ECHO(...) NOOP
- #define DEBUG_ECHO_F(...) NOOP
- #define DEBUG_ECHOLN(...) NOOP
- #define DEBUG_ECHOPGM(...) NOOP
- #define DEBUG_ECHOLNPGM(...) NOOP
- #define DEBUG_ECHOPAIR(...) NOOP
- #define DEBUG_ECHOPAIR_F(...) NOOP
- #define DEBUG_ECHOLNPAIR(...) NOOP
- #define DEBUG_ECHOLNPAIR_F(...) NOOP
- #define DEBUG_ECHO_MSG(...) NOOP
- #define DEBUG_ERROR_MSG(...) NOOP
- #define DEBUG_EOL() NOOP
- #define DEBUG_POS(...) NOOP
- #define DEBUG_XYZ(...) NOOP
- #define DEBUG_DELAY(...) NOOP
+ #define DEBUG_PRINT_P(P) NOOP
+ #define DEBUG_ECHO_START() NOOP
+ #define DEBUG_ERROR_START() NOOP
+ #define DEBUG_CHAR(...) NOOP
+ #define DEBUG_ECHO(...) NOOP
+ #define DEBUG_ECHO_F(...) NOOP
+ #define DEBUG_ECHOLN(...) NOOP
+ #define DEBUG_ECHOPGM(...) NOOP
+ #define DEBUG_ECHOLNPGM(...) NOOP
+ #define DEBUG_ECHOPAIR(...) NOOP
+ #define DEBUG_ECHOPAIR_P(...) NOOP
+ #define DEBUG_ECHOPAIR_F(...) NOOP
+ #define DEBUG_ECHOPAIR_F_P(...) NOOP
+ #define DEBUG_ECHOLNPAIR(...) NOOP
+ #define DEBUG_ECHOLNPAIR_P(...) NOOP
+ #define DEBUG_ECHOLNPAIR_F(...) NOOP
+ #define DEBUG_ECHOLNPAIR_F_P(...) NOOP
+ #define DEBUG_ECHO_MSG(...) NOOP
+ #define DEBUG_ERROR_MSG(...) NOOP
+ #define DEBUG_EOL() NOOP
+ #define DEBUG_POS(...) NOOP
+ #define DEBUG_XYZ(...) NOOP
+ #define DEBUG_DELAY(...) NOOP
#endif
#undef DEBUG_OUT
diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h
index a6e480c14103..44434581a5a6 100644
--- a/Marlin/src/core/drivers.h
+++ b/Marlin/src/core/drivers.h
@@ -67,12 +67,14 @@
#define AXIS_DRIVER_TYPE(A,T) AXIS_DRIVER_TYPE_##A(T)
+#define HAS_E_DRIVER(T) ( AXIS_DRIVER_TYPE_E0(T) || AXIS_DRIVER_TYPE_E1(T) \
+ || AXIS_DRIVER_TYPE_E2(T) || AXIS_DRIVER_TYPE_E3(T) \
+ || AXIS_DRIVER_TYPE_E4(T) || AXIS_DRIVER_TYPE_E5(T) )
+
#define HAS_DRIVER(T) ( AXIS_DRIVER_TYPE_X(T) || AXIS_DRIVER_TYPE_X2(T) \
|| AXIS_DRIVER_TYPE_Y(T) || AXIS_DRIVER_TYPE_Y2(T) \
|| AXIS_DRIVER_TYPE_Z(T) || AXIS_DRIVER_TYPE_Z2(T) || AXIS_DRIVER_TYPE_Z3(T) \
- || AXIS_DRIVER_TYPE_E0(T) || AXIS_DRIVER_TYPE_E1(T) \
- || AXIS_DRIVER_TYPE_E2(T) || AXIS_DRIVER_TYPE_E3(T) \
- || AXIS_DRIVER_TYPE_E4(T) || AXIS_DRIVER_TYPE_E5(T) )
+ || HAS_E_DRIVER(T) )
// Test for supported TMC drivers that require advanced configuration
// Does not match standalone configurations
@@ -84,6 +86,8 @@
|| HAS_DRIVER(TMC5130) \
|| HAS_DRIVER(TMC5160) )
+#define HAS_TMC220x (HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209))
+
#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \
|| AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) \
@@ -117,8 +121,21 @@
|| AXIS_DRIVER_TYPE(A,TMC5130) \
|| AXIS_DRIVER_TYPE(A,TMC5160) )
+#define HAS_TMC_E_DRIVER ( HAS_E_DRIVER(TMC2130) \
+ || HAS_E_DRIVER(TMC2160) \
+ || HAS_E_DRIVER(TMC2660) \
+ || HAS_E_DRIVER(TMC2209) \
+ || HAS_E_DRIVER(TMC5130) \
+ || HAS_E_DRIVER(TMC5160) )
+
+#define HAS_TMC_STANDALONE_E_DRIVER ( HAS_E_DRIVER(TMC2130_STANDALONE) \
+ || HAS_E_DRIVER(TMC2160_STANDALONE) \
+ || HAS_E_DRIVER(TMC2660_STANDALONE) \
+ || HAS_E_DRIVER(TMC2209_STANDALONE) \
+ || HAS_E_DRIVER(TMC5130_STANDALONE) \
+ || HAS_E_DRIVER(TMC5160_STANDALONE) )
//
-// Stretching 'drivers.h' to include LPC SD options
+// Stretching 'drivers.h' to include LPC/SAMD51 SD options
//
#define _SDCARD_LCD 1
#define _SDCARD_ONBOARD 2
diff --git a/Marlin/src/core/enum.h b/Marlin/src/core/enum.h
deleted file mode 100644
index a6a3f57888f2..000000000000
--- a/Marlin/src/core/enum.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Axis indices as enumerated constants
- *
- * - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
- * - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
- * - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
- */
-enum AxisEnum : unsigned char {
- X_AXIS = 0,
- A_AXIS = 0,
- Y_AXIS = 1,
- B_AXIS = 1,
- Z_AXIS = 2,
- C_AXIS = 2,
- E_AXIS = 3,
- X_HEAD = 4,
- Y_HEAD = 5,
- Z_HEAD = 6,
- E0_AXIS = 3,
- E1_AXIS = 4,
- E2_AXIS = 5,
- E3_AXIS = 6,
- E4_AXIS = 7,
- E5_AXIS = 8,
- ALL_AXES = 0xFE,
- NO_AXIS = 0xFF
-};
-
-#if HAS_DRIVER(L6470)
- enum L6470_driver_enum : unsigned char { X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5 };
-#endif
-
-#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
-#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
-#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
-#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
-
-#define LOOP_NA(VAR) LOOP_L_N(VAR, NUM_AXIS)
-#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
-#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
-#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
-#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
-#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
-#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
-
-typedef enum {
- LINEARUNIT_MM,
- LINEARUNIT_INCH
-} LinearUnit;
-
-typedef enum {
- TEMPUNIT_C,
- TEMPUNIT_K,
- TEMPUNIT_F
-} TempUnit;
diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h
index c291b0549aa2..cfce9d9ae1e2 100644
--- a/Marlin/src/core/language.h
+++ b/Marlin/src/core/language.h
@@ -37,7 +37,7 @@
// NOTE: IF YOU CHANGE LANGUAGE FILES OR MERGE A FILE WITH CHANGES
//
-// ==> ALWAYS TRY TO COMPILE MARLIN WITH/WITHOUT "ULTIPANEL" / "ULTRALCD" / "SDSUPPORT" #define IN "Configuration.h"
+// ==> ALWAYS TRY TO COMPILE MARLIN WITH/WITHOUT "ULTIPANEL" / "ULTRA_LCD" / "SDSUPPORT" #define IN "Configuration.h"
// ==> ALSO TRY ALL AVAILABLE LANGUAGE OPTIONS
// See also http://marlinfw.org/docs/development/lcd_language.html
@@ -46,9 +46,10 @@
// bg Bulgarian
// ca Catalan
// cz Czech
+// da Danish
// de German
// el Greek
-// el-gr Greek (Greece)
+// el_gr Greek (Greece)
// en English
// es Spanish
// eu Basque-Euskera
@@ -57,16 +58,17 @@
// gl Galician
// hr Croatian
// it Italian
-// jp-kana Japanese
+// jp_kana Japanese
// ko_KR Korean (South Korea)
// nl Dutch
// pl Polish
// pt Portuguese
-// pt-br Portuguese (Brazilian)
+// pt_br Portuguese (Brazilian)
// ru Russian
// sk Slovak
// tr Turkish
// uk Ukrainian
+// vi Vietnamese
// zh_CN Chinese (Simplified)
// zh_TW Chinese (Traditional)
@@ -89,12 +91,26 @@
#define MACHINE_UUID DEFAULT_MACHINE_UUID
#endif
-#ifdef BOARD_WEBSITE_URL
- #undef WEBSITE_URL
- #define WEBSITE_URL BOARD_WEBSITE_URL
-#endif
+#define MARLIN_WEBSITE_URL "http://marlinfw.org"
+
+//#if !defined(STRING_SPLASH_LINE3) && defined(WEBSITE_URL)
+// #define STRING_SPLASH_LINE3 WEBSITE_URL
+//#endif
+
+#if HAS_CHARACTER_LCD
-#if HAS_GRAPHICAL_LCD
+ // Custom characters defined in the first 8 characters of the LCD
+ #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string!
+ #define LCD_STR_DEGREE "\x01"
+ #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation
+ #define LCD_STR_UPLEVEL "\x03"
+ #define LCD_STR_REFRESH "\x04"
+ #define LCD_STR_FOLDER "\x05"
+ #define LCD_STR_FEEDRATE "\x06"
+ #define LCD_STR_CLOCK "\x07"
+ #define LCD_STR_ARROW_RIGHT ">" /* from the default character set */
+
+#else
//
// Custom characters from Marlin_symbols.fon which was merged into ISO10646-0-3.bdf
// \x00 intentionally skipped to avoid problems in strings
@@ -117,19 +133,6 @@
#define LCD_STR_FILAM_DIA "\xF8"
#define LCD_STR_FILAM_MUL "\xA4"
-#elif HAS_CHARACTER_LCD
-
- // Custom characters defined in the first 8 characters of the LCD
- #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string!
- #define LCD_STR_DEGREE "\x01"
- #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation
- #define LCD_STR_UPLEVEL "\x03"
- #define LCD_STR_REFRESH "\x04"
- #define LCD_STR_FOLDER "\x05"
- #define LCD_STR_FEEDRATE "\x06"
- #define LCD_STR_CLOCK "\x07"
- #define LCD_STR_ARROW_RIGHT ">" /* from the default character set */
-
#endif
// Common LCD messages
@@ -165,7 +168,6 @@
#define MSG_INVALID_E_STEPPER "Invalid E stepper"
#define MSG_E_STEPPER_NOT_SPECIFIED "E stepper not specified"
#define MSG_INVALID_SOLENOID "Invalid solenoid"
-#define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature"
#define MSG_M115_REPORT "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID
#define MSG_COUNT_X " Count X:"
#define MSG_COUNT_A " Count A:"
@@ -195,7 +197,7 @@
#define MSG_Z3_MAX "z3_max"
#define MSG_Z_PROBE "z_probe"
#define MSG_FILAMENT_RUNOUT_SENSOR "filament"
-#define MSG_PROBE_Z_OFFSET "Probe Z Offset"
+#define MSG_PROBE_OFFSET "Probe Offset"
#define MSG_SKEW_MIN "min_skew_factor: "
#define MSG_SKEW_MAX "max_skew_factor: "
#define MSG_ERR_MATERIAL_INDEX "M145 S out of range (0-1)"
@@ -240,10 +242,9 @@
#define MSG_ERR_COLD_EXTRUDE_STOP " cold extrusion prevented"
#define MSG_ERR_LONG_EXTRUDE_STOP " too long extrusion prevented"
#define MSG_ERR_HOTEND_TOO_COLD "Hotend too cold"
+#define MSG_ERR_Z_HOMING_SER "Home XY first"
+#define MSG_ERR_EEPROM_WRITE "Error writing to EEPROM!"
-#define MSG_FILAMENT_CHANGE_HEAT "Press button (or M108) to heat nozzle"
-#define MSG_FILAMENT_CHANGE_INSERT "Insert filament and press button (or M108)"
-#define MSG_FILAMENT_CHANGE_WAIT "Press button (or M108) to resume"
#define MSG_FILAMENT_CHANGE_HEAT_LCD "Press button to heat nozzle"
#define MSG_FILAMENT_CHANGE_INSERT_LCD "Insert filament and press button"
#define MSG_FILAMENT_CHANGE_WAIT_LCD "Press button to resume"
@@ -251,17 +252,15 @@
#define MSG_FILAMENT_CHANGE_INSERT_M108 "Insert filament and send M108"
#define MSG_FILAMENT_CHANGE_WAIT_M108 "Send M108 to resume"
-#define MSG_ERR_EEPROM_WRITE "Error writing to EEPROM!"
-
-#define MSG_STOP_BLTOUCH "STOP called because of BLTouch error - restart with M999"
-#define MSG_STOP_UNHOMED "STOP called because of unhomed error - restart with M999"
-#define MSG_KILL_INACTIVE_TIME "KILL caused by too much inactive time - current command: "
-#define MSG_KILL_BUTTON "KILL caused by KILL button/pin"
+#define MSG_STOP_BLTOUCH "!! STOP called because of BLTouch error - restart with M999"
+#define MSG_STOP_UNHOMED "!! STOP called because of unhomed error - restart with M999"
+#define MSG_KILL_INACTIVE_TIME "!! KILL caused by too much inactive time - current command: "
+#define MSG_KILL_BUTTON "!! KILL caused by KILL button/pin"
// temperature.cpp strings
-#define MSG_PID_AUTOTUNE "PID Autotune"
-#define MSG_PID_AUTOTUNE_START MSG_PID_AUTOTUNE " start"
-#define MSG_PID_AUTOTUNE_FAILED MSG_PID_AUTOTUNE " failed!"
+#define MSG_PID_AUTOTUNE_PREFIX "PID Autotune"
+#define MSG_PID_AUTOTUNE_START MSG_PID_AUTOTUNE_PREFIX " start"
+#define MSG_PID_AUTOTUNE_FAILED MSG_PID_AUTOTUNE_PREFIX " failed!"
#define MSG_PID_BAD_EXTRUDER_NUM MSG_PID_AUTOTUNE_FAILED " Bad extruder number"
#define MSG_PID_TEMP_TOO_HIGH MSG_PID_AUTOTUNE_FAILED " Temperature too high"
#define MSG_PID_TIMEOUT MSG_PID_AUTOTUNE_FAILED " timeout"
@@ -276,7 +275,7 @@
#define MSG_KI " Ki: "
#define MSG_KD " Kd: "
#define MSG_AT " @:"
-#define MSG_PID_AUTOTUNE_FINISHED MSG_PID_AUTOTUNE " finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
+#define MSG_PID_AUTOTUNE_FINISHED MSG_PID_AUTOTUNE_PREFIX " finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
#define MSG_PID_DEBUG " PID_DEBUG "
#define MSG_PID_DEBUG_INPUT ": Input "
#define MSG_PID_DEBUG_OUTPUT " Output "
@@ -295,6 +294,8 @@
#define MSG_T_THERMAL_RUNAWAY "Thermal Runaway"
#define MSG_T_MAXTEMP "MAXTEMP triggered"
#define MSG_T_MINTEMP "MINTEMP triggered"
+#define MSG_ERR_PROBING_FAILED "Probing Failed"
+#define MSG_ZPROBE_OUT_SER "Z Probe Past Bed"
// Debug
#define MSG_DEBUG_PREFIX "DEBUG:"
@@ -310,11 +311,9 @@
#define LANGUAGE_DATA_INCL_(M) STRINGIFY_(fontdata/langdata_##M.h)
#define LANGUAGE_DATA_INCL(M) LANGUAGE_DATA_INCL_(M)
-#define INCLUDE_LANGUAGE_DATA LANGUAGE_DATA_INCL(LCD_LANGUAGE)
#define LANGUAGE_INCL_(M) STRINGIFY_(../lcd/language/language_##M.h)
#define LANGUAGE_INCL(M) LANGUAGE_INCL_(M)
-#define INCLUDE_LANGUAGE LANGUAGE_INCL(LCD_LANGUAGE)
// Never translate these strings
#define MSG_X "X"
@@ -334,54 +333,63 @@
#define MSG_Y2 "Y2"
#define MSG_Z2 "Z2"
#define MSG_Z3 "Z3"
-#define MSG_H1 "1"
-#define MSG_H2 "2"
-#define MSG_H3 "3"
-#define MSG_H4 "4"
-#define MSG_H5 "5"
-#define MSG_H6 "6"
-#define MSG_LCD_N0 " 1"
-#define MSG_LCD_N1 " 2"
-#define MSG_LCD_N2 " 3"
-#define MSG_LCD_N3 " 4"
-#define MSG_LCD_N4 " 5"
-#define MSG_LCD_N5 " 6"
-#define MSG_E1 "E1"
-#define MSG_E2 "E2"
-#define MSG_E3 "E3"
-#define MSG_E4 "E4"
-#define MSG_E5 "E5"
-#define MSG_E6 "E6"
-#define MSG_MOVE_E1 "1"
-#define MSG_MOVE_E2 "2"
-#define MSG_MOVE_E3 "3"
-#define MSG_MOVE_E4 "4"
-#define MSG_MOVE_E5 "5"
-#define MSG_MOVE_E6 "6"
-#define MSG_DIAM_E1 " 1"
-#define MSG_DIAM_E2 " 2"
-#define MSG_DIAM_E3 " 3"
-#define MSG_DIAM_E4 " 4"
-#define MSG_DIAM_E5 " 5"
-#define MSG_DIAM_E6 " 6"
-
-#include INCLUDE_LANGUAGE
-
-#if DISABLED(DISPLAY_CHARSET_ISO10646_1) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_5) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_KANA) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_GREEK) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_CN) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_TR) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_PL) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_CZ) \
- && DISABLED(DISPLAY_CHARSET_ISO10646_SK)
- #define DISPLAY_CHARSET_ISO10646_1 // use the better font on full graphic displays.
+
+#define LCD_STR_A MSG_A
+#define LCD_STR_B MSG_B
+#define LCD_STR_C MSG_C
+#define LCD_STR_E MSG_E
+
+/**
+ * Tool indexes for LCD display only
+ *
+ * By convention the LCD shows "E1" for the first extruder.
+ * However, internal to Marlin E0/T0 is the first tool, and
+ * most board silkscreens say "E0." Zero-based labels will
+ * make these indexes consistent but this defies expectation.
+ *
+ */
+#if ENABLED(NUMBER_TOOLS_FROM_0)
+ #define LCD_FIRST_TOOL '0'
+ #define LCD_STR_N0 "0"
+ #define LCD_STR_N1 "1"
+ #define LCD_STR_N2 "2"
+ #define LCD_STR_N3 "3"
+ #define LCD_STR_N4 "4"
+ #define LCD_STR_N5 "5"
+#else
+ #define LCD_FIRST_TOOL '1'
+ #define LCD_STR_N0 "1"
+ #define LCD_STR_N1 "2"
+ #define LCD_STR_N2 "3"
+ #define LCD_STR_N3 "4"
+ #define LCD_STR_N4 "5"
+ #define LCD_STR_N5 "6"
#endif
-#include "../lcd/language/language_en.h"
+#define LCD_STR_E0 "E" LCD_STR_N0
+#define LCD_STR_E1 "E" LCD_STR_N1
+#define LCD_STR_E2 "E" LCD_STR_N2
+#define LCD_STR_E3 "E" LCD_STR_N3
+#define LCD_STR_E4 "E" LCD_STR_N4
+#define LCD_STR_E5 "E" LCD_STR_N5
+
+#include "multi_language.h" // Allow multiple languages
-#ifdef CUSTOM_USER_MENU_TITLE
- #undef MSG_USER_MENU
- #define MSG_USER_MENU CUSTOM_USER_MENU_TITLE
+#include "../lcd/language/language_en.h"
+#include LANGUAGE_INCL(LCD_LANGUAGE)
+#include LANGUAGE_INCL(LCD_LANGUAGE_2)
+#include LANGUAGE_INCL(LCD_LANGUAGE_3)
+#include LANGUAGE_INCL(LCD_LANGUAGE_4)
+#include LANGUAGE_INCL(LCD_LANGUAGE_5)
+
+#if NONE(DISPLAY_CHARSET_ISO10646_1, \
+ DISPLAY_CHARSET_ISO10646_5, \
+ DISPLAY_CHARSET_ISO10646_KANA, \
+ DISPLAY_CHARSET_ISO10646_GREEK, \
+ DISPLAY_CHARSET_ISO10646_CN, \
+ DISPLAY_CHARSET_ISO10646_TR, \
+ DISPLAY_CHARSET_ISO10646_PL, \
+ DISPLAY_CHARSET_ISO10646_CZ, \
+ DISPLAY_CHARSET_ISO10646_SK)
+ #define DISPLAY_CHARSET_ISO10646_1 // use the better font on full graphic displays.
#endif
diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h
index 918b3c6d1bd4..f3c9f3a81842 100644
--- a/Marlin/src/core/macros.h
+++ b/Marlin/src/core/macros.h
@@ -21,13 +21,11 @@
*/
#pragma once
-#include "minmax.h"
-
-#define NUM_AXIS 4
#define ABCE 4
#define XYZE 4
#define ABC 3
#define XYZ 3
+#define XY 2
#define _AXIS(A) (A##_AXIS)
@@ -47,6 +45,14 @@
#define _O2 __attribute__((optimize("O2")))
#define _O3 __attribute__((optimize("O3")))
+#ifndef UNUSED
+ #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+ #define UNUSED(X) (void)X
+ #else
+ #define UNUSED(x) ((void)(x))
+ #endif
+#endif
+
// Clock speed factors
#if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 on AVR
@@ -55,13 +61,11 @@
// Nanoseconds per cycle
#define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
-// Remove compiler warning on an unused variable
-#ifndef UNUSED
- #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
- #define UNUSED(X) (void)X
- #else
- #define UNUSED(x) ((void)(x))
- #endif
+// Macros to make sprintf_P read from PROGMEM (AVR extension)
+#ifdef __AVR__
+ #define S_FMT "%S"
+#else
+ #define S_FMT "%s"
#endif
// Macros to make a string from a macro
@@ -74,16 +78,23 @@
// Macros for bit masks
#undef _BV
#define _BV(n) (1<<(n))
-#define TEST(n,b) !!((n)&_BV(b))
-#define SBI(n,b) (n |= _BV(b))
-#define CBI(n,b) (n &= ~_BV(b))
+#define TEST(n,b) (!!((n)&_BV(b)))
#define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
+#ifndef SBI
+ #define SBI(A,B) (A |= (1 << (B)))
+#endif
+
+#ifndef CBI
+ #define CBI(A,B) (A &= ~(1 << (B)))
+#endif
+
#define _BV32(b) (1UL << (b))
#define TEST32(n,b) !!((n)&_BV32(b))
#define SBI32(n,b) (n |= _BV32(b))
#define CBI32(n,b) (n &= ~_BV32(b))
+#define cu(x) ((x)*(x)*(x))
#define RADIANS(d) ((d)*float(M_PI)/180.0f)
#define DEGREES(r) ((r)*180.0f/float(M_PI))
#define HYPOT2(x,y) (sq(x)+sq(y))
@@ -99,14 +110,14 @@
// C++11 solution that is standards compliant.
template static inline constexpr void NOLESS(V& v, const N n) {
- if (v < n) v = n;
+ if (n > v) v = n;
}
template static inline constexpr void NOMORE(V& v, const N n) {
- if (v > n) v = n;
+ if (n < v) v = n;
}
template static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
- if (v < n1) v = n1;
- else if (v > n2) v = n2;
+ if (n1 > v) v = n1;
+ else if (n2 < v) v = n2;
}
#else
@@ -114,24 +125,24 @@
// Using GCC extensions, but Travis GCC version does not like it and gives
// "error: statement-expressions are not allowed outside functions nor in template-argument lists"
#define NOLESS(v, n) \
- do { \
+ do{ \
__typeof__(n) _n = (n); \
- if (v < _n) v = _n; \
- } while(0)
+ if (_n > v) v = _n; \
+ }while(0)
#define NOMORE(v, n) \
- do { \
+ do{ \
__typeof__(n) _n = (n); \
- if (v > _n) v = _n; \
- } while(0)
+ if (_n < v) v = _n; \
+ }while(0)
#define LIMIT(v, n1, n2) \
- do { \
+ do{ \
__typeof__(n1) _n1 = (n1); \
__typeof__(n2) _n2 = (n2); \
- if (v < _n1) v = _n1; \
- else if (v > _n2) v = _n2; \
- } while(0)
+ if (_n1 > v) v = _n1; \
+ else if (_n2 < v) v = _n2; \
+ }while(0)
#endif
@@ -154,6 +165,7 @@
// Macros to support option testing
#define _CAT(a,V...) a##V
+#define CAT(a,V...) _CAT(a,V)
#define SWITCH_ENABLED_false 0
#define SWITCH_ENABLED_true 1
#define SWITCH_ENABLED_0 0
@@ -194,44 +206,29 @@
}while(0)
// Macros for initializing arrays
-#define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
-#define ARRAY_5(v1, v2, v3, v4, v5, ...) { v1, v2, v3, v4, v5 }
-#define ARRAY_4(v1, v2, v3, v4, ...) { v1, v2, v3, v4 }
-#define ARRAY_3(v1, v2, v3, ...) { v1, v2, v3 }
-#define ARRAY_2(v1, v2, ...) { v1, v2 }
-#define ARRAY_1(v1, ...) { v1 }
-
-#define _ARRAY_N(N,V...) ARRAY_##N(V)
-#define ARRAY_N(N,V...) _ARRAY_N(N,V)
-
-// Macros for adding
-#define INC_0 1
-#define INC_1 2
-#define INC_2 3
-#define INC_3 4
-#define INC_4 5
-#define INC_5 6
-#define INC_6 7
-#define INC_7 8
-#define INC_8 9
-#define INCREMENT_(n) INC_##n
-#define INCREMENT(n) INCREMENT_(n)
-
-// Macros for subtracting
-#define DEC_1 0
-#define DEC_2 1
-#define DEC_3 2
-#define DEC_4 3
-#define DEC_5 4
-#define DEC_6 5
-#define DEC_7 6
-#define DEC_8 7
-#define DEC_9 8
-#define DECREMENT_(n) DEC_##n
-#define DECREMENT(n) DECREMENT_(n)
-
-#define MMM_TO_MMS(MM_M) ((MM_M)/60.0f)
-#define MMS_TO_MMM(MM_S) ((MM_S)*60.0f)
+#define LIST_16(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P
+#define LIST_15(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O
+#define LIST_14(A,B,C,D,E,F,G,H,I,J,K,L,M,N,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N
+#define LIST_13(A,B,C,D,E,F,G,H,I,J,K,L,M,...) A,B,C,D,E,F,G,H,I,J,K,L,M
+#define LIST_12(A,B,C,D,E,F,G,H,I,J,K,L,...) A,B,C,D,E,F,G,H,I,J,K,L
+#define LIST_11(A,B,C,D,E,F,G,H,I,J,K,...) A,B,C,D,E,F,G,H,I,J,K
+#define LIST_10(A,B,C,D,E,F,G,H,I,J,...) A,B,C,D,E,F,G,H,I,J
+#define LIST_9( A,B,C,D,E,F,G,H,I,...) A,B,C,D,E,F,G,H,I
+#define LIST_8( A,B,C,D,E,F,G,H,...) A,B,C,D,E,F,G,H
+#define LIST_7( A,B,C,D,E,F,G,...) A,B,C,D,E,F,G
+#define LIST_6( A,B,C,D,E,F,...) A,B,C,D,E,F
+#define LIST_5( A,B,C,D,E,...) A,B,C,D,E
+#define LIST_4( A,B,C,D,...) A,B,C,D
+#define LIST_3( A,B,C,...) A,B,C
+#define LIST_2( A,B,...) A,B
+#define LIST_1( A,...) A
+
+#define _LIST_N(N,V...) LIST_##N(V)
+#define LIST_N(N,V...) _LIST_N(N,V)
+#define ARRAY_N(N,V...) { _LIST_N(N,V) }
+
+#define _JOIN_1(O) (O)
+#define JOIN_N(N,C,V...) (DO(JOIN,C,LIST_N(N,V)))
#define NOOP (void(0))
@@ -254,10 +251,11 @@
//
// Maths macros that can be overridden by HAL
//
+#define ACOS(x) acosf(x)
#define ATAN2(y, x) atan2f(y, x)
#define POW(x, y) powf(x, y)
#define SQRT(x) sqrtf(x)
-#define RSQRT(x) (1 / sqrtf(x))
+#define RSQRT(x) (1.0f / sqrtf(x))
#define CEIL(x) ceilf(x)
#define FLOOR(x) floorf(x)
#define LROUND(x) lroundf(x)
@@ -269,3 +267,182 @@
#else
#define I2C_ADDRESS(A) A
#endif
+
+// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
+#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
+#define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
+
+#ifdef __cplusplus
+
+ #ifndef _MINMAX_H_
+ #define _MINMAX_H_
+
+ extern "C++" {
+
+ // C++11 solution that is standards compliant. Return type is deduced automatically
+ template static inline constexpr auto _MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+ return lhs < rhs ? lhs : rhs;
+ }
+ template static inline constexpr auto _MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+ return lhs > rhs ? lhs : rhs;
+ }
+ template static inline constexpr const T _MIN(T V, Ts... Vs) { return _MIN(V, _MIN(Vs...)); }
+ template static inline constexpr const T _MAX(T V, Ts... Vs) { return _MAX(V, _MAX(Vs...)); }
+
+ }
+
+ #endif
+
+#else
+
+ #define MIN_2(a,b) ((a)<(b)?(a):(b))
+ #define MIN_3(a,V...) MIN_2(a,MIN_2(V))
+ #define MIN_4(a,V...) MIN_2(a,MIN_3(V))
+ #define MIN_5(a,V...) MIN_2(a,MIN_4(V))
+ #define MIN_6(a,V...) MIN_2(a,MIN_5(V))
+ #define MIN_7(a,V...) MIN_2(a,MIN_6(V))
+ #define MIN_8(a,V...) MIN_2(a,MIN_7(V))
+ #define MIN_9(a,V...) MIN_2(a,MIN_8(V))
+ #define MIN_10(a,V...) MIN_2(a,MIN_9(V))
+ #define __MIN_N(N,V...) MIN_##N(V)
+ #define _MIN_N(N,V...) __MIN_N(N,V)
+ #define _MIN(V...) _MIN_N(NUM_ARGS(V), V)
+
+ #define MAX_2(a,b) ((a)>(b)?(a):(b))
+ #define MAX_3(a,V...) MAX_2(a,MAX_2(V))
+ #define MAX_4(a,V...) MAX_2(a,MAX_3(V))
+ #define MAX_5(a,V...) MAX_2(a,MAX_4(V))
+ #define MAX_6(a,V...) MAX_2(a,MAX_5(V))
+ #define MAX_7(a,V...) MAX_2(a,MAX_6(V))
+ #define MAX_8(a,V...) MAX_2(a,MAX_7(V))
+ #define MAX_9(a,V...) MAX_2(a,MAX_8(V))
+ #define MAX_10(a,V...) MAX_2(a,MAX_9(V))
+ #define __MAX_N(N,V...) MAX_##N(V)
+ #define _MAX_N(N,V...) __MAX_N(N,V)
+ #define _MAX(V...) _MAX_N(NUM_ARGS(V), V)
+
+#endif
+
+// Macros for adding
+#define INC_0 1
+#define INC_1 2
+#define INC_2 3
+#define INC_3 4
+#define INC_4 5
+#define INC_5 6
+#define INC_6 7
+#define INC_7 8
+#define INC_8 9
+#define INCREMENT_(n) INC_##n
+#define INCREMENT(n) INCREMENT_(n)
+
+#define ADD0(N) N
+#define ADD1(N) INCREMENT_(N)
+#define ADD2(N) ADD1(ADD1(N))
+#define ADD3(N) ADD1(ADD2(N))
+#define ADD4(N) ADD2(ADD2(N))
+#define ADD5(N) ADD2(ADD3(N))
+#define ADD6(N) ADD3(ADD3(N))
+#define ADD7(N) ADD3(ADD4(N))
+#define ADD8(N) ADD4(ADD4(N))
+#define ADD9(N) ADD4(ADD5(N))
+#define ADD10(N) ADD5(ADD5(N))
+
+// Macros for subtracting
+#define DEC_0 0
+#define DEC_1 0
+#define DEC_2 1
+#define DEC_3 2
+#define DEC_4 3
+#define DEC_5 4
+#define DEC_6 5
+#define DEC_7 6
+#define DEC_8 7
+#define DEC_9 8
+#define DECREMENT_(n) DEC_##n
+#define DECREMENT(n) DECREMENT_(n)
+
+#define SUB0(N) N
+#define SUB1(N) DECREMENT_(N)
+#define SUB2(N) SUB1(SUB1(N))
+#define SUB3(N) SUB1(SUB2(N))
+#define SUB4(N) SUB2(SUB2(N))
+#define SUB5(N) SUB2(SUB3(N))
+#define SUB6(N) SUB3(SUB3(N))
+#define SUB7(N) SUB3(SUB4(N))
+#define SUB8(N) SUB4(SUB4(N))
+#define SUB9(N) SUB4(SUB5(N))
+#define SUB10(N) SUB5(SUB5(N))
+
+//
+// Primitives supporting precompiler REPEAT
+//
+#define FIRST(a,...) a
+#define SECOND(a,b,...) b
+
+// Defer expansion
+#define EMPTY()
+#define DEFER(M) M EMPTY()
+#define DEFER2(M) M EMPTY EMPTY()()
+#define DEFER3(M) M EMPTY EMPTY EMPTY()()()
+#define DEFER4(M) M EMPTY EMPTY EMPTY EMPTY()()()()
+
+// Force define expansion
+#define EVAL(V...) EVAL16(V)
+#define EVAL1024(V...) EVAL512(EVAL512(V))
+#define EVAL512(V...) EVAL256(EVAL256(V))
+#define EVAL256(V...) EVAL128(EVAL128(V))
+#define EVAL128(V...) EVAL64(EVAL64(V))
+#define EVAL64(V...) EVAL32(EVAL32(V))
+#define EVAL32(V...) EVAL16(EVAL16(V))
+#define EVAL16(V...) EVAL8(EVAL8(V))
+#define EVAL8(V...) EVAL4(EVAL4(V))
+#define EVAL4(V...) EVAL2(EVAL2(V))
+#define EVAL2(V...) EVAL1(EVAL1(V))
+#define EVAL1(V...) V
+
+#define IS_PROBE(V...) SECOND(V, 0) // Get the second item passed, or 0
+#define PROBE() ~, 1 // Second item will be 1 if this is passed
+#define _NOT_0 PROBE()
+#define NOT(x) IS_PROBE(_CAT(_NOT_, x)) // NOT('0') gets '1'. Anything else gets '0'.
+#define _BOOL(x) NOT(NOT(x)) // NOT('0') gets '0'. Anything else gets '1'.
+
+#define IF_ELSE(TF) _IF_ELSE(_BOOL(TF))
+#define _IF_ELSE(TF) _CAT(_IF_, TF)
+
+#define _IF_1(V...) V _IF_1_ELSE
+#define _IF_0(...) _IF_0_ELSE
+
+#define _IF_1_ELSE(...)
+#define _IF_0_ELSE(V...) V
+
+#define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)())
+#define _END_OF_ARGUMENTS_() 0
+
+//
+// REPEAT core macros. Recurse N times with ascending I.
+//
+
+// Call OP(I) N times with ascending counter.
+#define _REPEAT(_RPT_I,_RPT_N,_RPT_OP) \
+ _RPT_OP(_RPT_I) \
+ IF_ELSE(SUB1(_RPT_N)) \
+ ( DEFER2(__REPEAT)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP) ) \
+ ( /* Do nothing */ )
+#define __REPEAT() _REPEAT
+
+// Call OP(I, ...) N times with ascending counter.
+#define _REPEAT2(_RPT_I,_RPT_N,_RPT_OP,V...) \
+ _RPT_OP(_RPT_I,V) \
+ IF_ELSE(SUB1(_RPT_N)) \
+ ( DEFER2(__REPEAT2)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP,V) ) \
+ ( /* Do nothing */ )
+#define __REPEAT2() _REPEAT2
+
+// Repeat a macro passing S...N-1.
+#define REPEAT_S(S,N,OP) EVAL(_REPEAT(S,SUB##S(N),OP))
+#define REPEAT(N,OP) REPEAT_S(0,N,OP)
+
+// Repeat a macro passing 0...N-1 plus additional arguments.
+#define REPEAT2_S(S,N,OP,V...) EVAL(_REPEAT2(S,SUB##S(N),OP,V))
+#define REPEAT2(N,OP,V...) REPEAT2_S(0,N,OP,V)
diff --git a/Marlin/src/core/minmax.h b/Marlin/src/core/minmax.h
deleted file mode 100644
index cdb84138eccc..000000000000
--- a/Marlin/src/core/minmax.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 .
- *
- */
-#pragma once
-
-#undef MIN
-#undef MAX
-
-// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
-#define _NUM_ARGS(_0,_24_,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...) N
-#define NUM_ARGS(V...) _NUM_ARGS(0,V,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
-
-#ifdef __cplusplus
-
- #ifndef _MINMAX_H_
- #define _MINMAX_H_
-
- extern "C++" {
-
- // C++11 solution that is standards compliant. Return type is deduced automatically
- template static inline constexpr auto _MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
- return lhs < rhs ? lhs : rhs;
- }
- template static inline constexpr auto _MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
- return lhs > rhs ? lhs : rhs;
- }
- template static inline constexpr const T _MIN(T V, Ts... Vs) { return _MIN(V, _MIN(Vs...)); }
- template static inline constexpr const T _MAX(T V, Ts... Vs) { return _MAX(V, _MAX(Vs...)); }
-
- }
-
- #endif
-
-#else
-
- #define MIN_2(a,b) ((a)<(b)?(a):(b))
- #define MIN_3(a,...) MIN_2(a,MIN_2(__VA_ARGS__))
- #define MIN_4(a,...) MIN_2(a,MIN_3(__VA_ARGS__))
- #define MIN_5(a,...) MIN_2(a,MIN_4(__VA_ARGS__))
- #define MIN_6(a,...) MIN_2(a,MIN_5(__VA_ARGS__))
- #define MIN_7(a,...) MIN_2(a,MIN_6(__VA_ARGS__))
- #define MIN_8(a,...) MIN_2(a,MIN_7(__VA_ARGS__))
- #define MIN_9(a,...) MIN_2(a,MIN_8(__VA_ARGS__))
- #define MIN_10(a,...) MIN_2(a,MIN_9(__VA_ARGS__))
- #define __MIN_N(N, ...) MIN_##N(__VA_ARGS__)
- #define _MIN_N(N, ...) __MIN_N(N,__VA_ARGS__)
- #define MIN(...) _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
-
- #define MAX_2(a,b) ((a)>(b)?(a):(b))
- #define MAX_3(a,...) MAX_2(a,MAX_2(__VA_ARGS__))
- #define MAX_4(a,...) MAX_2(a,MAX_3(__VA_ARGS__))
- #define MAX_5(a,...) MAX_2(a,MAX_4(__VA_ARGS__))
- #define MAX_6(a,...) MAX_2(a,MAX_5(__VA_ARGS__))
- #define MAX_7(a,...) MAX_2(a,MAX_6(__VA_ARGS__))
- #define MAX_8(a,...) MAX_2(a,MAX_7(__VA_ARGS__))
- #define MAX_9(a,...) MAX_2(a,MAX_8(__VA_ARGS__))
- #define MAX_10(a,...) MAX_2(a,MAX_9(__VA_ARGS__))
- #define __MAX_N(N, ...) MAX_##N(__VA_ARGS__)
- #define _MAX_N(N, ...) __MAX_N(N,__VA_ARGS__)
- #define MAX(...) _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
-
-#endif
diff --git a/Marlin/src/core/multi_language.cpp b/Marlin/src/core/multi_language.cpp
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/Marlin/src/core/multi_language.h b/Marlin/src/core/multi_language.h
new file mode 100644
index 000000000000..98020b1e8d9c
--- /dev/null
+++ b/Marlin/src/core/multi_language.h
@@ -0,0 +1,79 @@
+/********************
+ * multi_language.h *
+ ********************/
+
+/****************************************************************************
+ * Written By Marcio Teixeira 2019 - Aleph Objects, Inc. *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * To view a copy of the GNU General Public License, go to the following *
+ * location: . *
+ ****************************************************************************/
+#pragma once
+
+typedef const char Language_Str[];
+
+#if defined(LCD_LANGUAGE_5)
+ #define NUM_LANGUAGES 5
+#elif defined(LCD_LANGUAGE_4)
+ #define NUM_LANGUAGES 4
+#elif defined(LCD_LANGUAGE_3)
+ #define NUM_LANGUAGES 3
+#elif defined(LCD_LANGUAGE_2)
+ #define NUM_LANGUAGES 2
+#else
+ #define NUM_LANGUAGES 1
+#endif
+
+// Setting the unused languages equal to each other allows
+// the compiler to optimize away the conditionals
+
+#ifndef LCD_LANGUAGE_2
+ #define LCD_LANGUAGE_2 LCD_LANGUAGE
+#endif
+
+#ifndef LCD_LANGUAGE_3
+ #define LCD_LANGUAGE_3 LCD_LANGUAGE_2
+#endif
+
+#ifndef LCD_LANGUAGE_4
+ #define LCD_LANGUAGE_4 LCD_LANGUAGE_3
+#endif
+
+#ifndef LCD_LANGUAGE_5
+ #define LCD_LANGUAGE_5 LCD_LANGUAGE_4
+#endif
+
+#define _GET_LANG(LANG) Language_##LANG
+#define GET_LANG(LANG) _GET_LANG(LANG)
+
+#if NUM_LANGUAGES > 1
+ extern uint8_t lang;
+ #define GET_TEXT(MSG) ( \
+ lang == 0 ? GET_LANG(LCD_LANGUAGE)::MSG : \
+ lang == 1 ? GET_LANG(LCD_LANGUAGE_2)::MSG : \
+ lang == 2 ? GET_LANG(LCD_LANGUAGE_3)::MSG : \
+ lang == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
+ GET_LANG(LCD_LANGUAGE_5)::MSG \
+ )
+ #define MAX_LANG_CHARSIZE _MAX(GET_LANG(LCD_LANGUAGE)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_2)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_3)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_4)::CHARSIZE, \
+ GET_LANG(LCD_LANGUAGE_5)::CHARSIZE)
+#else
+ #define GET_TEXT(MSG) GET_LANG(LCD_LANGUAGE)::MSG
+ #define MAX_LANG_CHARSIZE GET_LANG(LCD_LANGUAGE)::CHARSIZE
+#endif
+#define GET_TEXT_F(MSG) (const __FlashStringHelper*)GET_TEXT(MSG)
+
+#define MSG_CONCAT(A,B) pgm_p_pair_t(GET_TEXT(A),GET_TEXT(B))
diff --git a/Marlin/src/core/serial.cpp b/Marlin/src/core/serial.cpp
index 84b64b8b62c1..4a5214f5c04d 100644
--- a/Marlin/src/core/serial.cpp
+++ b/Marlin/src/core/serial.cpp
@@ -22,7 +22,6 @@
#include "serial.h"
#include "language.h"
-#include "enum.h"
uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
@@ -68,15 +67,10 @@ void print_bin(const uint16_t val) {
}
}
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z) {
+extern const char SP_X_STR[], SP_Y_STR[], SP_Z_STR[];
+
+void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix/*=nullptr*/, PGM_P const suffix/*=nullptr*/) {
serialprintPGM(prefix);
- SERIAL_CHAR('(');
- SERIAL_ECHO(x);
- SERIAL_ECHOPAIR(", ", y, ", ", z);
- SERIAL_CHAR(')');
+ SERIAL_ECHOPAIR_P(SP_X_STR, x, SP_Y_STR, y, SP_Z_STR, z);
if (suffix) serialprintPGM(suffix); else SERIAL_EOL();
}
-
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]) {
- print_xyz(prefix, suffix, xyz[X_AXIS], xyz[Y_AXIS], xyz[Z_AXIS]);
-}
diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h
index e46696669845..c2745e972b0d 100644
--- a/Marlin/src/core/serial.h
+++ b/Marlin/src/core/serial.h
@@ -21,9 +21,7 @@
*/
#pragma once
-#include "../inc/MarlinConfigPre.h"
-#include "../core/minmax.h"
-#include HAL_PATH(../HAL, HAL.h)
+#include "../inc/MarlinConfig.h"
/**
* Define debug bit-masks
@@ -57,10 +55,12 @@ extern uint8_t marlin_debug_flags;
if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
}while(0)
+ #define SERIAL_ASSERT(P) if(serial_port_index!=(P)){ debugger(); }
#else
#define _PORT_REDIRECT(n,p) NOOP
#define _PORT_RESTORE(n) NOOP
#define SERIAL_OUT(WHAT, V...) (void)MYSERIAL0.WHAT(V)
+ #define SERIAL_ASSERT(P) NOOP
#endif
#define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
@@ -68,20 +68,22 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_CHAR(x) SERIAL_OUT(write, x)
#define SERIAL_ECHO(x) SERIAL_OUT(print, x)
-#define SERIAL_ECHO_F(V...) SERIAL_OUT(print, V)
+#define SERIAL_ECHO_F(V...) SERIAL_OUT(print, V)
#define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
#define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
#define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
-#define SERIAL_PRINTF(V...) SERIAL_OUT(printf, V)
+#define SERIAL_PRINTF(V...) SERIAL_OUT(printf, V)
#define SERIAL_FLUSH() SERIAL_OUT(flush)
-#if TX_BUFFER_SIZE > 0
+#ifdef __STM32F1__
+ #define SERIAL_FLUSHTX() SERIAL_OUT(flush)
+#elif TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX() SERIAL_OUT(flushTX)
#else
#define SERIAL_FLUSHTX()
#endif
-// Print up to 12 pairs of values
+// Print up to 12 pairs of values. Odd elements auto-wrapped in PSTR().
#define __SEP_N(N,V...) _SEP_##N(V)
#define _SEP_N(N,V...) __SEP_N(N,V)
#define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
@@ -111,6 +113,36 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_ECHOPAIR(V...) _SEP_N(NUM_ARGS(V),V)
+// Print up to 12 pairs of values. Odd elements must be PSTR pointers.
+#define __SEP_N_P(N,V...) _SEP_##N##_P(V)
+#define _SEP_N_P(N,V...) __SEP_N_P(N,V)
+#define _SEP_1_P(PRE) serialprintPGM(PRE)
+#define _SEP_2_P(PRE,V) serial_echopair_PGM(PRE,V)
+#define _SEP_3_P(a,b,c) do{ _SEP_2_P(a,b); serialprintPGM(c); }while(0)
+#define _SEP_4_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_2_P(V); }while(0)
+#define _SEP_5_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_3_P(V); }while(0)
+#define _SEP_6_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_4_P(V); }while(0)
+#define _SEP_7_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_5_P(V); }while(0)
+#define _SEP_8_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_6_P(V); }while(0)
+#define _SEP_9_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_7_P(V); }while(0)
+#define _SEP_10_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_8_P(V); }while(0)
+#define _SEP_11_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_9_P(V); }while(0)
+#define _SEP_12_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_10_P(V); }while(0)
+#define _SEP_13_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_11_P(V); }while(0)
+#define _SEP_14_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_12_P(V); }while(0)
+#define _SEP_15_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_13_P(V); }while(0)
+#define _SEP_16_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_14_P(V); }while(0)
+#define _SEP_17_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_15_P(V); }while(0)
+#define _SEP_18_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_16_P(V); }while(0)
+#define _SEP_19_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_17_P(V); }while(0)
+#define _SEP_20_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_18_P(V); }while(0)
+#define _SEP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_19_P(V); }while(0)
+#define _SEP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_20_P(V); }while(0)
+#define _SEP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_21_P(V); }while(0)
+#define _SEP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_22_P(V); }while(0)
+
+#define SERIAL_ECHOPAIR_P(V...) _SEP_N_P(NUM_ARGS(V),V)
+
// Print up to 12 pairs of values followed by newline
#define __SELP_N(N,V...) _SELP_##N(V)
#define _SELP_N(N,V...) __SELP_N(N,V)
@@ -137,15 +169,77 @@ extern uint8_t marlin_debug_flags;
#define _SELP_21(a,b,V...) do{ _SEP_2(a,b); _SELP_19(V); }while(0)
#define _SELP_22(a,b,V...) do{ _SEP_2(a,b); _SELP_20(V); }while(0)
#define _SELP_23(a,b,V...) do{ _SEP_2(a,b); _SELP_21(V); }while(0)
-#define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0)
+#define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0) // Eat two args, pass the rest up
#define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
-#define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
-#define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
+// Print up to 12 pairs of values followed by newline
+#define __SELP_N_P(N,V...) _SELP_##N##_P(V)
+#define _SELP_N_P(N,V...) __SELP_N_P(N,V)
+#define _SELP_1_P(PRE) serialprintPGM(PRE)
+#define _SELP_2_P(PRE,V) do{ serial_echopair_PGM(PRE,V); SERIAL_EOL(); }while(0)
+#define _SELP_3_P(a,b,c) do{ _SEP_2_P(a,b); serialprintPGM(c); }while(0)
+#define _SELP_4_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_2_P(V); }while(0)
+#define _SELP_5_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_3_P(V); }while(0)
+#define _SELP_6_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_4_P(V); }while(0)
+#define _SELP_7_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_5_P(V); }while(0)
+#define _SELP_8_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_6_P(V); }while(0)
+#define _SELP_9_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_7_P(V); }while(0)
+#define _SELP_10_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_8_P(V); }while(0)
+#define _SELP_11_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_9_P(V); }while(0)
+#define _SELP_12_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_10_P(V); }while(0)
+#define _SELP_13_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_11_P(V); }while(0)
+#define _SELP_14_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_12_P(V); }while(0)
+#define _SELP_15_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_13_P(V); }while(0)
+#define _SELP_16_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_14_P(V); }while(0)
+#define _SELP_17_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_15_P(V); }while(0)
+#define _SELP_18_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_16_P(V); }while(0)
+#define _SELP_19_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_17_P(V); }while(0)
+#define _SELP_20_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_18_P(V); }while(0)
+#define _SELP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_19_P(V); }while(0)
+#define _SELP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_20_P(V); }while(0)
+#define _SELP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_21_P(V); }while(0)
+#define _SELP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_22_P(V); }while(0) // Eat two args, pass the rest up
+
+#define SERIAL_ECHOLNPAIR_P(V...) _SELP_N_P(NUM_ARGS(V),V)
+
+// Print up to 20 comma-separated pairs of values
+#define __SLST_N(N,V...) _SLST_##N(V)
+#define _SLST_N(N,V...) __SLST_N(N,V)
+#define _SLST_1(a) SERIAL_ECHO(a)
+#define _SLST_2(a,b) do{ SERIAL_ECHO(a); SERIAL_ECHOPAIR(", ",b); }while(0)
+#define _SLST_3(a,b,c) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_1(c); }while(0)
+#define _SLST_4(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_2(V); }while(0)
+#define _SLST_5(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_3(V); }while(0)
+#define _SLST_6(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_4(V); }while(0)
+#define _SLST_7(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_5(V); }while(0)
+#define _SLST_8(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_6(V); }while(0)
+#define _SLST_9(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_7(V); }while(0)
+#define _SLST_10(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_8(V); }while(0)
+#define _SLST_11(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_9(V); }while(0)
+#define _SLST_12(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_10(V); }while(0)
+#define _SLST_13(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_11(V); }while(0)
+#define _SLST_14(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_12(V); }while(0)
+#define _SLST_15(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_13(V); }while(0)
+#define _SLST_16(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_14(V); }while(0)
+#define _SLST_17(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_15(V); }while(0)
+#define _SLST_18(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_16(V); }while(0)
+#define _SLST_19(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_17(V); }while(0)
+#define _SLST_20(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_18(V); }while(0) // Eat two args, pass the rest up
+
+#define SERIAL_ECHOLIST(pre,V...) do{ SERIAL_ECHOPGM(pre); _SLST_N(NUM_ARGS(V),V); }while(0)
+#define SERIAL_ECHOLIST_N(N,V...) _SLST_N(N,LIST_N(N,V))
-#define SERIAL_ECHOPAIR_F(pre, V...) do{ SERIAL_ECHO(pre); SERIAL_ECHO_F(V); }while(0)
-#define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
+#define SERIAL_ECHO_P(P) (serialprintPGM(P))
+
+#define SERIAL_ECHOPGM(S) (SERIAL_ECHO_P(PSTR(S)))
+#define SERIAL_ECHOLNPGM(S) (SERIAL_ECHO_P(PSTR(S "\n")))
+
+#define SERIAL_ECHOPAIR_F_P(P,V...) do{ serialprintPGM(P); SERIAL_ECHO_F(V); }while(0)
+#define SERIAL_ECHOLNPAIR_F_P(V...) do{ SERIAL_ECHOPAIR_F_P(V); SERIAL_EOL(); }while(0)
+
+#define SERIAL_ECHOPAIR_F(S,V...) SERIAL_ECHOPAIR_F_P(PSTR(S),V)
+#define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
#define SERIAL_ECHO_START() serial_echo_start()
#define SERIAL_ERROR_START() serial_error_start()
@@ -156,6 +250,8 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_ECHO_SP(C) serial_spaces(C)
+#define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
+
//
// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
//
@@ -182,7 +278,11 @@ void serial_spaces(uint8_t count);
void print_bin(const uint16_t val);
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z);
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]);
-#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); } while(0)
-#define SERIAL_XYZ(PREFIX,V...) do { print_xyz(PSTR(PREFIX), nullptr, V); } while(0)
+void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr);
+
+inline void print_xyz(const xyz_pos_t &xyz, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr) {
+ print_xyz(xyz.x, xyz.y, xyz.z, prefix, suffix);
+}
+
+#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(VAR, PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n")); }while(0)
+#define SERIAL_XYZ(PREFIX,V...) do { print_xyz(V, PSTR(PREFIX), nullptr); }while(0)
diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h
new file mode 100644
index 000000000000..72578faaaf27
--- /dev/null
+++ b/Marlin/src/core/types.h
@@ -0,0 +1,489 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+#include
+
+#include "millis_t.h"
+
+class __FlashStringHelper;
+typedef const __FlashStringHelper *progmem_str;
+
+//
+// Enumerated axis indices
+//
+// - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
+// - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
+// - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
+//
+enum AxisEnum : uint8_t {
+ X_AXIS = 0, A_AXIS = 0,
+ Y_AXIS = 1, B_AXIS = 1,
+ Z_AXIS = 2, C_AXIS = 2,
+ E_AXIS = 3,
+ X_HEAD = 4, Y_HEAD = 5, Z_HEAD = 6,
+ E0_AXIS = 3,
+ E1_AXIS = 4,
+ E2_AXIS = 5,
+ E3_AXIS = 6,
+ E4_AXIS = 7,
+ E5_AXIS = 8,
+ ALL_AXES = 0xFE, NO_AXIS = 0xFF
+};
+
+//
+// Loop over XYZE axes
+//
+
+#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
+#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
+#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
+#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
+
+#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
+#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
+#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
+#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
+#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
+#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
+
+//
+// Conditional type assignment magic. For example...
+//
+// typename IF<(MYOPT==12), int, float>::type myvar;
+//
+template
+struct IF { typedef R type; };
+template
+struct IF { typedef L type; };
+
+//
+// feedRate_t is just a humble float
+//
+typedef float feedRate_t;
+
+// Conversion macros
+#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f)
+#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f)
+#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage)
+
+//
+// Coordinates structures for XY, XYZ, XYZE...
+//
+
+// Helpers
+#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f)
+#define _ABS(N) ((N) < 0 ? -(N) : (N))
+#define _LS(N) (N = (T)(uint32_t(N) << v))
+#define _RS(N) (N = (T)(uint32_t(N) >> v))
+#define FI FORCE_INLINE
+
+// Forward declarations
+template struct XYval;
+template struct XYZval;
+template struct XYZEval;
+
+typedef struct XYval xy_bool_t;
+typedef struct XYZval xyz_bool_t;
+typedef struct XYZEval xyze_bool_t;
+
+typedef struct XYval xy_char_t;
+typedef struct XYZval xyz_char_t;
+typedef struct XYZEval xyze_char_t;
+
+typedef struct XYval