Problems with SDIO [STM32F4Discovery]

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

Moderator: RoccoMarco

Post Reply
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Problems with SDIO [STM32F4Discovery]

Post by Abhishek »

Hello All,

I'm trying to use SDIO with STM32F4Discovery board and a patchboard. After I got the SD card to initialize correctly. sdcConnect returns 0. I can't get it to display the contents of the card (in a listing sort of). It returns a FS_DISKERR error code.

ChibiOS used is 2.6.0, the one bundled with ChibiStudio by default.
The microSD Card I have currently is a Class 4 Transcend 8 GB Card [SDHC].

When I try with an unbranded 1 GB microSD card, and increased the STM32_SDIO_DIV_HS to 1, it works.
But no effect with the 8 GB card, same error.

When I stepped into the code, The problem seems to appear at sdc_lld.c, line 170 where:

Code: Select all

Thread [1] (Suspended)   
   8 sdc_lld_wait_transaction_end() sdc_lld.c:171 0x0800269c   
   7 sdc_lld_read_aligned() sdc_lld.c:603 0x08002812   
   6 sdcRead() sdc.c:399 0x08001732   
   5 sdcRead() sdc.c:384 0x08001732   
   4 check_fs() ff.c:1986 0x080057c2   
   3 chk_mounted() ff.c:2059 0x080058e6   
   2 f_opendir() ff.c:2966 0x08006334   
   1 main() main.c:390 0x080002e4   


and the

Code: Select all

if ((SDIO->STA & SDIO_STA_DATAEND) == 0)
condition evaluates to true.

From my debugging, it seems that commands are sent all right, and reception is also OK, but this flag being raised is mysterious.

Any hints on how to proceed further will be greatly appreciated.

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

Re: Problems with SDIO [STM32F4Discovery]

Post by Giovanni »

Hard to tell without being able to reproduce the problem. There was another report about the SDC driver with a proposed patch, please perform a search in this forum.

Giovanni
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: Problems with SDIO [STM32F4Discovery]

Post by Abhishek »

An update:

After changing:

Code: Select all

 palSetGroupMode(GPIOC, PAL_PORT_BIT(8) |  PAL_PORT_BIT(9) |
                 PAL_PORT_BIT(10) | PAL_PORT_BIT(11) | PAL_PORT_BIT(12),
                 0, PAL_MODE_ALTERNATE(12));

palSetGroupMode(GPIOD, PAL_PORT_BIT(2), 0, PAL_MODE_ALTERNATE(12));
to:

Code: Select all

 palSetGroupMode(GPIOC, PAL_PORT_BIT(8) |  PAL_PORT_BIT(9) |
                   PAL_PORT_BIT(10) | PAL_PORT_BIT(11) | PAL_PORT_BIT(12),
                   0, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_MID2 );

palSetGroupMode(GPIOD, PAL_PORT_BIT(2), 0, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_MID2);

This causes 1 GB SD card to work correctly at the highest speed i.e. STM32_SDIO_DIV_HS set to 0. The problem was due to slew rate control, I guessed.

I tested with another card, this time a Strontium 16 GB Class 10 SDHC card, and it works fine.
But the 8 GB card gives similar issues. I have no clue what's wrong.

I saw other topics, the patch seems to have no effect as this is a V2.0 card, and the patch is for legacy v1.1, as mentioned here: viewtopic.php?f=16&t=1084&start=10 . What is striking that it too reports a similar issue, even on the same line.

Looking forward to more hints. I'll try investigating further about this.

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

Re: Problems with SDIO [STM32F4Discovery]

Post by Giovanni »

Thanks for finding about the slew rate, this is really useful, at very least a note should be added about that.

I didn't heard back from Alexblack, he said to wait, I don't know if to merge that patch yet.

Giovanni
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: Problems with SDIO [STM32F4Discovery]

Post by Abhishek »

I did some more probing. The error that occurs is SDIO_STA_DCRCFAIL.

Then, I tried to bypass the CRC fail by accepting the faulty data frame (and commenting out the if ((SDIO->STA & SDIO_STA_DATAEND) == 0) condition).
More debugging reveals that there is a missing byte, probably the first byte as what should have been present at index 510 is now at 509 and what should have been at index 82 is now at 81.

I have no clues to the missing byte, probably that's why the CRC fails.

Even the STM32 F4 errata gives no clue, agreed, there are a few errata related to SDIO, but none applies to the implementation in ChibiOS.

No idea how to find the missing byte.

Abhishek
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: Problems with SDIO [STM32F4Discovery]

Post by alexblack »

Hi.
Giovanni wrote:Thanks for finding about the slew rate, this is really useful, at very least a note should be added about that.
I didn't heard back from Alexblack, he said to wait, I don't know if to merge that patch yet.
Giovanni

I tested all cards I found - all works, with the exception of those that are dead :)
I soldered another copy of my board with another MCU - STM32F407 and checked all cards again - all works fine too.
I think the patch can be merged.
Post Reply