stm32f407 SDIO problem

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

Moderators: barthess, RoccoMarco

MySOL
Posts: 8
Joined: Wed Mar 04, 2015 10:40 pm

stm32f407 SDIO problem

Postby MySOL » Sat Apr 18, 2015 11:00 pm

Hello! Sorry to trouble, but i can't find solving my problem on forum. I'm trying to connect my discovery board to 2 gb micro sd card via SDIO interface. I found examples in chibios archive and many others on other sources, but i've got some problem with it. Firstly i try to send any data from stm board and try to check, that output data have. but there is no data on pins (cmd/dat0) and clk is never formed. I know, that its hard to help me to find issue, but i hope, maybe i've got problem with initialisation procedure. For me now it is important to understand why the SDIO controller does not work. Here is my code

Code: Select all

static const SDCConfig sdccfg = {
  0
};

/*
 * Application entry point.
 */
int main(void) {
   
   uint32_t i;
   BlockDeviceInfo bdi;
   
  halInit();
  chSysInit();
   
   palSetPadMode(GPIOD, GPIOD_LED4, PAL_MODE_OUTPUT_PUSHPULL);
   palSetPadMode(GPIOD, GPIOD_LED3, PAL_MODE_OUTPUT_PUSHPULL);
   
   
   palSetPadMode(GPIOA, 1, PAL_MODE_OUTPUT_PUSHPULL); // SD Vdd
   
   palSetPadMode(GPIOC, 8, PAL_STM32_ALTERNATE(12) |   PAL_STM32_PUDR_PULLUP |
                                       PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); //DAT0
   palSetPadMode(GPIOC, 9, PAL_STM32_ALTERNATE(12) |   PAL_STM32_PUDR_PULLUP |
                                       PAL_STM32_OTYPE_PUSHPULL); //DAT1
   palSetPadMode(GPIOC, 10, PAL_STM32_ALTERNATE(12) |   PAL_STM32_PUDR_PULLUP |
                                       PAL_STM32_OTYPE_PUSHPULL); //DAT2
   palSetPadMode(GPIOC, 11,PAL_STM32_ALTERNATE(12) |   PAL_STM32_PUDR_PULLUP |
                                       PAL_STM32_OTYPE_PUSHPULL); //DAT3
   palSetPadMode(GPIOC, 12,PAL_STM32_ALTERNATE(12) | PAL_STM32_OSPEED_MID2 |
                                       PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); //CLK
   palSetPadMode(GPIOD, 2, PAL_STM32_ALTERNATE(12) |   PAL_STM32_PUDR_PULLUP |
                                       PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); //CMD
   
 
   
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
   
   palSetPad(GPIOA, 1);
   chThdSleepMilliseconds(500);
   sdcObjectInit(&SDCD1);
   sdcStart(&SDCD1, &sdccfg);
   
   sdc_lld_send_cmd_short_crc(&SDCD1, 0xAA, 0xAAAAAAAA, &i);
   
      
   
   while (TRUE)
   {
      palSetPad(GPIOD, 6);
      chThdSleepMicroseconds(100);
      palClearPad(GPIOD, 6);
      chThdSleepMicroseconds(100);
   }
}


I would be grateful for any help

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: stm32f407 SDIO problem

Postby Giovanni » Sun Apr 19, 2015 6:32 am

Hi,

In the past problems with SDIO were caused by:

1) Wrong GPIO initialization.
2) Long wires.
3) Lack of terminations.
4) Problems with card power.

About GPIO initialization, look at the STM32-E407 board files for an example.

Giovanni

MySOL
Posts: 8
Joined: Wed Mar 04, 2015 10:40 pm

Re: stm32f407 SDIO problem

Postby MySOL » Sun Apr 19, 2015 10:00 am

can you explaine, what do you mean by lack? theoretically can i test the SDIO without connecting the sd card?
Giovanni wrote:Hi,

