Skip to content

Commit 9ea6a58

Browse files
✨ M21 P / S / U - Select Volume (MarlinFirmware#23780)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 4b0e84d commit 9ea6a58

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Marlin/Configuration_adv.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,10 @@
16311631
// Enable if SD detect is rendered useless (e.g., by using an SD extender)
16321632
//#define NO_SD_DETECT
16331633

1634-
// Multiple volume support - EXPERIMENTAL.
1634+
/**
1635+
* Multiple volume support - EXPERIMENTAL.
1636+
* Adds 'M21 Pm' / 'M21 S' / 'M21 U' to mount SD Card / USB Drive.
1637+
*/
16351638
//#define MULTI_VOLUME
16361639
#if ENABLED(MULTI_VOLUME)
16371640
#define VOLUME_SD_ONBOARD

Marlin/src/gcode/gcode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
*
9292
*** Print from Media (SDSUPPORT) ***
9393
* M20 - List SD card. (Requires SDSUPPORT)
94-
* M21 - Init SD card. (Requires SDSUPPORT)
94+
* M21 - Init SD card. (Requires SDSUPPORT) With MULTI_VOLUME select a drive with `M21 Pn` / 'M21 S' / 'M21 U'.
9595
* M22 - Release SD card. (Requires SDSUPPORT)
9696
* M23 - Select SD file: "M23 /path/file.gco". (Requires SDSUPPORT)
9797
* M24 - Start/resume SD print. (Requires SDSUPPORT)

Marlin/src/gcode/host/M115.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ void GcodeSuite::M115() {
142142
// SDCARD (M20, M23, M24, etc.)
143143
cap_line(F("SDCARD"), ENABLED(SDSUPPORT));
144144

145+
// MULTI_VOLUME (M21 S/M21 U)
146+
#if ENABLED(SDSUPPORT)
147+
cap_line(F("MULTI_VOLUME"), ENABLED(MULTI_VOLUME));
148+
#endif
149+
145150
// REPEAT (M808)
146151
cap_line(F("REPEAT"), ENABLED(GCODE_REPEAT_MARKERS));
147152

Marlin/src/gcode/sd/M21_M22.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,21 @@
2929

3030
/**
3131
* M21: Init SD Card
32+
*
33+
* With MULTI_VOLUME:
34+
* P0 or S - Change to the SD Card and mount it
35+
* P1 or U - Change to the USB Drive and mount it
3236
*/
33-
void GcodeSuite::M21() { card.mount(); }
37+
void GcodeSuite::M21() {
38+
#if ENABLED(MULTI_VOLUME)
39+
const int8_t vol = parser.intval('P', -1);
40+
if (vol == 0 || parser.seen_test('S')) // "S" for SD Card
41+
card.changeMedia(&card.media_driver_sdcard);
42+
else if (vol == 1 || parser.seen_test('U')) // "U" for USB
43+
card.changeMedia(&card.media_driver_usbFlash);
44+
#endif
45+
card.mount();
46+
}
3447

3548
/**
3649
* M22: Release SD Card

0 commit comments

Comments
 (0)