Skip to content

Commit f60bc27

Browse files
committed
🩹 Misc. HAL, flag fixes
1 parent e0d8ea5 commit f60bc27

File tree

10 files changed

+22
-24
lines changed

10 files changed

+22
-24
lines changed

Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ bool sd_mmc_spi_wr_protect() { return false; }
2929
bool sd_mmc_spi_removal() { return !media_ready(); }
3030

3131
Ctrl_status sd_mmc_spi_test_unit_ready() {
32-
#ifdef DISABLE_DUE_SD_MMC
32+
#if ENABLED(DISABLE_DUE_SD_MMC)
3333
return CTRL_NO_PRESENT;
3434
#endif
35-
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
36-
return CTRL_GOOD;
35+
return sd_mmc_spi_removal() ? CTRL_NO_PRESENT : CTRL_GOOD;
3736
}
3837

3938
// 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];
5857
// #define DEBUG_MMC
5958

6059
Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
61-
#ifdef DISABLE_DUE_SD_MMC
60+
#if ENABLED(DISABLE_DUE_SD_MMC)
6261
return CTRL_NO_PRESENT;
6362
#endif
63+
6464
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
6565

6666
#ifdef DEBUG_MMC
@@ -97,9 +97,10 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
9797
}
9898

9999
Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
100-
#ifdef DISABLE_DUE_SD_MMC
100+
#if ENABLED(DISABLE_DUE_SD_MMC)
101101
return CTRL_NO_PRESENT;
102102
#endif
103+
103104
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
104105

105106
#ifdef DEBUG_MMC

