This commit is contained in:
2022-12-14 12:54:23 -05:00
836 changed files with 25627 additions and 12003 deletions

View File

@@ -4,10 +4,10 @@ root = true
[{*.patch,syntax_test_*}] [{*.patch,syntax_test_*}]
trim_trailing_whitespace = false trim_trailing_whitespace = false
[{*.c,*.cpp,*.h}] [{*.c,*.cpp,*.h,*.ino}]
charset = utf-8 charset = utf-8
[{*.c,*.cpp,*.h,Makefile}] [{*.c,*.cpp,*.h,*.ino,Makefile}]
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
end_of_line = lf end_of_line = lf

View File

@@ -89,6 +89,8 @@ jobs:
- mks_robin_nano35_stm32 - mks_robin_nano35_stm32
- NUCLEO_F767ZI - NUCLEO_F767ZI
- REMRAM_V1 - REMRAM_V1
- BTT_SKR_SE_BX
- chitu_f103
# Put lengthy tests last # Put lengthy tests last
@@ -98,6 +100,7 @@ jobs:
# Non-working environment tests # Non-working environment tests
#- at90usb1286_cdc #- at90usb1286_cdc
#- STM32F103CB_malyan #- STM32F103CB_malyan
#- STM32F103RE
#- mks_robin_mini #- mks_robin_mini
steps: steps:

23
.gitignore vendored
View File

@@ -122,29 +122,6 @@ tags
.gcc-flags.json .gcc-flags.json
/lib/ /lib/
# Workaround for Deviot+platformio quirks
Marlin/lib
Marlin/platformio.ini
Marlin/*/platformio.ini
Marlin/*/*/platformio.ini
Marlin/*/*/*/platformio.ini
Marlin/*/*/*/*/platformio.ini
Marlin/.travis.yml
Marlin/*/.travis.yml
Marlin/*/*/.travis.yml
Marlin/*/*/*/.travis.yml
Marlin/*/*/*/*/.travis.yml
Marlin/.gitignore
Marlin/*/.gitignore
Marlin/*/*/.gitignore
Marlin/*/*/*/.gitignore
Marlin/*/*/*/*/.gitignore
Marlin/readme.txt
Marlin/*/readme.txt
Marlin/*/*/readme.txt
Marlin/*/*/*/readme.txt
Marlin/*/*/*/*/readme.txt
# Secure Credentials # Secure Credentials
Configuration_Secure.h Configuration_Secure.h

View File

@@ -163,8 +163,8 @@
* PRUSA_MMU1 : Průša MMU1 (The "multiplexer" version) * PRUSA_MMU1 : Průša MMU1 (The "multiplexer" version)
* PRUSA_MMU2 : Průša MMU2 * PRUSA_MMU2 : Průša MMU2
* PRUSA_MMU2S : Průša MMU2S (Requires MK3S extruder with motion sensor, EXTRUDERS = 5) * PRUSA_MMU2S : Průša MMU2S (Requires MK3S extruder with motion sensor, EXTRUDERS = 5)
* SMUFF_EMU_MMU2 : Technik Gegg SMuFF (Průša MMU2 emulation mode) * EXTENDABLE_EMU_MMU2 : MMU with configurable number of filaments (ERCF, SMuFF or similar with Průša MMU2 compatible firmware)
* SMUFF_EMU_MMU2S : Technik Gegg SMuFF (Průša MMU2S emulation mode) * EXTENDABLE_EMU_MMU2S : MMUS with configurable number of filaments (ERCF, SMuFF or similar with Průša MMU2 compatible firmware)
* *
* Requires NOZZLE_PARK_FEATURE to park print head in case MMU unit fails. * Requires NOZZLE_PARK_FEATURE to park print head in case MMU unit fails.
* See additional options in Configuration_adv.h. * See additional options in Configuration_adv.h.
@@ -329,10 +329,13 @@
#define AUTO_POWER_E_FANS #define AUTO_POWER_E_FANS
#define AUTO_POWER_CONTROLLERFAN #define AUTO_POWER_CONTROLLERFAN
#define AUTO_POWER_CHAMBER_FAN #define AUTO_POWER_CHAMBER_FAN
#define AUTO_POWER_E_TEMP 50 // (°C) Turn on PSU if any extruder is over this temperature #define AUTO_POWER_COOLER_FAN
// #define AUTO_POWER_CHAMBER_TEMP 30 // (°C) Turn on PSU if the chamber is over this temperature //#define AUTO_POWER_E_TEMP 50 // (°C) Turn on PSU if any extruder is over this temperature
// #define POWER_TIMEOUT 30 // (s) Turn off power if the machine is idle for this duration //#define AUTO_POWER_CHAMBER_TEMP 30 // (°C) Turn on PSU if the chamber is over this temperature
// #define POWER_OFF_DELAY 60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time. //#define AUTO_POWER_COOLER_TEMP 26 // (°C) Turn on PSU if the cooler is over this temperature
#define POWER_TIMEOUT 30 // (s) Turn off power if the machine is idle for this duration
//#define POWER_OFF_DELAY 60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time.
#endif #endif
#endif #endif
@@ -418,6 +421,7 @@
#define TEMP_SENSOR_BED 1 #define TEMP_SENSOR_BED 1
#define TEMP_SENSOR_PROBE 0 #define TEMP_SENSOR_PROBE 0
#define TEMP_SENSOR_CHAMBER 0 #define TEMP_SENSOR_CHAMBER 0
#define TEMP_SENSOR_COOLER 0
// Dummy thermistor constant temperature readings, for use with 998 and 999 // Dummy thermistor constant temperature readings, for use with 998 and 999
#define DUMMY_THERMISTOR_998_VALUE 25 #define DUMMY_THERMISTOR_998_VALUE 25
@@ -473,6 +477,16 @@
#define BED_MAXTEMP 150 #define BED_MAXTEMP 150
#define CHAMBER_MAXTEMP 60 #define CHAMBER_MAXTEMP 60
/**
* Thermal Overshoot
* During heatup (and printing) the temperature can often "overshoot" the target by many degrees
* (especially before PID tuning). Setting the target temperature too close to MAXTEMP guarantees
* a MAXTEMP shutdown! Use these values to forbid temperatures being set too close to MAXTEMP.
*/
#define HOTEND_OVERSHOOT 15 // (°C) Forbid temperatures over MAXTEMP - OVERSHOOT
#define BED_OVERSHOOT 10 // (°C) Forbid temperatures over MAXTEMP - OVERSHOOT
#define COOLER_OVERSHOOT 2 // (°C) Forbid temperatures closer than OVERSHOOT
//=========================================================================== //===========================================================================
//============================= PID Settings ================================ //============================= PID Settings ================================
//=========================================================================== //===========================================================================
@@ -637,6 +651,7 @@
#define THERMAL_PROTECTION_HOTENDS // Enable thermal protection for all extruders #define THERMAL_PROTECTION_HOTENDS // Enable thermal protection for all extruders
#define THERMAL_PROTECTION_BED // Enable thermal protection for the heated bed #define THERMAL_PROTECTION_BED // Enable thermal protection for the heated bed
#define THERMAL_PROTECTION_CHAMBER // Enable thermal protection for the heated chamber #define THERMAL_PROTECTION_CHAMBER // Enable thermal protection for the heated chamber
#define THERMAL_PROTECTION_COOLER // Enable thermal protection for the laser cooling
//=========================================================================== //===========================================================================
//============================= Mechanical Settings ========================= //============================= Mechanical Settings =========================
@@ -922,7 +937,6 @@
* or (with LCD_BED_LEVELING) the LCD controller. * or (with LCD_BED_LEVELING) the LCD controller.
*/ */
//#define PROBE_MANUALLY //#define PROBE_MANUALLY
//#define MANUAL_PROBE_START_Z 0.2
/** /**
* A Fix-Mounted Probe either doesn't deploy or needs manual deployment. * A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
@@ -1214,10 +1228,12 @@
// @section machine // @section machine
// The size of the print bed // The size of the print bed
#define X_BED_SIZE 227 #define X_BED_SIZE 227
#define Y_BED_SIZE 148 #define Y_BED_SIZE 148
// Travel limits (mm) after homing, corresponding to endstop positions. // Travel limits (mm) after homing, corresponding to endstop positions.
#define X_MIN_POS 0 #define X_MIN_POS 0
#define Y_MIN_POS 0 #define Y_MIN_POS 0
@@ -1268,7 +1284,7 @@
* RAMPS-based boards use SERVO3_PIN for the first runout sensor. * RAMPS-based boards use SERVO3_PIN for the first runout sensor.
* For other boards you may need to define FIL_RUNOUT_PIN, FIL_RUNOUT2_PIN, etc. * For other boards you may need to define FIL_RUNOUT_PIN, FIL_RUNOUT2_PIN, etc.
*/ */
//#define FILAMENT_RUNOUT_SENSOR #define FILAMENT_RUNOUT_SENSOR
#if ENABLED(FILAMENT_RUNOUT_SENSOR) #if ENABLED(FILAMENT_RUNOUT_SENSOR)
#define FIL_RUNOUT_ENABLED_DEFAULT true // Enable the sensor on startup. Override with M412 followed by M500. #define FIL_RUNOUT_ENABLED_DEFAULT true // Enable the sensor on startup. Override with M412 followed by M500.
#define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each. #define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
@@ -1279,6 +1295,8 @@
//#define WATCH_ALL_RUNOUT_SENSORS // Execute runout script on any triggering sensor, not only for the active extruder. //#define WATCH_ALL_RUNOUT_SENSORS // Execute runout script on any triggering sensor, not only for the active extruder.
// This is automatically enabled for MIXING_EXTRUDERs. // This is automatically enabled for MIXING_EXTRUDERs.
// Override individually if the runout sensors vary // Override individually if the runout sensors vary
//#define FIL_RUNOUT1_STATE LOW //#define FIL_RUNOUT1_STATE LOW
//#define FIL_RUNOUT1_PULLUP //#define FIL_RUNOUT1_PULLUP
@@ -1320,13 +1338,13 @@
// After a runout is detected, continue printing this length of filament // After a runout is detected, continue printing this length of filament
// before executing the runout script. Useful for a sensor at the end of // before executing the runout script. Useful for a sensor at the end of
// a feed tube. Requires 4 bytes SRAM per sensor, plus 4 bytes overhead. // a feed tube. Requires 4 bytes SRAM per sensor, plus 4 bytes overhead.
//#define FILAMENT_RUNOUT_DISTANCE_MM 25 #define FILAMENT_RUNOUT_DISTANCE_MM 7
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #ifdef FILAMENT_RUNOUT_DISTANCE_MM
// Enable this option to use an encoder disc that toggles the runout pin // Enable this option to use an encoder disc that toggles the runout pin
// as the filament moves. (Be sure to set FILAMENT_RUNOUT_DISTANCE_MM // as the filament moves. (Be sure to set FILAMENT_RUNOUT_DISTANCE_MM
// large enough to avoid false positives.) // large enough to avoid false positives.)
//#define FILAMENT_MOTION_SENSOR #define FILAMENT_MOTION_SENSOR
#endif #endif
#endif #endif
@@ -1398,6 +1416,11 @@
*/ */
//#define DEBUG_LEVELING_FEATURE //#define DEBUG_LEVELING_FEATURE
#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL, PROBE_MANUALLY)
// Set a height for the start of manual adjustment
#define MANUAL_PROBE_START_Z 0.2 // (mm) Comment out to use the last-measured height
#endif
#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL) #if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL)
// Gradually reduce leveling correction until a set height is reached, // Gradually reduce leveling correction until a set height is reached,
// at which point movement will be level to the machine's XY plane. // at which point movement will be level to the machine's XY plane.
@@ -1468,6 +1491,8 @@
#define GRID_MAX_POINTS_X 10 // Don't use more than 15 points per axis, implementation limited. #define GRID_MAX_POINTS_X 10 // Don't use more than 15 points per axis, implementation limited.
#define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X #define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X
//#define UBL_HILBERT_CURVE // Use Hilbert distribution for less travel when probing multiple points
#define UBL_MESH_EDIT_MOVES_Z // Sophisticated users prefer no movement of nozzle #define UBL_MESH_EDIT_MOVES_Z // Sophisticated users prefer no movement of nozzle
#define UBL_SAVE_ACTIVE_ON_M500 // Save the currently active mesh in the current slot on M500 #define UBL_SAVE_ACTIVE_ON_M500 // Save the currently active mesh in the current slot on M500
@@ -2171,6 +2196,11 @@
// //
//#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER //#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
//
// K.3D Full Graphic Smart Controller
//
//#define K3D_FULL_GRAPHIC_SMART_CONTROLLER
// //
// ReprapWorld Graphical LCD // ReprapWorld Graphical LCD
// https://reprapworld.com/?products_details&products_id/1218 // https://reprapworld.com/?products_details&products_id/1218
@@ -2308,7 +2338,7 @@
//#define OLED_PANEL_TINYBOY2 //#define OLED_PANEL_TINYBOY2
// //
// MKS OLED 1.3" 128×64 FULL GRAPHICS CONTROLLER // MKS OLED 1.3" 128×64 Full Graphics Controller
// https://reprap.org/wiki/MKS_12864OLED // https://reprap.org/wiki/MKS_12864OLED
// //
// Tiny, but very sharp OLED display // Tiny, but very sharp OLED display
@@ -2317,7 +2347,7 @@
//#define MKS_12864OLED_SSD1306 // Uses the SSD1306 controller //#define MKS_12864OLED_SSD1306 // Uses the SSD1306 controller
// //
// Zonestar OLED 128×64 FULL GRAPHICS CONTROLLER // Zonestar OLED 128×64 Full Graphics Controller
// //
//#define ZONESTAR_12864LCD // Graphical (DOGM) with ST7920 controller //#define ZONESTAR_12864LCD // Graphical (DOGM) with ST7920 controller
//#define ZONESTAR_12864OLED // 1.3" OLED with SH1106 controller (default) //#define ZONESTAR_12864OLED // 1.3" OLED with SH1106 controller (default)
@@ -2334,10 +2364,15 @@
//#define OVERLORD_OLED //#define OVERLORD_OLED
// //
// FYSETC OLED 2.42" 128×64 FULL GRAPHICS CONTROLLER with WS2812 RGB // FYSETC OLED 2.42" 128×64 Full Graphics Controller with WS2812 RGB
// Where to find : https://www.aliexpress.com/item/4000345255731.html // Where to find : https://www.aliexpress.com/item/4000345255731.html
//#define FYSETC_242_OLED_12864 // Uses the SSD1309 controller //#define FYSETC_242_OLED_12864 // Uses the SSD1309 controller
//
// K.3D SSD1309 OLED 2.42" 128×64 Full Graphics Controller
//
//#define K3D_242_OLED_CONTROLLER // Software SPI
//============================================================================= //=============================================================================
//========================== Extensible UI Displays =========================== //========================== Extensible UI Displays ===========================
//============================================================================= //=============================================================================
@@ -2350,7 +2385,11 @@
//#define DGUS_LCD_UI_ORIGIN //#define DGUS_LCD_UI_ORIGIN
//#define DGUS_LCD_UI_FYSETC //#define DGUS_LCD_UI_FYSETC
//#define DGUS_LCD_UI_HIPRECY //#define DGUS_LCD_UI_HIPRECY
//#define DGUS_LCD_UI_MKS //#define DGUS_LCD_UI_MKS
#if ENABLED(DGUS_LCD_UI_MKS)
#define USE_MKS_GREEN_UI
#endif
// //
// Touch-screen LCD for Malyan M200/M300 printers // Touch-screen LCD for Malyan M200/M300 printers
@@ -2376,6 +2415,14 @@
//#define ANYCUBIC_LCD_DEBUG //#define ANYCUBIC_LCD_DEBUG
#endif #endif
//
// 320x240 Nextion 2.8" serial TFT Resistive Touch Screen NX3224T028
//
//#define NEXTION_TFT
#if ENABLED(NEXTION_TFT)
#define LCD_SERIAL_PORT 1 // Default is 1 for Nextion
#endif
// //
// Third-party or vendor-customized controller interfaces. // Third-party or vendor-customized controller interfaces.
// Sources should be installed in 'src/lcd/extui'. // Sources should be installed in 'src/lcd/extui'.
@@ -2461,6 +2508,11 @@
// //
//#define ANET_ET5_TFT35 //#define ANET_ET5_TFT35
//
// 1024x600, 7", RGB Stock Display from BIQU-BX
//
//#define BIQU_BX_TFT70
// //
// Generic TFT with detailed options // Generic TFT with detailed options
// //
@@ -2615,7 +2667,7 @@
* more current than the Arduino 5V linear regulator can produce. * more current than the Arduino 5V linear regulator can produce.
* *** CAUTION *** * *** CAUTION ***
* *
* LED Type. Enable only one of the following two options. * LED Typ/FYe. Enable only one of the following two options.
*/ */
//#define RGB_LED //#define RGB_LED
//#define RGBW_LED //#define RGBW_LED
@@ -2631,19 +2683,19 @@
#define NEOPIXEL_LED #define NEOPIXEL_LED
#if ENABLED(NEOPIXEL_LED) #if ENABLED(NEOPIXEL_LED)
#define NEOPIXEL_TYPE NEO_GRB // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h) #define NEOPIXEL_TYPE NEO_GRB // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h)
// #define NEOPIXEL_PIN 4 // LED driving pin // #define NEOPIXEL_PIN 4 // LED driving pin
//#define NEOPIXEL2_TYPE NEOPIXEL_TYPE #define NEOPIXEL2_TYPE NEO_GRB
//#define NEOPIXEL2_PIN 5 #define NEOPIXEL2_PIN P1_24
#define NEOPIXEL_PIXELS 3 // Number of LEDs in the strip. (Longest strip when NEOPIXEL2_SEPARATE is disabled.) #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip. (Longest strip when NEOPIXEL2_SEPARATE is disabled.)
#define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once. #define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once.
#define NEOPIXEL_BRIGHTNESS 255 // Initial brightness (0-255) #define NEOPIXEL_BRIGHTNESS 255 // Initial brightness (0-255)
//#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup #define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup
// Support for second Adafruit NeoPixel LED driver controlled with M150 S1 ... // Support for second Adafruit NeoPixel LED driver controlled with M150 S1 ...
//#define NEOPIXEL2_SEPARATE #define NEOPIXEL2_SEPARATE
#if ENABLED(NEOPIXEL2_SEPARATE) #if ENABLED(NEOPIXEL2_SEPARATE)
#define NEOPIXEL2_PIXELS 15 // Number of LEDs in the second strip #define NEOPIXEL2_PIXELS 30 // Number of LEDs in the second strip
#define NEOPIXEL2_BRIGHTNESS 127 // Initial brightness (0-255) #define NEOPIXEL2_BRIGHTNESS 255 // Initial brightness (0-255)
#define NEOPIXEL2_STARTUP_TEST // Cycle through colors at startup #define NEOPIXEL2_STARTUP_TEST // Cycle through colors at startup
#else #else
//#define NEOPIXEL2_INSERIES // Default behavior is NeoPixel 2 in parallel //#define NEOPIXEL2_INSERIES // Default behavior is NeoPixel 2 in parallel

View File

