stm32/usbd_msc: Allow to compile when USB enabled and SD card disabled.

This commit is contained in:
Damien George 2019-06-11 21:01:14 +10:00
parent 53200247b7
commit 8b18cfedee
2 changed files with 11 additions and 1 deletions

View File

@ -364,7 +364,9 @@ STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
for (size_t i = 0; i < msc_n; ++i) { for (size_t i = 0; i < msc_n; ++i) {
mp_obj_type_t *type = mp_obj_get_type(items[i]); mp_obj_type_t *type = mp_obj_get_type(items[i]);
if (type == &pyb_flash_type if (type == &pyb_flash_type
#if MICROPY_HW_ENABLE_SDCARD
|| type == &pyb_sdcard_type || type == &pyb_sdcard_type
#endif
#if MICROPY_HW_ENABLE_MMCARD #if MICROPY_HW_ENABLE_MMCARD
|| type == &pyb_mmcard_type || type == &pyb_mmcard_type
#endif #endif

View File

@ -135,6 +135,7 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
default: default:
return -1; return -1;
} }
#if MICROPY_HW_ENABLE_SDCARD
} else if (lu == &pyb_sdcard_type } else if (lu == &pyb_sdcard_type
#if MICROPY_HW_ENABLE_MMCARD #if MICROPY_HW_ENABLE_MMCARD
|| lu == &pyb_mmcard_type || lu == &pyb_mmcard_type
@ -158,6 +159,7 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
default: default:
return -1; return -1;
} }
#endif
} else { } else {
return -1; return -1;
} }
@ -205,12 +207,13 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou
if (lun >= usbd_msc_lu_num) { if (lun >= usbd_msc_lu_num) {
return -1; return -1;
} }
const void *lu = usbd_msc_lu_data[lun];
uint8_t alloc_len = params[3] << 8 | params[4]; uint8_t alloc_len = params[3] << 8 | params[4];
int len = MIN(sizeof(usbd_msc_inquiry_data), alloc_len); int len = MIN(sizeof(usbd_msc_inquiry_data), alloc_len);
memcpy(data_out, usbd_msc_inquiry_data, len); memcpy(data_out, usbd_msc_inquiry_data, len);
#if MICROPY_HW_ENABLE_SDCARD
const void *lu = usbd_msc_lu_data[lun];
if (len == sizeof(usbd_msc_inquiry_data)) { if (len == sizeof(usbd_msc_inquiry_data)) {
if (lu == &pyb_sdcard_type) { if (lu == &pyb_sdcard_type) {
memcpy(data_out + 24, "SDCard", sizeof("SDCard") - 1); 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
} }
#endif #endif
} }
#endif
return len; return len;
} }
@ -282,6 +286,7 @@ STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16
if (lu == &pyb_flash_type) { if (lu == &pyb_flash_type) {
storage_read_blocks(buf, blk_addr, blk_len); storage_read_blocks(buf, blk_addr, blk_len);
return 0; return 0;
#if MICROPY_HW_ENABLE_SDCARD
} else if (lu == &pyb_sdcard_type } else if (lu == &pyb_sdcard_type
#if MICROPY_HW_ENABLE_MMCARD #if MICROPY_HW_ENABLE_MMCARD
|| lu == &pyb_mmcard_type || 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
if (sdcard_read_blocks(buf, blk_addr, blk_len) == 0) { if (sdcard_read_blocks(buf, blk_addr, blk_len) == 0) {
return 0; return 0;
} }
#endif
} }
return -1; return -1;
} }
@ -304,6 +310,7 @@ STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint1
if (lu == &pyb_flash_type) { if (lu == &pyb_flash_type) {
storage_write_blocks(buf, blk_addr, blk_len); storage_write_blocks(buf, blk_addr, blk_len);
return 0; return 0;
#if MICROPY_HW_ENABLE_SDCARD
} else if (lu == &pyb_sdcard_type } else if (lu == &pyb_sdcard_type
#if MICROPY_HW_ENABLE_MMCARD #if MICROPY_HW_ENABLE_MMCARD
|| lu == &pyb_mmcard_type || 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
if (sdcard_write_blocks(buf, blk_addr, blk_len) == 0) { if (sdcard_write_blocks(buf, blk_addr, blk_len) == 0) {
return 0; return 0;
} }
#endif
} }
return -1; return -1;
} }