Skip to content

Commit

Permalink
Merge branch 'bugfix-2.1.x' into pr/26615
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 4, 2024
2 parents 1ee0542 + b5a562f commit aed7329
Show file tree
Hide file tree
Showing 34 changed files with 268 additions and 133 deletions.
9 changes: 7 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@
/**
* Enable detailed logging of G28, G29, M48, etc.
* Turn on with the command 'M111 S32'.
* NOTE: Requires a lot of PROGMEM!
* NOTE: Requires a lot of flash!
*/
//#define DEBUG_LEVELING_FEATURE

Expand Down Expand Up @@ -2343,7 +2343,7 @@
*/
//#define EEPROM_SETTINGS // Persistent storage with M500 and M501
//#define DISABLE_M503 // Saves ~2700 bytes of flash. Disable for release!
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM.
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save flash.
#define EEPROM_BOOT_SILENT // Keep M503 quiet and only give errors during first load
#if ENABLED(EEPROM_SETTINGS)
//#define EEPROM_AUTO_INIT // Init EEPROM automatically on any errors.
Expand Down Expand Up @@ -3015,6 +3015,11 @@
//
//#define BTT_MINI_12864

//
// BEEZ MINI 12864 is an alias for FYSETC_MINI_12864_2_1. Type A/B. NeoPixel RGB Backlight.
//
//#define BEEZ_MINI_12864

//
// Factory display for Creality CR-10 / CR-7 / Ender-3
// https://www.aliexpress.com/item/32833148327.html
Expand Down
15 changes: 14 additions & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@
#define CALIBRATION_NOZZLE_TIP_HEIGHT 1.0 // mm
#define CALIBRATION_NOZZLE_OUTER_DIAMETER 2.0 // mm

// Uncomment to enable reporting (required for "G425 V", but consumes PROGMEM).
// Uncomment to enable reporting (required for "G425 V", but consumes flash).
//#define CALIBRATION_REPORTING

// The true location and dimension the cube/bolt/washer on the bed.
Expand Down Expand Up @@ -2929,6 +2929,7 @@
//#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)
#define CONFIGURE_FILAMENT_CHANGE // Add M603 G-code and menu items. Requires ~1.3K bytes of flash.
#endif

// @section tmc_smart
Expand Down Expand Up @@ -3935,6 +3936,18 @@

//#define REPETIER_GCODE_M360 // Add commands originally from Repetier FW

/**
* Enable M111 debug flags 1=ECHO, 2=INFO, 4=ERRORS (unimplemented).
* Disable to save some flash. Some hosts (Repetier Host) may rely on this feature.
*/
#define DEBUG_FLAGS_GCODE

/**
* M115 - Report capabilites. Disable to save ~1150 bytes of flash.
* Some hosts (and serial TFT displays) rely on this feature.
*/
#define REPORT_CAPABILITIES_GCODE

/**
* Enable this option for a leaner build of Marlin that removes
* workspace offsets to slightly optimize performance.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* here we define this default string as the date where the latest release
* version was tagged.
*/
//#define STRING_DISTRIBUTION_DATE "2024-01-02"
//#define STRING_DISTRIBUTION_DATE "2024-01-04"