@@ -113,6 +113,12 @@
#define CHAMBER_BETA 3950 // Beta value #define CHAMBER_BETA 3950 // Beta value
#endif #endif
#if TEMP_SENSOR_COOLER == 1000
#define COOLER_PULLUP_RESISTOR_OHMS 4700 // Pullup resistor
#define COOLER_RESISTANCE_25C_OHMS 100000 // Resistance at 25C
#define COOLER_BETA 3950 // Beta value
#endif
#if TEMP_SENSOR_PROBE == 1000 #if TEMP_SENSOR_PROBE == 1000
#define PROBE_PULLUP_RESISTOR_OHMS 4700 // Pullup resistor #define PROBE_PULLUP_RESISTOR_OHMS 4700 // Pullup resistor
#define PROBE_RESISTANCE_25C_OHMS 100000 // Resistance at 25C #define PROBE_RESISTANCE_25C_OHMS 100000 // Resistance at 25C
@@ -157,7 +163,7 @@
//#define CHAMBER_FAN // Enable a fan on the chamber //#define CHAMBER_FAN // Enable a fan on the chamber
#if ENABLED(CHAMBER_FAN) #if ENABLED(CHAMBER_FAN)
#define CHAMBER_FAN_MODE 2 // Fan control mode: 0=Static; 1=Linear increase when temp is higher than target; 2=V-shaped curve. #define CHAMBER_FAN_MODE 2 // Fan control mode: 0=Static; 1=Linear increase when temp is higher than target; 2=V-shaped curve; 3=similar to 1 but fan is always on.
#if CHAMBER_FAN_MODE == 0 #if CHAMBER_FAN_MODE == 0
#define CHAMBER_FAN_BASE 255 // Chamber fan PWM (0-255) #define CHAMBER_FAN_BASE 255 // Chamber fan PWM (0-255)
#elif CHAMBER_FAN_MODE == 1 #elif CHAMBER_FAN_MODE == 1
@@ -166,6 +172,9 @@
#elif CHAMBER_FAN_MODE == 2 #elif CHAMBER_FAN_MODE == 2
#define CHAMBER_FAN_BASE 128 // Minimum chamber fan PWM (0-255) #define CHAMBER_FAN_BASE 128 // Minimum chamber fan PWM (0-255)
#define CHAMBER_FAN_FACTOR 25 // PWM increase per °C difference from target #define CHAMBER_FAN_FACTOR 25 // PWM increase per °C difference from target
#elif CHAMBER_FAN_MODE == 3
#define CHAMBER_FAN_BASE 128 // Base chamber fan PWM (0-255)
#define CHAMBER_FAN_FACTOR 25 // PWM increase per °C above target
#endif #endif
#endif #endif
@@ -179,6 +188,39 @@
#endif #endif
#endif #endif
//
// Laser Cooler options
//
#if TEMP_SENSOR_COOLER
#define COOLER_MINTEMP 8 // (°C)
#define COOLER_MAXTEMP 26 // (°C)
#define COOLER_DEFAULT_TEMP 16 // (°C)
#define TEMP_COOLER_HYSTERESIS 1 // (°C) Temperature proximity considered "close enough" to the target
#define COOLER_PIN 8 // Laser cooler on/off pin used to control power to the cooling element e.g. TEC, External chiller via relay
#define COOLER_INVERTING false
#define TEMP_COOLER_PIN 15 // Laser/Cooler temperature sensor pin. ADC is required.
#define COOLER_FAN // Enable a fan on the cooler, Fan# 0,1,2,3 etc.
#define COOLER_FAN_INDEX 0 // FAN number 0, 1, 2 etc. e.g.
#if ENABLED(COOLER_FAN)
#define COOLER_FAN_BASE 100 // Base Cooler fan PWM (0-255); turns on when Cooler temperature is above the target
#define COOLER_FAN_FACTOR 25 // PWM increase per °C above target
#endif
#endif
//
// Laser Coolant Flow Meter
//
//#define LASER_COOLANT_FLOW_METER
#if ENABLED(LASER_COOLANT_FLOW_METER)
#define FLOWMETER_PIN 20 // Requires an external interrupt-enabled pin (e.g., RAMPS 2,3,18,19,20,21)
#define FLOWMETER_PPL 5880 // (pulses/liter) Flow meter pulses-per-liter on the input pin
#define FLOWMETER_INTERVAL 1000 // (ms) Flow rate calculation interval in milliseconds
#define FLOWMETER_SAFETY // Prevent running the laser without the minimum flow rate set below
#if ENABLED(FLOWMETER_SAFETY)
#define FLOWMETER_MIN_LITERS_PER_MINUTE 1.5 // (liters/min) Minimum flow required when enabled
#endif
#endif
/** /**
* Thermal Protection provides additional protection to your printer from damage * Thermal Protection provides additional protection to your printer from damage
* and fire. Marlin always includes safe min and max temperature ranges which * and fire. Marlin always includes safe min and max temperature ranges which
@@ -248,6 +290,20 @@
#define WATCH_CHAMBER_TEMP_INCREASE 2 // Degrees Celsius #define WATCH_CHAMBER_TEMP_INCREASE 2 // Degrees Celsius
#endif #endif
/**
* Thermal Protection parameters for the laser cooler.
*/
#if ENABLED(THERMAL_PROTECTION_COOLER)
#define THERMAL_PROTECTION_COOLER_PERIOD 10 // Seconds
#define THERMAL_PROTECTION_COOLER_HYSTERESIS 3 // Degrees Celsius
/**
* Laser cooling watch settings (M143/M193).
*/
#define WATCH_COOLER_TEMP_PERIOD 60 // Seconds
#define WATCH_COOLER_TEMP_INCREASE 3 // Degrees Celsius
#endif
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
// Add an experimental additional term to the heater power, proportional to the extrusion speed. // Add an experimental additional term to the heater power, proportional to the extrusion speed.
// A well-chosen Kc value should add just enough power to melt the increased material volume. // A well-chosen Kc value should add just enough power to melt the increased material volume.
@@ -493,11 +549,15 @@
#define E6_AUTO_FAN_PIN -1 #define E6_AUTO_FAN_PIN -1
#define E7_AUTO_FAN_PIN -1 #define E7_AUTO_FAN_PIN -1
#define CHAMBER_AUTO_FAN_PIN -1 #define CHAMBER_AUTO_FAN_PIN -1
#define COOLER_AUTO_FAN_PIN -1
#define COOLER_FAN_PIN -1
#define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_TEMPERATURE 50
#define EXTRUDER_AUTO_FAN_SPEED 255 // 255 == full speed #define EXTRUDER_AUTO_FAN_SPEED 255 // 255 == full speed
#define CHAMBER_AUTO_FAN_TEMPERATURE 30 #define CHAMBER_AUTO_FAN_TEMPERATURE 30
#define CHAMBER_AUTO_FAN_SPEED 255 #define CHAMBER_AUTO_FAN_SPEED 255
#define COOLER_AUTO_FAN_TEMPERATURE 18
#define COOLER_AUTO_FAN_SPEED 255
/** /**
* Part-Cooling Fan Multiplexer * Part-Cooling Fan Multiplexer
@@ -912,6 +972,9 @@
#define BACKLASH_DISTANCE_MM { 0, 0, 0 } // (mm) #define BACKLASH_DISTANCE_MM { 0, 0, 0 } // (mm)
#define BACKLASH_CORRECTION 0.0 // 0.0 = no correction; 1.0 = full correction #define BACKLASH_CORRECTION 0.0 // 0.0 = no correction; 1.0 = full correction
// Add steps for motor direction changes on CORE kinematics
//#define CORE_BACKLASH
// Set BACKLASH_SMOOTHING_MM to spread backlash correction over multiple segments // Set BACKLASH_SMOOTHING_MM to spread backlash correction over multiple segments
// to reduce print artifacts. (Enabling this is costly in memory and computation!) // to reduce print artifacts. (Enabling this is costly in memory and computation!)
//#define BACKLASH_SMOOTHING_MM 3 // (mm) //#define BACKLASH_SMOOTHING_MM 3 // (mm)
@@ -1420,6 +1483,15 @@
// Enable if SD detect is rendered useless (e.g., by using an SD extender) // Enable if SD detect is rendered useless (e.g., by using an SD extender)
//#define NO_SD_DETECT //#define NO_SD_DETECT
// Multiple volume support - EXPERIMENTAL.
//#define MULTI_VOLUME
#if ENABLED(MULTI_VOLUME)
#define VOLUME_SD_ONBOARD
#define VOLUME_USB_FLASH_DRIVE
#define DEFAULT_VOLUME SD_ONBOARD
#define DEFAULT_SHARED_VOLUME USB_FLASH_DRIVE
#endif
#endif // SDSUPPORT #endif // SDSUPPORT
/** /**
@@ -1497,6 +1569,8 @@
#define STATUS_BED_ANIM // Use a second bitmap to indicate bed heating #define STATUS_BED_ANIM // Use a second bitmap to indicate bed heating
#define STATUS_CHAMBER_ANIM // Use a second bitmap to indicate chamber heating #define STATUS_CHAMBER_ANIM // Use a second bitmap to indicate chamber heating
//#define STATUS_CUTTER_ANIM // Use a second bitmap to indicate spindle / laser active //#define STATUS_CUTTER_ANIM // Use a second bitmap to indicate spindle / laser active
//#define STATUS_COOLER_ANIM // Use a second bitmap to indicate laser cooling
//#define STATUS_FLOWMETER_ANIM // Use multiple bitmaps to indicate coolant flow
//#define STATUS_ALT_BED_BITMAP // Use the alternative bed bitmap //#define STATUS_ALT_BED_BITMAP // Use the alternative bed bitmap
//#define STATUS_ALT_FAN_BITMAP // Use the alternative fan bitmap //#define STATUS_ALT_FAN_BITMAP // Use the alternative fan bitmap
//#define STATUS_FAN_FRAMES 3 // :[0,1,2,3,4] Number of fan animation frames //#define STATUS_FAN_FRAMES 3 // :[0,1,2,3,4] Number of fan animation frames
@@ -1548,6 +1622,31 @@
#endif #endif
#endif // HAS_DGUS_LCD #endif // HAS_DGUS_LCD
//
// Additional options for AnyCubic Chiron TFT displays
//
#if ENABLED(ANYCUBIC_LCD_CHIRON)
// By default the type of panel is automatically detected.
// Enable one of these options if you know the panel type.
//#define CHIRON_TFT_STANDARD
//#define CHIRON_TFT_NEW
// Enable the longer Anycubic powerup startup tune
//#define AC_DEFAULT_STARTUP_TUNE
/**
* Display Folders
* By default the file browser lists all G-code files (including those in subfolders) in a flat list.
* Enable this option to display a hierarchical file browser.
*
* NOTES:
* - Without this option it helps to enable SDCARD_SORT_ALPHA so files are sorted before/after folders.
* - When used with the "new" panel, folder names will also have '.gcode' appended to their names.
* This hack is currently required to force the panel to show folders.
*/
#define AC_SD_FOLDER_VIEW
#endif
// //
// Specify additional languages for the UI. Default specified by LCD_LANGUAGE. // Specify additional languages for the UI. Default specified by LCD_LANGUAGE.
// //
@@ -2046,6 +2145,26 @@
*/ */
//#define EMERGENCY_PARSER //#define EMERGENCY_PARSER
/**
* Realtime Reporting (requires EMERGENCY_PARSER)
*
* - Report position and state of the machine (like Grbl).
* - Auto-report position during long moves.
* - Useful for CNC/LASER.
*
* Adds support for commands:
* S000 : Report State and Position while moving.
* P000 : Instant Pause / Hold while moving.
* R000 : Resume from Pause / Hold.
*
* - During Hold all Emergency Parser commands are available, as usual.
* - Enable NANODLP_Z_SYNC and NANODLP_ALL_AXIS for move command end-state reports.
*/
//#define REALTIME_REPORTING_COMMANDS
#if ENABLED(REALTIME_REPORTING_COMMANDS)
//#define FULL_REPORT_TO_HOST_FEATURE // Auto-report the machine status like Grbl CNC
#endif
// Bad Serial-connections can miss a received command by sending an 'ok' // Bad Serial-connections can miss a received command by sending an 'ok'
// Therefore some clients abort after 30 seconds in a timeout. // Therefore some clients abort after 30 seconds in a timeout.
// Some other clients start sending commands while receiving a 'wait'. // Some other clients start sending commands while receiving a 'wait'.
@@ -2120,6 +2239,12 @@
//#define EVENT_GCODE_AFTER_TOOLCHANGE "G12X" // Extra G-code to run after tool-change //#define EVENT_GCODE_AFTER_TOOLCHANGE "G12X" // Extra G-code to run after tool-change
#endif #endif
/**
* Tool Sensors detect when tools have been picked up or dropped.
* Requires the pins TOOL_SENSOR1_PIN, TOOL_SENSOR2_PIN, etc.
*/
//#define TOOL_SENSOR
/** /**
* Retract and prime filament on tool-change to reduce * Retract and prime filament on tool-change to reduce
* ooze and stringing and to get cleaner transitions. * ooze and stringing and to get cleaner transitions.
@@ -2596,6 +2721,7 @@
* Define your own with: * Define your own with:
* { <off_time[1..15]>, <hysteresis_end[-3..12]>, hysteresis_start[1..8] } * { <off_time[1..15]>, <hysteresis_end[-3..12]>, hysteresis_start[1..8] }
*/ */
#define CHOPPER_TIMING CHOPPER_DEFAULT_24V // All axes (override below) #define CHOPPER_TIMING CHOPPER_DEFAULT_24V // All axes (override below)
//#define CHOPPER_TIMING_X CHOPPER_DEFAULT_12V // For X Axes (override below) //#define CHOPPER_TIMING_X CHOPPER_DEFAULT_12V // For X Axes (override below)
//#define CHOPPER_TIMING_X2 CHOPPER_DEFAULT_12V //#define CHOPPER_TIMING_X2 CHOPPER_DEFAULT_12V
@@ -2614,6 +2740,25 @@
//#define CHOPPER_TIMING_E6 CHOPPER_DEFAULT_12V //#define CHOPPER_TIMING_E6 CHOPPER_DEFAULT_12V
//#define CHOPPER_TIMING_E7 CHOPPER_DEFAULT_12V //#define CHOPPER_TIMING_E7 CHOPPER_DEFAULT_12V
// #define CHOPPER_TIMING CHOPPER_DEFAULT_12V // All axes (override below)
//#define CHOPPER_TIMING_X CHOPPER_TIMING // For X Axes (override below)
//#define CHOPPER_TIMING_X2 CHOPPER_TIMING_X
//#define CHOPPER_TIMING_Y CHOPPER_TIMING // For Y Axes (override below)
//#define CHOPPER_TIMING_Y2 CHOPPER_TIMING_Y
//#define CHOPPER_TIMING_Z CHOPPER_TIMING // For Z Axes (override below)
//#define CHOPPER_TIMING_Z2 CHOPPER_TIMING_Z
//#define CHOPPER_TIMING_Z3 CHOPPER_TIMING_Z
//#define CHOPPER_TIMING_Z4 CHOPPER_TIMING_Z
//#define CHOPPER_TIMING_E CHOPPER_TIMING // For Extruders (override below)
//#define CHOPPER_TIMING_E1 CHOPPER_TIMING_E
//#define CHOPPER_TIMING_E2 CHOPPER_TIMING_E
//#define CHOPPER_TIMING_E3 CHOPPER_TIMING_E
//#define CHOPPER_TIMING_E4 CHOPPER_TIMING_E
//#define CHOPPER_TIMING_E5 CHOPPER_TIMING_E
//#define CHOPPER_TIMING_E6 CHOPPER_TIMING_E
//#define CHOPPER_TIMING_E7 CHOPPER_TIMING_E
/** /**
* Monitor Trinamic drivers * Monitor Trinamic drivers
* for error conditions like overtemperature and short to ground. * for error conditions like overtemperature and short to ground.
@@ -2685,20 +2830,20 @@
* Comment *_STALL_SENSITIVITY to disable sensorless homing for that axis. * Comment *_STALL_SENSITIVITY to disable sensorless homing for that axis.
*/ */
//#define SENSORLESS_HOMING // StallGuard capable drivers only #define SENSORLESS_HOMING // StallGuard capable drivers only
#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING) #if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING)
// TMC2209: 0...255. TMC2130: -64...63 // TMC2209: 0...255. TMC2130: -64...63
//#define X_STALL_SENSITIVITY 15 #define X_STALL_SENSITIVITY 15
// #define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY // #define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY
//#define Y_STALL_SENSITIVITY 15 #define Y_STALL_SENSITIVITY 15
// #define Y2_STALL_SENSITIVITY Y_STALL_SENSITIVITY // #define Y2_STALL_SENSITIVITY Y_STALL_SENSITIVITY
// #define Z_STALL_SENSITIVITY 6 // #define Z_STALL_SENSITIVITY 6
//#define Z2_STALL_SENSITIVITY Z_STALL_SENSITIVITY //#define Z2_STALL_SENSITIVITY Z_STALL_SENSITIVITY
//#define Z3_STALL_SENSITIVITY Z_STALL_SENSITIVITY //#define Z3_STALL_SENSITIVITY Z_STALL_SENSITIVITY
//#define Z4_STALL_SENSITIVITY Z_STALL_SENSITIVITY //#define Z4_STALL_SENSITIVITY Z_STALL_SENSITIVITY
//#define SPI_ENDSTOPS // TMC2130 only //#define SPI_ENDSTOPS // TMC2130 only
//#define IMPROVE_HOMING_RELIABILITY #define IMPROVE_HOMING_RELIABILITY
#endif #endif
/** /**
@@ -2721,7 +2866,7 @@
/** /**
* Enable M122 debugging command for TMC stepper drivers. * Enable M122 debugging command for TMC stepper drivers.
* M122 S0/1 will enable continous reporting. * M122 S0/1 will enable continuous reporting.
*/ */
#define TMC_DEBUG #define TMC_DEBUG
@@ -3042,6 +3187,12 @@
#define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC)
//#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11
#if ENABLED(AIR_EVACUATION)
#define AIR_EVACUATION_ACTIVE LOW // Set to "HIGH" if the on/off function is active HIGH
#define AIR_EVACUATION_PIN 42 // Override the default Cutter Vacuum or Laser Blower pin
#endif
//#define SPINDLE_SERVO // A servo converting an angle to spindle power //#define SPINDLE_SERVO // A servo converting an angle to spindle power
#ifdef SPINDLE_SERVO #ifdef SPINDLE_SERVO
#define SPINDLE_SERVO_NR 0 // Index of servo used for spindle control #define SPINDLE_SERVO_NR 0 // Index of servo used for spindle control
@@ -3177,6 +3328,18 @@
#endif #endif
#endif #endif
/**
* Synchronous Laser Control with M106/M107
*
* Marlin normally applies M106/M107 fan speeds at a time "soon after" processing
* a planner block. This is too inaccurate for a PWM/TTL laser attached to the fan
* header (as with some add-on laser kits). Enable this option to set fan/laser
* speeds with much more exact timing for improved print fidelity.
*
* NOTE: This option sacrifices some cooling fan speed options.
*/
//#define LASER_SYNCHRONOUS_M106_M107
/** /**
* Coolant Control * Coolant Control
* *
@@ -3236,13 +3399,27 @@
*/ */
//#define POWER_MONITOR_CURRENT // Monitor the system current //#define POWER_MONITOR_CURRENT // Monitor the system current
//#define POWER_MONITOR_VOLTAGE // Monitor the system voltage //#define POWER_MONITOR_VOLTAGE // Monitor the system voltage
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
#if ENABLED(POWER_MONITOR_CURRENT)
#define POWER_MONITOR_VOLTS_PER_AMP 0.05000 // Input voltage to the MCU analog pin per amp - DO NOT apply more than ADC_VREF! #define POWER_MONITOR_VOLTS_PER_AMP 0.05000 // Input voltage to the MCU analog pin per amp - DO NOT apply more than ADC_VREF!
#define POWER_MONITOR_CURRENT_OFFSET -1 // Offset value for current sensors with linear function output #define POWER_MONITOR_CURRENT_OFFSET 0 // Offset (in amps) applied to the calculated current
#define POWER_MONITOR_VOLTS_PER_VOLT 0.11786 // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
#define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display) #define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display)
#endif #endif
#if ENABLED(POWER_MONITOR_VOLTAGE)
#define POWER_MONITOR_VOLTS_PER_VOLT 0.077933 // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
#define POWER_MONITOR_VOLTAGE_OFFSET 0 // Offset (in volts) applied to the calculated voltage
#endif
/**
* Stepper Driver Anti-SNAFU Protection
*
* If the SAFE_POWER_PIN is defined for your board, Marlin will check
* that stepper drivers are properly plugged in before applying power.
* Disable protection if your stepper drivers don't support the feature.
*/
//#define DISABLE_DRIVER_SAFE_POWER_PROTECT
/** /**
* CNC Coordinate Systems * CNC Coordinate Systems
* *
@@ -3309,7 +3486,7 @@
//#define NO_WORKSPACE_OFFSETS //#define NO_WORKSPACE_OFFSETS
// Extra options for the M114 "Current Position" report // Extra options for the M114 "Current Position" report
//#define M114_DETAIL // Use 'M114` for details to check planner calculations #define M114_DETAIL // Use 'M114` for details to check planner calculations
//#define M114_REALTIME // Real current position based on forward kinematics //#define M114_REALTIME // Real current position based on forward kinematics
//#define M114_LEGACY // M114 used to synchronize on every call. Enable if needed. //#define M114_LEGACY // M114 used to synchronize on every call. Enable if needed.
@@ -3333,7 +3510,9 @@
//#define GCODE_QUOTED_STRINGS // Support for quoted string parameters //#define GCODE_QUOTED_STRINGS // Support for quoted string parameters
#endif #endif
//#define MEATPACK // Support for MeatPack G-code compression (https://github.com/scottmudge/OctoPrint-MeatPack) // Support for MeatPack G-code compression (https://github.com/scottmudge/OctoPrint-MeatPack)
//#define MEATPACK_ON_SERIAL_PORT_1
//#define MEATPACK_ON_SERIAL_PORT_2
//#define GCODE_CASE_INSENSITIVE // Accept G-code sent to the firmware in lowercase //#define GCODE_CASE_INSENSITIVE // Accept G-code sent to the firmware in lowercase
@@ -3373,6 +3552,71 @@
#define GCODE_MACROS_SLOT_SIZE 50 // Maximum length of a single macro #define GCODE_MACROS_SLOT_SIZE 50 // Maximum length of a single macro
#endif #endif
/**
* User-defined menu items to run custom G-code.
* Up to 25 may be defined, but the actual number is LCD-dependent.
*/
// Custom Menu: Main Menu
#define CUSTOM_MENU_MAIN
#if ENABLED(CUSTOM_MENU_MAIN)
#define CUSTOM_MENU_MAIN_TITLE "Custom Commands"
#define CUSTOM_MENU_MAIN_SCRIPT_DONE "M117 User Script Done"
#define CUSTOM_MENU_MAIN_SCRIPT_AUDIBLE_FEEDBACK
//#define CUSTOM_MENU_MAIN_SCRIPT_RETURN // Return to status screen after a script
#define CUSTOM_MENU_MAIN_ONLY_IDLE // Only show custom menu when the machine is idle
#define MAIN_MENU_ITEM_1_DESC "Home & UBL Info"
#define MAIN_MENU_ITEM_1_GCODE "G28\nG29 W"
//#define MAIN_MENU_ITEM_1_CONFIRM // Show a confirmation dialog before this action
#define MAIN_MENU_ITEM_2_DESC "Preheat for " PREHEAT_1_LABEL
#define MAIN_MENU_ITEM_2_GCODE "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND)
//#define MAIN_MENU_ITEM_2_CONFIRM
//#define MAIN_MENU_ITEM_3_DESC "Preheat for " PREHEAT_2_LABEL
//#define MAIN_MENU_ITEM_3_GCODE "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND)
//#define MAIN_MENU_ITEM_3_CONFIRM
//#define MAIN_MENU_ITEM_4_DESC "Heat Bed/Home/Level"
//#define MAIN_MENU_ITEM_4_GCODE "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29"
//#define MAIN_MENU_ITEM_4_CONFIRM
//#define MAIN_MENU_ITEM_5_DESC "Home & Info"
//#define MAIN_MENU_ITEM_5_GCODE "G28\nM503"
//#define MAIN_MENU_ITEM_5_CONFIRM
#endif
// Custom Menu: Configuration Menu
//#define CUSTOM_MENU_CONFIG
#if ENABLED(CUSTOM_MENU_CONFIG)
//#define CUSTOM_MENU_CONFIG_TITLE "Custom Commands"
#define CUSTOM_MENU_CONFIG_SCRIPT_DONE "M117 Wireless Script Done"
#define CUSTOM_MENU_CONFIG_SCRIPT_AUDIBLE_FEEDBACK
//#define CUSTOM_MENU_CONFIG_SCRIPT_RETURN // Return to status screen after a script
#define CUSTOM_MENU_CONFIG_ONLY_IDLE // Only show custom menu when the machine is idle
#define CONFIG_MENU_ITEM_1_DESC "Wifi ON"
#define CONFIG_MENU_ITEM_1_GCODE "M118 [ESP110] WIFI-STA pwd=12345678"
//#define CONFIG_MENU_ITEM_1_CONFIRM // Show a confirmation dialog before this action
#define CONFIG_MENU_ITEM_2_DESC "Bluetooth ON"
#define CONFIG_MENU_ITEM_2_GCODE "M118 [ESP110] BT pwd=12345678"
//#define CONFIG_MENU_ITEM_2_CONFIRM
//#define CONFIG_MENU_ITEM_3_DESC "Radio OFF"
//#define CONFIG_MENU_ITEM_3_GCODE "M118 [ESP110] OFF pwd=12345678"
//#define CONFIG_MENU_ITEM_3_CONFIRM
//#define CONFIG_MENU_ITEM_4_DESC "Wifi ????"
//#define CONFIG_MENU_ITEM_4_GCODE "M118 ????"
//#define CONFIG_MENU_ITEM_4_CONFIRM
//#define CONFIG_MENU_ITEM_5_DESC "Wifi ????"
//#define CONFIG_MENU_ITEM_5_GCODE "M118 ????"
//#define CONFIG_MENU_ITEM_5_CONFIRM
#endif
/** /**
* User-defined buttons to run custom G-code. * User-defined buttons to run custom G-code.
* Up to 25 may be defined. * Up to 25 may be defined.
@@ -3380,7 +3624,7 @@
//#define CUSTOM_USER_BUTTONS //#define CUSTOM_USER_BUTTONS
#if ENABLED(CUSTOM_USER_BUTTONS) #if ENABLED(CUSTOM_USER_BUTTONS)
//#define BUTTON1_PIN -1 //#define BUTTON1_PIN -1
#if PIN_EXISTS(BUTTON1_PIN) #if PIN_EXISTS(BUTTON1)
#define BUTTON1_HIT_STATE LOW // State of the triggered button. NC=LOW. NO=HIGH. #define BUTTON1_HIT_STATE LOW // State of the triggered button. NC=LOW. NO=HIGH.
#define BUTTON1_WHEN_PRINTING false // Button allowed to trigger during printing? #define BUTTON1_WHEN_PRINTING false // Button allowed to trigger during printing?
#define BUTTON1_GCODE "G28" #define BUTTON1_GCODE "G28"
@@ -3388,7 +3632,7 @@
#endif #endif
//#define BUTTON2_PIN -1 //#define BUTTON2_PIN -1
#if PIN_EXISTS(BUTTON2_PIN) #if PIN_EXISTS(BUTTON2)
#define BUTTON2_HIT_STATE LOW #define BUTTON2_HIT_STATE LOW
#define BUTTON2_WHEN_PRINTING false #define BUTTON2_WHEN_PRINTING false
#define BUTTON2_GCODE "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) #define BUTTON2_GCODE "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND)
@@ -3396,7 +3640,7 @@
#endif #endif
//#define BUTTON3_PIN -1 //#define BUTTON3_PIN -1
#if PIN_EXISTS(BUTTON3_PIN) #if PIN_EXISTS(BUTTON3)
#define BUTTON3_HIT_STATE LOW #define BUTTON3_HIT_STATE LOW
#define BUTTON3_WHEN_PRINTING false #define BUTTON3_WHEN_PRINTING false
#define BUTTON3_GCODE "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) #define BUTTON3_GCODE "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND)
@@ -3405,33 +3649,7 @@
#endif #endif
/** /**
* User-defined menu items to run custom G-code.
* Up to 25 may be defined, but the actual number is LCD-dependent.
*/
#define CUSTOM_USER_MENUS
#if ENABLED(CUSTOM_USER_MENUS)
//#define CUSTOM_USER_MENU_TITLE "Custom Commands"
#define USER_SCRIPT_DONE "M117 User Script Done"
#define USER_SCRIPT_AUDIBLE_FEEDBACK
//#define USER_SCRIPT_RETURN // Return to status screen after a script
#define USER_DESC_1 "Home & UBL Info"
#define USER_GCODE_1 "G28\nG29W"
#define USER_DESC_2 "Preheat for " PREHEAT_1_LABEL
#define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND)
#define USER_DESC_3 "Preheat for " PREHEAT_2_LABEL
#define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND)
#define USER_DESC_4 "Heat Bed/Home/Level"
#define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29"
#define USER_DESC_5 "Home & Info"
#define USER_GCODE_5 "G28\nM503"
#endif
/**
* Host Action Commands * Host Action Commands
* *
* Define host streamer action commands in compliance with the standard. * Define host streamer action commands in compliance with the standard.
@@ -3457,6 +3675,9 @@
* Implement M486 to allow Marlin to skip objects * Implement M486 to allow Marlin to skip objects
*/ */
//#define CANCEL_OBJECTS //#define CANCEL_OBJECTS
#if ENABLED(CANCEL_OBJECTS)
#define CANCEL_OBJECTS_REPORTING // Emit the current object as a status message
#endif
/** /**
* I2C position encoders for closed loop control. * I2C position encoders for closed loop control.
@@ -3614,14 +3835,13 @@
/** /**
* NanoDLP Sync support * NanoDLP Sync support
* *
* Add support for Synchronized Z moves when using with NanoDLP. G0/G1 axis moves will output "Z_move_comp" * Support for Synchronized Z moves when used with NanoDLP. G0/G1 axis moves will
* string to enable synchronization with DLP projector exposure. This change will allow to use * output a "Z_move_comp" string to enable synchronization with DLP projector exposure.
* [[WaitForDoneMessage]] instead of populating your gcode with M400 commands * This feature allows you to use [[WaitForDoneMessage]] instead of M400 commands.
*/ */
//#define NANODLP_Z_SYNC //#define NANODLP_Z_SYNC
#if ENABLED(NANODLP_Z_SYNC) #if ENABLED(NANODLP_Z_SYNC)
//#define NANODLP_ALL_AXIS // Enables "Z_move_comp" output on any axis move. //#define NANODLP_ALL_AXIS // Send a "Z_move_comp" report for any axis move (not just Z).
// Default behavior is limited to Z axis only.
#endif #endif
/** /**
@@ -3796,3 +4016,9 @@
* a crash from a remote location. Requires ~400 bytes of SRAM and 5Kb of flash. * a crash from a remote location. Requires ~400 bytes of SRAM and 5Kb of flash.
*/ */
//#define POSTMORTEM_DEBUGGING //#define POSTMORTEM_DEBUGGING
/**
* Software Reset options
*/
//#define SOFT_RESET_VIA_SERIAL // 'KILL' and '^X' commands will soft-reset the controller
//#define SOFT_RESET_ON_KILL // Use a digital button to soft-reset the controller after KILL

