SD Card + SPI interface + USB Device Mass Storage?
Hi! I am trying to connect my code (SD in SPI mode) to USB Device Mass Storage. I have tested my SD with SPI interface writing and reading blocks and files with FATFS and it works without problems... But when I connect it with STORAGE_Write_FS and STORAGE_Read_FS the computer ask me to format the unit... The computer read properly the card capacity but only when it is going to format the unit. I don't know what to do to solve this.
I share the code lines below:
int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
{
/* USER CODE BEGIN 3 */ //// storage is a extern variable that reads the card capacity (this is OK)
*block_num = storage / BLOCK_SIZE; //fre_sect/2 / BLOCK_SIZE;
*block_size = BLOCK_SIZE;
return (USBD_OK);
/* USER CODE END 3 */
}
int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
/* USER CODE BEGIN 6 */
uint64_t br=0;
while(br<blk_len)
{
SD_Read_Block(buf, blk_addr);br++;
}
HAL_UART_Transmit(&huart2, (uint8_t*)"READ_USB", sizeof("READ_USB"),100);
return (USBD_OK);
/* USER CODE END 6 */
}
int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
/* USER CODE BEGIN 7 */
uint64_t bw=0;
while(bw<blk_len)
{
SD_Write_Block(buf, blk_addr);bw++;
}
HAL_UART_Transmit(&huart2, (uint8_t*)"WRITE_USB", sizeof("WRITE_USB"),100);
return (USBD_OK);
/* USER CODE END 7 */
}