In the past problems with SDIO were caused by:

1) Wrong GPIO initialization.
2) Long wires.
3) Lack of terminations.
4) Problems with card power.

About GPIO initialization, look at the STM32-E407 board files for an example.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: stm32f407 SDIO problem

Postby Giovanni » Sun Apr 19, 2015 10:10 am

Hi,

Many schematics I have see have resistive terminations on SDIO lines.

Giovanni

STM32-E407_Rev_B1_sch.zip
(119.74 KiB) Downloaded 391 times

MySOL
Posts: 8
Joined: Wed Mar 04, 2015 10:40 pm

Re: stm32f407 SDIO problem

Postby MySOL » Sun Apr 19, 2015 10:58 am

You mean that there may be no resistors can strongly affect the SDIO, if instead they use a software pull up?
Giovanni wrote:Hi,

Many schematics I have see have resistive terminations on SDIO lines.

Giovanni

STM32-E407_Rev_B1_sch.zip

provincialex
Posts: 5
Joined: Sat Nov 29, 2014 12:08 pm

Re: stm32f407 SDIO problem

Postby provincialex » Sun Apr 19, 2015 5:29 pm

I use internal pullups, its OK.

For test you'd better try SDC example testhal\STM32F4xx\SDC, you may throw out everythyng from main.c and use only the folowing functions:
halInit
chSysInit
sdcStart
sdcConnect
and finally sdcRead/sdcWrite

no need in any pin manipulations in this case.

MySOL
Posts: 8
Joined: Wed Mar 04, 2015 10:40 pm

Re: stm32f407 SDIO problem

Postby MySOL » Sat Apr 25, 2015 5:41 pm

provincialex wrote:I use internal pullups, its OK.

For test you'd better try SDC example testhal\STM32F4xx\SDC, you may throw out everythyng from main.c and use only the folowing functions:
halInit
chSysInit
sdcStart
sdcConnect
and finally sdcRead/sdcWrite

no need in any pin manipulations in this case.


Thx for help. I'll try it

chradev
Posts: 48
Joined: Sun Apr 28, 2013 6:52 am

Re: stm32f407 SDIO problem

Postby chradev » Fri May 22, 2015 8:36 am

Hi guys

I am trying to test SD card on Olimex stm32-e407 (rev B) board with ChibiOS ver. 3.0dev (svn-7788-trunk) using test and demo staff as-is but had some problems.
Following cards ware used: 2 kinds 4GB Micro SD HC (ADATA and no name) FAT32 formatted and 128MB Micro SD (SanDisk) with 12MB FAT partition on it.
ChaN FatFs used with ChibiOS ver. 3.0dev was R0.10b taken from ChibiOS repository. Tools was from ChibiStudio preview 7 with Eclipse updated to Luna.

For reference I had also used demo staff from ver. 2.6.7. There you are the results:
RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB (ChibiOS ver. 3.0dev): not work with all cards tested;
STM32F4xx-SDC (ChibiOS ver. 3.0dev): not work with with 4GB cards but work with 128MB one;
ARMCM4-STM32F407-LWIP-FATFS-USB (ChibiOS ver. 2.6.7): work with all cards tested;

RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB (ChibiOS ver. 3.0dev) staff was also tested on Olimex stm32-e407 (rev E) board with FAT32 formatted card without success.

RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB demo was tested unsuccessfully with ChibiOS ver. 3.0.0p2/3 thanks to ChibiStudio preview 10.
STM32F4xx-SDC test was run with ChibiOS ver. 3.0.0p3 and did not work with with 4GB cards but worked with 128MB one.

ChibiOS ver. 3.0.0p4 cannot be compiled because of cat/egrep tools lack.

Where could be the problem(s)? Thanks in advance.

Best regards
Chris

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: stm32f407 SDIO problem

Postby Giovanni » Fri May 22, 2015 8:54 am

Hi,

