{"id":707,"date":"2023-02-01T19:21:12","date_gmt":"2023-02-01T11:21:12","guid":{"rendered":"http:\/\/www.huangrongzhen.ink\/?p=707"},"modified":"2023-09-15T11:13:20","modified_gmt":"2023-09-15T03:13:20","slug":"%e8%af%bb%e5%86%99%e6%b5%8b%e8%af%95%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/www.huangrongzhen.ink\/?p=707","title":{"rendered":"\u8bfb\u5199\u6d4b\u8bd5\u4ee3\u7801"},"content":{"rendered":"<div class=\"wp-block-post-excerpt\"><p class=\"wp-block-post-excerpt__excerpt\">\u4f7f\u7528\u968f\u673a\u6570\u505a\u8bfb\u5199\u6d4b\u8bd5 <\/p><\/div>\n\n\n<p>\u8fd9\u6bb5\u8bfb\u5199\u6d4b\u8bd5\u4ee3\u7801\u53ef\u4ee5\u5e94\u7528\u4e8e EEPROM\u3001SPI Flash\u3001Nand Flash \u7b49\u5b58\u50a8\u8bbe\u5907\u7684\u8bfb\u5199\u6d4b\u8bd5\uff0c\u5728\u8fd9\u91cc\u505a\u4e00\u4e2a\u603b\u7ed3\uff0c\u907f\u514d\u6bcf\u6b21\u90fd\u91cd\u65b0\u7f16\u5199\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include \"stdio.h\"\n#include \"stdlib.h\"\n\n\/\/\u6d4b\u8bd5\u957f\u5ea6\u5b9a\u4e49\n#define SECTOR_SIZE (2048)\n#define RW_TEST_LEN (SECTOR_SIZE * 10)\n\n\/\/\u4e3b\u51fd\u6570\nvoid main(void)\n{\n  \/\/\u53d8\u91cf\u5b9a\u4e49\n  static unsigned char s_arrWriteBuf[RW_TEST_LEN] = {0};\n  static unsigned char s_arrReadBuf[RW_TEST_LEN] = {0};\n  unsigned int i, error, writeData;\n\n  \/\/\u586b\u5145\u5199\u7f13\u51b2\u533a\n  srand(0);\n  for(i = 0; i &lt; RW_TEST_LEN; i++)\n  {\n    writeData = rand();\n    s_arrWriteBuf[i] = writeData &amp; 0xFF;\n    srand(writeData);\n  }\n\n  \/\/\u5199\u5165\n  FTLWriteSectors(s_arrWriteBuf, 0, FTL_SECTOR_SIZE, RW_TEST_LEN \/ SECTOR_SIZE);\n  \n  \/\/\u8bfb\u53d6\n  FTLReadSectors(s_arrReadBuf, 0, FTL_SECTOR_SIZE, RW_TEST_LEN \/ SECTOR_SIZE);\n\n  \/\/\u6821\u9a8c\n  error = 0;\n  for(i = 0; i &lt; RW_TEST_LEN; i++)\n  {\n    if(s_arrReadBuf[i] != s_arrWriteBuf[i])\n    {\n      error = 1;\n      break;\n    }\n  }\n  \n  \/\/\u8f93\u51fa\u6821\u9a8c\u7ed3\u679c\n  if(1 == error)\n  {\n    printf(\"Fail to check\\r\\n\");\n  }\n  else\n  {\n    printf(\"Check OK\\r\\n\");\n  }\n\n  while(1)\n  {\n\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5bf9\u4e8e FATFS\uff0c\u8bfb\u5199\u6d4b\u8bd5\u4ee3\u7801\u53ef\u4ee5\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"ff.h\"\n\n\/\/\u6d4b\u8bd5\u957f\u5ea6\u5b9a\u4e49\n#define SECTOR_SIZE (2048)\n#define RW_TEST_LEN (SECTOR_SIZE * 10)\n\n\/\/\u4e3b\u51fd\u6570\nvoid main(void)\n{\n  \/\/\u53d8\u91cf\u5b9a\u4e49\n  static FIL s_structFile;\n  FRESULT result;\n  unsigned int readNum, writeNum;\n  static unsigned char s_arrWriteBuf[RW_TEST_LEN] = {0};\n  static unsigned char s_arrReadBuf[RW_TEST_LEN] = {0};\n  unsigned int i, error, writeData;\n  \n  \/\/\u586b\u5145\u5199\u7f13\u51b2\u533a\n  srand(0);\n  for(i = 0; i &lt; RW_TEST_LEN; i++)\n  {\n    writeData = rand();\n    s_arrWriteBuf[i] = writeData &amp; 0xFF;\n    srand(writeData);\n  }\n  \n  \/\/\u521b\u5efa\u6587\u4ef6\uff0c\u5982\u679c\u8be5\u6587\u4ef6\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u8986\u76d6\u8be5\u6587\u4ef6\n  result = f_open(&amp;s_structFile, \"1:\/NandFlashTest.txt\", FA_CREATE_ALWAYS | FA_WRITE);\n  if(FR_OK != result)\n  {\n    printf(\"NandFlasReadWrite: fail to create file\\r\\n\");\n    while(1){}\n  }\n  \n  \/\/\u5199\u5165\u6570\u636e\n  result = f_write(&amp;s_structFile, s_arrWriteBuf, RW_TEST_LEN, &amp;writeNum);\n  if(FR_OK != result)\n  {\n    printf(\"NandFlasReadWrite: fail to write data\\r\\n\");\n    while(1){}\n  }\n  \n  \/\/\u4fdd\u5b58\n  f_close(&amp;s_structFile);\n  \n  \/\/\u6253\u5f00\u6587\u4ef6\n  result = f_open(&amp;s_structFile, \"1:\/NandFlashTest.txt\", FA_READ);\n  if(FR_OK != result)\n  {\n    printf(\"ReadFile: fail to open file\\r\\n\");\n    while(1){}\n  }\n\n  \/\/\u8bfb\u53d6\u6570\u636e\n  result = f_read(&amp;s_structFile, s_arrReadBuf, RW_TEST_LEN, &amp;readNum);\n  if(FR_OK != result)\n  {\n    printf(\"ReadFile: fail to read data from file\\r\\n\");\n    while(1){}\n  }\n\n  \/\/\u5173\u95ed\u6587\u4ef6\n  f_close(&amp;s_structFile);\n  \n  \/\/\u6821\u9a8c\n  error = 0;\n  for(i = 0; i &lt; RW_TEST_LEN; i++)\n  {\n    if(s_arrReadBuf[i] != s_arrWriteBuf[i])\n    {\n      error = 1;\n      break;\n    }\n  }\n  \n  \/\/\u8f93\u51fa\u6821\u9a8c\u7ed3\u679c\n  if(1 == error)\n  {\n    printf(\"Fail to check\\r\\n\");\n  }\n  else\n  {\n    printf(\"Check OK\\r\\n\");\n  }\n\n  while(1)\n  {\n\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u968f\u673a\u6570\u505a\u8bfb\u5199\u6d4b\u8bd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/707"}],"collection":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=707"}],"version-history":[{"count":12,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":1953,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions\/1953"}],"wp:attachment":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}