本帖最后由 xieshang 于 2012-4-15 16:08 编辑
最近在学RTT,想将SD卡做成热插拔,通过USB在电脑上显示为U盘。
现在是只要插入或者拔出后再插入SD卡,再重新接上USB就会出现硬件错误。折腾了一个多星期了还没弄明白。
我现在做的USB设备是HID+SPI FLASH+SD卡,即HID+2个MASS
其中,SD卡的热插拔经过测试,加载到文件系统,通过finsh的device_test("sd0"),这说明了底层设备驱动并没有问题。
调试过程如下:
SPI File System initialized!
SD File System initialized!
finsh>>SDCARD unmount! //这里拔出SD卡
SDCARD mount! //重新插上SD卡
//下面是device_test sd卡,读写都OK
finsh>>device_test("sd0")
block device!
device info:
sector size : 512 byte
sector count : 1931264
block size : 1024 byte
device I/O R/W test pass!
device I/O speed test.
RT_TICK_PER_SECOND:100
read 200 sector from 1976 to 1991,682666 byte/s
write 200 sector from 1991 to 2094,99417 byte/s
0, 0x00000000
而讲USB插入到PC,或者将上拉拉上的结果:
psr: 0x61000000
pc: 0x08000272
lr: 0x08000319
r12: 0x00000000
r03: 0x20003044
r02: 0x00000005
r01: 0x00000020
r00: 0x20000000
hard fault on thread: self
thread pri status sp stack size max used left tick error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
msc_thre 0x1f ready 0x00000040 0x00000400 0x00000040 0x00000001 000
tidle 0x1f ready 0x00000040 0x00000100 0x00000040 0x00000020 000
timer 0x08 suspend 0x00000078 0x00000200 0x00000078 0x0000000a 000
tshell 0x14 suspend 0x00000088 0x00000800 0x000002a4 0x00000009 000
init 0x08 0x00000068 0x00000800 0x00000448 0x00000011 000
self 0x14 ready 0x00000048 0x00000200 0x00000160 0x00000002 000、
其中,self进程的while(1)内容:
while (1)
{
if(SDCARD_change)
{
SDCARD_change = 0;
GPIO_SetBits(GPIOB, GPIO_Pin_5);
//SD卡插入 下降沿 即卡被插入
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7) == 0)
{
if( rt_device_find("sd0") == RT_NULL)//未加载SD0
{
count = sd_remount();
if(count && rt_device_find("sd0") != RT_NULL)
{
// GPIO_SetBits(GPIOB, GPIO_Pin_5);
USB_sdcard();
Max_Lun = 1;
// USB_cable();
if(dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
{
rt_kprintf("SDCARD mount!\n");
}
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
}
}
}//SD卡插入 上升沿 即卡被拔出
else
{
dev = rt_device_find("sd0");
if(dev != RT_NULL)
{
GPIO_SetBits(GPIOB, GPIO_Pin_5);
dfs_unmount("/sd");
rt_device_unregister(dev);
//GPIO_SetBits(GPIOC,GPIO_Pin_6); /* SD card power down */
Max_Lun = 0;
rt_kprintf("SDCARD unmount!\n");
}
}
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
}
}
|