Marlin/src/HAL/LPC1768/HAL.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,8 @@ void MarlinHAL::init() {
173173
// HAL idle task
174174
void MarlinHAL::idletask() {
175175
#if HAS_SHARED_MEDIA
176-
// If Marlin is using the SD card we need to lock it to prevent access from
177-
// a PC via USB.
178-
// Other HALs use card.isStillPrinting() and card.isFileOpen() to check for access but
179-
// this will not reliably detect delete operations. To be safe we will lock
180-
// the disk if Marlin has it mounted. Unfortunately there is currently no way
181-
// to unmount the disk from the LCD menu.
182-
// if (card.isStillPrinting() || card.isFileOpen())
176+
// When Marlin is using the SD Card it must be locked to prevent PC access via USB.
177+
// For maximum safety we lock the disk if Marlin has it mounted for any reason.
183178
if (card.isMounted())
184179
MSC_Aquire_Lock();
185180
else

Marlin/src/HAL/LPC1768/eeprom/eeprom_sdcard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ bool eeprom_file_open = false;
5252
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
5353

5454
bool PersistentStore::access_start() {
55-
const char eeprom_erase_value = 0xFF;
5655
MSC_Aquire_Lock();
5756
if (f_mount(&fat_fs, "", 1)) {
5857
MSC_Release_Lock();
@@ -65,6 +64,7 @@ bool PersistentStore::access_start() {
6564
UINT bytes_written;
6665
FSIZE_t file_size = f_size(&eeprom_file);
6766
f_lseek(&eeprom_file, file_size);
67+
const char eeprom_erase_value = 0xFF;
6868
while (file_size < capacity() && res == FR_OK) {
6969
res = f_write(&eeprom_file, &eeprom_erase_value, 1, &bytes_written);
7070
file_size++;

Marlin/src/HAL/RP2040/HAL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void MarlinHAL::init() {
7777

7878
HAL_timer_init();
7979

80-
#if ENABLED(EMERGENCY_PARSER) && USBD_USE_CDC
80+
#if ALL(EMERGENCY_PARSER, USBD_USE_CDC)
8181
USB_Hook_init();
8282
#endif
8383

Marlin/src/HAL/STM32/HAL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void MarlinHAL::init() {
8787

8888
SetTimerInterruptPriorities();
8989

90-
#if ENABLED(EMERGENCY_PARSER) && (USBD_USE_CDC || USBD_USE_CDC_MSC)
90+
#if ENABLED(EMERGENCY_PARSER) && ANY(USBD_USE_CDC, USBD_USE_CDC_MSC)
9191
USB_Hook_init();
9292
#endif
9393

Marlin/src/HAL/STM32/usb_serial.cpp

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

2727
#include "../../inc/MarlinConfigPre.h"
2828

29-
#if ENABLED(EMERGENCY_PARSER) && (USBD_USE_CDC || USBD_USE_CDC_MSC)
29+
#if ENABLED(EMERGENCY_PARSER) && ANY(USBD_USE_CDC, USBD_USE_CDC_MSC)
3030

3131
#include "usb_serial.h"
3232
#include "../../feature/e_parser.h"
@@ -56,5 +56,5 @@ void USB_Hook_init() {
5656
USBD_CDC_fops.Receive = USBD_CDC_Receive_hook;
5757
}
5858

59-
#endif // EMERGENCY_PARSER && USBD_USE_CDC
59+
#endif // EMERGENCY_PARSER && (USBD_USE_CDC || USBD_USE_CDC_MSC)
6060
#endif // HAL_STM32

Marlin/src/HAL/STM32F1/HAL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ uint16_t adc_results[ADC_COUNT];
6565
emergency_parser.update(MSerial0.emergency_state, buf[i + total - len]);
6666
}
6767
#endif
68-
#endif
68+
69+
#endif // SERIAL_USB && !HAS_SD_HOST_DRIVE
6970

7071
// ------------------------
7172
// Watchdog Timer

Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ bool MAX3421e::start() {
109109
// Initialize pins and SPI bus
110110

111111
SET_OUTPUT(USB_CS_PIN);
112-
SET_INPUT_PULLUP(USB_INTR_PIN);
112+
SET_INPUT_PULLUP(USB_INTR_PIN); // Active LOW
113113
ncs();
114114
spiBegin();
115115

ini/stm32f1-maple.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ board_build.address = 0x08010000
219219
board_build.rename = project.bin
220220
board_build.ldscript = STM32F103VE_longer.ld
221221
build_flags = ${STM32F1_maple.build_flags}
222-
-DMCU_STM32F103VE -DSTM32F1xx -USERIAL_USB -DU20 -DTS_V12
222+
-DMCU_STM32F103VE -DSTM32F1xx -DSERIAL_USB -DU20 -DTS_V12
223223
build_unflags = ${STM32F1_maple.build_unflags}
224224
-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DERROR_LED_PORT=GPIOE -DERROR_LED_PIN=6
225225

ini/stm32f1.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ board_build.offset = 0x7000
6464
board_upload.offset_address = 0x08007000
6565

6666
[USBD_CDC_MSC]
67-
build_flags = -DUSE_USB_FS -DUSBD_USE_CDC_MSC -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
67+
build_flags = -DUSE_USB_FS -DUSBD_USE_CDC_MSC -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
68+
build_unflags = -DUSBD_USE_CDC
6869

6970
[env:STM32F103RC_btt_USB]
7071
extends = env:STM32F103RC_btt
7172
platform_packages = ${stm_flash_drive.platform_packages}
7273
build_flags = ${env:STM32F103RC_btt.build_flags} ${USBD_CDC_MSC.build_flags}
73-
build_unflags = ${env:STM32F103RC_btt.build_unflags} -DUSBD_USE_CDC
74+
build_unflags = ${env:STM32F103RC_btt.build_unflags} ${USBD_CDC_MSC.build_unflags}
7475

7576
#
7677
# Panda Pi V2.9 - Standalone (STM32F103RC)
@@ -227,7 +228,7 @@ upload_protocol = jlink
227228
extends = env:STM32F103RE_btt
228229
platform_packages = ${stm_flash_drive.platform_packages}
229230
build_flags = ${env:STM32F103RE_btt.build_flags} ${USBD_CDC_MSC.build_flags}
230-
build_unflags = ${env:STM32F103RE_btt.build_unflags} -DUSBD_USE_CDC
231+
build_unflags = ${env:STM32F103RE_btt.build_unflags} ${USBD_CDC_MSC.build_unflags}
231232

232233
#
233234
# ZNP Robin Nano V1.2
@@ -473,7 +474,7 @@ board_upload.maximum_size = 237568
473474
extra_scripts = ${stm32_variant.extra_scripts}
474475
build_flags = ${stm32_variant.build_flags} ${USBD_CDC_MSC.build_flags}
475476
-DSS_TIMER=4 -DTIMER_SERVO=TIM5
476-
build_unflags = ${stm32_variant.build_unflags} -DUSBD_USE_CDC
477+
build_unflags = ${stm32_variant.build_unflags} ${USBD_CDC_MSC.build_unflags}
477478

478479
[env:STM32F103RC_ZM3E2_USB]
479480
extends = ZONESTAR_ZM3E

0 commit comments

Comments
 (0)