Incorrect OCR sent during SD card init Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
rawsock
Posts: 5
Joined: Fri Feb 17, 2017 11:26 am
Been thanked: 1 time

Incorrect OCR sent during SD card init

Post by rawsock »

In hal_sdc.c, sdc_init, there is an incorrect OCR word sent in ACMD41:

ocr = 0xC0100000U;

while the correct value according to SD card specification is:

ocr = 0x50FF8000U;

That is, busy=0, hc=1, full performance, full voltage range. There are two major results of this change:

- sending empty voltage range is invalid for initialization, as it only queries for a supported voltage range without initializing the card (according to spec, but seems to work on most cards anyway)
- there is 2-4x performance speedup because full performance bit is set (currently it is 0 which means power save)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Incorrect OCR sent during SD card init

Post by Giovanni »

Hi,

Interesting, have you tested this on multiple cards? I am not the author of that part so I am not very informed.

Giovanni
rawsock
Posts: 5
Joined: Fri Feb 17, 2017 11:26 am
Been thanked: 1 time

Re: Incorrect OCR sent during SD card init

Post by rawsock »

I tested on 2 SanDisk cards and 1 noname. All got significant performance boost during write (I did not test read speed).
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Incorrect OCR sent during SD card init

Post by alex31 »

I confirm the performance speedup (F4 and F7, samsung SHDC card)

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

Re: Incorrect OCR sent during SD card init

Post by Giovanni »

Question, the complete code is:

Code: Select all

  if ((sdcp->cardmode &  SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_SDV20) {
    ocr = 0xC0100000U;
  }
  else {
    ocr = 0x80100000U;
  }


Is the constant for non-v20 cards correct? my idea is to make both constants configurable, does it make sense?

Giovanni
rawsock
Posts: 5
Joined: Fri Feb 17, 2017 11:26 am
Been thanked: 1 time

Re: Incorrect OCR sent during SD card init

Post by rawsock »

OCR for non-v20 cards needs to be changed as well. Probably only HC bit needs to be off, when compared to v20 OCR, but I did not test it.
The only configurable options that would make sense are power save vs full performance and voltage range.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Incorrect OCR sent during SD card init

Post by Giovanni »

Fixed as bug #826.

I added two configuration options that allow to override the default initialization values. The default for v20 cards is the suggested one.

Giovanni
Post Reply