Merge branch 'bugfix-2.0.x' of https://github.com/MarlinFirmware/Marlin into bugfix-2.0.x

This commit is contained in:
InsanityAutomation 2020-11-06 09:30:48 -05:00
commit a348c3caa9
270 changed files with 6517 additions and 10067 deletions

2
.gitattributes vendored
View file

@ -17,3 +17,5 @@
*.png binary *.png binary
*.jpg binary *.jpg binary
*.fon binary *.fon binary
*.bin binary
*.woff binary

View file

@ -36,9 +36,11 @@ jobs:
# Base Environments # Base Environments
- DUE - DUE
- DUE_archim
- esp32 - esp32
- linux_native - linux_native
- mega2560 - mega2560
- at90usb1286_dfu
- teensy31 - teensy31
- teensy35 - teensy35
- teensy41 - teensy41
@ -95,7 +97,6 @@ jobs:
# Non-working environment tests # Non-working environment tests
#- at90usb1286_cdc #- at90usb1286_cdc
#- at90usb1286_dfu
#- STM32F103CB_malyan #- STM32F103CB_malyan
#- mks_robin_mini #- mks_robin_mini

View file

@ -674,6 +674,8 @@
* *
* A4988 is assumed for unspecified drivers. * A4988 is assumed for unspecified drivers.
* *
* Use TMC2208/TMC2208_STANDALONE for TMC2225 drivers and TMC2209/TMC2209_STANDALONE for TMC2226 drivers.
*
* Options: A4988, A5984, DRV8825, LV8729, L6470, L6474, POWERSTEP01, * Options: A4988, A5984, DRV8825, LV8729, L6470, L6474, POWERSTEP01,
* TB6560, TB6600, TMC2100, * TB6560, TB6600, TMC2100,
* TMC2130, TMC2130_STANDALONE, TMC2160, TMC2160_STANDALONE, * TMC2130, TMC2130_STANDALONE, TMC2160, TMC2160_STANDALONE,
@ -1170,6 +1172,12 @@
* Filament Runout Sensors * Filament Runout Sensors
* Mechanical or opto endstops are used to check for the presence of filament. * Mechanical or opto endstops are used to check for the presence of filament.
* *
* IMPORTANT: Runout will only trigger if Marlin is aware that a print job is running.
* Marlin knows a print job is running when:
* 1. Running a print job from media started with M24.
* 2. The Print Job Timer has been started with M75.
* 3. The heaters were turned on and PRINTJOB_TIMER_AUTOSTART is enabled.
*
* 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.
*/ */
@ -2196,7 +2204,7 @@
// //
// Third-party or vendor-customized controller interfaces. // Third-party or vendor-customized controller interfaces.
// Sources should be installed in 'src/lcd/extensible_ui'. // Sources should be installed in 'src/lcd/extui'.
// //
//#define EXTENSIBLE_UI //#define EXTENSIBLE_UI

View file

@ -1090,6 +1090,9 @@
// BACK menu items keep the highlight at the top // BACK menu items keep the highlight at the top
//#define TURBO_BACK_MENU_ITEM //#define TURBO_BACK_MENU_ITEM
// Add a mute option to the LCD menu
//#define SOUND_MENU_ITEM
/** /**
* LED Control Menu * LED Control Menu
* Add LED Control to the LCD menu * Add LED Control to the LCD menu
@ -2940,11 +2943,18 @@
#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 SPINDLE_SERVO // A servo converting an angle to spindle power
#ifdef SPINDLE_SERVO
#define SPINDLE_SERVO_NR 0 // Index of servo used for spindle control
#define SPINDLE_SERVO_MIN 10 // Minimum angle for servo spindle
#endif
/** /**
* Speed / Power can be set ('M3 S') and displayed in terms of: * Speed / Power can be set ('M3 S') and displayed in terms of:
* - PWM255 (S0 - S255) * - PWM255 (S0 - S255)
* - PERCENT (S0 - S100) * - PERCENT (S0 - S100)
* - RPM (S0 - S50000) Best for use with a spindle * - RPM (S0 - S50000) Best for use with a spindle
* - SERVO (S0 - S180)
*/ */
#define CUTTER_POWER_UNIT PWM255 #define CUTTER_POWER_UNIT PWM255

View file

@ -59,7 +59,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -996,7 +996,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = ee_Read(uint32_t(pos)); uint8_t c = ee_Read(uint32_t(pos));
if (writing) *value = c; if (writing) *value = c;

View file

@ -62,7 +62,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -477,7 +477,7 @@
#define DIO91_PIN 15 #define DIO91_PIN 15
#define DIO91_WPORT PIOB #define DIO91_WPORT PIOB
#if ARDUINO_SAM_ARCHIM #ifdef ARDUINO_SAM_ARCHIM
#define DIO92_PIN 11 #define DIO92_PIN 11
#define DIO92_WPORT PIOC #define DIO92_WPORT PIOC

View file

@ -84,7 +84,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
card.getSd2Card().readData(sector_buf); card.getSd2Card().readData(sector_buf);
// RAM -> USB // RAM -> USB
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) { if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().readStop(); card.getSd2Card().readStop();
return CTRL_FAIL; return CTRL_FAIL;
} }
@ -120,7 +120,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
while (nb_sector--) { while (nb_sector--) {
// USB -> RAM // USB -> RAM
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) { if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().writeStop(); card.getSd2Card().writeStop();
return CTRL_FAIL; return CTRL_FAIL;
} }

View file

@ -36,7 +36,7 @@ void watchdogSetup() {
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
// 4 seconds timeout // 4 seconds timeout
uint32_t timeout = 4000; uint32_t timeout = TERN(WATCHDOG_DURATION_8S, 8000, 4000);
// Calculate timeout value in WDT counter ticks: This assumes // Calculate timeout value in WDT counter ticks: This assumes
// the slow clock is running at 32.768 kHz watchdog // the slow clock is running at 32.768 kHz watchdog

View file

@ -44,7 +44,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
uint8_t c = EEPROM.read(pos++); uint8_t c = EEPROM.read(pos++);
if (writing) value[i] = c; if (writing) value[i] = c;

View file

@ -184,7 +184,7 @@ int i2s_init() {
// Allocate the array of pointers to the buffers // Allocate the array of pointers to the buffers
dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT); dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT);
if (dma.buffers == nullptr) return -1; if (!dma.buffers) return -1;
// Allocate each buffer that can be used by the DMA controller // Allocate each buffer that can be used by the DMA controller
for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) { for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
@ -194,7 +194,7 @@ int i2s_init() {
// Allocate the array of DMA descriptors // Allocate the array of DMA descriptors
dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT); dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT);
if (dma.desc == nullptr) return -1; if (!dma.desc) return -1;
// Allocate each DMA descriptor that will be used by the DMA controller // Allocate each DMA descriptor that will be used by the DMA controller
for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) { for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {

View file

@ -24,15 +24,9 @@
#include <stdint.h> #include <stdint.h>
#include <driver/timer.h> #include <driver/timer.h>
// Includes needed to get I2S_STEPPER_STREAM. Note that pins.h
// is included in case this header is being included early.
#include "../../inc/MarlinConfig.h"
#include "../../pins/pins.h"
// ------------------------ // ------------------------
// Defines // Defines
// ------------------------ // ------------------------
//
#define FORCE_INLINE __attribute__((always_inline)) inline #define FORCE_INLINE __attribute__((always_inline)) inline
typedef uint64_t hal_timer_t; typedef uint64_t hal_timer_t;

View file

@ -25,6 +25,8 @@
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
#include "watchdog.h" #include "watchdog.h"
void watchdogSetup() { void watchdogSetup() {

View file

@ -23,7 +23,7 @@
#define CPU_32_BIT #define CPU_32_BIT
#define F_CPU 100000000 #define F_CPU 100000000UL
#define SystemCoreClock F_CPU #define SystemCoreClock F_CPU
#include <iostream> #include <iostream>
#include <stdint.h> #include <stdint.h>

View file

@ -40,7 +40,7 @@ size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
const char eeprom_erase_value = 0xFF; const char eeprom_erase_value = 0xFF;
FILE * eeprom_file = fopen(filename, "rb"); FILE * eeprom_file = fopen(filename, "rb");
if (eeprom_file == nullptr) return false; if (!eeprom_file) return false;
fseek(eeprom_file, 0L, SEEK_END); fseek(eeprom_file, 0L, SEEK_END);
std::size_t file_size = ftell(eeprom_file); std::size_t file_size = ftell(eeprom_file);
@ -59,7 +59,7 @@ bool PersistentStore::access_start() {
bool PersistentStore::access_finish() { bool PersistentStore::access_finish() {
FILE * eeprom_file = fopen(filename, "wb"); FILE * eeprom_file = fopen(filename, "wb");
if (eeprom_file == nullptr) return false; if (!eeprom_file) return false;
fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file); fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file);
fclose(eeprom_file); fclose(eeprom_file);
return true; return true;
@ -78,7 +78,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return (bytes_written != size); // return true for any error return (bytes_written != size); // return true for any error
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
std::size_t bytes_read = 0; std::size_t bytes_read = 0;
if (writing) { if (writing) {
for (std::size_t i = 0; i < size; i++) { for (std::size_t i = 0; i < size; i++) {

View file

@ -86,10 +86,10 @@ public:
GpioEvent::Type evt_type = value > 1 ? GpioEvent::SET_VALUE : value > pin_map[pin].value ? GpioEvent::RISE : value < pin_map[pin].value ? GpioEvent::FALL : GpioEvent::NOP; GpioEvent::Type evt_type = value > 1 ? GpioEvent::SET_VALUE : value > pin_map[pin].value ? GpioEvent::RISE : value < pin_map[pin].value ? GpioEvent::FALL : GpioEvent::NOP;
pin_map[pin].value = value; pin_map[pin].value = value;
GpioEvent evt(Clock::nanos(), pin, evt_type); GpioEvent evt(Clock::nanos(), pin, evt_type);
if (pin_map[pin].cb != nullptr) { if (pin_map[pin].cb) {
pin_map[pin].cb->interrupt(evt); pin_map[pin].cb->interrupt(evt);
} }
if (Gpio::logger != nullptr) Gpio::logger->log(evt); if (Gpio::logger) Gpio::logger->log(evt);
} }
static uint16_t get(pin_type pin) { static uint16_t get(pin_type pin) {
@ -105,8 +105,8 @@ public:
if (!valid_pin(pin)) return; if (!valid_pin(pin)) return;
pin_map[pin].mode = value; pin_map[pin].mode = value;
GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM); GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM);
if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt); if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt);
if (Gpio::logger != nullptr) Gpio::logger->log(evt); if (Gpio::logger) Gpio::logger->log(evt);
} }
static uint8_t getMode(pin_type pin) { static uint8_t getMode(pin_type pin) {
@ -118,8 +118,8 @@ public:
if (!valid_pin(pin)) return; if (!valid_pin(pin)) return;
pin_map[pin].dir = value; pin_map[pin].dir = value;
GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD); GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD);
if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt); if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt);
if (Gpio::logger != nullptr) Gpio::logger->log(evt); if (Gpio::logger) Gpio::logger->log(evt);
} }
static uint8_t getDir(pin_type pin) { static uint8_t getDir(pin_type pin) {

View file

@ -26,15 +26,15 @@
*/ */
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
#define pwm_details(pin) pin = pin // do nothing // print PWM details #define pwm_details(pin) NOOP // (do nothing)
#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin. #define pwm_status(pin) false // Print a pin's PWM status. Return true if it's currently a PWM pin.
#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0) #define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
#define digitalRead_mod(p) digitalRead(p) #define digitalRead_mod(p) digitalRead(p)
#define PRINT_PORT(p) #define PRINT_PORT(p)
#define GET_ARRAY_PIN(p) pin_array[p].pin #define GET_ARRAY_PIN(p) pin_array[p].pin
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0) #define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0) #define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin #define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
// active ADC function/mode/code values for PINSEL registers // active ADC function/mode/code values for PINSEL registers
constexpr int8_t ADC_pin_mode(pin_t pin) { constexpr int8_t ADC_pin_mode(pin_t pin) {

View file

@ -27,6 +27,8 @@
#include "watchdog.h" #include "watchdog.h"
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
void watchdog_init() {} void watchdog_init() {}
void HAL_watchdog_refresh() {} void HAL_watchdog_refresh() {}

View file

@ -21,7 +21,5 @@
*/ */
#pragma once #pragma once
#define WDT_TIMEOUT 4000000 // 4 second timeout
void watchdog_init(); void watchdog_init();
void HAL_watchdog_refresh(); void HAL_watchdog_refresh();

View file

@ -263,8 +263,9 @@ uint16_t SPIClass::transfer16(const uint16_t data) {
} }
void SPIClass::end() { void SPIClass::end() {
// SSP_Cmd(_currentSetting->spi_d, DISABLE); // stop device or SSP_DeInit? // Neither is needed for Marlin
SSP_DeInit(_currentSetting->spi_d); //SSP_Cmd(_currentSetting->spi_d, DISABLE);
//SSP_DeInit(_currentSetting->spi_d);
} }
void SPIClass::send(uint8_t data) { void SPIClass::send(uint8_t data) {
@ -356,8 +357,8 @@ void SPIClass::setDataSize(uint32_t ds) {
void SPIClass::updateSettings() { void SPIClass::updateSettings() {
//SSP_DeInit(_currentSetting->spi_d); //todo: need force de init?! //SSP_DeInit(_currentSetting->spi_d); //todo: need force de init?!
// divide PCLK by 2 for SSP0 // Divide PCLK by 2 for SSP0
CLKPWR_SetPCLKDiv(_currentSetting->spi_d == LPC_SSP0 ? CLKPWR_PCLKSEL_SSP0 : CLKPWR_PCLKSEL_SSP1, CLKPWR_PCLKSEL_CCLK_DIV_2); //CLKPWR_SetPCLKDiv(_currentSetting->spi_d == LPC_SSP0 ? CLKPWR_PCLKSEL_SSP0 : CLKPWR_PCLKSEL_SSP1, CLKPWR_PCLKSEL_CCLK_DIV_2);
SSP_CFG_Type HW_SPI_init; // data structure to hold init values SSP_CFG_Type HW_SPI_init; // data structure to hold init values
SSP_ConfigStructInit(&HW_SPI_init); // set values for SPI mode SSP_ConfigStructInit(&HW_SPI_init); // set values for SPI mode

View file

@ -119,7 +119,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; // return true for any error return false; // return true for any error
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos]; const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos];
if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[pos + i]; if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[pos + i];
crc16(crc, buff, size); crc16(crc, buff, size);

View file

@ -143,7 +143,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return bytes_written != size; // return true for any error return bytes_written != size; // return true for any error
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
if (!eeprom_file_open) return true; if (!eeprom_file_open) return true;
UINT bytes_read = 0; UINT bytes_read = 0;
FRESULT s; FRESULT s;

View file

@ -64,7 +64,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { 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);

View file

@ -37,13 +37,14 @@
#define DATA_SIZE_8BIT SSP_DATABIT_8 #define DATA_SIZE_8BIT SSP_DATABIT_8
#define DATA_SIZE_16BIT SSP_DATABIT_16 #define DATA_SIZE_16BIT SSP_DATABIT_16
#define SPI_CLOCK_DIV2 8333333 //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED #define SPI_CLOCK_MAX_TFT 30000000UL
#define SPI_CLOCK_DIV4 4166667 //(SCR: 5) desired: 4,000,000 actual: 4,166,667 +4.2% SPI_HALF_SPEED #define SPI_CLOCK_DIV2 8333333 //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED
#define SPI_CLOCK_DIV8 2083333 //(SCR: 11) desired: 2,000,000 actual: 2,083,333 +4.2% SPI_QUARTER_SPEED #define SPI_CLOCK_DIV4 4166667 //(SCR: 5) desired: 4,000,000 actual: 4,166,667 +4.2% SPI_HALF_SPEED
#define SPI_CLOCK_DIV16 1000000 //(SCR: 24) desired: 1,000,000 actual: 1,000,000 SPI_EIGHTH_SPEED #define SPI_CLOCK_DIV8 2083333 //(SCR: 11) desired: 2,000,000 actual: 2,083,333 +4.2% SPI_QUARTER_SPEED
#define SPI_CLOCK_DIV32 500000 //(SCR: 49) desired: 500,000 actual: 500,000 SPI_SPEED_5 #define SPI_CLOCK_DIV16 1000000 //(SCR: 24) desired: 1,000,000 actual: 1,000,000 SPI_EIGHTH_SPEED
#define SPI_CLOCK_DIV64 250000 //(SCR: 99) desired: 250,000 actual: 250,000 SPI_SPEED_6 #define SPI_CLOCK_DIV32 500000 //(SCR: 49) desired: 500,000 actual: 500,000 SPI_SPEED_5
#define SPI_CLOCK_DIV128 125000 //(SCR:199) desired: 125,000 actual: 125,000 Default from HAL.h #define SPI_CLOCK_DIV64 250000 //(SCR: 99) desired: 250,000 actual: 250,000 SPI_SPEED_6
#define SPI_CLOCK_DIV128 125000 //(SCR:199) desired: 125,000 actual: 125,000 Default from HAL.h
#define SPI_CLOCK_MAX SPI_CLOCK_DIV2 #define SPI_CLOCK_MAX SPI_CLOCK_DIV2

View file

@ -89,7 +89,7 @@ void TFT_SPI::Init() {
#elif TFT_MISO_PIN == BOARD_SPI2_MISO_PIN #elif TFT_MISO_PIN == BOARD_SPI2_MISO_PIN
SPIx.setModule(2); SPIx.setModule(2);
#endif #endif
SPIx.setClock(SPI_CLOCK_MAX); SPIx.setClock(SPI_CLOCK_MAX_TFT);
SPIx.setBitOrder(MSBFIRST); SPIx.setBitOrder(MSBFIRST);
SPIx.setDataMode(SPI_MODE0); SPIx.setDataMode(SPI_MODE0);
} }
@ -125,7 +125,7 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
} }
DataTransferEnd(); DataTransferEnd();
SPIx.setClock(SPI_CLOCK_MAX); SPIx.setClock(SPI_CLOCK_MAX_TFT);
#endif #endif
return data >> 7; return data >> 7;

View file

@ -28,6 +28,8 @@
#include <lpc17xx_wdt.h> #include <lpc17xx_wdt.h>
#include "watchdog.h" #include "watchdog.h"
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
void watchdog_init() { void watchdog_init() {
#if ENABLED(WATCHDOG_RESET_MANUAL) #if ENABLED(WATCHDOG_RESET_MANUAL)
// We enable the watchdog timer, but only for the interrupt. // We enable the watchdog timer, but only for the interrupt.
@ -52,7 +54,7 @@ void watchdog_init() {
#else #else
WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET); WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
#endif #endif
WDT_Start(WDT_TIMEOUT); WDT_Start(WDT_TIMEOUT_US);
} }
void HAL_watchdog_refresh() { void HAL_watchdog_refresh() {

View file

@ -21,8 +21,6 @@
*/ */
#pragma once #pragma once
#define WDT_TIMEOUT 4000000 // 4 second timeout
void watchdog_init(); void watchdog_init();
void HAL_watchdog_refresh(); void HAL_watchdog_refresh();

View file

@ -300,7 +300,7 @@ uint16_t HAL_adc_result;
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
DMA_STEPSEL_SRC // STEPSEL DMA_STEPSEL_SRC // STEPSEL
); );
if (descriptor != nullptr) if (descriptor)
descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT; descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
adc0DMAProgram.startJob(); adc0DMAProgram.startJob();
} }
@ -337,7 +337,7 @@ uint16_t HAL_adc_result;
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
DMA_STEPSEL_SRC // STEPSEL DMA_STEPSEL_SRC // STEPSEL
); );
if (descriptor != nullptr) if (descriptor)
descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT; descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
adc1DMAProgram.startJob(); adc1DMAProgram.startJob();
} }

