SDIO port to STM32F4x

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.
efs113
Posts: 14
Joined: Mon Mar 19, 2012 3:51 pm

Re: SDIO port to STM32F4x

Post by efs113 »

Hi All,

I spent some time debugging the 1.1 detection bug I reported previously. Not sure exactly what is happening, but do have some information that someone more knowledgeable with the SD protocol may be able to make some sense of.

First, I tried a 2.0 card, it worked fine.

So, I went back to the 1.1 card and added some debug. Code referenced below is in the sdcConnect() function in os/hal/src/sdc.c, rev4032, branches/sdc_dev2. The card IS being detected as a 1.1 card (if on 230, SDC_CM8_PATTERN, returns failure and sdcp->cardmode is set to SDC_MODE_CARDTYPE_SDV11 on line 248). The problem occurs at the next sdc_lld_send_cmd_short_crc(), line 271, when SDC_CMD_APP_CMD is sent. sdc_lld_send_cmd_short_crc() succeeds, but the resp code is flagged as an error by the SDC_R1_ERROR(resp[0]) part of the if condition. resp[0] contains 0x00400120. resp[0], when masked with SDC_R1_ERROR_MASK, becomes 0x00400000. This causes SDC_R1_ERROR(resp[0]) to return true resulting in the 'goto failed' on line 273.

I dug through the SD card documentation (not very thoroughly though) and couldn't find what that bit might represent. The documentation I was looking at stated SDC_CMD_APP_CMD response should only be 8 bits long. Anyone have any idea what the bit represents? Where did SDC_R1_ERROR_MASK come from and what do its bits represent?

So, I decided to ignore the error. I commented out the 'goto failed' on line 273 after the failing command. Reran the haltest and it PASSED successfully several times.

Could this possibly be a false error?

Eric
Jacon
Posts: 143
Joined: Wed Dec 08, 2010 7:52 am
Has thanked: 50 times
Been thanked: 5 times

Re: SDIO port to STM32F4x

Post by Jacon »

Hi Giovanni,

You changed retval names in sdc.c, but they are not in-line with descriptions ;)

They should look like this:

Code: Select all

 * @retval CH_FAILED    operation failed..
 * @retval CH_SUCCESS   operation succeeded.

instead of actual:

Code: Select all

 * @retval CH_FAILED    operation succeeded.
 * @retval CH_SUCCESS   operation failed.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

Thanks, I will fix those.

@Eric, I hoped barthess would know more about that, I will study a bit that problem when I will rework the SDC driver.

BTW, I am working to add a generic "block" interface to both the SDC and MMC_SPI drivers, much like the streams for serial devices, this way any block device can be accessed in the same way.

Giovanni
Jacon
Posts: 143
Joined: Wed Dec 08, 2010 7:52 am
Has thanked: 50 times
Been thanked: 5 times

Re: SDIO port to STM32F4x

Post by Jacon »

Giovanni wrote:Thanks, I will fix those.
Giovanni

Still not fixed... ;)

Similar problem in newly added files / file sections:
- io-block.h - you used old retval names, instead of new ones;
- mmc-spi.c - same problem;
- sdc.c - same problem - mixture of both systems in one file now;

It's good time to replace them globally in all files, I think...
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

Frankly I am scared to change that in all files, probably it is better to leave TRUE/FALSE in the code and just document CH_FAILED/CH_SUCCESS as aliases. If we have to go through the pain probably it would be better to drop the bool_t and define a proper error type (maybe cherr_t) as an enumeration.

BTW, I am still working on both SDC and MMC_SPI, expect a new commit in the evening. I am trying to make the two drivers share code and definitions.

Giovanni
Jacon
Posts: 143
Joined: Wed Dec 08, 2010 7:52 am
Has thanked: 50 times
Been thanked: 5 times

Re: SDIO port to STM32F4x

Post by Jacon »

Giovanni wrote:... probably it is better to leave TRUE/FALSE in the code and just document CH_FAILED/CH_SUCCESS as aliases. ...

In my opinion - no. It's one of the hardest confusion sources in whole code,
especially for newcomers.

But - you're the Boss here...
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

I am not disagreeing but then I prefer to create an explicit error type, it makes things entirely unambiguous.

Giovanni
User avatar
part1zan_
Posts: 44
Joined: Sun Sep 08, 2013 9:04 pm

Re: SDIO port to STM32F4x

Post by part1zan_ »

Will SDIO work at STM32F3Discovery?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: SDIO port to STM32F4x

Post by Tectu »

part1zan_ wrote:Will SDIO work at STM32F3Discovery?

The STM32F303 does not provide an SDIO interface.


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

Re: SDIO port to STM32F4x

Post by Giovanni »

No, the STM32F3 does not have the SDIO peripheral.

giovanni
Post Reply