Skip to content

Commit aed7329

Browse files
committed
Merge branch 'bugfix-2.1.x' into pr/26615
2 parents 1ee0542 + b5a562f commit aed7329

34 files changed

+268
-133
lines changed

Marlin/Configuration.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@
20542054
/**
20552055
* Enable detailed logging of G28, G29, M48, etc.
20562056
* Turn on with the command 'M111 S32'.
2057-
* NOTE: Requires a lot of PROGMEM!
2057+
* NOTE: Requires a lot of flash!
20582058
*/
20592059
//#define DEBUG_LEVELING_FEATURE
20602060

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

3018+
//
3019+
// BEEZ MINI 12864 is an alias for FYSETC_MINI_12864_2_1. Type A/B. NeoPixel RGB Backlight.
3020+
//
3021+
//#define BEEZ_MINI_12864
3022+
30183023
//
30193024
// Factory display for Creality CR-10 / CR-7 / Ender-3
30203025
// https://www.aliexpress.com/item/32833148327.html

Marlin/Configuration_adv.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@
13421342
#define CALIBRATION_NOZZLE_TIP_HEIGHT 1.0 // mm
13431343
#define CALIBRATION_NOZZLE_OUTER_DIAMETER 2.0 // mm
13441344

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

13481348
// The true location and dimension the cube/bolt/washer on the bed.
@@ -2929,6 +2929,7 @@
29292929

29302930
//#define FILAMENT_LOAD_UNLOAD_GCODES // Add M701/M702 Load/Unload G-codes, plus Load/Unload in the LCD Prepare menu.
29312931
//#define FILAMENT_UNLOAD_ALL_EXTRUDERS // Allow M702 to unload all extruders above a minimum target temp (as set by M302)
2932+
#define CONFIGURE_FILAMENT_CHANGE // Add M603 G-code and menu items. Requires ~1.3K bytes of flash.
29322933
#endif
29332934

29342935
// @section tmc_smart
@@ -3935,6 +3936,18 @@
39353936

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

3939+
/**
3940+
* Enable M111 debug flags 1=ECHO, 2=INFO, 4=ERRORS (unimplemented).
3941+
* Disable to save some flash. Some hosts (Repetier Host) may rely on this feature.
3942+
*/
3943+
#define DEBUG_FLAGS_GCODE
3944+
3945+
/**
3946+
* M115 - Report capabilites. Disable to save ~1150 bytes of flash.
3947+
* Some hosts (and serial TFT displays) rely on this feature.
3948+
*/
3949+
#define REPORT_CAPABILITIES_GCODE
3950+
39383951
/**
39393952
* Enable this option for a leaner build of Marlin that removes
39403953
* workspace offsets to slightly optimize performance.

Marlin/Version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* here we define this default string as the date where the latest release
4242
* version was tagged.
4343
*/
44-
//#define STRING_DISTRIBUTION_DATE "2024-01-02"
44+
//#define STRING_DISTRIBUTION_DATE "2024-01-04"
4545

