cancel
Showing results for 
Search instead for 
Did you mean: 

USB HS MSD on STM32H7 is very unstable.

VVi.1701
Associate II

I am using STM32H750 with eMMC in MSD mode, with code generated by CubeMX Version: 6.1.0.

USB works in HS mode with external phy USB3320.

USB MSD correctly recognized by PC, but when i try to download file from it, transfer crashes in random time.

If i increase MSC_MEDIA_PACKET size, data sends faster, but transfer becomes more unstable.

I found place on which crashes transfer - this is function PCD_WriteEmptyTxFifo(), at random time when PCD_WriteEmptyTxFifo() start working, after call function USB_WritePacket() that writes data to USB FIFO, data stops readout from FIFO, FIFO becomes fullfilled and condition "(USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= len32b" is not satisfied. Transfer stops and USB is not working anymore.

There is one weird thing: i tried to replace function that reads data from eMMC by memset(), and found that if the function sets working buffer by all zeros, USB stack works fine, transfer complete without any errors, but if function set working buffer by other values i.e. 0xFE - transfer crashes.

(See the code, function STORAGE_Read_HS uses memset() instead of HAL_MMC_ReadBlocks() starting from address 0x0001D000, so mass storage device is correctly initialized by PC, because file system table is placed "before" this address in eMMC)

uint8_t byte = 0;
 
int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
	if(blk_addr >= 0x0001D000){//this "if" works only when i try to download file, while initialising USB MSD works HAL_MMC_ReadBlocks
		printf("wr 0x%02X\n", byte);
		memset(buf, (uint8_t)byte, (size_t)(blk_len*512));//if byte == 0, transfer already works fine
		return HAL_OK;
	}
 
	while(Wait_MMCCARD_Ready() != HAL_OK){}
	if(HAL_MMC_ReadBlocks(&hmmc2, buf, blk_addr, (uint32_t)blk_len, 5) == HAL_OK){
		return HAL_OK;
	}
	return (-1);
}

What may be cause of this problem? Looks like the host stops reading data from device.

1 REPLY 1
VVi.1701
Associate II

I changed USB3320 crystal oscillator from 26 MHz to 24 MHz, and USB became working well on Windows. But there still was errors when i tried to download files from device on Linux.

Then i connected VBAT pin of USB3320 to 5V (it was connected to 3.3V) and seems like the problem was solved.