From 7410d24f1f445466ada20e9fa218a70a2ae8c8e0 Mon Sep 17 00:00:00 2001 From: InsanityAutomation Date: Fri, 28 Sep 2018 12:13:04 -0400 Subject: [PATCH] Update removed / renamed / moved files --- Marlin/src/HAL/Delay.h | 148 -- .../src/HAL/HAL_AVR/persistent_store_impl.cpp | 51 - .../src/HAL/HAL_DUE/persistent_store_impl.cpp | 59 - Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp | 321 ---- Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h | 191 -- Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp | 329 ---- Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h | 120 -- .../HAL/HAL_LPC1768/persistent_store_impl.cpp | 170 -- Marlin/src/HAL/HAL_SPI.h | 82 - .../HAL/HAL_STM32F1/persistent_store_impl.cpp | 97 - .../HAL/HAL_STM32F4/persistent_store_impl.cpp | 74 - .../HAL/HAL_STM32F7/persistent_store_impl.cpp | 77 - Marlin/src/HAL/I2cEeprom.cpp | 160 -- Marlin/src/HAL/SpiEeprom.cpp | 119 -- Marlin/src/HAL/backtrace/backtrace.cpp | 101 - Marlin/src/HAL/backtrace/backtrace.h | 29 - Marlin/src/HAL/backtrace/unwarm.cpp | 175 -- Marlin/src/HAL/backtrace/unwarm.h | 143 -- Marlin/src/HAL/backtrace/unwarm_arm.cpp | 597 ------ Marlin/src/HAL/backtrace/unwarm_thumb.cpp | 1127 ----------- Marlin/src/HAL/backtrace/unwarmbytab.cpp | 441 ----- Marlin/src/HAL/backtrace/unwarmbytab.h | 34 - Marlin/src/HAL/backtrace/unwarmmem.cpp | 118 -- Marlin/src/HAL/backtrace/unwarmmem.h | 25 - Marlin/src/HAL/backtrace/unwinder.cpp | 61 - Marlin/src/HAL/backtrace/unwinder.h | 175 -- Marlin/src/HAL/backtrace/unwmemaccess.cpp | 147 -- Marlin/src/HAL/backtrace/unwmemaccess.h | 26 - Marlin/src/HAL/math_32bit.h | 35 - Marlin/src/HAL/persistent_store_api.h | 18 - Marlin/src/HAL/servo.cpp | 161 -- Marlin/src/HAL/servo.h | 113 -- Marlin/src/HAL/servo_private.h | 102 - .../examples/Azteeg/X5GT/Configuration_adv.h | 1685 ---------------- .../delta/kossel_pro/Configuration_adv.h | 1692 ----------------- Marlin/src/pins/pins_RURAMPS4D.h | 253 --- 36 files changed, 9256 deletions(-) delete mode 100644 Marlin/src/HAL/Delay.h delete mode 100644 Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp delete mode 100644 Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h delete mode 100644 Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp delete mode 100644 Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h delete mode 100644 Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/HAL_SPI.h delete mode 100644 Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/I2cEeprom.cpp delete mode 100644 Marlin/src/HAL/SpiEeprom.cpp delete mode 100644 Marlin/src/HAL/backtrace/backtrace.cpp delete mode 100644 Marlin/src/HAL/backtrace/backtrace.h delete mode 100644 Marlin/src/HAL/backtrace/unwarm.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwarm.h delete mode 100644 Marlin/src/HAL/backtrace/unwarm_arm.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwarm_thumb.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwarmbytab.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwarmbytab.h delete mode 100644 Marlin/src/HAL/backtrace/unwarmmem.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwarmmem.h delete mode 100644 Marlin/src/HAL/backtrace/unwinder.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwinder.h delete mode 100644 Marlin/src/HAL/backtrace/unwmemaccess.cpp delete mode 100644 Marlin/src/HAL/backtrace/unwmemaccess.h delete mode 100644 Marlin/src/HAL/math_32bit.h delete mode 100644 Marlin/src/HAL/persistent_store_api.h delete mode 100644 Marlin/src/HAL/servo.cpp delete mode 100644 Marlin/src/HAL/servo.h delete mode 100644 Marlin/src/HAL/servo_private.h delete mode 100644 Marlin/src/config/examples/Azteeg/X5GT/Configuration_adv.h delete mode 100644 Marlin/src/config/examples/delta/kossel_pro/Configuration_adv.h delete mode 100644 Marlin/src/pins/pins_RURAMPS4D.h diff --git a/Marlin/src/HAL/Delay.h b/Marlin/src/HAL/Delay.h deleted file mode 100644 index 972f1e2c18..0000000000 --- a/Marlin/src/HAL/Delay.h +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * Busy wait delay cycles routines: - * - * DELAY_CYCLES(count): Delay execution in cycles - * DELAY_NS(count): Delay execution in nanoseconds - * DELAY_US(count): Delay execution in microseconds - */ - -#ifndef MARLIN_DELAY_H -#define MARLIN_DELAY_H - -#include "../core/macros.h" - -#if defined(__arm__) || defined(__thumb__) - - // https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles - - #define nop() __asm__ __volatile__("nop;\n\t":::) - - FORCE_INLINE static void __delay_4cycles(uint32_t cy) { // +1 cycle - #if ARCH_PIPELINE_RELOAD_CYCLES < 2 - #define EXTRA_NOP_CYCLES A("nop") - #else - #define EXTRA_NOP_CYCLES "" - #endif - - __asm__ __volatile__( - A(".syntax unified") // is to prevent CM0,CM1 non-unified syntax - L("1") - A("subs %[cnt],#1") - EXTRA_NOP_CYCLES - A("bne 1b") - : [cnt]"+r"(cy) // output: +r means input+output - : // input: - : "cc" // clobbers: - ); - } - - // Delay in cycles - FORCE_INLINE static void DELAY_CYCLES(uint32_t x) { - - if (__builtin_constant_p(x)) { - #define MAXNOPS 4 - - if (x <= (MAXNOPS)) { - switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); } - } - else { // because of +1 cycle inside delay_4cycles - const uint32_t rem = (x - 1) % (MAXNOPS); - switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); } - if ((x = (x - 1) / (MAXNOPS))) - __delay_4cycles(x); // if need more then 4 nop loop is more optimal - } - #undef MAXNOPS - } - else - __delay_4cycles(x / 4); - } - #undef nop - -#elif defined(__AVR__) - - #define nop() __asm__ __volatile__("nop;\n\t":::) - - FORCE_INLINE static void __delay_4cycles(uint8_t cy) { - __asm__ __volatile__( - L("1") - A("dec %[cnt]") - A("nop") - A("brne 1b") - : [cnt] "+r"(cy) // output: +r means input+output - : // input: - : "cc" // clobbers: - ); - } - - // Delay in cycles - FORCE_INLINE static void DELAY_CYCLES(uint16_t x) { - - if (__builtin_constant_p(x)) { - #define MAXNOPS 4 - - if (x <= (MAXNOPS)) { - switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); } - } - else { - const uint32_t rem = (x) % (MAXNOPS); - switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); } - if ((x = (x) / (MAXNOPS))) - __delay_4cycles(x); // if need more then 4 nop loop is more optimal - } - - #undef MAXNOPS - } - else - __delay_4cycles(x / 4); - } - #undef nop - -#elif defined(ESP32) - - FORCE_INLINE static void DELAY_CYCLES(uint32_t x) { - unsigned long ccount, stop; - - __asm__ __volatile__ ( "rsr %0, ccount" : "=a" (ccount) ); - - stop = ccount + x; // This can overflow - - while (ccount < stop) { // This doesn't deal with overflows - __asm__ __volatile__ ( "rsr %0, ccount" : "=a" (ccount) ); - } - } - -#else - - #error "Unsupported MCU architecture" - -#endif - -// Delay in nanoseconds -#define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) / 1000L ) - -// Delay in microseconds -#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) ) - -#endif // MARLIN_DELAY_H diff --git a/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp deleted file mode 100644 index ef6fbeabd5..0000000000 --- a/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef __AVR__ - -#include "../persistent_store_api.h" - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) - -namespace HAL { -namespace PersistentStore { - -bool access_start() { return true; } -bool access_finish() { return true; } - -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { - while (size--) { - uint8_t * const p = (uint8_t * const)pos; - uint8_t v = *value; - // EEPROM has only ~100,000 write cycles, - // so only write bytes that have changed! - if (v != eeprom_read_byte(p)) { - eeprom_write_byte(p, v); - if (eeprom_read_byte(p) != v) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE); - return true; - } - } - crc16(crc, &v, 1); - pos++; - value++; - }; - return false; -} - -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) { - do { - uint8_t c = eeprom_read_byte((unsigned char*)pos); - if (writing) *value = c; - crc16(crc, &c, 1); - pos++; - value++; - } while (--size); - return false; // always assume success for AVR's -} - -} -} - -#endif // EEPROM_SETTINGS -#endif // __AVR__ diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp deleted file mode 100644 index aef1d79f48..0000000000 --- a/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifdef ARDUINO_ARCH_SAM - -#include "../persistent_store_api.h" - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) - -extern void eeprom_flush(void); - -namespace HAL { -namespace PersistentStore { - -bool access_start() { return true; } - -bool access_finish() { - #if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM) - eeprom_flush(); - #endif - return true; -} - -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { - while (size--) { - uint8_t * const p = (uint8_t * const)pos; - uint8_t v = *value; - // EEPROM has only ~100,000 write cycles, - // so only write bytes that have changed! - if (v != eeprom_read_byte(p)) { - eeprom_write_byte(p, v); - if (eeprom_read_byte(p) != v) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE); - return true; - } - } - crc16(crc, &v, 1); - pos++; - value++; - }; - return false; -} - -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) { - do { - uint8_t c = eeprom_read_byte((unsigned char*)pos); - if (writing) *value = c; - crc16(crc, &c, 1); - pos++; - value++; - } while (--size); - return false; -} - -} -} - -#endif // EEPROM_SETTINGS -#endif // __AVR__ diff --git a/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp deleted file mode 100644 index 98ea4f8fc6..0000000000 --- a/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifdef TARGET_LPC1768 - -#include "HardwareSerial.h" - -#if SERIAL_PORT == 0 || SERIAL_PORT_2 == 0 - HardwareSerial Serial = HardwareSerial(LPC_UART0); -#elif SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 - HardwareSerial Serial1 = HardwareSerial((LPC_UART_TypeDef *) LPC_UART1); -#elif SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 - HardwareSerial Serial2 = HardwareSerial(LPC_UART2); -#elif SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 - HardwareSerial Serial3 = HardwareSerial(LPC_UART3); -#endif - -void HardwareSerial::begin(uint32_t baudrate) { - - UART_CFG_Type UARTConfigStruct; - PINSEL_CFG_Type PinCfg; - UART_FIFO_CFG_Type FIFOConfig; - - if (Baudrate == baudrate) return; // No need to re-initialize - - if (UARTx == LPC_UART0) { - // Initialize UART0 pin connect - PinCfg.Funcnum = 1; - PinCfg.OpenDrain = 0; - PinCfg.Pinmode = 0; - PinCfg.Pinnum = 2; - PinCfg.Portnum = 0; - PINSEL_ConfigPin(&PinCfg); - PinCfg.Pinnum = 3; - PINSEL_ConfigPin(&PinCfg); - } else if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) { - // Initialize UART1 pin connect - PinCfg.Funcnum = 1; - PinCfg.OpenDrain = 0; - PinCfg.Pinmode = 0; - PinCfg.Pinnum = 15; - PinCfg.Portnum = 0; - PINSEL_ConfigPin(&PinCfg); - PinCfg.Pinnum = 16; - PINSEL_ConfigPin(&PinCfg); - } else if (UARTx == LPC_UART2) { - // Initialize UART2 pin connect - PinCfg.Funcnum = 1; - PinCfg.OpenDrain = 0; - PinCfg.Pinmode = 0; - PinCfg.Pinnum = 10; - PinCfg.Portnum = 0; - PINSEL_ConfigPin(&PinCfg); - PinCfg.Pinnum = 11; - PINSEL_ConfigPin(&PinCfg); - } else if (UARTx == LPC_UART3) { - // Initialize UART2 pin connect - PinCfg.Funcnum = 1; - PinCfg.OpenDrain = 0; - PinCfg.Pinmode = 0; - PinCfg.Pinnum = 0; - PinCfg.Portnum = 0; - PINSEL_ConfigPin(&PinCfg); - PinCfg.Pinnum = 1; - PINSEL_ConfigPin(&PinCfg); - } - - /* Initialize UART Configuration parameter structure to default state: - * Baudrate = 9600bps - * 8 data bit - * 1 Stop bit - * None parity - */ - UART_ConfigStructInit(&UARTConfigStruct); - - // Re-configure baudrate - UARTConfigStruct.Baud_rate = baudrate; - - // Initialize eripheral with given to corresponding parameter - UART_Init(UARTx, &UARTConfigStruct); - - // Enable and reset the TX and RX FIFOs - UART_FIFOConfigStructInit(&FIFOConfig); - UART_FIFOConfig(UARTx, &FIFOConfig); - - // Enable UART Transmit - UART_TxCmd(UARTx, ENABLE); - - // Configure Interrupts - UART_IntConfig(UARTx, UART_INTCFG_RBR, ENABLE); - UART_IntConfig(UARTx, UART_INTCFG_RLS, ENABLE); - - if (UARTx == LPC_UART0) NVIC_EnableIRQ(UART0_IRQn); - else if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) NVIC_EnableIRQ(UART1_IRQn); - else if (UARTx == LPC_UART2) NVIC_EnableIRQ(UART2_IRQn); - else if (UARTx == LPC_UART3) NVIC_EnableIRQ(UART3_IRQn); - - RxQueueWritePos = RxQueueReadPos = 0; - #if TX_BUFFER_SIZE > 0 - TxQueueWritePos = TxQueueReadPos = 0; - #endif - - // Save the configured baudrate - Baudrate = baudrate; -} - -int HardwareSerial::peek() { - int byte = -1; - - // Temporarily lock out UART receive interrupts during this read so the UART receive - // interrupt won't cause problems with the index values - UART_IntConfig(UARTx, UART_INTCFG_RBR, DISABLE); - - if (RxQueueReadPos != RxQueueWritePos) - byte = RxBuffer[RxQueueReadPos]; - - // Re-enable UART interrupts - UART_IntConfig(UARTx, UART_INTCFG_RBR, ENABLE); - - return byte; -} - -int HardwareSerial::read() { - int byte = -1; - - // Temporarily lock out UART receive interrupts during this read so the UART receive - // interrupt won't cause problems with the index values - UART_IntConfig(UARTx, UART_INTCFG_RBR, DISABLE); - - if (RxQueueReadPos != RxQueueWritePos) { - byte = RxBuffer[RxQueueReadPos]; - RxQueueReadPos = (RxQueueReadPos + 1) % RX_BUFFER_SIZE; - } - - // Re-enable UART interrupts - UART_IntConfig(UARTx, UART_INTCFG_RBR, ENABLE); - - return byte; -} - -size_t HardwareSerial::write(uint8_t send) { -#if TX_BUFFER_SIZE > 0 - size_t bytes = 0; - uint32_t fifolvl = 0; - - // If the Tx Buffer is full, wait for space to clear - if ((TxQueueWritePos+1) % TX_BUFFER_SIZE == TxQueueReadPos) flushTX(); - - // Temporarily lock out UART transmit interrupts during this read so the UART transmit interrupt won't - // cause problems with the index values - UART_IntConfig(UARTx, UART_INTCFG_THRE, DISABLE); - - // LPC17xx.h incorrectly defines FIFOLVL as a uint8_t, when it's actually a 32-bit register - if ((LPC_UART1_TypeDef *) UARTx == LPC_UART1) { - fifolvl = *(reinterpret_cast(&((LPC_UART1_TypeDef *) UARTx)->FIFOLVL)); - } else fifolvl = *(reinterpret_cast(&UARTx->FIFOLVL)); - - // If the queue is empty and there's space in the FIFO, immediately send the byte - if (TxQueueWritePos == TxQueueReadPos && fifolvl < UART_TX_FIFO_SIZE) { - bytes = UART_Send(UARTx, &send, 1, BLOCKING); - } - // Otherwiise, write the byte to the transmit buffer - else if ((TxQueueWritePos+1) % TX_BUFFER_SIZE != TxQueueReadPos) { - TxBuffer[TxQueueWritePos] = send; - TxQueueWritePos = (TxQueueWritePos+1) % TX_BUFFER_SIZE; - bytes++; - } - - // Re-enable the TX Interrupt - UART_IntConfig(UARTx, UART_INTCFG_THRE, ENABLE); - - return bytes; -#else - return UART_Send(UARTx, &send, 1, BLOCKING); -#endif -} - -#if TX_BUFFER_SIZE > 0 - void HardwareSerial::flushTX() { - // Wait for the tx buffer and FIFO to drain - while (TxQueueWritePos != TxQueueReadPos && UART_CheckBusy(UARTx) == SET); - } -#endif - -int HardwareSerial::available() { - return (RxQueueWritePos + RX_BUFFER_SIZE - RxQueueReadPos) % RX_BUFFER_SIZE; -} - -void HardwareSerial::flush() { - RxQueueWritePos = 0; - RxQueueReadPos = 0; -} - -void HardwareSerial::printf(const char *format, ...) { - char RxBuffer[256]; - va_list vArgs; - va_start(vArgs, format); - int length = vsnprintf(RxBuffer, 256, format, vArgs); - va_end(vArgs); - if (length > 0 && length < 256) { - for (int i = 0; i < length; ++i) - write(RxBuffer[i]); - } -} - -void HardwareSerial::IRQHandler() { - uint32_t IIRValue; - uint8_t LSRValue, byte; - - IIRValue = UART_GetIntId(UARTx); - IIRValue &= UART_IIR_INTID_MASK; // check bit 1~3, interrupt identification - - // Receive Line Status - if (IIRValue == UART_IIR_INTID_RLS) { - LSRValue = UART_GetLineStatus(UARTx); - - // Receive Line Status - if (LSRValue & (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE | UART_LSR_RXFE | UART_LSR_BI)) { - // There are errors or break interrupt - // Read LSR will clear the interrupt - Status = LSRValue; - byte = UART_ReceiveByte(UARTx); // Dummy read on RX to clear interrupt, then bail out - return; - } - } - - // Receive Data Available - if (IIRValue == UART_IIR_INTID_RDA) { - // Clear the FIFO - while (UART_Receive(UARTx, &byte, 1, NONE_BLOCKING)) { - #if ENABLED(EMERGENCY_PARSER) - emergency_parser.update(emergency_state, byte); - #endif - if ((RxQueueWritePos + 1) % RX_BUFFER_SIZE != RxQueueReadPos) { - RxBuffer[RxQueueWritePos] = byte; - RxQueueWritePos = (RxQueueWritePos + 1) % RX_BUFFER_SIZE; - } else - break; - } - // Character timeout indicator - } else if (IIRValue == UART_IIR_INTID_CTI) { - // Character Time-out indicator - Status |= 0x100; // Bit 9 as the CTI error - } - - #if TX_BUFFER_SIZE > 0 - if (IIRValue == UART_IIR_INTID_THRE) { - // Disable THRE interrupt - UART_IntConfig(UARTx, UART_INTCFG_THRE, DISABLE); - - // Wait for FIFO buffer empty - while (UART_CheckBusy(UARTx) == SET); - - // Transfer up to UART_TX_FIFO_SIZE bytes of data - for (int i = 0; i < UART_TX_FIFO_SIZE && TxQueueWritePos != TxQueueReadPos; i++) { - // Move a piece of data into the transmit FIFO - if (UART_Send(UARTx, &TxBuffer[TxQueueReadPos], 1, NONE_BLOCKING)) { - TxQueueReadPos = (TxQueueReadPos+1) % TX_BUFFER_SIZE; - } else break; - } - - // If there is no more data to send, disable the transmit interrupt - else enable it or keep it enabled - if (TxQueueWritePos == TxQueueReadPos) { - UART_IntConfig(UARTx, UART_INTCFG_THRE, DISABLE); - } else UART_IntConfig(UARTx, UART_INTCFG_THRE, ENABLE); - } - #endif -} - -#ifdef __cplusplus -extern "C" { -#endif - -void UART0_IRQHandler(void) { - #if SERIAL_PORT == 0 || SERIAL_PORT_2 == 0 - Serial.IRQHandler(); - #endif -} - -void UART1_IRQHandler(void) { - #if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 - Serial1.IRQHandler(); - #endif -} - -void UART2_IRQHandler(void) { - #if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 - Serial2.IRQHandler(); - #endif -} - -void UART3_IRQHandler(void) { - #if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 - Serial3.IRQHandler(); - #endif -} - -#ifdef __cplusplus -} -#endif - -#endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h b/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h deleted file mode 100644 index 0f96652410..0000000000 --- a/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h +++ /dev/null @@ -1,191 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -#ifndef HARDWARE_SERIAL_H_ -#define HARDWARE_SERIAL_H_ - -#include "../../inc/MarlinConfigPre.h" -#if ENABLED(EMERGENCY_PARSER) - #include "../../feature/emergency_parser.h" -#endif - -#include -#include -#include - -extern "C" { - #include - #include "lpc17xx_pinsel.h" -} - -class HardwareSerial : public Stream { -private: - LPC_UART_TypeDef *UARTx; - - uint32_t Baudrate; - uint32_t Status; - uint8_t RxBuffer[RX_BUFFER_SIZE]; - uint32_t RxQueueWritePos; - uint32_t RxQueueReadPos; - #if TX_BUFFER_SIZE > 0 - uint8_t TxBuffer[TX_BUFFER_SIZE]; - uint32_t TxQueueWritePos; - uint32_t TxQueueReadPos; - #endif - #if ENABLED(EMERGENCY_PARSER) - EmergencyParser::State emergency_state; - #endif - -public: - HardwareSerial(LPC_UART_TypeDef *UARTx) - : UARTx(UARTx) - , Baudrate(0) - , RxQueueWritePos(0) - , RxQueueReadPos(0) - #if TX_BUFFER_SIZE > 0 - , TxQueueWritePos(0) - , TxQueueReadPos(0) - #endif - #if ENABLED(EMERGENCY_PARSER) - , emergency_state(EmergencyParser::State::EP_RESET) - #endif - { - } - - void begin(uint32_t baudrate); - int peek(); - int read(); - size_t write(uint8_t send); - #if TX_BUFFER_SIZE > 0 - void flushTX(); - #endif - int available(); - void flush(); - void printf(const char *format, ...); - - operator bool() { return true; } - - void IRQHandler(); - - #define DEC 10 - #define HEX 16 - #define OCT 8 - #define BIN 2 - - void print_bin(uint32_t value, uint8_t num_digits) { - uint32_t mask = 1 << (num_digits -1); - for (uint8_t i = 0; i < num_digits; i++) { - if (!(i % 4) && i) printf(" "); - if (!(i % 16) && i) printf(" "); - if (value & mask) printf("1"); - else printf("0"); - value <<= 1; - } - } - - void print(const char value[]) { - printf("%s" , value); - } - void print(char value, int nbase = 0) { - if (nbase == BIN) print_bin(value,8); - else if (nbase == OCT) printf("%3o", value); - else if (nbase == HEX) printf("%2X", value); - else if (nbase == DEC ) printf("%d", value); - else printf("%c" , value); - } - void print(unsigned char value, int nbase = 0) { - if (nbase == BIN) print_bin(value,8); - else if (nbase == OCT) printf("%3o", value); - else if (nbase == HEX) printf("%2X", value); - else printf("%u" , value); - } - void print(int value, int nbase = 0) { - if (nbase == BIN) print_bin(value,16); - else if (nbase == OCT) printf("%6o", value); - else if (nbase == HEX) printf("%4X", value); - else printf("%d", value); - } - void print(unsigned int value, int nbase = 0) { - if (nbase == BIN) print_bin(value,16); - else if (nbase == OCT) printf("%6o", value); - else if (nbase == HEX) printf("%4X", value); - else printf("%u" , value); - } - void print(long value, int nbase = 0) { - if (nbase == BIN) print_bin(value,32); - else if (nbase == OCT) printf("%11o", value); - else if (nbase == HEX) printf("%8X", value); - else printf("%ld" , value); - } - void print(unsigned long value, int nbase = 0) { - if (nbase == BIN) print_bin(value,32); - else if (nbase == OCT) printf("%11o", value); - else if (nbase == HEX) printf("%8X", value); - else printf("%lu" , value); - } - void print(float value, int round = 6) { - printf("%f" , value); - } - void print(double value, int round = 6) { - printf("%f" , value ); - } - - void println(const char value[]) { - printf("%s\n" , value); - } - void println(char value, int nbase = 0) { - print(value, nbase); - println(); - } - void println(unsigned char value, int nbase = 0) { - print(value, nbase); - println(); - } - void println(int value, int nbase = 0) { - print(value, nbase); - println(); - } - void println(unsigned int value, int nbase = 0) { - print(value, nbase); - println(); - } - void println(long value, int nbase = 0) { - print(value, nbase); - println(); - } - void println(unsigned long value, int nbase = 0) { - print(value, nbase); - println(); - } - void println(float value, int round = 6) { - printf("%f\n" , value ); - } - void println(double value, int round = 6) { - printf("%f\n" , value ); - } - void println(void) { - print('\n'); - } - -}; - -#endif // MARLIN_SRC_HAL_HAL_SERIAL_H_ diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp deleted file mode 100644 index 9604d045ba..0000000000 --- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * SoftwareSerial.cpp (formerly NewSoftSerial.cpp) - * - * Multi-instance software serial library for Arduino/Wiring - * -- Interrupt-driven receive and other improvements by ladyada - * (http://ladyada.net) - * -- Tuning, circular buffer, derivation from class Print/Stream, - * multi-instance support, porting to 8MHz processors, - * various optimizations, PROGMEM delay tables, inverse logic and - * direct port writing by Mikal Hart (http://www.arduiniana.org) - * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) - * -- 20MHz processor support by Garrett Mace (http://www.macetech.com) - * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * The latest version of this library can always be found at - * http://arduiniana.org. - */ - -#ifdef TARGET_LPC1768 - -// -// Includes -// -//#include -#include "../../inc/MarlinConfig.h" -#include "../Delay.h" -#include -#include -#include -#include -#include "fastio.h" -#include "SoftwareSerial.h" - -void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode); -void GpioDisableInt(uint32_t port, uint32_t pin); -// -// Statics -// -SoftwareSerial *SoftwareSerial::active_object = 0; -unsigned char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF]; -volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0; -volatile uint8_t SoftwareSerial::_receive_buffer_head = 0; - -typedef struct _DELAY_TABLE { - long baud; - uint16_t rx_delay_centering; - uint16_t rx_delay_intrabit; - uint16_t rx_delay_stopbit; - uint16_t tx_delay; -} DELAY_TABLE; - -// rough delay estimation -static const DELAY_TABLE table[] = { - //baud |rxcenter|rxintra |rxstop |tx { 250000, 2, 4, 4, 4, }, //Done but not good due to instruction cycle error { 115200, 4, 8, 8, 8, }, //Done but not good due to instruction cycle error - //{ 74880, 69, 139, 62, 162, }, // estimation - //{ 57600, 100, 185, 1, 208, }, // Done but not good due to instruction cycle error - //{ 38400, 13, 26, 26, 26, }, // Done - //{ 19200, 26, 52, 52, 52, }, // Done { 9600, 52, 104, 104, 104, }, // Done - //{ 4800, 104, 208, 208, 208, }, - //{ 2400, 208, 417, 417, 417, }, - //{ 1200, 416, 833, 833, 833,}, -}; - -// -// Private methods -// - -inline void SoftwareSerial::tunedDelay(const uint32_t count) { - DELAY_US(count); -} - -// This function sets the current object as the "listening" -// one and returns true if it replaces another -bool SoftwareSerial::listen() { - if (!_rx_delay_stopbit) - return false; - - if (active_object != this) { - if (active_object) - active_object->stopListening(); - - _buffer_overflow = false; - _receive_buffer_head = _receive_buffer_tail = 0; - active_object = this; - - setRxIntMsk(true); - return true; - } - - return false; -} - -// Stop listening. Returns true if we were actually listening. -bool SoftwareSerial::stopListening() { - if (active_object == this) { - setRxIntMsk(false); - active_object = NULL; - return true; - } - return false; -} - -// -// The receive routine called by the interrupt handler -// -void SoftwareSerial::recv() { - uint8_t d = 0; - - // If RX line is high, then we don't see any start bit - // so interrupt is probably not for us - if (_inverse_logic ? rx_pin_read() : !rx_pin_read()) { - // Disable further interrupts during reception, this prevents - // triggering another interrupt directly after we return, which can - // cause problems at higher baudrates. - setRxIntMsk(false);//__disable_irq();// - - // Wait approximately 1/2 of a bit width to "center" the sample - tunedDelay(_rx_delay_centering); - // Read each of the 8 bits - for (uint8_t i=8; i > 0; --i) { - tunedDelay(_rx_delay_intrabit); - d >>= 1; - if (rx_pin_read()) d |= 0x80; - } - - if (_inverse_logic) d = ~d; - - // if buffer full, set the overflow flag and return - uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF; - if (next != _receive_buffer_head) { - // save new data in buffer: tail points to where byte goes - _receive_buffer[_receive_buffer_tail] = d; // save new byte - _receive_buffer_tail = next; - } - else { - _buffer_overflow = true; - } - tunedDelay(_rx_delay_stopbit); - // Re-enable interrupts when we're sure to be inside the stop bit - setRxIntMsk(true); //__enable_irq();// - } -} - -uint32_t SoftwareSerial::rx_pin_read() { - return digitalRead(_receivePin); -} - -// -// Interrupt handling -// - -/* static */ -inline void SoftwareSerial::handle_interrupt() { - if (active_object) - active_object->recv(); -} -extern "C" void intWrapper() { - SoftwareSerial::handle_interrupt(); -} -// -// Constructor -// -SoftwareSerial::SoftwareSerial(pin_t receivePin, pin_t transmitPin, bool inverse_logic /* = false */) : - _rx_delay_centering(0), - _rx_delay_intrabit(0), - _rx_delay_stopbit(0), - _tx_delay(0), - _buffer_overflow(false), - _inverse_logic(inverse_logic) { - setTX(transmitPin); - setRX(receivePin); -} - -// -// Destructor -// -SoftwareSerial::~SoftwareSerial() { - end(); -} - -void SoftwareSerial::setTX(pin_t tx) { - // First write, then set output. If we do this the other way around, - // the pin would be output low for a short while before switching to - // output hihg. Now, it is input with pullup for a short while, which - // is fine. With inverse logic, either order is fine. - - digitalWrite(tx, _inverse_logic ? LOW : HIGH); - pinMode(tx,OUTPUT); - _transmitPin = tx; -} - -void SoftwareSerial::setRX(pin_t rx) { - pinMode(rx, INPUT_PULLUP); // pullup for normal logic! - //if (!_inverse_logic) - // digitalWrite(rx, HIGH); - _receivePin = rx; - _receivePort = LPC1768_PIN_PORT(rx); - _receivePortPin = LPC1768_PIN_PIN(rx); - /* GPIO_T * rxPort = digitalPinToPort(rx); - _receivePortRegister = portInputRegister(rxPort); - _receiveBitMask = digitalPinToBitMask(rx);*/ -} - -// -// Public methods -// - -void SoftwareSerial::begin(long speed) { - _rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0; - - for(uint8_t i = 0; i < sizeof(table)/sizeof(table[0]); ++i) { - long baud = table[i].baud; - if (baud == speed) { - _rx_delay_centering = table[i].rx_delay_centering; - _rx_delay_intrabit = table[i].rx_delay_intrabit; - _rx_delay_stopbit = table[i].rx_delay_stopbit; - _tx_delay = table[i].tx_delay; - break; - } - } - - attachInterrupt(_receivePin, intWrapper, CHANGE); //this->handle_interrupt, CHANGE); - - listen(); - tunedDelay(_tx_delay); - -} - -void SoftwareSerial::setRxIntMsk(bool enable) { - if (enable) - GpioEnableInt(_receivePort,_receivePin,CHANGE); - else - GpioDisableInt(_receivePort,_receivePin); -} - -void SoftwareSerial::end() { - stopListening(); -} - - -// Read data from buffer -int SoftwareSerial::read() { - if (!isListening()) return -1; - - // Empty buffer? - if (_receive_buffer_head == _receive_buffer_tail) return -1; - - // Read from "head" - uint8_t d = _receive_buffer[_receive_buffer_head]; // grab next byte - _receive_buffer_head = (_receive_buffer_head + 1) % _SS_MAX_RX_BUFF; - return d; -} - -int SoftwareSerial::available() { - if (!isListening()) return 0; - - return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; -} - -size_t SoftwareSerial::write(uint8_t b) { - // By declaring these as local variables, the compiler will put them - // in registers _before_ disabling interrupts and entering the - // critical timing sections below, which makes it a lot easier to - // verify the cycle timings - - bool inv = _inverse_logic; - uint16_t delay = _tx_delay; - - if (inv) b = ~b; - - cli(); // turn off interrupts for a clean txmit - - // Write the start bit - digitalWrite(_transmitPin, !!inv); - - tunedDelay(delay); - - // Write each of the 8 bits - for (uint8_t i = 8; i > 0; --i) { - digitalWrite(_transmitPin, b & 1); // send 1 //(GPIO_Desc[_transmitPin].P)->DOUT |= GPIO_Desc[_transmitPin].bit; - // send 0 //(GPIO_Desc[_transmitPin].P)->DOUT &= ~GPIO_Desc[_transmitPin].bit; - tunedDelay(delay); - b >>= 1; - } - - // restore pin to natural state - digitalWrite(_transmitPin, !inv); - - sei(); // turn interrupts back on - tunedDelay(delay); - - return 1; -} - -void SoftwareSerial::flush() { - if (!isListening()) return; - - cli(); - _receive_buffer_head = _receive_buffer_tail = 0; - sei(); -} - -int SoftwareSerial::peek() { - if (!isListening()) - return -1; - - // Empty buffer? - if (_receive_buffer_head == _receive_buffer_tail) - return -1; - - // Read from "head" - return _receive_buffer[_receive_buffer_head]; -} - -#endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h deleted file mode 100644 index 93df76b53a..0000000000 --- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SoftwareSerial.h (formerly NewSoftSerial.h) - * - * Multi-instance software serial library for Arduino/Wiring - * -- Interrupt-driven receive and other improvements by ladyada - * (http://ladyada.net) - * -- Tuning, circular buffer, derivation from class Print/Stream, - * multi-instance support, porting to 8MHz processors, - * various optimizations, PROGMEM delay tables, inverse logic and - * direct port writing by Mikal Hart (http://www.arduiniana.org) - * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) - * -- 20MHz processor support by Garrett Mace (http://www.macetech.com) - * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * The latest version of this library can always be found at - * http://arduiniana.org. - */ - -#ifndef SOFTWARESERIAL_H -#define SOFTWARESERIAL_H - -#include -#include -//#include "serial.h" -#include -#include - -/****************************************************************************** -* Definitions -******************************************************************************/ - -#define _SS_MAX_RX_BUFF 64 // RX buffer size - -class SoftwareSerial : public Stream -{ -private: - // per object data - pin_t _receivePin; - pin_t _transmitPin; -// uint32_t _receiveBitMask; // for rx interrupts - uint32_t _receivePort; - uint32_t _receivePortPin; - - - // Expressed as 4-cycle delays (must never be 0!) - uint16_t _rx_delay_centering; - uint16_t _rx_delay_intrabit; - uint16_t _rx_delay_stopbit; - uint16_t _tx_delay; - - uint16_t _buffer_overflow:1; - uint16_t _inverse_logic:1; - - // static data - static unsigned char _receive_buffer[_SS_MAX_RX_BUFF]; - static volatile uint8_t _receive_buffer_tail; - static volatile uint8_t _receive_buffer_head; - static SoftwareSerial *active_object; - - // private methods - void recv(); - uint32_t rx_pin_read(); - void tx_pin_write(uint8_t pin_state); - void setTX(pin_t transmitPin); - void setRX(pin_t receivePin); - void setRxIntMsk(bool enable); - - // private static method for timing - static inline void tunedDelay(uint32_t delay); - -public: - // public methods - - SoftwareSerial(pin_t receivePin, pin_t transmitPin, bool inverse_logic = false); - ~SoftwareSerial(); - void begin(long speed); - bool listen(); - void end(); - bool isListening() { return this == active_object; } - bool stopListening(); - bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; } - int peek(); - - virtual size_t write(uint8_t byte); - virtual int read(); - virtual int available(); - virtual void flush(); - operator bool() { return true; } - - using Print::write; - //using HalSerial::write; - - // public only for easy access by interrupt handlers - static inline void handle_interrupt() __attribute__((__always_inline__)); -}; - -// Arduino 0012 workaround -#undef int -#undef char -#undef long -#undef byte -#undef float -#undef abs -#undef round - -#endif // SOFTWARESERIAL_H diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp deleted file mode 100644 index c03dceeec6..0000000000 --- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#ifdef TARGET_LPC1768 - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) - -#include "../persistent_store_api.h" - -#include "chanfs/diskio.h" -#include "chanfs/ff.h" - -extern uint32_t MSC_Aquire_Lock(); -extern uint32_t MSC_Release_Lock(); - -namespace HAL { -namespace PersistentStore { - -FATFS fat_fs; -FIL eeprom_file; - -bool access_start() { - const char eeprom_erase_value = 0xFF; - MSC_Aquire_Lock(); - if (f_mount(&fat_fs, "", 1)) { - MSC_Release_Lock(); - return false; - } - FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ); - if (res) MSC_Release_Lock(); - - if (res == FR_OK) { - UINT bytes_written; - FSIZE_t file_size = f_size(&eeprom_file); - f_lseek(&eeprom_file, file_size); - while (file_size <= E2END && res == FR_OK) { - res = f_write(&eeprom_file, &eeprom_erase_value, 1, &bytes_written); - file_size++; - } - } - if (res == FR_OK) { - f_lseek(&eeprom_file, 0); - f_sync(&eeprom_file); - } - return res == FR_OK; -} - -bool access_finish() { - f_close(&eeprom_file); - f_unmount(""); - MSC_Release_Lock(); - return true; -} - -// File function return codes for type FRESULT This goes away soon. But it is helpful right now to see -// the different errors the read_data() and write_data() functions are seeing. -// -// typedef enum { -// FR_OK = 0, /* (0) Succeeded */ -// FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */ -// FR_INT_ERR, /* (2) Assertion failed */ -// FR_NOT_READY, /* (3) The physical drive cannot work */ -// FR_NO_FILE, /* (4) Could not find the file */ -// FR_NO_PATH, /* (5) Could not find the path */ -// FR_INVALID_NAME, /* (6) The path name format is invalid */ -// FR_DENIED, /* (7) Access denied due to prohibited access or directory full */ -// FR_EXIST, /* (8) Access denied due to prohibited access */ -// FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ -// FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ -// FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ -// FR_NOT_ENABLED, /* (12) The volume has no work area */ -// FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ -// FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */ -// FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ -// FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ -// FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ -// FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */ -// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ -// } FRESULT; - -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { - FRESULT s; - UINT bytes_written = 0; - - s = f_lseek(&eeprom_file, pos); - if (s) { - SERIAL_PROTOCOLPAIR(" write_data(", pos); // This extra chit-chat goes away soon. But it is helpful - SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the - SERIAL_PROTOCOLPAIR(",", (int)size); // read_data() and write_data() functions - SERIAL_PROTOCOLLNPGM("...)"); - SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s); - return s; - } - - s = f_write(&eeprom_file, (void *)value, size, &bytes_written); - if (s) { - SERIAL_PROTOCOLPAIR(" write_data(", pos); // This extra chit-chat goes away soon. But it is helpful - SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the - SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions - SERIAL_PROTOCOLLNPGM("...)"); - SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s); - SERIAL_PROTOCOLPAIR(" size=", size); - SERIAL_PROTOCOLLNPAIR("\n bytes_written=", bytes_written); - return s; - } - crc16(crc, value, size); - pos = pos + size; - return (bytes_written != size); // return true for any error -} - -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) { - UINT bytes_read = 0; - FRESULT s; - s = f_lseek(&eeprom_file, pos); - if (s) { - SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful - SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the - SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions - SERIAL_PROTOCOLLNPGM("...)"); - SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s); - return true; - } - if (writing) { - s = f_read(&eeprom_file, (void *)value, size, &bytes_read); - crc16(crc, value, size); - } - else { - uint8_t temp[size]; - s = f_read(&eeprom_file, (void *)temp, size, &bytes_read); - crc16(crc, temp, size); - } - if (s) { - SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful - SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the - SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions - SERIAL_PROTOCOLLNPGM("...)"); - SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s); - SERIAL_PROTOCOLPAIR(" size=", size); - SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read); - return true; - } - pos = pos + size; - return bytes_read != size; // return true for any error -} - -} // PersistentStore -} // HAL - -#endif // EEPROM_SETTINGS -#endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_SPI.h b/Marlin/src/HAL/HAL_SPI.h deleted file mode 100644 index c011436b77..0000000000 --- a/Marlin/src/HAL/HAL_SPI.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * HAL/HAL_SPI.h - * Core Marlin definitions for SPI, implemented in the HALs - */ - -#ifndef _HAL_SPI_H_ -#define _HAL_SPI_H_ - -#include - -/** - * SPI speed where 0 <= index <= 6 - * - * Approximate rates : - * - * 0 : 8 - 10 MHz - * 1 : 4 - 5 MHz - * 2 : 2 - 2.5 MHz - * 3 : 1 - 1.25 MHz - * 4 : 500 - 625 kHz - * 5 : 250 - 312 kHz - * 6 : 125 - 156 kHz - * - * On AVR, actual speed is F_CPU/2^(1 + index). - * On other platforms, speed should be in range given above where possible. - */ - -#define SPI_FULL_SPEED 0 // Set SCK to max rate -#define SPI_HALF_SPEED 1 // Set SCK rate to half of max rate -#define SPI_QUARTER_SPEED 2 // Set SCK rate to quarter of max rate -#define SPI_EIGHTH_SPEED 3 // Set SCK rate to 1/8 of max rate -#define SPI_SIXTEENTH_SPEED 4 // Set SCK rate to 1/16 of max rate -#define SPI_SPEED_5 5 // Set SCK rate to 1/32 of max rate -#define SPI_SPEED_6 6 // Set SCK rate to 1/64 of max rate - -#define SPI_LSBFIRST 0 -#define SPI_MSBFIRST 1 - -#define SPI_DATAMODE_0 0x00 -#define SPI_DATAMODE_1 0x04 -#define SPI_DATAMODE_2 0x08 -#define SPI_DATAMODE_3 0x0C - -// Standard SPI functions -/** Initialise SPI bus */ -void spiBegin(void); -/** Configure SPI for specified SPI speed */ -void spiInit(uint8_t spiRate); -/** Write single byte to SPI */ -void spiSend(uint8_t b); -/** Read single byte from SPI */ -uint8_t spiRec(void); -/** Read from SPI into buffer */ -void spiRead(uint8_t* buf, uint16_t nbyte); -/** Write token and then write from 512 byte buffer to SPI (for SD card) */ -void spiSendBlock(uint8_t token, const uint8_t* buf); -/** Begin SPI transaction, set clock, bit order, data mode */ -void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode); - -#endif // _HAL_SPI_H_ diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp deleted file mode 100644 index a64eab076f..0000000000 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com - * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * HAL for stm32duino.com based on Libmaple and compatible (STM32F1) - */ - -#ifdef __STM32F1__ - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) - -#include "../persistent_store_api.h" - -//#include "../../core/types.h" -//#include "../../core/language.h" -//#include "../../core/serial.h" -//#include "../../core/utility.h" - -#include "../../sd/cardreader.h" - - -namespace HAL { -namespace PersistentStore { - -#define HAL_STM32F1_EEPROM_SIZE 4096 -char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE]; - -char eeprom_filename[] = "eeprom.dat"; - -bool access_start() { - if (!card.cardOK) return false; - int16_t bytes_read = 0; - constexpr char eeprom_zero = 0xFF; - card.openFile(eeprom_filename, true); - bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); - if (bytes_read < 0) return false; - for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) - HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero; - card.closefile(); - return true; -} - -bool access_finish() { - if (!card.cardOK) return false; - card.openFile(eeprom_filename, true); - int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); - card.closefile(); - return (bytes_written == HAL_STM32F1_EEPROM_SIZE); -} - -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { - for (int i = 0; i < size; i++) - HAL_STM32F1_eeprom_content[pos + i] = value[i]; - crc16(crc, value, size); - pos += size; - return false; -} - -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) { - for (int i = 0; i < size; i++) { - uint8_t c = HAL_STM32F1_eeprom_content[pos + i]; - if (writing) value[i] = c; - crc16(crc, &c, 1); - } - pos += size; - return false; -} - -} // PersistentStore:: -} // HAL:: - -#endif // EEPROM_SETTINGS - -#endif // __STM32F1__ - diff --git a/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp deleted file mode 100644 index a896bded30..0000000000 --- a/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com - * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#if defined(STM32F4) || defined(STM32F4xx) - -#include "../persistent_store_api.h" - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) - -namespace HAL { -namespace PersistentStore { - -bool access_start() { return true; } -bool access_finish() { return true; } - -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { - while (size--) { - uint8_t * const p = (uint8_t * const)pos; - uint8_t v = *value; - // EEPROM has only ~100,000 write cycles, - // so only write bytes that have changed! - if (v != eeprom_read_byte(p)) { - eeprom_write_byte(p, v); - if (eeprom_read_byte(p) != v) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE); - return true; - } - } - crc16(crc, &v, 1); - pos++; - value++; - }; - return false; -} - -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing) { - do { - uint8_t c = eeprom_read_byte((unsigned char*)pos); - if (writing) *value = c; - crc16(crc, &c, 1); - pos++; - value++; - } while (--size); - return false; -} - -} // PersistentStore -} // HAL - -#endif // EEPROM_SETTINGS -#endif // STM32F4 || STM32F4xx diff --git a/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp deleted file mode 100644 index 0cd37b9533..0000000000 --- a/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com - * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com - * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - - -#ifdef STM32F7 - -#include "../persistent_store_api.h" - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) - -namespace HAL { -namespace PersistentStore { - -bool access_start() { return true; } -bool access_finish() { return true; } - -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { - while (size--) { - uint8_t * const p = (uint8_t * const)pos; - uint8_t v = *value; - // EEPROM has only ~100,000 write cycles, - // so only write bytes that have changed! - if (v != eeprom_read_byte(p)) { - eeprom_write_byte(p, v); - if (eeprom_read_byte(p) != v) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE); - return true; - } - } - crc16(crc, &v, 1); - pos++; - value++; - }; - return false; -} - -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { - do { - uint8_t c = eeprom_read_byte((unsigned char*)pos); - *value = c; - crc16(crc, &c, 1); - pos++; - value++; - } while (--size); - return false; -} - -} -} - -#endif // EEPROM_SETTINGS -#endif // STM32F7 - - diff --git a/Marlin/src/HAL/I2cEeprom.cpp b/Marlin/src/HAL/I2cEeprom.cpp deleted file mode 100644 index 874b99c80a..0000000000 --- a/Marlin/src/HAL/I2cEeprom.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * Description: functions for I2C connected external EEPROM. - * Not platform dependent. - */ - -#include "../inc/MarlinConfig.h" - -#if ENABLED(I2C_EEPROM) - -// -------------------------------------------------------------------------- -// Includes -// -------------------------------------------------------------------------- - -#include HAL_PATH(., HAL.h) -#include - -// -------------------------------------------------------------------------- -// Externals -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Local defines -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Types -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Variables -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Public Variables -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Private Variables -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Function prototypes -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Private functions -// -------------------------------------------------------------------------- - -// -------------------------------------------------------------------------- -// Public functions -// -------------------------------------------------------------------------- - -static uint8_t eeprom_device_address = 0x50; - -static void eeprom_init(void) { - static bool eeprom_initialised = false; - if (!eeprom_initialised) { - Wire.begin(); - eeprom_initialised = true; - } -} - -void eeprom_write_byte(unsigned char *pos, unsigned char value) { - unsigned eeprom_address = (unsigned) pos; - - eeprom_init(); - - Wire.beginTransmission(eeprom_device_address); - Wire.write((int)(eeprom_address >> 8)); // MSB - Wire.write((int)(eeprom_address & 0xFF)); // LSB - Wire.write(value); - Wire.endTransmission(); - - // wait for write cycle to complete - // this could be done more efficiently with "acknowledge polling" - delay(5); -} - -// WARNING: address is a page address, 6-bit end will wrap around -// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes -void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) { - eeprom_init(); - - Wire.beginTransmission(eeprom_device_address); - Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB - Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB - Wire.endTransmission(); - - uint8_t *ptr = (uint8_t*)pos; - uint8_t flag = 0; - Wire.requestFrom(eeprom_device_address, (byte)n); - for (byte c = 0; c < n && Wire.available(); c++) - flag |= Wire.read() ^ ptr[c]; - - if (flag) { - Wire.beginTransmission(eeprom_device_address); - Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB - Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB - Wire.write((uint8_t*)pos, n); - Wire.endTransmission(); - - // wait for write cycle to complete - // this could be done more efficiently with "acknowledge polling" - delay(5); - } -} - - -unsigned char eeprom_read_byte(unsigned char *pos) { - byte data = 0xFF; - unsigned eeprom_address = (unsigned)pos; - - eeprom_init(); - - Wire.beginTransmission(eeprom_device_address); - Wire.write((int)(eeprom_address >> 8)); // MSB - Wire.write((int)(eeprom_address & 0xFF)); // LSB - Wire.endTransmission(); - Wire.requestFrom(eeprom_device_address, (byte)1); - return Wire.available() ? Wire.read() : 0xFF; -} - -// maybe let's not read more than 30 or 32 bytes at a time! -void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) { - eeprom_init(); - - Wire.beginTransmission(eeprom_device_address); - Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB - Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB - Wire.endTransmission(); - Wire.requestFrom(eeprom_device_address, (byte)n); - for (byte c = 0; c < n; c++ ) - if (Wire.available()) *((uint8_t*)pos + c) = Wire.read(); -} - - -#endif // ENABLED(I2C_EEPROM) - diff --git a/Marlin/src/HAL/SpiEeprom.cpp b/Marlin/src/HAL/SpiEeprom.cpp deleted file mode 100644 index 6d36d1ca7e..0000000000 --- a/Marlin/src/HAL/SpiEeprom.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * Description: functions for SPI connected external EEPROM. - * Not platform dependent. - */ - -#include "../inc/MarlinConfig.h" - -#if ENABLED(SPI_EEPROM) - -#include HAL_PATH(., HAL.h) - -#define CMD_WREN 6 // WREN -#define CMD_READ 2 // WRITE -#define CMD_WRITE 2 // WRITE - -uint8_t eeprom_read_byte(uint8_t* pos) { - uint8_t v; - uint8_t eeprom_temp[3]; - - // set read location - // begin transmission from device - eeprom_temp[0] = CMD_READ; - eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF; // addr High - eeprom_temp[2] = (unsigned)pos& 0xFF; // addr Low - WRITE(SPI_EEPROM1_CS, HIGH); - WRITE(SPI_EEPROM1_CS, LOW); - spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3); - - v = spiRec(SPI_CHAN_EEPROM1); - WRITE(SPI_EEPROM1_CS, HIGH); - return v; -} - -void eeprom_read_block(void* dest, const void* eeprom_address, size_t n) { - uint8_t eeprom_temp[3]; - - // set read location - // begin transmission from device - eeprom_temp[0] = CMD_READ; - eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; // addr High - eeprom_temp[2] = (unsigned)eeprom_address& 0xFF; // addr Low - WRITE(SPI_EEPROM1_CS, HIGH); - WRITE(SPI_EEPROM1_CS, LOW); - spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3); - - uint8_t *p_dest = (uint8_t *)dest; - while (n--) - *p_dest++ = spiRec(SPI_CHAN_EEPROM1); - WRITE(SPI_EEPROM1_CS, HIGH); -} - -void eeprom_write_byte(uint8_t* pos, uint8_t value) { - uint8_t eeprom_temp[3]; - - /*write enable*/ - eeprom_temp[0] = CMD_WREN; - WRITE(SPI_EEPROM1_CS, LOW); - spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1); - WRITE(SPI_EEPROM1_CS, HIGH); - delay(1); - - /*write addr*/ - eeprom_temp[0] = CMD_WRITE; - eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF; //addr High - eeprom_temp[2] = (unsigned)pos & 0xFF; //addr Low - WRITE(SPI_EEPROM1_CS, LOW); - spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3); - - spiSend(SPI_CHAN_EEPROM1, value); - WRITE(SPI_EEPROM1_CS, HIGH); - delay(7); // wait for page write to complete -} - -void eeprom_update_block(const void* src, void* eeprom_address, size_t n) { - uint8_t eeprom_temp[3]; - - /*write enable*/ - eeprom_temp[0] = CMD_WREN; - WRITE(SPI_EEPROM1_CS, LOW); - spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1); - WRITE(SPI_EEPROM1_CS, HIGH); - delay(1); - - /*write addr*/ - eeprom_temp[0] = CMD_WRITE; - eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; //addr High - eeprom_temp[2] = (unsigned)eeprom_address & 0xFF; //addr Low - WRITE(SPI_EEPROM1_CS, LOW); - spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3); - - spiSend(SPI_CHAN_EEPROM1, (const uint8_t*)src, n); - WRITE(SPI_EEPROM1_CS, HIGH); - delay(7); // wait for page write to complete -} - - -#endif // ENABLED(SPI_EEPROM) diff --git a/Marlin/src/HAL/backtrace/backtrace.cpp b/Marlin/src/HAL/backtrace/backtrace.cpp deleted file mode 100644 index 4a688b369c..0000000000 --- a/Marlin/src/HAL/backtrace/backtrace.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016, 2017 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 . - * - */ - -#include "backtrace.h" - -#if defined(__arm__) || defined(__thumb__) - -#include "unwinder.h" -#include "unwmemaccess.h" - -#include "../../core/serial.h" -#include - -// Dump a backtrace entry -static bool UnwReportOut(void* ctx, const UnwReport* bte) { - int *p = (int*)ctx; - - (*p)++; - - SERIAL_CHAR('#'); SERIAL_PRINT(*p,DEC); SERIAL_ECHOPGM(" : "); - SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, HEX); - SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC); - SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n'); - return true; -} - -#ifdef UNW_DEBUG - void UnwPrintf(const char* format, ...) { - char dest[256]; - va_list argptr; - va_start(argptr, format); - vsprintf(dest, format, argptr); - va_end(argptr); - TX(&dest[0]); - } -#endif - -/* Table of function pointers for passing to the unwinder */ -static const UnwindCallbacks UnwCallbacks = { - UnwReportOut, - UnwReadW, - UnwReadH, - UnwReadB - #ifdef UNW_DEBUG - , UnwPrintf - #endif -}; - -void backtrace(void) { - - UnwindFrame btf; - uint32_t sp = 0, lr = 0, pc = 0; - - // Capture the values of the registers to perform the traceback - __asm__ __volatile__ ( - " mov %[lrv],lr\n" - " mov %[spv],sp\n" - " mov %[pcv],pc\n" - : [spv]"+r"( sp ), - [lrv]"+r"( lr ), - [pcv]"+r"( pc ) - :: - ); - - // Fill the traceback structure - btf.sp = sp; - btf.fp = btf.sp; - btf.lr = lr; - btf.pc = pc | 1; // Force Thumb, as CORTEX only support it - - // Perform a backtrace - SERIAL_ERROR_START(); - SERIAL_ERRORLNPGM("Backtrace:"); - int ctr = 0; - UnwindStart(&btf, &UnwCallbacks, &ctr); -} - -#else // !__arm__ && !__thumb__ - -void backtrace(void) {} - -#endif diff --git a/Marlin/src/HAL/backtrace/backtrace.h b/Marlin/src/HAL/backtrace/backtrace.h deleted file mode 100644 index c2761b9f5a..0000000000 --- a/Marlin/src/HAL/backtrace/backtrace.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -#ifndef _BACKTRACE_H_ -#define _BACKTRACE_H_ - -// Perform a backtrace to the serial port -void backtrace(void); - -#endif \ No newline at end of file diff --git a/Marlin/src/HAL/backtrace/unwarm.cpp b/Marlin/src/HAL/backtrace/unwarm.cpp deleted file mode 100644 index f6d85b708b..0000000000 --- a/Marlin/src/HAL/backtrace/unwarm.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Utility functions and glue for ARM unwinding sub-modules. - **************************************************************************/ - -#if defined(__arm__) || defined(__thumb__) - -#define MODULE_NAME "UNWARM" - -#include -#include -#include -#include -#include "unwarm.h" -#include "unwarmmem.h" - -#if defined(UNW_DEBUG) - -/** - * Printf wrapper. - * This is used such that alternative outputs for any output can be selected - * by modification of this wrapper function. - */ -void UnwPrintf(const char *format, ...) { - va_list args; - - va_start( args, format ); - vprintf(format, args ); -} -#endif - -/** - * Invalidate all general purpose registers. - */ -void UnwInvalidateRegisterFile(RegData *regFile) { - uint8_t t = 0; - do { - regFile[t].o = REG_VAL_INVALID; - t++; - } while (t < 13); -} - - -/** - * Initialise the data used for unwinding. - */ -void UnwInitState(UnwState * const state, /**< Pointer to structure to fill. */ - const UnwindCallbacks *cb, /**< Callbacks. */ - void *rptData, /**< Data to pass to report function. */ - uint32_t pcValue, /**< PC at which to start unwinding. */ - uint32_t spValue) { /**< SP at which to start unwinding. */ - - UnwInvalidateRegisterFile(state->regData); - - /* Store the pointer to the callbacks */ - state->cb = cb; - state->reportData = rptData; - - /* Setup the SP and PC */ - state->regData[13].v = spValue; - state->regData[13].o = REG_VAL_FROM_CONST; - state->regData[15].v = pcValue; - state->regData[15].o = REG_VAL_FROM_CONST; - - UnwPrintd3("\nInitial: PC=0x%08x SP=0x%08x\n", pcValue, spValue); - - /* Invalidate all memory addresses */ - memset(state->memData.used, 0, sizeof(state->memData.used)); -} - -// Detect if function names are available -static int __attribute__ ((noinline)) has_function_names(void) { - uint32_t flag_word = ((uint32_t*)(((uint32_t)(&has_function_names)) & (-4))) [-1]; - return ((flag_word & 0xFF000000) == 0xFF000000) ? 1 : 0; -} - -/** - * Call the report function to indicate some return address. - * This returns the value of the report function, which if true - * indicates that unwinding may continue. - */ -bool UnwReportRetAddr(UnwState * const state, uint32_t addr) { - - UnwReport entry; - - // We found two acceptable values. - entry.name = NULL; - entry.address = addr & 0xFFFFFFFE; // Remove Thumb bit - entry.function = 0; - - // If there are function names, try to solve name - if (has_function_names()) { - - // Lets find the function name, if possible - - // Align address to 4 bytes - uint32_t pf = addr & (-4); - - // Scan backwards until we find the function name - uint32_t v; - while (state->cb->readW(pf-4,&v)) { - - // Check if name descriptor is valid - if ((v & 0xFFFFFF00) == 0xFF000000 && (v & 0xFF) > 1) { - // Assume the name was found! - entry.name = ((const char*)pf) - 4 - (v & 0xFF); - entry.function = pf; - break; - } - - // Go backwards to the previous word - pf -= 4; - } - } - - /* Cast away const from reportData. - * The const is only to prevent the unw module modifying the data. - */ - return state->cb->report((void *)state->reportData, &entry); -} - - -/** - * Write some register to memory. - * This will store some register and meta data onto the virtual stack. - * The address for the write - * \param state [in/out] The unwinding state. - * \param wAddr [in] The address at which to write the data. - * \param reg [in] The register to store. - * \return true if the write was successful, false otherwise. - */ -bool UnwMemWriteRegister(UnwState * const state, const uint32_t addr, const RegData * const reg) { - return UnwMemHashWrite(&state->memData, addr, reg->v, M_IsOriginValid(reg->o)); -} - -/** - * Read a register from memory. - * This will read a register from memory, and setup the meta data. - * If the register has been previously written to memory using - * UnwMemWriteRegister, the local hash will be used to return the - * value while respecting whether the data was valid or not. If the - * register was previously written and was invalid at that point, - * REG_VAL_INVALID will be returned in *reg. - * \param state [in] The unwinding state. - * \param addr [in] The address to read. - * \param reg [out] The result, containing the data value and the origin - * which will be REG_VAL_FROM_MEMORY, or REG_VAL_INVALID. - * \return true if the address could be read and *reg has been filled in. - * false is the data could not be read. - */ -bool UnwMemReadRegister(UnwState * const state, const uint32_t addr, RegData * const reg) { - bool tracked; - - // Check if the value can be found in the hash - if (UnwMemHashRead(&state->memData, addr, ®->v, &tracked)) { - reg->o = tracked ? REG_VAL_FROM_MEMORY : REG_VAL_INVALID; - return true; - } - else if (state->cb->readW(addr, ®->v)) { // Not in the hash, so read from real memory - reg->o = REG_VAL_FROM_MEMORY; - return true; - } - else return false; // Not in the hash, and failed to read from memory -} - -#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/backtrace/unwarm.h b/Marlin/src/HAL/backtrace/unwarm.h deleted file mode 100644 index 8ecdeba8a5..0000000000 --- a/Marlin/src/HAL/backtrace/unwarm.h +++ /dev/null @@ -1,143 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Internal interface between the ARM unwinding sub-modules. - **************************************************************************/ - -#ifndef UNWARM_H -#define UNWARM_H - -#include "unwinder.h" - -/** The maximum number of instructions to interpet in a function. - * Unwinding will be unconditionally stopped and UNWIND_EXHAUSTED returned - * if more than this number of instructions are interpreted in a single - * function without unwinding a stack frame. This prevents infinite loops - * or corrupted program memory from preventing unwinding from progressing. - */ -#define UNW_MAX_INSTR_COUNT 500 - -/** The size of the hash used to track reads and writes to memory. - * This should be a prime value for efficiency. - */ -#define MEM_HASH_SIZE 31 - -/*************************************************************************** - * Type Definitions - **************************************************************************/ - -typedef enum { - /** Invalid value. */ - REG_VAL_INVALID = 0x00, - REG_VAL_FROM_STACK = 0x01, - REG_VAL_FROM_MEMORY = 0x02, - REG_VAL_FROM_CONST = 0x04, - REG_VAL_ARITHMETIC = 0x80 -} RegValOrigin; - - -/** Type for tracking information about a register. - * This stores the register value, as well as other data that helps unwinding. - */ -typedef struct { - - /** The value held in the register. */ - uint32_t v; - - /** The origin of the register value. - * This is used to track how the value in the register was loaded. - */ - int o; /* (RegValOrigin) */ -} RegData; - - -/** Structure used to track reads and writes to memory. - * This structure is used as a hash to store a small number of writes - * to memory. - */ -typedef struct { - /** Memory contents. */ - uint32_t v[MEM_HASH_SIZE]; - - /** Address at which v[n] represents. */ - uint32_t a[MEM_HASH_SIZE]; - - /** Indicates whether the data in v[n] and a[n] is occupied. - * Each bit represents one hash value. - */ - uint8_t used[(MEM_HASH_SIZE + 7) / 8]; - - /** Indicates whether the data in v[n] is valid. - * This allows a[n] to be set, but for v[n] to be marked as invalid. - * Specifically this is needed for when an untracked register value - * is written to memory. - */ - uint8_t tracked[(MEM_HASH_SIZE + 7) / 8]; -} MemData; - - -/** Structure that is used to keep track of unwinding meta-data. - * This data is passed between all the unwinding functions. - */ -typedef struct { - /** The register values and meta-data. */ - RegData regData[16]; - - /** Memory tracking data. */ - MemData memData; - - /** Pointer to the callback functions */ - const UnwindCallbacks *cb; - - /** Pointer to pass to the report function. */ - const void *reportData; -} UnwState; - -/*************************************************************************** - * Macros - **************************************************************************/ - -#define M_IsOriginValid(v) (((v) & 0x7F) ? true : false) -#define M_Origin2Str(v) ((v) ? "VALID" : "INVALID") - -#if defined(UNW_DEBUG) -#define UnwPrintd1(a) state->cb->printf(a) -#define UnwPrintd2(a,b) state->cb->printf(a,b) -#define UnwPrintd3(a,b,c) state->cb->printf(a,b,c) -#define UnwPrintd4(a,b,c,d) state->cb->printf(a,b,c,d) -#define UnwPrintd5(a,b,c,d,e) state->cb->printf(a,b,c,d,e) -#define UnwPrintd6(a,b,c,d,e,f) state->cb->printf(a,b,c,d,e,f) -#define UnwPrintd7(a,b,c,d,e,f,g) state->cb->printf(a,b,c,d,e,f,g) -#define UnwPrintd8(a,b,c,d,e,f,g,h) state->cb->printf(a,b,c,d,e,f,g,h) -#else -#define UnwPrintd1(a) -#define UnwPrintd2(a,b) -#define UnwPrintd3(a,b,c) -#define UnwPrintd4(a,b,c,d) -#define UnwPrintd5(a,b,c,d,e) -#define UnwPrintd6(a,b,c,d,e,f) -#define UnwPrintd7(a,b,c,d,e,f,g) -#define UnwPrintd8(a,b,c,d,e,f,g,h) -#endif - -/*************************************************************************** - * Function Prototypes - **************************************************************************/ - -UnwResult UnwStartArm(UnwState * const state); -UnwResult UnwStartThumb(UnwState * const state); -void UnwInvalidateRegisterFile(RegData *regFile); -void UnwInitState(UnwState * const state, const UnwindCallbacks *cb, void *rptData, uint32_t pcValue, uint32_t spValue); -bool UnwReportRetAddr(UnwState * const state, uint32_t addr); -bool UnwMemWriteRegister(UnwState * const state, const uint32_t addr, const RegData * const reg); -bool UnwMemReadRegister(UnwState * const state, const uint32_t addr, RegData * const reg); -void UnwMemHashGC(UnwState * const state); - -#endif // UNWARM_H diff --git a/Marlin/src/HAL/backtrace/unwarm_arm.cpp b/Marlin/src/HAL/backtrace/unwarm_arm.cpp deleted file mode 100644 index 09528885f7..0000000000 --- a/Marlin/src/HAL/backtrace/unwarm_arm.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Abstract interpreter for ARM mode. - **************************************************************************/ - -#if defined(__arm__) || defined(__thumb__) - -#define MODULE_NAME "UNWARM_ARM" - -#include -#include "unwarm.h" - -/** Check if some instruction is a data-processing instruction. - * Decodes the passed instruction, checks if it is a data-processing and - * verifies that the parameters and operation really indicate a data- - * processing instruction. This is needed because some parts of the - * instruction space under this instruction can be extended or represent - * other operations such as MRS, MSR. - * - * \param[in] inst The instruction word. - * \retval true Further decoding of the instruction indicates that this is - * a valid data-processing instruction. - * \retval false This is not a data-processing instruction, - */ -static bool isDataProc(uint32_t instr) { - - uint8_t opcode = (instr & 0x01E00000) >> 21; - bool S = (instr & 0x00100000) ? true : false; - - if ((instr & 0xFC000000) != 0xE0000000) { - return false; - } - else if (!S && opcode >= 8 && opcode <= 11) { - /* TST, TEQ, CMP and CMN all require S to be set */ - return false; - } - else - return true; -} - -UnwResult UnwStartArm(UnwState * const state) { - - bool found = false; - uint16_t t = UNW_MAX_INSTR_COUNT; - - do { - uint32_t instr; - - /* Attempt to read the instruction */ - if (!state->cb->readW(state->regData[15].v, &instr)) { - return UNWIND_IREAD_W_FAIL; - } - - UnwPrintd4("A %x %x %08x:", state->regData[13].v, state->regData[15].v, instr); - - /* Check that the PC is still on Arm alignment */ - if (state->regData[15].v & 0x3) { - UnwPrintd1("\nError: PC misalignment\n"); - return UNWIND_INCONSISTENT; - } - - /* Check that the SP and PC have not been invalidated */ - if (!M_IsOriginValid(state->regData[13].o) || !M_IsOriginValid(state->regData[15].o)) { - UnwPrintd1("\nError: PC or SP invalidated\n"); - return UNWIND_INCONSISTENT; - } - - /* Branch and Exchange (BX) - * This is tested prior to data processing to prevent - * mis-interpretation as an invalid TEQ instruction. - */ - if ((instr & 0xFFFFFFF0) == 0xE12FFF10) { - uint8_t rn = instr & 0xF; - - UnwPrintd4("BX r%d\t ; r%d %s\n", rn, rn, M_Origin2Str(state->regData[rn].o)); - - if (!M_IsOriginValid(state->regData[rn].o)) { - UnwPrintd1("\nUnwind failure: BX to untracked register\n"); - return UNWIND_FAILURE; - } - - /* Set the new PC value */ - state->regData[15].v = state->regData[rn].v; - - /* Check if the return value is from the stack */ - if (state->regData[rn].o == REG_VAL_FROM_STACK) { - - /* Now have the return address */ - UnwPrintd2(" Return PC=%x\n", state->regData[15].v & (~0x1)); - - /* Report the return address */ - if (!UnwReportRetAddr(state, state->regData[rn].v)) - return UNWIND_TRUNCATED; - } - - /* Determine the return mode */ - if (state->regData[rn].v & 0x1) { - - /* Branching to THUMB */ - return UnwStartThumb(state); - } - else { - - /* Branch to ARM */ - - /* Account for the auto-increment which isn't needed */ - state->regData[15].v -= 4; - } - } - /* Branch */ - else if ((instr & 0xFF000000) == 0xEA000000) { - - int32_t offset = (instr & 0x00FFFFFF); - - /* Shift value */ - offset = offset << 2; - - /* Sign extend if needed */ - if (offset & 0x02000000) { - offset |= 0xFC000000; - } - - UnwPrintd2("B %d\n", offset); - - /* Adjust PC */ - state->regData[15].v += offset; - - /* Account for pre-fetch, where normally the PC is 8 bytes - * ahead of the instruction just executed. - */ - state->regData[15].v += 4; - } - - /* MRS */ - else if ((instr & 0xFFBF0FFF) == 0xE10F0000) { -#if defined(UNW_DEBUG) - bool R = (instr & 0x00400000) ? true : false; -#endif - uint8_t rd = (instr & 0x0000F000) >> 12; - - UnwPrintd4("MRS r%d,%s\t; r%d invalidated", rd, R ? "SPSR" : "CPSR", rd); - - /* Status registers untracked */ - state->regData[rd].o = REG_VAL_INVALID; - } - /* MSR */ - else if ((instr & 0xFFB0F000) == 0xE120F000) { -#if defined(UNW_DEBUG) - bool R = (instr & 0x00400000) ? true : false; - - UnwPrintd2("MSR %s_?, ???", R ? "SPSR" : "CPSR"); -#endif - /* Status registers untracked. - * Potentially this could change processor mode and switch - * banked registers r8-r14. Most likely is that r13 (sp) will - * be banked. However, invalidating r13 will stop unwinding - * when potentially this write is being used to disable/enable - * interrupts (a common case). Therefore no invalidation is - * performed. - */ - } - /* Data processing */ - else if (isDataProc(instr)) { - bool I = (instr & 0x02000000) ? true : false; - uint8_t opcode = (instr & 0x01E00000) >> 21; -#if defined(UNW_DEBUG) - bool S = (instr & 0x00100000) ? true : false; -#endif - uint8_t rn = (instr & 0x000F0000) >> 16; - uint8_t rd = (instr & 0x0000F000) >> 12; - uint16_t operand2 = (instr & 0x00000FFF); - uint32_t op2val; - int op2origin; - - switch(opcode) { - case 0: UnwPrintd4("AND%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 1: UnwPrintd4("EOR%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 2: UnwPrintd4("SUB%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 3: UnwPrintd4("RSB%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 4: UnwPrintd4("ADD%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 5: UnwPrintd4("ADC%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 6: UnwPrintd4("SBC%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 7: UnwPrintd4("RSC%s r%d,r%d,", S ? "S" : "", rd, rn); break; - case 8: UnwPrintd3("TST%s r%d,", S ? "S" : "", rn); break; - case 9: UnwPrintd3("TEQ%s r%d,", S ? "S" : "", rn); break; - case 10: UnwPrintd3("CMP%s r%d,", S ? "S" : "", rn); break; - case 11: UnwPrintd3("CMN%s r%d,", S ? "S" : "", rn); break; - case 12: UnwPrintd3("ORR%s r%d,", S ? "S" : "", rn); break; - case 13: UnwPrintd3("MOV%s r%d,", S ? "S" : "", rd); break; - case 14: UnwPrintd4("BIC%s r%d,r%d", S ? "S" : "", rd, rn); break; - case 15: UnwPrintd3("MVN%s r%d,", S ? "S" : "", rd); break; - } - - /* Decode operand 2 */ - if (I) { - uint8_t shiftDist = (operand2 & 0x0F00) >> 8; - uint8_t shiftConst = (operand2 & 0x00FF); - - /* rotate const right by 2 * shiftDist */ - shiftDist *= 2; - op2val = (shiftConst >> shiftDist) | - (shiftConst << (32 - shiftDist)); - op2origin = REG_VAL_FROM_CONST; - - UnwPrintd2("#0x%x", op2val); - } - else { - - /* Register and shift */ - uint8_t rm = (operand2 & 0x000F); - uint8_t regShift = (operand2 & 0x0010) ? true : false; - uint8_t shiftType = (operand2 & 0x0060) >> 5; - uint32_t shiftDist; -#if defined(UNW_DEBUG) - const char * const shiftMnu[4] = { "LSL", "LSR", "ASR", "ROR" }; -#endif - UnwPrintd2("r%d ", rm); - - /* Get the shift distance */ - if (regShift) { - - uint8_t rs = (operand2 & 0x0F00) >> 8; - - if (operand2 & 0x00800) { - - UnwPrintd1("\nError: Bit should be zero\n"); - return UNWIND_ILLEGAL_INSTR; - } - else if (rs == 15) { - - UnwPrintd1("\nError: Cannot use R15 with register shift\n"); - return UNWIND_ILLEGAL_INSTR; - } - - /* Get shift distance */ - shiftDist = state->regData[rs].v; - op2origin = state->regData[rs].o; - - UnwPrintd7("%s r%d\t; r%d %s r%d %s", shiftMnu[shiftType], rs, rm, M_Origin2Str(state->regData[rm].o), rs, M_Origin2Str(state->regData[rs].o)); - } - else { - shiftDist = (operand2 & 0x0F80) >> 7; - op2origin = REG_VAL_FROM_CONST; - - if (shiftDist) { - UnwPrintd3("%s #%d", shiftMnu[shiftType], shiftDist); - } - UnwPrintd3("\t; r%d %s", rm, M_Origin2Str(state->regData[rm].o)); - } - - /* Apply the shift type to the source register */ - switch(shiftType) { - case 0: /* logical left */ - op2val = state->regData[rm].v << shiftDist; - break; - - case 1: /* logical right */ - if (!regShift && shiftDist == 0) { - shiftDist = 32; - } - - op2val = state->regData[rm].v >> shiftDist; - break; - - case 2: /* arithmetic right */ - if (!regShift && shiftDist == 0) { - shiftDist = 32; - } - - if (state->regData[rm].v & 0x80000000) { - - /* Register shifts maybe greater than 32 */ - if (shiftDist >= 32) { - op2val = 0xFFFFFFFF; - } - else { - op2val = state->regData[rm].v >> shiftDist; - op2val |= 0xFFFFFFFF << (32 - shiftDist); - } - } - else { - op2val = state->regData[rm].v >> shiftDist; - } - break; - - case 3: /* rotate right */ - - if (!regShift && shiftDist == 0) { - /* Rotate right with extend. - * This uses the carry bit and so always has an - * untracked result. - */ - op2origin = REG_VAL_INVALID; - op2val = 0; - } - else { - /* Limit shift distance to 0-31 incase of register shift */ - shiftDist &= 0x1F; - - op2val = (state->regData[rm].v >> shiftDist) | - (state->regData[rm].v << (32 - shiftDist)); - } - break; - - default: - UnwPrintd2("\nError: Invalid shift type: %d\n", shiftType); - return UNWIND_FAILURE; - } - - /* Decide the data origin */ - if (M_IsOriginValid(op2origin) && - M_IsOriginValid(state->regData[rm].o)) { - - op2origin = state->regData[rm].o; - op2origin |= REG_VAL_ARITHMETIC; - } - else { - op2origin = REG_VAL_INVALID; - } - } - - /* Propagate register validity */ - switch(opcode) { - case 0: /* AND: Rd := Op1 AND Op2 */ - case 1: /* EOR: Rd := Op1 EOR Op2 */ - case 2: /* SUB: Rd:= Op1 - Op2 */ - case 3: /* RSB: Rd:= Op2 - Op1 */ - case 4: /* ADD: Rd:= Op1 + Op2 */ - case 12: /* ORR: Rd:= Op1 OR Op2 */ - case 14: /* BIC: Rd:= Op1 AND NOT Op2 */ - if (!M_IsOriginValid(state->regData[rn].o) || - !M_IsOriginValid(op2origin)) { - state->regData[rd].o = REG_VAL_INVALID; - } - else { - state->regData[rd].o = state->regData[rn].o; - state->regData[rd].o = (RegValOrigin)(state->regData[rd].o | op2origin); - } - break; - - case 5: /* ADC: Rd:= Op1 + Op2 + C */ - case 6: /* SBC: Rd:= Op1 - Op2 + C */ - case 7: /* RSC: Rd:= Op2 - Op1 + C */ - /* CPSR is not tracked */ - state->regData[rd].o = REG_VAL_INVALID; - break; - - case 8: /* TST: set condition codes on Op1 AND Op2 */ - case 9: /* TEQ: set condition codes on Op1 EOR Op2 */ - case 10: /* CMP: set condition codes on Op1 - Op2 */ - case 11: /* CMN: set condition codes on Op1 + Op2 */ - break; - - case 13: /* MOV: Rd:= Op2 */ - case 15: /* MVN: Rd:= NOT Op2 */ - state->regData[rd].o = (RegValOrigin) op2origin; - break; - } - - /* Account for pre-fetch by temporarily adjusting PC */ - if (rn == 15) { - - /* If the shift amount is specified in the instruction, - * the PC will be 8 bytes ahead. If a register is used - * to specify the shift amount the PC will be 12 bytes - * ahead. - */ - if (!I && (operand2 & 0x0010)) - state->regData[rn].v += 12; - else - state->regData[rn].v += 8; - } - - /* Compute values */ - switch(opcode) { - case 0: /* AND: Rd := Op1 AND Op2 */ - state->regData[rd].v = state->regData[rn].v & op2val; - break; - - case 1: /* EOR: Rd := Op1 EOR Op2 */ - state->regData[rd].v = state->regData[rn].v ^ op2val; - break; - - case 2: /* SUB: Rd:= Op1 - Op2 */ - state->regData[rd].v = state->regData[rn].v - op2val; - break; - case 3: /* RSB: Rd:= Op2 - Op1 */ - state->regData[rd].v = op2val - state->regData[rn].v; - break; - - case 4: /* ADD: Rd:= Op1 + Op2 */ - state->regData[rd].v = state->regData[rn].v + op2val; - break; - - case 5: /* ADC: Rd:= Op1 + Op2 + C */ - case 6: /* SBC: Rd:= Op1 - Op2 + C */ - case 7: /* RSC: Rd:= Op2 - Op1 + C */ - case 8: /* TST: set condition codes on Op1 AND Op2 */ - case 9: /* TEQ: set condition codes on Op1 EOR Op2 */ - case 10: /* CMP: set condition codes on Op1 - Op2 */ - case 11: /* CMN: set condition codes on Op1 + Op2 */ - UnwPrintd1("\t; ????"); - break; - - case 12: /* ORR: Rd:= Op1 OR Op2 */ - state->regData[rd].v = state->regData[rn].v | op2val; - break; - - case 13: /* MOV: Rd:= Op2 */ - state->regData[rd].v = op2val; - break; - - case 14: /* BIC: Rd:= Op1 AND NOT Op2 */ - state->regData[rd].v = state->regData[rn].v & (~op2val); - break; - - case 15: /* MVN: Rd:= NOT Op2 */ - state->regData[rd].v = ~op2val; - break; - } - - /* Remove the prefetch offset from the PC */ - if (rd != 15 && rn == 15) { - if (!I && (operand2 & 0x0010)) - state->regData[rn].v -= 12; - else - state->regData[rn].v -= 8; - } - } - - /* Block Data Transfer - * LDM, STM - */ - else if ((instr & 0xFE000000) == 0xE8000000) { - - bool P = (instr & 0x01000000) ? true : false; - bool U = (instr & 0x00800000) ? true : false; - bool S = (instr & 0x00400000) ? true : false; - bool W = (instr & 0x00200000) ? true : false; - bool L = (instr & 0x00100000) ? true : false; - uint16_t baseReg = (instr & 0x000F0000) >> 16; - uint16_t regList = (instr & 0x0000FFFF); - uint32_t addr = state->regData[baseReg].v; - bool addrValid = M_IsOriginValid(state->regData[baseReg].o); - int8_t r; - -#if defined(UNW_DEBUG) - /* Display the instruction */ - if (L) { - UnwPrintd6("LDM%c%c r%d%s, {reglist}%s\n", P ? 'E' : 'F', U ? 'D' : 'A', baseReg, W ? "!" : "", S ? "^" : ""); - } - else { - UnwPrintd6("STM%c%c r%d%s, {reglist}%s\n", !P ? 'E' : 'F', !U ? 'D' : 'A', baseReg, W ? "!" : "", S ? "^" : ""); - } -#endif - /* S indicates that banked registers (untracked) are used, unless - * this is a load including the PC when the S-bit indicates that - * that CPSR is loaded from SPSR (also untracked, but ignored). - */ - if (S && (!L || (regList & (0x01 << 15)) == 0)) { - UnwPrintd1("\nError:S-bit set requiring banked registers\n"); - return UNWIND_FAILURE; - } - else if (baseReg == 15) { - UnwPrintd1("\nError: r15 used as base register\n"); - return UNWIND_FAILURE; - } - else if (regList == 0) { - UnwPrintd1("\nError: Register list empty\n"); - return UNWIND_FAILURE; - } - - /* Check if ascending or descending. - * Registers are loaded/stored in order of address. - * i.e. r0 is at the lowest address, r15 at the highest. - */ - r = U ? 0 : 15; - do { - - /* Check if the register is to be transferred */ - if (regList & (0x01 << r)) { - - if (P) - addr += U ? 4 : -4; - - if (L) { - - if (addrValid) { - - if (!UnwMemReadRegister(state, addr, &state->regData[r])) { - return UNWIND_DREAD_W_FAIL; - } - - /* Update the origin if read via the stack pointer */ - if (M_IsOriginValid(state->regData[r].o) && baseReg == 13) { - state->regData[r].o = REG_VAL_FROM_STACK; - } - - UnwPrintd5(" R%d = 0x%08x\t; r%d %s\n",r,state->regData[r].v,r, M_Origin2Str(state->regData[r].o)); - } - else { - - /* Invalidate the register as the base reg was invalid */ - state->regData[r].o = REG_VAL_INVALID; - - UnwPrintd2(" R%d = ???\n", r); - } - } - else { - if (addrValid) { - if (!UnwMemWriteRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DWRITE_W_FAIL; - } - } - - UnwPrintd2(" R%d = 0x%08x\n", r); - } - - if (!P) - addr += U ? 4 : -4; - } - - /* Check the next register */ - r += U ? 1 : -1; - - } while (r >= 0 && r <= 15); - - /* Check the writeback bit */ - if (W) - state->regData[baseReg].v = addr; - - /* Check if the PC was loaded */ - if (L && (regList & (0x01 << 15))) { - if (!M_IsOriginValid(state->regData[15].o)) { - /* Return address is not valid */ - UnwPrintd1("PC popped with invalid address\n"); - return UNWIND_FAILURE; - } - else { - /* Store the return address */ - if (!UnwReportRetAddr(state, state->regData[15].v)) { - return UNWIND_TRUNCATED; - } - - UnwPrintd2(" Return PC=0x%x", state->regData[15].v); - - /* Determine the return mode */ - if (state->regData[15].v & 0x1) { - /* Branching to THUMB */ - return UnwStartThumb(state); - } - else { - /* Branch to ARM */ - - /* Account for the auto-increment which isn't needed */ - state->regData[15].v -= 4; - } - } - } - } - else { - UnwPrintd1("????"); - - /* Unknown/undecoded. May alter some register, so invalidate file */ - UnwInvalidateRegisterFile(state->regData); - } - - UnwPrintd1("\n"); - - /* Should never hit the reset vector */ - if (state->regData[15].v == 0) return UNWIND_RESET; - - /* Check next address */ - state->regData[15].v += 4; - - /* Garbage collect the memory hash (used only for the stack) */ - UnwMemHashGC(state); - - t--; - if (t == 0) - return UNWIND_EXHAUSTED; - - } while (!found); - - return UNWIND_UNSUPPORTED; -} - -#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/backtrace/unwarm_thumb.cpp b/Marlin/src/HAL/backtrace/unwarm_thumb.cpp deleted file mode 100644 index a4afbeaf8d..0000000000 --- a/Marlin/src/HAL/backtrace/unwarm_thumb.cpp +++ /dev/null @@ -1,1127 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Abstract interpretation for Thumb mode. - **************************************************************************/ - -#if defined(__arm__) || defined(__thumb__) - -#define MODULE_NAME "UNWARM_THUMB" - -#include -#include "unwarm.h" - -/** Sign extend an 11 bit value. - * This function simply inspects bit 11 of the input \a value, and if - * set, the top 5 bits are set to give a 2's compliment signed value. - * \param value The value to sign extend. - * \return The signed-11 bit value stored in a 16bit data type. - */ -static int32_t signExtend11(uint16_t value) { - - if(value & 0x400) { - value |= 0xFFFFF800; - } - - return value; -} - -UnwResult UnwStartThumb(UnwState * const state) { - - bool found = false; - uint16_t t = UNW_MAX_INSTR_COUNT; - uint32_t lastJumpAddr = 0; // Last JUMP address, to try to detect infinite loops - bool loopDetected = false; // If a loop was detected - - do { - uint16_t instr; - - /* Attempt to read the instruction */ - if(!state->cb->readH(state->regData[15].v & (~0x1), &instr)) { - return UNWIND_IREAD_H_FAIL; - } - - UnwPrintd4("T %x %x %04x:", state->regData[13].v, state->regData[15].v, instr); - - /* Check that the PC is still on Thumb alignment */ - if(!(state->regData[15].v & 0x1)) { - UnwPrintd1("\nError: PC misalignment\n"); - return UNWIND_INCONSISTENT; - } - - /* Check that the SP and PC have not been invalidated */ - if(!M_IsOriginValid(state->regData[13].o) || !M_IsOriginValid(state->regData[15].o)) { - UnwPrintd1("\nError: PC or SP invalidated\n"); - return UNWIND_INCONSISTENT; - } - - /* - * Detect 32bit thumb instructions - */ - if ((instr & 0xE000) == 0xE000 && (instr & 0x1800) != 0) { - uint16_t instr2; - - /* Check next address */ - state->regData[15].v += 2; - - /* Attempt to read the 2nd part of the instruction */ - if(!state->cb->readH(state->regData[15].v & (~0x1), &instr2)) { - return UNWIND_IREAD_H_FAIL; - } - - UnwPrintd3(" %x %04x:", state->regData[15].v, instr2); - - /* - * Load/Store multiple: Only interpret - * PUSH and POP - */ - if ((instr & 0xFE6F) == 0xE82D) { - bool L = (instr & 0x10) ? true : false; - uint16_t rList = instr2; - - if(L) { - uint8_t r; - - /* Load from memory: POP */ - UnwPrintd1("POP {Rlist}\n"); - - /* Load registers from stack */ - for(r = 0; r < 16; r++) { - if(rList & (0x1 << r)) { - - /* Read the word */ - if(!UnwMemReadRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DREAD_W_FAIL; - } - - /* Alter the origin to be from the stack if it was valid */ - if(M_IsOriginValid(state->regData[r].o)) { - - state->regData[r].o = REG_VAL_FROM_STACK; - - /* If restoring the PC */ - if (r == 15) { - - /* The bottom bit should have been set to indicate that - * the caller was from Thumb. This would allow return - * by BX for interworking APCS. - */ - if((state->regData[15].v & 0x1) == 0) { - UnwPrintd2("Warning: Return address not to Thumb: 0x%08x\n", state->regData[15].v); - - /* Pop into the PC will not switch mode */ - return UNWIND_INCONSISTENT; - } - - /* Store the return address */ - if(!UnwReportRetAddr(state, state->regData[15].v)) { - return UNWIND_TRUNCATED; - } - - /* Now have the return address */ - UnwPrintd2(" Return PC=%x\n", state->regData[15].v); - - /* Compensate for the auto-increment, which isn't needed here */ - state->regData[15].v -= 2; - - } - - } else { - - if (r == 15) { - /* Return address is not valid */ - UnwPrintd1("PC popped with invalid address\n"); - return UNWIND_FAILURE; - } - } - - state->regData[13].v += 4; - - UnwPrintd3(" r%d = 0x%08x\n", r, state->regData[r].v); - } - } - } - else { - int8_t r; - - /* Store to memory: PUSH */ - UnwPrintd1("PUSH {Rlist}"); - - for(r = 15; r >= 0; r--) { - if(rList & (0x1 << r)) { - UnwPrintd4("\n r%d = 0x%08x\t; %s", r, state->regData[r].v, M_Origin2Str(state->regData[r].o)); - - state->regData[13].v -= 4; - - if(!UnwMemWriteRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DWRITE_W_FAIL; - } - } - } - } - } - /* - * PUSH register - */ - else if (instr == 0xF84D && (instr2 & 0x0FFF) == 0x0D04) { - uint8_t r = instr2 >> 12; - - /* Store to memory: PUSH */ - UnwPrintd2("PUSH {R%d}\n", r); - UnwPrintd4("\n r%d = 0x%08x\t; %s", r, state->regData[r].v, M_Origin2Str(state->regData[r].o)); - - state->regData[13].v -= 4; - - if(!UnwMemWriteRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DWRITE_W_FAIL; - } - } - /* - * POP register - */ - else if (instr == 0xF85D && (instr2 & 0x0FFF) == 0x0B04) { - uint8_t r = instr2 >> 12; - - /* Load from memory: POP */ - UnwPrintd2("POP {R%d}\n", r); - - /* Read the word */ - if(!UnwMemReadRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DREAD_W_FAIL; - } - - /* Alter the origin to be from the stack if it was valid */ - if(M_IsOriginValid(state->regData[r].o)) { - - state->regData[r].o = REG_VAL_FROM_STACK; - - /* If restoring the PC */ - if (r == 15) { - - /* The bottom bit should have been set to indicate that - * the caller was from Thumb. This would allow return - * by BX for interworking APCS. - */ - if((state->regData[15].v & 0x1) == 0) { - UnwPrintd2("Warning: Return address not to Thumb: 0x%08x\n", state->regData[15].v); - - /* Pop into the PC will not switch mode */ - return UNWIND_INCONSISTENT; - } - - /* Store the return address */ - if(!UnwReportRetAddr(state, state->regData[15].v)) { - return UNWIND_TRUNCATED; - } - - /* Now have the return address */ - UnwPrintd2(" Return PC=%x\n", state->regData[15].v); - - /* Compensate for the auto-increment, which isn't needed here */ - state->regData[15].v -= 2; - - } - - } else { - - if (r == 15) { - /* Return address is not valid */ - UnwPrintd1("PC popped with invalid address\n"); - return UNWIND_FAILURE; - } - } - - state->regData[13].v += 4; - - UnwPrintd3(" r%d = 0x%08x\n", r, state->regData[r].v); - } - /* - * TBB / TBH - */ - else if ((instr & 0xFFF0) == 0xE8D0 && (instr2 & 0xFFE0) == 0xF000) { - /* We are only interested in - * the forms - * TBB [PC, ...] - * TBH [PC, ..., LSL #1] - * as those are used by the C compiler to implement - * the switch clauses - */ - uint8_t rn = instr & 0xF; - bool H = (instr2 & 0x10) ? true : false; - - UnwPrintd5("TB%c [r%d,r%d%s]\n", H ? 'H' : 'B', rn, (instr2 & 0xF), H ? ",LSL #1" : ""); - - // We are only interested if the RN is the PC. Let's choose the 1st destination - if (rn == 15) { - if (H) { - uint16_t rv; - if(!state->cb->readH((state->regData[15].v & (~1)) + 2, &rv)) { - return UNWIND_DREAD_H_FAIL; - } - state->regData[15].v += rv * 2; - } else { - uint8_t rv; - if(!state->cb->readB((state->regData[15].v & (~1)) + 2, &rv)) { - return UNWIND_DREAD_B_FAIL; - } - state->regData[15].v += rv * 2; - } - } - } - /* - * Unconditional branch - */ - else if ((instr & 0xF800) == 0xF000 && (instr2 & 0xD000) == 0x9000) { - uint32_t v; - - uint8_t S = (instr & 0x400) >> 10; - uint16_t imm10 = (instr & 0x3FF); - uint8_t J1 = (instr2 & 0x2000) >> 13; - uint8_t J2 = (instr2 & 0x0800) >> 11; - uint16_t imm11 = (instr2 & 0x7FF); - - uint8_t I1 = J1 ^ S ^ 1; - uint8_t I2 = J2 ^ S ^ 1; - uint32_t imm32 = (S << 24) | (I1 << 23) | (I2 << 22) |(imm10 << 12) | (imm11 << 1); - if (S) imm32 |= 0xFE000000; - - UnwPrintd2("B %d \n", imm32); - - /* Update PC */ - state->regData[15].v += imm32; - - /* Need to advance by a word to account for pre-fetch. - * Advance by a half word here, allowing the normal address - * advance to account for the other half word. - */ - state->regData[15].v += 2; - - /* Compute the jump address */ - v = state->regData[15].v + 2; - - /* Display PC of next instruction */ - UnwPrintd2(" New PC=%x", v); - - /* Did we detect an infinite loop ? */ - loopDetected = lastJumpAddr == v; - - /* Remember the last address we jumped to */ - lastJumpAddr = v; - } - - /* - * Branch with link - */ - else if ((instr & 0xF800) == 0xF000 && (instr2 & 0xD000) == 0xD000) { - - uint8_t S = (instr & 0x400) >> 10; - uint16_t imm10 = (instr & 0x3FF); - uint8_t J1 = (instr2 & 0x2000) >> 13; - uint8_t J2 = (instr2 & 0x0800) >> 11; - uint16_t imm11 = (instr2 & 0x7FF); - - uint8_t I1 = J1 ^ S ^ 1; - uint8_t I2 = J2 ^ S ^ 1; - uint32_t imm32 = (S << 24) | (I1 << 23) | (I2 << 22) |(imm10 << 12) | (imm11 << 1); - if (S) imm32 |= 0xFE000000; - - UnwPrintd2("BL %d \n", imm32); - - /* Never taken, as we are unwinding the stack */ - if (0) { - - /* Store return address in LR register */ - state->regData[14].v = state->regData[15].v + 2; - state->regData[14].o = REG_VAL_FROM_CONST; - - /* Update PC */ - state->regData[15].v += imm32; - - /* Need to advance by a word to account for pre-fetch. - * Advance by a half word here, allowing the normal address - * advance to account for the other half word. - */ - state->regData[15].v += 2; - - /* Display PC of next instruction */ - UnwPrintd2(" Return PC=%x", state->regData[15].v); - - /* Report the return address, including mode bit */ - if(!UnwReportRetAddr(state, state->regData[15].v)) { - return UNWIND_TRUNCATED; - } - - /* Determine the new mode */ - if(state->regData[15].v & 0x1) { - /* Branching to THUMB */ - - /* Account for the auto-increment which isn't needed */ - state->regData[15].v -= 2; - } - else { - /* Branch to ARM */ - return UnwStartArm(state); - } - } - } - - /* - * Conditional branches. Usually not taken, unless infinite loop is detected - */ - else if ((instr & 0xF800) == 0xF000 && (instr2 & 0xD000) == 0x8000) { - - uint8_t S = (instr & 0x400) >> 10; - uint16_t imm6 = (instr & 0x3F); - uint8_t J1 = (instr2 & 0x2000) >> 13; - uint8_t J2 = (instr2 & 0x0800) >> 11; - uint16_t imm11 = (instr2 & 0x7FF); - - uint8_t I1 = J1 ^ S ^ 1; - uint8_t I2 = J2 ^ S ^ 1; - uint32_t imm32 = (S << 20) | (I1 << 19) | (I2 << 18) |(imm6 << 12) | (imm11 << 1); - if (S) imm32 |= 0xFFE00000; - - UnwPrintd2("Bcond %d\n", imm32); - - /* Take the jump only if a loop is detected */ - if (loopDetected) { - - /* Update PC */ - state->regData[15].v += imm32; - - /* Need to advance by a word to account for pre-fetch. - * Advance by a half word here, allowing the normal address - * advance to account for the other half word. - */ - state->regData[15].v += 2; - - /* Display PC of next instruction */ - UnwPrintd2(" New PC=%x", state->regData[15].v + 2); - } - } - /* - * PC-relative load - * LDR Rd,[PC, #+/-imm] - */ - else if((instr & 0xFF7F) == 0xF85F) { - uint8_t rt = (instr2 & 0xF000) >> 12; - uint8_t imm12 = (instr2 & 0x0FFF); - bool A = (instr & 0x80) ? true : false; - uint32_t address; - - /* Compute load address, adding a word to account for prefetch */ - address = (state->regData[15].v & (~0x3)) + 4; - if (A) address += imm12; - else address -= imm12; - - UnwPrintd4("LDR r%d,[PC #%c0x%08x]", rt, A?'+':'-', address); - - if(!UnwMemReadRegister(state, address, &state->regData[rt])) { - return UNWIND_DREAD_W_FAIL; - } - } - /* - * LDR immediate. - * We are only interested when destination is PC. - * LDR Rt,[Rn , #n] - */ - else if ((instr & 0xFFF0) == 0xF8D0) { - uint8_t rn = (instr & 0xF); - uint8_t rt = (instr2 & 0xF000) >> 12; - uint16_t imm12 = (instr2 & 0xFFF); - - /* If destination is PC and we don't know the source value, then fail */ - if (!M_IsOriginValid(state->regData[rn].o)) { - state->regData[rt].o = state->regData[rn].o; - } else { - uint32_t address = state->regData[rn].v + imm12; - if(!UnwMemReadRegister(state, address, &state->regData[rt])) { - return UNWIND_DREAD_W_FAIL; - } - } - } - /* - * LDR immediate - * We are only interested when destination is PC. - * LDR Rt,[Rn , #-n] - * LDR Rt,[Rn], #+/-n] - * LDR Rt,[Rn, #+/-n]! - */ - else if ((instr & 0xFFF0) == 0xF850 && (instr2 & 0x0800) == 0x0800) { - uint8_t rn = (instr & 0xF); - uint8_t rt = (instr2 & 0xF000) >> 12; - uint16_t imm8 = (instr2 & 0xFF); - bool P = (instr2 & 0x400) ? true : false; - bool U = (instr2 & 0x200) ? true : false; - bool W = (instr2 & 0x100) ? true : false; - - if (!M_IsOriginValid(state->regData[rn].o)) { - state->regData[rt].o = state->regData[rn].o; - } else { - uint32_t offaddress = state->regData[rn].v + imm8; - if (U) offaddress += imm8; - else offaddress -= imm8; - - uint32_t address; - if (P) { - address = offaddress; - } else { - address = state->regData[rn].v; - } - - if(!UnwMemReadRegister(state, address, &state->regData[rt])) { - return UNWIND_DREAD_W_FAIL; - } - - if (W) { - state->regData[rn].v = offaddress; - } - } - } - /* - * LDR (register). - * We are interested in the form - * ldr Rt, [Rn, Rm, lsl #x] - * Where Rt is PC, Rn value is known, Rm is not known or unknown - */ - else if ((instr & 0xFFF0) == 0xF850 && (instr2 & 0x0FC0) == 0x0000) { - uint8_t rn = (instr & 0xF); - uint8_t rt = (instr2 & 0xF000) >> 12; - uint8_t rm = (instr2 & 0xF); - uint8_t imm2 = (instr2 & 0x30) >> 4; - - if (!M_IsOriginValid(state->regData[rn].o) || - !M_IsOriginValid(state->regData[rm].o)) { - - /* If Rt is PC, and Rn is known, then do an exception and assume - Rm equals 0 => This takes the first case in a switch() */ - if (rt == 15 && M_IsOriginValid(state->regData[rn].o)) { - uint32_t address = state->regData[rn].v; - if(!UnwMemReadRegister(state, address, &state->regData[rt])) { - return UNWIND_DREAD_W_FAIL; - } - } else { - /* Propagate unknown value */ - state->regData[rt].o = state->regData[rn].o; - } - } else { - uint32_t address = state->regData[rn].v + (state->regData[rm].v << imm2); - if(!UnwMemReadRegister(state, address, &state->regData[rt])) { - return UNWIND_DREAD_W_FAIL; - } - } - } - else { - UnwPrintd1("???? (32)"); - - /* Unknown/undecoded. May alter some register, so invalidate file */ - UnwInvalidateRegisterFile(state->regData); - } - /* End of thumb 32bit code */ - - } - /* Format 1: Move shifted register - * LSL Rd, Rs, #Offset5 - * LSR Rd, Rs, #Offset5 - * ASR Rd, Rs, #Offset5 - */ - else if((instr & 0xE000) == 0x0000 && (instr & 0x1800) != 0x1800) { - bool signExtend; - uint8_t op = (instr & 0x1800) >> 11; - uint8_t offset5 = (instr & 0x07C0) >> 6; - uint8_t rs = (instr & 0x0038) >> 3; - uint8_t rd = (instr & 0x0007); - - switch(op) { - case 0: /* LSL */ - UnwPrintd6("LSL r%d, r%d, #%d\t; r%d %s", rd, rs, offset5, rs, M_Origin2Str(state->regData[rs].o)); - state->regData[rd].v = state->regData[rs].v << offset5; - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - break; - - case 1: /* LSR */ - UnwPrintd6("LSR r%d, r%d, #%d\t; r%d %s", rd, rs, offset5, rs, M_Origin2Str(state->regData[rs].o)); - state->regData[rd].v = state->regData[rs].v >> offset5; - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - break; - - case 2: /* ASR */ - UnwPrintd6("ASL r%d, r%d, #%d\t; r%d %s", rd, rs, offset5, rs, M_Origin2Str(state->regData[rs].o)); - - signExtend = (state->regData[rs].v & 0x8000) ? true : false; - state->regData[rd].v = state->regData[rs].v >> offset5; - if(signExtend) { - state->regData[rd].v |= 0xFFFFFFFF << (32 - offset5); - } - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - break; - } - } - /* Format 2: add/subtract - * ADD Rd, Rs, Rn - * ADD Rd, Rs, #Offset3 - * SUB Rd, Rs, Rn - * SUB Rd, Rs, #Offset3 - */ - else if((instr & 0xF800) == 0x1800) { - bool I = (instr & 0x0400) ? true : false; - bool op = (instr & 0x0200) ? true : false; - uint8_t rn = (instr & 0x01C0) >> 6; - uint8_t rs = (instr & 0x0038) >> 3; - uint8_t rd = (instr & 0x0007); - - /* Print decoding */ - UnwPrintd6("%s r%d, r%d, %c%d\t;",op ? "SUB" : "ADD",rd, rs,I ? '#' : 'r',rn); - UnwPrintd5("r%d %s, r%d %s",rd, M_Origin2Str(state->regData[rd].o),rs, M_Origin2Str(state->regData[rs].o)); - if(!I) { - - UnwPrintd3(", r%d %s", rn, M_Origin2Str(state->regData[rn].o)); - - /* Perform calculation */ - if(op) { - state->regData[rd].v = state->regData[rs].v - state->regData[rn].v; - } - else { - state->regData[rd].v = state->regData[rs].v + state->regData[rn].v; - } - - /* Propagate the origin */ - if(M_IsOriginValid(state->regData[rs].o) && - M_IsOriginValid(state->regData[rn].o)) { - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - } - else { - state->regData[rd].o = REG_VAL_INVALID; - } - } - else { - /* Perform calculation */ - if(op) { - state->regData[rd].v = state->regData[rs].v - rn; - } - else { - state->regData[rd].v = state->regData[rs].v + rn; - } - - /* Propagate the origin */ - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - } - } - /* Format 3: move/compare/add/subtract immediate - * MOV Rd, #Offset8 - * CMP Rd, #Offset8 - * ADD Rd, #Offset8 - * SUB Rd, #Offset8 - */ - else if((instr & 0xE000) == 0x2000) { - - uint8_t op = (instr & 0x1800) >> 11; - uint8_t rd = (instr & 0x0700) >> 8; - uint8_t offset8 = (instr & 0x00FF); - - switch(op) { - case 0: /* MOV */ - UnwPrintd3("MOV r%d, #0x%x", rd, offset8); - state->regData[rd].v = offset8; - state->regData[rd].o = REG_VAL_FROM_CONST; - break; - - case 1: /* CMP */ - /* Irrelevant to unwinding */ - UnwPrintd1("CMP ???"); - break; - - case 2: /* ADD */ - UnwPrintd5("ADD r%d, #0x%x\t; r%d %s", rd, offset8, rd, M_Origin2Str(state->regData[rd].o)); - state->regData[rd].v += offset8; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - break; - - case 3: /* SUB */ - UnwPrintd5("SUB r%d, #0x%d\t; r%d %s", rd, offset8, rd, M_Origin2Str(state->regData[rd].o)); - state->regData[rd].v -= offset8; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - break; - } - } - /* Format 4: ALU operations - * AND Rd, Rs - * EOR Rd, Rs - * LSL Rd, Rs - * LSR Rd, Rs - * ASR Rd, Rs - * ADC Rd, Rs - * SBC Rd, Rs - * ROR Rd, Rs - * TST Rd, Rs - * NEG Rd, Rs - * CMP Rd, Rs - * CMN Rd, Rs - * ORR Rd, Rs - * MUL Rd, Rs - * BIC Rd, Rs - * MVN Rd, Rs - */ - else if((instr & 0xFC00) == 0x4000) { - uint8_t op = (instr & 0x03C0) >> 6; - uint8_t rs = (instr & 0x0038) >> 3; - uint8_t rd = (instr & 0x0007); - -#if defined(UNW_DEBUG) - static const char * const mnu[16] = { - "AND", "EOR", "LSL", "LSR", - "ASR", "ADC", "SBC", "ROR", - "TST", "NEG", "CMP", "CMN", - "ORR", "MUL", "BIC", "MVN" }; -#endif - /* Print the mnemonic and registers */ - switch(op) { - case 0: /* AND */ - case 1: /* EOR */ - case 2: /* LSL */ - case 3: /* LSR */ - case 4: /* ASR */ - case 7: /* ROR */ - case 9: /* NEG */ - case 12: /* ORR */ - case 13: /* MUL */ - case 15: /* MVN */ - UnwPrintd8("%s r%d ,r%d\t; r%d %s, r%d %s",mnu[op],rd, rs, rd, M_Origin2Str(state->regData[rd].o), rs, M_Origin2Str(state->regData[rs].o)); - break; - - case 5: /* ADC */ - case 6: /* SBC */ - UnwPrintd4("%s r%d, r%d", mnu[op], rd, rs); - break; - - case 8: /* TST */ - case 10: /* CMP */ - case 11: /* CMN */ - /* Irrelevant to unwinding */ - UnwPrintd2("%s ???", mnu[op]); - break; - - case 14: /* BIC */ - UnwPrintd5("r%d ,r%d\t; r%d %s", rd, rs, rs, M_Origin2Str(state->regData[rs].o)); - break; - } - - /* Perform operation */ - switch(op) { - case 0: /* AND */ - state->regData[rd].v &= state->regData[rs].v; - break; - - case 1: /* EOR */ - state->regData[rd].v ^= state->regData[rs].v; - break; - - case 2: /* LSL */ - state->regData[rd].v <<= state->regData[rs].v; - break; - - case 3: /* LSR */ - state->regData[rd].v >>= state->regData[rs].v; - break; - - case 4: /* ASR */ - if(state->regData[rd].v & 0x80000000) { - state->regData[rd].v >>= state->regData[rs].v; - state->regData[rd].v |= 0xFFFFFFFF << (32 - state->regData[rs].v); - } - else { - state->regData[rd].v >>= state->regData[rs].v; - } - - break; - - case 5: /* ADC */ - case 6: /* SBC */ - case 8: /* TST */ - case 10: /* CMP */ - case 11: /* CMN */ - break; - - case 7: /* ROR */ - state->regData[rd].v = (state->regData[rd].v >> state->regData[rs].v) | - (state->regData[rd].v << (32 - state->regData[rs].v)); - break; - - case 9: /* NEG */ - state->regData[rd].v = -state->regData[rs].v; - break; - - case 12: /* ORR */ - state->regData[rd].v |= state->regData[rs].v; - break; - - case 13: /* MUL */ - state->regData[rd].v *= state->regData[rs].v; - break; - - case 14: /* BIC */ - state->regData[rd].v &= ~state->regData[rs].v; - break; - - case 15: /* MVN */ - state->regData[rd].v = ~state->regData[rs].v; - break; - } - - /* Propagate data origins */ - switch(op) { - case 0: /* AND */ - case 1: /* EOR */ - case 2: /* LSL */ - case 3: /* LSR */ - case 4: /* ASR */ - case 7: /* ROR */ - case 12: /* ORR */ - case 13: /* MUL */ - case 14: /* BIC */ - if(M_IsOriginValid(state->regData[rd].o) && M_IsOriginValid(state->regData[rs].o)) { - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - } - else { - state->regData[rd].o = REG_VAL_INVALID; - } - break; - - case 5: /* ADC */ - case 6: /* SBC */ - /* C-bit not tracked */ - state->regData[rd].o = REG_VAL_INVALID; - break; - - case 8: /* TST */ - case 10: /* CMP */ - case 11: /* CMN */ - /* Nothing propagated */ - break; - - case 9: /* NEG */ - case 15: /* MVN */ - state->regData[rd].o = state->regData[rs].o; - state->regData[rd].o |= REG_VAL_ARITHMETIC; - break; - } - } - /* Format 5: Hi register operations/branch exchange - * ADD Rd, Hs - * CMP Hd, Rs - * MOV Hd, Hs - */ - else if((instr & 0xFC00) == 0x4400) { - uint8_t op = (instr & 0x0300) >> 8; - bool h1 = (instr & 0x0080) ? true: false; - bool h2 = (instr & 0x0040) ? true: false; - uint8_t rhs = (instr & 0x0038) >> 3; - uint8_t rhd = (instr & 0x0007); - - /* Adjust the register numbers */ - if(h2) - rhs += 8; - if(h1) - rhd += 8; - - switch(op) { - case 0: /* ADD */ - UnwPrintd5("ADD r%d, r%d\t; r%d %s", rhd, rhs, rhs, M_Origin2Str(state->regData[rhs].o)); - state->regData[rhd].v += state->regData[rhs].v; - state->regData[rhd].o = state->regData[rhs].o; - state->regData[rhd].o |= REG_VAL_ARITHMETIC; - break; - - case 1: /* CMP */ - /* Irrelevant to unwinding */ - UnwPrintd1("CMP ???"); - break; - - case 2: /* MOV */ - UnwPrintd5("MOV r%d, r%d\t; r%d %s", rhd, rhs, rhd, M_Origin2Str(state->regData[rhs].o)); - state->regData[rhd].v = state->regData[rhs].v; - state->regData[rhd].o = state->regData[rhd].o; - break; - - case 3: /* BX */ - UnwPrintd4("BX r%d\t; r%d %s\n", rhs, rhs, M_Origin2Str(state->regData[rhs].o)); - - /* Only follow BX if the data was from the stack or BX LR */ - if(rhs == 14 || state->regData[rhs].o == REG_VAL_FROM_STACK) { - UnwPrintd2(" Return PC=0x%x\n", state->regData[rhs].v & (~0x1)); - - /* Report the return address, including mode bit */ - if(!UnwReportRetAddr(state, state->regData[rhs].v)) { - return UNWIND_TRUNCATED; - } - - /* Update the PC */ - state->regData[15].v = state->regData[rhs].v; - - /* Determine the new mode */ - if(state->regData[rhs].v & 0x1) { - /* Branching to THUMB */ - - /* Account for the auto-increment which isn't needed */ - state->regData[15].v -= 2; - } - else { - /* Branch to ARM */ - return UnwStartArm(state); - } - } - else { - UnwPrintd4("\nError: BX to invalid register: r%d = 0x%x (%s)\n", rhs, state->regData[rhs].o, M_Origin2Str(state->regData[rhs].o)); - return UNWIND_FAILURE; - } - } - } - /* Format 9: PC-relative load - * LDR Rd,[PC, #imm] - */ - else if((instr & 0xF800) == 0x4800) { - uint8_t rd = (instr & 0x0700) >> 8; - uint8_t word8 = (instr & 0x00FF); - uint32_t address; - - /* Compute load address, adding a word to account for prefetch */ - address = (state->regData[15].v & (~0x3)) + 4 + (word8 << 2); - - UnwPrintd3("LDR r%d, 0x%08x", rd, address); - - if(!UnwMemReadRegister(state, address, &state->regData[rd])) { - return UNWIND_DREAD_W_FAIL; - } - } - /* Format 13: add offset to Stack Pointer - * ADD sp,#+imm - * ADD sp,#-imm - */ - else if((instr & 0xFF00) == 0xB000) { - uint8_t value = (instr & 0x7F) * 4; - - /* Check the negative bit */ - if((instr & 0x80) != 0) { - UnwPrintd2("SUB sp,#0x%x", value); - state->regData[13].v -= value; - } - else { - UnwPrintd2("ADD sp,#0x%x", value); - state->regData[13].v += value; - } - } - /* Format 14: push/pop registers - * PUSH {Rlist} - * PUSH {Rlist, LR} - * POP {Rlist} - * POP {Rlist, PC} - */ - else if((instr & 0xF600) == 0xB400) { - bool L = (instr & 0x0800) ? true : false; - bool R = (instr & 0x0100) ? true : false; - uint8_t rList = (instr & 0x00FF); - - if(L) { - uint8_t r; - - /* Load from memory: POP */ - UnwPrintd2("POP {Rlist%s}\n", R ? ", PC" : ""); - - for(r = 0; r < 8; r++) { - if(rList & (0x1 << r)) { - - /* Read the word */ - if(!UnwMemReadRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DREAD_W_FAIL; - } - - /* Alter the origin to be from the stack if it was valid */ - if(M_IsOriginValid(state->regData[r].o)) { - state->regData[r].o = REG_VAL_FROM_STACK; - } - - state->regData[13].v += 4; - - UnwPrintd3(" r%d = 0x%08x\n", r, state->regData[r].v); - } - } - - /* Check if the PC is to be popped */ - if(R) { - /* Get the return address */ - if(!UnwMemReadRegister(state, state->regData[13].v, &state->regData[15])) { - return UNWIND_DREAD_W_FAIL; - } - - /* Alter the origin to be from the stack if it was valid */ - if(!M_IsOriginValid(state->regData[15].o)) { - /* Return address is not valid */ - UnwPrintd1("PC popped with invalid address\n"); - return UNWIND_FAILURE; - } - else { - /* The bottom bit should have been set to indicate that - * the caller was from Thumb. This would allow return - * by BX for interworking APCS. - */ - if((state->regData[15].v & 0x1) == 0) { - UnwPrintd2("Warning: Return address not to Thumb: 0x%08x\n", state->regData[15].v); - - /* Pop into the PC will not switch mode */ - return UNWIND_INCONSISTENT; - } - - /* Store the return address */ - if(!UnwReportRetAddr(state, state->regData[15].v)) { - return UNWIND_TRUNCATED; - } - - /* Now have the return address */ - UnwPrintd2(" Return PC=%x\n", state->regData[15].v); - - /* Update the pc */ - state->regData[13].v += 4; - - /* Compensate for the auto-increment, which isn't needed here */ - state->regData[15].v -= 2; - } - } - } - else { - int8_t r; - - /* Store to memory: PUSH */ - UnwPrintd2("PUSH {Rlist%s}", R ? ", LR" : ""); - - /* Check if the LR is to be pushed */ - if(R) { - UnwPrintd3("\n lr = 0x%08x\t; %s", state->regData[14].v, M_Origin2Str(state->regData[14].o)); - - state->regData[13].v -= 4; - - /* Write the register value to memory */ - if(!UnwMemWriteRegister(state, state->regData[13].v, &state->regData[14])) { - return UNWIND_DWRITE_W_FAIL; - } - } - - for(r = 7; r >= 0; r--) { - if(rList & (0x1 << r)) { - UnwPrintd4("\n r%d = 0x%08x\t; %s", r, state->regData[r].v, M_Origin2Str(state->regData[r].o)); - - state->regData[13].v -= 4; - - if(!UnwMemWriteRegister(state, state->regData[13].v, &state->regData[r])) { - return UNWIND_DWRITE_W_FAIL; - } - } - } - } - } - - /* - * Conditional branches - * Bcond - */ - else if((instr & 0xF000) == 0xD000) { - int32_t branchValue = (instr & 0xFF); - if (branchValue & 0x80) branchValue |= 0xFFFFFF00; - - /* Branch distance is twice that specified in the instruction. */ - branchValue *= 2; - - UnwPrintd2("Bcond %d \n", branchValue); - - /* Only take the branch if a loop was detected */ - if (loopDetected) { - - /* Update PC */ - state->regData[15].v += branchValue; - - /* Need to advance by a word to account for pre-fetch. - * Advance by a half word here, allowing the normal address - * advance to account for the other half word. - */ - state->regData[15].v += 2; - - /* Display PC of next instruction */ - UnwPrintd2(" New PC=%x", state->regData[15].v + 2); - } - } - - /* Format 18: unconditional branch - * B label - */ - else if((instr & 0xF800) == 0xE000) { - uint32_t v; - int32_t branchValue = signExtend11(instr & 0x07FF); - - /* Branch distance is twice that specified in the instruction. */ - branchValue *= 2; - - UnwPrintd2("B %d \n", branchValue); - - /* Update PC */ - state->regData[15].v += branchValue; - - /* Need to advance by a word to account for pre-fetch. - * Advance by a half word here, allowing the normal address - * advance to account for the other half word. - */ - state->regData[15].v += 2; - - /* Compute the jump address */ - v = state->regData[15].v + 2; - - /* Display PC of next instruction */ - UnwPrintd2(" New PC=%x", v); - - /* Did we detect an infinite loop ? */ - loopDetected = lastJumpAddr == v; - - /* Remember the last address we jumped to */ - lastJumpAddr = v; - } - else { - UnwPrintd1("????"); - - /* Unknown/undecoded. May alter some register, so invalidate file */ - UnwInvalidateRegisterFile(state->regData); - } - - UnwPrintd1("\n"); - - /* Should never hit the reset vector */ - if(state->regData[15].v == 0) - return UNWIND_RESET; - - /* Check next address */ - state->regData[15].v += 2; - - /* Garbage collect the memory hash (used only for the stack) */ - UnwMemHashGC(state); - - t--; - if(t == 0) - return UNWIND_EXHAUSTED; - - } while(!found); - - return UNWIND_SUCCESS; -} - -#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/backtrace/unwarmbytab.cpp b/Marlin/src/HAL/backtrace/unwarmbytab.cpp deleted file mode 100644 index db49dcad7f..0000000000 --- a/Marlin/src/HAL/backtrace/unwarmbytab.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Libbacktrace - * Copyright 2015 Stephen Street - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This library was modified, some bugs fixed, stack address validated - * and adapted to be used in Marlin 3D printer firmware as backtracer - * for exceptions for debugging purposes in 2018 by Eduardo José Tagle. - */ - -#if defined(__arm__) || defined(__thumb__) - -#include "unwarmbytab.h" - -#include -#include - -/* These symbols point to the unwind index and should be provide by the linker script */ -extern "C" const UnwTabEntry __exidx_start[]; -extern "C" const UnwTabEntry __exidx_end[]; - -/* This prevents the linking of libgcc unwinder code */ -void __aeabi_unwind_cpp_pr0(void) {}; -void __aeabi_unwind_cpp_pr1(void) {}; -void __aeabi_unwind_cpp_pr2(void) {}; - -static inline __attribute__((always_inline)) uint32_t prel31_to_addr(const uint32_t *prel31) { - uint32_t offset = (((uint32_t)(*prel31)) << 1) >> 1; - return ((uint32_t)prel31 + offset) & 0x7FFFFFFF; -} - -static const UnwTabEntry *UnwTabSearchIndex(const UnwTabEntry *start, const UnwTabEntry *end, uint32_t ip) { - const UnwTabEntry *middle; - - /* Perform a binary search of the unwind index */ - while (start < end - 1) { - middle = start + ((end - start + 1) >> 1); - if (ip < prel31_to_addr(&middle->addr_offset)) - end = middle; - else - start = middle; - } - return start; -} - -/* - * Get the function name or NULL if not found - */ -static const char *UnwTabGetFunctionName(const UnwindCallbacks *cb, uint32_t address) { - uint32_t flag_word = 0; - if (!cb->readW(address-4,&flag_word)) - return NULL; - - if ((flag_word & 0xFF000000) == 0xFF000000) { - return (const char *)(address - 4 - (flag_word & 0x00FFFFFF)); - } - return NULL; -} - -/** - * Get the next frame unwinding instruction - * - * Return either the instruction or -1 to signal no more instructions - * are available - */ -static int UnwTabGetNextInstruction(const UnwindCallbacks *cb, UnwTabState *ucb) { - int instruction; - - /* Are there more instructions */ - if (ucb->remaining == 0) - return -1; - - /* Extract the current instruction */ - uint32_t v = 0; - if (!cb->readW(ucb->current, &v)) - return -1; - instruction = (v >> (ucb->byte << 3)) & 0xFF; - - /* Move the next byte */ - --ucb->byte; - if (ucb->byte < 0) { - ucb->current += 4; - ucb->byte = 3; - } - --ucb->remaining; - - return instruction; -} - -/** - * Initialize the frame unwinding state - */ -static UnwResult UnwTabStateInit(const UnwindCallbacks *cb, UnwTabState *ucb, uint32_t instructions, const UnwindFrame *frame) { - - /* Initialize control block */ - memset(ucb, 0, sizeof(UnwTabState)); - ucb->current = instructions; - - /* Is a short unwind description */ - uint32_t v = 0; - if (!cb->readW(instructions, &v)) - return UNWIND_DREAD_W_FAIL; - - if ((v & 0xFF000000) == 0x80000000) { - ucb->remaining = 3; - ucb->byte = 2; - /* Is a long unwind description */ - } else if ((v & 0xFF000000) == 0x81000000) { - ucb->remaining = ((v & 0x00FF0000) >> 14) + 2; - ucb->byte = 1; - } else - return UNWIND_UNSUPPORTED_DWARF_PERSONALITY; - - /* Initialize the virtual register set */ - ucb->vrs[7] = frame->fp; - ucb->vrs[13] = frame->sp; - ucb->vrs[14] = frame->lr; - ucb->vrs[15] = 0; - - /* All good */ - return UNWIND_SUCCESS; -} - -/* - * Execute unwinding instructions - */ -static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabState *ucb) { - - int instruction; - uint32_t mask; - uint32_t reg; - uint32_t vsp; - - /* Consume all instruction byte */ - while ((instruction = UnwTabGetNextInstruction(cb, ucb)) != -1) { - - if ((instruction & 0xC0) == 0x00) { // ARM_EXIDX_CMD_DATA_POP - /* vsp = vsp + (xxxxxx << 2) + 4 */ - ucb->vrs[13] += ((instruction & 0x3F) << 2) + 4; - } else - if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH - /* vsp = vsp - (xxxxxx << 2) - 4 */ - ucb->vrs[13] -= ((instruction & 0x3F) << 2) - 4; - } else - if ((instruction & 0xF0) == 0x80) { - /* pop under mask {r15-r12},{r11-r4} or refuse to unwind */ - instruction = instruction << 8 | UnwTabGetNextInstruction(cb, ucb); - - /* Check for refuse to unwind */ - if (instruction == 0x8000) // ARM_EXIDX_CMD_REFUSED - return UNWIND_REFUSED; - - /* Pop registers using mask */ // ARM_EXIDX_CMD_REG_POP - vsp = ucb->vrs[13]; - mask = instruction & 0xFFF; - - reg = 4; - while (mask) { - if ((mask & 1) != 0) { - uint32_t v; - if (!cb->readW(vsp,&v)) - return UNWIND_DREAD_W_FAIL; - ucb->vrs[reg] = v; - v += 4; - } - mask >>= 1; - ++reg; - } - - /* Patch up the vrs sp if it was in the mask */ - if ((instruction & (1 << (13 - 4))) != 0) - ucb->vrs[13] = vsp; - - } else - if ((instruction & 0xF0) == 0x90 && // ARM_EXIDX_CMD_REG_TO_SP - instruction != 0x9D && - instruction != 0x9F) { - /* vsp = r[nnnn] */ - ucb->vrs[13] = ucb->vrs[instruction & 0x0F]; - } else - if ((instruction & 0xF0) == 0xA0) { // ARM_EXIDX_CMD_REG_POP - /* pop r4-r[4+nnn] or pop r4-r[4+nnn], r14*/ - vsp = ucb->vrs[13]; - - for (reg = 4; reg <= uint32_t((instruction & 0x07) + 4); ++reg) { - uint32_t v; - if (!cb->readW(vsp,&v)) - return UNWIND_DREAD_W_FAIL; - - ucb->vrs[reg] = v; - vsp += 4; - } - - if (instruction & 0x08) { // ARM_EXIDX_CMD_REG_POP - uint32_t v; - if (!cb->readW(vsp,&v)) - return UNWIND_DREAD_W_FAIL; - ucb->vrs[14] = v; - vsp += 4; - } - - ucb->vrs[13] = vsp; - - } else - if (instruction == 0xB0) { // ARM_EXIDX_CMD_FINISH - /* finished */ - if (ucb->vrs[15] == 0) - ucb->vrs[15] = ucb->vrs[14]; - - /* All done unwinding */ - return UNWIND_SUCCESS; - - } else - if (instruction == 0xB1) { // ARM_EXIDX_CMD_REG_POP - /* pop register under mask {r3,r2,r1,r0} */ - vsp = ucb->vrs[13]; - mask = UnwTabGetNextInstruction(cb, ucb); - - reg = 0; - while (mask) { - if ((mask & 1) != 0) { - uint32_t v; - if (!cb->readW(vsp,&v)) - return UNWIND_DREAD_W_FAIL; - - ucb->vrs[reg] = v; - vsp += 4; - } - mask >>= 1; - ++reg; - } - ucb->vrs[13] = (uint32_t)vsp; - - } else - if (instruction == 0xB2) { // ARM_EXIDX_CMD_DATA_POP - /* vps = vsp + 0x204 + (uleb128 << 2) */ - ucb->vrs[13] += 0x204 + (UnwTabGetNextInstruction(cb, ucb) << 2); - - } else - if (instruction == 0xB3 || // ARM_EXIDX_CMD_VFP_POP - instruction == 0xC8 || - instruction == 0xC9) { - - /* pop VFP double-precision registers */ - vsp = ucb->vrs[13]; - - /* D[ssss]-D[ssss+cccc] */ - uint32_t v; - if (!cb->readW(vsp,&v)) - return UNWIND_DREAD_W_FAIL; - - ucb->vrs[14] = v; - vsp += 4; - - if (instruction == 0xC8) { - /* D[16+sssss]-D[16+ssss+cccc] */ - ucb->vrs[14] |= 1 << 16; - } - - if (instruction != 0xB3) { - /* D[sssss]-D[ssss+cccc] */ - ucb->vrs[14] |= 1 << 17; - } - - ucb->vrs[13] = vsp; - - } else - if ((instruction & 0xF8) == 0xB8 || - (instruction & 0xF8) == 0xD0) { - - /* Pop VFP double precision registers D[8]-D[8+nnn] */ - ucb->vrs[14] = 0x80 | (instruction & 0x07); - - if ((instruction & 0xF8) == 0xD0) { - ucb->vrs[14] = 1 << 17; - } - - } else - return UNWIND_UNSUPPORTED_DWARF_INSTR; - } - - return UNWIND_SUCCESS; -} - -static inline __attribute__((always_inline)) uint32_t read_psp(void) { - - /* Read the current PSP and return its value as a pointer */ - uint32_t psp; - - __asm__ volatile ( - " mrs %0, psp \n" - : "=r" (psp) : : - ); - - return psp; -} - -/* - * Unwind the specified frame and goto the previous one - */ -static UnwResult UnwTabUnwindFrame(const UnwindCallbacks *cb, UnwindFrame *frame) { - - UnwResult err; - UnwTabState ucb; - const UnwTabEntry *index; - uint32_t instructions; - - /* Search the unwind index for the matching unwind table */ - index = UnwTabSearchIndex(__exidx_start, __exidx_end, frame->pc); - - /* Make sure we can unwind this frame */ - if (index->insn == 0x00000001) - return UNWIND_SUCCESS; - - /* Get the pointer to the first unwind instruction */ - if (index->insn & 0x80000000) - instructions = (uint32_t)&index->insn; - else - instructions = prel31_to_addr(&index->insn); - - /* Initialize the unwind control block */ - if ((err = UnwTabStateInit(cb, &ucb, instructions, frame)) < 0) - return err; - - /* Execute the unwind instructions */ - err = UnwTabExecuteInstructions(cb, &ucb); - if (err < 0) - return err; - - /* Set the virtual pc to the virtual lr if this is the first unwind */ - if (ucb.vrs[15] == 0) - ucb.vrs[15] = ucb.vrs[14]; - - /* Check for exception return */ - /* TODO Test with other ARM processors to verify this method. */ - if ((ucb.vrs[15] & 0xF0000000) == 0xF0000000) { - /* According to the Cortex Programming Manual (p.44), the stack address is always 8-byte aligned (Cortex-M7). - Depending on where the exception came from (MSP or PSP), we need the right SP value to work with. - - ucb.vrs[7] contains the right value, so take it and align it by 8 bytes, store it as the current - SP to work with (ucb.vrs[13]) which is then saved as the current (virtual) frame's SP. - */ - uint32_t stack; - ucb.vrs[13] = (ucb.vrs[7] & ~7); - - /* If we need to start from the MSP, we need to go down X words to find the PC, where: - X=2 if it was a non-floating-point exception - X=20 if it was a floating-point (VFP) exception - - If we need to start from the PSP, we need to go up exactly 6 words to find the PC. - See the ARMv7-M Architecture Reference Manual p.594 and Cortex-M7 Processor Programming Manual p.44/p.45 for details. - */ - if ((ucb.vrs[15] & 0xC) == 0) { - /* Return to Handler Mode: MSP (0xFFFFFF-1) */ - stack = ucb.vrs[13]; - - /* The PC is always 2 words down from the MSP, if it was a non-floating-point exception */ - stack -= 2*4; - - /* If there was a VFP exception (0xFFFFFFE1), the PC is located another 18 words down */ - if ((ucb.vrs[15] & 0xF0) == 0xE0) { - stack -= 18*4; - } - } - else { - /* Return to Thread Mode: PSP (0xFFFFFF-d) */ - stack = read_psp(); - - /* The PC is always 6 words up from the PSP */ - stack += 6*4; - } - - /* Store the PC */ - uint32_t v; - if (!cb->readW(stack,&v)) - return UNWIND_DREAD_W_FAIL; - ucb.vrs[15] = v; - stack -= 4; - - /* Store the LR */ - if (!cb->readW(stack,&v)) - return UNWIND_DREAD_W_FAIL; - ucb.vrs[14] = v; - stack -= 4; - } - - /* We are done if current frame pc is equal to the virtual pc, prevent infinite loop */ - if (frame->pc == ucb.vrs[15]) - return UNWIND_SUCCESS; - - /* Update the frame */ - frame->fp = ucb.vrs[7]; - frame->sp = ucb.vrs[13]; - frame->lr = ucb.vrs[14]; - frame->pc = ucb.vrs[15]; - - /* All good - Continue unwinding */ - return UNWIND_MORE_AVAILABLE; -} - -UnwResult UnwindByTableStart(UnwindFrame* frame, const UnwindCallbacks *cb, void *data) { - - UnwResult err = UNWIND_SUCCESS; - UnwReport entry; - - /* Use DWARF unwind information to unwind frames */ - do { - if (frame->pc == 0) { - /* Reached __exidx_end. */ - break; - } - - if (frame->pc == 0x00000001) { - /* Reached .cantunwind instruction. */ - break; - } - - /* Find the unwind index of the current frame pc */ - const UnwTabEntry *index = UnwTabSearchIndex(__exidx_start, __exidx_end, frame->pc); - - /* Clear last bit (Thumb indicator) */ - frame->pc &= 0xFFFFFFFEU; - - /* Generate the backtrace information */ - entry.address = frame->pc; - entry.function = prel31_to_addr(&index->addr_offset); - entry.name = UnwTabGetFunctionName(cb, entry.function); - if (!cb->report(data,&entry)) - break; - - /* Unwind frame and repeat */ - } while ((err = UnwTabUnwindFrame(cb, frame)) == UNWIND_MORE_AVAILABLE); - - /* All done */ - return err; -} - -#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/backtrace/unwarmbytab.h b/Marlin/src/HAL/backtrace/unwarmbytab.h deleted file mode 100644 index 527d3a6c72..0000000000 --- a/Marlin/src/HAL/backtrace/unwarmbytab.h +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Interface to the memory tracking sub-system. - **************************************************************************/ - -#ifndef UNWARMBYTAB_H -#define UNWARMBYTAB_H - -#include "unwarm.h" - -typedef struct { - uint32_t vrs[16]; - uint32_t current; /* Address of current byte */ - int remaining; - int byte; -} UnwTabState; - -typedef struct { - uint32_t addr_offset; - uint32_t insn; -} UnwTabEntry; - -UnwResult UnwindByTableStart(UnwindFrame* frame, const UnwindCallbacks *cb, void *data); - -#endif // UNWARMBYTAB_H diff --git a/Marlin/src/HAL/backtrace/unwarmmem.cpp b/Marlin/src/HAL/backtrace/unwarmmem.cpp deleted file mode 100644 index 7453fdb8db..0000000000 --- a/Marlin/src/HAL/backtrace/unwarmmem.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Implementation of the memory tracking sub-system. - **************************************************************************/ - -#if defined(__arm__) || defined(__thumb__) -#define MODULE_NAME "UNWARMMEM" - -#include -#include "unwarmmem.h" -#include "unwarm.h" - -#define M_IsIdxUsed(a, v) (((a)[v >> 3] & (1 << (v & 0x7))) ? true : false) -#define M_SetIdxUsed(a, v) ((a)[v >> 3] |= (1 << (v & 0x7))) -#define M_ClrIdxUsed(a, v) ((a)[v >> 3] &= ~(1 << (v & 0x7))) - -/** Search the memory hash to see if an entry is stored in the hash already. - * This will search the hash and either return the index where the item is - * stored, or -1 if the item was not found. - */ -static int16_t memHashIndex(MemData * const memData, const uint32_t addr) { - - const uint16_t v = addr % MEM_HASH_SIZE; - uint16_t s = v; - - do { - /* Check if the element is occupied */ - if(M_IsIdxUsed(memData->used, s)) { - /* Check if it is occupied with the sought data */ - if(memData->a[s] == addr) { - return s; - } - } - else { - /* Item is free, this is where the item should be stored */ - return s; - } - - /* Search the next entry */ - s++; - if(s > MEM_HASH_SIZE) { - s = 0; - } - } while(s != v); - - /* Search failed, hash is full and the address not stored */ - return -1; -} - -bool UnwMemHashRead(MemData * const memData, uint32_t addr,uint32_t * const data, bool * const tracked) { - - int16_t i = memHashIndex(memData, addr); - - if(i >= 0 && M_IsIdxUsed(memData->used, i) && memData->a[i] == addr) { - *data = memData->v[i]; - *tracked = M_IsIdxUsed(memData->tracked, i); - return true; - } - else { - /* Address not found in the hash */ - return false; - } -} - -bool UnwMemHashWrite(MemData * const memData, uint32_t addr, uint32_t val, bool valValid) { - - int16_t i = memHashIndex(memData, addr); - - if(i < 0){ - /* Hash full */ - return false; - } - else { - /* Store the item */ - memData->a[i] = addr; - M_SetIdxUsed(memData->used, i); - - if(valValid) - { - memData->v[i] = val; - M_SetIdxUsed(memData->tracked, i); - } - else { - #if defined(UNW_DEBUG) - memData->v[i] = 0xDEADBEEF; - #endif - M_ClrIdxUsed(memData->tracked, i); - } - - return true; - } -} - -void UnwMemHashGC(UnwState * const state) { - - const uint32_t minValidAddr = state->regData[13].v; - MemData * const memData = &state->memData; - uint16_t t; - - for(t = 0; t < MEM_HASH_SIZE; t++) { - if(M_IsIdxUsed(memData->used, t) && (memData->a[t] < minValidAddr)) { - UnwPrintd3("MemHashGC: Free elem %d, addr 0x%08x\n", t, memData->a[t]); - - M_ClrIdxUsed(memData->used, t); - } - } -} - -#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/backtrace/unwarmmem.h b/Marlin/src/HAL/backtrace/unwarmmem.h deleted file mode 100644 index f30846b34c..0000000000 --- a/Marlin/src/HAL/backtrace/unwarmmem.h +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Interface to the memory tracking sub-system. - **************************************************************************/ - -#ifndef UNWARMMEM_H -#define UNWARMMEM_H - -#include "unwarm.h" - -bool UnwMemHashRead(MemData * const memData, uint32_t addr, uint32_t * const data, bool * const tracked); -bool UnwMemHashWrite(MemData * const memData, uint32_t addr, uint32_t val, bool valValid); -void UnwMemHashGC(UnwState * const state); - -#endif - diff --git a/Marlin/src/HAL/backtrace/unwinder.cpp b/Marlin/src/HAL/backtrace/unwinder.cpp deleted file mode 100644 index 66281670c6..0000000000 --- a/Marlin/src/HAL/backtrace/unwinder.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Implementation of the interface into the ARM unwinder. - **************************************************************************/ - -#if defined(__arm__) || defined(__thumb__) - -#define MODULE_NAME "UNWINDER" - -#include -#include -#include "unwinder.h" -#include "unwarm.h" -#include "unwarmbytab.h" - -/* These symbols point to the unwind index and should be provide by the linker script */ -extern "C" const UnwTabEntry __exidx_start[]; -extern "C" const UnwTabEntry __exidx_end[]; - -// Detect if unwind information is present or not -static int HasUnwindTableInfo(void) { - // > 16 because there are default entries we can't supress - return ((char*)(&__exidx_end) - (char*)(&__exidx_start)) > 16 ? 1 : 0; -} - -UnwResult UnwindStart(UnwindFrame* frame, const UnwindCallbacks *cb, void *data) { - - if (HasUnwindTableInfo()) { - - /* We have unwind information tables */ - return UnwindByTableStart(frame, cb, data); - - } else { - - /* We don't have unwind information tables */ - UnwState state; - - /* Initialise the unwinding state */ - UnwInitState(&state, cb, data, frame->pc, frame->sp); - - /* Check the Thumb bit */ - if(frame->pc & 0x1) { - return UnwStartThumb(&state); - } - else { - return UnwStartArm(&state); - } - } -} -#endif - - diff --git a/Marlin/src/HAL/backtrace/unwinder.h b/Marlin/src/HAL/backtrace/unwinder.h deleted file mode 100644 index 29132d0b5b..0000000000 --- a/Marlin/src/HAL/backtrace/unwinder.h +++ /dev/null @@ -1,175 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - **************************************************************************/ -/** \file - * Interface to the ARM stack unwinding module. - **************************************************************************/ - -#ifndef UNWINDER_H -#define UNWINDER_H - -#include - -/** \def UNW_DEBUG - * If this define is set, additional information will be produced while - * unwinding the stack to allow debug of the unwind module itself. - */ -/* #define UNW_DEBUG 1 */ - -/*************************************************************************** - * Type Definitions - **************************************************************************/ - -/** Possible results for UnwindStart to return. - */ -typedef enum { - /** Unwinding was successful and complete. */ - UNWIND_SUCCESS = 0, - - /** Not an error: More frames are available. */ - UNWIND_MORE_AVAILABLE = 1, - - /** Unsupported DWARF unwind personality. */ - UNWIND_UNSUPPORTED_DWARF_PERSONALITY = -1, - - /** Refused to perform unwind. */ - UNWIND_REFUSED = -2, - - /** Reached an invalid SP. */ - UNWIND_INVALID_SP = -3, - - /** Reached an invalid PC */ - UNWIND_INVALID_PC = -4, - - /** Unsupported DWARF instruction */ - UNWIND_UNSUPPORTED_DWARF_INSTR = -5, - - /** More than UNW_MAX_INSTR_COUNT instructions were interpreted. */ - UNWIND_EXHAUSTED = -6, - - /** Unwinding stopped because the reporting func returned false. */ - UNWIND_TRUNCATED = -7, - - /** Read data was found to be inconsistent. */ - UNWIND_INCONSISTENT = -8, - - /** Unsupported instruction or data found. */ - UNWIND_UNSUPPORTED = -9, - - /** General failure. */ - UNWIND_FAILURE = -10, - - /** Illegal instruction. */ - UNWIND_ILLEGAL_INSTR = -11, - - /** Unwinding hit the reset vector. */ - UNWIND_RESET = -12, - - /** Failed read for an instruction word. */ - UNWIND_IREAD_W_FAIL = -13, - - /** Failed read for an instruction half-word. */ - UNWIND_IREAD_H_FAIL = -14, - - /** Failed read for an instruction byte. */ - UNWIND_IREAD_B_FAIL = -15, - - /** Failed read for a data word. */ - UNWIND_DREAD_W_FAIL = -16, - - /** Failed read for a data half-word. */ - UNWIND_DREAD_H_FAIL = -17, - - /** Failed read for a data byte. */ - UNWIND_DREAD_B_FAIL = -18, - - /** Failed write for a data word. */ - UNWIND_DWRITE_W_FAIL = -19 - -} UnwResult; - -/** A backtrace report */ -typedef struct { - uint32_t function; /** Starts address of function */ - const char *name; /** Function name, or null if not available */ - uint32_t address; /** PC on that function */ -} UnwReport; - -/** Type for function pointer for result callback. - * The function is passed two parameters, the first is a void * pointer, - * and the second is the return address of the function. The bottom bit - * of the passed address indicates the execution mode; if it is set, - * the execution mode at the return address is Thumb, otherwise it is - * ARM. - * - * The return value of this function determines whether unwinding should - * continue or not. If true is returned, unwinding will continue and the - * report function maybe called again in future. If false is returned, - * unwinding will stop with UnwindStart() returning UNWIND_TRUNCATED. - */ -typedef bool (*UnwindReportFunc)(void* data, const UnwReport* bte); - -/** Structure that holds memory callback function pointers. - */ -typedef struct { - - /** Report an unwind result. */ - UnwindReportFunc report; - - /** Read a 32 bit word from memory. - * The memory address to be read is passed as \a address, and - * \a *val is expected to be populated with the read value. - * If the address cannot or should not be read, false can be - * returned to indicate that unwinding should stop. If true - * is returned, \a *val is assumed to be valid and unwinding - * will continue. - */ - bool (*readW)(const uint32_t address, uint32_t *val); - - /** Read a 16 bit half-word from memory. - * This function has the same usage as for readW, but is expected - * to read only a 16 bit value. - */ - bool (*readH)(const uint32_t address, uint16_t *val); - - /** Read a byte from memory. - * This function has the same usage as for readW, but is expected - * to read only an 8 bit value. - */ - bool (*readB)(const uint32_t address, uint8_t *val); - - #ifdef UNW_DEBUG - /** Print a formatted line for debug. */ - void (*printf)(const char *format, ...); - #endif -} UnwindCallbacks; - -/* A frame */ -typedef struct { - uint32_t fp; - uint32_t sp; - uint32_t lr; - uint32_t pc; -} UnwindFrame; - -/** Start unwinding the current stack. - * This will unwind the stack starting at the PC value supplied to in the - * link register (i.e. not a normal register) and the stack pointer value - * supplied. - * - * -If the program was compiled with -funwind-tables , it will use them to - * perform the traceback. Otherwise, brute force will be employed - * -If the program was compiled with -mpoke-function-name, then you will - * get function names in the traceback. Otherwise, you will not. - */ -UnwResult UnwindStart(UnwindFrame* frame, const UnwindCallbacks *cb, void *data); - -#endif /* UNWINDER_H */ diff --git a/Marlin/src/HAL/backtrace/unwmemaccess.cpp b/Marlin/src/HAL/backtrace/unwmemaccess.cpp deleted file mode 100644 index b939be8803..0000000000 --- a/Marlin/src/HAL/backtrace/unwmemaccess.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Utility functions to access memory - **************************************************************************/ - -#if defined(__arm__) || defined(__thumb__) - -#include "unwmemaccess.h" - -/* Validate address */ - -#ifdef ARDUINO_ARCH_SAM -// For DUE, valid address ranges are -// SRAM (0x20070000 - 0x20088000) (96kb) -// FLASH (0x00080000 - 0x00100000) (512kb) -// -#define START_SRAM_ADDR 0x20070000 -#define END_SRAM_ADDR 0x20088000 -#define START_FLASH_ADDR 0x00080000 -#define END_FLASH_ADDR 0x00100000 -#endif - -#ifdef TARGET_LPC1768 -// For LPC1769: -// SRAM (0x10000000 - 0x10008000) (32kb) -// FLASH (0x00000000 - 0x00080000) (512kb) -// -#define START_SRAM_ADDR 0x10000000 -#define END_SRAM_ADDR 0x10008000 -#define START_FLASH_ADDR 0x00000000 -#define END_FLASH_ADDR 0x00080000 -#endif - -#if 0 -// For STM32F103CBT6 -// SRAM (0x20000000 - 0x20005000) (20kb) -// FLASH (0x00000000 - 0x00020000) (128kb) -// -#define START_SRAM_ADDR 0x20000000 -#define END_SRAM_ADDR 0x20005000 -#define START_FLASH_ADDR 0x00000000 -#define END_FLASH_ADDR 0x00020000 -#endif - -#ifdef __STM32F1__ -// For STM32F103ZET6/STM32F103VET6 -// SRAM (0x20000000 - 0x20010000) (64kb) -// FLASH (0x00000000 - 0x00080000) (512kb) -// -#define START_SRAM_ADDR 0x20000000 -#define END_SRAM_ADDR 0x20010000 -#define START_FLASH_ADDR 0x00000000 -#define END_FLASH_ADDR 0x00080000 -#endif - -#if defined(STM32F4) || defined(STM32F4xx) -// For STM32F407VET -// SRAM (0x20000000 - 0x20030000) (192kb) -// FLASH (0x08000000 - 0x08080000) (512kb) -// -#define START_SRAM_ADDR 0x20000000 -#define END_SRAM_ADDR 0x20030000 -#define START_FLASH_ADDR 0x08000000 -#define END_FLASH_ADDR 0x08080000 -#endif - -#ifdef STM32F7 -// For STM32F765 in BORG -// SRAM (0x20000000 - 0x20080000) (512kb) -// FLASH (0x08000000 - 0x08100000) (1024kb) -// -#define START_SRAM_ADDR 0x20000000 -#define END_SRAM_ADDR 0x20080000 -#define START_FLASH_ADDR 0x08000000 -#define END_FLASH_ADDR 0x08100000 -#endif - -#ifdef __MK64FX512__ -// For MK64FX512 in TEENSY 3.5 -// SRAM (0x1FFF0000 - 0x20020000) (192kb) -// FLASH (0x00000000 - 0x00080000) (512kb) -// -#define START_SRAM_ADDR 0x1FFF0000 -#define END_SRAM_ADDR 0x20020000 -#define START_FLASH_ADDR 0x00000000 -#define END_FLASH_ADDR 0x00080000 -#endif - -#ifdef __MK66FX1M0__ -// For MK66FX1M0 in TEENSY 3.6 -// SRAM (0x1FFF0000 - 0x20030000) (256kb) -// FLASH (0x00000000 - 0x00140000) (1.25Mb) -// -#define START_SRAM_ADDR 0x1FFF0000 -#define END_SRAM_ADDR 0x20030000 -#define START_FLASH_ADDR 0x00000000 -#define END_FLASH_ADDR 0x00140000 -#endif - -static bool validate_addr(uint32_t addr) { - - // Address must be in SRAM range - if (addr >= START_SRAM_ADDR && addr < END_SRAM_ADDR) - return true; - - // Or in FLASH range - if (addr >= START_FLASH_ADDR && addr < END_FLASH_ADDR) - return true; - - return false; -} - -bool UnwReadW(const uint32_t a, uint32_t *v) { - if (!validate_addr(a)) - return false; - - *v = *(uint32_t *)a; - return true; -} - -bool UnwReadH(const uint32_t a, uint16_t *v) { - if (!validate_addr(a)) - return false; - - *v = *(uint16_t *)a; - return true; -} - -bool UnwReadB(const uint32_t a, uint8_t *v) { - if (!validate_addr(a)) - return false; - - *v = *(uint8_t *)a; - return true; -} - -#endif - diff --git a/Marlin/src/HAL/backtrace/unwmemaccess.h b/Marlin/src/HAL/backtrace/unwmemaccess.h deleted file mode 100644 index 5405f3a673..0000000000 --- a/Marlin/src/HAL/backtrace/unwmemaccess.h +++ /dev/null @@ -1,26 +0,0 @@ -/*************************************************************************** - * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk - * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle - * - * This program is PUBLIC DOMAIN. - * This means that there is no copyright and anyone is able to take a copy - * 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 - * 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. - *************************************************************************** - * File Description: Utility functions to access memory - **************************************************************************/ - -#ifndef UNWMEMACCESS_H -#define UNWMEMACCESS_H - -#include "unwarm.h" -#include - -bool UnwReadW(const uint32_t a, uint32_t *v); -bool UnwReadH(const uint32_t a, uint16_t *v); -bool UnwReadB(const uint32_t a, uint8_t *v); - -#endif - diff --git a/Marlin/src/HAL/math_32bit.h b/Marlin/src/HAL/math_32bit.h deleted file mode 100644 index a59d221369..0000000000 --- a/Marlin/src/HAL/math_32bit.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -#ifndef MATH_32BIT_H -#define MATH_32BIT_H - -#include "../core/macros.h" - -/** - * Math helper functions for 32 bit CPUs - */ -static FORCE_INLINE uint32_t MultiU32X24toH32(uint32_t longIn1, uint32_t longIn2) { - return ((uint64_t)longIn1 * longIn2 + 0x00800000) >> 24; -} - -#endif // MATH_32BIT_H diff --git a/Marlin/src/HAL/persistent_store_api.h b/Marlin/src/HAL/persistent_store_api.h deleted file mode 100644 index 642e5712f3..0000000000 --- a/Marlin/src/HAL/persistent_store_api.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _PERSISTENT_STORE_H_ -#define _PERSISTENT_STORE_H_ - -#include -#include - -namespace HAL { -namespace PersistentStore { - -bool access_start(); -bool access_finish(); -bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc); -bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing=true); - -} // PersistentStore -} // HAL - -#endif // _PERSISTENT_STORE_H_ diff --git a/Marlin/src/HAL/servo.cpp b/Marlin/src/HAL/servo.cpp deleted file mode 100644 index a49aac0f99..0000000000 --- a/Marlin/src/HAL/servo.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 - * Copyright (c) 2009 Michael Margolis. All right reserved. - */ - -/** - * A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. - * The servos are pulsed in the background using the value most recently written using the write() method - * - * Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. - * Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. - * - * The methods are: - * - * Servo - Class for manipulating servo motors connected to Arduino pins. - * - * attach(pin) - Attach a servo motor to an i/o pin. - * attach(pin, min, max) - Attach to a pin, setting min and max values in microseconds - * Default min is 544, max is 2400 - * - * write() - Set the servo angle in degrees. (Invalid angles —over MIN_PULSE_WIDTH— are treated as µs.) - * writeMicroseconds() - Set the servo pulse width in microseconds. - * move(pin, angle) - Sequence of attach(pin), write(angle), safe_delay(servo_delay[servoIndex]). - * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after servo_delay[servoIndex]. - * read() - Get the last-written servo pulse width as an angle between 0 and 180. - * readMicroseconds() - Get the last-written servo pulse width in microseconds. - * attached() - Return true if a servo is attached. - * detach() - Stop an attached servo from pulsing its i/o pin. - * - */ - -#include "../inc/MarlinConfig.h" - -#if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768) || defined(STM32F4) || defined(STM32F4xx)) - -//#include -#include "servo.h" -#include "servo_private.h" - -ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures -uint8_t ServoCount = 0; // the total number of attached servos - -#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo -#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo - -/************ static functions common to all instances ***********************/ - -static boolean isTimerActive(timer16_Sequence_t timer) { - // returns true if any servo is active on this timer - for (uint8_t channel = 0; channel < SERVOS_PER_TIMER; channel++) { - if (SERVO(timer, channel).Pin.isActive) - return true; - } - return false; -} - -/****************** end of static functions ******************************/ - -Servo::Servo() { - if (ServoCount < MAX_SERVOS) { - this->servoIndex = ServoCount++; // assign a servo index to this instance - servo_info[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009 - } - else - this->servoIndex = INVALID_SERVO; // too many servos -} - -int8_t Servo::attach(const int pin) { - return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); -} - -int8_t Servo::attach(const int pin, const int min, const int max) { - - if (this->servoIndex >= MAX_SERVOS) return -1; - - if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin; - pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output - - // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128 - this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS - this->max = (MAX_PULSE_WIDTH - max) / 4; - - // initialize the timer if it has not already been initialized - timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); - if (!isTimerActive(timer)) initISR(timer); - servo_info[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive - - return this->servoIndex; -} - -void Servo::detach() { - servo_info[this->servoIndex].Pin.isActive = false; - timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); - if (!isTimerActive(timer)) finISR(timer); -} - -void Servo::write(int value) { - if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) - value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX()); - } - this->writeMicroseconds(value); -} - -void Servo::writeMicroseconds(int value) { - // calculate and store the values for the given channel - byte channel = this->servoIndex; - if (channel < MAX_SERVOS) { // ensure channel is valid - // ensure pulse width is valid - value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION); - value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009 - - CRITICAL_SECTION_START; - servo_info[channel].ticks = value; - CRITICAL_SECTION_END; - } -} - -// return the value as degrees -int Servo::read() { return map(this->readMicroseconds() + 1, SERVO_MIN(), SERVO_MAX(), 0, 180); } - -int Servo::readMicroseconds() { - return (this->servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[this->servoIndex].ticks) + TRIM_DURATION; -} - -bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; } - -void Servo::move(const int value) { - constexpr uint16_t servo_delay[] = SERVO_DELAY; - static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long."); - if (this->attach(0) >= 0) { - this->write(value); - safe_delay(servo_delay[this->servoIndex]); - #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE) - this->detach(); - #endif - } -} - -#endif // HAS_SERVOS diff --git a/Marlin/src/HAL/servo.h b/Marlin/src/HAL/servo.h deleted file mode 100644 index 5df396efd6..0000000000 --- a/Marlin/src/HAL/servo.h +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 - * Copyright (c) 2009 Michael Margolis. All right reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * - * A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. - * The servos are pulsed in the background using the value most recently written using the write() method - * - * Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. - * Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. - * The sequence used to seize timers is defined in timers.h - * - * The methods are: - * - * Servo - Class for manipulating servo motors connected to Arduino pins. - * - * attach(pin ) - Attaches a servo motor to an i/o pin. - * attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds - * default min is 544, max is 2400 - * - * write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) - * writeMicroseconds() - Sets the servo pulse width in microseconds - * read() - Gets the last written servo pulse width as an angle between 0 and 180. - * readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) - * attached() - Returns true if there is a servo attached. - * detach() - Stops an attached servos from pulsing its i/o pin. - * move(angle) - Sequence of attach(0), write(angle), - * With DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY and detach. - */ - -#ifndef SERVO_H -#define SERVO_H - -#if IS_32BIT_TEENSY - #include "HAL_TEENSY35_36/HAL_Servo_Teensy.h" // Teensy HAL uses an inherited library - -#elif defined(TARGET_LPC1768) - #include "HAL_LPC1768/LPC1768_Servo.h" -#elif defined(STM32F4) || defined(STM32F4xx) - #include "HAL_STM32F4/HAL_Servo_STM32F4.h" -#else - #include - - #if defined(__AVR__) || defined(ARDUINO_ARCH_SAM) - // we're good to go - #else - #error "This library only supports boards with an AVR or SAM3X processor." - #endif - - #define Servo_VERSION 2 // software version of this library - - class Servo { - public: - Servo(); - int8_t attach(const int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail) - int8_t attach(const int pin, const int min, const int max); // as above but also sets min and max values for writes. - void detach(); - void write(int value); // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds - void writeMicroseconds(int value); // write pulse width in microseconds - void move(const int value); // attach the servo, then move to value - // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds - // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach - int read(); // returns current pulse width as an angle between 0 and 180 degrees - int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) - bool attached(); // return true if this servo is attached, otherwise false - - private: - uint8_t servoIndex; // index into the channel data for this servo - int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH - int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH - }; - -#endif - -#endif // SERVO_H diff --git a/Marlin/src/HAL/servo_private.h b/Marlin/src/HAL/servo_private.h deleted file mode 100644 index 3b1bcda584..0000000000 --- a/Marlin/src/HAL/servo_private.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * servo_private.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 - * Copyright (c) 2009 Michael Margolis. All right reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef SERVO_PRIVATE_H -#define SERVO_PRIVATE_H - -#include - -// Architecture specific include -#ifdef __AVR__ - #include "HAL_AVR/ServoTimers.h" -#elif defined(ARDUINO_ARCH_SAM) - #include "HAL_DUE/ServoTimers.h" -#else - #error "This library only supports boards with an AVR or SAM3X processor." -#endif - -// Macros - -#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo -#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo -#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached -#define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds - -#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer -#define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER) - -#define INVALID_SERVO 255 // flag indicating an invalid servo index - -// -#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / PRESCALER) // converts microseconds to tick (PRESCALER depends on architecture) -#define ticksToUs(_ticks) (( (unsigned)_ticks * PRESCALER)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds - -//#define NBR_TIMERS ((MAX_SERVOS) / (SERVOS_PER_TIMER)) - -// convenience macros -#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo -#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % (SERVOS_PER_TIMER)) // returns the index of the servo on this timer -#define SERVO_INDEX(_timer,_channel) ((_timer*(SERVOS_PER_TIMER)) + _channel) // macro to access servo index by timer and channel -#define SERVO(_timer,_channel) (servo_info[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel - -// Types - -typedef struct { - uint8_t nbr : 6 ; // a pin number from 0 to 63 - uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false -} ServoPin_t; - -typedef struct { - ServoPin_t Pin; - unsigned int ticks; -} ServoInfo_t; - -// Global variables - -extern uint8_t ServoCount; -extern ServoInfo_t servo_info[MAX_SERVOS]; - -// Public functions - -extern void initISR(timer16_Sequence_t timer); -extern void finISR(timer16_Sequence_t timer); - -#endif // SERVO_PRIVATE_H diff --git a/Marlin/src/config/examples/Azteeg/X5GT/Configuration_adv.h b/Marlin/src/config/examples/Azteeg/X5GT/Configuration_adv.h deleted file mode 100644 index b6c0db3842..0000000000 --- a/Marlin/src/config/examples/Azteeg/X5GT/Configuration_adv.h +++ /dev/null @@ -1,1685 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -/** - * Configuration_adv.h - * - * Advanced settings. - * Only change these if you know exactly what you're doing. - * Some of these settings can damage your printer if improperly set! - * - * Basic settings can be found in Configuration.h - * - */ -#ifndef CONFIGURATION_ADV_H -#define CONFIGURATION_ADV_H -#define CONFIGURATION_ADV_H_VERSION 020000 - -// @section temperature - -//=========================================================================== -//=============================Thermal Settings ============================ -//=========================================================================== - -// -// Hephestos 2 24V heated bed upgrade kit. -// https://store.bq.com/en/heated-bed-kit-hephestos2 -// -//#define HEPHESTOS2_HEATED_BED_KIT -#if ENABLED(HEPHESTOS2_HEATED_BED_KIT) - #undef TEMP_SENSOR_BED - #define TEMP_SENSOR_BED 70 - #define HEATER_BED_INVERTING true -#endif - -#if DISABLED(PIDTEMPBED) - #define BED_CHECK_INTERVAL 5000 // ms between checks in bang-bang control - #if ENABLED(BED_LIMIT_SWITCHING) - #define BED_HYSTERESIS 2 // Only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS - #endif -#endif - -/** - * Thermal Protection provides additional protection to your printer from damage - * and fire. Marlin always includes safe min and max temperature ranges which - * protect against a broken or disconnected thermistor wire. - * - * The issue: If a thermistor falls out, it will report the much lower - * temperature of the air in the room, and the the firmware will keep - * the heater on. - * - * The solution: Once the temperature reaches the target, start observing. - * If the temperature stays too far below the target (hysteresis) for too - * long (period), the firmware will halt the machine as a safety precaution. - * - * If you get false positives for "Thermal Runaway", increase - * THERMAL_PROTECTION_HYSTERESIS and/or THERMAL_PROTECTION_PERIOD - */ -#if ENABLED(THERMAL_PROTECTION_HOTENDS) - #define THERMAL_PROTECTION_PERIOD 40 // Seconds - #define THERMAL_PROTECTION_HYSTERESIS 4 // Degrees Celsius - - /** - * Whenever an M104, M109, or M303 increases the target temperature, the - * firmware will wait for the WATCH_TEMP_PERIOD to expire. If the temperature - * hasn't increased by WATCH_TEMP_INCREASE degrees, the machine is halted and - * requires a hard reset. This test restarts with any M104/M109/M303, but only - * if the current temperature is far enough below the target for a reliable - * test. - * - * If you get false positives for "Heating failed", increase WATCH_TEMP_PERIOD - * and/or decrease WATCH_TEMP_INCREASE. WATCH_TEMP_INCREASE should not be set - * below 2. - */ - #define WATCH_TEMP_PERIOD 20 // Seconds - #define WATCH_TEMP_INCREASE 2 // Degrees Celsius -#endif - -/** - * Thermal Protection parameters for the bed are just as above for hotends. - */ -#if ENABLED(THERMAL_PROTECTION_BED) - #define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds - #define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius - - /** - * As described above, except for the bed (M140/M190/M303). - */ - #define WATCH_BED_TEMP_PERIOD 60 // Seconds - #define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius -#endif - -#if ENABLED(PIDTEMP) - // this adds an experimental additional term to the heating power, proportional to the extrusion speed. - // if Kc is chosen well, the additional required power due to increased melting should be compensated. - //#define PID_EXTRUSION_SCALING - #if ENABLED(PID_EXTRUSION_SCALING) - #define DEFAULT_Kc (100) //heating power=Kc*(e_speed) - #define LPQ_MAX_LEN 50 - #endif -#endif - -/** - * Automatic Temperature: - * The hotend target temperature is calculated by all the buffered lines of gcode. - * The maximum buffered steps/sec of the extruder motor is called "se". - * Start autotemp mode with M109 S B F - * The target temperature is set to mintemp+factor*se[steps/sec] and is limited by - * mintemp and maxtemp. Turn this off by executing M109 without F* - * Also, if the temperature is set to a value below mintemp, it will not be changed by autotemp. - * On an Ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode - */ -#define AUTOTEMP -#if ENABLED(AUTOTEMP) - #define AUTOTEMP_OLDWEIGHT 0.98 -#endif - -// Show extra position information in M114 -//#define M114_DETAIL - -// Show Temperature ADC value -// Enable for M105 to include ADC values read from temperature sensors. -//#define SHOW_TEMP_ADC_VALUES - -/** - * High Temperature Thermistor Support - * - * Thermistors able to support high temperature tend to have a hard time getting - * good readings at room and lower temperatures. This means HEATER_X_RAW_LO_TEMP - * will probably be caught when the heating element first turns on during the - * preheating process, which will trigger a min_temp_error as a safety measure - * and force stop everything. - * To circumvent this limitation, we allow for a preheat time (during which, - * min_temp_error won't be triggered) and add a min_temp buffer to handle - * aberrant readings. - * - * If you want to enable this feature for your hotend thermistor(s) - * uncomment and set values > 0 in the constants below - */ - -// The number of consecutive low temperature errors that can occur -// before a min_temp_error is triggered. (Shouldn't be more than 10.) -//#define MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED 0 - -// The number of milliseconds a hotend will preheat before starting to check -// the temperature. This value should NOT be set to the time it takes the -// hot end to reach the target temperature, but the time it takes to reach -// the minimum temperature your thermistor can read. The lower the better/safer. -// This shouldn't need to be more than 30 seconds (30000) -//#define MILLISECONDS_PREHEAT_TIME 0 - -// @section extruder - -// Extruder runout prevention. -// If the machine is idle and the temperature over MINTEMP -// then extrude some filament every couple of SECONDS. -//#define EXTRUDER_RUNOUT_PREVENT -#if ENABLED(EXTRUDER_RUNOUT_PREVENT) - #define EXTRUDER_RUNOUT_MINTEMP 190 - #define EXTRUDER_RUNOUT_SECONDS 30 - #define EXTRUDER_RUNOUT_SPEED 1500 // mm/m - #define EXTRUDER_RUNOUT_EXTRUDE 5 // mm -#endif - -// @section temperature - -// Calibration for AD595 / AD8495 sensor to adjust temperature measurements. -// The final temperature is calculated as (measuredTemp * GAIN) + OFFSET. -#define TEMP_SENSOR_AD595_OFFSET 0.0 -#define TEMP_SENSOR_AD595_GAIN 1.0 -#define TEMP_SENSOR_AD8495_OFFSET 0.0 -#define TEMP_SENSOR_AD8495_GAIN 1.0 - -/** - * Controller Fan - * To cool down the stepper drivers and MOSFETs. - * - * The fan will turn on automatically whenever any stepper is enabled - * and turn off after a set period after all steppers are turned off. - */ -//#define USE_CONTROLLER_FAN -#if ENABLED(USE_CONTROLLER_FAN) - //#define CONTROLLER_FAN_PIN -1 // Set a custom pin for the controller fan - #define CONTROLLERFAN_SECS 60 // Duration in seconds for the fan to run after all motors are disabled - #define CONTROLLERFAN_SPEED 255 // 255 == full speed -#endif - -// When first starting the main fan, run it at full speed for the -// given number of milliseconds. This gets the fan spinning reliably -// before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu) -//#define FAN_KICKSTART_TIME 100 - -/** - * PWM Fan Scaling - * - * Define the min/max speeds for PWM fans (as set with M106). - * - * With these options the M106 0-255 value range is scaled to a subset - * to ensure that the fan has enough power to spin, or to run lower - * current fans with higher current. (e.g., 5V/12V fans with 12V/24V) - * Value 0 always turns off the fan. - * - * Define one or both of these to override the default 0-255 range. - */ -//#define FAN_MIN_PWM 50 -//#define FAN_MAX_PWM 128 - -// @section extruder - -/** - * Extruder cooling fans - * - * Extruder auto fans automatically turn on when their extruders' - * temperatures go above EXTRUDER_AUTO_FAN_TEMPERATURE. - * - * Your board's pins file specifies the recommended pins. Override those here - * or set to -1 to disable completely. - * - * Multiple extruders can be assigned to the same pin in which case - * the fan will turn on when any selected extruder is above the threshold. - */ -#define E0_AUTO_FAN_PIN -1 -#define E1_AUTO_FAN_PIN -1 -#define E2_AUTO_FAN_PIN -1 -#define E3_AUTO_FAN_PIN -1 -#define E4_AUTO_FAN_PIN -1 -#define CHAMBER_AUTO_FAN_PIN -1 -#define EXTRUDER_AUTO_FAN_TEMPERATURE 50 -#define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed - -/** - * Part-Cooling Fan Multiplexer - * - * This feature allows you to digitally multiplex the fan output. - * The multiplexer is automatically switched at tool-change. - * Set FANMUX[012]_PINs below for up to 2, 4, or 8 multiplexed fans. - */ -#define FANMUX0_PIN -1 -#define FANMUX1_PIN -1 -#define FANMUX2_PIN -1 - -/** - * M355 Case Light on-off / brightness - */ -//#define CASE_LIGHT_ENABLE -#if ENABLED(CASE_LIGHT_ENABLE) - //#define CASE_LIGHT_PIN 4 // Override the default pin if needed - #define INVERT_CASE_LIGHT false // Set true if Case Light is ON when pin is LOW - #define CASE_LIGHT_DEFAULT_ON true // Set default power-up state on - #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // Set default power-up brightness (0-255, requires PWM pin) - //#define MENU_ITEM_CASE_LIGHT // Add a Case Light option to the LCD main menu - //#define CASE_LIGHT_USE_NEOPIXEL // Use Neopixel LED as case light, requires NEOPIXEL_LED. - #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) - #define CASE_LIGHT_NEOPIXEL_COLOR { 255, 255, 255, 255 } // { Red, Green, Blue, White } - #endif -#endif - -//=========================================================================== -//============================ Mechanical Settings ========================== -//=========================================================================== - -// @section homing - -// If you want endstops to stay on (by default) even when not homing -// enable this option. Override at any time with M120, M121. -//#define ENDSTOPS_ALWAYS_ON_DEFAULT - -// @section extras - -//#define Z_LATE_ENABLE // Enable Z the last moment. Needed if your Z driver overheats. - -/** - * Dual Steppers / Dual Endstops - * - * This section will allow you to use extra E drivers to drive a second motor for X, Y, or Z axes. - * - * For example, set X_DUAL_STEPPER_DRIVERS setting to use a second motor. If the motors need to - * spin in opposite directions set INVERT_X2_VS_X_DIR. If the second motor needs its own endstop - * set X_DUAL_ENDSTOPS. This can adjust for "racking." Use X2_USE_ENDSTOP to set the endstop plug - * that should be used for the second endstop. Extra endstops will appear in the output of 'M119'. - * - * Use X_DUAL_ENDSTOP_ADJUSTMENT to adjust for mechanical imperfection. After homing both motors - * this offset is applied to the X2 motor. To find the offset home the X axis, and measure the error - * in X2. Dual endstop offsets can be set at runtime with 'M666 X Y Z'. - */ - -//#define X_DUAL_STEPPER_DRIVERS -#if ENABLED(X_DUAL_STEPPER_DRIVERS) - #define INVERT_X2_VS_X_DIR true // Set 'true' if X motors should rotate in opposite directions - //#define X_DUAL_ENDSTOPS - #if ENABLED(X_DUAL_ENDSTOPS) - #define X2_USE_ENDSTOP _XMAX_ - #define X_DUAL_ENDSTOPS_ADJUSTMENT 0 - #endif -#endif - -//#define Y_DUAL_STEPPER_DRIVERS -#if ENABLED(Y_DUAL_STEPPER_DRIVERS) - #define INVERT_Y2_VS_Y_DIR true // Set 'true' if Y motors should rotate in opposite directions - //#define Y_DUAL_ENDSTOPS - #if ENABLED(Y_DUAL_ENDSTOPS) - #define Y2_USE_ENDSTOP _YMAX_ - #define Y_DUAL_ENDSTOPS_ADJUSTMENT 0 - #endif -#endif - -//#define Z_DUAL_STEPPER_DRIVERS -#if ENABLED(Z_DUAL_STEPPER_DRIVERS) - //#define Z_DUAL_ENDSTOPS - #if ENABLED(Z_DUAL_ENDSTOPS) - #define Z2_USE_ENDSTOP _XMAX_ - #define Z_DUAL_ENDSTOPS_ADJUSTMENT 0 - #endif -#endif - -// Enable this for dual x-carriage printers. -// A dual x-carriage design has the advantage that the inactive extruder can be parked which -// prevents hot-end ooze contaminating the print. It also reduces the weight of each x-carriage -// allowing faster printing speeds. Connect your X2 stepper to the first unused E plug. -//#define DUAL_X_CARRIAGE -#if ENABLED(DUAL_X_CARRIAGE) - // Configuration for second X-carriage - // Note: the first x-carriage is defined as the x-carriage which homes to the minimum endstop; - // the second x-carriage always homes to the maximum endstop. - #define X1_MIN_POS X_MIN_POS // set minimum to ensure first x-carriage doesn't hit the parked second X-carriage - #define X1_MAX_POS X_BED_SIZE // set maximum to ensure first x-carriage doesn't hit the parked second X-carriage - #define X2_MIN_POS 80 // set minimum to ensure second x-carriage doesn't hit the parked first X-carriage - #define X2_MAX_POS 353 // set maximum to the distance between toolheads when both heads are homed - #define X2_HOME_DIR 1 // the second X-carriage always homes to the maximum endstop position - #define X2_HOME_POS X2_MAX_POS // default home position is the maximum carriage position - // However: In this mode the HOTEND_OFFSET_X value for the second extruder provides a software - // override for X2_HOME_POS. This also allow recalibration of the distance between the two endstops - // without modifying the firmware (through the "M218 T1 X???" command). - // Remember: you should set the second extruder x-offset to 0 in your slicer. - - // There are a few selectable movement modes for dual x-carriages using M605 S - // Mode 0 (DXC_FULL_CONTROL_MODE): Full control. The slicer has full control over both x-carriages and can achieve optimal travel results - // as long as it supports dual x-carriages. (M605 S0) - // Mode 1 (DXC_AUTO_PARK_MODE) : Auto-park mode. The firmware will automatically park and unpark the x-carriages on tool changes so - // that additional slicer support is not required. (M605 S1) - // Mode 2 (DXC_DUPLICATION_MODE) : Duplication mode. The firmware will transparently make the second x-carriage and extruder copy all - // actions of the first x-carriage. This allows the printer to print 2 arbitrary items at - // once. (2nd extruder x offset and temp offset are set using: M605 S2 [Xnnn] [Rmmm]) - - // This is the default power-up mode which can be later using M605. - #define DEFAULT_DUAL_X_CARRIAGE_MODE DXC_FULL_CONTROL_MODE - - // Default settings in "Auto-park Mode" - #define TOOLCHANGE_PARK_ZLIFT 0.2 // the distance to raise Z axis when parking an extruder - #define TOOLCHANGE_UNPARK_ZLIFT 1 // the distance to raise Z axis when unparking an extruder - - // Default x offset in duplication mode (typically set to half print bed width) - #define DEFAULT_DUPLICATION_X_OFFSET 100 - -#endif // DUAL_X_CARRIAGE - -// Activate a solenoid on the active extruder with M380. Disable all with M381. -// Define SOL0_PIN, SOL1_PIN, etc., for each extruder that has a solenoid. -//#define EXT_SOLENOID - -// @section homing - -// Homing hits each endstop, retracts by these distances, then does a slower bump. -#define X_HOME_BUMP_MM 5 -#define Y_HOME_BUMP_MM 5 -#define Z_HOME_BUMP_MM 2 -#define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate) -//#define QUICK_HOME // If homing includes X and Y, do a diagonal move initially - -// When G28 is called, this option will make Y home before X -//#define HOME_Y_BEFORE_X - -// Enable this if X or Y can't home without homing the other axis first. -//#define CODEPENDENT_XY_HOMING - -// @section machine - -#define AXIS_RELATIVE_MODES {false, false, false, false} - -// Allow duplication mode with a basic dual-nozzle extruder -//#define DUAL_NOZZLE_DUPLICATION_MODE - -// By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step. -#define INVERT_X_STEP_PIN false -#define INVERT_Y_STEP_PIN false -#define INVERT_Z_STEP_PIN false -#define INVERT_E_STEP_PIN false - -// Default stepper release if idle. Set to 0 to deactivate. -// Steppers will shut down DEFAULT_STEPPER_DEACTIVE_TIME seconds after the last move when DISABLE_INACTIVE_? is true. -// Time can be set by M18 and M84. -#define DEFAULT_STEPPER_DEACTIVE_TIME 120 -#define DISABLE_INACTIVE_X true -#define DISABLE_INACTIVE_Y true -#define DISABLE_INACTIVE_Z true // set to false if the nozzle will fall down on your printed part when print has finished. -#define DISABLE_INACTIVE_E true - -#define DEFAULT_MINIMUMFEEDRATE 0.0 // minimum feedrate -#define DEFAULT_MINTRAVELFEEDRATE 0.0 - -//#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated - -// @section lcd - -#if ENABLED(ULTIPANEL) - #define MANUAL_FEEDRATE {50*60, 50*60, 4*60, 60} // Feedrates for manual moves along X, Y, Z, E from panel - #define ULTIPANEL_FEEDMULTIPLY // Comment to disable setting feedrate multiplier via encoder -#endif - -// @section extras - -// minimum time in microseconds that a movement needs to take if the buffer is emptied. -#define DEFAULT_MINSEGMENTTIME 20000 - -// If defined the movements slow down when the look ahead buffer is only half full -#define SLOWDOWN - -// Frequency limit -// See nophead's blog for more info -// Not working O -//#define XY_FREQUENCY_LIMIT 15 - -// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end -// of the buffer and all stops. This should not be much greater than zero and should only be changed -// if unwanted behavior is observed on a user's machine when running at very slow speeds. -#define MINIMUM_PLANNER_SPEED 0.05 // (mm/sec) - -// -// Use Junction Deviation instead of traditional Jerk Limiting -// -//#define JUNCTION_DEVIATION -#if ENABLED(JUNCTION_DEVIATION) - #define JUNCTION_DEVIATION_MM 0.02 // (mm) Distance from real junction edge -#endif - -/** - * Adaptive Step Smoothing increases the resolution of multi-axis moves, particularly at step frequencies - * below 1kHz (for AVR) or 10kHz (for ARM), where aliasing between axes in multi-axis moves causes audible - * vibration and surface artifacts. The algorithm adapts to provide the best possible step smoothing at the - * lowest stepping frequencies. - */ -//#define ADAPTIVE_STEP_SMOOTHING - -// Microstep setting (Only functional when stepper driver microstep pins are connected to MCU. -#define MICROSTEP_MODES { 16, 16, 16, 16, 16 } // [1,2,4,8,16] - -/** - * @section stepper motor current - * - * Some boards have a means of setting the stepper motor current via firmware. - * - * The power on motor currents are set by: - * PWM_MOTOR_CURRENT - used by MINIRAMBO & ULTIMAIN_2 - * known compatible chips: A4982 - * DIGIPOT_MOTOR_CURRENT - used by BQ_ZUM_MEGA_3D, RAMBO & SCOOVO_X9H - * known compatible chips: AD5206 - * DAC_MOTOR_CURRENT_DEFAULT - used by PRINTRBOARD_REVF & RIGIDBOARD_V2 - * known compatible chips: MCP4728 - * DIGIPOT_I2C_MOTOR_CURRENTS - used by 5DPRINT, AZTEEG_X3_PRO, MIGHTYBOARD_REVE - * known compatible chips: MCP4451, MCP4018 - * - * Motor currents can also be set by M907 - M910 and by the LCD. - * M907 - applies to all. - * M908 - BQ_ZUM_MEGA_3D, RAMBO, PRINTRBOARD_REVF, RIGIDBOARD_V2 & SCOOVO_X9H - * M909, M910 & LCD - only PRINTRBOARD_REVF & RIGIDBOARD_V2 - */ -//#define PWM_MOTOR_CURRENT { 1300, 1300, 1250 } // Values in milliamps -//#define DIGIPOT_MOTOR_CURRENT { 135,135,135,135,135 } // Values 0-255 (RAMBO 135 = ~0.75A, 185 = ~1A) -//#define DAC_MOTOR_CURRENT_DEFAULT { 70, 80, 90, 80 } // Default drive percent - X, Y, Z, E axis - -// Use an I2C based DIGIPOT (e.g., Azteeg X3 Pro) -//#define DIGIPOT_I2C -#if ENABLED(DIGIPOT_I2C) && !defined(DIGIPOT_I2C_ADDRESS_A) - /** - * Common slave addresses: - * - * A (A shifted) B (B shifted) IC - * Smoothie 0x2C (0x58) 0x2D (0x5A) MCP4451 - * AZTEEG_X3_PRO 0x2C (0x58) 0x2E (0x5C) MCP4451 - * MIGHTYBOARD_REVE 0x2F (0x5E) MCP4018 - */ - #define DIGIPOT_I2C_ADDRESS_A 0x2C // unshifted slave address for first DIGIPOT - #define DIGIPOT_I2C_ADDRESS_B 0x2D // unshifted slave address for second DIGIPOT -#endif - -//#define DIGIPOT_MCP4018 // Requires library from https://github.com/stawel/SlowSoftI2CMaster -#define DIGIPOT_I2C_NUM_CHANNELS 8 // 5DPRINT: 4 AZTEEG_X3_PRO: 8 MKS SBASE: 5 -// Actual motor currents in Amps. The number of entries must match DIGIPOT_I2C_NUM_CHANNELS. -// These correspond to the physical drivers, so be mindful if the order is changed. -#define DIGIPOT_I2C_MOTOR_CURRENTS { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 } // AZTEEG_X3_PRO - -//=========================================================================== -//=============================Additional Features=========================== -//=========================================================================== - -#define ENCODER_RATE_MULTIPLIER // If defined, certain menu edit operations automatically multiply the steps when the encoder is moved quickly -#define ENCODER_10X_STEPS_PER_SEC 75 // If the encoder steps per sec exceeds this value, multiply steps moved x10 to quickly advance the value -#define ENCODER_100X_STEPS_PER_SEC 160 // If the encoder steps per sec exceeds this value, multiply steps moved x100 to really quickly advance the value - -//#define CHDK 4 //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/ -#define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again - -// @section lcd - -// Include a page of printer information in the LCD Main Menu -//#define LCD_INFO_MENU - -// Scroll a longer status message into view -//#define STATUS_MESSAGE_SCROLLING - -// On the Info Screen, display XY with one decimal place when possible -//#define LCD_DECIMAL_SMALL_XY - -// The timeout (in ms) to return to the status screen from sub-menus -//#define LCD_TIMEOUT_TO_STATUS 15000 - -// Add an 'M73' G-code to set the current percentage -//#define LCD_SET_PROGRESS_MANUALLY - -#if ENABLED(SDSUPPORT) || ENABLED(LCD_SET_PROGRESS_MANUALLY) - //#define LCD_PROGRESS_BAR // Show a progress bar on HD44780 LCDs for SD printing - #if ENABLED(LCD_PROGRESS_BAR) - #define PROGRESS_BAR_BAR_TIME 2000 // (ms) Amount of time to show the bar - #define PROGRESS_BAR_MSG_TIME 3000 // (ms) Amount of time to show the status message - #define PROGRESS_MSG_EXPIRE 0 // (ms) Amount of time to retain the status message (0=forever) - //#define PROGRESS_MSG_ONCE // Show the message for MSG_TIME then clear it - //#define LCD_PROGRESS_BAR_TEST // Add a menu item to test the progress bar - #endif -#endif // SDSUPPORT || LCD_SET_PROGRESS_MANUALLY - -/** - * LED Control Menu - * Enable this feature to add LED Control to the LCD menu - */ -//#define LED_CONTROL_MENU -#if ENABLED(LED_CONTROL_MENU) - #define LED_COLOR_PRESETS // Enable the Preset Color menu option - #if ENABLED(LED_COLOR_PRESETS) - #define LED_USER_PRESET_RED 255 // User defined RED value - #define LED_USER_PRESET_GREEN 128 // User defined GREEN value - #define LED_USER_PRESET_BLUE 0 // User defined BLUE value - #define LED_USER_PRESET_WHITE 255 // User defined WHITE value - #define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity - //#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup - #endif -#endif // LED_CONTROL_MENU - -#if ENABLED(SDSUPPORT) - - // Some RAMPS and other boards don't detect when an SD card is inserted. You can work - // around this by connecting a push button or single throw switch to the pin defined - // as SD_DETECT_PIN in your board's pins definitions. - // This setting should be disabled unless you are using a push button, pulling the pin to ground. - // Note: This is always disabled for ULTIPANEL (except ELB_FULL_GRAPHIC_CONTROLLER). - #define SD_DETECT_INVERTED - - #define SD_FINISHED_STEPPERRELEASE true // Disable steppers when SD Print is finished - #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. - - // Reverse SD sort to show "more recent" files first, according to the card's FAT. - // Since the FAT gets out of order with usage, SDCARD_SORT_ALPHA is recommended. - #define SDCARD_RATHERRECENTFIRST - - // Add an option in the menu to run all auto#.g files - //#define MENU_ADDAUTOSTART - - /** - * Continue after Power-Loss (Creality3D) - * - * Store the current state to the SD Card at the start of each layer - * during SD printing. If the recovery file is found at boot time, present - * an option on the LCD screen to continue the print from the last-known - * point in the file. - */ - //#define POWER_LOSS_RECOVERY - #if ENABLED(POWER_LOSS_RECOVERY) - //#define POWER_LOSS_PIN 44 // Pin to detect power loss - //#define POWER_LOSS_STATE HIGH // State of pin indicating power loss - #endif - - /** - * Sort SD file listings in alphabetical order. - * - * With this option enabled, items on SD cards will be sorted - * by name for easier navigation. - * - * By default... - * - * - Use the slowest -but safest- method for sorting. - * - Folders are sorted to the top. - * - The sort key is statically allocated. - * - No added G-code (M34) support. - * - 40 item sorting limit. (Items after the first 40 are unsorted.) - * - * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the - * compiler to calculate the worst-case usage and throw an error if the SRAM - * limit is exceeded. - * - * - SDSORT_USES_RAM provides faster sorting via a static directory buffer. - * - SDSORT_USES_STACK does the same, but uses a local stack-based buffer. - * - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!) - * - SDSORT_DYNAMIC_RAM only uses RAM when the SD menu is visible. (Use with caution!) - */ - //#define SDCARD_SORT_ALPHA - - // SD Card Sorting options - #if ENABLED(SDCARD_SORT_ALPHA) - #define SDSORT_LIMIT 40 // Maximum number of sorted items (10-256). Costs 27 bytes each. - #define FOLDER_SORTING -1 // -1=above 0=none 1=below - #define SDSORT_GCODE false // Allow turning sorting on/off with LCD and M34 g-code. - #define SDSORT_USES_RAM false // Pre-allocate a static array for faster pre-sorting. - #define SDSORT_USES_STACK false // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.) - #define SDSORT_CACHE_NAMES false // Keep sorted items in RAM longer for speedy performance. Most expensive option. - #define SDSORT_DYNAMIC_RAM false // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use! - #define SDSORT_CACHE_VFATS 2 // Maximum number of 13-byte VFAT entries to use for sorting. - // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM. - #endif - - // This allows hosts to request long names for files and folders with M33 - //#define LONG_FILENAME_HOST_SUPPORT - - // Enable this option to scroll long filenames in the SD card menu - //#define SCROLL_LONG_FILENAMES - - /** - * This option allows you to abort SD printing when any endstop is triggered. - * This feature must be enabled with "M540 S1" or from the LCD menu. - * To have any effect, endstops must be enabled during SD printing. - */ - //#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED - - /** - * This option makes it easier to print the same SD Card file again. - * On print completion the LCD Menu will open with the file selected. - * You can just click to start the print, or navigate elsewhere. - */ - //#define SD_REPRINT_LAST_SELECTED_FILE - - /** - * Auto-report SdCard status with M27 S - */ - //#define AUTO_REPORT_SD_STATUS - -#endif // SDSUPPORT - -/** - * Additional options for Graphical Displays - * - * Use the optimizations here to improve printing performance, - * which can be adversely affected by graphical display drawing, - * especially when doing several short moves, and when printing - * on DELTA and SCARA machines. - * - * Some of these options may result in the display lagging behind - * controller events, as there is a trade-off between reliable - * printing performance versus fast display updates. - */ -#if ENABLED(DOGLCD) - // Show SD percentage next to the progress bar - //#define DOGM_SD_PERCENT - - // Enable to save many cycles by drawing a hollow frame on the Info Screen - #define XYZ_HOLLOW_FRAME - - // Enable to save many cycles by drawing a hollow frame on Menu Screens - #define MENU_HOLLOW_FRAME - - // A bigger font is available for edit items. Costs 3120 bytes of PROGMEM. - // Western only. Not available for Cyrillic, Kana, Turkish, Greek, or Chinese. - //#define USE_BIG_EDIT_FONT - - // A smaller font may be used on the Info Screen. Costs 2300 bytes of PROGMEM. - // Western only. Not available for Cyrillic, Kana, Turkish, Greek, or Chinese. - //#define USE_SMALL_INFOFONT - - // Enable this option and reduce the value to optimize screen updates. - // The normal delay is 10µs. Use the lowest value that still gives a reliable display. - //#define DOGM_SPI_DELAY_US 5 - - // Swap the CW/CCW indicators in the graphics overlay - //#define OVERLAY_GFX_REVERSE - - #if ENABLED(U8GLIB_ST7920) - /** - * ST7920-based LCDs can emulate a 16 x 4 character display using - * the ST7920 character-generator for very fast screen updates. - * Enable LIGHTWEIGHT_UI to use this special display mode. - * - * Since LIGHTWEIGHT_UI has limited space, the position and status - * message occupy the same line. Set STATUS_EXPIRE_SECONDS to the - * length of time to display the status message before clearing. - * - * Set STATUS_EXPIRE_SECONDS to zero to never clear the status. - * This will prevent position updates from being displayed. - */ - //#define LIGHTWEIGHT_UI - #if ENABLED(LIGHTWEIGHT_UI) - #define STATUS_EXPIRE_SECONDS 20 - #endif - #endif - -#endif // DOGLCD - -// @section safety - -// The hardware watchdog should reset the microcontroller disabling all outputs, -// in case the firmware gets stuck and doesn't do temperature regulation. -#define USE_WATCHDOG - -#if ENABLED(USE_WATCHDOG) - // If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on. - // The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset. - // However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled. - //#define WATCHDOG_RESET_MANUAL -#endif - -// @section lcd - -/** - * Babystepping enables movement of the axes by tiny increments without changing - * the current position values. This feature is used primarily to adjust the Z - * axis in the first layer of a print in real-time. - * - * Warning: Does not respect endstops! - */ -//#define BABYSTEPPING -#if ENABLED(BABYSTEPPING) - //#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA! - #define BABYSTEP_INVERT_Z false // Change if Z babysteps should go the other way - #define BABYSTEP_MULTIPLICATOR 1 // Babysteps are very small. Increase for faster motion. - //#define BABYSTEP_ZPROBE_OFFSET // Enable to combine M851 and Babystepping - //#define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping. - #define DOUBLECLICK_MAX_INTERVAL 1250 // Maximum interval between clicks, in milliseconds. - // Note: Extra time may be added to mitigate controller latency. - //#define BABYSTEP_ZPROBE_GFX_OVERLAY // Enable graphical overlay on Z-offset editor -#endif - -// @section extruder - -/** - * Linear Pressure Control v1.5 - * - * Assumption: advance [steps] = k * (delta velocity [steps/s]) - * K=0 means advance disabled. - * - * NOTE: K values for LIN_ADVANCE 1.5 differ from earlier versions! - * - * Set K around 0.22 for 3mm PLA Direct Drive with ~6.5cm between the drive gear and heatbreak. - * Larger K values will be needed for flexible filament and greater distances. - * If this algorithm produces a higher speed offset than the extruder can handle (compared to E jerk) - * print acceleration will be reduced during the affected moves to keep within the limit. - * - * See http://marlinfw.org/docs/features/lin_advance.html for full instructions. - * Mention @Sebastianv650 on GitHub to alert the author of any issues. - */ -//#define LIN_ADVANCE -#if ENABLED(LIN_ADVANCE) - #define LIN_ADVANCE_K 0.22 // Unit: mm compression per 1mm/s extruder speed - //#define LA_DEBUG // If enabled, this will generate debug information output over USB. -#endif - -// @section leveling - -#if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL) - // Override the mesh area if the automatic (max) area is too large - //#define MESH_MIN_X MESH_INSET - //#define MESH_MIN_Y MESH_INSET - //#define MESH_MAX_X X_BED_SIZE - (MESH_INSET) - //#define MESH_MAX_Y Y_BED_SIZE - (MESH_INSET) -#endif - -/** - * Repeatedly attempt G29 leveling until it succeeds. - * Stop after G29_MAX_RETRIES attempts. - */ -//#define G29_RETRY_AND_RECOVER -#if ENABLED(G29_RETRY_AND_RECOVER) - #define G29_MAX_RETRIES 3 - #define G29_HALT_ON_FAILURE - /** - * Specify the GCODE commands that will be executed when leveling succeeds, - * between attempts, and after the maximum number of retries have been tried. - */ - #define G29_SUCCESS_COMMANDS "M117 Bed leveling done." - #define G29_RECOVER_COMMANDS "M117 Probe failed. Rewiping.\nG28\nG12 P0 S12 T0" - #define G29_FAILURE_COMMANDS "M117 Bed leveling failed.\nG0 Z10\nM300 P25 S880\nM300 P50 S0\nM300 P25 S880\nM300 P50 S0\nM300 P25 S880\nM300 P50 S0\nG4 S1" - /** - * Specify an action command to send to the host on a recovery attempt or failure. - * Will be sent in the form '//action:ACTION_ON_G29_FAILURE', e.g. '//action:probe_failed'. - * The host must be configured to handle the action command. - */ - #define G29_ACTION_ON_RECOVER "probe_rewipe" - #define G29_ACTION_ON_FAILURE "probe_failed" -#endif - -// @section extras - -// -// G2/G3 Arc Support -// -#define ARC_SUPPORT // Disable this feature to save ~3226 bytes -#if ENABLED(ARC_SUPPORT) - #define MM_PER_ARC_SEGMENT 1 // Length of each arc segment - #define N_ARC_CORRECTION 25 // Number of intertpolated segments between corrections - //#define ARC_P_CIRCLES // Enable the 'P' parameter to specify complete circles - //#define CNC_WORKSPACE_PLANES // Allow G2/G3 to operate in XY, ZX, or YZ planes -#endif - -// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes. -//#define BEZIER_CURVE_SUPPORT - -// G38.2 and G38.3 Probe Target -// Set MULTIPLE_PROBING if you want G38 to double touch -//#define G38_PROBE_TARGET -#if ENABLED(G38_PROBE_TARGET) - #define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move) -#endif - -// Moves (or segments) with fewer steps than this will be joined with the next move -#define MIN_STEPS_PER_SEGMENT 6 - -/** - * Minimum delay after setting the stepper DIR (in ns) - * 0 : No delay (Expect at least 10µS since one Stepper ISR must transpire) - * 20 : Minimum for TMC2xxx drivers - * 200 : Minimum for A4988 drivers - * 500 : Minimum for LV8729 drivers (guess, no info in datasheet) - * 650 : Minimum for DRV8825 drivers - * 1500 : Minimum for TB6600 drivers (guess, no info in datasheet) - * 15000 : Minimum for TB6560 drivers (guess, no info in datasheet) - * - * Override the default value based on the driver type set in Configuration.h. - */ -//#define MINIMUM_STEPPER_DIR_DELAY 650 - -/** - * Minimum stepper driver pulse width (in µs) - * 0 : Smallest possible width the MCU can produce, compatible with TMC2xxx drivers - * 1 : Minimum for A4988 stepper drivers - * 1 : Minimum for LV8729 stepper drivers - * 2 : Minimum for DRV8825 stepper drivers - * 3 : Minimum for TB6600 stepper drivers - * 30 : Minimum for TB6560 stepper drivers - * - * Override the default value based on the driver type set in Configuration.h. - */ -//#define MINIMUM_STEPPER_PULSE 2 - -/** - * Maximum stepping rate (in Hz) the stepper driver allows - * If undefined, defaults to 1MHz / (2 * MINIMUM_STEPPER_PULSE) - * 500000 : Maximum for A4988 stepper driver - * 400000 : Maximum for TMC2xxx stepper drivers - * 250000 : Maximum for DRV8825 stepper driver - * 150000 : Maximum for TB6600 stepper driver - * 130000 : Maximum for LV8729 stepper driver - * 15000 : Maximum for TB6560 stepper driver - * - * Override the default value based on the driver type set in Configuration.h. - */ -//#define MAXIMUM_STEPPER_RATE 250000 - -// @section temperature - -// Control heater 0 and heater 1 in parallel. -//#define HEATERS_PARALLEL - -//=========================================================================== -//================================= Buffers ================================= -//=========================================================================== - -// @section hidden - -// The number of linear motions that can be in the plan at any give time. -// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2 (e.g. 8, 16, 32) because shifts and ors are used to do the ring-buffering. -#if ENABLED(SDSUPPORT) - #define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller -#else - #define BLOCK_BUFFER_SIZE 16 // maximize block buffer -#endif - -// @section serial - -// The ASCII buffer for serial input -#define MAX_CMD_SIZE 96 -#define BUFSIZE 4 - -// Transmission to Host Buffer Size -// To save 386 bytes of PROGMEM (and TX_BUFFER_SIZE+3 bytes of RAM) set to 0. -// To buffer a simple "ok" you need 4 bytes. -// For ADVANCED_OK (M105) you need 32 bytes. -// For debug-echo: 128 bytes for the optimal speed. -// Other output doesn't need to be that speedy. -// :[0, 2, 4, 8, 16, 32, 64, 128, 256] -#define TX_BUFFER_SIZE 0 - -// Host Receive Buffer Size -// Without XON/XOFF flow control (see SERIAL_XON_XOFF below) 32 bytes should be enough. -// To use flow control, set this buffer size to at least 1024 bytes. -// :[0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048] -//#define RX_BUFFER_SIZE 1024 - -#if RX_BUFFER_SIZE >= 1024 - // Enable to have the controller send XON/XOFF control characters to - // the host to signal the RX buffer is becoming full. - //#define SERIAL_XON_XOFF -#endif - -#if ENABLED(SDSUPPORT) - // Enable this option to collect and display the maximum - // RX queue usage after transferring a file to SD. - //#define SERIAL_STATS_MAX_RX_QUEUED - - // Enable this option to collect and display the number - // of dropped bytes after a file transfer to SD. - //#define SERIAL_STATS_DROPPED_RX -#endif - -// Enable an emergency-command parser to intercept certain commands as they -// enter the serial receive buffer, so they cannot be blocked. -// Currently handles M108, M112, M410 -// Does not work on boards using AT90USB (USBCON) processors! -//#define EMERGENCY_PARSER - -// Bad Serial-connections can miss a received command by sending an 'ok' -// Therefore some clients abort after 30 seconds in a timeout. -// Some other clients start sending commands while receiving a 'wait'. -// This "wait" is only sent when the buffer is empty. 1 second is a good value here. -//#define NO_TIMEOUTS 1000 // Milliseconds - -// Some clients will have this feature soon. This could make the NO_TIMEOUTS unnecessary. -//#define ADVANCED_OK - -// @section extras - -/** - * Firmware-based and LCD-controlled retract - * - * Add G10 / G11 commands for automatic firmware-based retract / recover. - * Use M207 and M208 to define parameters for retract / recover. - * - * Use M209 to enable or disable auto-retract. - * With auto-retract enabled, all G1 E moves within the set range - * will be converted to firmware-based retract/recover moves. - * - * Be sure to turn off auto-retract during filament change. - * - * Note that M207 / M208 / M209 settings are saved to EEPROM. - * - */ -//#define FWRETRACT // ONLY PARTIALLY TESTED -#if ENABLED(FWRETRACT) - #define MIN_AUTORETRACT 0.1 // When auto-retract is on, convert E moves of this length and over - #define MAX_AUTORETRACT 10.0 // Upper limit for auto-retract conversion - #define RETRACT_LENGTH 3 // Default retract length (positive mm) - #define RETRACT_LENGTH_SWAP 13 // Default swap retract length (positive mm), for extruder change - #define RETRACT_FEEDRATE 45 // Default feedrate for retracting (mm/s) - #define RETRACT_ZLIFT 0 // Default retract Z-lift - #define RETRACT_RECOVER_LENGTH 0 // Default additional recover length (mm, added to retract length when recovering) - #define RETRACT_RECOVER_LENGTH_SWAP 0 // Default additional swap recover length (mm, added to retract length when recovering from extruder change) - #define RETRACT_RECOVER_FEEDRATE 8 // Default feedrate for recovering from retraction (mm/s) - #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // Default feedrate for recovering from swap retraction (mm/s) -#endif - -/** - * Extra Fan Speed - * Adds a secondary fan speed for each print-cooling fan. - * 'M106 P T3-255' : Set a secondary speed for - * 'M106 P T2' : Use the set secondary speed - * 'M106 P T1' : Restore the previous fan speed - */ -//#define EXTRA_FAN_SPEED - -/** - * Advanced Pause - * Experimental feature for filament change support and for parking the nozzle when paused. - * Adds the GCode M600 for initiating filament change. - * If PARK_HEAD_ON_PAUSE enabled, adds the GCode M125 to pause printing and park the nozzle. - * - * Requires an LCD display. - * Requires NOZZLE_PARK_FEATURE. - * This feature is required for the default FILAMENT_RUNOUT_SCRIPT. - */ -//#define ADVANCED_PAUSE_FEATURE -#if ENABLED(ADVANCED_PAUSE_FEATURE) - #define PAUSE_PARK_RETRACT_FEEDRATE 60 // (mm/s) Initial retract feedrate. - #define PAUSE_PARK_RETRACT_LENGTH 2 // (mm) Initial retract. - // This short retract is done immediately, before parking the nozzle. - #define FILAMENT_CHANGE_UNLOAD_FEEDRATE 10 // (mm/s) Unload filament feedrate. This can be pretty fast. - #define FILAMENT_CHANGE_UNLOAD_ACCEL 25 // (mm/s^2) Lower acceleration may allow a faster feedrate. - #define FILAMENT_CHANGE_UNLOAD_LENGTH 100 // (mm) The length of filament for a complete unload. - // For Bowden, the full length of the tube and nozzle. - // For direct drive, the full length of the nozzle. - // Set to 0 for manual unloading. - #define FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE 6 // (mm/s) Slow move when starting load. - #define FILAMENT_CHANGE_SLOW_LOAD_LENGTH 0 // (mm) Slow length, to allow time to insert material. - // 0 to disable start loading and skip to fast load only - #define FILAMENT_CHANGE_FAST_LOAD_FEEDRATE 6 // (mm/s) Load filament feedrate. This can be pretty fast. - #define FILAMENT_CHANGE_FAST_LOAD_ACCEL 25 // (mm/s^2) Lower acceleration may allow a faster feedrate. - #define FILAMENT_CHANGE_FAST_LOAD_LENGTH 0 // (mm) Load length of filament, from extruder gear to nozzle. - // For Bowden, the full length of the tube and nozzle. - // For direct drive, the full length of the nozzle. - //#define ADVANCED_PAUSE_CONTINUOUS_PURGE // Purge continuously up to the purge length until interrupted. - #define ADVANCED_PAUSE_PURGE_FEEDRATE 3 // (mm/s) Extrude feedrate (after loading). Should be slower than load feedrate. - #define ADVANCED_PAUSE_PURGE_LENGTH 50 // (mm) Length to extrude after loading. - // Set to 0 for manual extrusion. - // Filament can be extruded repeatedly from the Filament Change menu - // until extrusion is consistent, and to purge old filament. - - // Filament Unload does a Retract, Delay, and Purge first: - #define FILAMENT_UNLOAD_RETRACT_LENGTH 13 // (mm) Unload initial retract length. - #define FILAMENT_UNLOAD_DELAY 5000 // (ms) Delay for the filament to cool after retract. - #define FILAMENT_UNLOAD_PURGE_LENGTH 8 // (mm) An unretract is done, then this length is purged. - - #define PAUSE_PARK_NOZZLE_TIMEOUT 45 // (seconds) Time limit before the nozzle is turned off for safety. - #define FILAMENT_CHANGE_ALERT_BEEPS 10 // Number of alert beeps to play when a response is needed. - #define PAUSE_PARK_NO_STEPPER_TIMEOUT // Enable for XYZ steppers to stay powered on during filament change. - - //#define PARK_HEAD_ON_PAUSE // Park the nozzle during pause and filament change. - //#define HOME_BEFORE_FILAMENT_CHANGE // Ensure homing has been completed prior to parking for filament change - - //#define FILAMENT_LOAD_UNLOAD_GCODES // Add M701/M702 Load/Unload G-codes, plus Load/Unload in the LCD Prepare menu. - //#define FILAMENT_UNLOAD_ALL_EXTRUDERS // Allow M702 to unload all extruders above a minimum target temp (as set by M302) -#endif - -// @section tmc - -/** - * TMC26X Stepper Driver options - * - * The TMC26XStepper library is required for this stepper driver. - * https://github.com/trinamic/TMC26XStepper - */ -#if HAS_DRIVER(TMC26X) - - #define X_MAX_CURRENT 1000 // in mA - #define X_SENSE_RESISTOR 91 // in mOhms - #define X_MICROSTEPS 16 // number of microsteps - - #define X2_MAX_CURRENT 1000 - #define X2_SENSE_RESISTOR 91 - #define X2_MICROSTEPS 16 - - #define Y_MAX_CURRENT 1000 - #define Y_SENSE_RESISTOR 91 - #define Y_MICROSTEPS 16 - - #define Y2_MAX_CURRENT 1000 - #define Y2_SENSE_RESISTOR 91 - #define Y2_MICROSTEPS 16 - - #define Z_MAX_CURRENT 1000 - #define Z_SENSE_RESISTOR 91 - #define Z_MICROSTEPS 16 - - #define Z2_MAX_CURRENT 1000 - #define Z2_SENSE_RESISTOR 91 - #define Z2_MICROSTEPS 16 - - #define E0_MAX_CURRENT 1000 - #define E0_SENSE_RESISTOR 91 - #define E0_MICROSTEPS 16 - - #define E1_MAX_CURRENT 1000 - #define E1_SENSE_RESISTOR 91 - #define E1_MICROSTEPS 16 - - #define E2_MAX_CURRENT 1000 - #define E2_SENSE_RESISTOR 91 - #define E2_MICROSTEPS 16 - - #define E3_MAX_CURRENT 1000 - #define E3_SENSE_RESISTOR 91 - #define E3_MICROSTEPS 16 - - #define E4_MAX_CURRENT 1000 - #define E4_SENSE_RESISTOR 91 - #define E4_MICROSTEPS 16 - -#endif // TMC26X - -// @section tmc_smart - -/** - * To use TMC2130 stepper drivers in SPI mode connect your SPI pins to - * the hardware SPI interface on your board and define the required CS pins - * in your `pins_MYBOARD.h` file. (e.g., RAMPS 1.4 uses AUX3 pins `X_CS_PIN 53`, `Y_CS_PIN 49`, etc.). - * You may also use software SPI if you wish to use general purpose IO pins. - * - * The TMC2130Stepper library is required for this stepper driver. - * https://github.com/teemuatlut/TMC2130Stepper - * - * To use TMC2208 stepper UART-configurable stepper drivers - * connect #_SERIAL_TX_PIN to the driver side PDN_UART pin with a 1K resistor. - * To use the reading capabilities, also connect #_SERIAL_RX_PIN - * to PDN_UART without a resistor. - * The drivers can also be used with hardware serial. - * - * The TMC2208Stepper library is required for this stepper driver. - * https://github.com/teemuatlut/TMC2208Stepper - */ -#if HAS_TRINAMIC - - #define R_SENSE 0.11 // R_sense resistor for SilentStepStick2130 - #define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current - #define INTERPOLATE true // Interpolate X/Y/Z_MICROSTEPS to 256 - - #define X_CURRENT 800 // rms current in mA. Multiply by 1.41 for peak current. - #define X_MICROSTEPS 16 // 0..256 - - #define Y_CURRENT 800 - #define Y_MICROSTEPS 16 - - #define Z_CURRENT 800 - #define Z_MICROSTEPS 16 - - #define X2_CURRENT 800 - #define X2_MICROSTEPS 16 - - #define Y2_CURRENT 800 - #define Y2_MICROSTEPS 16 - - #define Z2_CURRENT 800 - #define Z2_MICROSTEPS 16 - - #define E0_CURRENT 800 - #define E0_MICROSTEPS 16 - - #define E1_CURRENT 800 - #define E1_MICROSTEPS 16 - - #define E2_CURRENT 800 - #define E2_MICROSTEPS 16 - - #define E3_CURRENT 800 - #define E3_MICROSTEPS 16 - - #define E4_CURRENT 800 - #define E4_MICROSTEPS 16 - - /** - * Use software SPI for TMC2130. - * The default SW SPI pins are defined the respective pins files, - * but you can override or define them here. - */ - //#define TMC_USE_SW_SPI - //#define TMC_SW_MOSI -1 - //#define TMC_SW_MISO -1 - //#define TMC_SW_SCK -1 - - /** - * Use Trinamic's ultra quiet stepping mode. - * When disabled, Marlin will use spreadCycle stepping mode. - */ - #define STEALTHCHOP - - /** - * Monitor Trinamic TMC2130 and TMC2208 drivers for error conditions, - * like overtemperature and short to ground. TMC2208 requires hardware serial. - * In the case of overtemperature Marlin can decrease the driver current until error condition clears. - * Other detected conditions can be used to stop the current print. - * Relevant g-codes: - * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. - * M911 - Report stepper driver overtemperature pre-warn condition. - * M912 - Clear stepper driver overtemperature pre-warn condition flag. - * M122 S0/1 - Report driver parameters (Requires TMC_DEBUG) - */ - //#define MONITOR_DRIVER_STATUS - - #if ENABLED(MONITOR_DRIVER_STATUS) - #define CURRENT_STEP_DOWN 50 // [mA] - #define REPORT_CURRENT_CHANGE - #define STOP_ON_ERROR - #endif - - /** - * The driver will switch to spreadCycle when stepper speed is over HYBRID_THRESHOLD. - * This mode allows for faster movements at the expense of higher noise levels. - * STEALTHCHOP needs to be enabled. - * M913 X/Y/Z/E to live tune the setting - */ - //#define HYBRID_THRESHOLD - - #define X_HYBRID_THRESHOLD 100 // [mm/s] - #define X2_HYBRID_THRESHOLD 100 - #define Y_HYBRID_THRESHOLD 100 - #define Y2_HYBRID_THRESHOLD 100 - #define Z_HYBRID_THRESHOLD 3 - #define Z2_HYBRID_THRESHOLD 3 - #define E0_HYBRID_THRESHOLD 30 - #define E1_HYBRID_THRESHOLD 30 - #define E2_HYBRID_THRESHOLD 30 - #define E3_HYBRID_THRESHOLD 30 - #define E4_HYBRID_THRESHOLD 30 - - /** - * Use stallGuard2 to sense an obstacle and trigger an endstop. - * You need to place a wire from the driver's DIAG1 pin to the X/Y endstop pin. - * X, Y, and Z homing will always be done in spreadCycle mode. - * - * X/Y/Z_HOMING_SENSITIVITY is used for tuning the trigger sensitivity. - * Higher values make the system LESS sensitive. - * Lower value make the system MORE sensitive. - * Too low values can lead to false positives, while too high values will collide the axis without triggering. - * It is advised to set X/Y/Z_HOME_BUMP_MM to 0. - * M914 X/Y/Z to live tune the setting - */ - //#define SENSORLESS_HOMING // TMC2130 only - - #if ENABLED(SENSORLESS_HOMING) - #define X_HOMING_SENSITIVITY 8 - #define Y_HOMING_SENSITIVITY 8 - #define Z_HOMING_SENSITIVITY 8 - #endif - - /** - * Enable M122 debugging command for TMC stepper drivers. - * M122 S0/1 will enable continous reporting. - */ - //#define TMC_DEBUG - - /** - * M915 Z Axis Calibration - * - * - Adjust Z stepper current, - * - Drive the Z axis to its physical maximum, and - * - Home Z to account for the lost steps. - * - * Use M915 Snn to specify the current. - * Use M925 Znn to add extra Z height to Z_MAX_POS. - */ - //#define TMC_Z_CALIBRATION - #if ENABLED(TMC_Z_CALIBRATION) - #define CALIBRATION_CURRENT 250 - #define CALIBRATION_EXTRA_HEIGHT 10 - #endif - - /** - * You can set your own advanced settings by filling in predefined functions. - * A list of available functions can be found on the library github page - * https://github.com/teemuatlut/TMC2130Stepper - * https://github.com/teemuatlut/TMC2208Stepper - * - * Example: - * #define TMC_ADV() { \ - * stepperX.diag0_temp_prewarn(1); \ - * stepperY.interpolate(0); \ - * } - */ - #define TMC_ADV() { } - -#endif // TMC2130 || TMC2208 - -// @section L6470 - -/** - * L6470 Stepper Driver options - * - * The Arduino-L6470 library is required for this stepper driver. - * https://github.com/ameyer/Arduino-L6470 - */ -#if HAS_DRIVER(L6470) - - #define X_MICROSTEPS 16 // number of microsteps - #define X_OVERCURRENT 2000 // maxc current in mA. If the current goes over this value, the driver will switch off - #define X_STALLCURRENT 1500 // current in mA where the driver will detect a stall - - #define X2_MICROSTEPS 16 - #define X2_OVERCURRENT 2000 - #define X2_STALLCURRENT 1500 - - #define Y_MICROSTEPS 16 - #define Y_OVERCURRENT 2000 - #define Y_STALLCURRENT 1500 - - #define Y2_MICROSTEPS 16 - #define Y2_OVERCURRENT 2000 - #define Y2_STALLCURRENT 1500 - - #define Z_MICROSTEPS 16 - #define Z_OVERCURRENT 2000 - #define Z_STALLCURRENT 1500 - - #define Z2_MICROSTEPS 16 - #define Z2_OVERCURRENT 2000 - #define Z2_STALLCURRENT 1500 - - #define E0_MICROSTEPS 16 - #define E0_OVERCURRENT 2000 - #define E0_STALLCURRENT 1500 - - #define E1_MICROSTEPS 16 - #define E1_OVERCURRENT 2000 - #define E1_STALLCURRENT 1500 - - #define E2_MICROSTEPS 16 - #define E2_OVERCURRENT 2000 - #define E2_STALLCURRENT 1500 - - #define E3_MICROSTEPS 16 - #define E3_OVERCURRENT 2000 - #define E3_STALLCURRENT 1500 - - #define E4_MICROSTEPS 16 - #define E4_OVERCURRENT 2000 - #define E4_STALLCURRENT 1500 - -#endif // L6470 - -/** - * TWI/I2C BUS - * - * This feature is an EXPERIMENTAL feature so it shall not be used on production - * machines. Enabling this will allow you to send and receive I2C data from slave - * devices on the bus. - * - * ; Example #1 - * ; This macro send the string "Marlin" to the slave device with address 0x63 (99) - * ; It uses multiple M260 commands with one B arg - * M260 A99 ; Target slave address - * M260 B77 ; M - * M260 B97 ; a - * M260 B114 ; r - * M260 B108 ; l - * M260 B105 ; i - * M260 B110 ; n - * M260 S1 ; Send the current buffer - * - * ; Example #2 - * ; Request 6 bytes from slave device with address 0x63 (99) - * M261 A99 B5 - * - * ; Example #3 - * ; Example serial output of a M261 request - * echo:i2c-reply: from:99 bytes:5 data:hello - */ - -// @section i2cbus - -//#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave - -// @section extras - -/** - * Spindle & Laser control - * - * Add the M3, M4, and M5 commands to turn the spindle/laser on and off, and - * to set spindle speed, spindle direction, and laser power. - * - * SuperPid is a router/spindle speed controller used in the CNC milling community. - * Marlin can be used to turn the spindle on and off. It can also be used to set - * the spindle speed from 5,000 to 30,000 RPM. - * - * You'll need to select a pin for the ON/OFF function and optionally choose a 0-5V - * hardware PWM pin for the speed control and a pin for the rotation direction. - * - * See http://marlinfw.org/docs/configuration/laser_spindle.html for more config details. - */ -//#define SPINDLE_LASER_ENABLE -#if ENABLED(SPINDLE_LASER_ENABLE) - - #define SPINDLE_LASER_ENABLE_INVERT false // set to "true" if the on/off function is reversed - #define SPINDLE_LASER_PWM true // set to true if your controller supports setting the speed/power - #define SPINDLE_LASER_PWM_INVERT true // set to "true" if the speed/power goes up when you want it to go slower - #define SPINDLE_LASER_POWERUP_DELAY 5000 // delay in milliseconds to allow the spindle/laser to come up to speed/power - #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // delay in milliseconds to allow the spindle to stop - #define SPINDLE_DIR_CHANGE true // set to true if your spindle controller supports changing spindle direction - #define SPINDLE_INVERT_DIR false - #define SPINDLE_STOP_ON_DIR_CHANGE true // set to true if Marlin should stop the spindle before changing rotation direction - - /** - * The M3 & M4 commands use the following equation to convert PWM duty cycle to speed/power - * - * SPEED/POWER = PWM duty cycle * SPEED_POWER_SLOPE + SPEED_POWER_INTERCEPT - * where PWM duty cycle varies from 0 to 255 - * - * set the following for your controller (ALL MUST BE SET) - */ - - #define SPEED_POWER_SLOPE 118.4 - #define SPEED_POWER_INTERCEPT 0 - #define SPEED_POWER_MIN 5000 - #define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM - - //#define SPEED_POWER_SLOPE 0.3922 - //#define SPEED_POWER_INTERCEPT 0 - //#define SPEED_POWER_MIN 10 - //#define SPEED_POWER_MAX 100 // 0-100% -#endif - -/** - * Filament Width Sensor - * - * Measures the filament width in real-time and adjusts - * flow rate to compensate for any irregularities. - * - * Also allows the measured filament diameter to set the - * extrusion rate, so the slicer only has to specify the - * volume. - * - * Only a single extruder is supported at this time. - * - * 34 RAMPS_14 : Analog input 5 on the AUX2 connector - * 81 PRINTRBOARD : Analog input 2 on the Exp1 connector (version B,C,D,E) - * 301 RAMBO : Analog input 3 - * - * Note: May require analog pins to be defined for other boards. - */ -//#define FILAMENT_WIDTH_SENSOR - -#if ENABLED(FILAMENT_WIDTH_SENSOR) - #define FILAMENT_SENSOR_EXTRUDER_NUM 0 // Index of the extruder that has the filament sensor. :[0,1,2,3,4] - #define MEASUREMENT_DELAY_CM 14 // (cm) The distance from the filament sensor to the melting chamber - - #define FILWIDTH_ERROR_MARGIN 1.0 // (mm) If a measurement differs too much from nominal width ignore it - #define MAX_MEASUREMENT_DELAY 20 // (bytes) Buffer size for stored measurements (1 byte per cm). Must be larger than MEASUREMENT_DELAY_CM. - - #define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA // Set measured to nominal initially - - // Display filament width on the LCD status line. Status messages will expire after 5 seconds. - //#define FILAMENT_LCD_DISPLAY -#endif - -/** - * CNC Coordinate Systems - * - * Enables G53 and G54-G59.3 commands to select coordinate systems - * and G92.1 to reset the workspace to native machine space. - */ -//#define CNC_COORDINATE_SYSTEMS - -/** - * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins - */ -//#define PINS_DEBUGGING - -/** - * Auto-report temperatures with M155 S - */ -#define AUTO_REPORT_TEMPERATURES - -/** - * Include capabilities in M115 output - */ -#define EXTENDED_CAPABILITIES_REPORT - -/** - * Disable all Volumetric extrusion options - */ -//#define NO_VOLUMETRICS - -#if DISABLED(NO_VOLUMETRICS) - /** - * Volumetric extrusion default state - * Activate to make volumetric extrusion the default method, - * with DEFAULT_NOMINAL_FILAMENT_DIA as the default diameter. - * - * M200 D0 to disable, M200 Dn to set a new diameter. - */ - //#define VOLUMETRIC_DEFAULT_ON -#endif - -/** - * Enable this option for a leaner build of Marlin that removes all - * workspace offsets, simplifying coordinate transformations, leveling, etc. - * - * - M206 and M428 are disabled. - * - G92 will revert to its behavior from Marlin 1.0. - */ -//#define NO_WORKSPACE_OFFSETS - -/** - * Set the number of proportional font spaces required to fill up a typical character space. - * This can help to better align the output of commands like `G29 O` Mesh Output. - * - * For clients that use a fixed-width font (like OctoPrint), leave this set to 1.0. - * Otherwise, adjust according to your client and font. - */ -#define PROPORTIONAL_FONT_RATIO 1.0 - -/** - * Spend 28 bytes of SRAM to optimize the GCode parser - */ -#define FASTER_GCODE_PARSER - -/** - * User-defined menu items that execute custom GCode - */ -//#define CUSTOM_USER_MENUS -#if ENABLED(CUSTOM_USER_MENUS) - #define USER_SCRIPT_DONE "M117 User Script Done" - #define USER_SCRIPT_AUDIBLE_FEEDBACK - //#define USER_SCRIPT_RETURN // Return to status screen after a script - - #define USER_DESC_1 "Home & UBL Info" - #define USER_GCODE_1 "G28\nG29 W" - - #define USER_DESC_2 "Preheat for PLA" - #define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) - - #define USER_DESC_3 "Preheat for ABS" - #define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) - - #define USER_DESC_4 "Heat Bed/Home/Level" - #define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29" - - #define USER_DESC_5 "Home & Info" - #define USER_GCODE_5 "G28\nM503" -#endif - -/** - * Specify an action command to send to the host when the printer is killed. - * Will be sent in the form '//action:ACTION_ON_KILL', e.g. '//action:poweroff'. - * The host must be configured to handle the action command. - */ -//#define ACTION_ON_KILL "poweroff" - -/** - * Specify an action command to send to the host on pause and resume. - * Will be sent in the form '//action:ACTION_ON_PAUSE', e.g. '//action:pause'. - * The host must be configured to handle the action command. - */ -//#define ACTION_ON_PAUSE "pause" -//#define ACTION_ON_RESUME "resume" - -//=========================================================================== -//====================== I2C Position Encoder Settings ====================== -//=========================================================================== - -/** - * I2C position encoders for closed loop control. - * Developed by Chris Barr at Aus3D. - * - * Wiki: http://wiki.aus3d.com.au/Magnetic_Encoder - * Github: https://github.com/Aus3D/MagneticEncoder - * - * Supplier: http://aus3d.com.au/magnetic-encoder-module - * Alternative Supplier: http://reliabuild3d.com/ - * - * Reilabuild encoders have been modified to improve reliability. - */ - -//#define I2C_POSITION_ENCODERS -#if ENABLED(I2C_POSITION_ENCODERS) - - #define I2CPE_ENCODER_CNT 1 // The number of encoders installed; max of 5 - // encoders supported currently. - - #define I2CPE_ENC_1_ADDR I2CPE_PRESET_ADDR_X // I2C address of the encoder. 30-200. - #define I2CPE_ENC_1_AXIS X_AXIS // Axis the encoder module is installed on. _AXIS. - #define I2CPE_ENC_1_TYPE I2CPE_ENC_TYPE_LINEAR // Type of encoder: I2CPE_ENC_TYPE_LINEAR -or- - // I2CPE_ENC_TYPE_ROTARY. - #define I2CPE_ENC_1_TICKS_UNIT 2048 // 1024 for magnetic strips with 2mm poles; 2048 for - // 1mm poles. For linear encoders this is ticks / mm, - // for rotary encoders this is ticks / revolution. - //#define I2CPE_ENC_1_TICKS_REV (16 * 200) // Only needed for rotary encoders; number of stepper - // steps per full revolution (motor steps/rev * microstepping) - //#define I2CPE_ENC_1_INVERT // Invert the direction of axis travel. - #define I2CPE_ENC_1_EC_METHOD I2CPE_ECM_MICROSTEP // Type of error error correction. - #define I2CPE_ENC_1_EC_THRESH 0.10 // Threshold size for error (in mm) above which the - // printer will attempt to correct the error; errors - // smaller than this are ignored to minimize effects of - // measurement noise / latency (filter). - - #define I2CPE_ENC_2_ADDR I2CPE_PRESET_ADDR_Y // Same as above, but for encoder 2. - #define I2CPE_ENC_2_AXIS Y_AXIS - #define I2CPE_ENC_2_TYPE I2CPE_ENC_TYPE_LINEAR - #define I2CPE_ENC_2_TICKS_UNIT 2048 - //#define I2CPE_ENC_2_TICKS_REV (16 * 200) - //#define I2CPE_ENC_2_INVERT - #define I2CPE_ENC_2_EC_METHOD I2CPE_ECM_MICROSTEP - #define I2CPE_ENC_2_EC_THRESH 0.10 - - #define I2CPE_ENC_3_ADDR I2CPE_PRESET_ADDR_Z // Encoder 3. Add additional configuration options - #define I2CPE_ENC_3_AXIS Z_AXIS // as above, or use defaults below. - - #define I2CPE_ENC_4_ADDR I2CPE_PRESET_ADDR_E // Encoder 4. - #define I2CPE_ENC_4_AXIS E_AXIS - - #define I2CPE_ENC_5_ADDR 34 // Encoder 5. - #define I2CPE_ENC_5_AXIS E_AXIS - - // Default settings for encoders which are enabled, but without settings configured above. - #define I2CPE_DEF_TYPE I2CPE_ENC_TYPE_LINEAR - #define I2CPE_DEF_ENC_TICKS_UNIT 2048 - #define I2CPE_DEF_TICKS_REV (16 * 200) - #define I2CPE_DEF_EC_METHOD I2CPE_ECM_NONE - #define I2CPE_DEF_EC_THRESH 0.1 - - //#define I2CPE_ERR_THRESH_ABORT 100.0 // Threshold size for error (in mm) error on any given - // axis after which the printer will abort. Comment out to - // disable abort behaviour. - - #define I2CPE_TIME_TRUSTED 10000 // After an encoder fault, there must be no further fault - // for this amount of time (in ms) before the encoder - // is trusted again. - - /** - * Position is checked every time a new command is executed from the buffer but during long moves, - * this setting determines the minimum update time between checks. A value of 100 works well with - * error rolling average when attempting to correct only for skips and not for vibration. - */ - #define I2CPE_MIN_UPD_TIME_MS 4 // (ms) Minimum time between encoder checks. - - // Use a rolling average to identify persistant errors that indicate skips, as opposed to vibration and noise. - #define I2CPE_ERR_ROLLING_AVERAGE - -#endif // I2C_POSITION_ENCODERS - -/** - * MAX7219 Debug Matrix - * - * Add support for a low-cost 8x8 LED Matrix based on the Max7219 chip as a realtime status display. - * Requires 3 signal wires. Some useful debug options are included to demonstrate its usage. - */ -//#define MAX7219_DEBUG -#if ENABLED(MAX7219_DEBUG) - #define MAX7219_CLK_PIN 64 - #define MAX7219_DIN_PIN 57 - #define MAX7219_LOAD_PIN 44 - - //#define MAX7219_GCODE // Add the M7219 G-code to control the LED matrix - #define MAX7219_INIT_TEST 2 // Do a test pattern at initialization (Set to 2 for spiral) - #define MAX7219_NUMBER_UNITS 1 // Number of Max7219 units in chain. - #define MAX7219_ROTATE 0 // Rotate the display clockwise (in multiples of +/- 90°) - // connector at: right=0 bottom=-90 top=90 left=180 - - /** - * Sample debug features - * If you add more debug displays, be careful to avoid conflicts! - */ - #define MAX7219_DEBUG_PRINTER_ALIVE // Blink corner LED of 8x8 matrix to show that the firmware is functioning - #define MAX7219_DEBUG_PLANNER_HEAD 3 // Show the planner queue head position on this and the next LED matrix row - #define MAX7219_DEBUG_PLANNER_TAIL 5 // Show the planner queue tail position on this and the next LED matrix row - - #define MAX7219_DEBUG_PLANNER_QUEUE 0 // Show the current planner queue depth on this and the next LED matrix row - // If you experience stuttering, reboots, etc. this option can reveal how - // tweaks made to the configuration are affecting the printer in real-time. -#endif - -/** - * NanoDLP Sync support - * - * Add support for Synchronized Z moves when using with NanoDLP. G0/G1 axis moves will output "Z_move_comp" - * string to enable synchronization with DLP projector exposure. This change will allow to use - * [[WaitForDoneMessage]] instead of populating your gcode with M400 commands - */ -//#define NANODLP_Z_SYNC -#if ENABLED(NANODLP_Z_SYNC) - //#define NANODLP_ALL_AXIS // Enables "Z_move_comp" output on any axis move. - // Default behaviour is limited to Z axis only. -#endif - -/** - * WiFi Support (Espressif ESP32 WiFi) - */ -//#define WIFISUPPORT -#if ENABLED(WIFISUPPORT) - #define WIFI_SSID "Wifi SSID" - #define WIFI_PWD "Wifi Password" -#endif - -// Enable Marlin dev mode which adds some special commands -//#define MARLIN_DEV_MODE - -#endif // CONFIGURATION_ADV_H diff --git a/Marlin/src/config/examples/delta/kossel_pro/Configuration_adv.h b/Marlin/src/config/examples/delta/kossel_pro/Configuration_adv.h deleted file mode 100644 index c7c643d92a..0000000000 --- a/Marlin/src/config/examples/delta/kossel_pro/Configuration_adv.h +++ /dev/null @@ -1,1692 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - */ - -// Example configuration file for OpenBeam Kossel Pro -// tested on 2015-05-19 by @Wackerbarth -// using Arduino 1.6.5 (Mac) - - -/** - * Configuration_adv.h - * - * Advanced settings. - * Only change these if you know exactly what you're doing. - * Some of these settings can damage your printer if improperly set! - * - * Basic settings can be found in Configuration.h - * - */ -#ifndef CONFIGURATION_ADV_H -#define CONFIGURATION_ADV_H -#define CONFIGURATION_ADV_H_VERSION 020000 - -// @section temperature - -//=========================================================================== -//=============================Thermal Settings ============================ -//=========================================================================== - -// -// Hephestos 2 24V heated bed upgrade kit. -// https://store.bq.com/en/heated-bed-kit-hephestos2 -// -//#define HEPHESTOS2_HEATED_BED_KIT -#if ENABLED(HEPHESTOS2_HEATED_BED_KIT) - #undef TEMP_SENSOR_BED - #define TEMP_SENSOR_BED 70 - #define HEATER_BED_INVERTING true -#endif - -#if DISABLED(PIDTEMPBED) - #define BED_CHECK_INTERVAL 5000 // ms between checks in bang-bang control - #if ENABLED(BED_LIMIT_SWITCHING) - #define BED_HYSTERESIS 2 // Only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS - #endif -#endif - -/** - * Thermal Protection provides additional protection to your printer from damage - * and fire. Marlin always includes safe min and max temperature ranges which - * protect against a broken or disconnected thermistor wire. - * - * The issue: If a thermistor falls out, it will report the much lower - * temperature of the air in the room, and the the firmware will keep - * the heater on. - * - * The solution: Once the temperature reaches the target, start observing. - * If the temperature stays too far below the target (hysteresis) for too - * long (period), the firmware will halt the machine as a safety precaution. - * - * If you get false positives for "Thermal Runaway", increase - * THERMAL_PROTECTION_HYSTERESIS and/or THERMAL_PROTECTION_PERIOD - */ -#if ENABLED(THERMAL_PROTECTION_HOTENDS) - #define THERMAL_PROTECTION_PERIOD 40 // Seconds - #define THERMAL_PROTECTION_HYSTERESIS 4 // Degrees Celsius - - /** - * Whenever an M104, M109, or M303 increases the target temperature, the - * firmware will wait for the WATCH_TEMP_PERIOD to expire. If the temperature - * hasn't increased by WATCH_TEMP_INCREASE degrees, the machine is halted and - * requires a hard reset. This test restarts with any M104/M109/M303, but only - * if the current temperature is far enough below the target for a reliable - * test. - * - * If you get false positives for "Heating failed", increase WATCH_TEMP_PERIOD - * and/or decrease WATCH_TEMP_INCREASE. WATCH_TEMP_INCREASE should not be set - * below 2. - */ - #define WATCH_TEMP_PERIOD 20 // Seconds - #define WATCH_TEMP_INCREASE 2 // Degrees Celsius -#endif - -/** - * Thermal Protection parameters for the bed are just as above for hotends. - */ -#if ENABLED(THERMAL_PROTECTION_BED) - #define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds - #define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius - - /** - * As described above, except for the bed (M140/M190/M303). - */ - #define WATCH_BED_TEMP_PERIOD 60 // Seconds - #define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius -#endif - -#if ENABLED(PIDTEMP) - // this adds an experimental additional term to the heating power, proportional to the extrusion speed. - // if Kc is chosen well, the additional required power due to increased melting should be compensated. - //#define PID_EXTRUSION_SCALING - #if ENABLED(PID_EXTRUSION_SCALING) - #define DEFAULT_Kc (100) //heating power=Kc*(e_speed) - #define LPQ_MAX_LEN 50 - #endif -#endif - -/** - * Automatic Temperature: - * The hotend target temperature is calculated by all the buffered lines of gcode. - * The maximum buffered steps/sec of the extruder motor is called "se". - * Start autotemp mode with M109 S B F - * The target temperature is set to mintemp+factor*se[steps/sec] and is limited by - * mintemp and maxtemp. Turn this off by executing M109 without F* - * Also, if the temperature is set to a value below mintemp, it will not be changed by autotemp. - * On an Ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode - */ -#define AUTOTEMP -#if ENABLED(AUTOTEMP) - #define AUTOTEMP_OLDWEIGHT 0.98 -#endif - -// Show extra position information in M114 -//#define M114_DETAIL - -// Show Temperature ADC value -// Enable for M105 to include ADC values read from temperature sensors. -//#define SHOW_TEMP_ADC_VALUES - -/** - * High Temperature Thermistor Support - * - * Thermistors able to support high temperature tend to have a hard time getting - * good readings at room and lower temperatures. This means HEATER_X_RAW_LO_TEMP - * will probably be caught when the heating element first turns on during the - * preheating process, which will trigger a min_temp_error as a safety measure - * and force stop everything. - * To circumvent this limitation, we allow for a preheat time (during which, - * min_temp_error won't be triggered) and add a min_temp buffer to handle - * aberrant readings. - * - * If you want to enable this feature for your hotend thermistor(s) - * uncomment and set values > 0 in the constants below - */ - -// The number of consecutive low temperature errors that can occur -// before a min_temp_error is triggered. (Shouldn't be more than 10.) -//#define MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED 0 - -// The number of milliseconds a hotend will preheat before starting to check -// the temperature. This value should NOT be set to the time it takes the -// hot end to reach the target temperature, but the time it takes to reach -// the minimum temperature your thermistor can read. The lower the better/safer. -// This shouldn't need to be more than 30 seconds (30000) -//#define MILLISECONDS_PREHEAT_TIME 0 - -// @section extruder - -// Extruder runout prevention. -// If the machine is idle and the temperature over MINTEMP -// then extrude some filament every couple of SECONDS. -//#define EXTRUDER_RUNOUT_PREVENT -#if ENABLED(EXTRUDER_RUNOUT_PREVENT) - #define EXTRUDER_RUNOUT_MINTEMP 190 - #define EXTRUDER_RUNOUT_SECONDS 30 - #define EXTRUDER_RUNOUT_SPEED 1500 // mm/m - #define EXTRUDER_RUNOUT_EXTRUDE 5 // mm -#endif - -// @section temperature - -// Calibration for AD595 / AD8495 sensor to adjust temperature measurements. -// The final temperature is calculated as (measuredTemp * GAIN) + OFFSET. -#define TEMP_SENSOR_AD595_OFFSET 0.0 -#define TEMP_SENSOR_AD595_GAIN 1.0 -#define TEMP_SENSOR_AD8495_OFFSET 0.0 -#define TEMP_SENSOR_AD8495_GAIN 1.0 - -/** - * Controller Fan - * To cool down the stepper drivers and MOSFETs. - * - * The fan will turn on automatically whenever any stepper is enabled - * and turn off after a set period after all steppers are turned off. - */ -//#define USE_CONTROLLER_FAN -#if ENABLED(USE_CONTROLLER_FAN) - //#define CONTROLLER_FAN_PIN -1 // Set a custom pin for the controller fan - #define CONTROLLERFAN_SECS 60 // Duration in seconds for the fan to run after all motors are disabled - #define CONTROLLERFAN_SPEED 255 // 255 == full speed -#endif - -// When first starting the main fan, run it at full speed for the -// given number of milliseconds. This gets the fan spinning reliably -// before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu) -//#define FAN_KICKSTART_TIME 100 - -/** - * PWM Fan Scaling - * - * Define the min/max speeds for PWM fans (as set with M106). - * - * With these options the M106 0-255 value range is scaled to a subset - * to ensure that the fan has enough power to spin, or to run lower - * current fans with higher current. (e.g., 5V/12V fans with 12V/24V) - * Value 0 always turns off the fan. - * - * Define one or both of these to override the default 0-255 range. - */ -//#define FAN_MIN_PWM 50 -//#define FAN_MAX_PWM 128 - -// @section extruder - -/** - * Extruder cooling fans - * - * Extruder auto fans automatically turn on when their extruders' - * temperatures go above EXTRUDER_AUTO_FAN_TEMPERATURE. - * - * Your board's pins file specifies the recommended pins. Override those here - * or set to -1 to disable completely. - * - * Multiple extruders can be assigned to the same pin in which case - * the fan will turn on when any selected extruder is above the threshold. - */ -#define E0_AUTO_FAN_PIN -1 -#define E1_AUTO_FAN_PIN -1 -#define E2_AUTO_FAN_PIN -1 -#define E3_AUTO_FAN_PIN -1 -#define E4_AUTO_FAN_PIN -1 -#define CHAMBER_AUTO_FAN_PIN -1 -#define EXTRUDER_AUTO_FAN_TEMPERATURE 50 -#define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed - -/** - * Part-Cooling Fan Multiplexer - * - * This feature allows you to digitally multiplex the fan output. - * The multiplexer is automatically switched at tool-change. - * Set FANMUX[012]_PINs below for up to 2, 4, or 8 multiplexed fans. - */ -#define FANMUX0_PIN -1 -#define FANMUX1_PIN -1 -#define FANMUX2_PIN -1 - -/** - * M355 Case Light on-off / brightness - */ -//#define CASE_LIGHT_ENABLE -#if ENABLED(CASE_LIGHT_ENABLE) - //#define CASE_LIGHT_PIN 4 // Override the default pin if needed - #define INVERT_CASE_LIGHT false // Set true if Case Light is ON when pin is LOW - #define CASE_LIGHT_DEFAULT_ON true // Set default power-up state on - #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // Set default power-up brightness (0-255, requires PWM pin) - //#define MENU_ITEM_CASE_LIGHT // Add a Case Light option to the LCD main menu - //#define CASE_LIGHT_USE_NEOPIXEL // Use Neopixel LED as case light, requires NEOPIXEL_LED. - #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) - #define CASE_LIGHT_NEOPIXEL_COLOR { 255, 255, 255, 255 } // { Red, Green, Blue, White } - #endif -#endif - -//=========================================================================== -//============================ Mechanical Settings ========================== -//=========================================================================== - -// @section homing - -// If you want endstops to stay on (by default) even when not homing -// enable this option. Override at any time with M120, M121. -//#define ENDSTOPS_ALWAYS_ON_DEFAULT - -// @section extras - -//#define Z_LATE_ENABLE // Enable Z the last moment. Needed if your Z driver overheats. - -/** - * Dual Steppers / Dual Endstops - * - * This section will allow you to use extra E drivers to drive a second motor for X, Y, or Z axes. - * - * For example, set X_DUAL_STEPPER_DRIVERS setting to use a second motor. If the motors need to - * spin in opposite directions set INVERT_X2_VS_X_DIR. If the second motor needs its own endstop - * set X_DUAL_ENDSTOPS. This can adjust for "racking." Use X2_USE_ENDSTOP to set the endstop plug - * that should be used for the second endstop. Extra endstops will appear in the output of 'M119'. - * - * Use X_DUAL_ENDSTOP_ADJUSTMENT to adjust for mechanical imperfection. After homing both motors - * this offset is applied to the X2 motor. To find the offset home the X axis, and measure the error - * in X2. Dual endstop offsets can be set at runtime with 'M666 X Y Z'. - */ - -//#define X_DUAL_STEPPER_DRIVERS -#if ENABLED(X_DUAL_STEPPER_DRIVERS) - #define INVERT_X2_VS_X_DIR true // Set 'true' if X motors should rotate in opposite directions - //#define X_DUAL_ENDSTOPS - #if ENABLED(X_DUAL_ENDSTOPS) - #define X2_USE_ENDSTOP _XMAX_ - #define X_DUAL_ENDSTOPS_ADJUSTMENT 0 - #endif -#endif - -//#define Y_DUAL_STEPPER_DRIVERS -#if ENABLED(Y_DUAL_STEPPER_DRIVERS) - #define INVERT_Y2_VS_Y_DIR true // Set 'true' if Y motors should rotate in opposite directions - //#define Y_DUAL_ENDSTOPS - #if ENABLED(Y_DUAL_ENDSTOPS) - #define Y2_USE_ENDSTOP _YMAX_ - #define Y_DUAL_ENDSTOPS_ADJUSTMENT 0 - #endif -#endif - -//#define Z_DUAL_STEPPER_DRIVERS -#if ENABLED(Z_DUAL_STEPPER_DRIVERS) - //#define Z_DUAL_ENDSTOPS - #if ENABLED(Z_DUAL_ENDSTOPS) - #define Z2_USE_ENDSTOP _XMAX_ - #define Z_DUAL_ENDSTOPS_ADJUSTMENT 0 - #endif -#endif - -// Enable this for dual x-carriage printers. -// A dual x-carriage design has the advantage that the inactive extruder can be parked which -// prevents hot-end ooze contaminating the print. It also reduces the weight of each x-carriage -// allowing faster printing speeds. Connect your X2 stepper to the first unused E plug. -//#define DUAL_X_CARRIAGE -#if ENABLED(DUAL_X_CARRIAGE) - // Configuration for second X-carriage - // Note: the first x-carriage is defined as the x-carriage which homes to the minimum endstop; - // the second x-carriage always homes to the maximum endstop. - #define X1_MIN_POS X_MIN_POS // set minimum to ensure first x-carriage doesn't hit the parked second X-carriage - #define X1_MAX_POS X_BED_SIZE // set maximum to ensure first x-carriage doesn't hit the parked second X-carriage - #define X2_MIN_POS 80 // set minimum to ensure second x-carriage doesn't hit the parked first X-carriage - #define X2_MAX_POS 353 // set maximum to the distance between toolheads when both heads are homed - #define X2_HOME_DIR 1 // the second X-carriage always homes to the maximum endstop position - #define X2_HOME_POS X2_MAX_POS // default home position is the maximum carriage position - // However: In this mode the HOTEND_OFFSET_X value for the second extruder provides a software - // override for X2_HOME_POS. This also allow recalibration of the distance between the two endstops - // without modifying the firmware (through the "M218 T1 X???" command). - // Remember: you should set the second extruder x-offset to 0 in your slicer. - - // There are a few selectable movement modes for dual x-carriages using M605 S - // Mode 0 (DXC_FULL_CONTROL_MODE): Full control. The slicer has full control over both x-carriages and can achieve optimal travel results - // as long as it supports dual x-carriages. (M605 S0) - // Mode 1 (DXC_AUTO_PARK_MODE) : Auto-park mode. The firmware will automatically park and unpark the x-carriages on tool changes so - // that additional slicer support is not required. (M605 S1) - // Mode 2 (DXC_DUPLICATION_MODE) : Duplication mode. The firmware will transparently make the second x-carriage and extruder copy all - // actions of the first x-carriage. This allows the printer to print 2 arbitrary items at - // once. (2nd extruder x offset and temp offset are set using: M605 S2 [Xnnn] [Rmmm]) - - // This is the default power-up mode which can be later using M605. - #define DEFAULT_DUAL_X_CARRIAGE_MODE DXC_FULL_CONTROL_MODE - - // Default settings in "Auto-park Mode" - #define TOOLCHANGE_PARK_ZLIFT 0.2 // the distance to raise Z axis when parking an extruder - #define TOOLCHANGE_UNPARK_ZLIFT 1 // the distance to raise Z axis when unparking an extruder - - // Default x offset in duplication mode (typically set to half print bed width) - #define DEFAULT_DUPLICATION_X_OFFSET 100 - -#endif // DUAL_X_CARRIAGE - -// Activate a solenoid on the active extruder with M380. Disable all with M381. -// Define SOL0_PIN, SOL1_PIN, etc., for each extruder that has a solenoid. -//#define EXT_SOLENOID - -// @section homing - -// Homing hits each endstop, retracts by these distances, then does a slower bump. -#define X_HOME_BUMP_MM 5 -#define Y_HOME_BUMP_MM 5 -#define Z_HOME_BUMP_MM 5 // deltas need the same for all three axes -#define HOMING_BUMP_DIVISOR { 10, 10, 10 } // Re-Bump Speed Divisor (Divides the Homing Feedrate) -//#define QUICK_HOME // If homing includes X and Y, do a diagonal move initially - -// When G28 is called, this option will make Y home before X -//#define HOME_Y_BEFORE_X - -// Enable this if X or Y can't home without homing the other axis first. -//#define CODEPENDENT_XY_HOMING - -// @section machine - -#define AXIS_RELATIVE_MODES {false, false, false, false} - -// Allow duplication mode with a basic dual-nozzle extruder -//#define DUAL_NOZZLE_DUPLICATION_MODE - -// By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step. -#define INVERT_X_STEP_PIN false -#define INVERT_Y_STEP_PIN false -#define INVERT_Z_STEP_PIN false -#define INVERT_E_STEP_PIN false - -// Default stepper release if idle. Set to 0 to deactivate. -// Steppers will shut down DEFAULT_STEPPER_DEACTIVE_TIME seconds after the last move when DISABLE_INACTIVE_? is true. -// Time can be set by M18 and M84. -#define DEFAULT_STEPPER_DEACTIVE_TIME 60 -#define DISABLE_INACTIVE_X true -#define DISABLE_INACTIVE_Y true -#define DISABLE_INACTIVE_Z true // set to false if the nozzle will fall down on your printed part when print has finished. -#define DISABLE_INACTIVE_E true - -#define DEFAULT_MINIMUMFEEDRATE 0.0 // minimum feedrate -#define DEFAULT_MINTRAVELFEEDRATE 0.0 - -//#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated - -// @section lcd - -#if ENABLED(ULTIPANEL) - #define MANUAL_FEEDRATE_XYZ 50*60 - #define MANUAL_FEEDRATE { MANUAL_FEEDRATE_XYZ, MANUAL_FEEDRATE_XYZ, MANUAL_FEEDRATE_XYZ, 60 } // Feedrates for manual moves along X, Y, Z, E from panel - #define ULTIPANEL_FEEDMULTIPLY // Comment to disable setting feedrate multiplier via encoder -#endif - -// @section extras - -// minimum time in microseconds that a movement needs to take if the buffer is emptied. -#define DEFAULT_MINSEGMENTTIME 20000 - -// If defined the movements slow down when the look ahead buffer is only half full -// (don't use SLOWDOWN with DELTA because DELTA generates hundreds of segments per second) -//#define SLOWDOWN - -// Frequency limit -// See nophead's blog for more info -// Not working O -//#define XY_FREQUENCY_LIMIT 15 - -// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end -// of the buffer and all stops. This should not be much greater than zero and should only be changed -// if unwanted behavior is observed on a user's machine when running at very slow speeds. -#define MINIMUM_PLANNER_SPEED 0.05 // (mm/sec) - -// -// Use Junction Deviation instead of traditional Jerk Limiting -// -//#define JUNCTION_DEVIATION -#if ENABLED(JUNCTION_DEVIATION) - #define JUNCTION_DEVIATION_MM 0.02 // (mm) Distance from real junction edge -#endif - -/** - * Adaptive Step Smoothing increases the resolution of multi-axis moves, particularly at step frequencies - * below 1kHz (for AVR) or 10kHz (for ARM), where aliasing between axes in multi-axis moves causes audible - * vibration and surface artifacts. The algorithm adapts to provide the best possible step smoothing at the - * lowest stepping frequencies. - */ -//#define ADAPTIVE_STEP_SMOOTHING - -// Microstep setting (Only functional when stepper driver microstep pins are connected to MCU. -#define MICROSTEP_MODES { 16, 16, 16, 16, 16 } // [1,2,4,8,16] - -/** - * @section stepper motor current - * - * Some boards have a means of setting the stepper motor current via firmware. - * - * The power on motor currents are set by: - * PWM_MOTOR_CURRENT - used by MINIRAMBO & ULTIMAIN_2 - * known compatible chips: A4982 - * DIGIPOT_MOTOR_CURRENT - used by BQ_ZUM_MEGA_3D, RAMBO & SCOOVO_X9H - * known compatible chips: AD5206 - * DAC_MOTOR_CURRENT_DEFAULT - used by PRINTRBOARD_REVF & RIGIDBOARD_V2 - * known compatible chips: MCP4728 - * DIGIPOT_I2C_MOTOR_CURRENTS - used by 5DPRINT, AZTEEG_X3_PRO, MIGHTYBOARD_REVE - * known compatible chips: MCP4451, MCP4018 - * - * Motor currents can also be set by M907 - M910 and by the LCD. - * M907 - applies to all. - * M908 - BQ_ZUM_MEGA_3D, RAMBO, PRINTRBOARD_REVF, RIGIDBOARD_V2 & SCOOVO_X9H - * M909, M910 & LCD - only PRINTRBOARD_REVF & RIGIDBOARD_V2 - */ -//#define PWM_MOTOR_CURRENT { 1300, 1300, 1250 } // Values in milliamps -//#define DIGIPOT_MOTOR_CURRENT { 135,135,135,135,135 } // Values 0-255 (RAMBO 135 = ~0.75A, 185 = ~1A) -//#define DAC_MOTOR_CURRENT_DEFAULT { 70, 80, 90, 80 } // Default drive percent - X, Y, Z, E axis - -// Use an I2C based DIGIPOT (e.g., Azteeg X3 Pro) -//#define DIGIPOT_I2C -#if ENABLED(DIGIPOT_I2C) && !defined(DIGIPOT_I2C_ADDRESS_A) - /** - * Common slave addresses: - * - * A (A shifted) B (B shifted) IC - * Smoothie 0x2C (0x58) 0x2D (0x5A) MCP4451 - * AZTEEG_X3_PRO 0x2C (0x58) 0x2E (0x5C) MCP4451 - * MIGHTYBOARD_REVE 0x2F (0x5E) MCP4018 - */ - #define DIGIPOT_I2C_ADDRESS_A 0x2C // unshifted slave address for first DIGIPOT - #define DIGIPOT_I2C_ADDRESS_B 0x2D // unshifted slave address for second DIGIPOT -#endif - -//#define DIGIPOT_MCP4018 // Requires library from https://github.com/stawel/SlowSoftI2CMaster -#define DIGIPOT_I2C_NUM_CHANNELS 8 // 5DPRINT: 4 AZTEEG_X3_PRO: 8 MKS SBASE: 5 -// Actual motor currents in Amps. The number of entries must match DIGIPOT_I2C_NUM_CHANNELS. -// These correspond to the physical drivers, so be mindful if the order is changed. -#define DIGIPOT_I2C_MOTOR_CURRENTS { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 } // AZTEEG_X3_PRO - -//=========================================================================== -//=============================Additional Features=========================== -//=========================================================================== - -#define ENCODER_RATE_MULTIPLIER // If defined, certain menu edit operations automatically multiply the steps when the encoder is moved quickly -#define ENCODER_10X_STEPS_PER_SEC 75 // If the encoder steps per sec exceeds this value, multiply steps moved x10 to quickly advance the value -#define ENCODER_100X_STEPS_PER_SEC 160 // If the encoder steps per sec exceeds this value, multiply steps moved x100 to really quickly advance the value - -//#define CHDK 4 //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/ -#define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again - -// @section lcd - -// Include a page of printer information in the LCD Main Menu -//#define LCD_INFO_MENU - -// Scroll a longer status message into view -//#define STATUS_MESSAGE_SCROLLING - -// On the Info Screen, display XY with one decimal place when possible -//#define LCD_DECIMAL_SMALL_XY - -// The timeout (in ms) to return to the status screen from sub-menus -//#define LCD_TIMEOUT_TO_STATUS 15000 - -// Add an 'M73' G-code to set the current percentage -//#define LCD_SET_PROGRESS_MANUALLY - -#if ENABLED(SDSUPPORT) || ENABLED(LCD_SET_PROGRESS_MANUALLY) - //#define LCD_PROGRESS_BAR // Show a progress bar on HD44780 LCDs for SD printing - #if ENABLED(LCD_PROGRESS_BAR) - #define PROGRESS_BAR_BAR_TIME 2000 // (ms) Amount of time to show the bar - #define PROGRESS_BAR_MSG_TIME 3000 // (ms) Amount of time to show the status message - #define PROGRESS_MSG_EXPIRE 0 // (ms) Amount of time to retain the status message (0=forever) - //#define PROGRESS_MSG_ONCE // Show the message for MSG_TIME then clear it - //#define LCD_PROGRESS_BAR_TEST // Add a menu item to test the progress bar - #endif -#endif // SDSUPPORT || LCD_SET_PROGRESS_MANUALLY - -/** - * LED Control Menu - * Enable this feature to add LED Control to the LCD menu - */ -//#define LED_CONTROL_MENU -#if ENABLED(LED_CONTROL_MENU) - #define LED_COLOR_PRESETS // Enable the Preset Color menu option - #if ENABLED(LED_COLOR_PRESETS) - #define LED_USER_PRESET_RED 255 // User defined RED value - #define LED_USER_PRESET_GREEN 128 // User defined GREEN value - #define LED_USER_PRESET_BLUE 0 // User defined BLUE value - #define LED_USER_PRESET_WHITE 255 // User defined WHITE value - #define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity - //#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup - #endif -#endif // LED_CONTROL_MENU - -#if ENABLED(SDSUPPORT) - - // Some RAMPS and other boards don't detect when an SD card is inserted. You can work - // around this by connecting a push button or single throw switch to the pin defined - // as SD_DETECT_PIN in your board's pins definitions. - // This setting should be disabled unless you are using a push button, pulling the pin to ground. - // Note: This is always disabled for ULTIPANEL (except ELB_FULL_GRAPHIC_CONTROLLER). - #define SD_DETECT_INVERTED - - #define SD_FINISHED_STEPPERRELEASE true // Disable steppers when SD Print is finished - #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. - - // Reverse SD sort to show "more recent" files first, according to the card's FAT. - // Since the FAT gets out of order with usage, SDCARD_SORT_ALPHA is recommended. - #define SDCARD_RATHERRECENTFIRST - - // Add an option in the menu to run all auto#.g files - //#define MENU_ADDAUTOSTART - - /** - * Continue after Power-Loss (Creality3D) - * - * Store the current state to the SD Card at the start of each layer - * during SD printing. If the recovery file is found at boot time, present - * an option on the LCD screen to continue the print from the last-known - * point in the file. - */ - //#define POWER_LOSS_RECOVERY - #if ENABLED(POWER_LOSS_RECOVERY) - //#define POWER_LOSS_PIN 44 // Pin to detect power loss - //#define POWER_LOSS_STATE HIGH // State of pin indicating power loss - #endif - - /** - * Sort SD file listings in alphabetical order. - * - * With this option enabled, items on SD cards will be sorted - * by name for easier navigation. - * - * By default... - * - * - Use the slowest -but safest- method for sorting. - * - Folders are sorted to the top. - * - The sort key is statically allocated. - * - No added G-code (M34) support. - * - 40 item sorting limit. (Items after the first 40 are unsorted.) - * - * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the - * compiler to calculate the worst-case usage and throw an error if the SRAM - * limit is exceeded. - * - * - SDSORT_USES_RAM provides faster sorting via a static directory buffer. - * - SDSORT_USES_STACK does the same, but uses a local stack-based buffer. - * - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!) - * - SDSORT_DYNAMIC_RAM only uses RAM when the SD menu is visible. (Use with caution!) - */ - //#define SDCARD_SORT_ALPHA - - // SD Card Sorting options - #if ENABLED(SDCARD_SORT_ALPHA) - #define SDSORT_LIMIT 40 // Maximum number of sorted items (10-256). Costs 27 bytes each. - #define FOLDER_SORTING -1 // -1=above 0=none 1=below - #define SDSORT_GCODE false // Allow turning sorting on/off with LCD and M34 g-code. - #define SDSORT_USES_RAM false // Pre-allocate a static array for faster pre-sorting. - #define SDSORT_USES_STACK false // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.) - #define SDSORT_CACHE_NAMES false // Keep sorted items in RAM longer for speedy performance. Most expensive option. - #define SDSORT_DYNAMIC_RAM false // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use! - #define SDSORT_CACHE_VFATS 2 // Maximum number of 13-byte VFAT entries to use for sorting. - // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM. - #endif - - // This allows hosts to request long names for files and folders with M33 - //#define LONG_FILENAME_HOST_SUPPORT - - // Enable this option to scroll long filenames in the SD card menu - //#define SCROLL_LONG_FILENAMES - - /** - * This option allows you to abort SD printing when any endstop is triggered. - * This feature must be enabled with "M540 S1" or from the LCD menu. - * To have any effect, endstops must be enabled during SD printing. - */ - //#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED - - /** - * This option makes it easier to print the same SD Card file again. - * On print completion the LCD Menu will open with the file selected. - * You can just click to start the print, or navigate elsewhere. - */ - //#define SD_REPRINT_LAST_SELECTED_FILE - - /** - * Auto-report SdCard status with M27 S - */ - //#define AUTO_REPORT_SD_STATUS - -#endif // SDSUPPORT - -/** - * Additional options for Graphical Displays - * - * Use the optimizations here to improve printing performance, - * which can be adversely affected by graphical display drawing, - * especially when doing several short moves, and when printing - * on DELTA and SCARA machines. - * - * Some of these options may result in the display lagging behind - * controller events, as there is a trade-off between reliable - * printing performance versus fast display updates. - */ -#if ENABLED(DOGLCD) - // Show SD percentage next to the progress bar - //#define DOGM_SD_PERCENT - - // Enable to save many cycles by drawing a hollow frame on the Info Screen - #define XYZ_HOLLOW_FRAME - - // Enable to save many cycles by drawing a hollow frame on Menu Screens - #define MENU_HOLLOW_FRAME - - // A bigger font is available for edit items. Costs 3120 bytes of PROGMEM. - // Western only. Not available for Cyrillic, Kana, Turkish, Greek, or Chinese. - //#define USE_BIG_EDIT_FONT - - // A smaller font may be used on the Info Screen. Costs 2300 bytes of PROGMEM. - // Western only. Not available for Cyrillic, Kana, Turkish, Greek, or Chinese. - //#define USE_SMALL_INFOFONT - - // Enable this option and reduce the value to optimize screen updates. - // The normal delay is 10µs. Use the lowest value that still gives a reliable display. - //#define DOGM_SPI_DELAY_US 5 - - // Swap the CW/CCW indicators in the graphics overlay - //#define OVERLAY_GFX_REVERSE - - #if ENABLED(U8GLIB_ST7920) - /** - * ST7920-based LCDs can emulate a 16 x 4 character display using - * the ST7920 character-generator for very fast screen updates. - * Enable LIGHTWEIGHT_UI to use this special display mode. - * - * Since LIGHTWEIGHT_UI has limited space, the position and status - * message occupy the same line. Set STATUS_EXPIRE_SECONDS to the - * length of time to display the status message before clearing. - * - * Set STATUS_EXPIRE_SECONDS to zero to never clear the status. - * This will prevent position updates from being displayed. - */ - //#define LIGHTWEIGHT_UI - #if ENABLED(LIGHTWEIGHT_UI) - #define STATUS_EXPIRE_SECONDS 20 - #endif - #endif - -#endif // DOGLCD - -// @section safety - -// The hardware watchdog should reset the microcontroller disabling all outputs, -// in case the firmware gets stuck and doesn't do temperature regulation. -#define USE_WATCHDOG - -#if ENABLED(USE_WATCHDOG) - // If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on. - // The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset. - // However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled. - //#define WATCHDOG_RESET_MANUAL -#endif - -// @section lcd - -/** - * Babystepping enables movement of the axes by tiny increments without changing - * the current position values. This feature is used primarily to adjust the Z - * axis in the first layer of a print in real-time. - * - * Warning: Does not respect endstops! - */ -//#define BABYSTEPPING -#if ENABLED(BABYSTEPPING) - //#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA! - #define BABYSTEP_INVERT_Z false // Change if Z babysteps should go the other way - #define BABYSTEP_MULTIPLICATOR 1 // Babysteps are very small. Increase for faster motion. - //#define BABYSTEP_ZPROBE_OFFSET // Enable to combine M851 and Babystepping - //#define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping. - #define DOUBLECLICK_MAX_INTERVAL 1250 // Maximum interval between clicks, in milliseconds. - // Note: Extra time may be added to mitigate controller latency. - //#define BABYSTEP_ZPROBE_GFX_OVERLAY // Enable graphical overlay on Z-offset editor -#endif - -// @section extruder - -/** - * Linear Pressure Control v1.5 - * - * Assumption: advance [steps] = k * (delta velocity [steps/s]) - * K=0 means advance disabled. - * - * NOTE: K values for LIN_ADVANCE 1.5 differ from earlier versions! - * - * Set K around 0.22 for 3mm PLA Direct Drive with ~6.5cm between the drive gear and heatbreak. - * Larger K values will be needed for flexible filament and greater distances. - * If this algorithm produces a higher speed offset than the extruder can handle (compared to E jerk) - * print acceleration will be reduced during the affected moves to keep within the limit. - * - * See http://marlinfw.org/docs/features/lin_advance.html for full instructions. - * Mention @Sebastianv650 on GitHub to alert the author of any issues. - */ -//#define LIN_ADVANCE -#if ENABLED(LIN_ADVANCE) - #define LIN_ADVANCE_K 0.22 // Unit: mm compression per 1mm/s extruder speed - //#define LA_DEBUG // If enabled, this will generate debug information output over USB. -#endif - -// @section leveling - -#if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL) - // Override the mesh area if the automatic (max) area is too large - //#define MESH_MIN_X MESH_INSET - //#define MESH_MIN_Y MESH_INSET - //#define MESH_MAX_X X_BED_SIZE - (MESH_INSET) - //#define MESH_MAX_Y Y_BED_SIZE - (MESH_INSET) -#endif - -/** - * Repeatedly attempt G29 leveling until it succeeds. - * Stop after G29_MAX_RETRIES attempts. - */ -//#define G29_RETRY_AND_RECOVER -#if ENABLED(G29_RETRY_AND_RECOVER) - #define G29_MAX_RETRIES 3 - #define G29_HALT_ON_FAILURE - /** - * Specify the GCODE commands that will be executed when leveling succeeds, - * between attempts, and after the maximum number of retries have been tried. - */ - #define G29_SUCCESS_COMMANDS "M117 Bed leveling done." - #define G29_RECOVER_COMMANDS "M117 Probe failed. Rewiping.\nG28\nG12 P0 S12 T0" - #define G29_FAILURE_COMMANDS "M117 Bed leveling failed.\nG0 Z10\nM300 P25 S880\nM300 P50 S0\nM300 P25 S880\nM300 P50 S0\nM300 P25 S880\nM300 P50 S0\nG4 S1" - /** - * Specify an action command to send to the host on a recovery attempt or failure. - * Will be sent in the form '//action:ACTION_ON_G29_FAILURE', e.g. '//action:probe_failed'. - * The host must be configured to handle the action command. - */ - #define G29_ACTION_ON_RECOVER "probe_rewipe" - #define G29_ACTION_ON_FAILURE "probe_failed" -#endif - -// @section extras - -// -// G2/G3 Arc Support -// -#define ARC_SUPPORT // Disable this feature to save ~3226 bytes -#if ENABLED(ARC_SUPPORT) - #define MM_PER_ARC_SEGMENT 1 // Length of each arc segment - #define N_ARC_CORRECTION 25 // Number of intertpolated segments between corrections - //#define ARC_P_CIRCLES // Enable the 'P' parameter to specify complete circles - //#define CNC_WORKSPACE_PLANES // Allow G2/G3 to operate in XY, ZX, or YZ planes -#endif - -// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes. -//#define BEZIER_CURVE_SUPPORT - -// G38.2 and G38.3 Probe Target -// Set MULTIPLE_PROBING if you want G38 to double touch -//#define G38_PROBE_TARGET -#if ENABLED(G38_PROBE_TARGET) - #define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move) -#endif - -// Moves (or segments) with fewer steps than this will be joined with the next move -#define MIN_STEPS_PER_SEGMENT 6 - -/** - * Minimum delay after setting the stepper DIR (in ns) - * 0 : No delay (Expect at least 10µS since one Stepper ISR must transpire) - * 20 : Minimum for TMC2xxx drivers - * 200 : Minimum for A4988 drivers - * 500 : Minimum for LV8729 drivers (guess, no info in datasheet) - * 650 : Minimum for DRV8825 drivers - * 1500 : Minimum for TB6600 drivers (guess, no info in datasheet) - * 15000 : Minimum for TB6560 drivers (guess, no info in datasheet) - * - * Override the default value based on the driver type set in Configuration.h. - */ -//#define MINIMUM_STEPPER_DIR_DELAY 650 - -/** - * Minimum stepper driver pulse width (in µs) - * 0 : Smallest possible width the MCU can produce, compatible with TMC2xxx drivers - * 1 : Minimum for A4988 stepper drivers - * 1 : Minimum for LV8729 stepper drivers - * 2 : Minimum for DRV8825 stepper drivers - * 3 : Minimum for TB6600 stepper drivers - * 30 : Minimum for TB6560 stepper drivers - * - * Override the default value based on the driver type set in Configuration.h. - */ -//#define MINIMUM_STEPPER_PULSE 2 - -/** - * Maximum stepping rate (in Hz) the stepper driver allows - * If undefined, defaults to 1MHz / (2 * MINIMUM_STEPPER_PULSE) - * 500000 : Maximum for A4988 stepper driver - * 400000 : Maximum for TMC2xxx stepper drivers - * 250000 : Maximum for DRV8825 stepper driver - * 150000 : Maximum for TB6600 stepper driver - * 130000 : Maximum for LV8729 stepper driver - * 15000 : Maximum for TB6560 stepper driver - * - * Override the default value based on the driver type set in Configuration.h. - */ -//#define MAXIMUM_STEPPER_RATE 250000 - -// @section temperature - -// Control heater 0 and heater 1 in parallel. -//#define HEATERS_PARALLEL - -//=========================================================================== -//================================= Buffers ================================= -//=========================================================================== - -// @section hidden - -// The number of linear motions that can be in the plan at any give time. -// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2 (e.g. 8, 16, 32) because shifts and ors are used to do the ring-buffering. -#if ENABLED(SDSUPPORT) - #define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller -#else - #define BLOCK_BUFFER_SIZE 16 // maximize block buffer -#endif - -// @section serial - -// The ASCII buffer for serial input -#define MAX_CMD_SIZE 96 -#define BUFSIZE 4 - -// Transmission to Host Buffer Size -// To save 386 bytes of PROGMEM (and TX_BUFFER_SIZE+3 bytes of RAM) set to 0. -// To buffer a simple "ok" you need 4 bytes. -// For ADVANCED_OK (M105) you need 32 bytes. -// For debug-echo: 128 bytes for the optimal speed. -// Other output doesn't need to be that speedy. -// :[0, 2, 4, 8, 16, 32, 64, 128, 256] -#define TX_BUFFER_SIZE 0 - -// Host Receive Buffer Size -// Without XON/XOFF flow control (see SERIAL_XON_XOFF below) 32 bytes should be enough. -// To use flow control, set this buffer size to at least 1024 bytes. -// :[0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048] -//#define RX_BUFFER_SIZE 1024 - -#if RX_BUFFER_SIZE >= 1024 - // Enable to have the controller send XON/XOFF control characters to - // the host to signal the RX buffer is becoming full. - //#define SERIAL_XON_XOFF -#endif - -#if ENABLED(SDSUPPORT) - // Enable this option to collect and display the maximum - // RX queue usage after transferring a file to SD. - //#define SERIAL_STATS_MAX_RX_QUEUED - - // Enable this option to collect and display the number - // of dropped bytes after a file transfer to SD. - //#define SERIAL_STATS_DROPPED_RX -#endif - -// Enable an emergency-command parser to intercept certain commands as they -// enter the serial receive buffer, so they cannot be blocked. -// Currently handles M108, M112, M410 -// Does not work on boards using AT90USB (USBCON) processors! -//#define EMERGENCY_PARSER - -// Bad Serial-connections can miss a received command by sending an 'ok' -// Therefore some clients abort after 30 seconds in a timeout. -// Some other clients start sending commands while receiving a 'wait'. -// This "wait" is only sent when the buffer is empty. 1 second is a good value here. -//#define NO_TIMEOUTS 1000 // Milliseconds - -// Some clients will have this feature soon. This could make the NO_TIMEOUTS unnecessary. -//#define ADVANCED_OK - -// @section extras - -/** - * Firmware-based and LCD-controlled retract - * - * Add G10 / G11 commands for automatic firmware-based retract / recover. - * Use M207 and M208 to define parameters for retract / recover. - * - * Use M209 to enable or disable auto-retract. - * With auto-retract enabled, all G1 E moves within the set range - * will be converted to firmware-based retract/recover moves. - * - * Be sure to turn off auto-retract during filament change. - * - * Note that M207 / M208 / M209 settings are saved to EEPROM. - * - */ -//#define FWRETRACT // ONLY PARTIALLY TESTED -#if ENABLED(FWRETRACT) - #define MIN_AUTORETRACT 0.1 // When auto-retract is on, convert E moves of this length and over - #define MAX_AUTORETRACT 10.0 // Upper limit for auto-retract conversion - #define RETRACT_LENGTH 3 // Default retract length (positive mm) - #define RETRACT_LENGTH_SWAP 13 // Default swap retract length (positive mm), for extruder change - #define RETRACT_FEEDRATE 45 // Default feedrate for retracting (mm/s) - #define RETRACT_ZLIFT 0 // Default retract Z-lift - #define RETRACT_RECOVER_LENGTH 0 // Default additional recover length (mm, added to retract length when recovering) - #define RETRACT_RECOVER_LENGTH_SWAP 0 // Default additional swap recover length (mm, added to retract length when recovering from extruder change) - #define RETRACT_RECOVER_FEEDRATE 8 // Default feedrate for recovering from retraction (mm/s) - #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // Default feedrate for recovering from swap retraction (mm/s) -#endif - -/** - * Extra Fan Speed - * Adds a secondary fan speed for each print-cooling fan. - * 'M106 P T3-255' : Set a secondary speed for - * 'M106 P T2' : Use the set secondary speed - * 'M106 P T1' : Restore the previous fan speed - */ -//#define EXTRA_FAN_SPEED - -/** - * Advanced Pause - * Experimental feature for filament change support and for parking the nozzle when paused. - * Adds the GCode M600 for initiating filament change. - * If PARK_HEAD_ON_PAUSE enabled, adds the GCode M125 to pause printing and park the nozzle. - * - * Requires an LCD display. - * Requires NOZZLE_PARK_FEATURE. - * This feature is required for the default FILAMENT_RUNOUT_SCRIPT. - */ -//#define ADVANCED_PAUSE_FEATURE -#if ENABLED(ADVANCED_PAUSE_FEATURE) - #define PAUSE_PARK_RETRACT_FEEDRATE 60 // (mm/s) Initial retract feedrate. - #define PAUSE_PARK_RETRACT_LENGTH 2 // (mm) Initial retract. - // This short retract is done immediately, before parking the nozzle. - #define FILAMENT_CHANGE_UNLOAD_FEEDRATE 10 // (mm/s) Unload filament feedrate. This can be pretty fast. - #define FILAMENT_CHANGE_UNLOAD_ACCEL 25 // (mm/s^2) Lower acceleration may allow a faster feedrate. - #define FILAMENT_CHANGE_UNLOAD_LENGTH 100 // (mm) The length of filament for a complete unload. - // For Bowden, the full length of the tube and nozzle. - // For direct drive, the full length of the nozzle. - // Set to 0 for manual unloading. - #define FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE 6 // (mm/s) Slow move when starting load. - #define FILAMENT_CHANGE_SLOW_LOAD_LENGTH 0 // (mm) Slow length, to allow time to insert material. - // 0 to disable start loading and skip to fast load only - #define FILAMENT_CHANGE_FAST_LOAD_FEEDRATE 6 // (mm/s) Load filament feedrate. This can be pretty fast. - #define FILAMENT_CHANGE_FAST_LOAD_ACCEL 25 // (mm/s^2) Lower acceleration may allow a faster feedrate. - #define FILAMENT_CHANGE_FAST_LOAD_LENGTH 0 // (mm) Load length of filament, from extruder gear to nozzle. - // For Bowden, the full length of the tube and nozzle. - // For direct drive, the full length of the nozzle. - //#define ADVANCED_PAUSE_CONTINUOUS_PURGE // Purge continuously up to the purge length until interrupted. - #define ADVANCED_PAUSE_PURGE_FEEDRATE 3 // (mm/s) Extrude feedrate (after loading). Should be slower than load feedrate. - #define ADVANCED_PAUSE_PURGE_LENGTH 50 // (mm) Length to extrude after loading. - // Set to 0 for manual extrusion. - // Filament can be extruded repeatedly from the Filament Change menu - // until extrusion is consistent, and to purge old filament. - - // Filament Unload does a Retract, Delay, and Purge first: - #define FILAMENT_UNLOAD_RETRACT_LENGTH 13 // (mm) Unload initial retract length. - #define FILAMENT_UNLOAD_DELAY 5000 // (ms) Delay for the filament to cool after retract. - #define FILAMENT_UNLOAD_PURGE_LENGTH 8 // (mm) An unretract is done, then this length is purged. - - #define PAUSE_PARK_NOZZLE_TIMEOUT 45 // (seconds) Time limit before the nozzle is turned off for safety. - #define FILAMENT_CHANGE_ALERT_BEEPS 10 // Number of alert beeps to play when a response is needed. - #define PAUSE_PARK_NO_STEPPER_TIMEOUT // Enable for XYZ steppers to stay powered on during filament change. - - //#define PARK_HEAD_ON_PAUSE // Park the nozzle during pause and filament change. - //#define HOME_BEFORE_FILAMENT_CHANGE // Ensure homing has been completed prior to parking for filament change - - //#define FILAMENT_LOAD_UNLOAD_GCODES // Add M701/M702 Load/Unload G-codes, plus Load/Unload in the LCD Prepare menu. - //#define FILAMENT_UNLOAD_ALL_EXTRUDERS // Allow M702 to unload all extruders above a minimum target temp (as set by M302) -#endif - -// @section tmc - -/** - * TMC26X Stepper Driver options - * - * The TMC26XStepper library is required for this stepper driver. - * https://github.com/trinamic/TMC26XStepper - */ -#if HAS_DRIVER(TMC26X) - - #define X_MAX_CURRENT 1000 // in mA - #define X_SENSE_RESISTOR 91 // in mOhms - #define X_MICROSTEPS 16 // number of microsteps - - #define X2_MAX_CURRENT 1000 - #define X2_SENSE_RESISTOR 91 - #define X2_MICROSTEPS 16 - - #define Y_MAX_CURRENT 1000 - #define Y_SENSE_RESISTOR 91 - #define Y_MICROSTEPS 16 - - #define Y2_MAX_CURRENT 1000 - #define Y2_SENSE_RESISTOR 91 - #define Y2_MICROSTEPS 16 - - #define Z_MAX_CURRENT 1000 - #define Z_SENSE_RESISTOR 91 - #define Z_MICROSTEPS 16 - - #define Z2_MAX_CURRENT 1000 - #define Z2_SENSE_RESISTOR 91 - #define Z2_MICROSTEPS 16 - - #define E0_MAX_CURRENT 1000 - #define E0_SENSE_RESISTOR 91 - #define E0_MICROSTEPS 16 - - #define E1_MAX_CURRENT 1000 - #define E1_SENSE_RESISTOR 91 - #define E1_MICROSTEPS 16 - - #define E2_MAX_CURRENT 1000 - #define E2_SENSE_RESISTOR 91 - #define E2_MICROSTEPS 16 - - #define E3_MAX_CURRENT 1000 - #define E3_SENSE_RESISTOR 91 - #define E3_MICROSTEPS 16 - - #define E4_MAX_CURRENT 1000 - #define E4_SENSE_RESISTOR 91 - #define E4_MICROSTEPS 16 - -#endif // TMC26X - -// @section tmc_smart - -/** - * To use TMC2130 stepper drivers in SPI mode connect your SPI pins to - * the hardware SPI interface on your board and define the required CS pins - * in your `pins_MYBOARD.h` file. (e.g., RAMPS 1.4 uses AUX3 pins `X_CS_PIN 53`, `Y_CS_PIN 49`, etc.). - * You may also use software SPI if you wish to use general purpose IO pins. - * - * The TMC2130Stepper library is required for this stepper driver. - * https://github.com/teemuatlut/TMC2130Stepper - * - * To use TMC2208 stepper UART-configurable stepper drivers - * connect #_SERIAL_TX_PIN to the driver side PDN_UART pin with a 1K resistor. - * To use the reading capabilities, also connect #_SERIAL_RX_PIN - * to PDN_UART without a resistor. - * The drivers can also be used with hardware serial. - * - * The TMC2208Stepper library is required for this stepper driver. - * https://github.com/teemuatlut/TMC2208Stepper - */ -#if HAS_TRINAMIC - - #define R_SENSE 0.11 // R_sense resistor for SilentStepStick2130 - #define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current - #define INTERPOLATE true // Interpolate X/Y/Z_MICROSTEPS to 256 - - #define X_CURRENT 800 // rms current in mA. Multiply by 1.41 for peak current. - #define X_MICROSTEPS 16 // 0..256 - - #define Y_CURRENT 800 - #define Y_MICROSTEPS 16 - - #define Z_CURRENT 800 - #define Z_MICROSTEPS 16 - - #define X2_CURRENT 800 - #define X2_MICROSTEPS 16 - - #define Y2_CURRENT 800 - #define Y2_MICROSTEPS 16 - - #define Z2_CURRENT 800 - #define Z2_MICROSTEPS 16 - - #define E0_CURRENT 800 - #define E0_MICROSTEPS 16 - - #define E1_CURRENT 800 - #define E1_MICROSTEPS 16 - - #define E2_CURRENT 800 - #define E2_MICROSTEPS 16 - - #define E3_CURRENT 800 - #define E3_MICROSTEPS 16 - - #define E4_CURRENT 800 - #define E4_MICROSTEPS 16 - - /** - * Use software SPI for TMC2130. - * The default SW SPI pins are defined the respective pins files, - * but you can override or define them here. - */ - //#define TMC_USE_SW_SPI - //#define TMC_SW_MOSI -1 - //#define TMC_SW_MISO -1 - //#define TMC_SW_SCK -1 - - /** - * Use Trinamic's ultra quiet stepping mode. - * When disabled, Marlin will use spreadCycle stepping mode. - */ - #define STEALTHCHOP - - /** - * Monitor Trinamic TMC2130 and TMC2208 drivers for error conditions, - * like overtemperature and short to ground. TMC2208 requires hardware serial. - * In the case of overtemperature Marlin can decrease the driver current until error condition clears. - * Other detected conditions can be used to stop the current print. - * Relevant g-codes: - * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. - * M911 - Report stepper driver overtemperature pre-warn condition. - * M912 - Clear stepper driver overtemperature pre-warn condition flag. - * M122 S0/1 - Report driver parameters (Requires TMC_DEBUG) - */ - //#define MONITOR_DRIVER_STATUS - - #if ENABLED(MONITOR_DRIVER_STATUS) - #define CURRENT_STEP_DOWN 50 // [mA] - #define REPORT_CURRENT_CHANGE - #define STOP_ON_ERROR - #endif - - /** - * The driver will switch to spreadCycle when stepper speed is over HYBRID_THRESHOLD. - * This mode allows for faster movements at the expense of higher noise levels. - * STEALTHCHOP needs to be enabled. - * M913 X/Y/Z/E to live tune the setting - */ - //#define HYBRID_THRESHOLD - - #define X_HYBRID_THRESHOLD 100 // [mm/s] - #define X2_HYBRID_THRESHOLD 100 - #define Y_HYBRID_THRESHOLD 100 - #define Y2_HYBRID_THRESHOLD 100 - #define Z_HYBRID_THRESHOLD 3 - #define Z2_HYBRID_THRESHOLD 3 - #define E0_HYBRID_THRESHOLD 30 - #define E1_HYBRID_THRESHOLD 30 - #define E2_HYBRID_THRESHOLD 30 - #define E3_HYBRID_THRESHOLD 30 - #define E4_HYBRID_THRESHOLD 30 - - /** - * Use stallGuard2 to sense an obstacle and trigger an endstop. - * You need to place a wire from the driver's DIAG1 pin to the X/Y endstop pin. - * X, Y, and Z homing will always be done in spreadCycle mode. - * - * X/Y/Z_HOMING_SENSITIVITY is used for tuning the trigger sensitivity. - * Higher values make the system LESS sensitive. - * Lower value make the system MORE sensitive. - * Too low values can lead to false positives, while too high values will collide the axis without triggering. - * It is advised to set X/Y/Z_HOME_BUMP_MM to 0. - * M914 X/Y/Z to live tune the setting - */ - //#define SENSORLESS_HOMING // TMC2130 only - - #if ENABLED(SENSORLESS_HOMING) - #define X_HOMING_SENSITIVITY 8 - #define Y_HOMING_SENSITIVITY 8 - #define Z_HOMING_SENSITIVITY 8 - #endif - - /** - * Enable M122 debugging command for TMC stepper drivers. - * M122 S0/1 will enable continous reporting. - */ - //#define TMC_DEBUG - - /** - * M915 Z Axis Calibration - * - * - Adjust Z stepper current, - * - Drive the Z axis to its physical maximum, and - * - Home Z to account for the lost steps. - * - * Use M915 Snn to specify the current. - * Use M925 Znn to add extra Z height to Z_MAX_POS. - */ - //#define TMC_Z_CALIBRATION - #if ENABLED(TMC_Z_CALIBRATION) - #define CALIBRATION_CURRENT 250 - #define CALIBRATION_EXTRA_HEIGHT 10 - #endif - - /** - * You can set your own advanced settings by filling in predefined functions. - * A list of available functions can be found on the library github page - * https://github.com/teemuatlut/TMC2130Stepper - * https://github.com/teemuatlut/TMC2208Stepper - * - * Example: - * #define TMC_ADV() { \ - * stepperX.diag0_temp_prewarn(1); \ - * stepperY.interpolate(0); \ - * } - */ - #define TMC_ADV() { } - -#endif // TMC2130 || TMC2208 - -// @section L6470 - -/** - * L6470 Stepper Driver options - * - * The Arduino-L6470 library is required for this stepper driver. - * https://github.com/ameyer/Arduino-L6470 - */ -#if HAS_DRIVER(L6470) - - #define X_MICROSTEPS 16 // number of microsteps - #define X_OVERCURRENT 2000 // maxc current in mA. If the current goes over this value, the driver will switch off - #define X_STALLCURRENT 1500 // current in mA where the driver will detect a stall - - #define X2_MICROSTEPS 16 - #define X2_OVERCURRENT 2000 - #define X2_STALLCURRENT 1500 - - #define Y_MICROSTEPS 16 - #define Y_OVERCURRENT 2000 - #define Y_STALLCURRENT 1500 - - #define Y2_MICROSTEPS 16 - #define Y2_OVERCURRENT 2000 - #define Y2_STALLCURRENT 1500 - - #define Z_MICROSTEPS 16 - #define Z_OVERCURRENT 2000 - #define Z_STALLCURRENT 1500 - - #define Z2_MICROSTEPS 16 - #define Z2_OVERCURRENT 2000 - #define Z2_STALLCURRENT 1500 - - #define E0_MICROSTEPS 16 - #define E0_OVERCURRENT 2000 - #define E0_STALLCURRENT 1500 - - #define E1_MICROSTEPS 16 - #define E1_OVERCURRENT 2000 - #define E1_STALLCURRENT 1500 - - #define E2_MICROSTEPS 16 - #define E2_OVERCURRENT 2000 - #define E2_STALLCURRENT 1500 - - #define E3_MICROSTEPS 16 - #define E3_OVERCURRENT 2000 - #define E3_STALLCURRENT 1500 - - #define E4_MICROSTEPS 16 - #define E4_OVERCURRENT 2000 - #define E4_STALLCURRENT 1500 - -#endif // L6470 - -/** - * TWI/I2C BUS - * - * This feature is an EXPERIMENTAL feature so it shall not be used on production - * machines. Enabling this will allow you to send and receive I2C data from slave - * devices on the bus. - * - * ; Example #1 - * ; This macro send the string "Marlin" to the slave device with address 0x63 (99) - * ; It uses multiple M260 commands with one B arg - * M260 A99 ; Target slave address - * M260 B77 ; M - * M260 B97 ; a - * M260 B114 ; r - * M260 B108 ; l - * M260 B105 ; i - * M260 B110 ; n - * M260 S1 ; Send the current buffer - * - * ; Example #2 - * ; Request 6 bytes from slave device with address 0x63 (99) - * M261 A99 B5 - * - * ; Example #3 - * ; Example serial output of a M261 request - * echo:i2c-reply: from:99 bytes:5 data:hello - */ - -// @section i2cbus - -//#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave - -// @section extras - -/** - * Spindle & Laser control - * - * Add the M3, M4, and M5 commands to turn the spindle/laser on and off, and - * to set spindle speed, spindle direction, and laser power. - * - * SuperPid is a router/spindle speed controller used in the CNC milling community. - * Marlin can be used to turn the spindle on and off. It can also be used to set - * the spindle speed from 5,000 to 30,000 RPM. - * - * You'll need to select a pin for the ON/OFF function and optionally choose a 0-5V - * hardware PWM pin for the speed control and a pin for the rotation direction. - * - * See http://marlinfw.org/docs/configuration/laser_spindle.html for more config details. - */ -//#define SPINDLE_LASER_ENABLE -#if ENABLED(SPINDLE_LASER_ENABLE) - - #define SPINDLE_LASER_ENABLE_INVERT false // set to "true" if the on/off function is reversed - #define SPINDLE_LASER_PWM true // set to true if your controller supports setting the speed/power - #define SPINDLE_LASER_PWM_INVERT true // set to "true" if the speed/power goes up when you want it to go slower - #define SPINDLE_LASER_POWERUP_DELAY 5000 // delay in milliseconds to allow the spindle/laser to come up to speed/power - #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // delay in milliseconds to allow the spindle to stop - #define SPINDLE_DIR_CHANGE true // set to true if your spindle controller supports changing spindle direction - #define SPINDLE_INVERT_DIR false - #define SPINDLE_STOP_ON_DIR_CHANGE true // set to true if Marlin should stop the spindle before changing rotation direction - - /** - * The M3 & M4 commands use the following equation to convert PWM duty cycle to speed/power - * - * SPEED/POWER = PWM duty cycle * SPEED_POWER_SLOPE + SPEED_POWER_INTERCEPT - * where PWM duty cycle varies from 0 to 255 - * - * set the following for your controller (ALL MUST BE SET) - */ - - #define SPEED_POWER_SLOPE 118.4 - #define SPEED_POWER_INTERCEPT 0 - #define SPEED_POWER_MIN 5000 - #define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM - - //#define SPEED_POWER_SLOPE 0.3922 - //#define SPEED_POWER_INTERCEPT 0 - //#define SPEED_POWER_MIN 10 - //#define SPEED_POWER_MAX 100 // 0-100% -#endif - -/** - * Filament Width Sensor - * - * Measures the filament width in real-time and adjusts - * flow rate to compensate for any irregularities. - * - * Also allows the measured filament diameter to set the - * extrusion rate, so the slicer only has to specify the - * volume. - * - * Only a single extruder is supported at this time. - * - * 34 RAMPS_14 : Analog input 5 on the AUX2 connector - * 81 PRINTRBOARD : Analog input 2 on the Exp1 connector (version B,C,D,E) - * 301 RAMBO : Analog input 3 - * - * Note: May require analog pins to be defined for other boards. - */ -//#define FILAMENT_WIDTH_SENSOR - -#if ENABLED(FILAMENT_WIDTH_SENSOR) - #define FILAMENT_SENSOR_EXTRUDER_NUM 0 // Index of the extruder that has the filament sensor. :[0,1,2,3,4] - #define MEASUREMENT_DELAY_CM 14 // (cm) The distance from the filament sensor to the melting chamber - - #define FILWIDTH_ERROR_MARGIN 1.0 // (mm) If a measurement differs too much from nominal width ignore it - #define MAX_MEASUREMENT_DELAY 20 // (bytes) Buffer size for stored measurements (1 byte per cm). Must be larger than MEASUREMENT_DELAY_CM. - - #define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA // Set measured to nominal initially - - // Display filament width on the LCD status line. Status messages will expire after 5 seconds. - //#define FILAMENT_LCD_DISPLAY -#endif - -/** - * CNC Coordinate Systems - * - * Enables G53 and G54-G59.3 commands to select coordinate systems - * and G92.1 to reset the workspace to native machine space. - */ -//#define CNC_COORDINATE_SYSTEMS - -/** - * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins - */ -//#define PINS_DEBUGGING - -/** - * Auto-report temperatures with M155 S - */ -#define AUTO_REPORT_TEMPERATURES - -/** - * Include capabilities in M115 output - */ -#define EXTENDED_CAPABILITIES_REPORT - -/** - * Disable all Volumetric extrusion options - */ -//#define NO_VOLUMETRICS - -#if DISABLED(NO_VOLUMETRICS) - /** - * Volumetric extrusion default state - * Activate to make volumetric extrusion the default method, - * with DEFAULT_NOMINAL_FILAMENT_DIA as the default diameter. - * - * M200 D0 to disable, M200 Dn to set a new diameter. - */ - //#define VOLUMETRIC_DEFAULT_ON -#endif - -/** - * Enable this option for a leaner build of Marlin that removes all - * workspace offsets, simplifying coordinate transformations, leveling, etc. - * - * - M206 and M428 are disabled. - * - G92 will revert to its behavior from Marlin 1.0. - */ -//#define NO_WORKSPACE_OFFSETS - -/** - * Set the number of proportional font spaces required to fill up a typical character space. - * This can help to better align the output of commands like `G29 O` Mesh Output. - * - * For clients that use a fixed-width font (like OctoPrint), leave this set to 1.0. - * Otherwise, adjust according to your client and font. - */ -#define PROPORTIONAL_FONT_RATIO 1.0 - -/** - * Spend 28 bytes of SRAM to optimize the GCode parser - */ -#define FASTER_GCODE_PARSER - -/** - * User-defined menu items that execute custom GCode - */ -//#define CUSTOM_USER_MENUS -#if ENABLED(CUSTOM_USER_MENUS) - #define USER_SCRIPT_DONE "M117 User Script Done" - #define USER_SCRIPT_AUDIBLE_FEEDBACK - //#define USER_SCRIPT_RETURN // Return to status screen after a script - - #define USER_DESC_1 "Home & UBL Info" - #define USER_GCODE_1 "G28\nG29 W" - - #define USER_DESC_2 "Preheat for PLA" - #define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) - - #define USER_DESC_3 "Preheat for ABS" - #define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) - - #define USER_DESC_4 "Heat Bed/Home/Level" - #define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29" - - #define USER_DESC_5 "Home & Info" - #define USER_GCODE_5 "G28\nM503" -#endif - -/** - * Specify an action command to send to the host when the printer is killed. - * Will be sent in the form '//action:ACTION_ON_KILL', e.g. '//action:poweroff'. - * The host must be configured to handle the action command. - */ -//#define ACTION_ON_KILL "poweroff" - -/** - * Specify an action command to send to the host on pause and resume. - * Will be sent in the form '//action:ACTION_ON_PAUSE', e.g. '//action:pause'. - * The host must be configured to handle the action command. - */ -//#define ACTION_ON_PAUSE "pause" -//#define ACTION_ON_RESUME "resume" - -//=========================================================================== -//====================== I2C Position Encoder Settings ====================== -//=========================================================================== - -/** - * I2C position encoders for closed loop control. - * Developed by Chris Barr at Aus3D. - * - * Wiki: http://wiki.aus3d.com.au/Magnetic_Encoder - * Github: https://github.com/Aus3D/MagneticEncoder - * - * Supplier: http://aus3d.com.au/magnetic-encoder-module - * Alternative Supplier: http://reliabuild3d.com/ - * - * Reilabuild encoders have been modified to improve reliability. - */ - -//#define I2C_POSITION_ENCODERS -#if ENABLED(I2C_POSITION_ENCODERS) - - #define I2CPE_ENCODER_CNT 1 // The number of encoders installed; max of 5 - // encoders supported currently. - - #define I2CPE_ENC_1_ADDR I2CPE_PRESET_ADDR_X // I2C address of the encoder. 30-200. - #define I2CPE_ENC_1_AXIS X_AXIS // Axis the encoder module is installed on. _AXIS. - #define I2CPE_ENC_1_TYPE I2CPE_ENC_TYPE_LINEAR // Type of encoder: I2CPE_ENC_TYPE_LINEAR -or- - // I2CPE_ENC_TYPE_ROTARY. - #define I2CPE_ENC_1_TICKS_UNIT 2048 // 1024 for magnetic strips with 2mm poles; 2048 for - // 1mm poles. For linear encoders this is ticks / mm, - // for rotary encoders this is ticks / revolution. - //#define I2CPE_ENC_1_TICKS_REV (16 * 200) // Only needed for rotary encoders; number of stepper - // steps per full revolution (motor steps/rev * microstepping) - //#define I2CPE_ENC_1_INVERT // Invert the direction of axis travel. - #define I2CPE_ENC_1_EC_METHOD I2CPE_ECM_MICROSTEP // Type of error error correction. - #define I2CPE_ENC_1_EC_THRESH 0.10 // Threshold size for error (in mm) above which the - // printer will attempt to correct the error; errors - // smaller than this are ignored to minimize effects of - // measurement noise / latency (filter). - - #define I2CPE_ENC_2_ADDR I2CPE_PRESET_ADDR_Y // Same as above, but for encoder 2. - #define I2CPE_ENC_2_AXIS Y_AXIS - #define I2CPE_ENC_2_TYPE I2CPE_ENC_TYPE_LINEAR - #define I2CPE_ENC_2_TICKS_UNIT 2048 - //#define I2CPE_ENC_2_TICKS_REV (16 * 200) - //#define I2CPE_ENC_2_INVERT - #define I2CPE_ENC_2_EC_METHOD I2CPE_ECM_MICROSTEP - #define I2CPE_ENC_2_EC_THRESH 0.10 - - #define I2CPE_ENC_3_ADDR I2CPE_PRESET_ADDR_Z // Encoder 3. Add additional configuration options - #define I2CPE_ENC_3_AXIS Z_AXIS // as above, or use defaults below. - - #define I2CPE_ENC_4_ADDR I2CPE_PRESET_ADDR_E // Encoder 4. - #define I2CPE_ENC_4_AXIS E_AXIS - - #define I2CPE_ENC_5_ADDR 34 // Encoder 5. - #define I2CPE_ENC_5_AXIS E_AXIS - - // Default settings for encoders which are enabled, but without settings configured above. - #define I2CPE_DEF_TYPE I2CPE_ENC_TYPE_LINEAR - #define I2CPE_DEF_ENC_TICKS_UNIT 2048 - #define I2CPE_DEF_TICKS_REV (16 * 200) - #define I2CPE_DEF_EC_METHOD I2CPE_ECM_NONE - #define I2CPE_DEF_EC_THRESH 0.1 - - //#define I2CPE_ERR_THRESH_ABORT 100.0 // Threshold size for error (in mm) error on any given - // axis after which the printer will abort. Comment out to - // disable abort behaviour. - - #define I2CPE_TIME_TRUSTED 10000 // After an encoder fault, there must be no further fault - // for this amount of time (in ms) before the encoder - // is trusted again. - - /** - * Position is checked every time a new command is executed from the buffer but during long moves, - * this setting determines the minimum update time between checks. A value of 100 works well with - * error rolling average when attempting to correct only for skips and not for vibration. - */ - #define I2CPE_MIN_UPD_TIME_MS 4 // (ms) Minimum time between encoder checks. - - // Use a rolling average to identify persistant errors that indicate skips, as opposed to vibration and noise. - #define I2CPE_ERR_ROLLING_AVERAGE - -#endif // I2C_POSITION_ENCODERS - -/** - * MAX7219 Debug Matrix - * - * Add support for a low-cost 8x8 LED Matrix based on the Max7219 chip as a realtime status display. - * Requires 3 signal wires. Some useful debug options are included to demonstrate its usage. - */ -//#define MAX7219_DEBUG -#if ENABLED(MAX7219_DEBUG) - #define MAX7219_CLK_PIN 64 - #define MAX7219_DIN_PIN 57 - #define MAX7219_LOAD_PIN 44 - - //#define MAX7219_GCODE // Add the M7219 G-code to control the LED matrix - #define MAX7219_INIT_TEST 2 // Do a test pattern at initialization (Set to 2 for spiral) - #define MAX7219_NUMBER_UNITS 1 // Number of Max7219 units in chain. - #define MAX7219_ROTATE 0 // Rotate the display clockwise (in multiples of +/- 90°) - // connector at: right=0 bottom=-90 top=90 left=180 - - /** - * Sample debug features - * If you add more debug displays, be careful to avoid conflicts! - */ - #define MAX7219_DEBUG_PRINTER_ALIVE // Blink corner LED of 8x8 matrix to show that the firmware is functioning - #define MAX7219_DEBUG_PLANNER_HEAD 3 // Show the planner queue head position on this and the next LED matrix row - #define MAX7219_DEBUG_PLANNER_TAIL 5 // Show the planner queue tail position on this and the next LED matrix row - - #define MAX7219_DEBUG_PLANNER_QUEUE 0 // Show the current planner queue depth on this and the next LED matrix row - // If you experience stuttering, reboots, etc. this option can reveal how - // tweaks made to the configuration are affecting the printer in real-time. -#endif - -/** - * NanoDLP Sync support - * - * Add support for Synchronized Z moves when using with NanoDLP. G0/G1 axis moves will output "Z_move_comp" - * string to enable synchronization with DLP projector exposure. This change will allow to use - * [[WaitForDoneMessage]] instead of populating your gcode with M400 commands - */ -//#define NANODLP_Z_SYNC -#if ENABLED(NANODLP_Z_SYNC) - //#define NANODLP_ALL_AXIS // Enables "Z_move_comp" output on any axis move. - // Default behaviour is limited to Z axis only. -#endif - -/** - * WiFi Support (Espressif ESP32 WiFi) - */ -//#define WIFISUPPORT -#if ENABLED(WIFISUPPORT) - #define WIFI_SSID "Wifi SSID" - #define WIFI_PWD "Wifi Password" -#endif - -// Enable Marlin dev mode which adds some special commands -//#define MARLIN_DEV_MODE - -#endif // CONFIGURATION_ADV_H diff --git a/Marlin/src/pins/pins_RURAMPS4D.h b/Marlin/src/pins/pins_RURAMPS4D.h deleted file mode 100644 index 4f4ad0977e..0000000000 --- a/Marlin/src/pins/pins_RURAMPS4D.h +++ /dev/null @@ -1,253 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 . - * - * Ported sys0724 & Vynt - */ - -/** - * Arduino Mega? or Due with RuRAMPS4DUE pin assignments - * - * Applies to the following boards: - * RURAMPS4DUE (Hotend0, Hotend1, Hotend2, Fan0, Fan1, Bed) - * - * Differences between - * RADDS | RuRAMPS4DUE - * | - */ - -#ifndef __SAM3X8E__ - #error "Oops! Make sure you have 'Arduino Due' selected from the 'Tools -> Boards' menu." -#endif - -#ifndef BOARD_NAME - #define BOARD_NAME "RuRAMPS4Due" -#endif - -// -// Limit Switches -// -#define X_MIN_PIN 45 -#define X_MAX_PIN 39 -#define Y_MIN_PIN 46 -#define Y_MAX_PIN 41 -#define Z_MIN_PIN 47 -#define Z_MAX_PIN 43 - -// -// Z Probe (when not Z_MIN_PIN) -// -#ifndef Z_MIN_PROBE_PIN - #define Z_MIN_PROBE_PIN 43 -#endif - -// -// Steppers -// -#define X_STEP_PIN 37 // Support Extension Board -#define X_DIR_PIN 36 -#define X_ENABLE_PIN 38 - -#define Y_STEP_PIN 32 // Support Extension Board -#define Y_DIR_PIN 35 -#define Y_ENABLE_PIN 34 - -#define Z_STEP_PIN 30 // Support Extension Board -#define Z_DIR_PIN 2 -#define Z_ENABLE_PIN 33 - -#define E0_STEP_PIN 29 -#define E0_DIR_PIN 28 -#define E0_ENABLE_PIN 31 - -#define E1_STEP_PIN 22 -#define E1_DIR_PIN 24 -#define E1_ENABLE_PIN 26 - -#define E2_STEP_PIN 25 -#define E2_DIR_PIN 23 -#define E2_ENABLE_PIN 27 - -#define E3_STEP_PIN 15 // Only For Extension Board -#define E3_DIR_PIN 14 -#define E3_ENABLE_PIN 61 - -//#define X_CS_PIN -1 -//#define Y_CS_PIN -1 -//#define Z_CS_PIN -1 -//#define E0_CS_PIN -1 -//#define E1_CS_PIN -1 -//#define E2_CS_PIN -1 -//#define E3_CS_PIN -1 - -// For Future: Microstepping pins - Mapping not from fastio.h (?) -//#define E3_MS1_PIN ? -//#define E3_MS2_PIN ? -//#define E3_MS3_PIN ? -//#define Z2_MS1_PIN ? // shared with E3_MS1_PIN -//#define Z2_MS2_PIN ? // shared with E3_MS2_PIN -//#define Z2_MS3_PIN ? // shared with E3_MS3_PIN - -#if DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) - #define Z_MIN_PROBE_PIN 49 -#endif - -#if ENABLED(FILAMENT_RUNOUT_SENSOR) - #ifndef FIL_RUNOUT_PIN - #define FIL_RUNOUT_PIN Y_MIN_PIN - #endif -#endif - -// -// Heaters / Fans -// -#define HEATER_0_PIN 13 -#define HEATER_1_PIN 12 -#define HEATER_2_PIN 11 -#define HEATER_BED_PIN 7 // BED H1 - -#ifndef FAN_PIN - #define FAN_PIN 9 -#endif -#define FAN1_PIN 8 -#define CONTROLLER_FAN_PIN -1 - -// -// Temperature Sensors -// -#define TEMP_0_PIN 0 // ANALOG A0 -#define TEMP_1_PIN 1 // ANALOG A1 -#define TEMP_2_PIN 2 // ANALOG A2 -#define TEMP_3_PIN 3 // ANALOG A2 -#define TEMP_BED_PIN 4 // ANALOG A3 -//Thermocouple Use Analog Pins -#if ENABLED(VER_WITH_THERMOCOUPLE) // If Nead, define is in Configuration.h - #define TEMP_4_PIN 5 // A5 - #define TEMP_5_PIN 6 // A6 (Marlin 2.0 not support) -#endif - -// SPI for Max6675 or Max31855 Thermocouple -//#if DISABLED(SDSUPPORT) -// #define MAX6675_SS 53 -//#else -// #define MAX6675_SS 49 -//#endif - -// -// Servos -// -#define SERVO0_PIN 5 -#define SERVO1_PIN 3 -#define SERVO2_PIN -1 -#define SERVO3_PIN -1 - -// -// Misc. Functions -// -#define SDSS 4 // 4,10,52 if using HW SPI. -#define LED_PIN -1 // 13 - HEATER_0_PIN -#define PS_ON_PIN -1 // 65 - -// MKS TFT / Nextion Use internal USART-1 -#define TFT_LCD_MODULE_COM 1 -#define TFT_LCD_MODULE_BAUDRATE 115600 - -// ESP WiFi Use internal USART-2 -#define ESP_WIFI_MODULE_COM 2 -#define ESP_WIFI_MODULE_BAUDRATE 115600 -#define ESP_WIFI_MODULE_RESET_PIN -1 -#define PIGGY_GPIO_PIN -1 - -// -// EEPROM -// -#define E2END 0x7FFF // 32Kb (24lc256) -#define I2C_EEPROM // EEPROM on I2C-0 -//#define EEPROM_SD // EEPROM on SDCARD -//#define SPI_EEPROM // EEPROM on SPI-0 -//#define SPI_CHAN_EEPROM1 ? -//#define SPI_EEPROM1_CS ? -// 2K EEPROM -//#define SPI_EEPROM2_CS ? -// 32Mb FLASH -//#define SPI_FLASH_CS ? - -// -// LCD / Controller -// -#if ENABLED(ULTRA_LCD) - - #if ENABLED(RADDS_DISPLAY) || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) - - #define LCD_PINS_RS 63 - #define LCD_PINS_ENABLE 64 - #define LCD_PINS_D4 48 - #define LCD_PINS_D5 50 - #define LCD_PINS_D6 52 - #define LCD_PINS_D7 53 - - #define BEEPER_PIN 62 - - #define BTN_EN1 44 - #define BTN_EN2 42 - #define BTN_ENC 40 - - #define SD_DETECT_PIN 51 - - #elif ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) - - #define LCD_PINS_RS 52 - #define LCD_PINS_ENABLE 53 - #define LCD_PINS_D4 48 - #define LCD_PINS_D5 50 - #define LCD_PINS_D6 52 - #define LCD_PINS_D7 53 - - #define BEEPER_PIN 62 - - #if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) - #define BTN_EN1 44 - #define BTN_EN2 42 - #define BTN_ENC 40 - #define SD_DETECT_PIN 51 - #endif - - #elif ENABLED(SSD1306_OLED_I2C_CONTROLLER) - - #define BTN_EN1 44 - #define BTN_EN2 42 - #define BTN_ENC 40 - #define BEEPER_PIN 62 - #define LCD_SDSS 10 - #define SD_DETECT_PIN 51 - - #elif ENABLED(SPARK_FULL_GRAPHICS) - - //http://doku.radds.org/dokumentation/other-electronics/sparklcd/ - #error "Oops! SPARK_FULL_GRAPHICS not supported with RURAMPS4D." - //#define LCD_PINS_D4 29//? - //#define LCD_PINS_ENABLE 27//? - //#define LCD_PINS_RS 25//? - //#define BTN_EN1 35//? - //#define BTN_EN2 33//? - //#define BTN_ENC 37//? - - #endif // SPARK_FULL_GRAPHICS - -#endif // ULTRA_LCD