SD card maximum write speed in SPI mode - embedded

I am interfacing SD cards (1/2GB SD cards and 4GB SDHC cards from different manufactures) to a custom board in SPI mode and I am using a FATfs file system from elm-chan.
I am able to write files and read files on the SD card. However I would like to know where can I get the information on the maximum clock frequency (I can drive my SPI bus) for the given SD card.
I have seen that for some SD cards maximum speed was about 1.33MHz and for some 20MHz.
I assumed this speed was in the CSD register (TAAC value, as the TRAN_SPEED was the same on all the cards set at 25Mhz). However I realized its not true. I would really appreciate if someone can share their knowledge on this. Thanks!

Without a clear part number of the SD card, it is not feasible to find it. The probability of getting a correct answer is high only if you can share the exact details. I suggest you to check the specification thoroughly of the respective SD card for a quick answer. Can you confirm whether the observation done by you is different from the information provided in the specification ?

Related

STM32F746 - SD Card CRC failing in 4-bit mode, but working fine in 1-bit mode

Recently, I bought a Nucleo-144 development board for the STM32F746. For the project I'm working on, I need to get consistent >3 MB/s write speeds to the SD card. Using STM32CubeIDE, I've been able to get SD 1-bit mode working with FatFS in both polling and DMA modes at full speed. However, switching to SD 4-bit mode, I start getting lots of IO errors relating to bad data CRCs while reading.
Details
In SD 4-bit polling mode, I can't even get a single block read to process correctly. Calling f_mount returns an IO error, and debugging it further reveals that the first call to HAL_SD_ReadBlocks, reading sector 0, fails with the error code SDMMC_ERROR_DATA_CRC_FAIL:
Inspecting the 512 byte data buffer it's read to from the card reveals that data is at least partially intact containing some strings you'd expect to see in the first sector:
Importantly, this buffer is corrupted in the exact same manner between each run of the software. If it was some kind of electrical interference problem, I'd expect to see different bytes being corrupted, but I don't. The buffer is identical between runs. Switching back to 1-bit mode and inspecting the data buffer, it's clearly in a lot better shape. The 4-bit buffer clearly has a lot of corrupted bits and bits that are missing entirely, offsetting everything. 4-bit mode is reading mostly junk, but consistently the same junk.
What I've Tried
Polling and DMA mode.
Both fail in a similar manner, although it's harder to debug DMA.
Decreasing the SDMMCCLK clock divider all the way down to 255, the highest divider (and lowest clock speed) it'll go.
On my older, cheaper, Lexar SD card read/writes in this mode work flawlessly (albeit very slowly).
On my newer, more expensive, Samsung SD card read/writes still fail with a SDMMC_ERROR_DATA_CRC_FAIL error. The data buffer appears much more intact, but it's clearly still garbage data.
Transfers with GPIO pull-ups applied to all SD pins (except clock) as well as without pull-ups.
No change, at least as far as I could tell.
Using multiple different SD cards.
Specifically, a Lexar "300x" 32 GB card and a Samsung "EVO Plus" 128 GB card.
As mentioned previously, decreasing the clock speed allowed one of my two cards to work.
However, my higher quality card still fails on the first read even at the minimum speed.
Wiring
Not sure how relevant this is, but figured I'd include it for sake of completion. This is how I have my SD card connected while prototyping. All of the cables are the same length, but perhaps they're interfering with each other even over such a short distance? I'm also using an Adafruit SD card breakout adapter for testing.
SD Card
GPIO Pin
CLK
PC12
D0
PC8
CMD
PD2
D3
PC11
D1
PC9
D2
PC10
Summary
It appears that with some cards, even at lower clock speeds, IO errors are incredibly common in SD 4-bit mode only. At higher clock speeds, all cards I'm able to test with start having IO errors in 4-bit mode. In SD 1-bit mode, however, even at the maximum clock speed I'm able to read and write fine.
I'd like to take advantage of the 4-bit mode for faster speeds. What am I doing wrong? Is it something electrical, like for example needing stronger pull-up resistors or shorter wires? Thanks, I really appreciate it!
I had similar issues on a H743ZI Nucleo. My code worked fine on two other H743 boards with onboard sdcard readers, but failed on the Nucleo with Adafruit breakout. I believe it was just due to signal integrity..
I see you tried dropping the clock divider down, but have you tried a slower SDMMC clock? This was what made the difference for me. Was failing at 48MHz, but fine at 24MHz and lower with 0 divider.

Mag stripe keyboard wedge print speed

I am writing an application where I need to accept information from a mag swipe keyboard edge. I am running into concerns in regards to the wedge's print speed. Any lag in the application, even at input, is very important.
I can not seem to find an answer to this question:
What is the main bottleneck for a mag stripe reader's print speed (keyboard wedge specific via usb or usb slave)?
I have noticed that the print speed differs from machine to machine. I want to say that it is either the usb port or the RAM on the device but I unfortunately don't know enough about the hardware end of things to come to a conclusion. Furthermore might it be the operating system or card reader? I know the reader itself has a print speed but that does not explain the fluctuation.
Anyone know as to what it might be?
So it turns out it is the baud rate. You can change the baud rate on the computer and the card reader to adjust the speed at which the data (or print) speed is sent/received.

having trouble looking for the right gps

I'm looking for a GPS for a small class project. We want the smallest GPS possible and all we really need it to do is to give us longitude and latitude values when we poll it.
I tried looking at sparkfun, but since we haven't really worked with this type of hardware before, it's hard to know which kind we really want/what parts we need.
What We Need:
smallest possible
longest battery life
only need long and lat
able to be polled from some other device such as a mobile app or website
Thanks!
there are two paths to this, one is just get a bluetooth receiver, you will be able to poll it from a mobile phone or whatever. going to likely be as big as the phone, have the battery inside, etc. not sure how long it will last on one charge.
There are other solutions designed for putting in packages being shipped, better battery life, but their goal is as data loggers and not necessarily something you can cable up and poll and likely not wireless if that is what you are after.
Now if you want to build your own, and you already went to sparkfun, here is another path.
I know that leaving links in an answer at SO is bad...This was longer than a comment and will add some more info...
You want small you can go with this
https://www.sparkfun.com/products/11571
It is a GP-635T gps receiver, if you look at the picture it really is around the size of a quarter. 50 channel. Point it up the way they tell you, antenna is built in, just power it and it works.
You will need to hook up to it. It is the serial version not usb, in either case you need a cable like this.
https://www.sparkfun.com/products/10361
This link is to a cable with 6 or 8 inch pigtails, the gps receiver comes on a board with a not so uncommon connector on it, this cable allows you get at those connections, you only need three.
The datasheet on the sparkfun page or probably just search for the part number, you need to look at the UART TTL pinouts not the usb pinouts. Yo uneed 3.3 to 5.5volts to power it pin 2, pin 1 is ground. then pin 3 is txa serial out. This is where you get your data.
these are various solutions that will work
https://www.sparkfun.com/products/9873
https://www.sparkfun.com/products/718
http://jim.sh/ftx/
some soldering may be required. The above links are various solutions between $10 and $15 for ftdi usb to serial/uart break out boards. These will include 3.3v and ground and the rx pin is the receiver for the ftdi uart, you tie that to txa on the gps unit.
What you may not know and may be interested in is that almost universally gps units do their math magic and come up with the various items time, position (2d or 3d), speed, etc. And they output this data in a serial manner. search for NMEA or NMEA-0183. The data sheet for this and any other should give an indication of the default data rate (4800, 9600, 19200, etc baud) and what messages are sent. sometimes you can change the baud rate, sometimes you cant. The ftdi chips/boards are very flexible use a usb cable to plug in the board to a computer, configure your software or a dumb terminal program like minicom or hyperterm or teraterm or whatever (no parity, no hardware flow control) and the messages will appear usually once a second. Whether it is your car navigation, handheld gps, whatever, buried inside is some flavor of gps reciever (sparkfun will give you an indication of just how many different flavors there are and their selection is just scratching the surface) that outputs serial and the software in that unit is receiving that serial data and then doing its thing (mapping, navigating, etc). As with modems back in the day the ones you find in your cell phone might have some of the software/math done by the main processor in the phone to save on money, these libraries are not generally available, when you make the deal to buy thousands or millions of units they allow you to pay for the software to go with it along with your signature on a bunch of legal documents. I assume this is the case, that is how the ones in phones are down to $10 or so where these fully contained solutions are usually $50 to $100 in single quantities and likely not a lot cheaper in quantity.
Once powered, even if it says X number of seconds hot or cold to lock it doesnt always take that, sometimes if it has to search it may still take a while, the less metal you have around (like being in a building or the center of a car) the worse it is to the point it may not lock.
if you have an older garmin street pilot (that is otherwise dead I would hate to kill one of those if it is working) you can rip it apart and likely find a sirf III or other module in there, likely a 5V not 3.3 (there are 5V ftdi based breakout usb to serial. the microftx is both 5v and 3.3, note the gps receiver linked above is also 5v or 3.3) googling will be required to figure out the pinout and such, and soldering might or might not be a challenge.
you can also find old etrex or other handhelds on ebay or wherever (that work!) and for $15 or so get a serial cable, well then you need a serial to usb likely which will also need a level shifter like a max232, you dont plug this right into a ftdi break out board, it will fry it. newer ones have usb and you can power the unit from the usb and likely see the nmea data over the usb as well.
Most of the stuff you see on sparkfun in the gps area is going to be related to these various brands and models of gps recivers that output nmea data over serial. some are 5V some are 3.3, many do not have antennas and you have to buy those separately (and get the right kind, one that plugs into the connector provided, etc). I have a number of these items and they all work just fine, some do better than others around buildings or in trees, etc. Around sparkfun you will also find lipo battery solutions and bluetooth or xbee or other wireless solutions, very quickly if you need wireless, I think you will find just buying an off the shelf solution is best. I have had my eye on the garmin bluetooth thing google
Garmin GLO Portable GPS and GLONASS Receiver
it is about $99. I have not pulled the trigger yet so I dont know how good or bad it is, the el cheapo brands just look cheap.
Of course, a smart phone has both wireless and a gps and you can get a lot of used phones for cheap on ebay. Ios and android. You could "just write an android app" and put it on the phone and use one of the wireless interfaces built into the phone. It will chew through the battery yes, how fast? who knows.

SDHC SPI write issues

I've been trying to do an SD card interface with the LPC1766 SPI peripheral for a while and right now I'm stuck in a problem that I couldn't find the answer anywhere.
The problem is: SDHC cards are not responding to write and read commands as expected.
Everything works fine on the initialization that was based on Chan's flowchart and on an NXP application note. I can differentiate the cards versions, read the OCR, CID, CSD and determine their sizes.
After that step I start writing single blocks every one second and reading it back to check the data integrity. On a Kingston SDHC 4 GB Class 4 card I can send a first write command but on the second one the card does not even answer (0x00 or 0x01) to the CMD24. With a SanDisk 4 GB Class 4 card the results are different, every command is answered by the card, but I get only zeroes when reading the data back (I'm sure I'm not writing zeroes). If I use SDSC cards, everything works fine.
I'm aware that SDHC are block addressed and not byte addressed and that I need to send ACMD41 with the CCS on for SDHC. I also know that the clock frequency is not an issue (using 400 KHz to start and then 20 MHz to write/read), because I just turned on the CRC checking and all cards are accepting the commands and data. If I stop calculating the CRC all cards reject commands and data.
How do you connect your SD card? Depending on the mode/state the SD(HC) card needs an external pull-up resistor. Without that you read zero, so that may be your problem.

SD card initialization using SPI

I saw a lot of information about MMC/SD cards and I tried to make a library to read this (modifying the Procyon AVRlib).
But I have some problems here. I don't change the original code and tried here. My problem is about the initialization of an SD card. I have two here, a 256 MB and another 1 GB.
I send the init commands in this order: CMD0, CMD55, ACMD41, and CMD1.
But the 256 MB SD card only returns a 0x01 response for each command. I send the CMD1 a lot of times and the 256 MB SD card always returns only 0x01, never 0x00.
The 1 GB SD is more crazy... CMD0 returns with 0x01. Nice, but the CMD55 command responds with 0x05. At other times it responds with 0xC1 and also sometimes responds with 0xF0 with a 0x5F in the next interation...
Around the Internet there is information and examples, but it is a bit confused. Here in my project, I must use a 1 GB card and I'm trying with a microSD card with an SD adapter (I think that this is not the problem).
How do I fix this problem?
PS: My problem is like the problem in Stack Overflow question Initializing SD card in SPI issues, but the solution didn't solve my problem. The 1 GB SD card only returns 0x01 ever... :cry:
Why do you need CMD1? And did you read the note below it, that says "CMD1 is a valid command for the thin (1.4 mm) standard size SD memory card only if used after re-initializing a card (not after power on reset)."?
About the 1 GB card, ideas that come to mind:
After every command (send command, get reply), do you send 8 dummy bytes before making CS high?
The values returned seem weird (0x05 doesn't have busy bit set, so WTF?), maybe there's a hardware issue?
Does the card work otherwise?
Maybe this helps a bit:
SD Specifications Part 1 Physical LayerSimplified Specification
A simple explanation of MMC/SD usage over SPI is provided here. I have used the associated FAT file-system library too and it works well.
However, the solution may not work for some makes of cards. For such cards, you may have to edit the procedure/library. That may be why your 1 GB card acts differently -- it may be a different make of card. The SPI mode of certain cards may not be that popular for commercial equipment, and thus may be more deviated in specification by some card manufacturers.
If you bit bang the commands and clocks, you may have more control and confidence that those procedures are correct. That is useful because you need some solid ground to build on to progress bit by bit. I found that the <400 kHz 80 clocks was critical on one card, but could run at more than 2 MHz on another.
Try to progress one command at a time that is reliable for both cards.