4646
/**
4747
* Defines a generic printer name to be output to the LCD after booting Marlin.

Marlin/src/HAL/DUE/usb/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# USB Files Source Documentation
2+
3+
## Source
4+
5+
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.
6+
7+
Atmel doesn't provide these files in a source repository but they can be extracted from ASF, which can be downloaded from Atmel.
8+
9+
[Advanced Software Framework](https://www.microchip.com/en-us/tools-resources/develop/libraries/advanced-software-framework)
10+
11+
## Modifications
12+
13+
The files are mostly unmodified except for minor cosmetic changes but some more significant changes were needed.
14+
15+
The changes that prompted the addition of this README file are listed below. Other changes may have been made prior to this.
16+
17+
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.
18+
19+
## Version Information
20+
21+
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.
22+
23+
## Upgrade Considerations
24+
25+
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.
26+
27+
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.
28+
29+
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.

Marlin/src/HAL/DUE/usb/uotghs_device_due.c

+70-9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@
116116
//#define dbg_print printf
117117
#define dbg_print(...)
118118

119+
// Marlin modification: Redefine the otg_freeze_clock and otg_unfreeze_clock macros
120+
// to add memory barriers to ensure that any accesses to USB registers aren't re-ordered
121+
// to occur while the clock is frozen.
122+
#undef otg_freeze_clock
123+
#undef otg_unfreeze_clock
124+
125+
#define otg_freeze_clock() do { \
126+
__DSB(); \
127+
Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK); \
128+
} while (0)
129+
130+
#define otg_unfreeze_clock() \
131+
do { \
132+
Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK); \
133+
__DSB(); \
134+
} while (0)
135+
119136
/**
120137
* \ingroup udd_group
121138
* \defgroup udd_udphs_group USB On-The-Go High-Speed Port for device mode (UOTGHS)
@@ -611,6 +628,18 @@ ISR(UDD_USB_INT_FUN)
611628
// The wakeup interrupt is automatic acked when a suspend occur
612629
udd_disable_wake_up_interrupt();
613630
udd_enable_suspend_interrupt();
631+
632+
// Marlin modification: The RESET, SOF, and MSOF interrupts were previously
633+
// enabled in udd_attach, which caused a race condition where they could
634+
// be raised and unclearable with the clock is frozen. They are now
635+
// enabled here, after the clock has been unfrozen in response to the wake
636+
// interrupt.
637+
udd_enable_reset_interrupt();
638+
udd_enable_sof_interrupt();
639+
#ifdef USB_DEVICE_HS_SUPPORT
640+
udd_enable_msof_interrupt();
641+
#endif
642+
614643
udd_sleep_mode(true); // Enter in IDLE mode
615644
#ifdef UDC_RESUME_EVENT
616645
UDC_RESUME_EVENT();
@@ -776,6 +805,27 @@ void udd_disable(void)
776805
cpu_irq_restore(flags);
777806
}
778807

808+
// Marlin modification: The original implementation did not use a memory
809+
// barrier between disabling and clearing interrupts. This sometimes
810+
// allowed interrupts to remain raised and unclearable after the clock
811+
// was frozen. This helper was added to ensure that memory barriers
812+
// are used consistently from all places where interrupts are disabled.
813+
static void disable_and_ack_sync_interrupts()
814+
{
815+
// Disable USB line events
816+
udd_disable_reset_interrupt();
817+
udd_disable_sof_interrupt();
818+
#ifdef USB_DEVICE_HS_SUPPORT
819+
udd_disable_msof_interrupt();
820+
#endif
821+
__DSB();
822+
udd_ack_reset();
823+
udd_ack_sof();
824+
#ifdef USB_DEVICE_HS_SUPPORT
825+
udd_ack_msof();
826+
#endif
827+
__DSB();
828+
}
779829

780830
void udd_attach(void)
781831
{
@@ -796,17 +846,16 @@ void udd_attach(void)
796846
udd_attach_device();
797847

798848
// Enable USB line events
799-
udd_enable_reset_interrupt();
800849
udd_enable_suspend_interrupt();
801850
udd_enable_wake_up_interrupt();
802-
udd_enable_sof_interrupt();
803-
#ifdef USB_DEVICE_HS_SUPPORT
804-
udd_enable_msof_interrupt();
805-
#endif
806-
// Reset following interrupts flag
807-
udd_ack_reset();
808-
udd_ack_sof();
809-
udd_ack_msof();
851+
852+
// Marlin modification: The RESET, SOF, and MSOF interrupts were previously
853+
// enabled here, which caused a race condition where they could be raised
854+
// and unclearable with the clock is frozen. They are now enabled in the
855+
// wake interrupt handler, after the clock has been unfrozen. They are now
856+
// explicitly disabled here to ensure that they cannot be raised before
857+
// the clock is frozen.
858+
disable_and_ack_sync_interrupts();
810859

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

825874
// Detach device from the bus
826875
udd_detach_device();
876+
877+
// Marlin modification: Added the explicit disabling of the RESET, SOF, and
878+
// MSOF interrupts here, to ensure that they cannot be raised after the
879+
// clock is frozen.
880+
disable_and_ack_sync_interrupts();
881+
827882
otg_freeze_clock();
828883
udd_sleep_mode(false);
829884
}
@@ -2043,6 +2098,12 @@ static bool udd_ep_interrupt(void)
20432098
dbg_print("I ");
20442099
udd_disable_in_send_interrupt(ep);
20452100
// One bank is free then send a ZLP
2101+
2102+
// Marlin modification: Add a barrier to ensure in_send is disabled
2103+
// before it is cleared. This was not an observed problem, but
2104+
// other interrupts were seen to misbehave without this barrier.
2105+
__DSB();
2106+
20462107
udd_ack_in_send(ep);
20472108
udd_ack_fifocon(ep);
20482109
udd_ep_finish_job(ptr_job, false, ep);

Marlin/src/core/serial.h

+8-13
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,14 @@
3333
//
3434
enum MarlinDebugFlags : uint8_t {
3535
MARLIN_DEBUG_NONE = 0,
36-
MARLIN_DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed
37-
MARLIN_DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output
38-
MARLIN_DEBUG_ERRORS = _BV(2), ///< Not implemented
39-
MARLIN_DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands
40-
MARLIN_DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
41-
#if ENABLED(DEBUG_LEVELING_FEATURE)
42-
MARLIN_DEBUG_LEVELING = _BV(5), ///< Print detailed output for homing and leveling
43-
MARLIN_DEBUG_MESH_ADJUST = _BV(6), ///< UBL bed leveling
44-
#else
45-
MARLIN_DEBUG_LEVELING = 0,
46-
MARLIN_DEBUG_MESH_ADJUST = 0,
47-
#endif
48-
MARLIN_DEBUG_ALL = 0xFF
36+
MARLIN_DEBUG_ECHO = TERN0(DEBUG_FLAGS_GCODE, _BV(0)), //!< Echo commands in order as they are processed
37+
MARLIN_DEBUG_INFO = TERN0(DEBUG_FLAGS_GCODE, _BV(1)), //!< Print messages for code that has debug output
38+
MARLIN_DEBUG_ERRORS = TERN0(DEBUG_FLAGS_GCODE, _BV(2)), //!< Not implemented
39+
MARLIN_DEBUG_DRYRUN = _BV(3), //!< Ignore temperature setting and E movement commands
40+
MARLIN_DEBUG_COMMUNICATION = TERN0(DEBUG_FLAGS_GCODE, _BV(4)), //!< Not implemented
41+
MARLIN_DEBUG_LEVELING = TERN0(DEBUG_LEVELING_FEATURE, _BV(5)), //!< Print detailed output for homing and leveling
42+
MARLIN_DEBUG_MESH_ADJUST = TERN0(DEBUG_LEVELING_FEATURE, _BV(6)), //!< UBL bed leveling
43+
MARLIN_DEBUG_ALL = MARLIN_DEBUG_ECHO|MARLIN_DEBUG_INFO|MARLIN_DEBUG_ERRORS|MARLIN_DEBUG_COMMUNICATION|MARLIN_DEBUG_LEVELING|MARLIN_DEBUG_MESH_ADJUST
4944
};
5045

5146
extern uint8_t marlin_debug_flags;

Marlin/src/feature/max7219.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
#if ENABLED(MAX7219_DEBUG)
4141

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

4444
#include "max7219.h"
4545

Marlin/src/feature/pause.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ static xyze_pos_t resume_position;
8989
PauseMode pause_mode = PAUSE_MODE_PAUSE_PRINT;
9090
#endif
9191

92-
fil_change_settings_t fc_settings[EXTRUDERS];
92+
#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
93+
fil_change_settings_t fc_settings[EXTRUDERS];
94+
#endif
9395

9496
#if HAS_MEDIA
9597
#include "../sd/cardreader.h"

Marlin/src/feature/pause.h

+14-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
* This may be combined with related G-codes if features are consolidated.
2727
*/
2828