View File

@@ -219,7 +219,7 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1111)
else ifeq ($(HARDWARE_MOTHERBOARD),1112) else ifeq ($(HARDWARE_MOTHERBOARD),1112)
# MKS GEN L # MKS GEN L
else ifeq ($(HARDWARE_MOTHERBOARD),1113) else ifeq ($(HARDWARE_MOTHERBOARD),1113)
# zrib V2.0 control board (Chinese knock off RAMPS replica) # zrib V2.0 control board (Chinese RAMPS replica)
else ifeq ($(HARDWARE_MOTHERBOARD),1114) else ifeq ($(HARDWARE_MOTHERBOARD),1114)
# BigTreeTech or BIQU KFB2.0 # BigTreeTech or BIQU KFB2.0
else ifeq ($(HARDWARE_MOTHERBOARD),1115) else ifeq ($(HARDWARE_MOTHERBOARD),1115)
@@ -993,5 +993,5 @@ clean:
.PHONY: all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter .PHONY: all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter
# Automaticaly include the dependency files created by gcc # Automatically include the dependency files created by gcc
-include ${patsubst %.o, %.d, ${OBJ}} -include ${patsubst %.o, %.d, ${OBJ}}

View File

@@ -25,7 +25,7 @@
#include "HAL.h" #include "HAL.h"
#ifdef USBCON #ifdef USBCON
DefaultSerial MSerial(false, Serial); DefaultSerial1 MSerial0(false, Serial);
#ifdef BLUETOOTH #ifdef BLUETOOTH
BTSerial btSerial(false, bluetoothSerial); BTSerial btSerial(false, bluetoothSerial);
#endif #endif
@@ -58,6 +58,15 @@ void HAL_init() {
#endif #endif
} }
void HAL_reboot() {
#if ENABLED(USE_WATCHDOG)
while (1) { /* run out the watchdog */ }
#else
void (*resetFunc)() = 0; // Declare resetFunc() at address 0
resetFunc(); // Jump to address 0
#endif
}
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
#include "../../sd/SdFatUtil.h" #include "../../sd/SdFatUtil.h"

View File

@@ -83,38 +83,38 @@ typedef int8_t pin_t;
// Serial ports // Serial ports
#ifdef USBCON #ifdef USBCON
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
extern DefaultSerial MSerial; extern DefaultSerial1 MSerial0;
#ifdef BLUETOOTH #ifdef BLUETOOTH
typedef ForwardSerial0Type< decltype(bluetoothSerial) > BTSerial; typedef ForwardSerial1Class< decltype(bluetoothSerial) > BTSerial;
extern BTSerial btSerial; extern BTSerial btSerial;
#endif #endif
#define MYSERIAL0 TERN(BLUETOOTH, btSerial, MSerial) #define MYSERIAL1 TERN(BLUETOOTH, btSerial, MSerial0)
#else #else
#if !WITHIN(SERIAL_PORT, -1, 3) #if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#define MYSERIAL0 customizedSerial1 #define MYSERIAL1 customizedSerial1
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3) #if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT_2 must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#define MYSERIAL1 customizedSerial2 #define MYSERIAL2 customizedSerial2
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT #ifdef MMU2_SERIAL_PORT
#if !WITHIN(MMU2_SERIAL_PORT, -1, 3) #if !WITHIN(MMU2_SERIAL_PORT, -1, 3)
#error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "MMU2_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#define MMU2_SERIAL mmuSerial #define MMU2_SERIAL mmuSerial
#endif #endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if !WITHIN(LCD_SERIAL_PORT, -1, 3) #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#define LCD_SERIAL lcdSerial #define LCD_SERIAL lcdSerial
#if HAS_DGUS_LCD #if HAS_DGUS_LCD
@@ -135,7 +135,7 @@ void HAL_init();
inline void HAL_clear_reset_source() { MCUSR = 0; } inline void HAL_clear_reset_source() { MCUSR = 0; }
inline uint8_t HAL_get_reset_source() { return MCUSR; } inline uint8_t HAL_get_reset_source() { return MCUSR; }
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
#if GCC_VERSION <= 50000 #if GCC_VERSION <= 50000
#pragma GCC diagnostic push #pragma GCC diagnostic push

View File

@@ -88,7 +88,7 @@ void spiBegin() {
} }
/** SPI read data */ /** SPI read data */
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
if (nbyte-- == 0) return; if (nbyte-- == 0) return;
SPDR = 0xFF; SPDR = 0xFF;
for (uint16_t i = 0; i < nbyte; i++) { for (uint16_t i = 0; i < nbyte; i++) {
@@ -107,7 +107,7 @@ void spiBegin() {
} }
/** SPI send block */ /** SPI send block */
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPDR = token; SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) { for (uint16_t i = 0; i < 512; i += 2) {
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ } while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
@@ -215,7 +215,7 @@ void spiBegin() {
} }
// Soft SPI read data // Soft SPI read data
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
for (uint16_t i = 0; i < nbyte; i++) for (uint16_t i = 0; i < nbyte; i++)
buf[i] = spiRec(); buf[i] = spiRec();
} }
@@ -242,7 +242,7 @@ void spiBegin() {
} }
// Soft SPI send block // Soft SPI send block
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
spiSend(token); spiSend(token);
for (uint16_t i = 0; i < 512; i++) for (uint16_t i = 0; i < 512; i++)
spiSend(buf[i]); spiSend(buf[i]);

View File

@@ -454,7 +454,7 @@ void MarlinSerial<Cfg>::flush() {
} }
template<typename Cfg> template<typename Cfg>
size_t MarlinSerial<Cfg>::write(const uint8_t c) { void MarlinSerial<Cfg>::write(const uint8_t c) {
if (Cfg::TX_SIZE == 0) { if (Cfg::TX_SIZE == 0) {
_written = true; _written = true;
@@ -480,7 +480,7 @@ size_t MarlinSerial<Cfg>::write(const uint8_t c) {
// location". This makes sure flush() won't return until the bytes // location". This makes sure flush() won't return until the bytes
// actually got written // actually got written
B_TXC = 1; B_TXC = 1;
return 1; return;
} }
const uint8_t i = (tx_buffer.head + 1) & (Cfg::TX_SIZE - 1); const uint8_t i = (tx_buffer.head + 1) & (Cfg::TX_SIZE - 1);
@@ -510,7 +510,6 @@ size_t MarlinSerial<Cfg>::write(const uint8_t c) {
// Enable TX ISR - Non atomic, but it will eventually enable TX ISR // Enable TX ISR - Non atomic, but it will eventually enable TX ISR
B_UDRIE = 1; B_UDRIE = 1;
} }
return 1;
} }
template<typename Cfg> template<typename Cfg>

View File

@@ -210,7 +210,7 @@
static int read(); static int read();
static void flush(); static void flush();
static ring_buffer_pos_t available(); static ring_buffer_pos_t available();
static size_t write(const uint8_t c); static void write(const uint8_t c);
static void flushTX(); static void flushTX();
#if HAS_DGUS_LCD #if HAS_DGUS_LCD
static ring_buffer_pos_t get_tx_buffer_free(); static ring_buffer_pos_t get_tx_buffer_free();
@@ -238,11 +238,11 @@
static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED); static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED);
}; };
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT; typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
extern MSerialT customizedSerial1; extern MSerialT customizedSerial1;
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2; typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
extern MSerialT2 customizedSerial2; extern MSerialT2 customizedSerial2;
#endif #endif
@@ -252,17 +252,17 @@
template <uint8_t serial> template <uint8_t serial>
struct MMU2SerialCfg { struct MMU2SerialCfg {
static constexpr int PORT = serial; static constexpr int PORT = serial;
static constexpr unsigned int RX_SIZE = 32;
static constexpr unsigned int TX_SIZE = 32;
static constexpr bool XONOFF = false; static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = false; static constexpr bool EMERGENCYPARSER = false;
static constexpr bool DROPPED_RX = false; static constexpr bool DROPPED_RX = false;
static constexpr bool RX_FRAMING_ERRORS = false; static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false; static constexpr bool MAX_RX_QUEUED = false;
static constexpr unsigned int RX_SIZE = 32;
static constexpr unsigned int TX_SIZE = 32;
static constexpr bool RX_OVERRUNS = false; static constexpr bool RX_OVERRUNS = false;
}; };
typedef Serial0Type< MarlinSerial< MMU2SerialCfg<MMU2_SERIAL_PORT> > > MSerialT3; typedef Serial1Class< MarlinSerial< MMU2SerialCfg<MMU2_SERIAL_PORT> > > MSerialT3;
extern MSerialT3 mmuSerial; extern MSerialT3 mmuSerial;
#endif #endif
@@ -271,33 +271,22 @@
template <uint8_t serial> template <uint8_t serial>
struct LCDSerialCfg { struct LCDSerialCfg {
static constexpr int PORT = serial; static constexpr int PORT = serial;
static constexpr unsigned int RX_SIZE = TERN(HAS_DGUS_LCD, DGUS_RX_BUFFER_SIZE, 64);
static constexpr unsigned int TX_SIZE = TERN(HAS_DGUS_LCD, DGUS_TX_BUFFER_SIZE, 128);
static constexpr bool XONOFF = false; static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER); static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER);
static constexpr bool DROPPED_RX = false; static constexpr bool DROPPED_RX = false;
static constexpr bool RX_FRAMING_ERRORS = false; static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false; static constexpr bool MAX_RX_QUEUED = false;
#if HAS_DGUS_LCD static constexpr bool RX_OVERRUNS = BOTH(HAS_DGUS_LCD, SERIAL_STATS_RX_BUFFER_OVERRUNS);
static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE;
static constexpr bool RX_OVERRUNS = ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS);
#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
static constexpr unsigned int RX_SIZE = 64;
static constexpr unsigned int TX_SIZE = 128;
static constexpr bool RX_OVERRUNS = false;
#else
static constexpr unsigned int RX_SIZE = 64;
static constexpr unsigned int TX_SIZE = 128;
static constexpr bool RX_OVERRUNS = false
#endif
}; };
typedef Serial1Class< MarlinSerial< LCDSerialCfg<LCD_SERIAL_PORT> > > MSerialT4;
typedef Serial0Type< MarlinSerial< LCDSerialCfg<LCD_SERIAL_PORT> > > MSerialT4;
extern MSerialT4 lcdSerial; extern MSerialT4 lcdSerial;
#endif #endif
// Use the UART for Bluetooth in AT90USB configurations // Use the UART for Bluetooth in AT90USB configurations
#if defined(USBCON) && ENABLED(BLUETOOTH) #if defined(USBCON) && ENABLED(BLUETOOTH)
typedef Serial0Type<HardwareSerial> MSerialT5; typedef Serial1Class<HardwareSerial> MSerialT5;
extern MSerialT5 bluetoothSerial; extern MSerialT5 bluetoothSerial;
#endif #endif

View File

@@ -40,13 +40,13 @@ bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -241,7 +241,7 @@ uint8_t extDigitalRead(const int8_t pin) {
* *
* DC values -1.0 to 1.0. Negative duty cycle inverts the pulse. * DC values -1.0 to 1.0. Negative duty cycle inverts the pulse.
*/ */
uint16_t set_pwm_frequency_hz(const float &hz, const float dca, const float dcb, const float dcc) { uint16_t set_pwm_frequency_hz(const_float_t hz, const float dca, const float dcb, const float dcc) {
float count = 0; float count = 0;
if (hz > 0 && (dca || dcb || dcc)) { if (hz > 0 && (dca || dcb || dcc)) {
count = float(F_CPU) / hz; // 1x prescaler, TOP for 16MHz base freq. count = float(F_CPU) / hz; // 1x prescaler, TOP for 16MHz base freq.

View File

@@ -285,7 +285,7 @@ enum ClockSource2 : char {
*/ */
// Determine which harware PWMs are already in use // Determine which harware PWMs are already in use
#define _PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == E6_AUTO_FAN_PIN || P == E7_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN) #define _PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == E6_AUTO_FAN_PIN || P == E7_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN || P == COOLER_AUTO_FAN_PIN)
#if PIN_EXISTS(CONTROLLER_FAN) #if PIN_EXISTS(CONTROLLER_FAN)
#define PWM_CHK_FAN_B(P) (_PWM_CHK_FAN_B(P) || P == CONTROLLER_FAN_PIN) #define PWM_CHK_FAN_B(P) (_PWM_CHK_FAN_B(P) || P == CONTROLLER_FAN_PIN)
#else #else

View File

@@ -77,6 +77,8 @@ uint8_t HAL_get_reset_source() {
} }
} }
void HAL_reboot() { rstc_start_software_reset(RSTC); }
void _delay_ms(const int delay_ms) { void _delay_ms(const int delay_ms) {
// Todo: port for Due? // Todo: port for Due?
delay(delay_ms); delay(delay_ms);
@@ -106,17 +108,17 @@ uint16_t HAL_adc_get_result() {
} }
// Forward the default serial ports // Forward the default serial ports
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
DefaultSerial MSerial(false, Serial); DefaultSerial1 MSerial0(false, Serial);
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
DefaultSerial1 MSerial1(false, Serial1); DefaultSerial2 MSerial1(false, Serial1);
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
DefaultSerial2 MSerial2(false, Serial2); DefaultSerial3 MSerial2(false, Serial2);
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
DefaultSerial3 MSerial3(false, Serial3); DefaultSerial4 MSerial3(false, Serial3);
#endif #endif
#endif // ARDUINO_ARCH_SAM #endif // ARDUINO_ARCH_SAM

View File

@@ -38,35 +38,34 @@
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1; typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2; typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3; typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
extern DefaultSerial MSerial; extern DefaultSerial1 MSerial0;
extern DefaultSerial1 MSerial1; extern DefaultSerial2 MSerial1;
extern DefaultSerial2 MSerial2; extern DefaultSerial3 MSerial2;
extern DefaultSerial3 MSerial3; extern DefaultSerial4 MSerial3;
#define _MSERIAL(X) MSerial##X #define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
// Define MYSERIAL0/1 before MarlinSerial includes! // Define MYSERIAL1/2 before MarlinSerial includes!
#if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER) #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
#define MYSERIAL0 customizedSerial1 #define MYSERIAL1 customizedSerial1
#elif WITHIN(SERIAL_PORT, 0, 3) #elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else #else
#error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "The required SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
#define MYSERIAL1 customizedSerial2 #define MYSERIAL2 customizedSerial2
#elif WITHIN(SERIAL_PORT_2, 0, 3) #elif WITHIN(SERIAL_PORT_2, 0, 3)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else #else
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT_2 must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
@@ -74,7 +73,7 @@ extern DefaultSerial3 MSerial3;
#if WITHIN(MMU2_SERIAL_PORT, 0, 3) #if WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT) #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else #else
#error "MMU2_SERIAL_PORT must be from 0 to 3. Please update your configuration." #error "MMU2_SERIAL_PORT must be from 0 to 3."
#endif #endif
#endif #endif
@@ -84,7 +83,7 @@ extern DefaultSerial3 MSerial3;
#elif WITHIN(LCD_SERIAL_PORT, 0, 3) #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
@@ -114,7 +113,7 @@ void sei(); // Enable interrupts
void HAL_clear_reset_source(); // clear reset reason void HAL_clear_reset_source(); // clear reset reason
uint8_t HAL_get_reset_source(); // get reset reason uint8_t HAL_get_reset_source(); // get reset reason
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
// //
// ADC // ADC

View File

@@ -56,8 +56,8 @@
#pragma GCC optimize (3) #pragma GCC optimize (3)
typedef uint8_t (*pfnSpiTransfer)(uint8_t b); typedef uint8_t (*pfnSpiTransfer)(uint8_t b);
typedef void (*pfnSpiRxBlock)(uint8_t* buf, uint32_t nbyte); typedef void (*pfnSpiRxBlock)(uint8_t *buf, uint32_t nbyte);
typedef void (*pfnSpiTxBlock)(const uint8_t* buf, uint32_t nbyte); typedef void (*pfnSpiTxBlock)(const uint8_t *buf, uint32_t nbyte);
/* ---------------- Macros to be able to access definitions from asm */ /* ---------------- Macros to be able to access definitions from asm */
#define _PORT(IO) DIO ## IO ## _WPORT #define _PORT(IO) DIO ## IO ## _WPORT
@@ -270,7 +270,7 @@
static pfnSpiTransfer spiTransferTx = (pfnSpiTransfer)spiTransferX; static pfnSpiTransfer spiTransferTx = (pfnSpiTransfer)spiTransferX;
// Block transfers run at ~8 .. ~10Mhz - Tx version (Rx data discarded) // Block transfers run at ~8 .. ~10Mhz - Tx version (Rx data discarded)
static void spiTxBlock0(const uint8_t* ptr, uint32_t todo) { static void spiTxBlock0(const uint8_t *ptr, uint32_t todo) {
uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(SD_MOSI_PIN)) + 0x30; /* SODR of port */ uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(SD_MOSI_PIN)) + 0x30; /* SODR of port */
uint32_t MOSI_MASK = PIN_MASK(SD_MOSI_PIN); uint32_t MOSI_MASK = PIN_MASK(SD_MOSI_PIN);
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */ uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */
@@ -349,7 +349,7 @@
); );
} }
static void spiRxBlock0(uint8_t* ptr, uint32_t todo) { static void spiRxBlock0(uint8_t *ptr, uint32_t todo) {
uint32_t bin = 0; uint32_t bin = 0;
uint32_t work = 0; uint32_t work = 0;
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(SD_MISO_PIN))+0x3C, PIN_SHIFT(SD_MISO_PIN)); /* PDSR of port in bitband area */ uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(SD_MISO_PIN))+0x3C, PIN_SHIFT(SD_MISO_PIN)); /* PDSR of port in bitband area */
@@ -425,13 +425,13 @@
); );
} }
static void spiTxBlockX(const uint8_t* buf, uint32_t todo) { static void spiTxBlockX(const uint8_t *buf, uint32_t todo) {
do { do {
(void)spiTransferTx(*buf++); (void)spiTransferTx(*buf++);
} while (--todo); } while (--todo);
} }
static void spiRxBlockX(uint8_t* buf, uint32_t todo) { static void spiRxBlockX(uint8_t *buf, uint32_t todo) {
do { do {
*buf++ = spiTransferRx(0xFF); *buf++ = spiTransferRx(0xFF);
} while (--todo); } while (--todo);
@@ -463,7 +463,7 @@
return b; return b;
} }
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
if (nbyte) { if (nbyte) {
_SS_WRITE(LOW); _SS_WRITE(LOW);
WRITE(SD_MOSI_PIN, HIGH); // Output 1s 1 WRITE(SD_MOSI_PIN, HIGH); // Output 1s 1
@@ -478,7 +478,7 @@
_SS_WRITE(HIGH); _SS_WRITE(HIGH);
} }
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
_SS_WRITE(LOW); _SS_WRITE(LOW);
(void)spiTransferTx(token); (void)spiTransferTx(token);
spiTxBlock(buf, 512); spiTxBlock(buf, 512);
@@ -645,7 +645,7 @@
} }
// Read from SPI into buffer // Read from SPI into buffer
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
if (!nbyte) return; if (!nbyte) return;
--nbyte; --nbyte;
for (int i = 0; i < nbyte; i++) { for (int i = 0; i < nbyte; i++) {
@@ -668,7 +668,7 @@
//DELAY_US(1U); //DELAY_US(1U);
} }
void spiSend(const uint8_t* buf, size_t nbyte) { void spiSend(const uint8_t *buf, size_t nbyte) {
if (!nbyte) return; if (!nbyte) return;
--nbyte; --nbyte;
for (size_t i = 0; i < nbyte; i++) { for (size_t i = 0; i < nbyte; i++) {
@@ -689,7 +689,7 @@
FLUSH_RX(); FLUSH_RX();
} }
void spiSend(uint32_t chan, const uint8_t* buf, size_t nbyte) { void spiSend(uint32_t chan, const uint8_t *buf, size_t nbyte) {
if (!nbyte) return; if (!nbyte) return;
--nbyte; --nbyte;
for (size_t i = 0; i < nbyte; i++) { for (size_t i = 0; i < nbyte; i++) {
@@ -702,7 +702,7 @@
} }
// Write from buffer to SPI // Write from buffer to SPI
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPI0->SPI_TDR = (uint32_t)token | SPI_PCS(SPI_CHAN); SPI0->SPI_TDR = (uint32_t)token | SPI_PCS(SPI_CHAN);
WHILE_TX(0); WHILE_TX(0);
//WHILE_RX(0); //WHILE_RX(0);
@@ -801,19 +801,19 @@
uint8_t spiRec() { return (uint8_t)spiTransfer(0xFF); } uint8_t spiRec() { return (uint8_t)spiTransfer(0xFF); }
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
for (int i = 0; i < nbyte; i++) for (int i = 0; i < nbyte; i++)
buf[i] = spiTransfer(0xFF); buf[i] = spiTransfer(0xFF);
} }
void spiSend(uint8_t data) { spiTransfer(data); } void spiSend(uint8_t data) { spiTransfer(data); }
void spiSend(const uint8_t* buf, size_t nbyte) { void spiSend(const uint8_t *buf, size_t nbyte) {
for (uint16_t i = 0; i < nbyte; i++) for (uint16_t i = 0; i < nbyte; i++)
spiTransfer(buf[i]); spiTransfer(buf[i]);
} }
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
spiTransfer(token); spiTransfer(token);
for (uint16_t i = 0; i < 512; i++) for (uint16_t i = 0; i < 512; i++)
spiTransfer(buf[i]); spiTransfer(buf[i]);

View File

@@ -476,7 +476,7 @@ void MarlinSerial<Cfg>::flushTX() {
// If not using the USB port as serial port // If not using the USB port as serial port
#if SERIAL_PORT >= 0 #if defined(SERIAL_PORT) && SERIAL_PORT >= 0
template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT> >; template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT> >;
MSerialT customizedSerial1(MarlinSerialCfg<SERIAL_PORT>::EMERGENCYPARSER); MSerialT customizedSerial1(MarlinSerialCfg<SERIAL_PORT>::EMERGENCYPARSER);
#endif #endif

View File

@@ -140,12 +140,12 @@ struct MarlinSerialCfg {
static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED); static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED);
}; };
#if SERIAL_PORT >= 0 #if defined(SERIAL_PORT) && SERIAL_PORT >= 0
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT; typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
extern MSerialT customizedSerial1; extern MSerialT customizedSerial1;
#endif #endif
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 #if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2; typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
extern MSerialT2 customizedSerial2; extern MSerialT2 customizedSerial2;
#endif #endif

