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.
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.
- 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.
- Reset SD MMC :)
- 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.)
- Next step is to set the data timeout period which I have kept to pretty high value.
- I reset the FIFO
- I enable the clock and the SD Card controller comes alive.
- 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.
- CMD55 and ACM41 needs to be retried. The response is pretty slow hence it is good to have this in a retry loop.
- 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.
- To get the relative address I send a CMD3. This forms the RCA.
- 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 jnc100
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.
No comments:
Post a Comment