STM32F7 Cube Middleware bug SDcards > 4G
The USB/MSC/SDcard middleware code does not work correctly beyond 4G due to a bug.
My code that is seeing the problem is based on an older version of Cube, but the ST code appears the same in the V1.12.0 cube code I downloaded today.
The SCSI protocol uses a 32bit block address and SDcard uses a 32bit _sector_ address. These work ok and do not have a problem beyond 4G. Unfortunately ST's code tries to convert these block numbers into byte address which causes an overflow (duh.)
The block size on SDcards is 512.
Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c :
-----------
hmsc->scsi_blk_addr *= hmsc->scsi_blk_size; /* THIS OVERFLOWS 32bits */
-----------
Without rewriting that code, I believe it is a simple fix in
Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h
-----------
-- uint32_t scsi_blk_addr; /* Code overflows this. */
++ uint64_t scsi_blk_addr; /* Works correctly for >4G accesses */
uint32_t scsi_blk_len;
}
USBD_MSC_BOT_HandleTypeDef;
-----------
I made that change and now I can read and write beyond the 4G limit. It also means that the card works on Windows 10. Previously it would complain vigorously and when it offered to "fix" the card it actually wiped all the data.
James
PS. Not sure if this has been reported before, I did try searching.
