cancel
Showing results for 
Search instead for 
Did you mean: 

Using SD Card with STM32L152C Discovery

babak
Associate
Posted on July 08, 2015 at 09:25

I have a STM32L152C Discovery board. I want to use a 1GB FAT SD Card with STM32Cube and EWARM ide, but there is an error.

pins:

    STM --- SD Module

    PA5       SCK

    PA4       CS

    MISO    MISO

    MOSI    MOSI

    Ext_3V   3.3V

    GND     GND

I started STM32Cube, Selected my board ''STM32L152C-DISCO'' in board selector.

I checked FATFS->User-defined check box.

    RCC.High Speed Clock (HSE) -> Crystal/Ceramic Resonator

    SPI1->Full-Duplex Master

And I Created EWARM project.

f_mount() returns 0 and f_open() returns 13, even if I disconnect my sd card from sd module!

int main(void)

{

  printf(''Starting ...\n'');

  GPIO_PinState pinState = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_15);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_SPI1_Init();

  MX_FATFS_Init();

  FATFS SDFatFs;        // File system object for SD card logical drive

  FIL MyFile;           // File object

  volatile FRESULT res; // FatFs function common result code

 

  res = f_mount(&SDFatFs, ''0:'', 0); // returns 0

  if(res != FR_OK)

    printf(''f_mount Error : %d\n'', res); // there is no error

  else

  {

    printf(''f_mount OK\n'');

    res = f_open(&MyFile, ''file.txt'', FA_CREATE_ALWAYS | FA_WRITE); // returns 13

    if(res != FR_OK)

      printf(''f_open Error : %d\n'', res); // f_open Error : 13

    else

    {

      printf(''f_open OK\n'');

      f_close(&MyFile);

      printf(''file opened.'');

    }

    f_mount(0, '''', 1);

  }

}

#stm32l152c-sd-fatfs
0 REPLIES 0