View file

@ -35,10 +35,10 @@ uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE];
uint32_t QSPIFlash::_addr = INVALID_ADDR; uint32_t QSPIFlash::_addr = INVALID_ADDR;
void QSPIFlash::begin() { void QSPIFlash::begin() {
if (_flashBase != nullptr) return; if (_flashBase) return;
_flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI()); _flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI());
_flashBase->begin(NULL); _flashBase->begin(nullptr);
} }
size_t QSPIFlash::size() { size_t QSPIFlash::size() {

View file

@ -79,7 +79,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
while (size--) { while (size--) {
SYNC(NVMCTRL->SEESTAT.bit.BUSY); SYNC(NVMCTRL->SEESTAT.bit.BUSY);
uint8_t c = ((volatile uint8_t *)SEEPROM_ADDR)[pos]; uint8_t c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];

View file

@ -56,7 +56,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
while (size--) { while (size--) {
uint8_t c = qspi.readByte(pos); uint8_t c = qspi.readByte(pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -59,7 +59,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
while (size--) { while (size--) {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -24,28 +24,30 @@
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#include "watchdog.h" #include "watchdog.h"
void watchdog_init() { #define WDT_TIMEOUT_REG TERN(WATCHDOG_DURATION_8S, WDT_CONFIG_PER_CYC8192, WDT_CONFIG_PER_CYC4096) // 4 or 8 second timeout
// The low-power oscillator used by the WDT runs at 32,768 Hz with
// a 1:32 prescale, thus 1024 Hz, though probably not super precise.
// Setup WDT clocks void watchdog_init() {
MCLK->APBAMASK.bit.OSC32KCTRL_ = true; // The low-power oscillator used by the WDT runs at 32,768 Hz with
MCLK->APBAMASK.bit.WDT_ = true; // a 1:32 prescale, thus 1024 Hz, though probably not super precise.
OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config // Setup WDT clocks
SYNC(WDT->SYNCBUSY.bit.ENABLE); MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
MCLK->APBAMASK.bit.WDT_ = true;
OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config
WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096; // Set at least 4s period for chip reset SYNC(WDT->SYNCBUSY.bit.ENABLE);
HAL_watchdog_refresh(); WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt
WDT->CONFIG.reg = WDT_TIMEOUT_REG; // Set a 4s or 8s period for chip reset
WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode HAL_watchdog_refresh();
SYNC(WDT->SYNCBUSY.bit.ENABLE);
} WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode
SYNC(WDT->SYNCBUSY.bit.ENABLE);
}
#endif // USE_WATCHDOG #endif // USE_WATCHDOG

View file

@ -81,7 +81,9 @@ void HAL_init() {
SetTimerInterruptPriorities(); SetTimerInterruptPriorities();
TERN_(EMERGENCY_PARSER, USB_Hook_init()); #if ENABLED(EMERGENCY_PARSER) && USBD_USE_CDC
USB_Hook_init();
#endif
} }
void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); } void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
@ -128,8 +130,12 @@ uint16_t HAL_adc_get_result() { return HAL_adc_result; }
void flashFirmware(const int16_t) { NVIC_SystemReset(); } void flashFirmware(const int16_t) { NVIC_SystemReset(); }
// Maple Compatibility // Maple Compatibility
volatile uint32_t systick_uptime_millis = 0;
systickCallback_t systick_user_callback; systickCallback_t systick_user_callback;
void systick_attach_callback(systickCallback_t cb) { systick_user_callback = cb; } void systick_attach_callback(systickCallback_t cb) { systick_user_callback = cb; }
void HAL_SYSTICK_Callback() { if (systick_user_callback) systick_user_callback(); } void HAL_SYSTICK_Callback() {
systick_uptime_millis++;
if (systick_user_callback) systick_user_callback();
}
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

View file

@ -184,3 +184,21 @@ void flashFirmware(const int16_t);
typedef void (*systickCallback_t)(void); typedef void (*systickCallback_t)(void);
void systick_attach_callback(systickCallback_t cb); void systick_attach_callback(systickCallback_t cb);
void HAL_SYSTICK_Callback(); void HAL_SYSTICK_Callback();
extern volatile uint32_t systick_uptime_millis;
#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment
/**
* set_pwm_frequency
* Set the frequency of the timer corresponding to the provided pin
* All Timer PWM pins run at the same frequency
*/
void set_pwm_frequency(const pin_t pin, int f_desired);
/**
* set_pwm_duty
* Set the PWM duty cycle of the provided pin to the provided value
* Optionally allows inverting the duty cycle [default = false]
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
*/
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);

View file

@ -113,7 +113,7 @@ bool PersistentStore::access_start() {
// This must be the first time since power on that we have accessed the storage, or someone // This must be the first time since power on that we have accessed the storage, or someone
// loaded and called write_data and never called access_finish. // loaded and called write_data and never called access_finish.
// Lets go looking for the slot that holds our configuration. // Lets go looking for the slot that holds our configuration.
if (eeprom_data_written) DEBUG_ECHOLN("Dangling EEPROM write_data"); if (eeprom_data_written) DEBUG_ECHOLNPGM("Dangling EEPROM write_data");
uint32_t address = FLASH_ADDRESS_START; uint32_t address = FLASH_ADDRESS_START;
while (address <= FLASH_ADDRESS_END) { while (address <= FLASH_ADDRESS_END) {
uint32_t address_value = (*(__IO uint32_t*)address); uint32_t address_value = (*(__IO uint32_t*)address);
@ -261,7 +261,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
const uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[pos], eeprom_buffered_read_byte(pos)); const uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[pos], eeprom_buffered_read_byte(pos));
if (writing) *value = c; if (writing) *value = c;

View file

@ -78,7 +78,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
uint8_t c = HAL_eeprom_data[pos + i]; uint8_t c = HAL_eeprom_data[pos + i];
if (writing) value[i] = c; if (writing) value[i] = c;

View file

@ -52,7 +52,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
// Read from either external EEPROM, program flash or Backup SRAM // Read from either external EEPROM, program flash or Backup SRAM
const uint8_t c = ( *(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)) ); const uint8_t c = ( *(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)) );

View file

@ -65,7 +65,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
// Read from either external EEPROM, program flash or Backup SRAM // Read from either external EEPROM, program flash or Backup SRAM
const uint8_t c = eeprom_read_byte((uint8_t*)pos); const uint8_t c = eeprom_read_byte((uint8_t*)pos);

View file

@ -0,0 +1,57 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 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/>.
*
*/
#include "../../inc/MarlinConfigPre.h"
#if NEEDS_HARDWARE_PWM
#include "HAL.h"
#include "timers.h"
void set_pwm_frequency(const pin_t pin, int f_desired) {
if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer
PinName pin_name = digitalPinToPinName(pin);
TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance
LOOP_S_L_N(i, 0, NUM_HARDWARE_TIMERS) // Protect used timers
if (timer_instance[i] && timer_instance[i]->getHandle()->Instance == Instance)
return;
pwm_start(pin_name, f_desired, 0, RESOLUTION_8B_COMPARE_FORMAT);
}
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
PinName pin_name = digitalPinToPinName(pin);
TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM);
uint16_t adj_val = Instance->ARR * v / v_size;
if (invert) adj_val = Instance->ARR - adj_val;
switch (get_pwm_channel(pin_name)) {
case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break;
case TIM_CHANNEL_2: LL_TIM_OC_SetCompareCH2(Instance, adj_val); break;
case TIM_CHANNEL_3: LL_TIM_OC_SetCompareCH3(Instance, adj_val); break;
case TIM_CHANNEL_4: LL_TIM_OC_SetCompareCH4(Instance, adj_val); break;
}
}
#endif // NEEDS_HARDWARE_PWM

View file

@ -28,9 +28,6 @@
// #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" // #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
//#endif //#endif
#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
#error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32."
#endif
#if ENABLED(SDCARD_EEPROM_EMULATION) && DISABLED(SDSUPPORT) #if ENABLED(SDCARD_EEPROM_EMULATION) && DISABLED(SDSUPPORT)
#undef SDCARD_EEPROM_EMULATION // Avoid additional error noise #undef SDCARD_EEPROM_EMULATION // Avoid additional error noise

View file

@ -99,7 +99,7 @@ void XPT2046::Init() {
#endif #endif
} }
else { else {
SPIx.Instance = NULL; SPIx.Instance = nullptr;
SET_INPUT(TOUCH_MISO_PIN); SET_INPUT(TOUCH_MISO_PIN);
SET_OUTPUT(TOUCH_MOSI_PIN); SET_OUTPUT(TOUCH_MOSI_PIN);
SET_OUTPUT(TOUCH_SCK_PIN); SET_OUTPUT(TOUCH_SCK_PIN);

View file

@ -27,7 +27,6 @@
// Local defines // Local defines
// ------------------------ // ------------------------
#define NUM_HARDWARE_TIMERS 2
// Default timer priorities. Override by specifying alternate priorities in the board pins file. // Default timer priorities. Override by specifying alternate priorities in the board pins file.
// The TONE timer is not present here, as it currently cannot be set programmatically. It is set // The TONE timer is not present here, as it currently cannot be set programmatically. It is set
@ -68,26 +67,23 @@
#endif #endif
#ifdef STM32F0xx #ifdef STM32F0xx
#define MCU_TIMER_RATE (F_CPU) // Frequency of timer peripherals
#define MCU_STEP_TIMER 16 #define MCU_STEP_TIMER 16
#define MCU_TEMP_TIMER 17 #define MCU_TEMP_TIMER 17
#elif defined(STM32F1xx) #elif defined(STM32F1xx)
#define MCU_TIMER_RATE (F_CPU)
#define MCU_STEP_TIMER 4 #define MCU_STEP_TIMER 4
#define MCU_TEMP_TIMER 2 #define MCU_TEMP_TIMER 2
#elif defined(STM32F401xC) || defined(STM32F401xE) #elif defined(STM32F401xC) || defined(STM32F401xE)
#define MCU_TIMER_RATE (F_CPU / 2)
#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)
#define MCU_TIMER_RATE (F_CPU / 2)
#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
#ifndef HAL_TIMER_RATE #ifndef HAL_TIMER_RATE
#define HAL_TIMER_RATE MCU_TIMER_RATE #define HAL_TIMER_RATE GetStepperTimerClkFreq()
#endif #endif
#ifndef STEP_TIMER #ifndef STEP_TIMER
#define STEP_TIMER MCU_STEP_TIMER #define STEP_TIMER MCU_STEP_TIMER
#endif #endif
@ -109,12 +105,19 @@
// Private Variables // Private Variables
// ------------------------ // ------------------------
HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL }; HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { nullptr };
// ------------------------ // ------------------------
// Public functions // Public functions
// ------------------------ // ------------------------
uint32_t GetStepperTimerClkFreq() {
// Timer input clocks vary between devices, and in some cases between timers on the same device.
// Retrieve at runtime to ensure device compatibility. Cache result to avoid repeated overhead.
static uint32_t clkfreq = timer_instance[STEP_TIMER_NUM]->getTimerClkFreq();
return clkfreq;
}
// frequency is in Hertz // frequency is in Hertz
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
if (!HAL_timer_initialized(timer_num)) { if (!HAL_timer_initialized(timer_num)) {

View file

@ -43,6 +43,8 @@
#define hal_timer_t uint32_t #define hal_timer_t uint32_t
#define HAL_TIMER_TYPE_MAX UINT16_MAX #define HAL_TIMER_TYPE_MAX UINT16_MAX
#define NUM_HARDWARE_TIMERS 2
#ifndef STEP_TIMER_NUM #ifndef STEP_TIMER_NUM
#define STEP_TIMER_NUM 0 // Timer Index for Stepper #define STEP_TIMER_NUM 0 // Timer Index for Stepper
#endif #endif
@ -57,7 +59,8 @@
// TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp // TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp
#define STEPPER_TIMER_RATE 2000000 // 2 Mhz #define STEPPER_TIMER_RATE 2000000 // 2 Mhz
#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE)) extern uint32_t GetStepperTimerClkFreq();
#define STEPPER_TIMER_PRESCALE (GetStepperTimerClkFreq() / (STEPPER_TIMER_RATE))
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE #define PULSE_TIMER_RATE STEPPER_TIMER_RATE

View file

@ -21,7 +21,7 @@
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER) && USBD_USE_CDC
#include "usb_serial.h" #include "usb_serial.h"
#include "../../feature/e_parser.h" #include "../../feature/e_parser.h"

View file

@ -25,23 +25,26 @@
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#include "../../inc/MarlinConfig.h" #define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
#include "watchdog.h" #include "../../inc/MarlinConfig.h"
#include <IWatchdog.h>
void watchdog_init() { #include "watchdog.h"
#if DISABLED(DISABLE_WATCHDOG_INIT) #include <IWatchdog.h>
IWatchdog.begin(4000000); // 4 sec timeout
#endif
}
void HAL_watchdog_refresh() { void watchdog_init() {
IWatchdog.reload(); #if DISABLED(DISABLE_WATCHDOG_INIT)
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED) IWatchdog.begin(WDT_TIMEOUT_US);
TOGGLE(LED_PIN); // heartbeat indicator #endif
#endif }
}
void HAL_watchdog_refresh() {
IWatchdog.reload();
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
#endif // USE_WATCHDOG #endif // USE_WATCHDOG
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

View file

@ -124,7 +124,7 @@ void HAL_idletask();
#endif #endif
#ifndef digitalPinHasPWM #ifndef digitalPinHasPWM
#define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr) #define digitalPinHasPWM(P) !!PIN_MAP[P].timer_device
#define NO_COMPILE_TIME_PWM #define NO_COMPILE_TIME_PWM
#endif #endif
@ -244,3 +244,20 @@ void analogWrite(pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
#define PLATFORM_M997_SUPPORT #define PLATFORM_M997_SUPPORT
void flashFirmware(const int16_t); void flashFirmware(const int16_t);
#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment
/**
* set_pwm_frequency
* Set the frequency of the timer corresponding to the provided pin
* All Timer PWM pins run at the same frequency
*/
void set_pwm_frequency(const pin_t pin, int f_desired);
/**
* set_pwm_duty
* Set the PWM duty cycle of the provided pin to the provided value
* Optionally allows inverting the duty cycle [default = false]
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
*/
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);

View file

@ -656,7 +656,7 @@ static const spi_pins* dev_to_spi_pins(spi_dev *dev) {
#if BOARD_NR_SPI >= 3 #if BOARD_NR_SPI >= 3
case RCC_SPI3: return board_spi_pins + 2; case RCC_SPI3: return board_spi_pins + 2;
#endif #endif
default: return NULL; default: return nullptr;
} }
} }

View file

@ -68,7 +68,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t * const p = (uint8_t * const)pos; uint8_t * const p = (uint8_t * const)pos;
uint8_t c = eeprom_read_byte(p); uint8_t c = eeprom_read_byte(p);

View file

@ -101,7 +101,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; // return true for any error return false; // return true for any error
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos]; const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos];
if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[pos + i]; if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[pos + i];
crc16(crc, buff, size); crc16(crc, buff, size);

View file

@ -79,7 +79,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
uint8_t c = HAL_eeprom_data[pos + i]; uint8_t c = HAL_eeprom_data[pos + i];
if (writing) value[i] = c; if (writing) value[i] = c;

View file

@ -72,7 +72,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing && value) *value = c; if (writing && value) *value = c;

View file

@ -0,0 +1,68 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 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/>.
*
*/
#ifdef __STM32F1__
#include "../../inc/MarlinConfigPre.h"
#if NEEDS_HARDWARE_PWM
#include <pwm.h>
#include "HAL.h"
#include "timers.h"
void set_pwm_frequency(const pin_t pin, int f_desired) {
if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer
timer_dev *timer = PIN_MAP[pin].timer_device;
uint8_t channel = PIN_MAP[pin].timer_channel;
// Protect used timers
if (timer == get_timer_dev(TEMP_TIMER_NUM)) return;
if (timer == get_timer_dev(STEP_TIMER_NUM)) return;
#if PULSE_TIMER_NUM != STEP_TIMER_NUM
if (timer == get_timer_dev(PULSE_TIMER_NUM)) return;
#endif
if (!(timer->regs.bas->SR & TIMER_CR1_CEN)) // Ensure the timer is enabled
timer_init(timer);
timer_set_mode(timer, channel, TIMER_PWM);
uint16_t preload = 255; // Lock 255 PWM resolution for high frequencies
int32_t prescaler = (HAL_TIMER_RATE) / (preload + 1) / f_desired - 1;
if (prescaler > 65535) { // For low frequencies increase prescaler
prescaler = 65535;
preload = (HAL_TIMER_RATE) / (prescaler + 1) / f_desired - 1;
}
if (prescaler < 0) return; // Too high frequency
timer_set_reload(timer, preload);
timer_set_prescaler(timer, prescaler);
}
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
timer_dev *timer = PIN_MAP[pin].timer_device;
uint16_t max_val = timer->regs.bas->ARR * v / v_size;
if (invert) max_val = v_size - max_val;
pwmWrite(pin, max_val);
}
#endif // NEEDS_HARDWARE_PWM
#endif // __STM32F1__

View file

@ -51,7 +51,7 @@
#define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD) #define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
#define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD) #define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)
#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr) #define PWM_PIN(IO) !!PIN_MAP[IO].timer_device
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)

View file

@ -25,10 +25,6 @@
* Test STM32F1-specific configuration values for errors at compile-time. * Test STM32F1-specific configuration values for errors at compile-time.
*/ */
#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
#error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32F1."
#endif
#if !defined(HAVE_SW_SERIAL) && HAS_TMC_SW_SERIAL #if !defined(HAVE_SW_SERIAL) && HAS_TMC_SW_SERIAL
#warning "With TMC2208/9 consider using SoftwareSerialM with HAVE_SW_SERIAL and appropriate SS_TIMER." #warning "With TMC2208/9 consider using SoftwareSerialM with HAVE_SW_SERIAL and appropriate SS_TIMER."
#error "Missing SoftwareSerial implementation." #error "Missing SoftwareSerial implementation."

View file

@ -49,10 +49,6 @@
#undef SDSS #undef SDSS
#define SDSS SS_PIN #define SDSS SS_PIN
#if ENABLED(ENABLE_SPI3) #ifndef SPI_DEVICE
#define SPI_DEVICE 3
#elif ENABLED(ENABLE_SPI2)
#define SPI_DEVICE 2
#else
#define SPI_DEVICE 1 #define SPI_DEVICE 1
#endif #endif

View file