View File

@@ -50,7 +50,7 @@ struct MarlinSerialUSB {
FORCE_INLINE int rxMaxEnqueued() { return 0; } FORCE_INLINE int rxMaxEnqueued() { return 0; }
#endif #endif
}; };
typedef Serial0Type<MarlinSerialUSB> MSerialT; typedef Serial1Class<MarlinSerialUSB> MSerialT;
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
extern MSerialT customizedSerial1; extern MSerialT customizedSerial1;

View File

@@ -135,11 +135,11 @@ static uint8_t buffer[256] = {0}, // The RAM buffer to accumulate writes
#define DEBUG_OUT ENABLED(EE_EMU_DEBUG) #define DEBUG_OUT ENABLED(EE_EMU_DEBUG)
#include "../../core/debug_out.h" #include "../../core/debug_out.h"
static void ee_Dump(const int page, const void* data) { static void ee_Dump(const int page, const void *data) {
#ifdef EE_EMU_DEBUG #ifdef EE_EMU_DEBUG
const uint8_t* c = (const uint8_t*) data; const uint8_t *c = (const uint8_t*) data;
char buffer[80]; char buffer[80];
sprintf_P(buffer, PSTR("Page: %d (0x%04x)\n"), page, page); sprintf_P(buffer, PSTR("Page: %d (0x%04x)\n"), page, page);
@@ -181,7 +181,7 @@ static void ee_Dump(const int page, const void* data) {
* @param data (pointer to the data buffer) * @param data (pointer to the data buffer)
*/ */
__attribute__ ((long_call, section (".ramfunc"))) __attribute__ ((long_call, section (".ramfunc")))
static bool ee_PageWrite(uint16_t page, const void* data) { static bool ee_PageWrite(uint16_t page, const void *data) {
uint16_t i; uint16_t i;
uint32_t addrflash = uint32_t(getFlashStorage(page)); uint32_t addrflash = uint32_t(getFlashStorage(page));
@@ -293,8 +293,8 @@ static bool ee_PageWrite(uint16_t page, const void* data) {
ee_Dump(-page, data); ee_Dump(-page, data);
// Calculate count of changed bits // Calculate count of changed bits
uint32_t* p1 = (uint32_t*)addrflash; uint32_t *p1 = (uint32_t*)addrflash;
uint32_t* p2 = (uint32_t*)data; uint32_t *p2 = (uint32_t*)data;
int count = 0; int count = 0;
for (i =0; i<PageSize >> 2; i++) { for (i =0; i<PageSize >> 2; i++) {
if (p1[i] != p2[i]) { if (p1[i] != p2[i]) {
@@ -470,7 +470,7 @@ static uint8_t ee_Read(uint32_t address, bool excludeRAMBuffer=false) {
for (int page = curPage - 1; page >= 0; --page) { for (int page = curPage - 1; page >= 0; --page) {
// Get a pointer to the flash page // Get a pointer to the flash page
uint8_t* pflash = (uint8_t*)getFlashStorage(page + curGroup * PagesPerGroup); uint8_t *pflash = (uint8_t*)getFlashStorage(page + curGroup * PagesPerGroup);
uint16_t i = 0; uint16_t i = 0;
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */ while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
@@ -550,7 +550,7 @@ static uint32_t ee_GetAddrRange(uint32_t address, bool excludeRAMBuffer=false) {
for (int page = curPage - 1; page >= 0; --page) { for (int page = curPage - 1; page >= 0; --page) {
// Get a pointer to the flash page // Get a pointer to the flash page
uint8_t* pflash = (uint8_t*)getFlashStorage(page + curGroup * PagesPerGroup); uint8_t *pflash = (uint8_t*)getFlashStorage(page + curGroup * PagesPerGroup);
uint16_t i = 0; uint16_t i = 0;
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */ while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
@@ -589,7 +589,7 @@ static uint32_t ee_GetAddrRange(uint32_t address, bool excludeRAMBuffer=false) {
} }
static bool ee_IsPageClean(int page) { static bool ee_IsPageClean(int page) {
uint32_t* pflash = (uint32_t*) getFlashStorage(page); uint32_t *pflash = (uint32_t*) getFlashStorage(page);
for (uint16_t i = 0; i < (PageSize >> 2); ++i) for (uint16_t i = 0; i < (PageSize >> 2); ++i)
if (*pflash++ != 0xFFFFFFFF) return false; if (*pflash++ != 0xFFFFFFFF) return false;
return true; return true;
@@ -599,7 +599,7 @@ static bool ee_Flush(uint32_t overrideAddress = 0xFFFFFFFF, uint8_t overrideData
// Check if RAM buffer has something to be written // Check if RAM buffer has something to be written
bool isEmpty = true; bool isEmpty = true;
uint32_t* p = (uint32_t*) &buffer[0]; uint32_t *p = (uint32_t*) &buffer[0];
for (uint16_t j = 0; j < (PageSize >> 2); j++) { for (uint16_t j = 0; j < (PageSize >> 2); j++) {
if (*p++ != 0xFFFFFFFF) { if (*p++ != 0xFFFFFFFF) {
isEmpty = false; isEmpty = false;
@@ -976,14 +976,13 @@ bool PersistentStore::access_start() { ee_Init(); return true; }
bool PersistentStore::access_finish() { ee_Flush(); return true; } bool PersistentStore::access_finish() { ee_Flush(); return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != ee_Read(uint32_t(p))) {
ee_Write(uint32_t(p), v); ee_Write(uint32_t(p), v);
delay(2); if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (ee_Read(uint32_t(p)) != v) { if (ee_Read(uint32_t(p)) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -42,14 +42,13 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
delay(2); if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -32,7 +32,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready() {
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) { Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted()) if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT; return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1; *nb_sector = card.diskIODriver()->cardSize() - 1;
return CTRL_GOOD; return CTRL_GOOD;
} }
@@ -74,24 +74,24 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
#endif #endif
// Start reading // Start reading
if (!card.getSd2Card().readStart(addr)) if (!card.diskIODriver()->readStart(addr))
return CTRL_FAIL; return CTRL_FAIL;
// For each specified sector // For each specified sector
while (nb_sector--) { while (nb_sector--) {
// Read a sector // Read a sector
card.getSd2Card().readData(sector_buf); card.diskIODriver()->readData(sector_buf);
// RAM -> USB // RAM -> USB
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) { if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().readStop(); card.diskIODriver()->readStop();
return CTRL_FAIL; return CTRL_FAIL;
} }
} }
// Stop reading // Stop reading
card.getSd2Card().readStop(); card.diskIODriver()->readStop();
// Done // Done
return CTRL_GOOD; return CTRL_GOOD;
@@ -113,7 +113,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
} }
#endif #endif
if (!card.getSd2Card().writeStart(addr, nb_sector)) if (!card.diskIODriver()->writeStart(addr, nb_sector))
return CTRL_FAIL; return CTRL_FAIL;
// For each specified sector // For each specified sector
@@ -121,16 +121,16 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
// USB -> RAM // USB -> RAM
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) { if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().writeStop(); card.diskIODriver()->writeStop();
return CTRL_FAIL; return CTRL_FAIL;
} }
// Write a sector // Write a sector
card.getSd2Card().writeData(sector_buf); card.diskIODriver()->writeData(sector_buf);
} }
// Stop writing // Stop writing
card.getSd2Card().writeStop(); card.diskIODriver()->writeStop();
// Done // Done
return CTRL_GOOD; return CTRL_GOOD;

View File

@@ -675,11 +675,11 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
* - \code // Waits and gets a value on CDC line * - \code // Waits and gets a value on CDC line
int udi_cdc_getc(void); int udi_cdc_getc(void);
// Reads a RAM buffer on CDC line // Reads a RAM buffer on CDC line
iram_size_t udi_cdc_read_buf(int* buf, iram_size_t size); iram_size_t udi_cdc_read_buf(int *buf, iram_size_t size);
// Puts a byte on CDC line // Puts a byte on CDC line
int udi_cdc_putc(int value); int udi_cdc_putc(int value);
// Writes a RAM buffer on CDC line // Writes a RAM buffer on CDC line
iram_size_t udi_cdc_write_buf(const int* buf, iram_size_t size); \endcode iram_size_t udi_cdc_write_buf(const int *buf, iram_size_t size); \endcode
* *
* \section udi_cdc_use_cases Advanced use cases * \section udi_cdc_use_cases Advanced use cases
* For more advanced use of the UDI CDC module, see the following use cases: * For more advanced use of the UDI CDC module, see the following use cases:

View File

@@ -264,7 +264,7 @@ bool usb_task_extra_string(void) {
** Handle device requests that the ASF stack doesn't ** Handle device requests that the ASF stack doesn't
*/ */
bool usb_task_other_requests(void) { bool usb_task_other_requests(void) {
uint8_t* ptr = 0; uint8_t *ptr = 0;
uint16_t size = 0; uint16_t size = 0;
if (Udd_setup_type() == USB_REQ_TYPE_VENDOR) { if (Udd_setup_type() == USB_REQ_TYPE_VENDOR) {
@@ -322,7 +322,7 @@ void usb_task_init(void) {
char *sptr; char *sptr;
// Patch in the filament diameter // Patch in the filament diameter
sprintf_P(diam, PSTR("%d"), (int)((DEFAULT_NOMINAL_FILAMENT_DIA) * 1000.0)); itoa((int)((DEFAULT_NOMINAL_FILAMENT_DIA) * 1000), diam, 10);
// And copy it to the proper place, expanding it to unicode // And copy it to the proper place, expanding it to unicode
sptr = &diam[0]; sptr = &diam[0];

View File

@@ -20,11 +20,10 @@
* *
*/ */
#include "FlushableHardwareSerial.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include "FlushableHardwareSerial.h"
Serial0Type<FlushableHardwareSerial> flushableSerial(false, 0); Serial1Class<FlushableHardwareSerial> flushableSerial(false, 0);
#endif // ARDUINO_ARCH_ESP32 #endif

View File

@@ -21,9 +21,9 @@
*/ */
#pragma once #pragma once
#ifdef ARDUINO_ARCH_ESP32
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include "../shared/Marduino.h"
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
class FlushableHardwareSerial : public HardwareSerial { class FlushableHardwareSerial : public HardwareSerial {
@@ -31,6 +31,4 @@ public:
FlushableHardwareSerial(int uart_nr) : HardwareSerial(uart_nr) {} FlushableHardwareSerial(int uart_nr) : HardwareSerial(uart_nr) {}
}; };
extern Serial0Type<FlushableHardwareSerial> flushableSerial; extern Serial1Class<FlushableHardwareSerial> flushableSerial;
#endif // ARDUINO_ARCH_ESP32

View File

@@ -41,7 +41,7 @@
#endif #endif
#if ENABLED(ESP3D_WIFISUPPORT) #if ENABLED(ESP3D_WIFISUPPORT)
DefaultSerial MSerial(false, Serial2Socket); DefaultSerial1 MSerial0(false, Serial2Socket);
#endif #endif
// ------------------------ // ------------------------
@@ -141,6 +141,8 @@ void HAL_clear_reset_source() { }
uint8_t HAL_get_reset_source() { return rtc_get_reset_reason(1); } uint8_t HAL_get_reset_source() { return rtc_get_reset_reason(1); }
void HAL_reboot() { ESP.restart(); }
void _delay_ms(int delay_ms) { delay(delay_ms); } void _delay_ms(int delay_ms) { delay(delay_ms); }
// return free memory between end of heap (or end bss) and whatever is current // return free memory between end of heap (or end bss) and whatever is current
@@ -185,6 +187,7 @@ void HAL_adc_init() {
TERN_(HAS_TEMP_ADC_7, adc3_set_attenuation(get_channel(TEMP_7_PIN), ADC_ATTEN_11db)); TERN_(HAS_TEMP_ADC_7, adc3_set_attenuation(get_channel(TEMP_7_PIN), ADC_ATTEN_11db));
TERN_(HAS_HEATED_BED, adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db)); TERN_(HAS_HEATED_BED, adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db));
TERN_(HAS_TEMP_CHAMBER, adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db)); TERN_(HAS_TEMP_CHAMBER, adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db));
TERN_(HAS_TEMP_COOLER, adc1_set_attenuation(get_channel(TEMP_COOLER_PIN), ADC_ATTEN_11db));
TERN_(FILAMENT_WIDTH_SENSOR, adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db)); TERN_(FILAMENT_WIDTH_SENSOR, adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db));
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail. // Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.

View File

@@ -51,15 +51,15 @@
extern portMUX_TYPE spinlock; extern portMUX_TYPE spinlock;
#define MYSERIAL0 flushableSerial #define MYSERIAL1 flushableSerial
#if EITHER(WIFISUPPORT, ESP3D_WIFISUPPORT) #if EITHER(WIFISUPPORT, ESP3D_WIFISUPPORT)
#if ENABLED(ESP3D_WIFISUPPORT) #if ENABLED(ESP3D_WIFISUPPORT)
typedef ForwardSerial0Type< decltype(Serial2Socket) > DefaultSerial; typedef ForwardSerial1Class< decltype(Serial2Socket) > DefaultSerial1;
extern DefaultSerial MSerial; extern DefaultSerial1 MSerial0;
#define MYSERIAL1 MSerial #define MYSERIAL2 MSerial0
#else #else
#define MYSERIAL1 webSocketSerial #define MYSERIAL2 webSocketSerial
#endif #endif
#endif #endif
@@ -101,7 +101,7 @@ void HAL_clear_reset_source();
// reset reason // reset reason
uint8_t HAL_get_reset_source(); uint8_t HAL_get_reset_source();
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
void _delay_ms(int delay); void _delay_ms(int delay);

View File

@@ -85,7 +85,7 @@ uint8_t spiRec() {
return returnByte; return returnByte;
} }
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.transferBytes(0, buf, nbyte); SPI.transferBytes(0, buf, nbyte);
SPI.endTransaction(); SPI.endTransaction();
@@ -97,7 +97,7 @@ void spiSend(uint8_t b) {
SPI.endTransaction(); SPI.endTransaction();
} }
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.transfer(token); SPI.transfer(token);
SPI.writeBytes(const_cast<uint8_t*>(buf), 512); SPI.writeBytes(const_cast<uint8_t*>(buf), 512);

View File

@@ -137,7 +137,7 @@ size_t WebSocketSerial::write(const uint8_t c) {
return ret; return ret;
} }
size_t WebSocketSerial::write(const uint8_t* buffer, size_t size) { size_t WebSocketSerial::write(const uint8_t *buffer, size_t size) {
size_t written = 0; size_t written = 0;
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
written += write(buffer[i]); written += write(buffer[i]);

View File

@@ -54,7 +54,7 @@ public:
ring_buffer_pos_t read(uint8_t *buffer); ring_buffer_pos_t read(uint8_t *buffer);
void flush(); void flush();
ring_buffer_pos_t write(const uint8_t c); ring_buffer_pos_t write(const uint8_t c);
ring_buffer_pos_t write(const uint8_t* buffer, ring_buffer_pos_t size); ring_buffer_pos_t write(const uint8_t *buffer, ring_buffer_pos_t size);
}; };
class WebSocketSerial: public Stream { class WebSocketSerial: public Stream {
@@ -70,7 +70,7 @@ public:
int read(); int read();
void flush(); void flush();
size_t write(const uint8_t c); size_t write(const uint8_t c);
size_t write(const uint8_t* buffer, size_t size); size_t write(const uint8_t *buffer, size_t size);
#if ENABLED(SERIAL_STATS_DROPPED_RX) #if ENABLED(SERIAL_STATS_DROPPED_RX)
FORCE_INLINE uint32_t dropped() { return 0; } FORCE_INLINE uint32_t dropped() { return 0; }
@@ -81,5 +81,5 @@ public:
#endif #endif
}; };
typedef Serial0Type<WebSocketSerial> MSerialT; typedef Serial1Class<WebSocketSerial> MSerialT;
extern MSerialT webSocketSerial; extern MSerialT webSocketSerial;

View File

@@ -139,7 +139,7 @@ static void IRAM_ATTR i2s_intr_handler_default(void *arg) {
I2S0.int_clr.val = I2S0.int_st.val; //clear pending interrupt I2S0.int_clr.val = I2S0.int_st.val; //clear pending interrupt
} }
void stepperTask(void* parameter) { void stepperTask(void *parameter) {
uint32_t remaining = 0; uint32_t remaining = 0;
while (1) { while (1) {

View File

@@ -29,12 +29,6 @@
#include HAL_PATH(.,HAL.h) #include HAL_PATH(.,HAL.h)
#ifdef SERIAL_PORT_2
#define NUM_SERIAL 2
#else
#define NUM_SERIAL 1
#endif
#define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
#ifndef I2C_ADDRESS #ifndef I2C_ADDRESS

View File

@@ -73,4 +73,6 @@ void HAL_pwm_init() {
} }
void HAL_reboot() { /* Reset the application state and GPIO */ }
#endif // __PLAT_LINUX__ #endif // __PLAT_LINUX__

View File

@@ -61,7 +61,7 @@ uint8_t _getc();
#define SHARED_SERVOS HAS_SERVOS #define SHARED_SERVOS HAS_SERVOS
extern MSerialT usb_serial; extern MSerialT usb_serial;
#define MYSERIAL0 usb_serial #define MYSERIAL1 usb_serial
#define ST7920_DELAY_1 DELAY_NS(600) #define ST7920_DELAY_1 DELAY_NS(600)
#define ST7920_DELAY_2 DELAY_NS(750) #define ST7920_DELAY_2 DELAY_NS(750)
@@ -107,7 +107,7 @@ uint16_t HAL_adc_get_result();
inline void HAL_clear_reset_source(void) {} inline void HAL_clear_reset_source(void) {}
inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; } inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot(); // Reset the application state and GPIO
/* ---------------- Delay in cycles */ /* ---------------- Delay in cycles */
FORCE_INLINE static void DELAY_CYCLES(uint64_t x) { FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {

View File

@@ -115,4 +115,4 @@ struct HalSerial {
volatile bool host_connected; volatile bool host_connected;
}; };
typedef Serial0Type<HalSerial> MSerialT; typedef Serial1Class<HalSerial> MSerialT;

View File

@@ -105,8 +105,8 @@ int main() {
std::thread write_serial (write_serial_thread); std::thread write_serial (write_serial_thread);
std::thread read_serial (read_serial_thread); std::thread read_serial (read_serial_thread);
#ifdef MYSERIAL0 #ifdef MYSERIAL1
MYSERIAL0.begin(BAUDRATE); MYSERIAL1.begin(BAUDRATE);
SERIAL_ECHOLNPGM("x86_64 Initialized"); SERIAL_ECHOLNPGM("x86_64 Initialized");
SERIAL_FLUSHTX(); SERIAL_FLUSHTX();
#endif #endif

View File

@@ -29,7 +29,7 @@
#include "watchdog.h" #include "watchdog.h"
#endif #endif
DefaultSerial USBSerial(false, UsbSerial); DefaultSerial1 USBSerial(false, UsbSerial);
uint32_t HAL_adc_reading = 0; uint32_t HAL_adc_reading = 0;
@@ -67,7 +67,7 @@ void flashFirmware(const int16_t) {
delay(500); // Give OS time to disconnect delay(500); // Give OS time to disconnect
USB_Connect(false); // USB clear connection USB_Connect(false); // USB clear connection
delay(1000); // Give OS time to notice delay(1000); // Give OS time to notice
NVIC_SystemReset(); HAL_reboot();
} }
void HAL_clear_reset_source(void) { void HAL_clear_reset_source(void) {
@@ -81,4 +81,6 @@ uint8_t HAL_get_reset_source(void) {
return RST_POWER_ON; return RST_POWER_ON;
} }
void HAL_reboot() { NVIC_SystemReset(); }
#endif // TARGET_LPC1768 #endif // TARGET_LPC1768

View File

@@ -60,28 +60,27 @@ extern "C" volatile uint32_t _millis;
#define ST7920_DELAY_3 DELAY_NS(750) #define ST7920_DELAY_3 DELAY_NS(750)
#endif #endif
typedef ForwardSerial0Type< decltype(UsbSerial) > DefaultSerial; typedef ForwardSerial1Class< decltype(UsbSerial) > DefaultSerial1;
extern DefaultSerial USBSerial; extern DefaultSerial1 USBSerial;
#define _MSERIAL(X) MSerial##X #define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 USBSerial #define MYSERIAL1 USBSerial
#elif WITHIN(SERIAL_PORT, 0, 3) #elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else #else
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 #if SERIAL_PORT_2 == -1
#define MYSERIAL1 USBSerial #define MYSERIAL2 USBSerial
#elif WITHIN(SERIAL_PORT_2, 0, 3) #elif WITHIN(SERIAL_PORT_2, 0, 3)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else #else
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT_2 must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
@@ -91,7 +90,7 @@ extern DefaultSerial USBSerial;
#elif WITHIN(MMU2_SERIAL_PORT, 0, 3) #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT) #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else #else
#error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "MMU2_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
@@ -101,7 +100,10 @@ extern DefaultSerial USBSerial;
#elif WITHIN(LCD_SERIAL_PORT, 0, 3) #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() MSerial0.available()
#endif #endif
#endif #endif
@@ -216,4 +218,4 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255,
void HAL_clear_reset_source(void); void HAL_clear_reset_source(void);
uint8_t HAL_get_reset_source(void); uint8_t HAL_get_reset_source(void);
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();

View File

@@ -93,12 +93,12 @@
void spiSend(uint8_t b) { (void)spiTransfer(b); } void spiSend(uint8_t b) { (void)spiTransfer(b); }
void spiSend(const uint8_t* buf, size_t nbyte) { void spiSend(const uint8_t *buf, size_t nbyte) {
for (uint16_t i = 0; i < nbyte; i++) for (uint16_t i = 0; i < nbyte; i++)
(void)spiTransfer(buf[i]); (void)spiTransfer(buf[i]);
} }
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
(void)spiTransfer(token); (void)spiTransfer(token);
for (uint16_t i = 0; i < 512; i++) for (uint16_t i = 0; i < 512; i++)
(void)spiTransfer(buf[i]); (void)spiTransfer(buf[i]);
@@ -135,13 +135,13 @@
void spiSend(uint8_t b) { doio(b); } void spiSend(uint8_t b) { doio(b); }
void spiSend(const uint8_t* buf, size_t nbyte) { void spiSend(const uint8_t *buf, size_t nbyte) {
for (uint16_t i = 0; i < nbyte; i++) doio(buf[i]); for (uint16_t i = 0; i < nbyte; i++) doio(buf[i]);
} }
void spiSend(uint32_t chan, byte b) {} void spiSend(uint32_t chan, byte b) {}
void spiSend(uint32_t chan, const uint8_t* buf, size_t nbyte) {} void spiSend(uint32_t chan, const uint8_t *buf, size_t nbyte) {}
// Read single byte from SPI // Read single byte from SPI
uint8_t spiRec() { return doio(0xFF); } uint8_t spiRec() { return doio(0xFF); }
@@ -156,7 +156,7 @@
uint8_t spiTransfer(uint8_t b) { return doio(b); } uint8_t spiTransfer(uint8_t b) { return doio(b); }
// Write from buffer to SPI // Write from buffer to SPI
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
(void)spiTransfer(token); (void)spiTransfer(token);
for (uint16_t i = 0; i < 512; i++) for (uint16_t i = 0; i < 512; i++)
(void)spiTransfer(buf[i]); (void)spiTransfer(buf[i]);

View File

@@ -21,25 +21,26 @@
*/ */
#ifdef TARGET_LPC1768 #ifdef TARGET_LPC1768
#include "../../inc/MarlinConfigPre.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
#if ANY_SERIAL_IS(0) #include "../../inc/MarlinConfig.h"
#if USING_HW_SERIAL0
MarlinSerial _MSerial(LPC_UART0); MarlinSerial _MSerial(LPC_UART0);
MSerialT MSerial(true, _MSerial); MSerialT MSerial0(true, _MSerial);
extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); } extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); }
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
MarlinSerial _MSerial1((LPC_UART_TypeDef *) LPC_UART1); MarlinSerial _MSerial1((LPC_UART_TypeDef *) LPC_UART1);
MSerialT MSerial1(true, _MSerial1); MSerialT MSerial1(true, _MSerial1);
extern "C" void UART1_IRQHandler() { _MSerial1.IRQHandler(); } extern "C" void UART1_IRQHandler() { _MSerial1.IRQHandler(); }
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
MarlinSerial _MSerial2(LPC_UART2); MarlinSerial _MSerial2(LPC_UART2);
MSerialT MSerial2(true, _MSerial2); MSerialT MSerial2(true, _MSerial2);
extern "C" void UART2_IRQHandler() { _MSerial2.IRQHandler(); } extern "C" void UART2_IRQHandler() { _MSerial2.IRQHandler(); }
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
MarlinSerial _MSerial3(LPC_UART3); MarlinSerial _MSerial3(LPC_UART3);
MSerialT MSerial3(true, _MSerial3); MSerialT MSerial3(true, _MSerial3);
extern "C" void UART3_IRQHandler() { _MSerial3.IRQHandler(); } extern "C" void UART3_IRQHandler() { _MSerial3.IRQHandler(); }
@@ -50,16 +51,16 @@
bool MarlinSerial::recv_callback(const char c) { bool MarlinSerial::recv_callback(const char c) {
// Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro) // Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro)
if (false) {} if (false) {}
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
else if (this == &_MSerial) emergency_parser.update(MSerial.emergency_state, c); else if (this == &_MSerial) emergency_parser.update(MSerial0.emergency_state, c);
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c); else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c);
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
else if (this == &_MSerial2) emergency_parser.update(MSerial2.emergency_state, c); else if (this == &_MSerial2) emergency_parser.update(MSerial2.emergency_state, c);
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
else if (this == &_MSerial3) emergency_parser.update(MSerial3.emergency_state, c); else if (this == &_MSerial3) emergency_parser.update(MSerial3.emergency_state, c);
#endif #endif
return true; return true;

View File

@@ -54,8 +54,8 @@ public:
// On LPC176x framework, HardwareSerial does not implement the same interface as Arduino's Serial, so overloads // On LPC176x framework, HardwareSerial does not implement the same interface as Arduino's Serial, so overloads
// of 'available' and 'read' method are not used in this multiple inheritance scenario. // of 'available' and 'read' method are not used in this multiple inheritance scenario.
// Instead, use a ForwardSerial here that adapts the interface. // Instead, use a ForwardSerial here that adapts the interface.
typedef ForwardSerial0Type<MarlinSerial> MSerialT; typedef ForwardSerial1Class<MarlinSerial> MSerialT;
extern MSerialT MSerial; extern MSerialT MSerial0;
extern MSerialT MSerial1; extern MSerialT MSerial1;
extern MSerialT MSerial2; extern MSerialT MSerial2;
extern MSerialT MSerial3; extern MSerialT MSerial3;

View File

@@ -42,25 +42,22 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed!
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
if (v != eeprom_read_byte(p)) { if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;
} }
} }
crc16(crc, &v, 1); crc16(crc, &v, 1);
pos++; pos++;
value++; value++;
}; }
return false; return false;
} }
@@ -68,7 +65,6 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
do { do {
// Read from external EEPROM // Read from external EEPROM
const uint8_t c = eeprom_read_byte((uint8_t*)pos); const uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;
crc16(crc, &c, 1); crc16(crc, &c, 1);
pos++; pos++;

View File

@@ -92,7 +92,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#define ANY_TX(N,V...) DO(IS_TX##N,||,V) #define ANY_TX(N,V...) DO(IS_TX##N,||,V)
#define ANY_RX(N,V...) DO(IS_RX##N,||,V) #define ANY_RX(N,V...) DO(IS_RX##N,||,V)
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
#define IS_TX0(P) (P == P0_02) #define IS_TX0(P) (P == P0_02)
#define IS_RX0(P) (P == P0_03) #define IS_RX0(P) (P == P0_03)
#if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI) #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
@@ -106,7 +106,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef IS_RX0 #undef IS_RX0
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
#define IS_TX1(P) (P == P0_15) #define IS_TX1(P) (P == P0_15)
#define IS_RX1(P) (P == P0_16) #define IS_RX1(P) (P == P0_16)
#define _IS_TX1_1 IS_TX1 #define _IS_TX1_1 IS_TX1
@@ -127,7 +127,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef _IS_RX1_1 #undef _IS_RX1_1
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
#define IS_TX2(P) (P == P0_10) #define IS_TX2(P) (P == P0_10)
#define IS_RX2(P) (P == P0_11) #define IS_RX2(P) (P == P0_11)
#define _IS_TX2_1 IS_TX2 #define _IS_TX2_1 IS_TX2
@@ -161,7 +161,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef _IS_RX2_1 #undef _IS_RX2_1
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
#define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00) #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
#define PIN_IS_RX3(P) (P##_PIN == P0_01) #define PIN_IS_RX3(P) (P##_PIN == P0_01)
#if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)

View File

@@ -66,7 +66,7 @@
void spiBegin(); void spiBegin();
void spiInit(uint8_t spiRate); void spiInit(uint8_t spiRate);
void spiSend(uint8_t b); void spiSend(uint8_t b);
void spiSend(const uint8_t* buf, size_t n); void spiSend(const uint8_t *buf, size_t n);
static uint8_t rs_last_state = 255; static uint8_t rs_last_state = 255;

View File

@@ -25,20 +25,20 @@
#include <wiring_private.h> #include <wiring_private.h>
#ifdef ADAFRUIT_GRAND_CENTRAL_M4 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
#if ANY_SERIAL_IS(-1) #if USING_HW_SERIALUSB
DefaultSerial MSerial(false, Serial); DefaultSerial1 MSerial0(false, Serial);
#endif #endif
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
DefaultSerial1 MSerial1(false, Serial1); DefaultSerial2 MSerial1(false, Serial1);
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
DefaultSerial2 MSerial2(false, Serial2); DefaultSerial3 MSerial2(false, Serial2);
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
DefaultSerial3 MSerial3(false, Serial3); DefaultSerial4 MSerial3(false, Serial3);
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
DefaultSerial4 MSerial4(false, Serial4); DefaultSerial5 MSerial4(false, Serial4);
#endif #endif
#endif #endif
@@ -57,6 +57,7 @@
#define GET_PROBE_ADC() TERN(HAS_TEMP_PROBE, PIN_TO_ADC(TEMP_PROBE_PIN), -1) #define GET_PROBE_ADC() TERN(HAS_TEMP_PROBE, PIN_TO_ADC(TEMP_PROBE_PIN), -1)
#define GET_BED_ADC() TERN(HAS_TEMP_ADC_BED, PIN_TO_ADC(TEMP_BED_PIN), -1) #define GET_BED_ADC() TERN(HAS_TEMP_ADC_BED, PIN_TO_ADC(TEMP_BED_PIN), -1)
#define GET_CHAMBER_ADC() TERN(HAS_TEMP_ADC_CHAMBER, PIN_TO_ADC(TEMP_CHAMBER_PIN), -1) #define GET_CHAMBER_ADC() TERN(HAS_TEMP_ADC_CHAMBER, PIN_TO_ADC(TEMP_CHAMBER_PIN), -1)
#define GET_COOLER_ADC() TERN(HAS_TEMP_ADC_COOLER, PIN_TO_ADC(TEMP_COOLER_PIN), -1)
#define GET_FILAMENT_WIDTH_ADC() TERN(FILAMENT_WIDTH_SENSOR, PIN_TO_ADC(FILWIDTH_PIN), -1) #define GET_FILAMENT_WIDTH_ADC() TERN(FILAMENT_WIDTH_SENSOR, PIN_TO_ADC(FILWIDTH_PIN), -1)
#define GET_BUTTONS_ADC() TERN(HAS_ADC_BUTTONS, PIN_TO_ADC(ADC_KEYPAD_PIN), -1) #define GET_BUTTONS_ADC() TERN(HAS_ADC_BUTTONS, PIN_TO_ADC(ADC_KEYPAD_PIN), -1)
@@ -66,6 +67,7 @@
|| GET_PROBE_ADC() == n \ || GET_PROBE_ADC() == n \
|| GET_BED_ADC() == n \ || GET_BED_ADC() == n \
|| GET_CHAMBER_ADC() == n \ || GET_CHAMBER_ADC() == n \
|| GET_COOLER_ADC() == n \
|| GET_FILAMENT_WIDTH_ADC() == n \ || GET_FILAMENT_WIDTH_ADC() == n \
|| GET_BUTTONS_ADC() == n \ || GET_BUTTONS_ADC() == n \
) )
@@ -144,6 +146,9 @@ uint16_t HAL_adc_result;
#if GET_CHAMBER_ADC() == 0 #if GET_CHAMBER_ADC() == 0
TEMP_CHAMBER_PIN, TEMP_CHAMBER_PIN,
#endif #endif
#if GET_COOLER_ADC() == 0
TEMP_COOLER_PIN,
#endif
#if GET_FILAMENT_WIDTH_ADC() == 0 #if GET_FILAMENT_WIDTH_ADC() == 0
FILWIDTH_PIN, FILWIDTH_PIN,
#endif #endif
@@ -184,6 +189,9 @@ uint16_t HAL_adc_result;
#if GET_CHAMBER_ADC() == 1 #if GET_CHAMBER_ADC() == 1
TEMP_CHAMBER_PIN, TEMP_CHAMBER_PIN,
#endif #endif
#if GET_COOLER_ADC() == 1
TEMP_COOLER_PIN,
#endif
#if GET_FILAMENT_WIDTH_ADC() == 1 #if GET_FILAMENT_WIDTH_ADC() == 1
FILWIDTH_PIN, FILWIDTH_PIN,
#endif #endif
@@ -232,6 +240,9 @@ uint16_t HAL_adc_result;
#if GET_CHAMBER_ADC() == 0 #if GET_CHAMBER_ADC() == 0
{ PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) }, { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
#endif #endif
#if GET_COOLER_ADC() == 0
{ PIN_TO_INPUTCTRL(TEMP_COOLER_PIN) },
#endif
#if GET_FILAMENT_WIDTH_ADC() == 0 #if GET_FILAMENT_WIDTH_ADC() == 0
{ PIN_TO_INPUTCTRL(FILWIDTH_PIN) }, { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
#endif #endif
@@ -281,6 +292,9 @@ uint16_t HAL_adc_result;
#if GET_CHAMBER_ADC() == 1 #if GET_CHAMBER_ADC() == 1
{ PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) }, { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
#endif #endif
#if GET_COOLER_ADC() == 1
{ PIN_TO_INPUTCTRL(TEMP_COOLER_PIN) },
#endif
#if GET_FILAMENT_WIDTH_ADC() == 1 #if GET_FILAMENT_WIDTH_ADC() == 1
{ PIN_TO_INPUTCTRL(FILWIDTH_PIN) }, { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
#endif #endif
@@ -422,6 +436,8 @@ uint8_t HAL_get_reset_source() {
} }
#pragma pop_macro("WDT") #pragma pop_macro("WDT")
void HAL_reboot() { NVIC_SystemReset(); }
extern "C" { extern "C" {
void * _sbrk(int incr); void * _sbrk(int incr);

View File

@@ -32,58 +32,58 @@
#include "MarlinSerial_AGCM4.h" #include "MarlinSerial_AGCM4.h"
// Serial ports // Serial ports
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1; typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2; typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3; typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
typedef ForwardSerial0Type< decltype(Serial4) > DefaultSerial4; typedef ForwardSerial1Class< decltype(Serial4) > DefaultSerial5;
extern DefaultSerial MSerial; extern DefaultSerial1 MSerial0;
extern DefaultSerial1 MSerial1; extern DefaultSerial2 MSerial1;
extern DefaultSerial2 MSerial2; extern DefaultSerial3 MSerial2;
extern DefaultSerial3 MSerial3; extern DefaultSerial4 MSerial3;
extern DefaultSerial4 MSerial4; extern DefaultSerial5 MSerial4;
// MYSERIAL0 required before MarlinSerial includes! // MYSERIAL1 required before MarlinSerial includes!
#define __MSERIAL(X) MSerial##X #define __MSERIAL(X) MSerial##X
#define _MSERIAL(X) __MSERIAL(X) #define _MSERIAL(X) __MSERIAL(X)
#define MSERIAL(X) _MSERIAL(INCREMENT(X)) #define MSERIAL(X) _MSERIAL(INCREMENT(X))
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 MSerial #define MYSERIAL1 MSerial0
#elif WITHIN(SERIAL_PORT, 0, 3) #elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else #else
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 #if SERIAL_PORT_2 == -1
#define MYSERIAL1 MSerial #define MYSERIAL2 MSerial0
#elif WITHIN(SERIAL_PORT_2, 0, 3) #elif WITHIN(SERIAL_PORT_2, 0, 3)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else #else
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #error "SERIAL_PORT_2 must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT #ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1 #if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerial #define MMU2_SERIAL MSerial0
#elif WITHIN(MMU2_SERIAL_PORT, 0, 3) #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT) #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else #else
#error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "MMU2_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerial #define LCD_SERIAL MSerial0
#elif WITHIN(LCD_SERIAL_PORT, 0, 3) #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
@@ -109,7 +109,7 @@ typedef int8_t pin_t;
void HAL_clear_reset_source(); // clear reset reason void HAL_clear_reset_source(); // clear reset reason
uint8_t HAL_get_reset_source(); // get reset reason uint8_t HAL_get_reset_source(); // get reset reason
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
// //
// ADC // ADC

View File

@@ -103,7 +103,7 @@
* @param nbyte Number of bytes to receive. * @param nbyte Number of bytes to receive.
* @return Nothing * @return Nothing
*/ */
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
if (nbyte == 0) return; if (nbyte == 0) return;
memset(buf, 0xFF, nbyte); memset(buf, 0xFF, nbyte);
sdSPI.beginTransaction(spiConfig); sdSPI.beginTransaction(spiConfig);
@@ -132,7 +132,7 @@
* *
* @details Uses DMA * @details Uses DMA
*/ */
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
sdSPI.beginTransaction(spiConfig); sdSPI.beginTransaction(spiConfig);
sdSPI.transfer(token); sdSPI.transfer(token);
sdSPI.transfer((uint8_t*)buf, nullptr, 512); sdSPI.transfer((uint8_t*)buf, nullptr, 512);

View File

@@ -27,7 +27,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
UartT Serial2(false, &sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX); UartT Serial2(false, &sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
void SERCOM4_0_Handler() { Serial2.IrqHandler(); } void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
void SERCOM4_1_Handler() { Serial2.IrqHandler(); } void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
@@ -35,7 +35,7 @@
void SERCOM4_3_Handler() { Serial2.IrqHandler(); } void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
UartT Serial3(false, &sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX); UartT Serial3(false, &sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
void SERCOM1_0_Handler() { Serial3.IrqHandler(); } void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
void SERCOM1_1_Handler() { Serial3.IrqHandler(); } void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
@@ -43,7 +43,7 @@
void SERCOM1_3_Handler() { Serial3.IrqHandler(); } void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
UartT Serial4(false, &sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX); UartT Serial4(false, &sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
void SERCOM5_0_Handler() { Serial4.IrqHandler(); } void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
void SERCOM5_1_Handler() { Serial4.IrqHandler(); } void SERCOM5_1_Handler() { Serial4.IrqHandler(); }

View File

@@ -22,7 +22,7 @@
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef Serial0Type<Uart> UartT; typedef Serial1Class<Uart> UartT;
extern UartT Serial2; extern UartT Serial2;
extern UartT Serial3; extern UartT Serial3;

View File

@@ -41,12 +41,13 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
const uint8_t v = *value; const uint8_t v = *value;
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
if (v != eeprom_read_byte(p)) { if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
delay(2); if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -29,7 +29,7 @@
#include "../shared/Delay.h" #include "../shared/Delay.h"
#ifdef USBCON #ifdef USBCON
DefaultSerial MSerial(false, SerialUSB); DefaultSerial1 MSerial0(false, SerialUSB);
#endif #endif
#if ENABLED(SRAM_EEPROM_EMULATION) #if ENABLED(SRAM_EEPROM_EMULATION)
@@ -133,6 +133,8 @@ uint8_t HAL_get_reset_source() {
; ;
} }
void HAL_reboot() { NVIC_SystemReset(); }
void _delay_ms(const int delay_ms) { delay(delay_ms); } void _delay_ms(const int delay_ms) { delay(delay_ms); }
extern "C" { extern "C" {
@@ -147,8 +149,8 @@ extern "C" {
void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); } 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; } uint16_t HAL_adc_get_result() { return HAL_adc_result; }
// Reset the system (to initiate a firmware flash) // Reset the system to initiate a firmware flash
void flashFirmware(const int16_t) { NVIC_SystemReset(); } void flashFirmware(const int16_t) { HAL_reboot(); }
// Maple Compatibility // Maple Compatibility
volatile uint32_t systick_uptime_millis = 0; volatile uint32_t systick_uptime_millis = 0;

View File

@@ -40,8 +40,8 @@
#ifdef USBCON #ifdef USBCON
#include <USBSerial.h> #include <USBSerial.h>
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef ForwardSerial0Type< decltype(SerialUSB) > DefaultSerial; typedef ForwardSerial1Class< decltype(SerialUSB) > DefaultSerial1;
extern DefaultSerial MSerial; extern DefaultSerial1 MSerial0;
#endif #endif
// ------------------------ // ------------------------
@@ -51,40 +51,40 @@
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 MSerial #define MYSERIAL1 MSerial0
#elif WITHIN(SERIAL_PORT, 1, 6) #elif WITHIN(SERIAL_PORT, 1, 6)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else #else
#error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #error "SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 #if SERIAL_PORT_2 == -1
#define MYSERIAL1 MSerial #define MYSERIAL2 MSerial0
#elif WITHIN(SERIAL_PORT_2, 1, 6) #elif WITHIN(SERIAL_PORT_2, 1, 6)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else #else
#error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration." #error "SERIAL_PORT_2 must be from 1 to 6. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT #ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1 #if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerial #define MMU2_SERIAL MSerial0
#elif WITHIN(MMU2_SERIAL_PORT, 1, 6) #elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT) #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else #else
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #error "MMU2_SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
#endif #endif
#endif #endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerial #define LCD_SERIAL MSerial0
#elif WITHIN(LCD_SERIAL_PORT, 1, 6) #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #error "LCD_SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
#endif #endif
#if HAS_DGUS_LCD #if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
@@ -144,7 +144,7 @@ void HAL_clear_reset_source();
// Reset reason // Reset reason
uint8_t HAL_get_reset_source(); uint8_t HAL_get_reset_source();
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
void _delay_ms(const int delay); void _delay_ms(const int delay);

View File

@@ -193,7 +193,7 @@ static SPISettings spiConfig;
* *
* @details Uses DMA * @details Uses DMA
*/ */
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
if (nbyte == 0) return; if (nbyte == 0) return;
memset(buf, 0xFF, nbyte); memset(buf, 0xFF, nbyte);
SPI.transfer(buf, nbyte); SPI.transfer(buf, nbyte);
@@ -218,7 +218,7 @@ static SPISettings spiConfig;
* *
* @details Use DMA * @details Use DMA
*/ */
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
uint8_t rxBuf[512]; uint8_t rxBuf[512];
SPI.transfer(token); SPI.transfer(token);
SPI.transfer((uint8_t*)buf, &rxBuf, 512); SPI.transfer((uint8_t*)buf, &rxBuf, 512);

View File

@@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* *
*/ */
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(STM32H7xx)
#include "MarlinSPI.h" #include "MarlinSPI.h"

View File

@@ -28,7 +28,6 @@
#ifndef USART4 #ifndef USART4
#define USART4 UART4 #define USART4 UART4
#endif #endif
#ifndef USART5 #ifndef USART5
#define USART5 UART5 #define USART5 UART5
#endif #endif
@@ -38,22 +37,38 @@
MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \ MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \
void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); } void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); }
#define DECLARE_SERIAL_PORT_EXP(ser_num) DECLARE_SERIAL_PORT(ser_num) #if USING_HW_SERIAL1
DECLARE_SERIAL_PORT(1)
#if defined(SERIAL_PORT) && SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT)
#endif #endif
#if USING_HW_SERIAL2
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 DECLARE_SERIAL_PORT(2)
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
#endif #endif
#if USING_HW_SERIAL3
#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0 DECLARE_SERIAL_PORT(3)
DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT)
#endif #endif
#if USING_HW_SERIAL4
#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0 DECLARE_SERIAL_PORT(4)
DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT) #endif
#if USING_HW_SERIAL5
DECLARE_SERIAL_PORT(5)
#endif
#if USING_HW_SERIAL6
DECLARE_SERIAL_PORT(6)
#endif
#if USING_HW_SERIAL7
DECLARE_SERIAL_PORT(7)
#endif
#if USING_HW_SERIAL8
DECLARE_SERIAL_PORT(8)
#endif
#if USING_HW_SERIAL9
DECLARE_SERIAL_PORT(9)
#endif
#if USING_HW_SERIAL10
DECLARE_SERIAL_PORT(10)
#endif
#if USING_HW_SERIALLP1
DECLARE_SERIAL_PORT(LP1)
#endif #endif
void MarlinSerial::begin(unsigned long baud, uint8_t config) { void MarlinSerial::begin(unsigned long baud, uint8_t config) {

View File

@@ -29,20 +29,20 @@
typedef void (*usart_rx_callback_t)(serial_t * obj); typedef void (*usart_rx_callback_t)(serial_t * obj);
struct MarlinSerial : public HardwareSerial { struct MarlinSerial : public HardwareSerial {
MarlinSerial(void* peripheral, usart_rx_callback_t rx_callback) : MarlinSerial(void *peripheral, usart_rx_callback_t rx_callback) :
HardwareSerial(peripheral), _rx_callback(rx_callback) HardwareSerial(peripheral), _rx_callback(rx_callback)
{ } { }
void begin(unsigned long baud, uint8_t config); void begin(unsigned long baud, uint8_t config);
inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
void _rx_complete_irq(serial_t* obj); void _rx_complete_irq(serial_t *obj);
protected: protected:
usart_rx_callback_t _rx_callback; usart_rx_callback_t _rx_callback;
}; };
typedef Serial0Type<MarlinSerial> MSerialT; typedef Serial1Class<MarlinSerial> MSerialT;
extern MSerialT MSerial1; extern MSerialT MSerial1;
extern MSerialT MSerial2; extern MSerialT MSerial2;
extern MSerialT MSerial3; extern MSerialT MSerial3;

View File

@@ -36,7 +36,8 @@
// use USB drivers // use USB drivers
extern "C" { int8_t SD_MSC_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); extern "C" {
int8_t SD_MSC_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
int8_t SD_MSC_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t SD_MSC_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
extern SD_HandleTypeDef hsd; extern SD_HandleTypeDef hsd;
} }
@@ -75,7 +76,18 @@
#error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported" #error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
#endif #endif
// Fixed
#define SDIO_D0_PIN PC8
#define SDIO_D1_PIN PC9
#define SDIO_D2_PIN PC10
#define SDIO_D3_PIN PC11
#define SDIO_CK_PIN PC12
#define SDIO_CMD_PIN PD2
SD_HandleTypeDef hsd; // create SDIO structure SD_HandleTypeDef hsd; // create SDIO structure
// F4 supports one DMA for RX and another for TX, but Marlin will never
// do read and write at same time, so we use the same DMA for both.
DMA_HandleTypeDef hdma_sdio;
/* /*
SDIO_INIT_CLK_DIV is 118 SDIO_INIT_CLK_DIV is 118
@@ -96,7 +108,7 @@
// Target Clock, configurable. Default is 18MHz, from STM32F1 // Target Clock, configurable. Default is 18MHz, from STM32F1
#ifndef SDIO_CLOCK #ifndef SDIO_CLOCK
#define SDIO_CLOCK 18000000 /* 18 MHz */ #define SDIO_CLOCK 18000000 // 18 MHz
#endif #endif
// SDIO retries, configurable. Default is 3, from STM32F1 // SDIO retries, configurable. Default is 3, from STM32F1
@@ -120,24 +132,21 @@
} }
void go_to_transfer_speed() { void go_to_transfer_speed() {
SD_InitTypeDef Init;
/* Default SDIO peripheral configuration for SD card initialization */ /* Default SDIO peripheral configuration for SD card initialization */
Init.ClockEdge = hsd.Init.ClockEdge; hsd.Init.ClockEdge = hsd.Init.ClockEdge;
Init.ClockBypass = hsd.Init.ClockBypass; hsd.Init.ClockBypass = hsd.Init.ClockBypass;
Init.ClockPowerSave = hsd.Init.ClockPowerSave; hsd.Init.ClockPowerSave = hsd.Init.ClockPowerSave;
Init.BusWide = hsd.Init.BusWide; hsd.Init.BusWide = hsd.Init.BusWide;
Init.HardwareFlowControl = hsd.Init.HardwareFlowControl; hsd.Init.HardwareFlowControl = hsd.Init.HardwareFlowControl;
Init.ClockDiv = clock_to_divider(SDIO_CLOCK); hsd.Init.ClockDiv = clock_to_divider(SDIO_CLOCK);
/* Initialize SDIO peripheral interface with default configuration */ /* Initialize SDIO peripheral interface with default configuration */
SDIO_Init(hsd.Instance, Init); SDIO_Init(hsd.Instance, hsd.Init);
} }
void SD_LowLevel_Init(void) { void SD_LowLevel_Init(void) {
uint32_t tempreg; uint32_t tempreg;
__HAL_RCC_SDIO_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE(); //enable GPIO clocks __HAL_RCC_GPIOC_CLK_ENABLE(); //enable GPIO clocks
__HAL_RCC_GPIOD_CLK_ENABLE(); //enable GPIO clocks __HAL_RCC_GPIOD_CLK_ENABLE(); //enable GPIO clocks
@@ -163,11 +172,45 @@
GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Pin = GPIO_PIN_2;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
#if DISABLED(STM32F1xx) // Setup DMA
// TODO: use __HAL_RCC_SDIO_RELEASE_RESET() and __HAL_RCC_SDIO_CLK_ENABLE(); #if defined(STM32F1xx)
RCC->APB2RSTR &= ~RCC_APB2RSTR_SDIORST_Msk; // take SDIO out of reset hdma_sdio.Init.Mode = DMA_NORMAL;
RCC->APB2ENR |= RCC_APB2RSTR_SDIORST_Msk; // enable SDIO clock hdma_sdio.Instance = DMA2_Channel4;
// Enable the DMA2 Clock HAL_NVIC_EnableIRQ(DMA2_Channel4_5_IRQn);
#elif defined(STM32F4xx)
hdma_sdio.Init.Mode = DMA_PFCTRL;
hdma_sdio.Instance = DMA2_Stream3;
hdma_sdio.Init.Channel = DMA_CHANNEL_4;
hdma_sdio.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
hdma_sdio.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_sdio.Init.MemBurst = DMA_MBURST_INC4;
hdma_sdio.Init.PeriphBurst = DMA_PBURST_INC4;
HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
#endif
HAL_NVIC_EnableIRQ(SDIO_IRQn);
hdma_sdio.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_sdio.Init.MemInc = DMA_MINC_ENABLE;
hdma_sdio.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_sdio.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_sdio.Init.Priority = DMA_PRIORITY_LOW;
__HAL_LINKDMA(&hsd, hdmarx, hdma_sdio);
__HAL_LINKDMA(&hsd, hdmatx, hdma_sdio);
#if defined(STM32F1xx)
__HAL_RCC_SDIO_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
#else
__HAL_RCC_SDIO_FORCE_RESET();
delay(2);
__HAL_RCC_SDIO_RELEASE_RESET();
delay(2);
__HAL_RCC_SDIO_CLK_ENABLE();
__HAL_RCC_DMA2_FORCE_RESET();
delay(2);
__HAL_RCC_DMA2_RELEASE_RESET();
delay(2);
__HAL_RCC_DMA2_CLK_ENABLE();
#endif #endif
//Initialize the SDIO (with initial <400Khz Clock) //Initialize the SDIO (with initial <400Khz Clock)
@@ -179,6 +222,7 @@
// Power up the SDIO // Power up the SDIO
SDIO_PowerState_ON(SDIO); SDIO_PowerState_ON(SDIO);
hsd.Instance = SDIO;
} }
void HAL_SD_MspInit(SD_HandleTypeDef *hsd) { // application specific init void HAL_SD_MspInit(SD_HandleTypeDef *hsd) { // application specific init
@@ -222,107 +266,81 @@
if (!status) break; if (!status) break;
if (!--retry_Cnt) return false; // return failing status if retries are exhausted if (!--retry_Cnt) return false; // return failing status if retries are exhausted
} }
go_to_transfer_speed();
} }
#endif #endif
return true; return true;
} }
/*
void init_SDIO_pins(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
// SDIO GPIO Configuration static bool SDIO_ReadWriteBlock_DMA(uint32_t block, const uint8_t *src, uint8_t *dst) {
// PC8 ------> SDIO_D0 if (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) return false;
// PC12 ------> SDIO_CK
// PD2 ------> SDIO_CMD
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
*/
//bool SDIO_init() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
//bool SDIO_Init_C() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
bool SDIO_ReadBlock(uint32_t block, uint8_t *dst) {
hsd.Instance = SDIO;
uint8_t retryCnt = SDIO_READ_RETRIES;
bool status;
for (;;) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh()); TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
status = (bool) HAL_SD_ReadBlocks(&hsd, (uint8_t*)dst, block, 1, 1000); // read one 512 byte block with 500mS timeout
status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK HAL_StatusTypeDef ret;
if (!status) break; // return passing status if (src) {
if (!--retryCnt) break; // return failing status if retries are exhausted hdma_sdio.Init.Direction = DMA_MEMORY_TO_PERIPH;
HAL_DMA_Init(&hdma_sdio);
ret = HAL_SD_WriteBlocks_DMA(&hsd, (uint8_t *)src, block, 1);
}
else {
hdma_sdio.Init.Direction = DMA_PERIPH_TO_MEMORY;
HAL_DMA_Init(&hdma_sdio);
ret = HAL_SD_ReadBlocks_DMA(&hsd, (uint8_t *)dst, block, 1);
} }
return status;
/* if (ret != HAL_OK) {
return (bool) ((status_read | status_card) ? 1 : 0); HAL_DMA_Abort_IT(&hdma_sdio);
HAL_DMA_DeInit(&hdma_sdio);
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
if (blockAddress >= SdCard.LogBlockNbr) return false;
if ((0x03 & (uint32_t)data)) return false; // misaligned data
if (SdCard.CardType != CARD_SDHC_SDXC) { blockAddress *= 512U; }
if (!SDIO_CmdReadSingleBlock(blockAddress)) {
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS);
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
return false; return false;
} }
while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) {} millis_t timeout = millis() + 500;
// Wait the transfer
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL); while (hsd.State != HAL_SD_STATE_READY) {
if (ELAPSED(millis(), timeout)) {
if (SDIO->STA & SDIO_STA_RXDAVL) { HAL_DMA_Abort_IT(&hdma_sdio);
while (SDIO->STA & SDIO_STA_RXDAVL) (void)SDIO->FIFO; HAL_DMA_DeInit(&hdma_sdio);
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
return false; return false;
} }
if (SDIO_GET_FLAG(SDIO_STA_TRX_ERROR_FLAGS)) {
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
return false;
} }
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
*/ while (__HAL_DMA_GET_FLAG(&hdma_sdio, __HAL_DMA_GET_TC_FLAG_INDEX(&hdma_sdio)) != 0
|| __HAL_DMA_GET_FLAG(&hdma_sdio, __HAL_DMA_GET_TE_FLAG_INDEX(&hdma_sdio)) != 0) { /* nada */ }
HAL_DMA_Abort_IT(&hdma_sdio);
HAL_DMA_DeInit(&hdma_sdio);
timeout = millis() + 500;
while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) if (ELAPSED(millis(), timeout)) return false;
return true; return true;
} }
bool SDIO_ReadBlock(uint32_t block, uint8_t *dst) {
uint8_t retries = SDIO_READ_RETRIES;
while (retries--) if (SDIO_ReadWriteBlock_DMA(block, NULL, dst)) return true;
return false;
}
bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) { bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) {
hsd.Instance = SDIO; uint8_t retries = SDIO_READ_RETRIES;
uint8_t retryCnt = SDIO_READ_RETRIES; while (retries--) if (SDIO_ReadWriteBlock_DMA(block, src, NULL)) return true;
bool status; return false;
for (;;) {
status = (bool) HAL_SD_WriteBlocks(&hsd, (uint8_t*)src, block, 1, 500); // write one 512 byte block with 500mS timeout
status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK
if (!status) break; // return passing status
if (!--retryCnt) break; // return failing status if retries are exhausted
}
return status;
} }
#if defined(STM32F1xx)
#define DMA_IRQ_HANDLER DMA2_Channel4_5_IRQHandler
#elif defined(STM32F4xx)
#define DMA_IRQ_HANDLER DMA2_Stream3_IRQHandler
#else
#error "Unknown STM32 architecture."
#endif
extern "C" void SDIO_IRQHandler(void) { HAL_SD_IRQHandler(&hsd); }
extern "C" void DMA_IRQ_HANDLER(void) { HAL_DMA_IRQHandler(&hdma_sdio); }
#endif // !USBD_USE_CDC_COMPOSITE #endif // !USBD_USE_CDC_COMPOSITE
#endif // SDIO_SUPPORT #endif // SDIO_SUPPORT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

