From f60bc278fa14abc7d7fabf79a8ac9335a1a764b4 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 26 Apr 2025 17:21:41 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Misc.=20HAL,=20flag=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp | 11 ++++++----- Marlin/src/HAL/LPC1768/HAL.cpp | 9 ++------- Marlin/src/HAL/LPC1768/eeprom/eeprom_sdcard.cpp | 2 +- Marlin/src/HAL/RP2040/HAL.cpp | 2 +- Marlin/src/HAL/STM32/HAL.cpp | 2 +- Marlin/src/HAL/STM32/usb_serial.cpp | 4 ++-- Marlin/src/HAL/STM32F1/HAL.cpp | 3 ++- Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp | 2 +- ini/stm32f1-maple.ini | 2 +- ini/stm32f1.ini | 9 +++++---- 10 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp index ff6ff4859b..74cfd9b39b 100644 --- a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp +++ b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp @@ -29,11 +29,10 @@ bool sd_mmc_spi_wr_protect() { return false; } bool sd_mmc_spi_removal() { return !media_ready(); } Ctrl_status sd_mmc_spi_test_unit_ready() { - #ifdef DISABLE_DUE_SD_MMC + #if ENABLED(DISABLE_DUE_SD_MMC) return CTRL_NO_PRESENT; #endif - if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT; - return CTRL_GOOD; + return sd_mmc_spi_removal() ? CTRL_NO_PRESENT : CTRL_GOOD; } // NOTE: This function is defined as returning the address of the last block @@ -58,9 +57,10 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE]; // #define DEBUG_MMC Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { - #ifdef DISABLE_DUE_SD_MMC + #if ENABLED(DISABLE_DUE_SD_MMC) return CTRL_NO_PRESENT; #endif + if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT; #ifdef DEBUG_MMC @@ -97,9 +97,10 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { } Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) { - #ifdef DISABLE_DUE_SD_MMC + #if ENABLED(DISABLE_DUE_SD_MMC) return CTRL_NO_PRESENT; #endif + if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT; #ifdef DEBUG_MMC diff --git a/Marlin/src/HAL/LPC1768/HAL.cpp b/Marlin/src/HAL/LPC1768/HAL.cpp index 6e4357777d..4b0e255f37 100644 --- a/Marlin/src/HAL/LPC1768/HAL.cpp +++ b/Marlin/src/HAL/LPC1768/HAL.cpp @@ -173,13 +173,8 @@ void MarlinHAL::init() { // HAL idle task void MarlinHAL::idletask() { #if HAS_SHARED_MEDIA - // If Marlin is using the SD card we need to lock it to prevent access from - // a PC via USB. - // Other HALs use card.isStillPrinting() and card.isFileOpen() to check for access but - // 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 - // to unmount the disk from the LCD menu. - // if (card.isStillPrinting() || card.isFileOpen()) + // When Marlin is using the SD Card it must be locked to prevent PC access via USB. + // For maximum safety we lock the disk if Marlin has it mounted for any reason. if (card.isMounted()) MSC_Aquire_Lock(); else diff --git a/Marlin/src/HAL/LPC1768/eeprom/eeprom_sdcard.cpp b/Marlin/src/HAL/LPC1768/eeprom/eeprom_sdcard.cpp index 3500f3e7cf..5bf2d353b6 100644 --- a/Marlin/src/HAL/LPC1768/eeprom/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/LPC1768/eeprom/eeprom_sdcard.cpp @@ -52,7 +52,6 @@ bool eeprom_file_open = false; size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; } bool PersistentStore::access_start() { - const char eeprom_erase_value = 0xFF; MSC_Aquire_Lock(); if (f_mount(&fat_fs, "", 1)) { MSC_Release_Lock(); @@ -65,6 +64,7 @@ bool PersistentStore::access_start() { UINT bytes_written; FSIZE_t file_size = f_size(&eeprom_file); f_lseek(&eeprom_file, file_size); + const char eeprom_erase_value = 0xFF; while (file_size < capacity() && res == FR_OK) { res = f_write(&eeprom_file, &eeprom_erase_value, 1, &bytes_written); file_size++; diff --git a/Marlin/src/HAL/RP2040/HAL.cpp b/Marlin/src/HAL/RP2040/HAL.cpp index ceaf540452..6e35fac938 100644 --- a/Marlin/src/HAL/RP2040/HAL.cpp +++ b/Marlin/src/HAL/RP2040/HAL.cpp @@ -77,7 +77,7 @@ void MarlinHAL::init() { HAL_timer_init(); - #if ENABLED(EMERGENCY_PARSER) && USBD_USE_CDC + #if ALL(EMERGENCY_PARSER, USBD_USE_CDC) USB_Hook_init(); #endif diff --git a/Marlin/src/HAL/STM32/HAL.cpp b/Marlin/src/HAL/STM32/HAL.cpp index 6bebaa24f0..a44c333096 100644 --- a/Marlin/src/HAL/STM32/HAL.cpp +++ b/Marlin/src/HAL/STM32/HAL.cpp @@ -87,7 +87,7 @@ void MarlinHAL::init() { SetTimerInterruptPriorities(); - #if ENABLED(EMERGENCY_PARSER) && (USBD_USE_CDC || USBD_USE_CDC_MSC) + #if ENABLED(EMERGENCY_PARSER) && ANY(USBD_USE_CDC, USBD_USE_CDC_MSC) USB_Hook_init(); #endif diff --git a/Marlin/src/HAL/STM32/usb_serial.cpp b/Marlin/src/HAL/STM32/usb_serial.cpp index 0b2372f3a7..1ca8b19976 100644 --- a/Marlin/src/HAL/STM32/usb_serial.cpp +++ b/Marlin/src/HAL/STM32/usb_serial.cpp @@ -26,7 +26,7 @@ #include "../../inc/MarlinConfigPre.h" -#if ENABLED(EMERGENCY_PARSER) && (USBD_USE_CDC || USBD_USE_CDC_MSC) +#if ENABLED(EMERGENCY_PARSER) && ANY(USBD_USE_CDC, USBD_USE_CDC_MSC) #include "usb_serial.h" #include "../../feature/e_parser.h" @@ -56,5 +56,5 @@ void USB_Hook_init() { USBD_CDC_fops.Receive = USBD_CDC_Receive_hook; } -#endif // EMERGENCY_PARSER && USBD_USE_CDC +#endif // EMERGENCY_PARSER && (USBD_USE_CDC || USBD_USE_CDC_MSC) #endif // HAL_STM32 diff --git a/Marlin/src/HAL/STM32F1/HAL.cpp b/Marlin/src/HAL/STM32F1/HAL.cpp index d5f4ade79d..4072e55652 100644 --- a/Marlin/src/HAL/STM32F1/HAL.cpp +++ b/Marlin/src/HAL/STM32F1/HAL.cpp @@ -65,7 +65,8 @@ uint16_t adc_results[ADC_COUNT]; emergency_parser.update(MSerial0.emergency_state, buf[i + total - len]); } #endif -#endif + +#endif // SERIAL_USB && !HAS_SD_HOST_DRIVE // ------------------------ // Watchdog Timer diff --git a/Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp b/Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp index fd3849d1ed..6f3d44dd7f 100644 --- a/Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp +++ b/Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp @@ -109,7 +109,7 @@ bool MAX3421e::start() { // Initialize pins and SPI bus SET_OUTPUT(USB_CS_PIN); - SET_INPUT_PULLUP(USB_INTR_PIN); + SET_INPUT_PULLUP(USB_INTR_PIN); // Active LOW ncs(); spiBegin(); diff --git a/ini/stm32f1-maple.ini b/ini/stm32f1-maple.ini index 0e77ff8dfa..ddd75549c8 100644 --- a/ini/stm32f1-maple.ini +++ b/ini/stm32f1-maple.ini @@ -219,7 +219,7 @@ board_build.address = 0x08010000 board_build.rename = project.bin board_build.ldscript = STM32F103VE_longer.ld build_flags = ${STM32F1_maple.build_flags} - -DMCU_STM32F103VE -DSTM32F1xx -USERIAL_USB -DU20 -DTS_V12 + -DMCU_STM32F103VE -DSTM32F1xx -DSERIAL_USB -DU20 -DTS_V12 build_unflags = ${STM32F1_maple.build_unflags} -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DERROR_LED_PORT=GPIOE -DERROR_LED_PIN=6 diff --git a/ini/stm32f1.ini b/ini/stm32f1.ini index ed60983a23..58b33afaaf 100644 --- a/ini/stm32f1.ini +++ b/ini/stm32f1.ini @@ -64,13 +64,14 @@ board_build.offset = 0x7000 board_upload.offset_address = 0x08007000 [USBD_CDC_MSC] -build_flags = -DUSE_USB_FS -DUSBD_USE_CDC_MSC -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6 +build_flags = -DUSE_USB_FS -DUSBD_USE_CDC_MSC -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6 +build_unflags = -DUSBD_USE_CDC [env:STM32F103RC_btt_USB] extends = env:STM32F103RC_btt platform_packages = ${stm_flash_drive.platform_packages} build_flags = ${env:STM32F103RC_btt.build_flags} ${USBD_CDC_MSC.build_flags} -build_unflags = ${env:STM32F103RC_btt.build_unflags} -DUSBD_USE_CDC +build_unflags = ${env:STM32F103RC_btt.build_unflags} ${USBD_CDC_MSC.build_unflags} # # Panda Pi V2.9 - Standalone (STM32F103RC) @@ -227,7 +228,7 @@ upload_protocol = jlink extends = env:STM32F103RE_btt platform_packages = ${stm_flash_drive.platform_packages} build_flags = ${env:STM32F103RE_btt.build_flags} ${USBD_CDC_MSC.build_flags} -build_unflags = ${env:STM32F103RE_btt.build_unflags} -DUSBD_USE_CDC +build_unflags = ${env:STM32F103RE_btt.build_unflags} ${USBD_CDC_MSC.build_unflags} # # ZNP Robin Nano V1.2 @@ -473,7 +474,7 @@ board_upload.maximum_size = 237568 extra_scripts = ${stm32_variant.extra_scripts} build_flags = ${stm32_variant.build_flags} ${USBD_CDC_MSC.build_flags} -DSS_TIMER=4 -DTIMER_SERVO=TIM5 -build_unflags = ${stm32_variant.build_unflags} -DUSBD_USE_CDC +build_unflags = ${stm32_variant.build_unflags} ${USBD_CDC_MSC.build_unflags} [env:STM32F103RC_ZM3E2_USB] extends = ZONESTAR_ZM3E