SD card mount issue on F103

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
rizzir
Posts: 5
Joined: Mon Feb 29, 2016 7:48 pm

Re: SD card mount issue on F103

Post by rizzir »

Well, this thread is quite old but while trying to get an SD card working on an STM32-F103 I stumbled uppon this thread as well as another thread where Giovanni pointed to the F103 SD card example for version 2.6. I tried to port everything to the current 16.1.x version.

Anyway, I figured out that I have to configure the pins for the SPI bus like this:

Code: Select all

  palSetPadMode(IOPORT1, 5, PAL_MODE_STM32_ALTERNATE_PUSHPULL);      /* SCK.     */
  palSetPadMode(IOPORT1, 6, PAL_MODE_STM32_ALTERNATE_PUSHPULL);     /* MISO.    */
  palSetPadMode(IOPORT1, 7, PAL_MODE_STM32_ALTERNATE_PUSHPULL);     /* MOSI.    */

Otherwise the system always crashed when calling mmcConnect().

My question now is, if I have missed anything because I could not find this in any of the SPI SD examples and neither do I get where the pin configuration comes from (not even for 2.6) if not from the user. I looked into the MMC/SPI driver files but just found nothing.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SD card mount issue on F103

Post by Giovanni »

Hi,

The pin configuration comes from the STM32 data-sheet, there is a table with all alternate functions.

Giovanni
rizzir
Posts: 5
Joined: Mon Feb 29, 2016 7:48 pm

Re: SD card mount issue on F103

Post by rizzir »

Hi Giovanni,

In the SPI example for STM32F1 in the current Trunk the pins are configured in the main function.
I know that the datasheet is where you can find the possible pin functions but I meant which function/macro does call palSetPadMode to configure the pins in software if you do not do it yourself (e.g. in main).
You have to configure them to be usable for SPI because by default they are inputs, or am I wrong?
Sorry for not making clear what I meant in the first place.

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

Re: SD card mount issue on F103

Post by Giovanni »

Hi,

Default pin setup is done in "board files": board.c and board.h.

Those files are board-specific, you are supposed to create a set when porting to a new board.

Examine the existing ones for an F1 board and it will be clear.

Giovanni
rizzir
Posts: 5
Joined: Mon Feb 29, 2016 7:48 pm

Re: SD card mount issue on F103

Post by rizzir »

Ah, I see. It's done through PALConfig in board.c/.h .
I was just blind because I was only looking for palSetPadMode().
Thanks for pointing me into the right direction.
pl4nkton
Posts: 21
Joined: Thu Apr 21, 2016 12:57 pm
Been thanked: 14 times

Re: SD card mount issue on F103

Post by pl4nkton »

Hi,

I had the same problem and found the demo is missing the sdc init "sdcStart(&SDCD1, &sdccfg);".
The testhal for f4 gave clue.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SD card mount issue on F103

Post by Giovanni »

Hi,

Thanks for finding, I will review the demos and update them before next release.

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

Re: SD card mount issue on F103

Post by Giovanni »

Hi,

Added the missing call to the demo (bug #735).

Giovanni
Post Reply