View File

@@ -43,25 +43,22 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed!
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
if (v != eeprom_read_byte(p)) { if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;
} }
} }
crc16(crc, &v, 1); crc16(crc, &v, 1);
pos++; pos++;
value++; value++;
}; }
return false; return false;
} }

View File

@@ -52,6 +52,6 @@
#error "SERIAL_STATS_DROPPED_RX is not supported on STM32." #error "SERIAL_STATS_DROPPED_RX is not supported on STM32."
#endif #endif
#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) && NOT_TARGET(STM32F4xx, STM32F1xx) #if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) && NOT_TARGET(STM32H7xx, STM32F4xx, STM32F1xx)
#error "TFT_COLOR_UI, TFT_LVGL_UI and TFT_CLASSIC_UI are currently only supported on STM32F4 and STM32F1 hardware." #error "TFT_COLOR_UI, TFT_LVGL_UI and TFT_CLASSIC_UI are currently only supported on STM32H7, STM32F4 and STM32F1 hardware."
#endif #endif

View File

@@ -30,54 +30,66 @@
class Sd2CardUSBMscHandler : public USBMscHandler { class Sd2CardUSBMscHandler : public USBMscHandler {
public: public:
DiskIODriver* diskIODriver() {
#if ENABLED(MULTI_VOLUME)
#if SHARED_VOLUME_IS(SD_ONBOARD)
return &card.media_sd_spi;
#elif SHARED_VOLUME_IS(USB_FLASH_DRIVE)
return &card.media_usbFlashDrive;
#endif
#else
return diskIODriver();
#endif
}
bool GetCapacity(uint32_t *pBlockNum, uint16_t *pBlockSize) { bool GetCapacity(uint32_t *pBlockNum, uint16_t *pBlockSize) {
*pBlockNum = card.getSd2Card().cardSize(); *pBlockNum = diskIODriver()->cardSize();
*pBlockSize = BLOCK_SIZE; *pBlockSize = BLOCK_SIZE;
return true; return true;
} }
bool Write(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) { bool Write(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
auto sd2card = card.getSd2Card(); auto sd2card = diskIODriver();
// single block // single block
if (blkLen == 1) { if (blkLen == 1) {
watchdog_refresh(); watchdog_refresh();
sd2card.writeBlock(blkAddr, pBuf); sd2card->writeBlock(blkAddr, pBuf);
return true; return true;
} }
// multi block optmization // multi block optmization
sd2card.writeStart(blkAddr, blkLen); sd2card->writeStart(blkAddr, blkLen);
while (blkLen--) { while (blkLen--) {
watchdog_refresh(); watchdog_refresh();
sd2card.writeData(pBuf); sd2card->writeData(pBuf);
pBuf += BLOCK_SIZE; pBuf += BLOCK_SIZE;
} }
sd2card.writeStop(); sd2card->writeStop();
return true; return true;
} }
bool Read(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) { bool Read(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
auto sd2card = card.getSd2Card(); auto sd2card = diskIODriver();
// single block // single block
if (blkLen == 1) { if (blkLen == 1) {
watchdog_refresh(); watchdog_refresh();
sd2card.readBlock(blkAddr, pBuf); sd2card->readBlock(blkAddr, pBuf);
return true; return true;
} }
// multi block optmization // multi block optmization
sd2card.readStart(blkAddr); sd2card->readStart(blkAddr);
while (blkLen--) { while (blkLen--) {
watchdog_refresh(); watchdog_refresh();
sd2card.readData(pBuf); sd2card->readData(pBuf);
pBuf += BLOCK_SIZE; pBuf += BLOCK_SIZE;
} }
sd2card.readStop(); sd2card->readStop();
return true; return true;
} }
bool IsReady() { bool IsReady() {
return card.isMounted(); return diskIODriver()->isReady();
} }
}; };
@@ -105,8 +117,8 @@ USBMscHandler *pSingleMscHandler = &usbMscHandler;
void MSC_SD_init() { void MSC_SD_init() {
USBDevice.end(); USBDevice.end();
delay(200); delay(200);
USBDevice.begin();
USBDevice.registerMscHandlers(1, &pSingleMscHandler, Marlin_STORAGE_Inquirydata); USBDevice.registerMscHandlers(1, &pSingleMscHandler, Marlin_STORAGE_Inquirydata);
USBDevice.begin();
} }
#endif // __STM32F1__ && HAS_SD_HOST_DRIVE #endif // __STM32F1__ && HAS_SD_HOST_DRIVE

View File

@@ -0,0 +1,390 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "../../../inc/MarlinConfig.h"
#if HAS_LTDC_TFT
#include "tft_ltdc.h"
#include "pinconfig.h"
#define FRAME_BUFFER_ADDRESS 0XC0000000 // SDRAM address
#define SDRAM_TIMEOUT ((uint32_t)0xFFFF)
#define REFRESH_COUNT ((uint32_t)0x02A5) // SDRAM refresh counter
#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000)
#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001)
#define SDRAM_MODEREG_BURST_LENGTH_4 ((uint16_t)0x0002)
#define SDRAM_MODEREG_BURST_LENGTH_8 ((uint16_t)0x0004)
#define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000)
#define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008)
#define SDRAM_MODEREG_CAS_LATENCY_2 ((uint16_t)0x0020)
#define SDRAM_MODEREG_CAS_LATENCY_3 ((uint16_t)0x0030)
#define SDRAM_MODEREG_OPERATING_MODE_STANDARD ((uint16_t)0x0000)
#define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
#define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200)
void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) {
__IO uint32_t tmpmrd =0;
/* Step 1: Configure a clock configuration enable command */
Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
Command->AutoRefreshNumber = 1;
Command->ModeRegisterDefinition = 0;
/* Send the command */
HAL_SDRAM_SendCommand(hsdram, Command, SDRAM_TIMEOUT);
/* Step 2: Insert 100 us minimum delay */
/* Inserted delay is equal to 1 ms due to systick time base unit (ms) */
HAL_Delay(1);
/* Step 3: Configure a PALL (precharge all) command */
Command->CommandMode = FMC_SDRAM_CMD_PALL;
Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
Command->AutoRefreshNumber = 1;
Command->ModeRegisterDefinition = 0;
/* Send the command */
HAL_SDRAM_SendCommand(hsdram, Command, SDRAM_TIMEOUT);
/* Step 4 : Configure a Auto-Refresh command */
Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
Command->AutoRefreshNumber = 8;
Command->ModeRegisterDefinition = 0;
/* Send the command */
HAL_SDRAM_SendCommand(hsdram, Command, SDRAM_TIMEOUT);
/* Step 5: Program the external memory mode register */
tmpmrd = (uint32_t)(SDRAM_MODEREG_BURST_LENGTH_1 |
SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |
SDRAM_MODEREG_CAS_LATENCY_2 |
SDRAM_MODEREG_OPERATING_MODE_STANDARD |
SDRAM_MODEREG_WRITEBURST_MODE_SINGLE);
Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
Command->AutoRefreshNumber = 1;
Command->ModeRegisterDefinition = tmpmrd;
/* Send the command */
HAL_SDRAM_SendCommand(hsdram, Command, SDRAM_TIMEOUT);
/* Step 6: Set the refresh rate counter */
/* Set the device refresh rate */
HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT);
}
void SDRAM_Config() {
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_FMC_CLK_ENABLE();
SDRAM_HandleTypeDef hsdram;
FMC_SDRAM_TimingTypeDef SDRAM_Timing;
FMC_SDRAM_CommandTypeDef command;
/* Configure the SDRAM device */
hsdram.Instance = FMC_SDRAM_DEVICE;
hsdram.Init.SDBank = FMC_SDRAM_BANK1;
hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9;
hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13;
hsdram.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_2;
hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
hsdram.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
/* Timing configuration for 100Mhz as SDRAM clock frequency (System clock is up to 200Mhz) */
SDRAM_Timing.LoadToActiveDelay = 2;
SDRAM_Timing.ExitSelfRefreshDelay = 8;
SDRAM_Timing.SelfRefreshTime = 6;
SDRAM_Timing.RowCycleDelay = 6;
SDRAM_Timing.WriteRecoveryTime = 2;
SDRAM_Timing.RPDelay = 2;
SDRAM_Timing.RCDDelay = 2;
/* Initialize the SDRAM controller */
if (HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK)
{
/* Initialization Error */
}
/* Program the SDRAM external device */
SDRAM_Initialization_Sequence(&hsdram, &command);
}
void LTDC_Config() {
__HAL_RCC_LTDC_CLK_ENABLE();
__HAL_RCC_DMA2D_CLK_ENABLE();
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* The PLL3R is configured to provide the LTDC PCLK clock */
/* PLL3_VCO Input = HSE_VALUE / PLL3M = 25Mhz / 5 = 5 Mhz */
/* PLL3_VCO Output = PLL3_VCO Input * PLL3N = 5Mhz * 160 = 800 Mhz */
/* PLLLCDCLK = PLL3_VCO Output/PLL3R = 800Mhz / 16 = 50Mhz */
/* LTDC clock frequency = PLLLCDCLK = 50 Mhz */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLL3.PLL3M = 5;
PeriphClkInitStruct.PLL3.PLL3N = 160;
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
PeriphClkInitStruct.PLL3.PLL3P = 2;
PeriphClkInitStruct.PLL3.PLL3Q = 2;
PeriphClkInitStruct.PLL3.PLL3R = (800 / LTDC_LCD_CLK);
PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOWIDE;
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_2;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
LTDC_HandleTypeDef hltdc_F;
LTDC_LayerCfgTypeDef pLayerCfg;
/* LTDC Initialization -------------------------------------------------------*/
/* Polarity configuration */
/* Initialize the horizontal synchronization polarity as active low */
hltdc_F.Init.HSPolarity = LTDC_HSPOLARITY_AL;
/* Initialize the vertical synchronization polarity as active low */
hltdc_F.Init.VSPolarity = LTDC_VSPOLARITY_AL;
/* Initialize the data enable polarity as active low */
hltdc_F.Init.DEPolarity = LTDC_DEPOLARITY_AL;
/* Initialize the pixel clock polarity as input pixel clock */
hltdc_F.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
/* Timing configuration */
hltdc_F.Init.HorizontalSync = (LTDC_LCD_HSYNC - 1);
hltdc_F.Init.VerticalSync = (LTDC_LCD_VSYNC - 1);
hltdc_F.Init.AccumulatedHBP = (LTDC_LCD_HSYNC + LTDC_LCD_HBP - 1);
hltdc_F.Init.AccumulatedVBP = (LTDC_LCD_VSYNC + LTDC_LCD_VBP - 1);
hltdc_F.Init.AccumulatedActiveH = (TFT_HEIGHT + LTDC_LCD_VSYNC + LTDC_LCD_VBP - 1);
hltdc_F.Init.AccumulatedActiveW = (TFT_WIDTH + LTDC_LCD_HSYNC + LTDC_LCD_HBP - 1);
hltdc_F.Init.TotalHeigh = (TFT_HEIGHT + LTDC_LCD_VSYNC + LTDC_LCD_VBP + LTDC_LCD_VFP - 1);
hltdc_F.Init.TotalWidth = (TFT_WIDTH + LTDC_LCD_HSYNC + LTDC_LCD_HBP + LTDC_LCD_HFP - 1);
/* Configure R,G,B component values for LCD background color : all black background */
hltdc_F.Init.Backcolor.Blue = 0;
hltdc_F.Init.Backcolor.Green = 0;
hltdc_F.Init.Backcolor.Red = 0;
hltdc_F.Instance = LTDC;
/* Layer0 Configuration ------------------------------------------------------*/
/* Windowing configuration */
pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = TFT_WIDTH;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = TFT_HEIGHT;
/* Pixel Format configuration*/
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
/* Start Address configuration : frame buffer is located at SDRAM memory */
pLayerCfg.FBStartAdress = (uint32_t)(FRAME_BUFFER_ADDRESS);
/* Alpha constant (255 == totally opaque) */
pLayerCfg.Alpha = 255;
/* Default Color configuration (configure A,R,G,B component values) : no background color */
pLayerCfg.Alpha0 = 0; /* fully transparent */
pLayerCfg.Backcolor.Blue = 0;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
/* Configure blending factors */
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
/* Configure the number of lines and number of pixels per line */
pLayerCfg.ImageWidth = TFT_WIDTH;
pLayerCfg.ImageHeight = TFT_HEIGHT;
/* Configure the LTDC */
if (HAL_LTDC_Init(&hltdc_F) != HAL_OK)
{
/* Initialization Error */
}
/* Configure the Layer*/
if (HAL_LTDC_ConfigLayer(&hltdc_F, &pLayerCfg, 0) != HAL_OK)
{
/* Initialization Error */
}
}
uint16_t TFT_LTDC::x_min = 0;
uint16_t TFT_LTDC::x_max = 0;
uint16_t TFT_LTDC::y_min = 0;
uint16_t TFT_LTDC::y_max = 0;
uint16_t TFT_LTDC::x_cur = 0;
uint16_t TFT_LTDC::y_cur = 0;
uint8_t TFT_LTDC::reg = 0;
volatile uint16_t* TFT_LTDC::framebuffer = (volatile uint16_t* )FRAME_BUFFER_ADDRESS;
void TFT_LTDC::Init() {
// SDRAM pins init
for (uint16_t i = 0; PinMap_SDRAM[i].pin != NC; i++)
pinmap_pinout(PinMap_SDRAM[i].pin, PinMap_SDRAM);
// SDRAM peripheral config
SDRAM_Config();
// LTDC pins init
for (uint16_t i = 0; PinMap_LTDC[i].pin != NC; i++)
pinmap_pinout(PinMap_LTDC[i].pin, PinMap_LTDC);
// LTDC peripheral config
LTDC_Config();
}
uint32_t TFT_LTDC::GetID() {
return 0xABAB;
}
uint32_t TFT_LTDC::ReadID(tft_data_t Reg) {
return 0xABAB;
}
bool TFT_LTDC::isBusy() {
return false;
}
uint16_t TFT_LTDC::ReadPoint(uint16_t x, uint16_t y) {
return framebuffer[(TFT_WIDTH * y) + x];
}
void TFT_LTDC::DrawPoint(uint16_t x, uint16_t y, uint16_t color) {
framebuffer[(TFT_WIDTH * y) + x] = color;
}
void TFT_LTDC::DrawRect(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color) {
if (sx == ex || sy == ey) return;
uint16_t offline = TFT_WIDTH - (ex - sx);
uint32_t addr = (uint32_t)&framebuffer[(TFT_WIDTH * sy) + sx];
DMA2D->CR &= ~(1 << 0);
DMA2D->CR = 3 << 16;
DMA2D->OPFCCR = 0X02;
DMA2D->OOR = offline;
DMA2D->OMAR = addr;
DMA2D->NLR = (ey - sy) | ((ex - sx) << 16);
DMA2D->OCOLR = color;
DMA2D->CR |= 1<<0;
uint32_t timeout = 0;
while((DMA2D->ISR & (1<<1)) == 0)
{
timeout++;
if(timeout>0X1FFFFF)break;
}
DMA2D->IFCR |= 1<<1;
}
void TFT_LTDC::DrawImage(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t *colors) {
if (sx == ex || sy == ey) return;
uint16_t offline = TFT_WIDTH - (ex - sx);
uint32_t addr = (uint32_t)&framebuffer[(TFT_WIDTH * sy) + sx];
DMA2D->CR &= ~(1 << 0);
DMA2D->CR = 0 << 16;
DMA2D->FGPFCCR = 0X02;
DMA2D->FGOR = 0;
DMA2D->OOR = offline;
DMA2D->FGMAR = (uint32_t)colors;
DMA2D->OMAR = addr;
DMA2D->NLR = (ey - sy) | ((ex - sx) << 16);
DMA2D->CR |= 1<<0;
uint32_t timeout = 0;
while((DMA2D->ISR & (1<<1)) == 0)
{
timeout++;
if(timeout>0X1FFFFF)break;
}
DMA2D->IFCR |= 1<<1;
}
void TFT_LTDC::WriteData(uint16_t data) {
switch (reg) {
case 0x01: x_cur = x_min = data; return;
case 0x02: x_max = data; return;
case 0x03: y_cur = y_min = data; return;
case 0x04: y_max = data; return;
}
Transmit(data);
}
void TFT_LTDC::Transmit(tft_data_t Data) {
DrawPoint(x_cur, y_cur, Data);
x_cur++;
if (x_cur > x_max) {
x_cur = x_min;
y_cur++;
if (y_cur > y_max) y_cur = y_min;
}
}
void TFT_LTDC::WriteReg(uint16_t Reg) {
reg = Reg;
}
void TFT_LTDC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
while (x_cur != x_min && Count) {
Transmit(*Data);
if (MemoryIncrease == DMA_PINC_ENABLE) Data++;
Count--;
}
uint16_t width = x_max - x_min + 1;
uint16_t height = Count / width;
uint16_t x_end_cnt = Count - (width * height);
if (height) {
if (MemoryIncrease == DMA_PINC_ENABLE) {
DrawImage(x_min, y_cur, x_min + width, y_cur + height, Data);
Data += width * height;
} else {
DrawRect(x_min, y_cur, x_min + width, y_cur + height, *Data);
}
y_cur += height;
}
while (x_end_cnt) {
Transmit(*Data);
if (MemoryIncrease == DMA_PINC_ENABLE) Data++;
x_end_cnt--;
}
}
#endif // HAS_LTDC_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

View File

@@ -0,0 +1,155 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../../../inc/MarlinConfig.h"
#ifdef STM32H7xx
#include "stm32h7xx_hal.h"
#else
#error "LTDC TFT is currently only supported on STM32H7 hardware."
#endif
#define DATASIZE_8BIT SPI_DATASIZE_8BIT
#define DATASIZE_16BIT SPI_DATASIZE_16BIT
#define TFT_IO_DRIVER TFT_LTDC
#define TFT_DATASIZE DATASIZE_16BIT
typedef uint16_t tft_data_t;
class TFT_LTDC {
private:
static volatile uint16_t *framebuffer;
static uint16_t x_min, x_max, y_min, y_max, x_cur, y_cur;
static uint8_t reg;
static uint32_t ReadID(tft_data_t Reg);
static uint16_t ReadPoint(uint16_t x, uint16_t y);
static void DrawPoint(uint16_t x, uint16_t y, uint16_t color);
static void DrawRect(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color);
static void DrawImage(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t *colors);
static void Transmit(tft_data_t Data);
static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
public:
static void Init();
static uint32_t GetID();
static bool isBusy();
static void Abort() { /*__HAL_DMA_DISABLE(&DMAtx);*/ }
static void DataTransferBegin(uint16_t DataWidth = TFT_DATASIZE) {}
static void DataTransferEnd() {};
static void WriteData(uint16_t Data);
static void WriteReg(uint16_t Reg);
static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_ENABLE, Data, Count); }
static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_PINC_DISABLE, &Data, Count); }
static void WriteMultiple(uint16_t Color, uint32_t Count) {
static uint16_t Data; Data = Color;
while (Count > 0) {
TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
}
}
};
const PinMap PinMap_LTDC[] = {
{PF_10, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_DE
{PG_7, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_CLK
{PI_9, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_VSYNC
{PI_10, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_HSYNC
{PG_6, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_R7
{PH_12, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_R6
{PH_11, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_R5
{PH_10, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_R4
{PH_9, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_R3
{PI_2, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_G7
{PI_1, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_G6
{PI_0, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_G5
{PH_15, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_G4
{PH_14, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_G3
{PH_13, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_G2
{PI_7, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_B7
{PI_6, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_B6
{PI_5, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_B5
{PI_4, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_B4
{PG_11, LTDC, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_LTDC)}, // LCD_B3
{NC, NP, 0}
};
const PinMap PinMap_SDRAM[] = {
{PC_0, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_SDNWE
{PC_2, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_SDNE0
{PC_3, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_SDCKE0
{PE_0, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_NBL0
{PE_1, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_NBL1
{PF_11, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_SDNRAS
{PG_8, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_SDCLK
{PG_15, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_SDNCAS
{PG_4, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_BA0
{PG_5, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_BA1
{PD_14, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D0
{PD_15, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D1
{PD_0, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D2
{PD_1, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D3
{PE_7, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D4
{PE_8, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D5
{PE_9, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D6
{PE_10, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D7
{PE_11, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D8
{PE_12, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D9
{PE_13, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D10
{PE_14, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D11
{PE_15, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D12
{PD_8, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D13
{PD_9, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D14
{PD_10, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_D15
{PF_0, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A0
{PF_1, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A1
{PF_2, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A2
{PF_3, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A3
{PF_4, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A4
{PF_5, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A5
{PF_12, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A6
{PF_13, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A7
{PF_14, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A8
{PF_15, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A9
{PG_0, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A10
{PG_1, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A11
{PG_2, FMC_Bank1_R, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_FMC)}, // FMC_A12
{NC, NP, 0}
};
const PinMap PinMap_QUADSPI[] = {
{PB_2, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_CLK
{PB_10, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_NCS
{PF_6, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO3
{PF_7, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO2
{PF_8, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO0
{PF_9, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO1
{NC, NP, 0}
};

View File

@@ -74,7 +74,7 @@
#elif defined(STM32F401xC) || defined(STM32F401xE) #elif defined(STM32F401xC) || defined(STM32F401xE)
#define MCU_STEP_TIMER 9 #define MCU_STEP_TIMER 9
#define MCU_TEMP_TIMER 10 #define MCU_TEMP_TIMER 10
#elif defined(STM32F4xx) || defined(STM32F7xx) #elif defined(STM32F4xx) || defined(STM32F7xx) || defined(STM32H7xx)
#define MCU_STEP_TIMER 6 // STM32F401 has no TIM6, TIM7, or TIM8 #define MCU_STEP_TIMER 6 // STM32F401 has no TIM6, TIM7, or TIM8
#define MCU_TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used. #define MCU_TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used.
#endif #endif

View File

@@ -110,7 +110,7 @@ uint8_t BulkStorage::Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t bl
} }
uint8_t BulkStorage::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t * buf) { uint8_t BulkStorage::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t * buf) {
return USBH_MSC_Write(&hUsbHost, lun, addr, const_cast <uint8_t*>(buf), blocks) != USBH_OK; return USBH_MSC_Write(&hUsbHost, lun, addr, const_cast<uint8_t*>(buf), blocks) != USBH_OK;
} }
#endif // USE_OTG_USB_HOST && USBHOST #endif // USE_OTG_USB_HOST && USBHOST

View File

@@ -84,7 +84,7 @@
#if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE #if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
USBSerial SerialUSB; USBSerial SerialUSB;
DefaultSerial MSerial(true, SerialUSB); DefaultSerial1 MSerial0(true, SerialUSB);
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
#include "../libmaple/usb/stm32f1/usb_reg_map.h" #include "../libmaple/usb/stm32f1/usb_reg_map.h"
@@ -107,7 +107,7 @@
len = usb_cdcacm_peek(buf, total); len = usb_cdcacm_peek(buf, total);
for (uint32 i = 0; i < len; i++) for (uint32 i = 0; i < len; i++)
emergency_parser.update(MSerial.emergency_state, buf[i + total - len]); emergency_parser.update(MSerial0.emergency_state, buf[i + total - len]);
} }
#endif #endif
#endif #endif
@@ -132,6 +132,9 @@ const uint8_t adc_pins[] = {
#if HAS_TEMP_CHAMBER #if HAS_TEMP_CHAMBER
TEMP_CHAMBER_PIN, TEMP_CHAMBER_PIN,
#endif #endif
#if HAS_TEMP_COOLER
TEMP_COOLER_PIN,
#endif
#if HAS_TEMP_ADC_1 #if HAS_TEMP_ADC_1
TEMP_1_PIN, TEMP_1_PIN,
#endif #endif
@@ -189,6 +192,9 @@ enum TempPinIndex : char {
#if HAS_TEMP_CHAMBER #if HAS_TEMP_CHAMBER
TEMP_CHAMBER, TEMP_CHAMBER,
#endif #endif
#if HAS_TEMP_COOLER
TEMP_COOLER_PIN,
#endif
#if HAS_TEMP_ADC_1 #if HAS_TEMP_ADC_1
TEMP_1, TEMP_1,
#endif #endif
@@ -385,6 +391,9 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
#if HAS_TEMP_CHAMBER #if HAS_TEMP_CHAMBER
case TEMP_CHAMBER_PIN: pin_index = TEMP_CHAMBER; break; case TEMP_CHAMBER_PIN: pin_index = TEMP_CHAMBER; break;
#endif #endif
#if HAS_TEMP_COOLER
case TEMP_COOLER_PIN: pin_index = TEMP_COOLER; break;
#endif
#if HAS_TEMP_ADC_1 #if HAS_TEMP_ADC_1
case TEMP_1_PIN: pin_index = TEMP_1; break; case TEMP_1_PIN: pin_index = TEMP_1; break;
#endif #endif
@@ -444,6 +453,8 @@ void analogWrite(pin_t pin, int pwm_val8) {
analogWrite(uint8_t(pin), pwm_val8); analogWrite(uint8_t(pin), pwm_val8);
} }
void flashFirmware(const int16_t) { nvic_sys_reset(); } void HAL_reboot() { nvic_sys_reset(); }
void flashFirmware(const int16_t) { HAL_reboot(); }
#endif // __STM32F1__ #endif // __STM32F1__

View File

@@ -53,7 +53,7 @@
// ------------------------ // ------------------------
#ifndef STM32_FLASH_SIZE #ifndef STM32_FLASH_SIZE
#if EITHER(MCU_STM32F103RE, MCU_STM32F103VE) #if ANY(MCU_STM32F103RE, MCU_STM32F103VE, MCU_STM32F103ZE)
#define STM32_FLASH_SIZE 512 #define STM32_FLASH_SIZE 512
#else #else
#define STM32_FLASH_SIZE 256 #define STM32_FLASH_SIZE 256
@@ -61,11 +61,11 @@
#endif #endif
#ifdef SERIAL_USB #ifdef SERIAL_USB
typedef ForwardSerial0Type< USBSerial > DefaultSerial; typedef ForwardSerial1Class< USBSerial > DefaultSerial1;
extern DefaultSerial MSerial; extern DefaultSerial1 MSerial0;
#if !HAS_SD_HOST_DRIVE #if !HAS_SD_HOST_DRIVE
#define UsbSerial MSerial #define UsbSerial MSerial0
#else #else
#define UsbSerial MarlinCompositeSerial #define UsbSerial MarlinCompositeSerial
#endif #endif
@@ -81,24 +81,30 @@
#endif #endif
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 UsbSerial #define MYSERIAL1 UsbSerial
#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS) #elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
#elif NUM_UARTS == 5
#error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else #else
#error "SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #define MYSERIAL1 MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "SERIAL_PORT must be from 1 to 5. You can also use -1 if the board supports Native USB."
#else
#error "SERIAL_PORT must be from 1 to 3. You can also use -1 if the board supports Native USB."
#endif
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 #if SERIAL_PORT_2 == -1
#define MYSERIAL1 UsbSerial #define MYSERIAL2 UsbSerial
#elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS) #elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#elif NUM_UARTS == 5
#error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
#else #else
#error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration." #define MYSERIAL2 MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "SERIAL_PORT_2 must be from 1 to 5. You can also use -1 if the board supports Native USB."
#else
#error "SERIAL_PORT_2 must be from 1 to 3. You can also use -1 if the board supports Native USB."
#endif
#endif #endif
#endif #endif
@@ -107,10 +113,13 @@
#define MMU2_SERIAL UsbSerial #define MMU2_SERIAL UsbSerial
#elif WITHIN(MMU2_SERIAL_PORT, 1, NUM_UARTS) #elif WITHIN(MMU2_SERIAL_PORT, 1, NUM_UARTS)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT) #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#elif NUM_UARTS == 5
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else #else
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #define MMU2_SERIAL MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "MMU2_SERIAL_PORT must be from 1 to 5. You can also use -1 if the board supports Native USB."
#else
#error "MMU2_SERIAL_PORT must be from 1 to 3. You can also use -1 if the board supports Native USB."
#endif
#endif #endif
#endif #endif
@@ -119,10 +128,13 @@
#define LCD_SERIAL UsbSerial #define LCD_SERIAL UsbSerial
#elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS) #elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#elif NUM_UARTS == 5
#error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else #else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #define LCD_SERIAL MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "LCD_SERIAL_PORT must be from 1 to 5. You can also use -1 if the board supports Native USB."
#else
#error "LCD_SERIAL_PORT must be from 1 to 3. You can also use -1 if the board supports Native USB."
#endif
#endif #endif
#if HAS_DGUS_LCD #if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
@@ -195,7 +207,7 @@ void HAL_clear_reset_source();
// Reset reason // Reset reason
uint8_t HAL_get_reset_source(); uint8_t HAL_get_reset_source();
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
void _delay_ms(const int delay); void _delay_ms(const int delay);

View File

@@ -44,8 +44,8 @@ static void TXBegin() {
#warning "Using POSTMORTEM_DEBUGGING requires a physical U(S)ART hardware in case of severe error." #warning "Using POSTMORTEM_DEBUGGING requires a physical U(S)ART hardware in case of severe error."
#warning "Disabling the severe error reporting feature currently because the used serial port is not a HW port." #warning "Disabling the severe error reporting feature currently because the used serial port is not a HW port."
#else #else
// We use MYSERIAL0 here, so we need to figure out how to get the linked register // We use MYSERIAL1 here, so we need to figure out how to get the linked register
struct usart_dev* dev = MYSERIAL0.c_dev(); struct usart_dev* dev = MYSERIAL1.c_dev();
// Or use this if removing libmaple // Or use this if removing libmaple
// int irq = dev->irq_num; // int irq = dev->irq_num;
@@ -80,7 +80,7 @@ static void TXBegin() {
#define sw_barrier() __asm__ volatile("": : :"memory"); #define sw_barrier() __asm__ volatile("": : :"memory");
static void TX(char c) { static void TX(char c) {
#if WITHIN(SERIAL_PORT, 1, 6) #if WITHIN(SERIAL_PORT, 1, 6)
struct usart_dev* dev = MYSERIAL0.c_dev(); struct usart_dev* dev = MYSERIAL1.c_dev();
while (!(dev->regs->SR & USART_SR_TXE)) { while (!(dev->regs->SR & USART_SR_TXE)) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh()); TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
sw_barrier(); sw_barrier();

View File

@@ -123,7 +123,7 @@ uint8_t spiRec() {
* *
* @details Uses DMA * @details Uses DMA
*/ */
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
} }
@@ -146,7 +146,7 @@ void spiSend(uint8_t b) {
* *
* @details Use DMA * @details Use DMA
*/ */
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPI.send(token); SPI.send(token);
SPI.dmaSend(const_cast<uint8_t*>(buf), 512); SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
} }
@@ -160,7 +160,7 @@ uint8_t spiRec(uint32_t chan) { return SPI.transfer(0xFF); }
void spiSend(uint32_t chan, byte b) { SPI.send(b); } void spiSend(uint32_t chan, byte b) { SPI.send(b); }
// Write buffer to specified SPI channel // Write buffer to specified SPI channel
void spiSend(uint32_t chan, const uint8_t* buf, size_t n) { void spiSend(uint32_t chan, const uint8_t *buf, size_t n) {
for (size_t p = 0; p < n; p++) spiSend(chan, buf[p]); for (size_t p = 0; p < n; p++) spiSend(chan, buf[p]);
} }

View File

@@ -60,7 +60,7 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
} }
else if (srflags & USART_SR_ORE) { else if (srflags & USART_SR_ORE) {
// overrun and empty data, just do a dummy read to clear ORE // overrun and empty data, just do a dummy read to clear ORE
// and prevent a raise condition where a continous interrupt stream (due to ORE set) occurs // and prevent a raise condition where a continuous interrupt stream (due to ORE set) occurs
// (see chapter "Overrun error" ) in STM32 reference manual // (see chapter "Overrun error" ) in STM32 reference manual
regs->DR; regs->DR;
} }
@@ -134,12 +134,12 @@ constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; }
// If you encounter this error, replace SerialX with MSerialX, for example MSerial3. // If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
// Non-TMC ports were already validated in HAL.h, so do not require verbose error messages. // Non-TMC ports were already validated in HAL.h, so do not require verbose error messages.
#ifdef MYSERIAL0
CHECK_CFG_SERIAL(MYSERIAL0);
#endif
#ifdef MYSERIAL1 #ifdef MYSERIAL1
CHECK_CFG_SERIAL(MYSERIAL1); CHECK_CFG_SERIAL(MYSERIAL1);
#endif #endif
#ifdef MYSERIAL2
CHECK_CFG_SERIAL(MYSERIAL2);
#endif
#ifdef LCD_SERIAL #ifdef LCD_SERIAL
CHECK_CFG_SERIAL(LCD_SERIAL); CHECK_CFG_SERIAL(LCD_SERIAL);
#endif #endif

View File

@@ -47,7 +47,7 @@ struct MarlinSerial : public HardwareSerial {
#endif #endif
}; };
typedef Serial0Type<MarlinSerial> MSerialT; typedef Serial1Class<MarlinSerial> MSerialT;
extern MSerialT MSerial1; extern MSerialT MSerial1;
extern MSerialT MSerial2; extern MSerialT MSerial2;

View File

@@ -19,14 +19,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* *
*/ */
#ifdef __STM32F1__
/** /**
* PersistentStore for Arduino-style EEPROM interface * PersistentStore for Arduino-style EEPROM interface
* with simple implementations supplied by Marlin. * with simple implementations supplied by Marlin.
*/ */
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ENABLED(IIC_BL24CXX_EEPROM) #if ENABLED(IIC_BL24CXX_EEPROM)
@@ -48,13 +47,11 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
size_t written = 0; uint16_t written = 0;
while (size--) { while (size--) {
uint8_t v = *value; uint8_t v = *value;
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {

View File

@@ -48,8 +48,8 @@ static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
static bool eeprom_dirty = false; static bool eeprom_dirty = false;
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
const uint32_t* source = reinterpret_cast<const uint32_t*>(EEPROM_PAGE0_BASE); const uint32_t *source = reinterpret_cast<const uint32_t*>(EEPROM_PAGE0_BASE);
uint32_t* destination = reinterpret_cast<uint32_t*>(ram_eeprom); uint32_t *destination = reinterpret_cast<uint32_t*>(ram_eeprom);
static_assert(0 == (MARLIN_EEPROM_SIZE) % 4, "MARLIN_EEPROM_SIZE is corrupted. (Must be a multiple of 4.)"); // Ensure copying as uint32_t is safe static_assert(0 == (MARLIN_EEPROM_SIZE) % 4, "MARLIN_EEPROM_SIZE is corrupted. (Must be a multiple of 4.)"); // Ensure copying as uint32_t is safe
constexpr size_t eeprom_size_u32 = (MARLIN_EEPROM_SIZE) / 4; constexpr size_t eeprom_size_u32 = (MARLIN_EEPROM_SIZE) / 4;

View File

@@ -40,7 +40,7 @@ void eeprom_init() { BL24CXX::init(); }
// Public functions // Public functions
// ------------------------ // ------------------------
void eeprom_write_byte(uint8_t *pos, unsigned char value) { void eeprom_write_byte(uint8_t *pos, uint8_t value) {
const unsigned eeprom_address = (unsigned)pos; const unsigned eeprom_address = (unsigned)pos;
return BL24CXX::writeOneByte(eeprom_address, value); return BL24CXX::writeOneByte(eeprom_address, value);
} }

View File

@@ -52,13 +52,13 @@ bool PersistentStore::access_start() {
} }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -24,7 +24,7 @@
#define PRODUCT_ID 0x29 #define PRODUCT_ID 0x29
USBMassStorage MarlinMSC; USBMassStorage MarlinMSC;
Serial0Type<USBCompositeSerial> MarlinCompositeSerial(true); Serial1Class<USBCompositeSerial> MarlinCompositeSerial(true);
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
@@ -43,10 +43,10 @@ Serial0Type<USBCompositeSerial> MarlinCompositeSerial(true);
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
// The original callback is not called (no way to retrieve address). // The original callback is not called (no way to retrieve address).
// That callback detects a special STM32 reset sequence: this functionality is not essential // That callback detects a special STM32 reset sequence: this functionality is not essential
// as M997 achieves the same. // as M997 achieves the same.
void my_rx_callback(unsigned int, void*) { void my_rx_callback(unsigned int, void*) {
// max length of 16 is enough to contain all emergency commands // max length of 16 is enough to contain all emergency commands
uint8 buf[16]; uint8 buf[16];
@@ -62,7 +62,8 @@ void my_rx_callback(unsigned int, void*) {
for (uint32 i = 0; i < len; i++) for (uint32 i = 0; i < len; i++)
emergency_parser.update(MarlinCompositeSerial.emergency_state, buf[i+total-len]); emergency_parser.update(MarlinCompositeSerial.emergency_state, buf[i+total-len]);
} }
#endif #endif
void MSC_SD_init() { void MSC_SD_init() {

View File

@@ -21,6 +21,6 @@
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
extern USBMassStorage MarlinMSC; extern USBMassStorage MarlinMSC;
extern Serial0Type<USBCompositeSerial> MarlinCompositeSerial; extern Serial1Class<USBCompositeSerial> MarlinCompositeSerial;
void MSC_SD_init(); void MSC_SD_init();

View File

@@ -48,7 +48,7 @@ DRESULT disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
#endif #endif
#if _DISKIO_IOCTL #if _DISKIO_IOCTL
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff); DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff);
#endif #endif
/* Disk Status Bits (DSTATUS) */ /* Disk Status Bits (DSTATUS) */

View File

@@ -31,7 +31,13 @@
#include <Wire.h> #include <Wire.h>
DefaultSerial MSerial(false); #define _IMPLEMENT_SERIAL(X) DefaultSerial##X MSerial##X(false, Serial##X)
#define IMPLEMENT_SERIAL(X) _IMPLEMENT_SERIAL(X)
#if WITHIN(SERIAL_PORT, 0, 3)
IMPLEMENT_SERIAL(SERIAL_PORT);
#else
#error "SERIAL_PORT must be from 0 to 3."
#endif
USBSerialType USBSerial(false, SerialUSB); USBSerialType USBSerial(false, SerialUSB);
uint16_t HAL_adc_result; uint16_t HAL_adc_result;
@@ -72,6 +78,8 @@ uint8_t HAL_get_reset_source() {
return 0; return 0;
} }
void HAL_reboot() { _reboot_Teensyduino_(); }
extern "C" { extern "C" {
extern char __bss_end; extern char __bss_end;
extern char __heap_start; extern char __heap_start;

View File

@@ -34,7 +34,6 @@
#include "fastio.h" #include "fastio.h"
#include "watchdog.h" #include "watchdog.h"
#include <stdint.h> #include <stdint.h>
#define ST7920_DELAY_1 DELAY_NS(600) #define ST7920_DELAY_1 DELAY_NS(600)
@@ -51,19 +50,24 @@
#endif #endif
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef Serial0Type<decltype(Serial)> DefaultSerial;
extern DefaultSerial MSerial; #define Serial0 Serial
typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType; #define _DECLARE_SERIAL(X) \
typedef ForwardSerial1Class<decltype(Serial##X)> DefaultSerial##X; \
extern DefaultSerial##X MSerial##X
#define DECLARE_SERIAL(X) _DECLARE_SERIAL(X)
typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
extern USBSerialType USBSerial; extern USBSerialType USBSerial;
#define _MSERIAL(X) MSerial##X #define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 USBSerial #define MYSERIAL1 USBSerial
#elif WITHIN(SERIAL_PORT, 0, 3) #elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) DECLARE_SERIAL(SERIAL_PORT);
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#endif #endif
#define HAL_SERVO_LIB libServo #define HAL_SERVO_LIB libServo
@@ -88,7 +92,7 @@ void HAL_clear_reset_source();
// Get the reason for the reset // Get the reason for the reset
uint8_t HAL_get_reset_source(); uint8_t HAL_get_reset_source();
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); } FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }

View File

@@ -82,7 +82,7 @@ uint8_t spiRec() {
} }
// SPI read data // SPI read data
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.transfer(buf, nbyte); SPI.transfer(buf, nbyte);
SPI.endTransaction(); SPI.endTransaction();
@@ -107,7 +107,7 @@ void spiSend(uint8_t b) {
} }
// SPI send block // SPI send block
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPDR = token; SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) { for (uint16_t i = 0; i < 512; i += 2) {

View File

@@ -18,14 +18,14 @@
*/ */
#ifdef __MK20DX256__ #ifdef __MK20DX256__
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
/** /**
* HAL PersistentStore for Teensy 3.2 (MK20DX256) * HAL PersistentStore for Teensy 3.2 (MK20DX256)
*/ */
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
#include "../shared/eeprom_api.h" #include "../shared/eeprom_api.h"
#include <avr/eeprom.h> #include <avr/eeprom.h>
@@ -38,13 +38,13 @@ bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -31,7 +31,12 @@
#include <Wire.h> #include <Wire.h>
DefaultSerial MSerial(false); #define _IMPLEMENT_SERIAL(X) DefaultSerial##X MSerial##X(false, Serial##X)
#define IMPLEMENT_SERIAL(X) _IMPLEMENT_SERIAL(X)
#if WITHIN(SERIAL_PORT, 0, 3)
IMPLEMENT_SERIAL(SERIAL_PORT);
#endif
USBSerialType USBSerial(false, SerialUSB); USBSerialType USBSerial(false, SerialUSB);
uint16_t HAL_adc_result, HAL_adc_select; uint16_t HAL_adc_result, HAL_adc_select;
@@ -81,6 +86,8 @@ uint8_t HAL_get_reset_source() {
return 0; return 0;
} }
void HAL_reboot() { _reboot_Teensyduino_(); }
extern "C" { extern "C" {
extern char __bss_end; extern char __bss_end;
extern char __heap_start; extern char __heap_start;

View File

@@ -54,19 +54,26 @@
#endif #endif
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef Serial0Type<decltype(Serial)> DefaultSerial;
extern DefaultSerial MSerial; #define Serial0 Serial
typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType; #define _DECLARE_SERIAL(X) \
typedef ForwardSerial1Class<decltype(Serial##X)> DefaultSerial##X; \
extern DefaultSerial##X MSerial##X
#define DECLARE_SERIAL(X) _DECLARE_SERIAL(X)
typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
extern USBSerialType USBSerial; extern USBSerialType USBSerial;
#define _MSERIAL(X) MSerial##X #define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 USBSerial #define MYSERIAL1 USBSerial
#elif WITHIN(SERIAL_PORT, 0, 3) #elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
DECLARE_SERIAL(SERIAL_PORT);
#else
#error "SERIAL_PORT must be from 0 to 3, or -1 for Native USB."
#endif #endif
#define HAL_SERVO_LIB libServo #define HAL_SERVO_LIB libServo
@@ -94,7 +101,7 @@ void HAL_clear_reset_source();
// Reset reason // Reset reason
uint8_t HAL_get_reset_source(); uint8_t HAL_get_reset_source();
inline void HAL_reboot() {} // reboot the board or restart the bootloader void HAL_reboot();
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); } FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }

View File

@@ -80,7 +80,7 @@ uint8_t spiRec() {
//return SPDR; //return SPDR;
} }
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.transfer(buf, nbyte); SPI.transfer(buf, nbyte);
SPI.endTransaction(); SPI.endTransaction();
@@ -103,7 +103,7 @@ void spiSend(uint8_t b) {
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ } //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
} }
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPDR = token; SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) { for (uint16_t i = 0; i < 512; i += 2) {

View File

@@ -42,13 +42,13 @@ bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -32,7 +32,11 @@
#include <Wire.h> #include <Wire.h>
DefaultSerial MSerial(false); #define _IMPLEMENT_SERIAL(X) DefaultSerial##X MSerial##X(false, Serial##X)
#define IMPLEMENT_SERIAL(X) _IMPLEMENT_SERIAL(X)
#if WITHIN(SERIAL_PORT, 0, 3)
IMPLEMENT_SERIAL(SERIAL_PORT);
#endif
USBSerialType USBSerial(false, SerialUSB); USBSerialType USBSerial(false, SerialUSB);
uint16_t HAL_adc_result, HAL_adc_select; uint16_t HAL_adc_result, HAL_adc_select;
@@ -116,6 +120,8 @@ uint8_t HAL_get_reset_source() {
return 0; return 0;
} }
void HAL_reboot() { _reboot_Teensyduino_(); }
#define __bss_end _ebss #define __bss_end _ebss
extern "C" { extern "C" {

View File

@@ -56,32 +56,36 @@
#endif #endif
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
typedef Serial0Type<decltype(Serial)> DefaultSerial; #define Serial0 Serial
extern DefaultSerial MSerial; #define _DECLARE_SERIAL(X) \
typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType; typedef ForwardSerial1Class<decltype(Serial##X)> DefaultSerial##X; \
extern DefaultSerial##X MSerial##X
#define DECLARE_SERIAL(X) _DECLARE_SERIAL(X)
typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
extern USBSerialType USBSerial; extern USBSerialType USBSerial;
#define _MSERIAL(X) MSerial##X #define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
#define MYSERIAL0 SerialUSB #define MYSERIAL1 SerialUSB
#elif WITHIN(SERIAL_PORT, 0, 8) #elif WITHIN(SERIAL_PORT, 0, 8)
#define MYSERIAL0 MSERIAL(SERIAL_PORT) DECLARE_SERIAL(SERIAL_PORT);
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else #else
#error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration." #error "The required SERIAL_PORT must be from 0 to 8, or -1 for Native USB."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 #if SERIAL_PORT_2 == -1
#define MYSERIAL1 usbSerial #define MYSERIAL2 usbSerial
#elif SERIAL_PORT_2 == -2 #elif SERIAL_PORT_2 == -2
#define MYSERIAL1 ethernet.telnetClient #define MYSERIAL2 ethernet.telnetClient
#elif WITHIN(SERIAL_PORT_2, 0, 8) #elif WITHIN(SERIAL_PORT_2, 0, 8)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else #else
#error "SERIAL_PORT_2 must be from -2 to 8. Please update your configuration." #error "SERIAL_PORT_2 must be from 0 to 8, or -1 for Native USB, or -2 for Ethernet."
#endif #endif
#endif #endif
@@ -117,6 +121,8 @@ void HAL_clear_reset_source();
// Reset reason // Reset reason
uint8_t HAL_get_reset_source(); uint8_t HAL_get_reset_source();
void HAL_reboot();
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); } FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
#if GCC_VERSION <= 50000 #if GCC_VERSION <= 50000

View File

@@ -97,7 +97,7 @@ uint8_t spiRec() {
//return SPDR; //return SPDR;
} }
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t *buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPI.transfer(buf, nbyte); SPI.transfer(buf, nbyte);
SPI.endTransaction(); SPI.endTransaction();
@@ -120,7 +120,7 @@ void spiSend(uint8_t b) {
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ } //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
} }
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t *buf) {
SPI.beginTransaction(spiConfig); SPI.beginTransaction(spiConfig);
SPDR = token; SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) { for (uint16_t i = 0; i < 512; i += 2) {

View File

@@ -22,14 +22,14 @@
*/ */
#ifdef __IMXRT1062__ #ifdef __IMXRT1062__
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
/** /**
* HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A) * HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
*/ */
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
#include "../shared/eeprom_api.h" #include "../shared/eeprom_api.h"
#include <avr/eeprom.h> #include <avr/eeprom.h>
@@ -42,13 +42,13 @@ bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) { while (size--) {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value; uint8_t v = *value;
// EEPROM has only ~100,000 write cycles, if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) { if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true; return true;

View File

@@ -150,8 +150,37 @@ void calibrate_delay_loop();
#endif #endif
// Delay in nanoseconds /**************************************************************
#define DELAY_NS(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL) / 1000UL) * Delay in nanoseconds. Requires the F_CPU macro.
* These macros follow avr-libc delay conventions.
*
* For AVR there are three possible operation modes, due to its
* slower clock speeds and thus coarser delay resolution. For
* example, when F_CPU = 16000000 the resolution is 62.5ns.
*
* Round up (default)
* Round up the delay according to the CPU clock resolution.
* e.g., 100 will give a delay of 2 cycles (125ns).
*
* Round down (DELAY_NS_ROUND_DOWN)
* Round down the delay according to the CPU clock resolution.
* e.g., 100 will be rounded down to 1 cycle (62.5ns).
*
* Nearest (DELAY_NS_ROUND_CLOSEST)
* Round the delay to the nearest number of clock cycles.
* e.g., 165 will be rounded up to 3 cycles (187.5ns) because
* it's closer to the requested delay than 2 cycle (125ns).
*/
#ifndef __AVR__
#undef DELAY_NS_ROUND_DOWN
#undef DELAY_NS_ROUND_CLOSEST
#endif
#if ENABLED(DELAY_NS_ROUND_DOWN)
#define DELAY_NS(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL) / 1000UL) // floor
#elif ENABLED(DELAY_NS_ROUND_CLOSEST)
#define DELAY_NS(x) DELAY_CYCLES(((x) * ((F_CPU) / 1000000UL) + 500) / 1000UL) // round
#else
#define DELAY_NS(x) DELAY_CYCLES(((x) * ((F_CPU) / 1000000UL) + 999) / 1000UL) // "ceil"
#endif

View File

@@ -42,7 +42,7 @@ struct MinSerial {
HAL_min_serial_out(ch); HAL_min_serial_out(ch);
} }
// Send String through UART // Send String through UART
static void TX(const char* s) { while (*s) TX(*s++); } static void TX(const char *s) { while (*s) TX(*s++); }
// Send a digit through UART // Send a digit through UART
static void TXDigit(uint32_t d) { static void TXDigit(uint32_t d) {
if (d < 10) TX((char)(d+'0')); if (d < 10) TX((char)(d+'0'));

View File

@@ -71,10 +71,10 @@ void spiSend(uint8_t b);
uint8_t spiRec(); uint8_t spiRec();
// Read from SPI into buffer // Read from SPI into buffer
void spiRead(uint8_t* buf, uint16_t nbyte); 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); 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); void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode);
@@ -87,7 +87,7 @@ void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode);
void spiSend(uint32_t chan, byte b); void spiSend(uint32_t chan, byte b);
// Write buffer to specified SPI channel // Write buffer to specified SPI channel
void spiSend(uint32_t chan, const uint8_t* buf, size_t n); void spiSend(uint32_t chan, const uint8_t *buf, size_t n);
// Read single byte from specified SPI channel // Read single byte from specified SPI channel
uint8_t spiRec(uint32_t chan); uint8_t spiRec(uint32_t chan);

View File

@@ -29,7 +29,7 @@
#include <stdarg.h> #include <stdarg.h>
// Dump a backtrace entry // Dump a backtrace entry
static bool UnwReportOut(void* ctx, const UnwReport* bte) { static bool UnwReportOut(void *ctx, const UnwReport *bte) {
int *p = (int*)ctx; int *p = (int*)ctx;
(*p)++; (*p)++;
@@ -44,7 +44,7 @@ static bool UnwReportOut(void* ctx, const UnwReport* bte) {
} }
#ifdef UNW_DEBUG #ifdef UNW_DEBUG
void UnwPrintf(const char* format, ...) { void UnwPrintf(const char *format, ...) {
char dest[256]; char dest[256];
va_list argptr; va_list argptr;
va_start(argptr, format); va_start(argptr, format);

View File

@@ -114,7 +114,7 @@ typedef struct {
* report function maybe called again in future. If false is returned, * report function maybe called again in future. If false is returned,
* unwinding will stop with UnwindStart() returning UNWIND_TRUNCATED. * unwinding will stop with UnwindStart() returning UNWIND_TRUNCATED.
*/ */
typedef bool (*UnwindReportFunc)(void* data, const UnwReport* bte); typedef bool (*UnwindReportFunc)(void *data, const UnwReport *bte);
/** Structure that holds memory callback function pointers. /** Structure that holds memory callback function pointers.
*/ */

View File

@@ -320,8 +320,8 @@ void hook_cpu_exceptions() {
// So we'll simply mask the top 8 bits of the first handler as an hint of being in the flash or not -that's poor and will // So we'll simply mask the top 8 bits of the first handler as an hint of being in the flash or not -that's poor and will
// probably break if the flash happens to be more than 128MB, but in this case, we are not magician, we need help from outside. // probably break if the flash happens to be more than 128MB, but in this case, we are not magician, we need help from outside.
unsigned long * vecAddr = (unsigned long*)get_vtor(); unsigned long *vecAddr = (unsigned long*)get_vtor();
SERIAL_ECHO("Vector table addr: "); SERIAL_ECHOPGM("Vector table addr: ");
SERIAL_PRINTLN(get_vtor(), HEX); SERIAL_PRINTLN(get_vtor(), HEX);
#ifdef VECTOR_TABLE_SIZE #ifdef VECTOR_TABLE_SIZE
@@ -348,7 +348,7 @@ void hook_cpu_exceptions() {
// 128 bytes alignement is required for writing the VTOR register // 128 bytes alignement is required for writing the VTOR register
alignas(128) static unsigned long vectable[VECTOR_TABLE_SENTINEL]; alignas(128) static unsigned long vectable[VECTOR_TABLE_SENTINEL];
SERIAL_ECHO("Detected vector table size: "); SERIAL_ECHOPGM("Detected vector table size: ");
SERIAL_PRINTLN(vec_size, HEX); SERIAL_PRINTLN(vec_size, HEX);
#endif #endif
@@ -372,7 +372,7 @@ void hook_cpu_exceptions() {
HW_REG(0xE000ED08) = (unsigned long)vectable | _BV32(29); // 29th bit is for telling the CPU the table is now in SRAM (should be present already) HW_REG(0xE000ED08) = (unsigned long)vectable | _BV32(29); // 29th bit is for telling the CPU the table is now in SRAM (should be present already)
SERIAL_ECHOLN("Installed fault handlers"); SERIAL_ECHOLNPGM("Installed fault handlers");
#endif #endif
} }

View File

@@ -45,11 +45,11 @@ public:
// Read one or more bytes of data and update the CRC // Read one or more bytes of data and update the CRC
// Return 'true' on read error // Return 'true' on read error
static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true); static bool read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing=true);
// Write one or more bytes of data // Write one or more bytes of data
// Return 'true' on write error // Return 'true' on write error
static inline bool write_data(const int pos, const uint8_t* value, const size_t size=sizeof(uint8_t)) { static inline bool write_data(const int pos, const uint8_t *value, const size_t size=sizeof(uint8_t)) {
int data_pos = pos; int data_pos = pos;
uint16_t crc = 0; uint16_t crc = 0;
return write_data(data_pos, value, size, &crc); return write_data(data_pos, value, size, &crc);
@@ -61,7 +61,7 @@ public:
// Read one or more bytes of data // Read one or more bytes of data
// Return 'true' on read error // Return 'true' on read error
static inline bool read_data(const int pos, uint8_t* value, const size_t size=1) { static inline bool read_data(const int pos, uint8_t *value, const size_t size=1) {
int data_pos = pos; int data_pos = pos;
uint16_t crc = 0; uint16_t crc = 0;
return read_data(data_pos, value, size, &crc); return read_data(data_pos, value, size, &crc);

View File

@@ -25,5 +25,5 @@
// EEPROM // EEPROM
// //
void eeprom_init(); void eeprom_init();
void eeprom_write_byte(uint8_t *pos, unsigned char value); void eeprom_write_byte(uint8_t *pos, uint8_t value);
uint8_t eeprom_read_byte(uint8_t *pos); uint8_t eeprom_read_byte(uint8_t *pos);

View File

@@ -55,12 +55,15 @@ static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(EEPROM_DEVICE_ADDRE
// Public functions // Public functions
// ------------------------ // ------------------------
void eeprom_write_byte(uint8_t *pos, unsigned char value) { static void _eeprom_begin(uint8_t * const pos) {
const unsigned eeprom_address = (unsigned)pos; const unsigned eeprom_address = (unsigned)pos;
Wire.beginTransmission(eeprom_device_address); Wire.beginTransmission(eeprom_device_address);
Wire.write(int(eeprom_address >> 8)); // MSB Wire.write(int(eeprom_address >> 8)); // Address High
Wire.write(int(eeprom_address & 0xFF)); // LSB Wire.write(int(eeprom_address & 0xFF)); // Address Low
}
void eeprom_write_byte(uint8_t *pos, uint8_t value) {
_eeprom_begin(pos);
Wire.write(value); Wire.write(value);
Wire.endTransmission(); Wire.endTransmission();
@@ -70,11 +73,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
} }
uint8_t eeprom_read_byte(uint8_t *pos) { uint8_t eeprom_read_byte(uint8_t *pos) {
const unsigned eeprom_address = (unsigned)pos; _eeprom_begin(pos);
Wire.beginTransmission(eeprom_device_address);
Wire.write(int(eeprom_address >> 8)); // MSB
Wire.write(int(eeprom_address & 0xFF)); // LSB
Wire.endTransmission(); Wire.endTransmission();
Wire.requestFrom(eeprom_device_address, (byte)1); Wire.requestFrom(eeprom_device_address, (byte)1);
return Wire.available() ? Wire.read() : 0xFF; return Wire.available() ? Wire.read() : 0xFF;

Some files were not shown because too many files have changed in this diff Show More