Part Number:AM3352
单板使用 SOC_MMCHS_1_REGS 连接 MTFC8GAKAJCN-4M IT(多媒体卡芯片),驱动参考“AM335X_StarterWare_02_00_01_01” 的hsMmcSdRw工程 更改的。
程序中收发数据采用的查询方式实现的,目前卡识别功能正常,数据读写功能不正常,辛苦帮忙看下那部分的设置有问题。
unsigned char emmc_wr_test(void)
{
unsigned char sd_size;
unsigned char state;
// unsigned char i=0;
for(sd_size=0;sd_size<128;sd_size++)
{
r_buf[sd_size] = 0;
w_buf[sd_size] =1+sd_size;
}
state =MMCSDWriteCmdSend(&ctrlInfo, w_buf,r_buf, 1,1);
if(!state)
{
return state;
}
for(sd_size=0;sd_size<128;sd_size++)
{
if(r_buf[sd_size]!=w_buf[sd_size])
{
state =0;
break;
}
}
state = 1;
return state;
}
/**
* \brief This function 实现SD卡的读写测试功能.
*
* \param mmcsdCtrlInfo It holds the mmcsd control information.
* \param ptr It determines the address from where data has to written
* \param r_ptr It determines the address from where data has to read
* \param block It determines to which block data to be written
* \param nblks It determines the number of blocks to be written
*
* \returns 1 – successfull written of data.
* 0 – failure to write the data.
**/
unsigned int MMCSDWriteCmdSend(mmcsdCtrlInfo *ctrl, void *ptr, void *r_ptr, unsigned int block,
unsigned int nblks)
{
mmcsdCardInfo *card = ctrl->card;
unsigned int status = 0, i=0;
unsigned int address;
mmcsdCmd cmd;
unsigned char state =0;//mmc card state
/*
* Address is in blks for high cap cards and in actual bytes
* for standard capacity cards
*/
if (card->highCap)
{
address = block;
}
else//MMC card 和低容量的SD卡一样
{
address = block * card->blkLen;
}
/* Clean the data cache. */
CacheDataCleanBuff((unsigned int) ptr, (512 * nblks));
// ctrl->xferSetup(ctrl, 0, ptr, 512, nblks);
/*cmd7 */
cmd.flags = SD_CMDRSP_BUSY;
cmd.arg = card->rca << 16;
cmd.nblks = nblks;
cmd.idx = SD_CMD(7);
status = MMCSDCmdSend(ctrl, &cmd);
//数据发送后,SD_RSP10=0x00000700;这里状态是正确的,mmc卡的状态为stby
if (status == 0)
{
return 0;
}
state =(cmd.rsp[0]>>9)&0x0F;//state 的值为3,emmc卡的状态变为传送态,后面的指令才有意义
HWREG(ctrl->memBase + MMCHS_BLK)|=0x200;//set 512 bytes block length
if(state !=3)//cmd7 指令异常
{
return 0;
}
/*cmd13 read card states */
cmd.flags = SD_CMDRSP_NONE;
cmd.arg = card->rca << 16;
cmd.idx = SD_CMD(13);
status = MMCSDCmdSend(ctrl, &cmd);
//数据发送后,SD_RSP10=0x00000700;这里状态是错误 的,mmc卡的状态应该为trans, 问题:这里的状态错误怎么改正???
if (status == 0)
{
return 0;
}
/*cmd16 设置块的长度*/
cmd.flags = SD_CMDRSP_NONE;
cmd.arg = 0x200;
cmd.idx = SD_CMD(16);
status = MMCSDCmdSend(ctrl, &cmd);
if (status == 0)
{
return 0;
}
state =(cmd.rsp[0]>>9)&0x0F;
//数据发送后,SD_RSP10=0x00000700;这里状态是错误 的,mmc卡的状态应该为trans,目前为stdby,问题:怎样改???
/*cmd24 写单个块的值*/
cmd.flags = SD_CMDRSP_WRITE | SD_CMDRSP_DATA;
cmd.arg = address;
cmd.nblks = nblks;
if (nblks > 1)
{
cmd.idx = SD_CMD(25);
cmd.flags |= SD_CMDRSP_ABORT;
}
else
{
cmd.idx = SD_CMD(24);
}
status = MMCSDCmdSend(ctrl, &cmd);
//数据发送后,SD_RSP10=0x00000900;这里状态是正确,mmc卡的状态为trans,
if (status == 0)
{
return 0;
}
// /*cmd13 read card states */
// cmd.flags = SD_CMDRSP_NONE;
// cmd.arg = card->rca << 16;
// cmd.idx = SD_CMD(13);
// status = MMCSDCmdSend(ctrl, &cmd);
// //数据发送后,SD_RSP10=0x00000900;这里状态是错误 的,mmc卡的状态应该为rcv 问题:怎样改正????,
// if (status == 0)
// {
// return 0;
// }
//write data SD_STAT =0,问题 状态值为何为0???
// HWREG(ctrl->memBase + MMCHS_BLK)|=0x200;//set 512 bytes block length
IntMasterIRQDisable();
while(!((HWREG(ctrl->memBase + MMCHS_STAT) & MMCHS_STAT_TC) >>MMCHS_STAT_TC_SHIFT))
{
for (i = 0; i <128; i++)
{
if((HWREG(ctrl->memBase + MMCHS_PSTATE) &MMCHS_PSTATE_BWE)>>MMCHS_PSTATE_BWE_SHIFT)
HWREG(ctrl->memBase + MMCHS_DATA) = ((unsigned int*)ptr)[i]; //问题:在这里写入时,看不到Data寄存器的数据变化
else
{
break;
}
}
// if(i == 128)
// {
// break;
// }
}
IntMasterIRQEnable();
// status = ctrl->xferStatusGet(ctrl);
if((HWREG(ctrl->memBase + MMCHS_STAT) & MMCHS_STAT_TC) >>MMCHS_STAT_TC_SHIFT)
{
HWREG(ctrl->memBase + MMCHS_STAT) |=1 <<MMCHS_STAT_TC_SHIFT;
}
/*cmd17 读取数据*/
cmd.flags = SD_CMDRSP_READ | SD_CMDRSP_DATA;
cmd.arg = address;
cmd.nblks = nblks;
if (nblks > 1)
{
cmd.flags |= SD_CMDRSP_ABORT;
cmd.idx = SD_CMD(18);
}
else
{
cmd.idx = SD_CMD(17);
}
status = MMCSDCmdSend(ctrl, &cmd);
// while(!(HWREG(ctrl->memBase + MMCHS_STAT) & MMCHS_STAT_CC));
//
// HWREG(ctrl->memBase + MMCHS_STAT) |=1 <<MMCHS_STAT_CC_SHIFT;//清楚指令完成标志位
if (status == 0)
{
return 0;
}
IntMasterIRQDisable();
while(!((HWREG(ctrl->memBase + MMCHS_STAT) & MMCHS_STAT_TC) >>MMCHS_STAT_TC_SHIFT))
{
for (i = 0; i <128; i++)
{
if((HWREG(ctrl->memBase + MMCHS_PSTATE) &MMCHS_PSTATE_BRE)>>MMCHS_PSTATE_BRE_SHIFT)
((unsigned int*)r_ptr)[i]= HWREG(ctrl->memBase + MMCHS_DATA); //问题:这里可以读到值,所有的读取值一样,和写入的值不一样
}
}
IntMasterIRQEnable();
// if (status == 0)
// {
// return 0;
// }
/* Send a STOP */
if (cmd.nblks > 1)
{
status = MMCSDStopCmdSend(ctrl);
if (status == 0)
{
return 0;
}
}
return 1;
}
问题1:程序中标注的几个问题,指令发送后,响应的状态位不对?
问题2:关于cache的代码是必须的吗?CacheDataCleanBuff()?
Cherry Zhou:
您好,我们把您的问题升级到英文论坛给美国工程师看下,有答复尽快给到您。
,
Cherry Zhou:
抱歉,我们已不再支持 AM335x 基于 Starterware 的软件开发。 详情可参阅该处:https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1071334/notice-regarding-processor-sdk-ti-rtos-for-am335x-am437x-omap-l13x-c674x-k2g-devices