Skip to main content
Topic: CMD18 & CMD25 with MMC/SD: how to? (Read 8626 times) previous topic - next topic

CMD18 & CMD25 with MMC/SD: how to?

Hi there,

I know how to read a single block in MMC/SD cards sending the sequence SET_BLOCKLEN (CMD16) followed by the READ_SINGLE_BLOCK (CMD17) as namely in this example:
 
SPI>[0x50 0x00 0x00 0x02 0x00 0xFF r:8] (using cmd16 to set 512 bytes for the blocks' size, 0x02h 0x00h = 512 DECIMAL)
 
SPI>[0x51 0x00 0x00 0x00 0x00 0xFF r:520] (using CMD17 in order to read 520bytes within the block 0, 512 bytes are the content of the block 0, remaining 8 bytes are token and CRC)
 
It is easy, but how using the CMD18 READ_MULTIPLE_BLOCK?
Is there anybody who know how correctly use CMD18 READ_MULTIPLE_BLOCK (but even CMD25 WRITE_MULTIPLE_BLOCK on the write side) with Bus Pirate?
I mean send CMD18 READ_MULTIPLE_BLOCK or CMD25 WRITE_MULTIPLE_BLOCK in order to get data continuously on the terminal until the CMD12 STOP_ TRANSMISSION (or any other pertinent command) is issued.
Any idea?
 
Thanks in advance and regards,
 
U.Sb

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #1
Maybe something like:

SPI>{0x52 0x00 0x00 0x00 0x00 CRC r    (CMD18, 32 bit address, CRC, and read the response token)
SPI>r:520                                          (read 520 bytes)
SPI>r:514                                          (read another 520 bytes)
SPI>0x4C 0x00 0x00 0x00 0x00 CRC r}    (CMD12, 32 bit argument, CRC and read the response token)

I used { instead of [ as during the sending of last 6 bytes, there is still data coming in that's why I read 514 bytes but explain as reading 520.

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #2
Hi tayken,
 
thanks for the reply, you are great.
I tried to follow the your hint noticing this.
I do not understand very well what is the difference between [ ] and { }, me need to dig the matter, however I have got as follow.
 
SPI>{0x52 0x00 0x00 0x00 0x00 0x93 r
/CS ENABLED
WRITE: 0x52 READ: 0xFF
WRITE: 0x00 READ: 0xFF
WRITE: 0x00 READ: 0xFF
WRITE: 0x00 READ: 0xFF
WRITE: 0x00 READ: 0xFF
WRITE: 0x93 READ: 0xFF
READ: 0xFF
 
I can say good.
Then,
 
SPI>r:520
READ: 0x00 0xFF 0xFF 0xFE 0xEB 0x58 0x90 0x4D 0x53 0x44 0x4F 0x53 0x35 0x2E 0x30
 0x00 0x02 0x04 0x26 0x00 0x02 0x00 0x00 0x00 0x00 0xF8 0x00 0x00 0x3F 0x00 0xFF
 0x00 0x00 0x00 0x00 0x00 0x00 0x90 0x07 0x00 0xC5 0x03 0x00 0x00 0x00 0x00 0x00
 0x00 0x02 0x00 0x00 0x00 0x01 0x00 0x06 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x29 0x75 0x27 0x9F 0x64 0x4E 0x4F 0x20 0x4E
 0x41 0x4D 0x45 0x20 0x20 0x20 0x20 0x46 0x41 0x54 0x33 0x32 0x20 0x20 0x20 0x33
 0xC9 0x8E 0xD1 0xBC 0xF4 0x7B 0x8E 0xC1 0x8E 0xD9 0xBD 0x00 0x7C 0x88 0x4E 0x02
 0x8A 0x56 0x40 0xB4 0x08 0xCD 0x13 0x73 0x05 0xB9 0xFF 0xFF 0x8A 0xF1 0x66 0x0F
 0xB6 0xC6 0x40 0x66 0x0F 0xB6 0xD1 0x80 0xE2 0x3F 0xF7 0xE2 0x86 0xCD 0xC0 0xED
 0x06 0x41 0x66 0x0F 0xB7 0xC9 0x66 0xF7 0xE1 0x66 0x89 0x46 0xF8 0x83 0x7E 0x16
 0x00 0x75 0x38 0x83 0x7E 0x2A 0x00 0x77 0x32 0x66 0x8B 0x46 0x1C 0x66 0x83 0xC0
 0x0C 0xBB 0x00 0x80 0xB9 0x01 0x00 0xE8 0x2B 0x00 0xE9 0x48 0x03 0xA0 0xFA 0x7D
 0xB4 0x7D 0x8B 0xF0 0xAC 0x84 0xC0 0x74 0x17 0x3C 0xFF 0x74 0x09 0xB4 0x0E 0xBB
 0x07 0x00 0xCD 0x10 0xEB 0xEE 0xA0 0xFB 0x7D 0xEB 0xE5 0xA0 0xF9 0x7D 0xEB 0xE0
 0x98 0xCD 0x16 0xCD 0x19 0x66 0x60 0x66 0x3B 0x46 0xF8 0x0F 0x82 0x4A 0x00 0x66
 0x6A 0x00 0x66 0x50 0x06 0x53 0x66 0x68 0x10 0x00 0x01 0x00 0x80 0x7E 0x02 0x00
 0x0F 0x85 0x20 0x00 0xB4 0x41 0xBB 0xAA 0x55 0x8A 0x56 0x40 0xCD 0x13 0x0F 0x82
 0x1C 0x00 0x81 0xFB 0x55 0xAA 0x0F 0x85 0x14 0x00 0xF6 0xC1 0x01 0x0F 0x84 0x0D
 0x00 0xFE 0x46 0x02 0xB4 0x42 0x8A 0x56 0x40 0x8B 0xF4 0xCD 0x13 0xB0 0xF9 0x66
 0x58 0x66 0x58 0x66 0x58 0x66 0x58 0xEB 0x2A 0x66 0x33 0xD2 0x66 0x0F 0xB7 0x4E
 0x18 0x66 0xF7 0xF1 0xFE 0xC2 0x8A 0xCA 0x66 0x8B 0xD0 0x66 0xC1 0xEA 0x10 0xF7
 0x76 0x1A 0x86 0xD6 0x8A 0x56 0x40 0x8A 0xE8 0xC0 0xE4 0x06 0x0A 0xCC 0xB8 0x01
 0x02 0xCD 0x13 0x66 0x61 0x0F 0x82 0x54 0xFF 0x81 0xC3 0x00 0x02 0x66 0x40 0x49
 0x0F 0x85 0x71 0xFF 0xC3 0x4E 0x54 0x4C 0x44 0x52 0x20 0x20 0x20 0x20 0x20 0x20
 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x0D 0x0A 0x52 0x69 0x6D 0x75 0x6F 0x76 0x65 0x72 0x65 0x20 0x73 0x75 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FF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
 0xFF 0xFF 0x55
 
This is really amazing, perfect I can say.
Indeed you are right, it is the reading of a precisely 512byte's block inside its tokens.
OK one time again, you won I'm babo.
Much terrific, crazy!
But let's go all the way to the end.
 
SPI>0x4C 0x00 0x00 0x00 0x00 0x61 r}
WRITE: 0x4C READ: 0x2A
WRITE: 0x00 READ: 0xFF
WRITE: 0x00 READ: 0xFF
WRITE: 0x00 READ: 0xFE
WRITE: 0x00 READ: 0x00
WRITE: 0x61 READ: 0x00
READ: 0x7F
ERROR: command has no effect here
Syntax error at char 32
 
That is weird.
Performing the final sequence I get the message "command has no effect here Syntax error at char 32".
So I have tried changing the last with the new
 
0x4C 0x00 0x00 0x00 0x00 0x61 r]
 
and then it's fine.
Also using the sequence
 
[0x52 0x00 0x00 0x00 0x00 0x93 r 
r:520
r:514
0x4C 0x00 0x00 0x00 0x00 0x61 r]
 
it works for me.
 
Now for what I understand, seems to me that repeating the r:514 sequence I'll get the next sector of 512bytes blocks and that is fine.
However I wonder if it is possible automate the thing so that it is not necessary to manually repeat the r: 514 sequence.
I need and so I was looking for a way to automatically read a great amount of blocks, even the whole card in some case, or fill them with fixed values.
Maybe using the Bus Pirate's scripting capabilities, it doesn't matter if using external programs (i.e. Serial AT Command Script Processor 00.08.03 or similar other), would be possible do it and reach the goal.
Sadly I do not know how to do.
Ok, apologize me I dwelt much.
Thank you again tayken,
 
Regards,
 
U.Sb

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #3
Hey there!

The difference between [ ] and { } is explained here: http://dangerousprototypes.com/docs/SPI#Syntax Simply put, first makes CS low, second make CS low and sets up the device so that you puts the read messages to the screen. } and } are the same and that is one strange ass error. Will have to look into that.

You can use the binary scripting mode: http://dangerousprototypes.com/docs/SPI_%28binary%29 You just have to send some stuff to the serial port. There are example source files in the SVN. I personally use Python and code from scratch. Then you can just pass the parameters to the program and save the results in a file.

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #4
Hi tayken,
 
thanks alot for the useful informations and priceless support, you are the best!
 
First.
I read your link (http://dangerousprototypes.com/docs/SPI#Syntax)
Already I knew it but I had never paid attention to it although when I wrote about my intention to dig the matter I knew I would have to go there and read in order to retrieve informations.
So thank you again for the hint!
About the error message, yes it is weird due the fact } and ] should be the same.
Me, and I am sure even much others, I'll glad if you could take a glance at it.
Thanks in advance tayken!
 
Second.
I read your link (http://dangerousprototypes.com/docs/SPI_%28binary%29) but honestly I have not understood very especially because I am unable to put my Bus Pirate v3.6 in the raw binary bitbang mode (binary scripting mode).
In order to gain the raw binary bitbang mode I have downloaded and used Hercules_3-2-6 from http://www.hw-group.com site.
I tried with it but sadly, first the image that show how it have to be set it is not complete (in the top of http://dangerousprototypes.com/docs/SPI_%28binary%29 link), so I can not see how the commands are sent as seems to me that sending them from the terminal in the usual way it is not possible due the "command has no effect here" message.
Hence I tried sending {00} sequence from the send panel in the bottom (there are 3 of them, I used the top one but even the others have the same effect).
I do not know if that is the correct way, however no joy, one more time I fail.
When I send {00} using one of the sends panel, in the terminal I get {00}{00} which it is pink the first and black the latter.
Insisting in sending at a certain time I always get {00}{00} which it is only and all pink, but no joy again.
Seeing the picture in the link (the top of http://dangerousprototypes.com/docs/SPI_%28binary%29) I understand that the right sequence must be some what like
{00}BBIO1{00}SPI1{31}{01}
where the first {00} it is gray, BBIO1 it is black, {00} it is gray, SPI1 it is black, {31} it is pink and {01} it is gray, namely the submitted values are pink and the answers are gray like {01} if the values have been accepted and {00} if those have been refused.
Black BBIO1 and SPI1 labels should be the Bus Pirate's status.
If I could at least achieve the binary bitbang mode I groped to understand something more, sadly I can not even put my Bus Pirate into that modality, though.
Right now I use the v6.3 software release in my Bus Pirate, maybe it is necessary to use particular firmware in order to gain bitbang mode, is not it?
 
Thank you again tayken,
 
Regards,
 
U.Sb

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #5
v6.3 is fine. However you have to send 20 0x00 commands to enter the binary command mode. And they should be 0x00 meaning hexadecimal 0. Don't pay attention to the picture, it shows a state where the BP already entered the binary mode.
Check hex near the box on Hercules. Look at the picture for info:
[attachment=0]

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #6
[quote author="tayken"]} and } are the same and that is one strange ass error. Will have to look into that.[/quote]

Found the cause of the error. Fixed it in the source but not compiled the firmware and tested it out yet. Nevertheless I'm pushing it to the SVN. For the record:

The problem was in busPirateCore.c file, line 225. There is a struct defining what each key press does. ] is mapped to stop function and } is mapped to stopR function. In definitions for SPI, I stumbled into this:
Code: [Select]
	nullfunc1,				// stopR

It should be:
Code: [Select]
	SPIstop,				// stopR

Re: CMD18 & CMD25 with MMC/SD: how to?

Reply #7
Hi tayken,
 
thanks alot for for your patient help, you are amazing!
OK, I get it now!
Thanks to your picture I finally understood how put my Bus Pirate in bitbang mode, so thank you very much!
Before I always failed due the lack in documentation.
In fact I could not see the bottom of the image and so I was sending the wrong sequence like {00} instead of the correct one 00 00 00...
It was my bad.
Sending 00h twenty times as you explained I immediately got the bitbang mode, great!
Now I have to try to understand three things.
First.
Understand how correctly set the Bus Pirate in order to work with MMC/SD.
Maybe that is easy, because I could try using the same settings I use in SPI mode with the ordinary terminal (HyperTerminal).
It should work fine, I guess.
 
Second.
Understand how send the MMC/SD related commands in this new scenario.
Perhaps even this should be easy because I can try sending the same sequences I use with HyperTerminal and SPI mode on Bus Pirate.
The main problem is that until now I am not able to get the right answers 0x01/0x00 as stated in the documentation (http://dangerousprototypes.com/docs/SPI_%28binary%29).
This could be a big problem for me.
We will see.
 
Third.
Understand how automate the process, because honestly I have not yet figured out how I could get such a thing.
Truthfully this is the harder part of the whole matter.
You wrote about Python script and perhaps I need to looking for someone of those in order to see how they are made, even if I guess I do not I'll understand nothing.
Of course I understand that Python's approach is one thing and what I want to do with Hercules_3-2-6 it is another, pretty different things I can say.
I'll try to dig more the matter, we will see.
Right now I can not do anything but thank you very very much for your invaluable help!
Thank you again tayken,
 
Regards,
 
U.Sb
 
P.S. my sincere congratulations to you even for your ability to find and fix the problem with } and ] instructions.
You are really very competent on the matter, it is good for people like me you are here in the group.
Thank you tayken!