Skip to content

Commit 8b18cfe

Browse files
committed
stm32/usbd_msc: Allow to compile when USB enabled and SD card disabled.
1 parent 5320024 commit 8b18cfe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ports/stm32/usb.c

+2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
364364
for (size_t i = 0; i < msc_n; ++i) {
365365
mp_obj_type_t *type = mp_obj_get_type(items[i]);
366366
if (type == &pyb_flash_type
367+
#if MICROPY_HW_ENABLE_SDCARD
367368
|| type == &pyb_sdcard_type
369+
#endif
368370
#if MICROPY_HW_ENABLE_MMCARD
369371
|| type == &pyb_mmcard_type
370372
#endif

ports/stm32/usbd_msc_interface.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
135135
default:
136136
return -1;
137137
}
138+
#if MICROPY_HW_ENABLE_SDCARD
138139
} else if (lu == &pyb_sdcard_type
139140
#if MICROPY_HW_ENABLE_MMCARD
140141
|| lu == &pyb_mmcard_type
@@ -158,6 +159,7 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
158159
default:
159160
return -1;
160161
}
162+
#endif
161163
} else {
162164
return -1;
163165
}
@@ -205,12 +207,13 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou
205207
if (lun >= usbd_msc_lu_num) {
206208
return -1;
207209
}
208-
const void *lu = usbd_msc_lu_data[lun];
209210

210211
uint8_t alloc_len = params[3] << 8 | params[4];
211212
int len = MIN(sizeof(usbd_msc_inquiry_data), alloc_len);
212213
memcpy(data_out, usbd_msc_inquiry_data, len);
213214

215+
#if MICROPY_HW_ENABLE_SDCARD
216+
const void *lu = usbd_msc_lu_data[lun];
214217
if (len == sizeof(usbd_msc_inquiry_data)) {
215218
if (lu == &pyb_sdcard_type) {
216219
memcpy(data_out + 24, "SDCard", sizeof("SDCard") - 1);
@@ -221,6 +224,7 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou
221224
}
222225
#endif
223226
}
227+
#endif
224228

225229
return len;
226230
}
@@ -282,6 +286,7 @@ STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16
282286
if (lu == &pyb_flash_type) {
283287
storage_read_blocks(buf, blk_addr, blk_len);
284288
return 0;
289+
#if MICROPY_HW_ENABLE_SDCARD
285290
} else if (lu == &pyb_sdcard_type
286291
#if MICROPY_HW_ENABLE_MMCARD
287292
|| lu == &pyb_mmcard_type
@@ -290,6 +295,7 @@ STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16
290295
if (sdcard_read_blocks(buf, blk_addr, blk_len) == 0) {
291296
return 0;
292297
}
298+
#endif
293299
}
294300
return -1;
295301
}
@@ -304,6 +310,7 @@ STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint1
304310
if (lu == &pyb_flash_type) {
305311
storage_write_blocks(buf, blk_addr, blk_len);
306312
return 0;
313+
#if MICROPY_HW_ENABLE_SDCARD
307314
} else if (lu == &pyb_sdcard_type
308315
#if MICROPY_HW_ENABLE_MMCARD
309316
|| lu == &pyb_mmcard_type
@@ -312,6 +319,7 @@ STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint1
312319
if (sdcard_write_blocks(buf, blk_addr, blk_len) == 0) {
313320
return 0;
314321
}
322+
#endif
315323
}
316324
return -1;
317325
}

0 commit comments

Comments
 (0)