cancel
Showing results for 
Search instead for 
Did you mean: 

Where is the UsbMassStorage Examples / Supt for stm32f4xx ? - Solved

jlchoobs
Associate II
Posted on April 18, 2012 at 06:58

I have an obvious question :

How do I implement SDCard as MassStorage on the Stm32f4Discovery Board ?

Why is there Examples of this for the stm32F103 but not for the stm32F4discovery ?

The wonderful 22examples for the Discovery are a lot less than the stm32f103 examples present.

It seems like it should be a simple modifying of code.

But, I find no examples or support for this anywhere at Stm or on the internet (besides my site).

Has Anybody tried this Project yet ?

#stm32f4discovery #stm3240g #epic-fail #msc
35 REPLIES 35
Posted on June 22, 2012 at 00:02

Attached is am initial correction to the MSC library code for the F2, for the F4 you'll want to pull out the SD_ReadMultiBlocksFIXED() and SD_WriteMultiBlocksFIXED() into the stm324xg_eval_sdio.c & .h files (or whatever they are called). Should just be a cut-n-paste operation.

I've basically moved from a BYTE orientated addressing to BLOCK orientated addressing so the offset into the flash device doesn't exceed the 32-bit / 4GB bounds. I also addresses so unnecessary casting between 16-32-16 bit to avoid any potential future loss of precision.

I've done some early testing of this, will do some more.

If the forum crashed in the future and eats this attachment, or you need to discuss it off-board, my address is sourcer32@gmail.com

________________

Attachments :

patched_4gb_msc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0ZD&d=%2Fa%2F0X0000000baU%2FZejudsZTfY6vLnVvip_SPwLDmrkmI.NxsbH4GP9WJKI&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 25, 2012 at 20:21

Attached is a complete STM32F4-Discovery project for SDHC Cards via USB Mass Storage (MSC)

The SD Slot/Socket is expected to be wired as follows

CARDDETECT = PC2 (Retargetable)

CLK = PC12

CMD = PD2

D0 = PC8

D1 = PC9

D2 = PC10

D3 = PC11

VDD = 3V

VSS = GND

PC10 (SCLK) and PC12 (SDIN) potentially conflict with the CS43L22

This builds with GNU/GCC 4.6.2 or 4.7.1

________________

Attachments :

stm32f4_discovery_msc_sdhc_release_1.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtZW&d=%2Fa%2F0X0000000aRs%2FabJy6M7lXP0vxZjlXODQPOPNQrRf.xKTQu_yEq4Ewao&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jlchoobs
Associate II
Posted on June 26, 2012 at 16:58

My Notes on Porting the Stm3240g Code over to Stm32F4Discovery :

* CardDetect had to be rewired to PH0 and reconfigured in stm324xg_eval.h :

  #define SD_DETECT_PIN                     GPIO_Pin_0              /* PH.0 */

  #define SD_DETECT_GPIO_PORT      GPIOH                      /* GPIOH */

* In stm324xg_eval.c comment out code for unused periphs like Buttons etc.

* Tested successfully using 128MB and 512MB SD Cards.

Also, you can try testing around the Card Detect -by ignoring it in stm324xg_eval_sdio_sd.c :

uint8_t SD_Detect(void)

{

  __IO uint8_t status = SD_PRESENT;

  /*!< Check GPIO to detect SD */

 //  if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != Bit_RESET) // SD_DETECT_PIN=PH13

  if( 0 )  // - TEST

  {

    status = SD_NOT_PRESENT;

  }

  return status;

}

arnold
Associate II
Posted on June 29, 2012 at 20:20

Maybee a stupid question but how do i convert a uint64_t to string 

i wan't to display the cardsize on my glcd

Posted on June 29, 2012 at 23:02

Maybee a stupid question but how do i convert a uint64_t to string i wan't to display the cardsize on my glcd

Would depend on your tool chain and printf support. You could easily get it into a 32-bit range by dividing into GB, MB or KB units. An off the cuff 64-bit unsigned to ASCII could look like this

char *dec64(uint64_t i)
{
static char string[32]; // enough for 20 digits + NUL

char *s = string + sizeof(string);
*--s = 0;
do
{
*--s = '0' + (char)(i % 10);
i = i / 10;
} while(i);
return(s);
}

I might also mention that you should be putting 47K pull-ups on the D0..D3, CMD and CARDDETECT pins.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arnold
Associate II
Posted on June 30, 2012 at 09:04

thanks a lot, know i can display the card size :)

looks like works for me. next thing display a bmp from sd to the display.
rishi
Associate II
Posted on July 05, 2012 at 17:57

@ clive1...where is the keil 4 project file as mentioned by you....where is the working code download link...please share...need that urgently

arnold
Associate II
Posted on July 05, 2012 at 18:35

it is his attachment, in the titel of every post you can see if there is an attachment or not. 

just look for the paperclip

 

 

 

Posted on July 05, 2012 at 19:05

@ clive1...where is the keil 4 project file as mentioned by you....where is the working code download link...please share...need that urgently

I've only posted the GNU project as it is stand-alone. The Keil one has library/source dependencies. You will need to email to get a copy of it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rishi
Associate II
Posted on July 09, 2012 at 12:02

why i am getting the format the card when  i want to open that...and during format the formatting ends with the error ''system cannot complete the formatting''

i am using 2gb card...