Eclipse开发调试ARM裸机程序(七)sd卡读写
时间:11-19
来源:互联网
点击:
主要用到了sd card官网上的几个文档,《SD Specifications Part 1 Physical Layer Simplified Specification Version 4.10 January 22, 2013》里边讲了SD卡内部的寄存器,一般的时序。还有《SD Specifications Part A1 Advanced Security SD Extension Simplified Specification Version 2.00 May 18, 2010》和《SD Specifications Part A2 SD Host Controller Simplified Specification Version 3.00 February 25, 2011》都提供了一些信息。另外一个《SD Specifications Part E1 SDIO Simplified Specification Version 3.00 February 25, 2011》是说SDIO的,是以SDIO为接口的衍生品,包括SDIO wifi等等。这些文档都可以在
每个寄存器都有特定的含义,我这里真分析的CSD寄存器,并用一个小程序算出每个参数的值。
先用Android手机或者开发板下载一个应用 “sd tools”,这样可以显示出SD卡的CSD,然后根据手册《SD Specifications Part 1 Physical Layer Simplified Specification Version 4.10 January 22, 2013》。测试的SD卡的CSD码值如图所示:
小程序如下:
#include#include typedef unsigned int u_size;int main(){u_size a = 0, b = 0, c = 0, d = 0;//CSD = 003e00325b5a83c5e597ffff12800000a = 0x003e0032; //[127:96]b = 0x5b5a83c5; //[95 :64]c = 0xe597ffff; //[63 :32]d = 0x12800000; //[31 :0 ]u_size CSD_STRUCTURE = a / (u_size)pow(2,30) & 0x3; // [127:126 - 96]u_size TAAC = a/(u_size)pow(2,16) & 0xff; // [119:112]u_size NSAC = a/(u_size)pow(2,8) & 0xff; // [111:104]u_size TRAN_SPEED = a/(u_size)pow(2,0) & 0xff; // [103:96 - 96]u_size CCC = b/(u_size)pow(2,20) & 0xfff;u_size READ_BL_LEN = b/(u_size)pow(2,16) & 0xf; // [83:80-64]u_size READ_BL_PARTIA = b/(u_size)pow(2,15) & 0x1;u_size WRITE_BLK_MISALIGN = b/(u_size)pow(2,14) & 0x1;u_size READ_BLK_MISALIGN = b/(u_size)pow(2,13) & 0x1;u_size DSR_IMP = b/(u_size)pow(2,12) & 0x1;u_size C_SIZE = (b & 0x3ff)*(u_size)pow(2,2) \+ ((c /(u_size)pow(2,30)) & 0x3); // [73:62]u_size VDD_R_CURR_MIN = c/(u_size)pow(2,27) & 0x7;u_size VDD_R_CURR_MAX = c/(u_size)pow(2,24) & 0x7;u_size VDD_W_CURR_MIN = c/(u_size)pow(2,21) & 0x7;u_size VDD_W_CURR_MAX = c/(u_size)pow(2,18) & 0x7;u_size C_SIZE_MULT = c/(u_size)pow(2,15) & 0x7; // [49:47]u_size ERASE_BLK_EN = d/(u_size)pow(2,14) & 0x1;u_size SECTOR_SIZE = d/(u_size)pow(2,7) & 0xef;u_size WP_GRP_SIZE = c/(u_size)pow(2,0) & 0xef;u_size WP_GRP_ENABLE = d/(u_size)pow(2,31) & 0x1;u_size R2W_FACTOR = d/(u_size)pow(2,26) & 0x7;u_size WRITE_BL_LEN = d/(u_size)pow(2,22) & 0xf;u_size WRITE_BL_PARTIAL = d/(u_size)pow(2,21) & 0x1;u_size TMP_WRITE_PROTECT = d/(u_size)pow(2,12) & 0x1;u_size FILE_FORMAT = d/(u_size)pow(2,10) & 0x3;u_size CRC = d/(u_size)pow(2,1) & 0xff;long C = (C_SIZE + 1) * pow(2, (C_SIZE_MULT+2)) * pow(2, READ_BL_LEN);// C = (3863 + 1) * 512 * 1024printf(" 1. CSD_STRUCTURE = 0x%x\n", CSD_STRUCTURE);printf(" 3. TAAC = 0x%x\n", TAAC);printf(" 4. NSAC = 0x%x\n", NSAC);printf(" 5. TRAN_SPEED = 0x%x (0x32==>25MHz;0x5a==>50MHz)\n", TRAN_SPEED);printf(" 6. CCC = 0x%x\n", CCC);printf(" 7. READ_BL_LEN = %d\n", READ_BL_LEN);printf(" 8. READ_BL_PARTIA = %d\n", READ_BL_PARTIA);printf(" 9. WRITE_BLK_MISALIGN = %d\n", WRITE_BLK_MISALIGN);printf("10. READ_BLK_MISALIGN = %d\n", READ_BLK_MISALIGN);printf("11. DSR_IMP = %d\n", DSR_IMP);printf("12. / *No Use* /\n");printf("13. C_SIZE = %d\n", C_SIZE);printf("14. VDD_R_CURR_MIN = %d\n", VDD_R_CURR_MIN);printf("15. VDD_R_CURR_MAX = %d\n", VDD_R_CURR_MAX);printf("16. VDD_W_CURR_MIN = %d\n", VDD_W_CURR_MIN);printf("17. VDD_W_CURR_MAX = %d\n", VDD_W_CURR_MAX);printf("18. C_SIZE_MULT = %d\t""(本SD卡容量 = %f G)\n", C_SIZE_MULT, (float)C/1073741824);printf("19. ERASE_BLK_EN = 0x%x\n", ERASE_BLK_EN);printf("20. SECTOR_SIZE = 0x%x\n", SECTOR_SIZE);printf("21. WP_GRP_SIZE = 0x%x\n", WP_GRP_SIZE);printf("22. WP_GRP_ENABLE = 0x%x\n", WP_GRP_ENABLE);printf("23. / *No Use* /\n");printf("24. R2W_FACTOR = 0x%x\n", R2W_FACTOR);printf("25. WRITE_BL_LEN = 0x%x\n", WRITE_BL_LEN);printf("26. WRITE_BL_PARTIAL = 0x%x\n", WRITE_BL_PARTIAL);printf("31. TMP_WRITE_PROTECT = 0x%x\n", TMP_WRITE_PROTECT);printf("32. FILE_FORMAT = 0x%x\n", FILE_FORMAT);printf("34. CRC = 0x%x\t", CRC);return 0;}
Eclipse开发调试ARM裸机程序sd卡读 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)