请教,关于SD+FATFS的
COM1初始化成功
SD卡初始化成功
成功读取SD卡信息
ManufacturerID:2
OEM/Application ID:21581
Product Revision:56
Product Serial Number:-1607701204
Manufacturing Date:140
CardCapacity:1967128576
CardBlockSize:1024
找到SD卡
读取第0块SD卡数据
EB 3C 90 4D 53 44 4F 53 35 2E 30 00 02 40 02 00
02 00 02 00 00 F8 EB 00 3F 00 FF 00 00 00 00 00
00 A0 3A 00 80 00 29 AA 65 C9 74 4E 4F 20 4E 41
4D 45 20 20 20 20 46 41 54 31 36 20 20 20 33 C9
8E D1 BC F0 7B 8E D9 B8 00 20 8E C0 FC BD 00 7C
38 4E 24 7D 24 8B C1 99 E8 3C 01 72 1C 83 EB 3A
66 A1 1C 7C 26 66 3B 07 26 8A 57 FC 75 06 80 CA
02 88 56 02 80 C3 10 73 EB 33 C9 8A 46 10 98 F7
66 16 03 46 1C 13 56 1E 03 46 0E 13 D1 8B 76 11
60 89 46 FC 89 56 FE B8 20 00 F7 E6 8B 5E 0B 03
C3 48 F7 F3 01 46 FC 11 4E FE 61 BF 00 00 E8 E6
00 72 39 26 38 2D 74 17 60 B1 0B BE A1 7D F3 A6
61 74 32 4E 74 09 83 C7 20 3B FB 72 E6 EB DC A0
FB 7D B4 7D 8B F0 AC 98 40 74 0C 48 74 13 B4 0E
BB 07 00 CD 10 EB EF A0 FD 7D EB E6 A0 FC 7D EB
E1 CD 16 CD 19 26 8B 55 1A 52 B0 01 BB 00 00 E8
3B 00 72 E8 5B 8A 56 24 BE 0B 7C 8B FC C7 46 F0
3D 7D C7 46 F4 29 7D 8C D9 89 4E F2 89 4E F6 C6
06 96 7D CB EA 03 00 00 20 0F B6 C8 66 8B 46 F8
66 03 46 1C 66 8B D0 66 C1 EA 10 EB 5E 0F B6 C8
4A 4A 8A 46 0D 32 E4 F7 E2 03 46 FC 13 56 FE EB
4A 52 50 06 53 6A 01 6A 10 91 8B 46 18 96 92 33
D2 F7 F6 91 F7 F6 42 87 CA F7 76 1A 8A F2 8A E8
C0 CC 02 0A CC B8 01 02 80 7E 02 0E 75 04 B4 42
8B F4 8A 56 24 CD 13 61 61 72 0B 40 75 01 42 03
5E 0B 49 75 06 F8 C3 41 BB 00 00 60 66 6A 00 EB
B0 42 4F 4F 54 4D 47 52 20 20 20 20 0D 0A 52 65
6D 6F 76 65 20 64 69 73 6B 73 20 6F 72 20 6F 74
68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73
6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20
61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61
72 74 0D 0A 00 00 00 00 00 00 00 AC CB D8 55 AA
读取第0块SD卡数据状态:42
当调用 FATFS 功能(main.c的 103行开始)的时候,程序就没有了反应。
我想没调用 FATFS 功能,能够读取卡数据,硬件应该不存在问题。FATFS 代码(0.09的代码)是从官方下载的,代码应该不会有问题。
有问题的应该是我的移植代码,我试了跟踪,程序进了异常,目前还不清楚异常是哪里产生的,想在这里请教热心人士,看看我的代码哪里存在问题,以下是工程源文件和HEX。
http://share.eepw.com.cn/share/download/id/78557
如果你做过相关实验,能否共享下代码,大家可以互相学习下。
谢谢。
关键词: 请教 关于 SD+FATFS
今天终于把 SDIO+FATFS 弄好了,之前出现的问题已经解决。
1、出现硬Fault异常 的问题,是因为自己开的堆栈太小了,
startup_stm32f10x_hd.s 文件中默认的 堆栈大小(Stack_Size)才为 0x00000400(1K),在函数中声明大点数组,很容易就出现 总线 Fault的异常。把
原来:Stack_Size EQU 0x00000400
改成:Stack_Size EQU 0x00000800
程序运行正常。
2、上次上传的源文件,使用的是 3.5的库+SDIO(09/28/2009, V3.1.2版)+FATFS(0.09),这次使用的是 3.5的库+SDIO(10/15/2010, VV4.3.0版)+FATFS(0.09),使用bit1+DMA模式,我用32M的MMC卡 和 2G的SD 卡,都可以正常读取。 记录如下
--------------------------------------------------------------------------------
MMC卡记录:
COM1初始化成功
SD卡初始化成功
成功读取SD卡信息
ManufacturerID:0
OEM/Application ID:2
Product Revision:51
Product Serial Number:842190132
Manufacturing Date:3601
CardCapacity:0
CardBlockSize:0
找到SD卡
将读取第0块SD卡数据
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 89 0D AE 2B 00 00 80 01
01 00 04 03 60 E9 20 00 00 00 E0 F4 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA
读取第0块SD卡数据状态:42
找到根目录
找到文件:VERSION.TXT
找到文件:DSCF8427.JPG
--------------------------------------------------------------------------------
SD卡记录:
COM1初始化成功
SD卡初始化成功
成功读取SD卡信息
ManufacturerID:2
OEM/Application ID:21581
Product Revision:56
Product Serial Number:-1607701204
Manufacturing Date:140
CardCapacity:1967128576
CardBlockSize:1024
找到SD卡
将读取第0块SD卡数据
EB 3C 90 4D 53 44 4F 53 35 2E 30 00 02 40 02 00
02 00 02 00 00 F8 EB 00 3F 00 FF 00 00 00 00 00
00 A0 3A 00 80 00 29 AA 65 C9 74 4E 4F 20 4E 41
4D 45 20 20 20 20 46 41 54 31 36 20 20 20 33 C9
8E D1 BC F0 7B 8E D9 B8 00 20 8E C0 FC BD 00 7C
38 4E 24 7D 24 8B C1 99 E8 3C 01 72 1C 83 EB 3A
66 A1 1C 7C 26 66 3B 07 26 8A 57 FC 75 06 80 CA
02 88 56 02 80 C3 10 73 EB 33 C9 8A 46 10 98 F7
66 16 03 46 1C 13 56 1E 03 46 0E 13 D1 8B 76 11
60 89 46 FC 89 56 FE B8 20 00 F7 E6 8B 5E 0B 03
C3 48 F7 F3 01 46 FC 11 4E FE 61 BF 00 00 E8 E6
00 72 39 26 38 2D 74 17 60 B1 0B BE A1 7D F3 A6
61 74 32 4E 74 09 83 C7 20 3B FB 72 E6 EB DC A0
FB 7D B4 7D 8B F0 AC 98 40 74 0C 48 74 13 B4 0E
BB 07 00 CD 10 EB EF A0 FD 7D EB E6 A0 FC 7D EB
E1 CD 16 CD 19 26 8B 55 1A 52 B0 01 BB 00 00 E8
3B 00 72 E8 5B 8A 56 24 BE 0B 7C 8B FC C7 46 F0
3D 7D C7 46 F4 29 7D 8C D9 89 4E F2 89 4E F6 C6
06 96 7D CB EA 03 00 00 20 0F B6 C8 66 8B 46 F8
66 03 46 1C 66 8B D0 66 C1 EA 10 EB 5E 0F B6 C8
4A 4A 8A 46 0D 32 E4 F7 E2 03 46 FC 13 56 FE EB
4A 52 50 06 53 6A 01 6A 10 91 8B 46 18 96 92 33
D2 F7 F6 91 F7 F6 42 87 CA F7 76 1A 8A F2 8A E8
C0 CC 02 0A CC B8 01 02 80 7E 02 0E 75 04 B4 42
8B F4 8A 56 24 CD 13 61 61 72 0B 40 75 01 42 03
5E 0B 49 75 06 F8 C3 41 BB 00 00 60 66 6A 00 EB
B0 42 4F 4F 54 4D 47 52 20 20 20 20 0D 0A 52 65
6D 6F 76 65 20 64 69 73 6B 73 20 6F 72 20 6F 74
68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73
6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20
61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61
72 74 0D 0A 00 00 00 00 00 00 00 AC CB D8 55 AA
读取第0块SD卡数据状态:42
找到根目录
找到文件:123.TXT
3、在调试过程中,有个很奇怪的现象,就是在用SD_ReadBlock函数读取数据前,没有调用过SD_ReadMultiBlocks函数,那么SD_ReadBlock函数返回的状态往往都是不成功的,数据也是不正确的,这会导致后面FATFS工作不起来。 这估计是 ST写的函数有Bug,之前一直都不怎么调SD_ReadMultiBlocks函数,以为是别的地方有问题,害得自己和SD_ReadBlock函数纠缠了好久。具体为什么要先调SD_ReadMultiBlocks才能正常,没做深究,看看有谁能专研下了。
4、参考
http://blog.csdn.net/cokewei/article/details/7343915
http://www.amobbs.com/thread-5148870-1-1.html
5、源代码和HEX
http://share.eepw.com.cn/share/download/id/78686
6、后记
调试这个SDIO+FATFS,花了我好长时间,估计有1个月把,遇到了很多问题,当不懂时只能问了,问了还不懂,只能查了,查了还不行,只能自己上了,不能什么都依赖别人。
当我遇到问题的时候,我先google一下,我相信我遇到的问题不是世界上第一个人遇到的,先看看别人是怎么解决的或查查有什么线索,最重要的是自己有没有恒心和毅力想把问题解决。
在调试这个实验时,才发现《ARM Cortex-M3权威指南》是多么的经典,以前看不懂,现在慢慢能看懂了,真的是本好书。
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |