cancel
Showing results for 
Search instead for 
Did you mean: 

Cube Generated USB MSC project for STM32F105

zhanzongru
Associate
Posted on December 21, 2015 at 10:37

I have a USB-MSC project developed with SPL and stand alone USB OTG Library(V2.1.0).

The CPU is STM32F105RB. The medium of Massstorage is a SPI-Flash, which has a 4096 Bytes sector size. The board works as a device only MSC device.

While it works just fine under SPL and the standalone USB OTG library, I would like to migrate to the STM32Cube tool to improve the maintainability of the whole project.

But now I have problem to make the MSC to work correctly with the Cube generated code. The PC only recognized the USB Disk, any read/write operation could not be proceeded.

By some debugging, I found the first  SCSI_Read10 commands pass wrong read block size to the STM32 USB core.

My sector size is 4096, but the first READ10 commands pass a size of 512 in the CBW length field(dDataLength). So the Read10 command parsing function return error(-1).

Before the first READ10 commands, there are some SCSI Read Format Capacity and SCSI Read Capacity commands, all these command are fed with correct sector size(4096).

On the Standalone USB Library - based project, the CBW data length field(dDataLength) are always correct sector size(4096).

P.S. The User Manual: UM1021, is about the standalone library. I have not found the counterpart manual of the Cube generated USB library code.  The two libraries are very different, because the new library use HAL and LL libraries, for which I also failed to find human readable documents.

Please give me some hints.

The SPL+USB Standalone project:

The host only send each one SCSI Read Format Capacity and SCSI Read Capacity command. Then SCSI Read 10 command.

The Cube Generated project:

The host sends 3 repeated SCSI Read Format Capacity and 2 repeated SCSI Read Capacity commands. Then SCSI Read 10 command(with wrong sector size 0x200).

I have compared the command responses, no difference found.

I suspected the responses from my board failed to reach host PC. Although the function:

HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)

Always returns  success(USBD_OK).

My CubeMx Version: 4.12.0,  Firmware Version: F1_1.20

I have used FreeRTOS.

#!stm32-!cubemx #usb #stm32 #stm32f1
1 REPLY 1
zhanzongru
Associate
Posted on December 21, 2015 at 16:12

Problem solved. Although I am not very sure where the issue was. I though it could be those debug ''printf''s.  I will investigate it later. Now I must focus on my project.