STM32F429I-Disco with SDCard

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

kiwi
Posts: 13
Joined: Mon Feb 23, 2015 3:47 pm

STM32F429I-Disco with SDCard

Post by kiwi »

Hello guys,

I'am fairly new to the whole micro controller programming except for some experience with Arduino and so far I have managed to build the stm32f429i-disco demo application as well as chibiOS with uGFX.
I've builded these sample applications Linux with make + vi.
The following questions I have for you are rather basic, but I really would appreciate some clarifications because I'm rather confused.

Ok, I want to connect a SDCard to my stm32f429, I guess I will have to use SPI for that, right?
To which ports do I have to connect my card?
I read through the official board manual and the documentation I could find but still I don't know to which ports on the board I have to connect my SDcard. Is there a document describing the properties of the ports? Something like 'you can use PA7 for SPI and I2C' and I can then choose which of the ports I use for what or is the function of a port statically defined (e.g. PA7 is SPI1 CS)?
Or can I use every free port for SPI connection as long as nothing else is using it for communication?

I would appreciate it if you could point me in the right direction.
thanks,
kiwi
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F429I-Disco with SDCard

Post by Giovanni »

Hi,

ChibiOS has both the driver for cards attached via SPI (MMC_SPI) and an SDC driver that uses the SDIO peripheral, you can use any of those. for MMC_SPI you can use any SPI port.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: STM32F429I-Disco with SDCard

Post by Tectu »

If you're interested: As soon as your SD card is working inside of the ChibiOS/RT framework you can use the GFILE module of the uGFX library to easily handle your files. Most uGFX items provide a highlevel GFILE API that makes it super easy to display images, save and restore calibration data etc.


~ Tectu
kiwi
Posts: 13
Joined: Mon Feb 23, 2015 3:47 pm

Re: STM32F429I-Disco with SDCard

Post by kiwi »

Hi Giovanni,

thanks so far. But it's still confusing for me which of the ports of the STM32F429i-disco is an SPI or SDIO port?
I can't find anything in the documentation provided here http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090.
Or do I have to configure the ports somwhere?

EDIT:
@tecu that is exactly where I want to go, but so far I think I'm lacking basic knowledge to connect and setup my SDCard properly.

best,
kiwi
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: STM32F429I-Disco with SDCard

Post by Tectu »

kiwi wrote:I can't find anything in the documentation provided here http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090.

When you decide to use SDIO (which I highly recommend as it is the standard) then you don't have a choice. There is only one set of SDC pins on the STM32. When you want to use SPI you can use any of the SPI peripherals.

In the datasheet of the microcontroller that you are using (http://www.st.com/st-web-ui/static/acti ... 071990.pdf) you can see on page 76 that the corresponding pins are PC8 to PC12 and PD2. All of them need to be configured as AF12.


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F429I-Disco with SDCard

Post by Giovanni »

Pin assignments are described in the STM32 DataSheet (not the Reference Manual). You can configure them by editing board.h. See the board files of the Olimex STM32-E407 board for an example.

Giovanni
kiwi
Posts: 13
Joined: Mon Feb 23, 2015 3:47 pm

Re: STM32F429I-Disco with SDCard

Post by kiwi »

Hello,

I connected my SDCard to the pins for SDIO mentioned in the datasheet and wrote a little test to check whether I'am able to write to the SDcard but according to gdb f_open returns FR_NOT_READY.
Can you tell me whether my code is correct or if I miss configured the board.h?
Here is the main.c and I put the board.h on gist.github.com: https://gist.github.com/bigzed/eaa8beb9e121321d5b98

thanks a lot,
kiwi

Code: Select all

#include "ch.h"
#include "hal.h"

/* FatFS */
#include "ff.h"

#include "main.h"

FATFS SDC_FS;

/* SDCDriver config. */
static SDCConfig sdccfg = {0};

int main(void)
{
  halInit();
  chSysInit();

  /* Initialize SDCard over SDIO */
  sdcObjectInit(&SDCD1);
  sdcStart(&SDCD1, &sdccfg);

  if(sdcConnect(&SDCD1)) {
    if(f_mount(0, &SDC_FS) == FR_OK) {
      FIL file;
      UINT written;

      if(f_open(&file, "test.txt", FA_CREATE_ALWAYS) == FR_OK) {
        f_write(&file, (void*)"a", 8, &written);
        f_close(&file);
      }
    }
  }

  while(TRUE) {
    chThdSleepMilliseconds(500);
  }

  return 1;
}
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F429I-Disco with SDCard

Post by Giovanni »

sdcConnect() returns true in case of errors, you are writing after the connection failed.

Giovanni
kiwi
Posts: 13
Joined: Mon Feb 23, 2015 3:47 pm

Re: STM32F429I-Disco with SDCard

Post by kiwi »

Ok, but shouldn't this mean I configured the pins incorrectly?
Here is a diff of my board.h to configure the pins PC8-PC12 and PD2 as AF12. Is this correct at all?
Sorry for the basic questions. :oops:

Code: Select all

-#define VAL_GPIOC_AFRH              (PIN_AFIO_AF(GPIOC_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_I2C3_SDA, 4) |       \
-                                     PIN_AFIO_AF(GPIOC_LCD_R2, 14) |        \
-                                     PIN_AFIO_AF(GPIOC_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOC_PIN12, 0) |          \
+#define VAL_GPIOC_AFRH              (PIN_AFIO_AF(GPIOC_PIN8, 12) |           \
+                                     PIN_AFIO_AF(GPIOC_I2C3_SDA, 12) |       \
+                                     PIN_AFIO_AF(GPIOC_LCD_R2, 12) |        \
+                                     PIN_AFIO_AF(GPIOC_PIN11, 12) |          \
+                                     PIN_AFIO_AF(GPIOC_PIN12, 12) |          \
                                      PIN_AFIO_AF(GPIOC_PIN13, 0) |          \
                                      PIN_AFIO_AF(GPIOC_OSC32_IN, 0) |       \
                                      PIN_AFIO_AF(GPIOC_OSC32_OUT, 0))
@@ -688,7 +688,8 @@
                                      PIN_AFIO_AF(GPIOD_PIN5, 0) |           \
                                      PIN_AFIO_AF(GPIOD_LCD_B2, 14) |        \
                                      PIN_AFIO_AF(GPIOD_PIN7, 0))
-#define VAL_GPIOD_AFRH              (PIN_AFIO_AF(GPIOD_FMC_D13, 12) |       \
+#define VAL_GPIOD_AFRH              (PIN_AFIO_AF(GPIOD_PIN2, 12) |          \
+                                     PIN_AFIO_AF(GPIOD_FMC_D13, 12) |       \
                                      PIN_AFIO_AF(GPIOD_FMC_D14, 12) |       \
                                      PIN_AFIO_AF(GPIOD_FMC_D15, 12) |       \
                                      PIN_AFIO_AF(GPIOD_LCD_TE, 0) |         \

User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F429I-Disco with SDCard

Post by Giovanni »

Hi,

For an example of SDC pin configuration give a look to the Olimex boards with F4 devices, for example the STM32-E407, if your board use the same pins you can copy the configuration from there.

Giovanni
Post Reply