/**
* Defines a generic printer name to be output to the LCD after booting Marlin.
Expand Down
29 changes: 29 additions & 0 deletions Marlin/src/HAL/DUE/usb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# USB Files Source Documentation

## Source

We sourced the USB files in Marlin from the Atmel ASF (Advanced Software Framework). The framework provides a variety of examples which were utilized in this project.

Atmel doesn't provide these files in a source repository but they can be extracted from ASF, which can be downloaded from Atmel.

[Advanced Software Framework](https://www.microchip.com/en-us/tools-resources/develop/libraries/advanced-software-framework)

## Modifications

The files are mostly unmodified except for minor cosmetic changes but some more significant changes were needed.

The changes that prompted the addition of this README file are listed below. Other changes may have been made prior to this.

1. Modified `uotghs_device_due.c` to resolve race conditions that could leave interrupts asserted when freezing the peripheral clock, resulting in hangs and watchdog resets due to the ensuing interrupt storm.

## Version Information

We don't know the exact version of ASF used as the source. However, the copyright information in the files indicates they are from 2015.

## Upgrade Considerations

We looked at the ASF 3.52.0 files released in 2022 but saw no immediate benefits to justify an upgrade. It's important to note that the files in Marlin don't follow the same folder structure as the files in ASF, which complicates the process of comparing and applying updated files.

When these files are updated it's important to carefully compare them to Marlin's versions so any improvements in the Marlin sources are brought forward.

It would be best to make Marlin's directory structure align with ASF or at least document the source of each file to ease future updates.
79 changes: 70 additions & 9 deletions Marlin/src/HAL/DUE/usb/uotghs_device_due.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@
//#define dbg_print printf
#define dbg_print(...)

// Marlin modification: Redefine the otg_freeze_clock and otg_unfreeze_clock macros
// to add memory barriers to ensure that any accesses to USB registers aren't re-ordered
// to occur while the clock is frozen.
#undef otg_freeze_clock
#undef otg_unfreeze_clock

#define otg_freeze_clock() do { \
__DSB(); \
Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK); \
} while (0)

#define otg_unfreeze_clock() \
do { \
Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK); \
__DSB(); \
} while (0)

/**
* \ingroup udd_group
* \defgroup udd_udphs_group USB On-The-Go High-Speed Port for device mode (UOTGHS)
Expand Down Expand Up @@ -611,6 +628,18 @@ ISR(UDD_USB_INT_FUN)
// The wakeup interrupt is automatic acked when a suspend occur
udd_disable_wake_up_interrupt();
udd_enable_suspend_interrupt();

// Marlin modification: The RESET, SOF, and MSOF interrupts were previously
// enabled in udd_attach, which caused a race condition where they could
// be raised and unclearable with the clock is frozen. They are now
// enabled here, after the clock has been unfrozen in response to the wake
// interrupt.
udd_enable_reset_interrupt();
udd_enable_sof_interrupt();
#ifdef USB_DEVICE_HS_SUPPORT
udd_enable_msof_interrupt();
#endif

udd_sleep_mode(true); // Enter in IDLE mode
#ifdef UDC_RESUME_EVENT
UDC_RESUME_EVENT();
Expand Down Expand Up @@ -776,6 +805,27 @@ void udd_disable(void)
cpu_irq_restore(flags);
}

// Marlin modification: The original implementation did not use a memory
// barrier between disabling and clearing interrupts. This sometimes
// allowed interrupts to remain raised and unclearable after the clock
// was frozen. This helper was added to ensure that memory barriers
// are used consistently from all places where interrupts are disabled.
static void disable_and_ack_sync_interrupts()
{
// Disable USB line events
udd_disable_reset_interrupt();
udd_disable_sof_interrupt();
#ifdef USB_DEVICE_HS_SUPPORT
udd_disable_msof_interrupt();
#endif
__DSB();
udd_ack_reset();
udd_ack_sof();
#ifdef USB_DEVICE_HS_SUPPORT
udd_ack_msof();
#endif
__DSB();
}

void udd_attach(void)
{
Expand All @@ -796,17 +846,16 @@ void udd_attach(void)
udd_attach_device();

// Enable USB line events
udd_enable_reset_interrupt();
udd_enable_suspend_interrupt();
udd_enable_wake_up_interrupt();
udd_enable_sof_interrupt();
#ifdef USB_DEVICE_HS_SUPPORT
udd_enable_msof_interrupt();
#endif
// Reset following interrupts flag
udd_ack_reset();
udd_ack_sof();
udd_ack_msof();

// Marlin modification: The RESET, SOF, and MSOF interrupts were previously
// enabled here, which caused a race condition where they could be raised
// and unclearable with the clock is frozen. They are now enabled in the
// wake interrupt handler, after the clock has been unfrozen. They are now
// explicitly disabled here to ensure that they cannot be raised before
// the clock is frozen.
disable_and_ack_sync_interrupts();

// The first suspend interrupt must be forced
// The first suspend interrupt is not detected else raise it
Expand All @@ -824,6 +873,12 @@ void udd_detach(void)

// Detach device from the bus
udd_detach_device();

// Marlin modification: Added the explicit disabling of the RESET, SOF, and
// MSOF interrupts here, to ensure that they cannot be raised after the
// clock is frozen.
disable_and_ack_sync_interrupts();

otg_freeze_clock();
udd_sleep_mode(false);
}
Expand Down Expand Up @@ -2043,6 +2098,12 @@ static bool udd_ep_interrupt(void)
dbg_print("I ");
udd_disable_in_send_interrupt(ep);
// One bank is free then send a ZLP

// Marlin modification: Add a barrier to ensure in_send is disabled
// before it is cleared. This was not an observed problem, but
// other interrupts were seen to misbehave without this barrier.
__DSB();

udd_ack_in_send(ep);
udd_ack_fifocon(ep);
udd_ep_finish_job(ptr_job, false, ep);
Expand Down
21 changes: 8 additions & 13 deletions Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,14 @@
//
enum MarlinDebugFlags : uint8_t {
MARLIN_DEBUG_NONE = 0,
MARLIN_DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed
MARLIN_DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output
MARLIN_DEBUG_ERRORS = _BV(2), ///< Not implemented
MARLIN_DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands
MARLIN_DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
#if ENABLED(DEBUG_LEVELING_FEATURE)
MARLIN_DEBUG_LEVELING = _BV(5), ///< Print detailed output for homing and leveling
MARLIN_DEBUG_MESH_ADJUST = _BV(6), ///< UBL bed leveling
#else
MARLIN_DEBUG_LEVELING = 0,
MARLIN_DEBUG_MESH_ADJUST = 0,
#endif
MARLIN_DEBUG_ALL = 0xFF
MARLIN_DEBUG_ECHO = TERN0(DEBUG_FLAGS_GCODE, _BV(0)), //!< Echo commands in order as they are processed
MARLIN_DEBUG_INFO = TERN0(DEBUG_FLAGS_GCODE, _BV(1)), //!< Print messages for code that has debug output
MARLIN_DEBUG_ERRORS = TERN0(DEBUG_FLAGS_GCODE, _BV(2)), //!< Not implemented
MARLIN_DEBUG_DRYRUN = _BV(3), //!< Ignore temperature setting and E movement commands
MARLIN_DEBUG_COMMUNICATION = TERN0(DEBUG_FLAGS_GCODE, _BV(4)), //!< Not implemented
MARLIN_DEBUG_LEVELING = TERN0(DEBUG_LEVELING_FEATURE, _BV(5)), //!< Print detailed output for homing and leveling
MARLIN_DEBUG_MESH_ADJUST = TERN0(DEBUG_LEVELING_FEATURE, _BV(6)), //!< UBL bed leveling
MARLIN_DEBUG_ALL = MARLIN_DEBUG_ECHO|MARLIN_DEBUG_INFO|MARLIN_DEBUG_ERRORS|MARLIN_DEBUG_COMMUNICATION|MARLIN_DEBUG_LEVELING|MARLIN_DEBUG_MESH_ADJUST
};

extern uint8_t marlin_debug_flags;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/max7219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#if ENABLED(MAX7219_DEBUG)

#define MAX7219_ERRORS // Disable to save 406 bytes of Program Memory
#define MAX7219_ERRORS // Requires ~400 bytes of flash

#include "max7219.h"

Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/feature/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ static xyze_pos_t resume_position;
PauseMode pause_mode = PAUSE_MODE_PAUSE_PRINT;
#endif

fil_change_settings_t fc_settings[EXTRUDERS];
#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
fil_change_settings_t fc_settings[EXTRUDERS];
#endif

#if HAS_MEDIA
#include "../sd/cardreader.h"
Expand Down
19 changes: 14 additions & 5 deletions Marlin/src/feature/pause.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
* This may be combined with related G-codes if features are consolidated.
*/

