cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F429 USB MSD with eMMC + FatFS

Uros Males
Associate II
Posted on October 13, 2015 at 13:07

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
13 REPLIES 13
qwer.asdf
Senior
Posted on October 13, 2015 at 13:57

Why don't you try to format it the traditional way using Windows (right click on drive then Format)? Maybe it's DiskPart's fault. If you have to use command line then I believe it's something like this (where Z: is you drive's letter):

format Z: /FS:NTFS /V:MYLABEL /Q

Warning: If you use NTFS you can't access your files in the microcontroller using FatFs, so use FAT or FAT32 instead of NTFS.
Posted on October 13, 2015 at 14:09

I'd instrument the code outputting the sector numbers it's accessing and double check the read/write are successful, and what sense codes are passed back to Windows. Check also the 64-bit math related to the size is correct.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Uros Males
Associate II
Posted on October 13, 2015 at 14:09

I tried all possible ways to format it (with Windows). None of them work. DiskPart can give you a bit more clue, about what goes wrong than only format command.

Only thing I did not try is to format it using qparted live cd, but I do not want to go there, as I am sure, the problem is with my implementation in the code.

Uros Males
Associate II
Posted on October 13, 2015 at 14:23

clive1, thanks for your input.

This is the card info I get from eMMC: 0690X0000060MnMQAU.gif 0690X0000060MnNQAU.gif *block_size = SDCardInfo.CardBlockSize = 512 *block_num = SDCardInfo.CardCapacity / SDCardInfo.CardBlockSize =8388608 I think I may have a problem with descriptor:

const int8_t STORAGE_Inquirydata_FS[] = {
/* LUN 0 */
0x00, 
0x80, 
0x02, 
0x02,
(STANDARD_INQUIRY_DATA_LEN - 5),
0x00,
0x00, 
0x00,
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'0', '.', '0' ,'1', /* Version : 4 Bytes */
};

/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
0x12, /*bLength */
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
#if (USBD_LPM_ENABLED == 1)
0x01, /*bcdUSB */ /* changed to USB version 2.01 
in order to support LPM L1 suspend
resume test of USBCV3.0*/
#else 
0x00, /* bcdUSB */
#endif
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
LOBYTE(USBD_VID), /*idVendor*/
HIBYTE(USBD_VID), /*idVendor*/
LOBYTE(USBD_PID_FS), /*idVendor*/
HIBYTE(USBD_PID_FS), /*idVendor*/
0x00, /*bcdDevice rel. 2.00*/
0x02,
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
USBD_IDX_PRODUCT_STR, /*Index of product string*/
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
} ;

( USBD_LPM_ENABLED = 0 )

#define USBD_VID 1155
#define USBD_LANGID_STRING 1033
#define USBD_MANUFACTURER_STRING ''STMicroelectronics''
#define USBD_PID_FS 22314
#define USBD_PRODUCT_STRING_FS ''STM32 Mass Storage''
/* USER CODE BEGIN SERIALNUMBER_STRING_FS */
#define USBD_SERIALNUMBER_STRING_FS ''00000000001A''
/* USER CODE END SERIALNUMBER_STRING_FS */
#define USBD_CONFIGURATION_STRING_FS ''MSC Config''
#define USBD_INTERFACE_STRING_FS ''MSC Interface''

Uros Males
Associate II
Posted on October 14, 2015 at 10:38

Update to the thread...

I found the problem. I forgot to wait for DMA to complete my requests...Sdio_WaitUntilDmaRdComplete(); andSdio_WaitUntilDmaTxComplete(); were missing inSTORAGE_Read_FS andSTORAGE_Write_FS

eMMC_ReadMultiBlocks(buf, blk_addr, blk_len);
Sdio_WaitUntilDmaRdComplete();

I was sucessful with formatting 5MB big size, formatting 4GB is stil in progress... it takes very long time. By current estimations... cca 4 days!! And from what I found out, it is the problem with waiting for reponse flag from eMMC that DMA reading/writting was completed. Formatting is basically writing byte by byte from Windows side, not for whole block (512) in one step, but 512 steps for each block. This issue I will address with implementing Chan FatFS and trying to execute format from fw side.
bryenton
Associate II
Posted on October 23, 2015 at 00:28

Hi,

Glad to hear you resolved this.

We are also trying to interface with 4G eMMC using SDIO interface, but can't find any drivers for this.

I see that you have some code snippets attached that do this, and was hoping you might be able to give a pointer to where the source code for this resides on the ST site (or elsewhere). I can't seem to find it anywhere.

Thanks,

Al

Uros Males
Associate II
Posted on October 23, 2015 at 12:20

Hi Al,

I also had big problem with finding some sample for handling eMMC. 

In the end, I had to go through all documentation of stm32f429 manual and JEDEC standard used on eMMC. 

I have finished handling yesterday, so the code above is not 100% complete and may include some small errors.

As this is a part of the code I did at work, I cannot give you all of the code, but if you will have any specific questions, I will try to answer you.

As a first test, I used the sample code generated from CubeMx, to get some feeling, how ST thinks of handling things (this is my first project with eMMC and STM). 

Then I had problems with using HAL drivers as some things are missing in HAL driver (which are in standard driver) and I manually checked differences and added some direct settings for registers etc. in my updated code...

Workflow:

1. SDIO init (with SDIO_BUS_WIDE_1B !)

2. NVIC config

3. eMMC init (eMMC commands)

4. set eMMC bus width to 8

5. set SDIO bus width to 8

6. SDIO clock to 24kHz

7. eMMC get card info (parsing results from command executed already in eMMC init step

8. here I have 2 options:

8.1 mounting FatFs by Chan on eMMC inside Firmware

or

8.2 mounting eMMC to USB MSD driver and using eMMC as Fat32 via usb on Windows

SD_read, SD_write for FatFs by Chan I pointed to same functions for STORAGE_Read_FS, STORAGE_Write_FS used by USB MSD. In this function then you have to:

1. check if eMMC is ready for data !! (otherwise I got corrupted files)

2. read/write to eMMC

3. wait for DMA read/write process to complete

The speed of reading from eMMC via USB MSD on Windows is cca 0,69 MB/s , write is cca 0,51 MB/s (tested with USB Flash Benchmark tool) and I am (for the moment) satisfied with this results as I am using USB FS and not USB HS.

Best regards, U.
qwer.asdf
Senior
Posted on October 23, 2015 at 13:08

> 6. SDIO clock to 24kHz

Isn't it too slow? Or maybe it's a typo (should've been MHz). If not, then maybe that's why your read/write speed is not impressive. Here is what the reference manual of STM32F429 saying:

SDIO_CK is the clock to the card: one bit is transferred on both command and data lines

 

with each clock cycle. The clock frequency can vary between 0 MHz and 20 MHz (for a

 

MultiMediaCard V3.31), between 0 and 48 MHz for a MultiMediaCard V4.0/4.2, or between 0 and 25 MHz (for an SD/SD I/O card).
Uros Males
Associate II
Posted on October 23, 2015 at 14:40

Yes, of course. That was a typo. 24 MHz is correct.

Sdio_SetClock_kHz(24000);

uint16_t Sdio_SetClock_kHz(uint16_t Freq)
{
uint32_t tmpreg;
uint16_t Divisor;
Divisor = 48000/Freq-2;
tmpreg = SDIO->CLKCR;
tmpreg &= 0xFFFFFF00;
Divisor &= 0x00FF;
tmpreg += Divisor;
SDIO->CLKCR = tmpreg;
return Divisor;
}