[ARM] LPC3250: Issue on Reading SD Card BootSector

Status
Not open for further replies.

shankarrg

Newbie level 6
Joined
Jun 6, 2017
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
150
Hello All,

I am interfacing SD card on ARM: LPC3250. The 2GB fat16 formatted sd card is initialized on reading Boot Sector (1st Block) CMD17 I am not getting valid boot sector information, instead I am getting below data in a 32 bit array every time
data[0] = 0x00000000
.....
data[110] = 0x00000000
data[111] = 0x02000000
data[112] = 0x3D06000A
data[113] = 0x0087BDFD
data[114] = 0xEF790000
data[115] = 0x0000003A

When i check the above data in hexa editor. each 32bit data is at was random location.

at the end when i check status register = 0x00000500 clearly says data end(bit 8) and Data block received(bit 10). i have spent lot of time, checked at different Clock.
Please suggest where i am Wrong
 

Sorry i am adding more detail here

I am interfacing SD card on ARM: LPC3250. The 2GB fat16 formatted sd card is initialized on reading Boot Sector (1st Block) CMD17 I am not getting valid boot sector information, instead I am getting below data in a 32 bit array every time

data[0] = 0x00000000
.....
data[110] = 0x00000000
data[111] = 0x02000000
data[112] = 0x3D06000A
data[113] = 0x0087BDFD
data[114] = 0xEF790000
data[115] = 0x0000003A

When i check the above data in hexa editor. each 32bit data is in random location but same data at every time.

1) At the end when i check status register = 0x00000500 clearly says data end(bit 8) and Data block received(bit 10).
2) i have set Clock(card initialization clock = 510Khz and then 5Mhz for data read).
3) I have tried different sd card also.
4) interrupt based Reading data when SD_Fifo half filled.
5) i have given my initialization sequence function below.

/*Application entry point*/
void c_entry(void)
{
/* Setup SDMMC card and controller */
if (sdmmc_setup() == FALSE)
{
return;
}

/* Read a bunch of data blocks */
sblk = BLKFIRST;
dbuff = databuff;
for (blk = 0; blk < BLKSTOTRANFER; blk++)
{
if (sdmmc_read_block(dbuff, 1, (sblk * SDMMC_BLK_SIZE), &resp) < 0)
{
goto ctrller_close;
}

sblk++;
dbuff += SDMMC_BLK_SIZE / sizeof(UNS_32);
}

/* Setup SDMMC card and controller */
BOOL_32 sdmmc_setup(void)
{
INT_32 ocrtries, sdcardtype, validocr;
SD_CMDRESP_T resp;
SDC_PRMS_T params;
SDC_XFER_SETUP_T dataset;

/* Open SD card controller driver */
sddev = sdcard_open(SDCARD, 0);
if (sddev == 0)
{
return FALSE;
}

/* Setup controller parameters */
params.opendrain = TRUE;
params.powermode = SD_POWER_ON_MODE;
params.pullup0 = 1;
params.pullup1 = 1;
params.pullup23 = 1;
params.pwrsave = FALSE;
params.sdclk_rate = SDMMC_OCR_CLOCK;
params.use_wide = FALSE;
if (sdcard_ioctl(sddev, SD_SETUP_PARAMS,
(INT_32) &params) == _ERROR)
{
return FALSE;
}

/* Setup data transfer paramaters */
dataset.data_callback = (PFV) wait4datadone;
dataset.cmd_callback = (PFV) wait4cmddone;
dataset.blocksize = SDMMC_BLK_SIZE;
dataset.data_to = 0x001FFFFF; /* Long timeout for slow MMC cards */
dataset.use_dma = FALSE;
sdcard_ioctl(sddev, SD_SETUP_DATA_XFER, (INT_32) &dataset);

/* Issue IDLE command */
sdmmc_cmd_send(SDMMC_IDLE, 0, &resp);

/* After the IDLE command, a small wait is needed to allow the cards
to initialize */
timer_wait_ms(TIMER_CNTR0, 100);

/* Issue APP command, only SD cards will respond to this */
sdcardtype = 0;
sdmmc_cmd_send(SDMMC_APP_CMD, 0, &resp);
if ((resp.cmd_status & SD_CMD_RESP_RECEIVED) != 0)
{
sdcardtype = 1;
}

ocrtries = SDMMC_MAX_OCR_RET;
validocr = 0;

/* If this is an SD card, use the SD sendop command */
if (sdcardtype == 1)
{
resp.cmd_resp [1] = 0;
while ((validocr == 0) && (ocrtries >= 0))
{
/* SD card init sequence */
app_cmd_send(SD_SENDOP_COND, OCRVAL, &resp);
if ((resp.cmd_resp [1] & SDMMC_OCR_MASK) == 0)
{
/* Response received and busy, so try again */
sdmmc_cmd_send(SDMMC_APP_CMD, 0, &resp);
}
else
{
validocr = 1;
}

ocrtries--;
}

if (validocr == 0)
{
return FALSE;
}

/* Enter push-pull mode and switch to fast clock */
params.opendrain = FALSE;
params.sdclk_rate = SD_NORM_CLOCK;
sdcard_ioctl(sddev, SD_SETUP_PARAMS, (INT_32) &params);

/* Get CID */
sdmmc_cmd_send(SDMMC_ALL_SEND_CID, 0, &resp);

/* Get relative card address */
sdmmc_cmd_send(SDMMC_SRA, 0, &resp);
rca = (resp.cmd_resp [1] >> 16) & 0xFFFF;

/* Select card (required for bus width change) */
sdmmc_cmd_send(SDMMC_SELECT_CARD, (rca << 16), &resp);

/* Set bus width to 4 bits */
sdmmc_cmd_send(SDMMC_APP_CMD, (rca << 16), &resp);
app_cmd_send(SD_SET_BUS_WIDTH, 2, &resp);

/* Switch controller to 4-bit data bus */
params.use_wide = TRUE;
sdcard_ioctl(sddev, SD_SETUP_PARAMS, (INT_32) &params);
}
else
{
/* MMC Intialize*/
}

/* Deselect card */
sdmmc_cmd_send(SDMMC_SELECT_CARD, 0, &resp);

/* Status request */
sdmmc_cmd_send(SDMMC_SSTAT, (rca << 16), &resp);

/* Select card */
sdmmc_cmd_send(SDMMC_SELECT_CARD, (rca << 16), &resp);

return TRUE;
}

INT_32 sdmmc_read_block(UNS_32 *buff,
INT_32 numblks, /* Must be 1 */
UNS_32 index,
SD_CMDRESP_T *resp)
{
SD_CMDDATA_T sdcmd;

/* Setup read data */
sdcmd.data.dataop = SD_DATAOP_READ;
sdcmd.data.blocks = numblks;
sdcmd.data.buff = buff;

/* Setup block count to data size */
sdmmc_cmd_send(SDMMC_SET_BLEN, SDMMC_BLK_SIZE, resp);

/* Perform command setup from standard MMC command table */
sdmmc_cmd_setup(&sdcmd.cmd, sdmmc_cmds[SDMMC_READ_SINGLE].cmd,
index, sdmmc_cmds[SDMMC_READ_SINGLE].resp);

/* Read data from the SD card */
return sdmmc_cmd_start_data(&sdcmd, resp);
}

Boot sector snap


Please suggest where i am Wrong/any workaround i am missing Thanks.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…