Skip to main content
antonius
Associate III
September 6, 2013
Question

Question for STM32 USB Full Speed Device Library V2.2.1

  • September 6, 2013
  • 23 replies
  • 2379 views
Posted on September 06, 2013 at 02:11

Hello guys,

I have a question for :

Question for STM32 USB Full Speed Device Library      V2.2.1

How can I use SD card on Mass_storage demos ?

is it connected via SPI or SDIO ? or I can choose ?

and how can I connect my USB to it ? where can I find the configuration for it ?

I have PA11 and PA12 connected to USB port.

Thanks a lot
    This topic has been closed for replies.

    23 replies

    Tesla DeLorean
    Guru
    September 6, 2013
    Posted on September 06, 2013 at 04:00

    May be 3.4.0 or 4.0.0 would be more appropriate, pick an EVAL board that approximates your board most closely. Mimic that, adjust/port as required.

    STM32_USB-FS-Device_Lib_V4.0.0\Utilities\STM32_EVAL\STM3210E_EVAL\stm3210e_eval_sdio_sd.c

    STM32_USB-FS-Device_Lib_V4.0.0\Utilities\STM32_EVAL\STM3210B_EVAL\stm3210b_eval_spi_sd.c

    STM32_USB-FS-Device_Lib_V4.0.0\Projects\Mass_Storage
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    September 6, 2013
    Posted on September 06, 2013 at 23:48

    ok, thanks for the clue .

    does this application have 2 ability on supporting SD card ?

    I saw on msd.c :

    /*******************************************************************************

    * Function Name  : SPI_Config

    * Description    : Initializes the SPI1 and CS pins.

    * Input          : None

    * Output         : None

    * Return         : None

    *******************************************************************************/

    void SPI_Config(void)

    {

      GPIO_InitTypeDef  GPIO_InitStructure;

      SPI_InitTypeDef   SPI_InitStructure;

      /* GPIOA and GPIOC Periph clock enable */

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);

      /* SPI1 Periph clock enable */

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

      /* Configure SPI1 pins: SCK, MISO and MOSI */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_Init(GPIOA, &GPIO_InitStructure);

      /* Configure PC12 pin: CS pin */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /* SPI1 Config */

      SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

      SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

      SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

      SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

      SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

      SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

      SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;

      SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

      SPI_InitStructure.SPI_CRCPolynomial = 7;

      SPI_Init(SPI1, &SPI_InitStructure);

      /* SPI1 enable */

      SPI_Cmd(SPI1, ENABLE);

    }

    and :

    on sdcard.c

    /*******************************************************************************

    * Function Name  : GPIO_Configuration

    * Description    : Configures the SDIO Corresponding GPIO Ports

    * Input          : None

    * Output         : None

    * Return         : None

    *******************************************************************************/

    static void GPIO_Configuration(void)

    {

      GPIO_InitTypeDef  GPIO_InitStructure;

      /* GPIOC and GPIOD Periph clock enable */

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);

      /* Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /* Configure PD.02 CMD line */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

      GPIO_Init(GPIOD, &GPIO_InitStructure);

    }

    How can I choose it ? or automatically detect which interface I used ?

    thanks

    Tesla DeLorean
    Guru
    September 6, 2013
    Posted on September 07, 2013 at 01:09

    How can I choose it ? or automatically detect which interface I used ?

     

    You should take a look at the project files, the method to select a particular board is usually driven by a define passed into the compiler, and a board appropriate interface is selected. Some F10x parts don't support SDIO, hence the SPI method. It would likely be possible to support multiple interfaces, but you'd have to deal with that and LUN support via MSC/SCSI. I would generally steer clear of SPI as it's hideously slow.

    Clone one of the board support packages under Utilities, and add in the #ifdef customization as required, or just cull the project down for your board, removing LCD and LED support as needed.

    For SDIO review the schematics, be sure to use 33-47K pull-up on the lines close to the socket. Most of the pins you have no choice over, but the Card Detect can be any convenient GPIO.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    September 7, 2013
    Posted on September 07, 2013 at 03:08

    Window can detect the reader as USB mass storage, but can't detect the card yet...

    I used this configuration for connecting the board to card module

    Is it right ?

    /**

      * @brief  Initializes the SD Card and put it into StandBy State (Ready for

      *         data transfer).

      * @param  None

      * @retval None

      */

    void SD_LowLevel_Init(void)

    {

      GPIO_InitTypeDef  GPIO_InitStructure;

      /*!< GPIOC and GPIOD Periph clock enable */

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);

      /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /*!< Configure PD.02 CMD line */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

      GPIO_Init(GPIOD, &GPIO_InitStructure);

      /*!< Configure SD_CD pin: SD Card detect pin */

      GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

      GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);

     

      /*!< Enable the SDIO AHB Clock */

      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);

      /*!< Enable the DMA2 Clock */

      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

    }

    antonius
    antoniusAuthor
    Associate III
    September 7, 2013
    Posted on September 07, 2013 at 03:18

    do you have the link for downloading it ?thanks

    Tesla DeLorean
    Guru
    September 7, 2013
    Posted on September 07, 2013 at 04:38

    [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32%20Legacy%20Firmware%20Libraries&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=5209]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fSTM32%20Legacy%20Firmware%20Libraries&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FAllItems.aspx¤tviews=5209

    http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF258157

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    September 8, 2013
    Posted on September 08, 2013 at 07:53

    Here's the connection to the card,

    Please correct me if I'm wrong

    STM32 --> SD card

    PC8 ---> pin7

    PC9 ---> pin8

    PC10 ---> pin9

    PC11 ---> pin5

    PD2 ---> pin2

    This is the configuration I used

    /**

      * @brief  Initializes the SD Card and put it into StandBy State (Ready for

      *         data transfer).

      * @param  None

      * @retval None

      */

    void SD_LowLevel_Init(void)

    {

      GPIO_InitTypeDef  GPIO_InitStructure;

      /*!< GPIOC and GPIOD Periph clock enable */

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);

      /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /*!< Configure PD.02 CMD line */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

      GPIO_Init(GPIOD, &GPIO_InitStructure);

      /*!< Configure SD_CD pin: SD Card detect pin */

      GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

      GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);

     

      /*!< Enable the SDIO AHB Clock */

      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);

      /*!< Enable the DMA2 Clock */

      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

    }

    it's on SDIO_SD.c

    Tesla DeLorean
    Guru
    September 8, 2013
    Posted on September 08, 2013 at 14:13

    Where's PC12 go? What about the card detect switch?

    This is a schematic of a card configuration, I'd be using pull-ups for all but the clock pins

    0690X0000060518QAA.png

    Personally I use MicroSD cards, they run faster, but ST's code works on 2GB and lower cards better.
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    September 8, 2013
    Posted on September 08, 2013 at 14:33

    Let me correct it :

    STM32 --> SD card

    PC8 ---> pin7

    PC9 ---> pin8

    PC10 ---> pin9

    PC11 ---> pin1

    PC12 -->pin5

    PD2 ---> pin2

    Please correct me if I'm wrong thank you

    Tesla DeLorean
    Guru
    September 8, 2013
    Posted on September 08, 2013 at 15:06

    Please correct me if I'm wrong thank you

    I would appear to have confirmed the connectivity.

    You should evaluate the SDIO functionality outside the context of the USB MSC.

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