SD card pinout. Connecting an SD card to a microcontroller

SD cards are based on the older Multi Media Card (MMC) format, but most are physically slightly thicker than MMC cards. They also boast higher data transfer rates. DRM features are available but are little-used. SD cards generally measure 32 mm × 24 mm × 2.1 mm, but can be as thin as 1.4 mm, just like MMC cards.

There are different speed grades available. They are referred to with the same nx notation as CD-ROMs; a multiple of 150 kB/s. Devices with SD slots can use the thinner MMC cards, but the standard SD cards will not fit into the thinner MMC slots. MiniSD and MicroSD cards can be used directly in SD slots with an adapter. There are readers which allow SD cards to be accessed via many connectivity ports such as USB, FireWire.

Pin SD Mode SPI Mode
Name Type Description Name Type Description
1 CD/DAT3 I/O/PP Card detection / Connector data line 3 C.S. I Chip selection in low status
2 CMD PP Command/Response line D.I. I Data input
3 Vss1 S GND VSS S GND
4 Vdd S Power supply VDD S Power supply
5 CLK I Clock SCLK I Clock
6 Vss2 S GND VSS2 S GND
7 DAT0 I/O/PP Connector data line 0 DO O/PP Data output
8 DAT1 I/O/PP Connector data line 1 RSV
9 DAT2 I/O/PP Connector data line 2 RSV

SD cards interface is compatible with standard MMC card operations. All SD memory and SDIO cards are required to support the older SPI/MMC mode which supports the slightly slower four-wire serial interface (clock, serial in, serial out, chip select) that is compatible with SPI ports on many microcontrollers. Many digital cameras, digital audio players, and other portable devices probably use MMC mode exclusively. MMC mode does not provide access to the proprietary encryption features of SD cards, and the free SD documentation does not describe these features. As the SD encryption exists primarily for media producers, it is not of much use to consumers who typically use SD cards to hold unprotected data.

There are three transfer modes supported by SD: SPI mode (separate serial in and serial out), one-bit SD mode (separate command and data channels and a proprietary transfer format), and four-bit SD mode (uses extra pins plus some reassigned pins) to support four bit wide parallel transfers. Low speed cards support 0 to 400 kbit/s data rate and SPI and one-bit SD transfer modes. High speed cards support 0 to 100 Mbit/s data rate in four-bit mode and 0?25 Mbit/s in SPI and one-bit SD modes.

SD cards security features includes:

  • Copyright protection mechanism with the SDMI standard (Secure Digital Music Initiative)
  • Integrated CPRM file protection and encryption system (CPRM is a Content Protection for Recordable Media)

Artem Makarov aka Robin

27.09.2014

Recently, flash drives made on a monocrystal basis, so-called monoliths, are increasingly being brought in for data recovery. Today we will talk about the process of recovering data from such a monolith - an SD memory card sent by a partner from the city of Kemerovo. The video of the wedding was recorded on the card, and when the celebration was successfully completed and it was time to start editing and releasing gift DVDs, the flash drive died for a long time.

Recovery of monolithic SD memory cards

It is noteworthy that from the outside it is not clear whether this is a “classic” SD card, with a PCB board, NAND memory and a controller, or a single crystal. Until the plastic case is opened. Most often, the failure of such memory cards is due to a failure in the translation tables. Less often - electromechanical damage.

To recover files from such a card, the first thing you need to do is read dumps from the crystal. To do this, the protective varnish that hides the tracks and contact pads of the monolith is removed mechanically (cleaning and grinding). After which the flash drive starts to look like this:

Tracks and pinout of a monolithic SD card

The contact pads to which the data bus, chip enable, read/write busy, power, etc. are connected are visible. Of course, nothing is marked, and there are no datasheets that describe in detail what to connect where, in free access also no. The pinout can be found either by taking exactly the same working flash drive (and there are a great many types of them, and having found the same conventional Kingston SD in appearance, you can get a completely different device inside) and, armed with a logic analyzer, painstakingly find out what goes where and why. Or by purchasing the pinout from a person/office that has already done such work for you.

The result is something like this:

Or this:

Now we need to eliminate internal transformations in the resulting dumps. The first step is to remove the XOR mask that the flash drive controller applied when writing information to NAND cells. With this mask the sector looks like this:

