Skip to content

Commit 6740f60

Browse files
rhapsodyvthinkyhead
authored andcommitted
Improve USB Media Host conditions (MarlinFirmware#20176)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent a9f7dfa commit 6740f60

11 files changed

Lines changed: 40 additions & 32 deletions

File tree

Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
*
2121
*/
2222
#pragma once
23+
24+
#if DISABLED(NO_SD_HOST_DRIVE)
25+
#define HAS_SD_HOST_DRIVE 1
26+
#endif

Marlin/src/HAL/LPC1768/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void HAL_init() {
122122
delay(1000); // Give OS time to notice
123123
USB_Connect(TRUE);
124124

125-
#if DISABLED(NO_SD_HOST_DRIVE)
125+
#if HAS_SD_HOST_DRIVE
126126
MSC_SD_Init(0); // Enable USB SD card access
127127
#endif
128128

@@ -140,7 +140,7 @@ void HAL_init() {
140140

141141
// HAL idle task
142142
void HAL_idletask() {
143-
#if HAS_SHARED_MEDIA
143+
#if HAS_SD_HOST_DRIVE
144144
// If Marlin is using the SD card we need to lock it to prevent access from
145145
// a PC via USB.
146146
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but

Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
3232
#endif
3333

34-
#ifdef USBD_USE_CDC_COMPOSITE
34+
#if HAS_SD_HOST_DRIVE
3535

3636
// use USB drivers
3737

Marlin/src/HAL/STM32/inc/Conditionals_adv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
*
2121
*/
2222
#pragma once
23+
24+
#if defined(USBD_USE_CDC_COMPOSITE) && DISABLED(NO_SD_HOST_DRIVE)
25+
#define HAS_SD_HOST_DRIVE 1
26+
#endif

Marlin/src/HAL/STM32F1/HAL.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
// Public Variables
8383
// ------------------------
8484

85-
#if (defined(SERIAL_USB) && !defined(USE_USB_COMPOSITE))
85+
#if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
8686
USBSerial SerialUSB;
8787
#endif
8888

@@ -251,7 +251,7 @@ void HAL_init() {
251251
#if PIN_EXISTS(LED)
252252
OUT_WRITE(LED_PIN, LOW);
253253
#endif
254-
#ifdef USE_USB_COMPOSITE
254+
#if HAS_SD_HOST_DRIVE
255255
MSC_SD_init();
256256
#endif
257257
#if PIN_EXISTS(USB_CONNECT)
@@ -263,17 +263,15 @@ void HAL_init() {
263263

264264
// HAL idle task
265265
void HAL_idletask() {
266-
#ifdef USE_USB_COMPOSITE
267-
#if HAS_SHARED_MEDIA
268-
// If Marlin is using the SD card we need to lock it to prevent access from
269-
// a PC via USB.
270-
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
271-
// this will not reliably detect delete operations. To be safe we will lock
272-
// the disk if Marlin has it mounted. Unfortunately there is currently no way
273-
// to unmount the disk from the LCD menu.
274-
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
275-
/* copy from lpc1768 framework, should be fixed later for process HAS_SHARED_MEDIA*/
276-
#endif
266+
#if HAS_SD_HOST_DRIVE
267+
// If Marlin is using the SD card we need to lock it to prevent access from
268+
// a PC via USB.
269+
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
270+
// this will not reliably detect delete operations. To be safe we will lock
271+
// the disk if Marlin has it mounted. Unfortunately there is currently no way
272+
// to unmount the disk from the LCD menu.
273+
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
274+
/* copy from lpc1768 framework, should be fixed later for process HAS_SD_HOST_DRIVE*/
277275
// process USB mass storage device class loop
278276
MarlinMSC.loop();
279277
#endif

Marlin/src/HAL/STM32F1/HAL.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

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

45-
#ifdef USE_USB_COMPOSITE
45+
#if HAS_SD_HOST_DRIVE
4646
#include "msc_sd.h"
4747
#endif
4848

@@ -61,7 +61,7 @@
6161
#endif
6262

6363
#ifdef SERIAL_USB
64-
#ifndef USE_USB_COMPOSITE
64+
#if !HAS_SD_HOST_DRIVE
6565
#define UsbSerial Serial
6666
#else
6767
#define UsbSerial MarlinCompositeSerial

Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,3 @@
2020
*
2121
*/
2222
#pragma once
23-
24-
#if ENABLED(USE_USB_COMPOSITE)
25-
//#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE."
26-
#undef SD_CHECK_AND_RETRY
27-
#endif

Marlin/src/HAL/STM32F1/inc/Conditionals_adv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@
2020
*
2121
*/
2222
#pragma once
23+
24+
#ifdef USE_USB_COMPOSITE
25+
//#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE."
26+
#undef SD_CHECK_AND_RETRY
27+
#if DISABLED(NO_SD_HOST_DRIVE)
28+
#define HAS_SD_HOST_DRIVE 1
29+
#endif
30+
#endif

Marlin/src/HAL/STM32F1/msc_sd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1414
*
1515
*/
16-
#if defined(__STM32F1__) && defined(USE_USB_COMPOSITE)
16+
#if defined(__STM32F1__) && HAS_SD_HOST_DRIVE
1717

1818
#include "msc_sd.h"
1919
#include "SPI.h"
@@ -77,4 +77,4 @@ void MSC_SD_init() {
7777
#endif
7878
}
7979

80-
#endif // __STM32F1__ && USE_USB_COMPOSITE
80+
#endif // __STM32F1__ && HAS_SD_HOST_DRIVE

Marlin/src/HAL/STM32F1/onboard_sd.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
#include "SPI.h"
2222
#include "fastio.h"
2323

24-
#if HAS_SHARED_MEDIA
25-
#ifndef ONBOARD_SPI_DEVICE
26-
#define ONBOARD_SPI_DEVICE SPI_DEVICE
27-
#endif
24+
#ifndef ONBOARD_SPI_DEVICE
25+
#define ONBOARD_SPI_DEVICE SPI_DEVICE
26+
#endif
27+
28+
#if HAS_SD_HOST_DRIVE
2829
#define ONBOARD_SD_SPI SPI
2930
#else
3031
SPIClass OnboardSPI(ONBOARD_SPI_DEVICE);

0 commit comments

Comments
 (0)