A bug has been fixed in p4 regarding SDC driver. If you are unable to compile set USE_SMARD_BUILD to no in the Makefile.

Giovanni

chradev
Posts: 48
Joined: Sun Apr 28, 2013 6:52 am

Re: stm32f407 SDIO problem

Postby chradev » Fri May 22, 2015 11:52 am

Giovanni wrote:Hi,

A bug has been fixed in p4 regarding SDC driver. If you are unable to compile set USE_SMARD_BUILD to no in the Makefile.

Giovanni


Hi Giovanni,

Thanks for your prompt replay. I succeed to test the staff with ChibiOS ver. 3.0.0p4 setting USE_SMARD_BUILD to no.

The results are:
STM32F4xx-SDC (ChibiOS ver. 3.0.0p4): fail with with ADATA 4GB card on performance tests but work with no name 4GB card and 128MB once;

STM32F4xx-SDC (ChibiOS ver. 3.0.0p4) with ADATA 4GB card had the same behavior after re-formatting the SD card but write test pass with all OK.
ch> sdc write
Connecting... OK

Card Info
CSD : 400E0032 5B590000 1D8A7F80 0A4040B8
CID : 03534453 55303447 80047EE9 5300BB9A
Mode : SDV20
Capacity : 3781MB
Writing...OK
Reading...OK
Writing...OK
Reading...OK


Interesting are performance characteristics:
128MB Micro SD (SanDisk) with 12MB FAT partition on it:
Card Info
CSD : 00260032 5F5983C0 FEFA4FFF 924040B4
CID : 03534453 55313238 80703BC9 69007CBC
Mode : SDV20
Capacity : 120MB
Single block aligned read performance: 2724 blocks/S, 1394688 bytes/S
16 sequential blocks aligned read performance: 12656 blocks/S, 6479872 bytes/S
Single block unaligned read performance: 2631 blocks/S, 1347072 bytes/S
16 sequential blocks unaligned read performance: 2752 blocks/S, 1409024 bytes/S

Approximately the same was performance characteristics at all cards tested with STM32F4xx-SDC test on ChibiOS ver. 2.6.7.

4GB Micro SD HC no name FAT32 formatted
Card Info
CSD : 400E0032 5B590000 1D9B7F80 0A40003A
CID : 1B534D30 30303030 1016CFC6 8000B77E
Mode : SDV20
Capacity : 3790MB
Single block aligned read performance: 1556 blocks/S, 796672 bytes/S
16 sequential blocks aligned read performance: 9552 blocks/S, 4890624 bytes/S
Single block unaligned read performance: 1499 blocks/S, 767488 bytes/S
16 sequential blocks unaligned read performance: 1408 blocks/S, 720896 bytes/S

Note 16 sequential blocks aligned read performance decrease (~25%) while other performances was increased (5+ times).

RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB (ChibiOS ver. 3.0.0p4): is (re-)connected successfully to all cards tested and with
128MB Micro SD (SanDisk) with 12MB FAT partition on it: print successfully free card space and file names;

4GB Micro SD HC no name FAT32 formatted (no files on it): print successfully free card space only (application continued working);
4GB Micro SD HC no name FAT32 formatted (with files on it): print successfully free card space and file names (application continued working);

4GB Micro SD HC ADATA FAT32 formatted (with files on it): print successfully free card space and but no file names and application freezes;
4GB Micro SD HC ADATA FAT32 re-formatted (with and without files on it): print successfully free card space and file names (application continued working).
Probably long hidden directories and files written by MacOS has too long names and application crashes but failed performance tests on it is strange anyway.

Successful tests make it possible to continue on ChibiOS bootloader and remote FW update mechanism based on FatFS stores (SD card and/or internal/external flash).
For that I plan to open a new forum topic and will be happy to get some feedback.

Thanks for the good work done by you Giovanni and all guys working to make ChibiOS the best RTOS world wide.

Best regards
Chris


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 30 guests