and when the required XOR mask is selected and applied, the sector takes on a meaningful appearance:

After eliminating XOR transformations, you need to set the correct sector geometry, describe the markers and the ECC data correction area. Correct bit errors using the ECC algorithm. Find out in what sequence the blocks were located and their size. Since the controller type is unknown (it’s a monolith!), it is necessary to determine which collector to use in this particular case. Will it be assembling the final image using a sector marker or using the rest of the translation tables?

After the image is assembled, check conflict blocks that have the same marker for relevance and substitute into the image those with which the final result will be the best. Having received a familiar image with a file system, you can open it in any disk editor and upload the files the user needs.

Of course, many operations are quite automated, but nevertheless, the amount of work involved in recovering data from monoliths (single crystals) is very large. Not every engineer or company that recovers information is eager to get involved in such work. And the price tag for this kind of restoration is very far from the concept of “budget”.

Here is another case using the example of SD Sandisk recovery - the same monolith, only made a little differently inside:

Ready to Read

Recovery of MicroSD flash drives

And here is what the contact pads look like on a Micro SD card. It should be noted right away that these are just a few examples of many layout options.

And here is the pinout option for a monolithic Memory Stick Pro Duo memory card

This is not to say that it is a monolith, but it is not an ordinary USB flash drive either. The memory chip (crystal) is filled with compound (glue).

And here’s what a monolithic Olympus XD Picture card looks like, from which it was necessary to restore photographs:

Restoring broken Micro SDs

Separately, it is worth mentioning the successful completion of tasks to recover information from MicroSD flash drives that were broken into pieces, with a broken piece, with cracks in the body, etc. Some examples in the pictures below:

In all cases, when we are talking about a flash drive broken into pieces, with a broken part, etc. It is possible to restore information if the NAND crystal remains intact. For example, in the Sandisk micro-flash drive from the example below, as a result of careless operation, a piece broke off and damaged the tracks marked with a red oval.

