Improve USB Media Host conditions (#20176)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Victor Oliveira 2020-11-18 02:48:14 -03:00 committed by GitHub
parent c1920f31ca
commit f1cdd02d4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 32 deletions

View file

@ -20,3 +20,7 @@
* *
*/ */
#pragma once #pragma once
#if DISABLED(NO_SD_HOST_DRIVE)
#define HAS_SD_HOST_DRIVE 1
#endif

View file

@ -122,7 +122,7 @@ void HAL_init() {
delay(1000); // Give OS time to notice delay(1000); // Give OS time to notice
USB_Connect(TRUE); USB_Connect(TRUE);
#if DISABLED(NO_SD_HOST_DRIVE) #if HAS_SD_HOST_DRIVE
MSC_SD_Init(0); // Enable USB SD card access MSC_SD_Init(0); // Enable USB SD card access
#endif #endif
@ -140,7 +140,7 @@ void HAL_init() {
// HAL idle task // HAL idle task
void HAL_idletask() { void HAL_idletask() {
#if HAS_SHARED_MEDIA #if HAS_SD_HOST_DRIVE
// If Marlin is using the SD card we need to lock it to prevent access from // If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB. // a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but

View file

@ -31,7 +31,7 @@
#error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported" #error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
#endif #endif
#ifdef USBD_USE_CDC_COMPOSITE #if HAS_SD_HOST_DRIVE
// use USB drivers // use USB drivers

View file

@ -20,3 +20,7 @@
* *
*/ */
#pragma once #pragma once
#if defined(USBD_USE_CDC_COMPOSITE) && DISABLED(NO_SD_HOST_DRIVE)
#define HAS_SD_HOST_DRIVE 1
#endif

View file

@ -82,7 +82,7 @@
// Public Variables // Public Variables
// ------------------------ // ------------------------
#if (defined(SERIAL_USB) && !defined(USE_USB_COMPOSITE)) #if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
USBSerial SerialUSB; USBSerial SerialUSB;
#endif #endif
@ -251,7 +251,7 @@ void HAL_init() {
#if PIN_EXISTS(LED) #if PIN_EXISTS(LED)
OUT_WRITE(LED_PIN, LOW); OUT_WRITE(LED_PIN, LOW);
#endif #endif
#ifdef USE_USB_COMPOSITE #if HAS_SD_HOST_DRIVE
MSC_SD_init(); MSC_SD_init();
#endif #endif
#if PIN_EXISTS(USB_CONNECT) #if PIN_EXISTS(USB_CONNECT)
@ -263,17 +263,15 @@ void HAL_init() {
// HAL idle task // HAL idle task
void HAL_idletask() { void HAL_idletask() {
#ifdef USE_USB_COMPOSITE #if HAS_SD_HOST_DRIVE
#if HAS_SHARED_MEDIA // If Marlin is using the SD card we need to lock it to prevent access from
// If Marlin is using the SD card we need to lock it to prevent access from // a PC via USB.
// a PC via USB. // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but // this will not reliably detect delete operations. To be safe we will lock
// this will not reliably detect delete operations. To be safe we will lock // the disk if Marlin has it mounted. Unfortunately there is currently no way
// the disk if Marlin has it mounted. Unfortunately there is currently no way // to unmount the disk from the LCD menu.
// to unmount the disk from the LCD menu. // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN()) /* copy from lpc1768 framework, should be fixed later for process HAS_SD_HOST_DRIVE*/
/* copy from lpc1768 framework, should be fixed later for process HAS_SHARED_MEDIA*/
#endif
// process USB mass storage device class loop // process USB mass storage device class loop
MarlinMSC.loop(); MarlinMSC.loop();
#endif #endif

View file

@ -42,7 +42,7 @@
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#ifdef USE_USB_COMPOSITE #if HAS_SD_HOST_DRIVE
#include "msc_sd.h" #include "msc_sd.h"
#endif #endif
@ -61,7 +61,7 @@
#endif #endif
#ifdef SERIAL_USB #ifdef SERIAL_USB
#ifndef USE_USB_COMPOSITE #if !HAS_SD_HOST_DRIVE
#define UsbSerial Serial #define UsbSerial Serial
#else #else
#define UsbSerial MarlinCompositeSerial #define UsbSerial MarlinCompositeSerial

View file

@ -20,8 +20,3 @@
* *
*/ */
#pragma once #pragma once
#if ENABLED(USE_USB_COMPOSITE)
//#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE."
#undef SD_CHECK_AND_RETRY
#endif

View file

@ -20,3 +20,11 @@
* *
*/ */
#pragma once #pragma once
#ifdef USE_USB_COMPOSITE
//#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE."
#undef SD_CHECK_AND_RETRY
#if DISABLED(NO_SD_HOST_DRIVE)
#define HAS_SD_HOST_DRIVE 1
#endif
#endif

View file

@ -13,7 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* *
*/ */
#if defined(__STM32F1__) && defined(USE_USB_COMPOSITE) #if defined(__STM32F1__) && HAS_SD_HOST_DRIVE
#include "msc_sd.h" #include "msc_sd.h"
#include "SPI.h" #include "SPI.h"
@ -77,4 +77,4 @@ void MSC_SD_init() {
#endif #endif
} }
#endif // __STM32F1__ && USE_USB_COMPOSITE #endif // __STM32F1__ && HAS_SD_HOST_DRIVE

View file

@ -21,10 +21,11 @@
#include "SPI.h" #include "SPI.h"
#include "fastio.h" #include "fastio.h"
#if HAS_SHARED_MEDIA #ifndef ONBOARD_SPI_DEVICE
#ifndef ONBOARD_SPI_DEVICE #define ONBOARD_SPI_DEVICE SPI_DEVICE
#define ONBOARD_SPI_DEVICE SPI_DEVICE #endif
#endif
#if HAS_SD_HOST_DRIVE
#define ONBOARD_SD_SPI SPI #define ONBOARD_SD_SPI SPI
#else #else
SPIClass OnboardSPI(ONBOARD_SPI_DEVICE); SPIClass OnboardSPI(ONBOARD_SPI_DEVICE);

View file

@ -360,14 +360,13 @@
*/ */
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
#if SD_CONNECTION_IS(ONBOARD) && DISABLED(NO_SD_HOST_DRIVE) && !defined(ARDUINO_GRAND_CENTRAL_M4) #if HAS_SD_HOST_DRIVE && SD_CONNECTION_IS(ONBOARD)
// //
// The external SD card is not used. Hardware SPI is used to access the card. // The external SD card is not used. Hardware SPI is used to access the card.
// When sharing the SD card with a PC we want the menu options to // When sharing the SD card with a PC we want the menu options to
// mount/unmount the card and refresh it. So we disable card detect. // mount/unmount the card and refresh it. So we disable card detect.
// //
#undef SD_DETECT_PIN #undef SD_DETECT_PIN
#define HAS_SHARED_MEDIA 1
#endif #endif
#if PIN_EXISTS(SD_DETECT) #if PIN_EXISTS(SD_DETECT)
@ -381,7 +380,6 @@
#define SD_DETECT_STATE LOW #define SD_DETECT_STATE LOW
#endif #endif
#endif #endif
#endif #endif
#if ANY(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT) || !PIN_EXISTS(SD_DETECT) #if ANY(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT) || !PIN_EXISTS(SD_DETECT)