29-
typedef struct {
30-
float unload_length, load_length;
31-
} fil_change_settings_t;
32-
3329
#include "../inc/MarlinConfigPre.h"
3430

3531
#if ENABLED(ADVANCED_PAUSE_FEATURE)
@@ -69,7 +65,20 @@ enum PauseMessage : char {
6965
extern PauseMode pause_mode;
7066
#endif
7167

72-
extern fil_change_settings_t fc_settings[EXTRUDERS];
68+
typedef struct FilamentChangeSettings {
69+
#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
70+
float load_length, unload_length;
71+
#else
72+
static constexpr float load_length = FILAMENT_CHANGE_FAST_LOAD_LENGTH,
73+
unload_length = FILAMENT_CHANGE_UNLOAD_LENGTH;
74+
#endif
75+
} fil_change_settings_t;
76+
77+
#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
78+
extern fil_change_settings_t fc_settings[EXTRUDERS];
79+
#else
80+
constexpr fil_change_settings_t fc_settings[EXTRUDERS];
81+
#endif
7382

7483
extern uint8_t did_pause_print;
7584

Marlin/src/gcode/control/M111.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,33 @@
2020
*
2121
*/
2222

23+
#include "../../inc/MarlinConfig.h"
2324
#include "../gcode.h"
2425

2526
/**
2627
* M111: Set the debug level
2728
*/
2829
void GcodeSuite::M111() {
2930
if (parser.seenval('S')) marlin_debug_flags = parser.value_byte();
30-
31-
static PGMSTR(str_debug_1, STR_DEBUG_ECHO);
32-
static PGMSTR(str_debug_2, STR_DEBUG_INFO);
33-
static PGMSTR(str_debug_4, STR_DEBUG_ERRORS);
31+
#if ENABLED(DEBUG_FLAGS_GCODE)
32+
static PGMSTR(str_debug_1, STR_DEBUG_ECHO);
33+
static PGMSTR(str_debug_2, STR_DEBUG_INFO);
34+
static PGMSTR(str_debug_4, STR_DEBUG_ERRORS);
35+
#endif
3436
static PGMSTR(str_debug_8, STR_DEBUG_DRYRUN);
35-
static PGMSTR(str_debug_16, STR_DEBUG_COMMUNICATION);
37+
#if ENABLED(DEBUG_FLAGS_GCODE)
38+
static PGMSTR(str_debug_16, STR_DEBUG_COMMUNICATION);
39+
#endif
3640
#if ENABLED(DEBUG_LEVELING_FEATURE)
3741
static PGMSTR(str_debug_detail, STR_DEBUG_DETAIL);
3842
#endif
3943

4044
static PGM_P const debug_strings[] PROGMEM = {
41-
str_debug_1, str_debug_2, str_debug_4, str_debug_8, str_debug_16,
45+
TERN(DEBUG_FLAGS_GCODE, str_debug_1, nullptr),
46+
TERN(DEBUG_FLAGS_GCODE, str_debug_2, nullptr),
47+
TERN(DEBUG_FLAGS_GCODE, str_debug_4, nullptr),
48+
str_debug_8,
49+
TERN(DEBUG_FLAGS_GCODE, str_debug_16, nullptr),
4250
TERN_(DEBUG_LEVELING_FEATURE, str_debug_detail)
4351
};
4452

@@ -47,31 +55,29 @@ void GcodeSuite::M111() {
4755
if (marlin_debug_flags) {
4856
uint8_t comma = 0;
4957
for (uint8_t i = 0; i < COUNT(debug_strings); ++i) {
50-
if (TEST(marlin_debug_flags, i)) {
58+
PGM_P const pstr = (PGM_P)pgm_read_ptr(&debug_strings[i]);
59+
if (pstr && TEST(marlin_debug_flags, i)) {
5160
if (comma++) SERIAL_CHAR(',');
52-
SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&debug_strings[i]));
61+
SERIAL_ECHOPGM_P(pstr);
5362
}
5463
}
5564
}
5665
else {
5766
SERIAL_ECHOPGM(STR_DEBUG_OFF);
58-
#if !defined(__AVR__) || !defined(USBCON)
67+
#if !(defined(__AVR__) && defined(USBCON))
5968
#if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
6069
SERIAL_ECHOPGM("\nBuffer Overruns: ", MYSERIAL1.buffer_overruns());
6170
#endif
62-
6371
#if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
6472
SERIAL_ECHOPGM("\nFraming Errors: ", MYSERIAL1.framing_errors());
6573
#endif
66-
6774
#if ENABLED(SERIAL_STATS_DROPPED_RX)
6875
SERIAL_ECHOPGM("\nDropped bytes: ", MYSERIAL1.dropped());
6976
#endif
70-
7177
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
7278
SERIAL_ECHOPGM("\nMax RX Queue Size: ", MYSERIAL1.rxMaxEnqueued());
7379
#endif
74-
#endif // !__AVR__ || !USBCON
80+
#endif // !(__AVR__ && USBCON)
7581
}
7682
SERIAL_EOL();
7783
}

0 commit comments

Comments
 (0)