You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ender3V2S1/Marlin/src/HAL/AVR/HAL.cpp

190 lines
5.8 KiB
C++

**New Year 2024 (20240107)** * The background of hot-end icon and bed icon blinks when they are being heating * Fix for https://github.com/mriscoc/Ender3V2S1/issues/1175 * Adds mesh inset to the mesh validation test * Fix screen background in trammingWizard regardless an error in the first corner **New in source code:** * Enabled M48 menu item only if Z_MIN_PROBE_REPEATABILITY_TEST is enabled * Moves Bed size menu items after XY MIN/MAX position * Enables the storage of parameters in the EEPROM only if the respective feature is enabled **From Marlin Bugfix** * Slimmer null T command (#26615) * Followup to optional M111/M115 (#26626) * Fix hangs in DUE native USB (#26572) * Fix Bed PID Autotune output (#26606) * CONFIGURE_FILAMENT_CHANGE - Optional M603 (#26613) * I3DBEE TECH Beez Mini 12864 (#26596) * Options to slim M111, remove M115 (#26603) * BSD string workaround (#26532) * Fix homing with FT_MOTION (#26595) * Fix, extend FAN / AUTOFAN confict check (#26591) * BigTreeTech Manta M8P V2.0 (STM32H723ZE) (#26578) * Optimize FT_MOTION (#26557) * TriGorilla Pro default to ONBOARD_SDIO (#26586) * Specify U8glib-HAL@0.5.4 (#26582) * Newer Platform & Toolchain for STM32G0 (#26585) * Initial support for HC32 U8G LCD (#26568) * Move U8G defines to HALs * BigTreeTech Kraken V1.0 (STM32H723ZG) (#26565) * Fix string buffer warning (#26550) * Fix MARKFORGED_INVERSE typos (#26558) * Creality Free Runs fixups (#26562) * Orca 3D Modular Controller (#26534) * Jerk correction for LIN_ADVANCE + CLASSIC_JERK (#26551) * Optional FAN_INVERTING * Just "warn" on SD fail * FT_MOTION improvements (#26074) * Fix Creality E3 "Free-runs" (#26533) * Creality E3 Free-runs Silent Motherboard (#25636) * Fix planner jerk limits (#26529) * MARKFORGED_INVERSE (#26516) * Fix MKS TS35 with BTT SKR 1.3/1.4 (#26176) * SERIAL_DMA (for some STM32Fx) (#26328) * Adjust Progress / Completion (#26466) * Encoder improvements (#26501) * Use strlcpy with buffer size (#26513) * Use PIO versioning (including HC32) (#26512) * Voxelab Aquila N32 (via Maple) (#26470) * Fix tool-change E prime (#26494) * Fix thermistor 14 & 60 constexprness (#26499) * UI refresh for some events (#26487) * Fix a NeoPixel override (#26492) * Fix ftostrX3sign (#26497) * DOUBLE_LCD_FRAMERATE (#26500) * Fix some action labels (#26490) * More num-to-string digits / precisions (#26343) * Fix BLTouch HSMode deploy (#26311) * Touch fixes (#26455) * XY_AFTER_HOMING, EVENT_GCODE_AFTER_HOMING (#26469) * BlackBeezMini 3D by I3DBEE (#26406) * HAL for HC32F460 (#26414) * MAX Thermocouples for Heated Bed (#26441) * Pins for FYSETC Spider King 4.07 (#26461) * Use ftpl for item strings (#26462) * BD_SENSOR_PROBE_NO_STOP (#26353) * Fix PANDA ZHU missing #endif (#26460) * Update Teensy 4.0/4.1 Serial (#26457) * Configurable FR/Flow edit ranges (#26446) * Fix MMU2 sscanf bug, optimize (#26449) * Fix GT2560_V41b Z2 pin (#26370) * BTT Octopus Pro V1.0.1 (STM32H723ZE) (#26159) * Fix Ender-5 S1 env * Fix more MarlinUI title centering (#26440) * Fix MarlinUI axis move / UBL strings (#26439) * Minor touch calibration improvement (#26445) * Fix rotational AxisFlags (#26444) * Rotational move items (#26438) * Define MarlinUI axis moves with lists (#26344) * Creality STM32F401RC w/out bootloader (#26373) * Fix runout state in menu (#26394) And many other Bug fixes and improvements from the Marlin bugfix branch
5 months ago
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifdef __AVR__
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include <avr/wdt.h>
#ifdef USBCON
DefaultSerial1 MSerial0(false, Serial);
#ifdef BLUETOOTH
BTSerial btSerial(false, bluetoothSerial);
#endif
#endif
// ------------------------
// Public Variables
// ------------------------
// Don't initialize/override variable (which would happen in .init4)
uint8_t MarlinHAL::reset_reason __attribute__((section(".noinit")));
// ------------------------
// Public functions
// ------------------------
__attribute__((naked)) // Don't output function pro- and epilogue
__attribute__((used)) // Output the function, even if "not used"
__attribute__((section(".init3"))) // Put in an early user definable section
void save_reset_reason() {
#if ENABLED(OPTIBOOT_RESET_REASON)
__asm__ __volatile__(
A("STS %0, r2")
: "=m"(hal.reset_reason)
);
#else
hal.reset_reason = MCUSR;
#endif
// Clear within 16ms since WDRF bit enables a 16ms watchdog timer -> Boot loop
hal.clear_reset_source();
wdt_disable();
}
#include "registers.h"
MarlinHAL::MarlinHAL() {
TERN_(HAL_AVR_DIRTY_INIT, _ATmega_resetperipherals()); // Clean-wipe the device state.
}
void MarlinHAL::init() {
// Init Servo Pins
#if HAS_SERVO_0
OUT_WRITE(SERVO0_PIN, LOW);
#endif
#if HAS_SERVO_1
OUT_WRITE(SERVO1_PIN, LOW);
#endif
#if HAS_SERVO_2
OUT_WRITE(SERVO2_PIN, LOW);
#endif
#if HAS_SERVO_3
OUT_WRITE(SERVO3_PIN, LOW);
#endif
init_pwm_timers(); // Init user timers to default frequency - 1000HZ
#if PIN_EXISTS(BEEPER) && ENABLED(HAL_AVR_DIRTY_INIT) && DISABLED(ATMEGA_NO_BEEPFIX)
// Make sure no alternative is locked onto the BEEPER.
// This fixes the issue where the ATmega is constantly beeping.
// Might disable other peripherals using the pin; to circumvent that please undefine one of the above things!
// The true culprit is the AVR ArduinoCore that enables peripherals redundantly.
// (USART1 on the GeeeTech GT2560)
// https://www.youtube.com/watch?v=jMgCvRXkexk
_ATmega_savePinAlternate(BEEPER_PIN);
OUT_WRITE(BEEPER_PIN, LOW);
#endif
}
void MarlinHAL::reboot() {
#if ENABLED(USE_WATCHDOG)
while (1) { /* run out the watchdog */ }
#else
void (*resetFunc)() = 0; // Declare resetFunc() at address 0
resetFunc(); // Jump to address 0
#endif
}
// ------------------------
// Watchdog Timer
// ------------------------
#if ENABLED(USE_WATCHDOG)
#include <avr/wdt.h>
#include "../../MarlinCore.h"
// Initialize watchdog with 8s timeout, if possible. Otherwise, make it 4s.
void MarlinHAL::watchdog_init() {
#if ENABLED(WATCHDOG_DURATION_8S) && defined(WDTO_8S)
#define WDTO_NS WDTO_8S
#else
#define WDTO_NS WDTO_4S
#endif
#if ENABLED(WATCHDOG_RESET_MANUAL)
// Enable the watchdog timer, but only for the interrupt.
// Take care, as this requires the correct order of operation, with interrupts disabled.
// See the datasheet of any AVR chip for details.
wdt_reset();
cli();
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
_WD_CONTROL_REG = _BV(WDIE) | (WDTO_NS & 0x07) | ((WDTO_NS & 0x08) << 2); // WDTO_NS directly does not work. bit 0-2 are consecutive in the register but the highest value bit is at bit 5
// So worked for up to WDTO_2S
sei();
wdt_reset();
#else
wdt_enable(WDTO_NS); // The function handles the upper bit correct.
#endif
//delay(10000); // test it!
}
//===========================================================================
//=================================== ISR ===================================
//===========================================================================
// Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
#if ENABLED(WATCHDOG_RESET_MANUAL)
ISR(WDT_vect) {
sei(); // With the interrupt driven serial we need to allow interrupts.
SERIAL_ERROR_MSG(STR_WATCHDOG_FIRED);
minkill(); // interrupt-safe final kill and infinite loop
}
#endif
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or AVR will go into emergency procedures.
void MarlinHAL::watchdog_refresh() { wdt_reset(); }
#endif // USE_WATCHDOG
// ------------------------
// Free Memory Accessor
// ------------------------
#if HAS_MEDIA
#include "../../sd/SdFatUtil.h"
int freeMemory() { return SdFatUtil::FreeRam(); }
#else // !HAS_MEDIA
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}
#endif // !HAS_MEDIA
#endif // __AVR__