2024-02-05 03:25 AM
Hi!
I'm currently trying to mount my sdcard via MSC/SDMMC and tinyUSB. It worked fine with RAM, could read and write, but I probably do the commands wrong for SD Card. Mounting with FatFS works fine, but I cannot get it to display any device on my drive. It just shows the SD Card and wants to format it, which will always fail.
Here are the functions I use for MSC, just changed the fufnctions from RAM readings to SD Card readings.
int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize)
{
(void) lun;
// if ( lba >= DISK_BLOCK_NUM ) return -1;
// size_t addr = lba * BLOCK_SIZE + offset;
HAL_SD_WriteBlocks(&hsd, (uint8_t*)buffer, lba, bufsize, 10);
// while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER){}
/* Wait until SD card is ready to use for new operation */
return (int32_t) bufsize;
}
int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{
(void) lun;
// out of ramdisk
// uint8_t const* addr = msc_disk[lba] + offset;
// size_t addr = lba * BLOCK_SIZE + offset;
// HAL_SD_ReadBlocks(&hsd, buffer, addr, bufsize, 100);
HAL_SD_ReadBlocks(&hsd, (uint8_t*)buffer, lba, bufsize, 10);
/* Wait until SD card is ready to use for new operation */
// while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER){}
return (int32_t) bufsize;
}
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size)
{
HAL_SD_CardInfoTypeDef info;
HAL_SD_GetCardInfo(&hsd, &info);
*block_count = info.LogBlockNbr - 1;
*block_size = info.LogBlockSize;
}
If anyone could tell me what I'm doing wrong, that would be so great, as I don't get any proper results with it!
Kind regards