typedef struct {
float unload_length, load_length;
} fil_change_settings_t;

#include "../inc/MarlinConfigPre.h"

#if ENABLED(ADVANCED_PAUSE_FEATURE)
Expand Down Expand Up @@ -69,7 +65,20 @@ enum PauseMessage : char {
extern PauseMode pause_mode;
#endif

extern fil_change_settings_t fc_settings[EXTRUDERS];
typedef struct FilamentChangeSettings {
#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
float load_length, unload_length;
#else
static constexpr float load_length = FILAMENT_CHANGE_FAST_LOAD_LENGTH,
unload_length = FILAMENT_CHANGE_UNLOAD_LENGTH;
#endif
} fil_change_settings_t;

#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
extern fil_change_settings_t fc_settings[EXTRUDERS];
#else
constexpr fil_change_settings_t fc_settings[EXTRUDERS];
#endif

extern uint8_t did_pause_print;

Expand Down
32 changes: 19 additions & 13 deletions Marlin/src/gcode/control/M111.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@
*
*/

#include "../../inc/MarlinConfig.h"
#include "../gcode.h"

/**
* M111: Set the debug level
*/
void GcodeSuite::M111() {
if (parser.seenval('S')) marlin_debug_flags = parser.value_byte();

static PGMSTR(str_debug_1, STR_DEBUG_ECHO);
static PGMSTR(str_debug_2, STR_DEBUG_INFO);
static PGMSTR(str_debug_4, STR_DEBUG_ERRORS);
#if ENABLED(DEBUG_FLAGS_GCODE)
static PGMSTR(str_debug_1, STR_DEBUG_ECHO);
static PGMSTR(str_debug_2, STR_DEBUG_INFO);
static PGMSTR(str_debug_4, STR_DEBUG_ERRORS);
#endif
static PGMSTR(str_debug_8, STR_DEBUG_DRYRUN);
static PGMSTR(str_debug_16, STR_DEBUG_COMMUNICATION);
#if ENABLED(DEBUG_FLAGS_GCODE)
static PGMSTR(str_debug_16, STR_DEBUG_COMMUNICATION);
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
static PGMSTR(str_debug_detail, STR_DEBUG_DETAIL);
#endif

static PGM_P const debug_strings[] PROGMEM = {
str_debug_1, str_debug_2, str_debug_4, str_debug_8, str_debug_16,
TERN(DEBUG_FLAGS_GCODE, str_debug_1, nullptr),
TERN(DEBUG_FLAGS_GCODE, str_debug_2, nullptr),
TERN(DEBUG_FLAGS_GCODE, str_debug_4, nullptr),
str_debug_8,
TERN(DEBUG_FLAGS_GCODE, str_debug_16, nullptr),
TERN_(DEBUG_LEVELING_FEATURE, str_debug_detail)
};

Expand All @@ -47,31 +55,29 @@ void GcodeSuite::M111() {
if (marlin_debug_flags) {
uint8_t comma = 0;
for (uint8_t i = 0; i < COUNT(debug_strings); ++i) {
if (TEST(marlin_debug_flags, i)) {
PGM_P const pstr = (PGM_P)pgm_read_ptr(&debug_strings[i]);
if (pstr && TEST(marlin_debug_flags, i)) {
if (comma++) SERIAL_CHAR(',');
SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&debug_strings[i]));
SERIAL_ECHOPGM_P(pstr);
}
}
}
else {
SERIAL_ECHOPGM(STR_DEBUG_OFF);
#if !defined(__AVR__) || !defined(USBCON)
#if !(defined(__AVR__) && defined(USBCON))
#if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
SERIAL_ECHOPGM("\nBuffer Overruns: ", MYSERIAL1.buffer_overruns());
#endif

#if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
SERIAL_ECHOPGM("\nFraming Errors: ", MYSERIAL1.framing_errors());
#endif

#if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOPGM("\nDropped bytes: ", MYSERIAL1.dropped());
#endif

#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOPGM("\nMax RX Queue Size: ", MYSERIAL1.rxMaxEnqueued());
#endif
#endif // !__AVR__ || !USBCON
#endif // !(__AVR__ && USBCON)
}
SERIAL_EOL();
}
Loading

0 comments on commit aed7329

Please sign in to comment.