The Hardmaster laboratory is one of the few that have experience and qualifications in data recovery from monolithic USB, SD, microSD, Memory Stick, etc. memory cards. If there are important files on your monolithic broken flash drive that you would like to return, please contact us!

  • Andreas says:

    Assembling a Memory Stick adapter with your own hands is not difficult if you know the purpose of the functional pins of a particular memory card. Usually called the pinout of a memory card or, for example, a microcircuit, chip, etc. In general, the technology is simple. Card layout is cut out MMC memory(MultiMedia Card) made of PCB. 7 tracks are cut out on the breadboard (MMC has 7 pins). Then, in accordance with the pinout shown in the figure below, the tracks are soldered to the pins of the SD memory card (has 9 pins, of which 2 are not used), microSD (has 8 pins, of which 2 are also not used, but note that the card micro memory SD no Vcc output) or microM2 (microM2 pinout in the related topic Memory Stick Micro M2 Adapter). That's it. The Memory Stick adapter is ready.

    P.S. We have 1 and 2 GB MMC memory cards in stock. The cost, respectively, is 285 and 360 rubles. Delivery is included in the stated price.

    You can also cheaply buy the following sizes of memory cards:
    - Memory Stick and Memory Stick M2;
    - Secure Digital (SD);
    - Mini SD;
    - Micro SD (TF);
    - Compact Flash;
    -XD;
    - USB Flash Drives of various designs and capacities.
    For example, these:

  • slava says:

    By the way, I’m not very clear in these writings. You can’t get the tracks from MicroCD to MMC on that page, I’ll be very grateful.

  • Andreas says:

    This is what the microSD to MMC adapter will look like:

  • slava says:
  • Good day everyone! Today we will talk about connecting an SD memory card to the STM32 microcontroller.

    It would seem that the STM32F10x controllers have plenty of memory, why would there be more, but this impression is deceiving) For example, we need to display a couple of different images on the display - format 320*240 - that is, 76800 pixels, each of which corresponds to as many as 2 byte. So we get about 150 kB per image. And this is a lot by the standards of a microcontroller, and it’s not a fact that two different pictures can be stuffed into its Flash memory. Or do we need to store large amounts of information, data from some sensor, for example. Moreover, so that this data is available even after the power is turned off. This is where external memory comes in handy. And a great solution would be SD memory card or MMC. By the way, in this article we will conduct experiments on micro SD card.

    First, a few words about the memory card itself, or more precisely about its pinout. The whole thing looks like this:

    So what do we have here? Well, it’s immediately clear that it has eight pins. The pin assignments are as follows (from left to right):


    The SPI Mode column hints to us that it interacts with the microcontroller using the SPI interface. BUT! We will take a different path 😉 The thing is that STM32 have on board a ready-made peripheral module for working with memory cards, and it’s called SDIO.

    In general, interaction with memory cards involves sending them certain commands. Some commands require an argument, some do not. Commands can be found in the official documentation for a specific card. So, the built-in SDIO module makes it possible to significantly simplify the process of transmitting commands, and indeed the process of working with external cards memory. For example, here is the register SDIO_CMD– there we simply write down the code of the command that we want to transfer to the card. Or here is the status register SDIO_STA– there are as many as 24 flags for each sneeze, that is, for a large number of events.

    By the way, STM also pleases with good documentation on this whole matter. Here, for example, is a detailed description of initialization for an SD memory card (everything is described similarly for other types of cards):

    Well, actually, it’s time to move on to a practical example. Let's dig into the Standard Peripheral Library.

    In file stm32f10x_sdio.h Traditionally, we find structures for all kinds of settings - that is, for selecting the source of the clock signal, the frequency of the SDIO controller, and setting the number of bytes transferred. Everything there is so generously commented on that I don’t even want to repeat it separately)) Just look:

    typedef struct (uint32_t SDIO_ClockEdge; /* Specifies the clock transition on which the bit capture is made. This parameter can be a value of @ref SDIO_Clock_Edge */ uint32_t SDIO_ClockBypass; /* Specifies whether the SDIO Clock divider bypass is enabled or disabled. This parameter can be a value of @ref SDIO_Clock_Bypass */ uint32_t SDIO_ClockPowerSave; /* Specifies whether SDIO Clock output is enabled or disabled when the bus is idle. This parameter can be a value of @ref SDIO_Clock_Power_Save */ uint32_t SDIO_BusWide; /* Specifies the SDIO bus width. This parameter can be a value of @ref SDIO_Bus_Wide */ uint32_t SDIO_HardwareFlowControl; /* Specifies whether the SDIO hardware flow control is enabled or disabled. This parameter can be a value of @ref SDIO_Hardware_Flow_Control */ uint8_t SDIO_ClockDiv; /* Specifies the clock frequency of the SDIO controller. This parameter can be a value between 0x00 and 0xFF. */) SDIO_InitTypeDef; typedef struct (uint32_t SDIO_Argument; /* Specifies the SDIO command argument which is sent to a card as part of a command message. If a command contains an argument, it must be loaded into this register before writing the command to the command register */ uint32_t SDIO_CmdIndex; /* Specifies the SDIO command index. It must be lower than 0x40. */ uint32_t SDIO_Response; /* Specifies the SDIO response type. This parameter can be a value of @ref SDIO_Response_Type */ uint32_t SDIO_Wait; /* Specifies whether SDIO wait-for-interrupt request is enabled or disabled. This parameter can be a value of @ref SDIO_Wait_Interrupt_State */ uint32_t SDIO_CPSM; /* Specifies whether SDIO Command path state machine (CPSM) is enabled or disabled. This parameter can be a value of @ref SDIO_CPSM_State */) SDIO_CmdInitTypeDef; typedef struct (uint32_t SDIO_DataTimeOut; /* Specifies the data timeout period in card bus clock periods. */ uint32_t SDIO_DataLength; /* Specifies the number of data bytes to be transferred. */ uint32_t SDIO_DataBlockSize; /* Specifies the data block size for block transfer. This parameter can be a value of @ref SDIO_Data_Block_Size */ uint32_t SDIO_TransferDir; /* Specifies the data transfer direction, whether the transfer is a read or write. This parameter can be a value of @ref SDIO_Transfer_Direction */ uint32_t SDIO_TransferMode; /* Specifies whether data transfer is in stream or block mode. This parameter can be a value of @ref SDIO_Transfer_Type */ uint32_t SDIO_DPSM; /* Specifies whether SDIO Data path state machine (DPSM) is enabled or disabled. This parameter can be a value of @ref SDIO_DPSM_State */) SDIO_DataInitTypeDef;

    Let us note how SPL implements the transfer of commands to a memory card. A separate structure has been allocated for these purposes. SDIO_CmdInitTypeDef. In the field SDIO_CmdIndex enter the command code in the field SDIO_Argument– command argument, also fill in the remaining fields. All that remains is to somehow stuff this data into micro card SD 😉 And for this they prepared a function for us:

    SDIO_SendCommand (SDIO_CmdInitTypeDef *SDIO_CmdInitStruct)

    As an argument, we pass it the structure we created. To record data there is a function - SDIO_WriteData(uint32_t Data). After calling this function, the data will be in a register specially designed for this purpose - SDIO_FIFO.

    This is how you work with the SDIO module in the STM32F10x)

    Now let's finally move on to practice. I will again work with the Mini STM32 board, since the kind Chinese were puzzled by installing a slot for a micro SD memory card on it. Here is a diagram of connecting the card connector to the microcontroller:

    To write the program, we will use a ready-made example for Keil - we will take two files from there, in which something like a driver for working with cards is implemented - these are the files sdcard.c And sdcard.h. We create a new project, attach these files there, and in addition, of course, the CMSIS and SPL files. Here is the finished project, in which everything has already been added - all that remains is to write the code for the main() function)

    The sdcard.c file implements all sorts of functions for working with a memory card, now all we have to do is use them 😉 Let’s write the code! For example, let’s write 512 bytes of test data to micro SD, and then try to read them:

    // Link the necessary files#include "stm32f10x.h" #include "sdcard.h" /*******************************************************************/ // Arrays of input and output data and a variable for storing data// about our card uint8_t writeBuffer[ 512 ] ; uint8_t readBuffer[ 512 ] ; SD_CardInfo SDCardInfo; /*******************************************************************/ int main() ( // Test data to write for (uint16_t i = 0 ; i< 512 ; i++ ) { writeBuffer[ i] = i % 256 ; readBuffer[ i] = 0 ; } // Initialize the map SD_Init() ; // Get information about the card SD_GetCardInfo(& SDCardInfo) ; // Selecting a card and setting the operating mode SD_SelectDeselect((uint32_t ) (SDCardInfo.RCA<< 16 ) ) ; SD_SetDeviceMode(SD_POLLING_MODE) ; // And finally, writing and reading SD_WriteBlock(0x00, writeBuffer, 512) ; SD_ReadBlock(0x00, readBuffer, 512) ; while (1 ) ( ) ) /*******************************************************************/

    Please note that the SD card supports recording in 512 byte blocks.

    If we run the program under the debugger, we will see that the read data matches the written data =) So we can consider the experiment a success. That's it for today, see you soon!

    A few years ago in May 2011, the creator of the cult game “Elite” David Braben presented the first concept of a single-board computer Raspberry Pi. This moment became a turning point in my life. The idea of ​​making a computer the size of a flash drive was on the surface, but it only gained momentum with the help of the Raspberry Pi Foundation.

    Already on July 25, 2011, the alpha version of the computer was put into production. Unfortunately, the concept of the project has changed, and it is now positioned as a computer the size of a credit card. Despite this circumstance, millions of people followed him. I too obeyed the crowd effect, checking the official project page every day. A long and painful wait began for the “miracle”, which happened on February 29, 2012 - the start of sales.

    The Raspberry Pi could be purchased through the Farnell network or from RS Components. As it turned out, on February 29 it was only possible to make a pre-order. None of the offices had these boards in stock. The first batch of devices was only 10,000 copies, so given the hype around the project, placing an order was very difficult. However, having overcome all difficulties, at 14:06 on the same day the computer was purchased for £46.73 from Farnell.

    It took so long for any of my foreign orders to be fulfilled. I was extremely upset that Farnell, having charged £20 for delivery, sent the parcel on May 29, 2012 (2 months later) by regular mail without a tracking number. Surprisingly, the symbiosis of the Royal and Russian Mail delivered the parcel safe and sound on June 22. This was the most desired package in the last few months, so, unable to withstand the stress, I had to take time off from work and run to the post office.

    There is no point in talking about how to configure the Raspberry Pi for the first launch. I’m a couple of years late with an article on this topic; many lines about this have already been written on other resources, and on Youtube A sufficient amount of video material has been posted. I want to talk about a significant design flaw for me - the inconvenient location of the SD card slot. When the card is inserted, it protrudes greatly beyond the board, which spoils the appearance of the homemade case.

    There are two options for solving this problem: solder an SD->microSD adapter parallel to the connector installed on the Raspberry Pi (you can read how to do this operation in the article on Habré), or use a Low-profile MicroSD->SD adapter. The first option is simply unacceptable for me - well, I don’t dare to solder the board, because... I'm afraid of ruining the presentation of my Raspberry. I think that the best choice is to use a Low-profile adapter.

    Initially, it was decided to purchase such an adapter in one of the foreign online stores. There is a choice, but the cost of such trinkets is simply prohibitive. The cheapest copies cost $10, and some samples frankly look homemade. The final decision to make the adapter ourselves was made after visiting the DIYGadget website; note how easy it is to repeat their creation.

    Are you ready? Let's move from words to action. To make the adapter correctly, let’s study the specifications for SD and microSD cards. I tried to systematize everything that is necessary for production in tables 1, 2.

    Table 2: SD memory card pinout

    By connecting the corresponding contacts on the memory cards, and combining Vss1, Vss2, we get electrical schematic diagram adapter

    To make an adapter we need:
    1) Holder for microSD (CF TFC-WPCE-08 MICROSD CARD) – 52.22 rub.
    2) A piece of double-sided foil fiberglass laminate with an area of ​​​​about 4 cm 2 (2% of the position FOIL GLASS TEXTOLITE 1.5MM 2 SIDES) – 3 rubles.
    3) Materials for installation (ferric chloride, tin, flux) – 10 rubles.

    Then the cost of the project will be 65 rubles 22 kopecks and a certain amount of free time. In order to reduce the cost of the design, you can replace the holder microSD cards to CF TFC-WPCER-08 MICROSD CARD. Unfortunately, this item was not available in the Promelektronika JSC warehouse, so I purchased a more expensive option. I draw your attention to the fact that if you change the type of holder, you may not be able to use my template for LUT (laser ironing technology).

    I used Autocad to design the PCB because... my favorite SprintLayout could not please me with the presence of the required template. For those who like to modify a printed circuit board, you can download the source in DWG format, and if there is no such need, then a blank in PDF format (I recommend checking the dimensions before applying the PDF template).

    After the template is transferred to the board, I recommend drilling holes with a diameter of 0.5 mm to transition from one layer to another.

    I make the transition from layer to layer using a thin wire, having previously irradiated the tracks of the future adapter. In those places where the holes are located under the microSD holder, it is necessary to grind off drops of tin with a file so that it is installed without distortion. Lastly, we install the holder. If various fluxes were used during the manufacturing process of the board, be sure to wash the board before pushing it into your Raspberry Pi.

    Make an adapter yourself or buy it – the choice is yours. To make your choice more informed, I have selected several links for purchase especially for you:
    1) Raspberry Pi Premium Low-profile MicroSD (TF) to SD Card Adapter. Protect Board.
    2) Raspberry Pi Low-profile MicroSD to SD Card Adapter, SD card won't get damaged!!
    3) MicroSD to "short" SD / RS-MMC adapter. For Everdrive carts, Raspberry Pi, etc.
    4) Low-profile MicroSD to SD Card Adapter for Raspberry Pi.
    5) SD card adapter for Raspberry pi REV2 +free shipping.

    In conclusion, I would like to say that all material is intended for informational purposes only. The use of developments for commercial purposes is strictly prohibited. Reproduction of materials is possible only with my permission and in compliance with references to the original source. Those who want to support not only in word, but also in deed, and also thank me, please email me.

    To assemble the device yourself, you need to download the following files:
    1. Source board for LUT in DWG format
    2. Payment for LUT in PDF format

    Good luck in your endeavors!!!

    Share: