Trying to get the SDHC to work | |
Description: | I have TWK-K60 REVC system. I downloaded sample codes to run the SDHC card. It will not work and am not sure why, maybe the code is wrong, maybe the SDHC properties are wrong, or maybe CW10.1 is not setup right. I have CW 10.1 installed on WIN7 and all patches applied. See attached files, these are my complete workspace with a project called fm15 within. Load on CW10.1 and see please. Do you need startup.c? I went into debug mode and the compiler is seemingly creating what looks like it own startup code by doing such things as zeroing .bss and also copying initialized variables etc.... Please be very specific on the solution as I am very technical and should be able to handle it. We are now delayed 1 week due to this so please help soon. Richard. |
This has been posted on the personal support board now 7 days without anyone looking at it from FREESCALE :smileysad: not having good luck, hope someone can help.
Richard.
Hi Richard,
could you, please, put a breakpoint in the CardSelection function in the component's C module (probably SDHC.c) on the if statement with the "Id != SDHC_NO_CARD" condition and send me the dump of the DeviceDataPrv local variable (in a readable form) and the SDHC registers. Also could you, please, send me the type of the inserted card (SD/MMC, capacity, manufacturer etc.). Thank you.
Ladislav
OK that looks like crap.
I made a PDF..... see attached.
Richard.
OK I decided to move the CW and the project to a WIN XP machine from the Vista Machine.... now I get new error messages......
So what am I not doing????
Am I not starting the project correctly?
Do I need a startup.c file?
I do not know why the result would differ......
Richard.
There are several problems with the "Typical usage" example code in the component's help which caused the errors.
I would recommend to test your application with a wider set of cards (SD/MMC - various spec. versions, high/low capacity, ...). Beside unveiled errors in the software component there could be also problems with electrical requirements of the various specifications.
Ladislav
Thank you again for the info. I'll try to figure out what the problem is and I'll let you know.
Ladislav
I did some very close investigations into when this error occurs, its in SDHC_SelectCard(), it selects an RCA of 1, and send the command CMD7 with argument 0x00010000 which looks right, its the 1 shift 16 left, when the SDHC hardware gets the command it returns 0x00400700 in RSP0 which means invalid command was sent and shows it was CMD7. SDHC_R1_IS_ILLEGAL_COMMAND(Response) ((Response)[0] & 0x00400000UL) Not sure why at this point CMD7 is illegal....
According to the specification, illegal commands are not responded to. The flag is set and sent with the next valid command. Therefore the illegal command may be the CMD1 sent at the end of card detection (which should be ignored by SD cards). Please, could you try the following workaround:
DeviceDataPrv->State = LDD_SDHC_VOLTAGE_VALIDATION;
DeviceDataPrv->Substate = SDHC1_VV_FINISH;
VoltageValidation(DeviceDataPrv, 0U, SDHC1_NO_RESPONSE);
DeviceDataPrv->Substate = SDHC1_CR_START_FINISH;
CardRegistration(DeviceDataPrv, 0U, SDHC1_NO_RESPONSE);
If you make these changes, the last command sent before CMD7 should be CMD3. This does not affect the functionality in the case you have only one card slot connected to the SDHC bus.
yes this has worked! thanks!
now in the function SD_ReadBlockPart(&SD, address, 0, 512, Buf);
I am trying to get by LBA (sector), is address the sector or do you need to multiply by 512?
Richard.
Great! I'm glad that it finally works. I'm sorry for the inconveniencies.
The address parameter in the demo example is a byte address. Internally the function uses the SD_ByteToCardAddress function which divides the byte address by 512 to get sector address (for high capacity cards) or uses the byte address directly (for low capacity cards) according to CardInfo.Caps.HighCapacity. If you want to use sector addresses, create a similar function SD_SectorToCardAddress, which will multiply by 512 for low capacity cards.
Ladislav
OK all working and hooked up to a FAT16/32 file system and all OK!
BUT....
You need ot start the component off with a clock of 400khz, I filled in higher speeds in the list, and called them through a function to change speed, when I do this it breaks..... any procedure to crank the speed up and how high can it go, do the cards tell you?
RIchard.
Did you get any error from the GetError function?
Here is an example how to speed up the communication (in the context of the Typical usage example code):
/* Switch from default 1-bit communication to 4-bit (if supported) */
if (SD.CardInfo.Caps.DataWidths & LDD_SDHC_CARD_DATA_WIDTH_4_BIT) {
SDHC1_SetDataWidth(SD.SDHCPtr, LDD_SDHC_CARD_DATA_WIDTH_4_BIT);
SD_Wait(&SD);
}
printf("Reading at 400kHz\n");
SD_Read(&SD);
SDHC1_SelectBusClock(SD.SDHCPtr, SDHC1_BUS_CLOCK_1MHz);
SD_Wait(&SD);
printf("Reading at 1MHz\n");
SD_Read(&SD);
SDHC1_SelectBusClock(SD.SDHCPtr, SDHC1_BUS_CLOCK_10MHz);
SD_Wait(&SD);
printf("Reading at 10MHz\n");
SD_Read(&SD);
if (SD.CardInfo.Caps.HighSpeed) {
SDHC1_SelectBusClock(SD.SDHCPtr, SDHC1_BUS_CLOCK_50MHz);
SD_Wait(&SD);
printf("Reading at 50MHz\n");
SD_Read(&SD);
}
The maximum low speed frequency is 25MHz. If you use higher frequencies (e.g. 50MHz), you should turn on high slew rate bits in the port control module on the SDHC pins. Otherwise you can get a data CRC error.
Ladislav
I just also found a SDHC example project for Kinetis using Processor Expert and this demo program gets the same results as mine.
Here is the output of the demo:
+++ Step 0 - begin +++
Description: Card initialization example
1) Reseting card...
2) Card inserted - detecting card type...
3) Card detected - selecting card...
ERROR Internal component error
+++ Step 0 - end +++
I get the same ERROR which is 12
Richard
Hi Richard,
Have you ever tried the BRTOS demo? We have a demo for the TWR-K60N512-KIT that supports the use of a SDHC card.
Here we have a video showing bitmap pictures being loaded in a LCD display:
http://www.youtube.com/watch?v=PrbfsqETglY
The demo code can be download here:
Regards,
Gustavo
We do not want an OS and we want to use Processor Expert for Kinetis, they advertise how simple it is to make things work, and yes most of the time it does, but so far with DMA to DAC, and SDHC it does not.
Richard.
Ok Richard, I just wanted to help.
If you had tested the demo you would have seen that the SDHC / FAT32 code is completely independent to the OS.
Sometimes is good to understand what you are doing and not just rely in Processor Expert. Portable C code can be used in any microcontroller. Think about it.