@ -33,6 +33,11 @@
#include <libmaple/iwdg.h> #include <libmaple/iwdg.h>
#include "watchdog.h" #include "watchdog.h"
/**
* The watchdog clock is 40Khz. So for a 4s or 8s interval use a /256 preescaler and 625 or 1250 reload value (counts down to 0).
*/
#define STM32F1_WD_RELOAD TERN(WATCHDOG_DURATION_8S, 1250, 625) // 4 or 8 second timeout
void HAL_watchdog_refresh() { void HAL_watchdog_refresh() {
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED) #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator TOGGLE(LED_PIN); // heartbeat indicator
@ -49,7 +54,7 @@ void watchdogSetup() {
* *
* @return No return * @return No return
* *
* @details The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and 625 reload value (counts down to 0) * @details The watchdog clock is 40Khz. So for a 4s or 8s interval use a /256 preescaler and 625 or 1250 reload value (counts down to 0).
*/ */
void watchdog_init() { void watchdog_init() {
#if DISABLED(DISABLE_WATCHDOG_INIT) #if DISABLED(DISABLE_WATCHDOG_INIT)

View file

@ -27,18 +27,9 @@
#include <libmaple/iwdg.h> #include <libmaple/iwdg.h>
/** // Initialize watchdog with a 4 or 8 second countdown time
* The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and
* 625 reload value (counts down to 0)
* use 1250 for 8 seconds
*/
#define STM32F1_WD_RELOAD 625
// Arduino STM32F1 core now has watchdog support
// Initialize watchdog with a 4 second countdown time
void watchdog_init(); void watchdog_init();
// Reset watchdog. MUST be called at least every 4 seconds after the // Reset watchdog. MUST be called every 4 or 8 seconds after the
// first watchdog_init or STM32F1 will reset. // first watchdog_init or the STM32F1 will reset.
void HAL_watchdog_refresh(); void HAL_watchdog_refresh();

View file

@ -96,7 +96,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = ee_read_byte((uint8_t*)pos); uint8_t c = ee_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -62,7 +62,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -25,31 +25,33 @@
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#include "watchdog.h" #include "watchdog.h"
IWDG_HandleTypeDef hiwdg; #define WDT_TIMEOUT_COUNT TERN(WATCHDOG_DURATION_8S, 8192, 4096) // 4 or 8 second timeout
void watchdog_init() { IWDG_HandleTypeDef hiwdg;
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_32; //32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock void watchdog_init() {
hiwdg.Init.Reload = 4095; //4095 counts = 4 seconds at 1024Hz hiwdg.Instance = IWDG;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { hiwdg.Init.Prescaler = IWDG_PRESCALER_32; // 32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
//Error_Handler(); hiwdg.Init.Reload = WDT_TIMEOUT_COUNT - 1;
} if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
else { //Error_Handler();
#if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
} }
else {
void HAL_watchdog_refresh() { #if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
/* Refresh IWDG: reload counter */ TOGGLE(LED_PIN); // heartbeat indicator
if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) { #endif
/* Refresh Error */
//Error_Handler();
}
} }
}
void HAL_watchdog_refresh() {
/* Refresh IWDG: reload counter */
if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
/* Refresh Error */
//Error_Handler();
}
}
#endif // USE_WATCHDOG #endif // USE_WATCHDOG
#endif // STM32GENERIC && (STM32F4 || STM32F7) #endif // STM32GENERIC && (STM32F4 || STM32F7)

View file

@ -57,7 +57,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -27,9 +27,11 @@
#include "watchdog.h" #include "watchdog.h"
#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
void watchdog_init() { void watchdog_init() {
WDOG_TOVALH = 0; WDOG_TOVALH = 0;
WDOG_TOVALL = 4000; WDOG_TOVALL = WDT_TIMEOUT_MS;
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN; WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
} }

View file

@ -61,7 +61,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -27,9 +27,11 @@
#include "watchdog.h" #include "watchdog.h"
#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
void watchdog_init() { void watchdog_init() {
WDOG_TOVALH = 0; WDOG_TOVALH = 0;
WDOG_TOVALL = 4000; WDOG_TOVALL = WDT_TIMEOUT_MS;
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN; WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
} }

View file

@ -61,7 +61,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; return false;
} }
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((uint8_t*)pos); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -19,31 +19,27 @@
* 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 __IMXRT1062__
/** /**
* HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A) * HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
*/ */
#ifdef __IMXRT1062__
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#include "watchdog.h" #include "watchdog.h"
// 4 seconds timeout #define WDT_TIMEOUT TERN(WATCHDOG_DURATION_8S, 8, 4) // 4 or 8 second timeout
#define WDTO 4 //seconds
uint8_t timeoutval = (WDTO - 0.5f) / 0.5f; constexpr uint8_t timeoutval = (WDT_TIMEOUT - 0.5f) / 0.5f;
void watchdog_init() { void watchdog_init() {
CCM_CCGR3 |= CCM_CCGR3_WDOG1(3); // enable WDOG1 clocks CCM_CCGR3 |= CCM_CCGR3_WDOG1(3); // enable WDOG1 clocks
WDOG1_WMCR = 0; // disable power down PDE WDOG1_WMCR = 0; // disable power down PDE
WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval); WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval);
WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE; WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE;
} }
void HAL_watchdog_refresh() { void HAL_watchdog_refresh() {

View file

@ -155,7 +155,7 @@
#endif #endif
// Delay in nanoseconds // Delay in nanoseconds
#define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU / 1000000UL) / 1000UL ) #define DELAY_NS(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL) / 1000UL)
// Delay in microseconds // Delay in microseconds
#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU / 1000000UL) ) #define DELAY_US(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL))

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commercially or otherwise. The only limitation is that I * any context, commercially or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liability for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Utility functions and glue for ARM unwinding sub-modules. * File Description: Utility functions and glue for ARM unwinding sub-modules.
**************************************************************************/ **************************************************************************/

View file

@ -6,7 +6,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commerically or otherwise. The only limitation is that I * any context, commerically or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liablity for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Internal interface between the ARM unwinding sub-modules. * File Description: Internal interface between the ARM unwinding sub-modules.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commercially or otherwise. The only limitation is that I * any context, commercially or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liability for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Abstract interpreter for ARM mode. * File Description: Abstract interpreter for ARM mode.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commercially or otherwise. The only limitation is that I * any context, commercially or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liability for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Abstract interpretation for Thumb mode. * File Description: Abstract interpretation for Thumb mode.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commerically or otherwise. The only limitation is that I * any context, commerically or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liablity for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Interface to the memory tracking sub-system. * File Description: Interface to the memory tracking sub-system.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commerically or otherwise. The only limitation is that I * any context, commerically or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liablity for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Implementation of the memory tracking sub-system. * File Description: Implementation of the memory tracking sub-system.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commerically or otherwise. The only limitation is that I * any context, commerically or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liablity for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Interface to the memory tracking sub-system. * File Description: Interface to the memory tracking sub-system.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commercially or otherwise. The only limitation is that I * any context, commercially or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liability for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Implementation of the interface into the ARM unwinder. * File Description: Implementation of the interface into the ARM unwinder.
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commerically or otherwise. The only limitation is that I * any context, commerically or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liablity for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
**************************************************************************/ **************************************************************************/
/** \file /** \file
* Interface to the ARM stack unwinding module. * Interface to the ARM stack unwinding module.

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commercially or otherwise. The only limitation is that I * any context, commercially or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liability for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Utility functions to access memory * File Description: Utility functions to access memory
**************************************************************************/ **************************************************************************/

View file

@ -7,7 +7,7 @@
* for free and use it as they wish, with or without modifications, and in * for free and use it as they wish, with or without modifications, and in
* any context, commerically or otherwise. The only limitation is that I * any context, commerically or otherwise. The only limitation is that I
* don't guarantee that the software is fit for any purpose or accept any * don't guarantee that the software is fit for any purpose or accept any
* liablity for it's use or misuse - this software is without warranty. * liability for its use or misuse - this software is without warranty.
*************************************************************************** ***************************************************************************
* File Description: Utility functions to access memory * File Description: Utility functions to access memory
**************************************************************************/ **************************************************************************/

View file

@ -92,7 +92,7 @@
#define BOARD_TRIGORILLA_14_11 1136 // ... Rev 1.1 (new servo pin order) #define BOARD_TRIGORILLA_14_11 1136 // ... Rev 1.1 (new servo pin order)
#define BOARD_RAMPS_ENDER_4 1137 // Creality: Ender-4, CR-8 #define BOARD_RAMPS_ENDER_4 1137 // Creality: Ender-4, CR-8
#define BOARD_RAMPS_CREALITY 1138 // Creality: CR10S, CR20, CR-X #define BOARD_RAMPS_CREALITY 1138 // Creality: CR10S, CR20, CR-X
#define BOARD_RAMPS_DAGOMA 1139 // Dagoma F5 #define BOARD_DAGOMA_F5 1139 // Dagoma F5
#define BOARD_FYSETC_F6_13 1140 // FYSETC F6 1.3 #define BOARD_FYSETC_F6_13 1140 // FYSETC F6 1.3
#define BOARD_FYSETC_F6_14 1141 // FYSETC F6 1.4 #define BOARD_FYSETC_F6_14 1141 // FYSETC F6 1.4
#define BOARD_DUPLICATOR_I3_PLUS 1142 // Wanhao Duplicator i3 Plus #define BOARD_DUPLICATOR_I3_PLUS 1142 // Wanhao Duplicator i3 Plus

View file

@ -348,7 +348,7 @@ float bilinear_z_offset(const xy_pos_t &raw) {
* Prepare a bilinear-leveled linear move on Cartesian, * Prepare a bilinear-leveled linear move on Cartesian,
* splitting the move where it crosses grid borders. * splitting the move where it crosses grid borders.
*/ */
void bilinear_line_to_destination(const feedRate_t scaled_fr_mm_s, uint16_t x_splits, uint16_t y_splits) { void bilinear_line_to_destination(const feedRate_t &scaled_fr_mm_s, uint16_t x_splits, uint16_t y_splits) {
// Get current and destination cells for this line // Get current and destination cells for this line
xy_int_t c1 { CELL_INDEX(x, current_position.x), CELL_INDEX(y, current_position.y) }, xy_int_t c1 { CELL_INDEX(x, current_position.x), CELL_INDEX(y, current_position.y) },
c2 { CELL_INDEX(x, destination.x), CELL_INDEX(y, destination.y) }; c2 { CELL_INDEX(x, destination.x), CELL_INDEX(y, destination.y) };

View file

@ -124,7 +124,7 @@ uint8_t MCP4728::getDrvPct(const uint8_t channel) { return uint8_t(100.0 * dac_v
* DAC Values array and calls fastwrite to update the DAC. * DAC Values array and calls fastwrite to update the DAC.
*/ */
void MCP4728::setDrvPct(xyze_uint8_t &pct) { void MCP4728::setDrvPct(xyze_uint8_t &pct) {
dac_values *= 0.01 * pct * (DAC_STEPPER_MAX); dac_values *= pct.asFloat() * 0.01f * (DAC_STEPPER_MAX);
fastWrite(); fastWrite();
} }

View file

@ -31,10 +31,10 @@ public:
Password() { is_locked = false; } Password() { is_locked = false; }
static void lock_machine(); static void lock_machine();
static void authentication_check();
#if HAS_LCD_MENU #if HAS_LCD_MENU
static void access_menu_password(); static void access_menu_password();
static void authentication_check();
static void authentication_done(); static void authentication_done();
static void media_gatekeeper(); static void media_gatekeeper();

View file

@ -30,6 +30,10 @@
#include "spindle_laser.h" #include "spindle_laser.h"
#if ENABLED(SPINDLE_SERVO)
#include "../module/servo.h"
#endif
SpindleLaser cutter; SpindleLaser cutter;
uint8_t SpindleLaser::power; uint8_t SpindleLaser::power;
bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR
@ -45,7 +49,11 @@ cutter_power_t SpindleLaser::menuPower, // Power s
// Init the cutter to a safe OFF state // Init the cutter to a safe OFF state
// //
void SpindleLaser::init() { void SpindleLaser::init() {
OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off #if ENABLED(SPINDLE_SERVO)
MOVE_SERVO(SPINDLE_SERVO_NR, SPINDLE_SERVO_MIN);
#else
OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off
#endif
#if ENABLED(SPINDLE_CHANGE_DIR) #if ENABLED(SPINDLE_CHANGE_DIR)
OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3) OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3)
#endif #endif
@ -97,6 +105,8 @@ void SpindleLaser::apply_power(const uint8_t opwr) {
ocr_off(); ocr_off();
isReady = false; isReady = false;
} }
#elif ENABLED(SPINDLE_SERVO)
MOVE_SERVO(SPINDLE_SERVO_NR, power);
#else #else
WRITE(SPINDLE_LASER_ENA_PIN, enabled() ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE); WRITE(SPINDLE_LASER_ENA_PIN, enabled() ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE);
isReady = true; isReady = true;

View file

@ -35,29 +35,33 @@
#endif #endif
#define PCT_TO_PWM(X) ((X) * 255 / 100) #define PCT_TO_PWM(X) ((X) * 255 / 100)
#define PCT_TO_SERVO(X) ((X) * 180 / 100)
#ifndef SPEED_POWER_INTERCEPT #ifndef SPEED_POWER_INTERCEPT
#define SPEED_POWER_INTERCEPT 0 #define SPEED_POWER_INTERCEPT 0
#endif #endif
#define SPEED_POWER_FLOOR TERN(CUTTER_POWER_RELATIVE, SPEED_POWER_MIN, 0)
// #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1))
class SpindleLaser { class SpindleLaser {
public: public:
static constexpr float static constexpr float
min_pct = round(TERN(CUTTER_POWER_RELATIVE, 0, (100 * float(SPEED_POWER_MIN) / TERN(SPINDLE_FEATURE, float(SPEED_POWER_MAX), 100)))), min_pct = TERN(CUTTER_POWER_RELATIVE, 0, TERN(SPINDLE_FEATURE, round(100.0f * (SPEED_POWER_MIN) / (SPEED_POWER_MAX)), SPEED_POWER_MIN)),
max_pct = round(TERN(SPINDLE_FEATURE, 100, float(SPEED_POWER_MAX))); max_pct = TERN(SPINDLE_FEATURE, 100, SPEED_POWER_MAX);
static const inline uint8_t pct_to_ocr(const float pct) { return uint8_t(PCT_TO_PWM(pct)); } static const inline uint8_t pct_to_ocr(const float pct) { return uint8_t(PCT_TO_PWM(pct)); }
// cpower = configured values (ie SPEED_POWER_MAX) // cpower = configured values (e.g., SPEED_POWER_MAX)
static const inline uint8_t cpwr_to_pct(const cutter_cpower_t cpwr) { // configured value to pct
return unitPower ? round(100 * (cpwr - SPEED_POWER_FLOOR) / (SPEED_POWER_MAX - SPEED_POWER_FLOOR)) : 0; // Convert configured power range to a percentage
static const inline uint8_t cpwr_to_pct(const cutter_cpower_t cpwr) {
constexpr cutter_cpower_t power_floor = TERN(CUTTER_POWER_RELATIVE, SPEED_POWER_MIN, 0),
power_range = SPEED_POWER_MAX - power_floor;
return unitPower ? round(100.0f * (cpwr - power_floor) / power_range) : 0;
} }
// Convert a configured value (cpower)(ie SPEED_POWER_STARTUP) to unit power (upwr, upower), // Convert a cpower (e.g., SPEED_POWER_STARTUP) to unit power (upwr, upower),
// which can be PWM, Percent, or RPM (rel/abs). // which can be PWM, Percent, Servo angle, or RPM (rel/abs).
static const inline cutter_power_t cpwr_to_upwr(const cutter_cpower_t cpwr) { // STARTUP power to Unit power static const inline cutter_power_t cpwr_to_upwr(const cutter_cpower_t cpwr) { // STARTUP power to Unit power
const cutter_power_t upwr = ( const cutter_power_t upwr = (
#if ENABLED(SPINDLE_FEATURE) #if ENABLED(SPINDLE_FEATURE)
@ -66,6 +70,8 @@ public:
cpwr // to RPM cpwr // to RPM
#elif CUTTER_UNIT_IS(PERCENT) // to PCT #elif CUTTER_UNIT_IS(PERCENT) // to PCT
cpwr_to_pct(cpwr) cpwr_to_pct(cpwr)
#elif CUTTER_UNIT_IS(SERVO) // to SERVO angle
PCT_TO_SERVO(cpwr_to_pct(cpwr))
#else // to PWM #else // to PWM
PCT_TO_PWM(cpwr_to_pct(cpwr)) PCT_TO_PWM(cpwr_to_pct(cpwr))
#endif #endif
@ -235,7 +241,7 @@ public:
// Inline modes of all other functions; all enable planner inline power control // Inline modes of all other functions; all enable planner inline power control
static inline void set_inline_enabled(const bool enable) { static inline void set_inline_enabled(const bool enable) {
if (enable) if (enable)
inline_power(cpwr_to_upwr(SPEED_POWER_STARTUP)); inline_power(255);
else { else {
isReady = false; isReady = false;
unitPower = menuPower = 0; unitPower = menuPower = 0;

View file

@ -103,9 +103,11 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
inline uint16_t get_microstep_counter() { return TMC::MSCNT(); } inline uint16_t get_microstep_counter() { return TMC::MSCNT(); }
#if HAS_STEALTHCHOP #if HAS_STEALTHCHOP
inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); } inline bool get_stealthChop() { return this->en_pwm_mode(); }
inline bool get_stealthChop() { return this->en_pwm_mode(); } inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); }
inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
#endif #endif
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
@ -170,9 +172,11 @@ class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
inline uint16_t get_microstep_counter() { return TMC2208Stepper::MSCNT(); } inline uint16_t get_microstep_counter() { return TMC2208Stepper::MSCNT(); }
#if HAS_STEALTHCHOP #if HAS_STEALTHCHOP
inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } inline bool get_stealthChop() { return !this->en_spreadCycle(); }
inline bool get_stealthChop() { return !this->en_spreadCycle(); } inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); }
inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
#endif #endif
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
@ -216,9 +220,11 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
inline uint16_t get_microstep_counter() { return TMC2209Stepper::MSCNT(); } inline uint16_t get_microstep_counter() { return TMC2209Stepper::MSCNT(); }
#if HAS_STEALTHCHOP #if HAS_STEALTHCHOP
inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } inline bool get_stealthChop() { return !this->en_spreadCycle(); }
inline bool get_stealthChop() { return !this->en_spreadCycle(); } inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); }
inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
#endif #endif
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)

View file

@ -129,15 +129,19 @@ void GcodeSuite::G35() {
const float z_probed_height = probe.probe_at_point(screws_tilt_adjust_pos[i], PROBE_PT_RAISE, 0, true); const float z_probed_height = probe.probe_at_point(screws_tilt_adjust_pos[i], PROBE_PT_RAISE, 0, true);
if (isnan(z_probed_height)) { if (isnan(z_probed_height)) {
SERIAL_ECHOPAIR("G35 failed at point ", int(i), " (", tramming_point_name[i], ")"); SERIAL_ECHOPAIR("G35 failed at point ", int(i), " (");
SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));
SERIAL_CHAR(')');
SERIAL_ECHOLNPAIR_P(SP_X_STR, screws_tilt_adjust_pos[i].x, SP_Y_STR, screws_tilt_adjust_pos[i].y); SERIAL_ECHOLNPAIR_P(SP_X_STR, screws_tilt_adjust_pos[i].x, SP_Y_STR, screws_tilt_adjust_pos[i].y);
err_break = true; err_break = true;
break; break;
} }
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("Probing point ", int(i), " (", tramming_point_name[i], ")"); DEBUG_ECHOPAIR("Probing point ", int(i), " (");
SERIAL_ECHOLNPAIR_P(SP_X_STR, screws_tilt_adjust_pos[i].x, SP_Y_STR, screws_tilt_adjust_pos[i].y, SP_Z_STR, z_probed_height); DEBUG_PRINT_P((char *)pgm_read_ptr(&tramming_point_name[i]));
DEBUG_CHAR(')');
DEBUG_ECHOLNPAIR_P(SP_X_STR, screws_tilt_adjust_pos[i].x, SP_Y_STR, screws_tilt_adjust_pos[i].y, SP_Z_STR, z_probed_height);
} }
z_measured[i] = z_probed_height; z_measured[i] = z_probed_height;
@ -155,9 +159,9 @@ void GcodeSuite::G35() {
const float decimal_part = adjust - float(full_turns); const float decimal_part = adjust - float(full_turns);
const int minutes = trunc(decimal_part * 60.0f); const int minutes = trunc(decimal_part * 60.0f);
SERIAL_ECHOPAIR("Turn ", tramming_point_name[i], SERIAL_ECHOPGM("Turn ");
" ", (screw_thread & 1) == (adjust > 0) ? "CCW" : "CW", SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));
" by ", abs(full_turns), " turns"); SERIAL_ECHOPAIR(" ", (screw_thread & 1) == (adjust > 0) ? "CCW" : "CW", " by ", abs(full_turns), " turns");
if (minutes) SERIAL_ECHOPAIR(" and ", abs(minutes), " minutes"); if (minutes) SERIAL_ECHOPAIR(" and ", abs(minutes), " minutes");
if (ENABLED(REPORT_TRAMMING_MM)) SERIAL_ECHOPAIR(" (", -diff, "mm)"); if (ENABLED(REPORT_TRAMMING_MM)) SERIAL_ECHOPAIR(" (", -diff, "mm)");
SERIAL_EOL(); SERIAL_EOL();

View file

@ -80,7 +80,7 @@ void GcodeSuite::G34() {
const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT);
const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS]; const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS];
stepper.set_digipot_current(1, target_current); stepper.set_digipot_current(1, target_current);
#elif HAS_MOTOR_CURRENT_DAC #elif ENABLED(HAS_MOTOR_CURRENT_DAC)
const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT); const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT);
const float previous_current = dac_amps(Z_AXIS, target_current); const float previous_current = dac_amps(Z_AXIS, target_current);
stepper_dac.set_current_value(Z_AXIS, target_current); stepper_dac.set_current_value(Z_AXIS, target_current);
@ -126,7 +126,7 @@ void GcodeSuite::G34() {
stepper.set_digipot_current(Z_AXIS, previous_current); stepper.set_digipot_current(Z_AXIS, previous_current);
#elif HAS_MOTOR_CURRENT_PWM #elif HAS_MOTOR_CURRENT_PWM
stepper.set_digipot_current(1, previous_current); stepper.set_digipot_current(1, previous_current);
#elif HAS_MOTOR_CURRENT_DAC #elif ENABLED(HAS_MOTOR_CURRENT_DAC)
stepper_dac.set_current_value(Z_AXIS, previous_current); stepper_dac.set_current_value(Z_AXIS, previous_current);
#elif ENABLED(HAS_MOTOR_CURRENT_I2C) #elif ENABLED(HAS_MOTOR_CURRENT_I2C)
digipot_i2c.set_current(Z_AXIS, previous_current) digipot_i2c.set_current(Z_AXIS, previous_current)

View file

@ -69,9 +69,13 @@ void GcodeSuite::M3_M4(const bool is_M4) {
auto get_s_power = [] { auto get_s_power = [] {
if (parser.seenval('S')) { if (parser.seenval('S')) {
const float spwr = parser.value_float(); const float spwr = parser.value_float();
cutter.unitPower = TERN(SPINDLE_LASER_PWM, #if ENABLED(SPINDLE_SERVO)
cutter.unitPower = spwr;
#else
cutter.unitPower = TERN(SPINDLE_LASER_PWM,
cutter.power_to_range(cutter_power_t(round(spwr))), cutter.power_to_range(cutter_power_t(round(spwr))),
spwr > 0 ? 255 : 0); spwr > 0 ? 255 : 0);
#endif
} }
else else
cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP); cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
@ -108,6 +112,8 @@ void GcodeSuite::M3_M4(const bool is_M4) {
} }
else else
cutter.set_power(cutter.upower_to_ocr(get_s_power())); cutter.set_power(cutter.upower_to_ocr(get_s_power()));
#elif ENABLED(SPINDLE_SERVO)
cutter.set_power(get_s_power());
#else #else
cutter.set_enabled(true); cutter.set_enabled(true);
#endif #endif

View file

@ -54,9 +54,7 @@
size_t total = persistentStore.capacity(); size_t total = persistentStore.capacity();
int pos = 0; int pos = 0;
const uint8_t value = 0x0; const uint8_t value = 0x0;
while(total--) { while (total--) persistentStore.write_data(pos, &value, 1);
persistentStore.write_data(pos, &value, 1);
}
persistentStore.access_finish(); persistentStore.access_finish();
#else #else
settings.reset(); settings.reset();
@ -70,7 +68,7 @@
uint8_t *pointer = parser.hex_adr_val('A'); uint8_t *pointer = parser.hex_adr_val('A');
uint16_t len = parser.ushortval('C', 1); uint16_t len = parser.ushortval('C', 1);
uintptr_t addr = (uintptr_t)pointer; uintptr_t addr = (uintptr_t)pointer;
NOMORE(addr, (size_t)(SRAM_SIZE - 1)); NOMORE(addr, size_t(SRAM_SIZE - 1));
NOMORE(len, SRAM_SIZE - addr); NOMORE(len, SRAM_SIZE - addr);
if (parser.seenval('X')) { if (parser.seenval('X')) {
// Write the hex bytes after the X // Write the hex bytes after the X
@ -91,16 +89,13 @@
uint8_t *pointer = parser.hex_adr_val('A'); uint8_t *pointer = parser.hex_adr_val('A');
uint16_t len = parser.ushortval('C', 1); uint16_t len = parser.ushortval('C', 1);
uintptr_t addr = (uintptr_t)pointer; uintptr_t addr = (uintptr_t)pointer;
#ifndef MARLIN_EEPROM_SIZE NOMORE(addr, size_t(persistentStore.capacity() - 1));
#define MARLIN_EEPROM_SIZE size_t(E2END + 1) NOMORE(len, persistentStore.capacity() - addr);
#endif
NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1));
NOMORE(len, MARLIN_EEPROM_SIZE - addr);
if (parser.seenval('X')) { if (parser.seenval('X')) {
uint16_t val = parser.hex_val('X'); uint16_t val = parser.hex_val('X');
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
persistentStore.access_start(); persistentStore.access_start();
while(len--) { while (len--) {
int pos = 0; int pos = 0;
persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val));
} }
@ -111,23 +106,18 @@
#endif #endif
} }
else { else {
while (len--) { // Read bytes from EEPROM
// Read bytes from EEPROM #if ENABLED(EEPROM_SETTINGS)
#if ENABLED(EEPROM_SETTINGS) persistentStore.access_start();
persistentStore.access_start(); int pos = 0;
uint8_t val; uint8_t val;
while(len--) { while (len--) if (!persistentStore.read_data(pos, &val, 1)) print_hex_byte(val);
int pos = 0; SERIAL_EOL();
if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) { persistentStore.access_finish();
print_hex_byte(val); #else
} SERIAL_ECHOLNPGM("NO EEPROM");
} len = 0;
SERIAL_EOL(); #endif
persistentStore.access_finish();
#else
SERIAL_ECHOLNPGM("NO EEPROM");
#endif
}
SERIAL_EOL(); SERIAL_EOL();
} }
} break; } break;
@ -156,7 +146,7 @@
uint8_t *pointer = parser.hex_adr_val('A'); uint8_t *pointer = parser.hex_adr_val('A');
uint16_t len = parser.ushortval('C', 1); uint16_t len = parser.ushortval('C', 1);
uintptr_t addr = (uintptr_t)pointer; uintptr_t addr = (uintptr_t)pointer;
NOMORE(addr, (size_t)(FLASH_SIZE - 1)); NOMORE(addr, size_t(FLASH_SIZE - 1));
NOMORE(len, FLASH_SIZE - addr); NOMORE(len, FLASH_SIZE - addr);
if (parser.seenval('X')) { if (parser.seenval('X')) {
// TODO: Write the hex bytes after the X // TODO: Write the hex bytes after the X
@ -181,7 +171,7 @@
// Use a low-level delay that does not rely on interrupts to function // Use a low-level delay that does not rely on interrupts to function
// Do not spin forever, to avoid thermal risks if heaters are enabled and // Do not spin forever, to avoid thermal risks if heaters are enabled and
// watchdog does not work. // watchdog does not work.
DELAY_US(10000000); for (int i = 10000; i--;) DELAY_US(1000UL);
ENABLE_ISRS(); ENABLE_ISRS();
SERIAL_ECHOLNPGM("FAILURE: Watchdog did not trigger board reset."); SERIAL_ECHOLNPGM("FAILURE: Watchdog did not trigger board reset.");
} }

View file

@ -245,7 +245,7 @@ public:
#endif #endif
// The code value pointer was set // The code value pointer was set
FORCE_INLINE static bool has_value() { return value_ptr != nullptr; } FORCE_INLINE static bool has_value() { return !!value_ptr; }
// Seen a parameter with a value // Seen a parameter with a value
static inline bool seenval(const char c) { return seen(c) && has_value(); } static inline bool seenval(const char c) { return seen(c) && has_value(); }

View file

@ -180,7 +180,7 @@ bool GCodeQueue::enqueue_one(const char* cmd) {
* Return 'true' if any commands were processed. * Return 'true' if any commands were processed.
*/ */
bool GCodeQueue::process_injected_command_P() { bool GCodeQueue::process_injected_command_P() {
if (injected_commands_P == nullptr) return false; if (!injected_commands_P) return false;
char c; char c;
size_t i = 0; size_t i = 0;
@ -480,7 +480,7 @@ void GCodeQueue::get_serial_commands() {
if (npos) { if (npos) {
bool M110 = strstr_P(command, PSTR("M110")) != nullptr; const bool M110 = !!strstr_P(command, PSTR("M110"));
if (M110) { if (M110) {
char* n2pos = strchr(command + 4, 'N'); char* n2pos = strchr(command + 4, 'N');

View file

@ -675,6 +675,10 @@
#define HAS_BED_PROBE 1 #define HAS_BED_PROBE 1
#endif #endif
#if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
#undef PROBE_MANUALLY
#endif
#if ANY(HAS_BED_PROBE, PROBE_MANUALLY, MESH_BED_LEVELING) #if ANY(HAS_BED_PROBE, PROBE_MANUALLY, MESH_BED_LEVELING)
#define PROBE_SELECTED 1 #define PROBE_SELECTED 1
#endif #endif
@ -747,6 +751,7 @@
#define HAS_PROBING_PROCEDURE 1 #define HAS_PROBING_PROCEDURE 1
#endif #endif
#if !HAS_LEVELING #if !HAS_LEVELING
#undef PROBE_MANUALLY
#undef RESTORE_LEVELING_AFTER_G28 #undef RESTORE_LEVELING_AFTER_G28
#endif #endif

View file

@ -33,7 +33,7 @@
// Determine NUM_SERVOS if none was supplied // Determine NUM_SERVOS if none was supplied
#ifndef NUM_SERVOS #ifndef NUM_SERVOS
#define NUM_SERVOS 0 #define NUM_SERVOS 0
#if ANY(CHAMBER_VENT, HAS_Z_SERVO_PROBE, SWITCHING_EXTRUDER, SWITCHING_NOZZLE) #if ANY(HAS_Z_SERVO_PROBE, CHAMBER_VENT, SWITCHING_TOOLHEAD, SWITCHING_EXTRUDER, SWITCHING_NOZZLE, SPINDLE_SERVO)
#if NUM_SERVOS <= Z_PROBE_SERVO_NR #if NUM_SERVOS <= Z_PROBE_SERVO_NR
#undef NUM_SERVOS #undef NUM_SERVOS
#define NUM_SERVOS (Z_PROBE_SERVO_NR + 1) #define NUM_SERVOS (Z_PROBE_SERVO_NR + 1)
@ -62,6 +62,10 @@
#undef NUM_SERVOS #undef NUM_SERVOS
#define NUM_SERVOS (SWITCHING_EXTRUDER_E23_SERVO_NR + 1) #define NUM_SERVOS (SWITCHING_EXTRUDER_E23_SERVO_NR + 1)
#endif #endif
#if NUM_SERVOS <= SPINDLE_SERVO_NR
#undef NUM_SERVOS
#define NUM_SERVOS (SPINDLE_SERVO_NR + 1)
#endif
#endif #endif
#endif #endif

View file

@ -2505,11 +2505,11 @@
/** /**
* Buzzer/Speaker * Buzzer/Speaker
*/ */
#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) #if PIN_EXISTS(BEEPER)
#define USE_BEEPER 1
#endif
#if USE_BEEPER || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER)
#define HAS_BUZZER 1 #define HAS_BUZZER 1
#if PIN_EXISTS(BEEPER)
#define USE_BEEPER 1
#endif
#endif #endif
#if ENABLED(LCD_USE_I2C_BUZZER) #if ENABLED(LCD_USE_I2C_BUZZER)
@ -2528,8 +2528,12 @@
#endif #endif
#endif #endif
#if HAS_BUZZER && LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ #if HAS_BUZZER
#define HAS_CHIRP 1 #if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ
#define HAS_CHIRP 1
#endif
#else
#undef SOUND_MENU_ITEM // No buzzer menu item without a buzzer
#endif #endif
/** /**

View file

@ -1382,9 +1382,6 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
* Unified Bed Leveling * Unified Bed Leveling
*/ */
// Hide PROBE_MANUALLY from the rest of the code
#undef PROBE_MANUALLY
#if IS_SCARA #if IS_SCARA
#error "AUTO_BED_LEVELING_UBL does not yet support SCARA printers." #error "AUTO_BED_LEVELING_UBL does not yet support SCARA printers."
#elif DISABLED(EEPROM_SETTINGS) #elif DISABLED(EEPROM_SETTINGS)
@ -1410,13 +1407,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#elif ENABLED(MESH_BED_LEVELING) #elif ENABLED(MESH_BED_LEVELING)
// Hide PROBE_MANUALLY from the rest of the code // Mesh Bed Leveling
#undef PROBE_MANUALLY
/**
* Mesh Bed Leveling
*/
#if ENABLED(DELTA) #if ENABLED(DELTA)
#error "MESH_BED_LEVELING is not compatible with DELTA printers." #error "MESH_BED_LEVELING is not compatible with DELTA printers."
#elif GRID_MAX_POINTS_X > 9 || GRID_MAX_POINTS_Y > 9 #elif GRID_MAX_POINTS_X > 9 || GRID_MAX_POINTS_Y > 9
@ -3007,8 +2998,8 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#if HAS_CUTTER #if HAS_CUTTER
#ifndef CUTTER_POWER_UNIT #ifndef CUTTER_POWER_UNIT
#error "CUTTER_POWER_UNIT is required with a spindle or laser. Please update your Configuration_adv.h." #error "CUTTER_POWER_UNIT is required with a spindle or laser. Please update your Configuration_adv.h."
#elif !CUTTER_UNIT_IS(PWM255) && !CUTTER_UNIT_IS(PERCENT) && !CUTTER_UNIT_IS(RPM) #elif !CUTTER_UNIT_IS(PWM255) && !CUTTER_UNIT_IS(PERCENT) && !CUTTER_UNIT_IS(RPM) && !CUTTER_UNIT_IS(SERVO)
#error "CUTTER_POWER_UNIT must be PWM255, PERCENT, or RPM. Please update your Configuration_adv.h." #error "CUTTER_POWER_UNIT must be PWM255, PERCENT, RPM, or SERVO. Please update your Configuration_adv.h."
#endif #endif
#if ENABLED(LASER_POWER_INLINE) #if ENABLED(LASER_POWER_INLINE)
@ -3047,8 +3038,8 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#define _PIN_CONFLICT(P) (PIN_EXISTS(P) && P##_PIN == SPINDLE_LASER_PWM_PIN) #define _PIN_CONFLICT(P) (PIN_EXISTS(P) && P##_PIN == SPINDLE_LASER_PWM_PIN)
#if BOTH(SPINDLE_FEATURE, LASER_FEATURE) #if BOTH(SPINDLE_FEATURE, LASER_FEATURE)
#error "Enable only one of SPINDLE_FEATURE or LASER_FEATURE." #error "Enable only one of SPINDLE_FEATURE or LASER_FEATURE."
#elif !PIN_EXISTS(SPINDLE_LASER_ENA) #elif !PIN_EXISTS(SPINDLE_LASER_ENA) && DISABLED(SPINDLE_SERVO)
#error "(SPINDLE|LASER)_FEATURE requires SPINDLE_LASER_ENA_PIN." #error "(SPINDLE|LASER)_FEATURE requires SPINDLE_LASER_ENA_PIN or SPINDLE_SERVO to control the power."
#elif ENABLED(SPINDLE_CHANGE_DIR) && !PIN_EXISTS(SPINDLE_DIR) #elif ENABLED(SPINDLE_CHANGE_DIR) && !PIN_EXISTS(SPINDLE_DIR)
#error "SPINDLE_DIR_PIN is required for SPINDLE_CHANGE_DIR." #error "SPINDLE_DIR_PIN is required for SPINDLE_CHANGE_DIR."
#elif ENABLED(SPINDLE_LASER_PWM) #elif ENABLED(SPINDLE_LASER_PWM)

View file

@ -42,7 +42,7 @@
* version was tagged. * version was tagged.
*/ */
#ifndef STRING_DISTRIBUTION_DATE #ifndef STRING_DISTRIBUTION_DATE
#define STRING_DISTRIBUTION_DATE "2020-10-23" #define STRING_DISTRIBUTION_DATE "2020-11-06"
#endif #endif
/** /**

View file

@ -113,6 +113,7 @@ static void createChar_P(const char c, const byte * const ptr) {
#if ENABLED(LCD_USE_I2C_BUZZER) #if ENABLED(LCD_USE_I2C_BUZZER)
void MarlinUI::buzz(const long duration, const uint16_t freq) { void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!buzzer_enabled) return;
lcd.buzz(duration, freq); lcd.buzz(duration, freq);
} }
#endif #endif
@ -1036,7 +1037,7 @@ void MarlinUI::draw_status_screen() {
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
ui.encoder_direction_normal(); ui.encoder_direction_normal();
uint8_t n = lcd_put_u8str_ind_P(0, 1, pstr, itemIndex, itemString, LCD_WIDTH - 1); uint8_t n = lcd_put_u8str_ind_P(0, 1, pstr, itemIndex, itemString, LCD_WIDTH - 1);
if (value != nullptr) { if (value) {
lcd_put_wchar(':'); n--; lcd_put_wchar(':'); n--;
const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space
const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit

View file

@ -289,6 +289,7 @@ uint8_t MarlinUI::read_slow_buttons(void) {
// Duration in ms, freq in Hz // Duration in ms, freq in Hz
void MarlinUI::buzz(const long duration, const uint16_t freq) { void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!PanelDetected) return; if (!PanelDetected) return;
if (!buzzer_enabled) return;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
SPI_SEND_ONE(BUZZER); SPI_SEND_ONE(BUZZER);
@ -863,7 +864,7 @@ void MarlinUI::draw_status_screen() {
lcd.setCursor(0, MIDDLE_Y); lcd.setCursor(0, MIDDLE_Y);
lcd.write(COLOR_EDIT); lcd.write(COLOR_EDIT);
lcd_put_u8str_P(pstr); lcd_put_u8str_P(pstr);
if (value != nullptr) { if (value) {
lcd.write(':'); lcd.write(':');
lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces
lcd.write(' '); // Overwrite char if value gets shorter lcd.write(' '); // Overwrite char if value gets shorter

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