cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 USB to SD interface

jogerh
Associate II
Posted on January 04, 2016 at 22:50

Dear Community

I tried CLIVE1‘ example (

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/STM32F4-Discovery%20USB%20Mass%20storage&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=9633

)

to connect a SD card via STM32F407 eval board to USB. I ported the files into a KEIL project which was setup using the latest drivers provided by ST. I used following preprocessor symbols:

STM32F40_41xxx, HSE_VALUE=8000000, USE_STM32F4_DISCOVERY,USE_STDPERIPH_DRIVER, USE_USB_OTG_FS,USB_OTG_FS_CORE

I checked the CLOCK setting using MCO and a scope and found everything appeared to be clocked correctly. However (I expected something similar) the example does not work (I don’t see anything detected by the USB master PC).

I started with troubleshooting and ended up here:

int8_t STORAGE_Init (uint8_t lun)

which appears to be  part of a state machine -  however it seems to be not toggled and I don’t know why.

While trialling and erroring I would be very happy if someone could support me by giving a hint were to start with troubleshooting e.g. something like a state machine diagram or a flow chart of what happens inside the example in general. 

null
5 REPLIES 5
Posted on January 05, 2016 at 00:26

to connect a SD card via STM32F407 eval board to USB

Ok, and is this the DISCO board, or something else you can be more specific about?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jogerh
Associate II
Posted on January 05, 2016 at 23:15

Dear Clive,

thank you for responding. I double checked my eval board: it is the STM32F407 Discovery Board Vers. C (meaning it contains the LIS3DSH accelerometer).

In the meantime I followed the code until USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) – where the VBUS seems to be initialized. Due to my pre settings the section  “USE_USB_OTG_FSâ€� is called (which I double checked once). I doubt that it initializes the right pins since the datasheet of the evalboard states: PA9 VBUS_FS; PA10 OTG-FS- ID; PA11 PM and PA12 ID. However I checked the OTG_FS_IRQHandler(void) which is called after the USB is plugged into the receptacle. Here an gintr_status.d32 is read: 0x49 0x53 0x50 0x4C thus it looks like USB initialization worked well (I didn’t checked the other contents of gintr_status yet).

jogerh
Associate II
Posted on January 11, 2016 at 22:32

Hi Folks,

it might be that CLIVE made his demo- prog for another kind of stm32F407 eval board than the one I tried to use for evaluating the code. To use CLIVES’ example code together with the STM32F407 discovery board (version C) and a e.g. the KEIL eval compiler some changes are required:

For proper SDIO detection intead of PH13 e.g. PD2 can be used - the other PINS need to be manually connected with the SD_CARD slot.

To make sure the SDcard is detected properly a test routine might be usefull:


if(SD_Detect() == SD_PRESENT) {
STM_EVAL_LEDOn(LED4);
} else STM_EVAL_LEDOn(LED5);

To make the USB Interface work some changes of the low level initialization are required:


#ifdef USE_USB_OTG_FS 
Lprint(''USE_USB_OTG_FS\0'');
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE); 
/* Configure SOF ID DM DP Pins 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | 
GPIO_Pin_11 | 
GPIO_Pin_12;
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | 
GPIO_Pin_11 | 
GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //100 MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
//GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ; 
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
//PA9 VBUS_FS ; PA10 OTG-FS- ID; PA11 PM and PA12 ID
/* Configure VBUS Pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
/* Configure ID pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 100MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ; 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;

Since the STM32F407 version C board has a quartz included the following predefines will do a god job: STM32F40_41xxx, HSE_VALUE=8000000,USE_STM32F4_DISCOVERY,USE_STDPERIPH_DRIVER, USE_USB_OTG_FS,USB_OTG_FS_CORE Hope this helps and thankyou CLIVE for charing your code with us.
Posted on January 12, 2016 at 01:24

The

http://uk.farnell.com/stmicroelectronics/stm32f4dis-bb/expansion-stm32f4-cortex-m4-discovery/dp/2250205

break out board uses PB.15 (defined in stm32f4_discovery.h w/SDIO additions)

For the original

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/DispForm.aspx?ID=2816

demo I used PC.02 (2012)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 07, 2018 at 20:19

 ,

 ,

Link to the wire-wrapped board

 ,
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..