Tuesday 27 October 2015

SD Card Development on the S3C2440 update #2

I finished development of write and erase. I feel that is good progress made. No difficulties there. Just followed the spec and I had write and erase working without hiccups.

Now the interesting part starts off with code refactoring to enable interrupts and a configurable MMU page table levels. Also there is the fun part of implementing multitasking.

I will be currently working on creating configurable clock settings. This is important as there are still lot of magic numbers in the code which should be calculated and parameterizable.

Science is what we understand well enough to explain to a computer. Art is everything else we do.
-Knuth

Thursday 22 October 2015

SD Card Development on the S3C2440 update.

It has been sometime that I have updated my blog. I was busy with work and had a personal emergency in September. I had decided to restart work on my firmware where I had left off i.e. the SD card driver just before the emergency. It took almost 2 weeks after the emergency to stabilize and start working on it.

I had initially assumed that I had finished reading data from the SD card. Looking at where I left off I had finished very little. I had just started off with the initializations and that too it was not very complete. So I took upon the task of at least writing code for reading SD card data.

Experience on SD card data read:

I had to stabilize my initialization function of SD Card controller and it was a mess! I had to clean up a lot of code. Luckily I had written some code comments and could pick up from there. So the first step was to verify whatever I have written that is the steps of initialization.

  1. Initialization of the pins. This is multiplexed as GPIOs and SD Block controller pins. So it has to be set to configure as SD Block controller.
  2. Reset SD MMC :)
  3. Set the prescaler. For initialization I have set it to lowest possible value possible i.e. 100kHz. (The spec says a 400kHz but I did not want to take any chance.)
  4. Next step is to set the data timeout period which I have kept to pretty high value.
  5. I reset the FIFO
  6. I enable the clock and the SD Card controller comes alive.
Now the initialization starts off based on the SD Card specification i.e. sending various commands. I will not go in elaborate details of the steps as most of it is explained in the specification. I will explain the problems which I encountered.
  1. It is better to set-up a very slow clock. The clock setup during initialization is usually 400kHz but in my case I set it up as 100kHz.
  2. CMD55 and ACM41 needs to be retried. The response is pretty slow hence it is good to have this in a retry loop.
  3. Most of the verification of the whether the card is setup right can be done by parsing the CID (Card Identification) register. The PNM (Product Name) can be verified. I get a SD08G i.e. a Sandisk 8GB.
  4. To get the relative address I send a CMD3. This forms the RCA.
  5. I had significant problems in understanding of the spec here. After sending a CMD3 the card has to go to  STBY (Standby) state. To check the state I need to send CMD13 which gets the present state but I was checking the state from the R1 response returned from CMD3. This response gives the state previous to sending the command. All thanks to





A mistress of perfect consistency, the computer rejects all but the flawless, offering no explanation. When the acceptable is finally offered, the machine's acceptance is total, unwavering and eternal.