{"id":61818,"date":"2026-01-18T17:18:10","date_gmt":"2026-01-18T09:18:10","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/61818.html"},"modified":"2026-01-18T17:18:10","modified_gmt":"2026-01-18T09:18:10","slug":"stm32g474vet6%e9%a9%b1%e5%8a%a8sst39vf800a-flash%e6%93%8d%e4%bd%9c%e4%bb%a3%e7%a0%81%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/61818.html","title":{"rendered":"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0"},"content":{"rendered":"<h2>\u901a\u8fc7\u7f51\u76d8\u5206\u4eab\u7684\u6587\u4ef6&#xff1a;STM32G474VET6&#043;NOR FLASH \u9a8c\u8bc1.zip<br \/>\n\u94fe\u63a5: https:\/\/pan.baidu.com\/s\/1323CdUaAsV1m6juSMh9i9g?pwd&#061;pbbn \u63d0\u53d6\u7801: pbbn\u00a0<br \/>\n&#8211;\u6765\u81ea\u767e\u5ea6\u7f51\u76d8\u8d85\u7ea7\u4f1a\u5458v4\u7684\u5206\u4eab<\/h2>\n<h2>CUBE MAX\u914d\u7f6e&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1080\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091808-696ca5502a960.png\" width=\"1920\" \/><\/h2>\n<p>\u672c\u6587\u5c06\u901a\u8fc7\u5206\u6790\u63d0\u4f9b\u7684\u4ee3\u7801\u548c\u6d41\u7a0b\u56fe&#xff0c;\u8be6\u7ec6\u89e3\u91caSTM32\u4e0eSST39VF800A Flash\u5b58\u50a8\u5668\u4e4b\u95f4\u7684\u64cd\u4f5c\u6d41\u7a0b&#xff0c;\u7279\u522b\u662f\u5b57\u7f16\u7a0b\u3001\u6247\u533a\u64e6\u9664\u548c\u8bbe\u5907ID\u8bfb\u53d6\u7684\u5b9e\u73b0\u3002<\/p>\n<p>\u914dFMC\u597d\u540e\u4f60\u5f80BANK\u4e2d\u5730\u5740\u8d4b\u503c&#xff0c;FMC\u4f1a\u81ea\u52a8\u6839\u636e\u5730\u8d28\u4e0e\u6570\u503c\u751f\u6210\u5bf9\u5e94\u4fe1\u53f7\u65f6\u5e8f<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"49\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091808-696ca550ee889.png\" width=\"108\" \/><\/p>\n<p>\u6bd4\u5982&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"181\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55100c84.png\" width=\"398\" \/><\/p>\n<p>\u5c31\u662f&#xff1a;<\/p>\n<p>#define FLASH_WORD_TO_BYTE(addr_word) ((addr_word) &lt;&lt; 1)<\/p>\n<p>*((volatile uint16_t*)(0x60000000 &#043; FLASH_WORD_TO_BYTE(0x2AAA))) &#061; (0x0055);<\/p>\n<h3><span style=\"color:#fe2c24\">\u4e5f\u5c31\u662fFLASH\u5185\u90e8\u4e00\u4e2a\u5730\u5740\u4ee3\u8868stm32\u6620\u5c04\u7684\u4e24\u4e2a\u5730\u5740\u6240\u4ee5\u8981\u4e58\u4ee52<\/span><\/h3>\n<p>\u4ed6\u5c31\u4f1a\u751f\u6210\u5f80\u5730\u57400x00002AAA\u5730\u5740\u8d4b\u503c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"710\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55106e6e.png\" width=\"687\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"630\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca5511fb00.png\" width=\"700\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"644\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55136e38.png\" width=\"715\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"806\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55157010.png\" width=\"662\" \/><\/p>\n<h3>\u4e00\u3001\u6838\u5fc3\u6982\u5ff5&#xff1a;Flash\u547d\u4ee4\u5e8f\u5217<\/h3>\n<p>\u4ece\u6d41\u7a0b\u56fe\u4e2d\u53ef\u4ee5\u770b\u51fa&#xff0c;SST39VF800A\u7684\u6240\u6709\u64cd\u4f5c\u90fd\u9075\u5faa\u547d\u4ee4\u5e8f\u5217\u6a21\u5f0f\u3002\u4e0eRAM\u7684\u7b80\u5355\u8bfb\u5199\u4e0d\u540c&#xff0c;Flash\u9700\u8981\u7279\u5b9a\u7684&#034;\u89e3\u9501-\u547d\u4ee4-\u6570\u636e\/\u5730\u5740&#034;\u5e8f\u5217\u6765\u6267\u884c\u7f16\u7a0b\u3001\u64e6\u9664\u7b49\u64cd\u4f5c\u3002<\/p>\n<h4>\u5173\u952e\u7279\u70b9&#xff1a;<\/h4>\n<li>\n<p>\u4e09\u5468\u671f\u89e3\u9501&#xff1a;\u6240\u6709\u547d\u4ee4\u90fd\u9700\u8981\u5148\u53d1\u9001\u4e24\u4e2a\u89e3\u9501\u5e8f\u5217<\/p>\n<\/li>\n<li>\n<p>\u5730\u5740\/\u6570\u636e\u590d\u7528&#xff1a;\u76f8\u540c\u5730\u5740&#xff08;5555H\/2AAAH&#xff09;\u5728\u4e0d\u540c\u547d\u4ee4\u4e2d\u4f20\u8f93\u4e0d\u540c\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u68c0\u6d4b&#xff1a;\u64cd\u4f5c\u5b8c\u6210\u540e\u9700\u8981\u68c0\u6d4bToggle Bit\u6216Data# Polling<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"710\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55106e6e.png\" width=\"687\" \/><\/p>\n<\/li>\n<h3>\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b0\u4e0e\u6d41\u7a0b\u56fe\u7684\u5bf9\u5e94\u5173\u7cfb<\/h3>\n<h4>1. \u89e3\u9501\u5e8f\u5217\u5b9e\u73b0 (SST_SendUnlockSequence)<\/h4>\n<p>\u6d41\u7a0b\u56fe\u8981\u6c42&#xff1a;<\/p>\n<\/p>\n<p>1. \u5411\u5730\u57405555H\u5199\u5165\u6570\u636e00AAH<br \/>\n2. \u5411\u5730\u57402AAAH\u5199\u5165\u6570\u636e0055H<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0&#xff1a;<\/p>\n<p>static void SST_SendUnlockSequence(void)<br \/>\n{<br \/>\n    \/* First unlock cycle &#8211; \u4f7f\u7528Flash\u5b57\u5730\u5740 *\/<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, SST_CMD_UNLOCK1);  \/\/ 0x5555 -&gt; 0x00AA<\/p>\n<p>    \/* \u5c0f\u5ef6\u65f6\u786e\u4fdd\u547d\u4ee4\u5b8c\u6210 *\/<br \/>\n    Delay_Us(1);<\/p>\n<p>    \/* Second unlock cycle &#8211; \u4f7f\u7528Flash\u5b57\u5730\u5740 *\/<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_2, SST_CMD_UNLOCK2);  \/\/ 0x2AAA -&gt; 0x0055<\/p>\n<p>    \/* \u5c0f\u5ef6\u65f6\u786e\u4fdd\u547d\u4ee4\u5b8c\u6210 *\/<br \/>\n    Delay_Us(1);<br \/>\n}<\/p>\n<p>\u6ce8\u610f&#xff1a;\u4ee3\u7801\u4e2d\u7684\u5730\u5740\u662fFlash\u5b57\u5730\u5740&#xff0c;\u4e0d\u662fSTM32\u7684\u5b57\u8282\u5730\u5740\u3002\u5b8fSST_WRITE_CMD\u5185\u90e8\u4f1a\u5c06\u5b57\u5730\u5740\u8f6c\u6362\u4e3a\u5b57\u8282\u5730\u5740\u3002<\/p>\n<hr \/>\n<h4>2. \u5b57\u7f16\u7a0b\u5b9e\u73b0 (SST_ByteProgram)<\/h4>\n<p>\u56fe18\u6d41\u7a0b&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"710\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55106e6e.png\" width=\"687\" \/><\/p>\n<p>1. \u89e3\u9501\u5e8f\u5217&#xff08;\u524d\u4e24\u6b65&#xff09;<br \/>\n2. \u54115555H\u5199\u5165A0H<br \/>\n3. \u5411\u76ee\u6807\u5730\u5740\u5199\u5165\u6570\u636e<br \/>\n4. \u7b49\u5f85\u64cd\u4f5c\u5b8c\u6210<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0&#xff1a;<\/p>\n<p>static bool SST_ByteProgram(uint32_t address, uint16_t data)<br \/>\n{<br \/>\n    \/* 1-3\u6b65&#xff1a;\u89e3\u9501\u5e8f\u5217 &#043; \u7f16\u7a0b\u547d\u4ee4 *\/<br \/>\n    SST_SendUnlockSequence();                    \/\/ \u89e3\u9501\u6b65\u9aa41-2<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, SST_CMD_PROGRAM);  \/\/ \u6b65\u9aa43: 0x5555 -&gt; 0x00A0<br \/>\n    Delay_Us(1);<\/p>\n<p>    \/* 4\u6b65&#xff1a;\u5411\u76ee\u6807\u5730\u5740\u5199\u5165\u6570\u636e *\/<br \/>\n    NOR_WRITE_BYTE(address, data);               \/\/ \u5199\u5165\u7528\u6237\u6570\u636e<\/p>\n<p>    \/* 5\u6b65&#xff1a;\u7b49\u5f85\u7f16\u7a0b\u5b8c\u6210&#xff08;\u4f7f\u7528Toggle Bit\u6216Data# Polling&#xff09; *\/<br \/>\n    return SST_WaitForOperationComplete(address, data, false);<br \/>\n}<\/p>\n<p>\u91cd\u8981\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>address\u53c2\u6570\u662f\u5b57\u8282\u5730\u5740&#xff0c;\u9700\u8981\u4fdd\u8bc1\u5b57\u5bf9\u9f50&#xff08;\u5076\u6570\u5730\u5740&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5199\u5165\u64cd\u4f5c\u524d\u5fc5\u987b\u786e\u4fdd\u76ee\u6807\u5730\u5740\u5df2\u64e6\u9664&#xff08;\u503c\u4e3a0xFFFF&#xff09;<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>3. \u6247\u533a\u64e6\u9664\u5b9e\u73b0 (SST_SectorErase)<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"806\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55157010.png\" width=\"662\" \/><\/h4>\n<p>\u6839\u636e\u6570\u636e\u624b\u518c\u76846\u5468\u671f\u64e6\u9664\u5e8f\u5217&#xff1a;<\/p>\n<p>1. \u89e3\u9501\u5e8f\u5217&#xff08;5555H-&gt;AAH, 2AAAH-&gt;55H&#xff09;<br \/>\n2. \u518d\u6b21\u54115555H\u5199\u516580H<br \/>\n3. \u518d\u6b21\u89e3\u9501\u5e8f\u5217&#xff08;5555H-&gt;AAH, 2AAAH-&gt;55H&#xff09;<br \/>\n4. \u5411\u6247\u533a\u5730\u5740\u5199\u516530H<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0&#xff1a;<\/p>\n<p>static bool SST_SectorErase(uint32_t sector_address)<br \/>\n{<br \/>\n    \/* \u8f6c\u6362\u4e3aFlash\u5b57\u5730\u5740 *\/<br \/>\n    uint16_t sector_word_addr &#061; FLASH_BYTE_TO_WORD(sector_address) &amp; 0x7FFF;<\/p>\n<p>    \/* 1-2\u6b65&#xff1a;\u89e3\u9501\u5e8f\u5217 &#043; \u64e6\u9664\u8bbe\u7f6e\u547d\u4ee4 *\/<br \/>\n    SST_SendUnlockSequence();                    \/\/ \u6b65\u9aa41-2<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, 0x0080);       \/\/ \u6b65\u9aa43: 5555H -&gt; 80H<br \/>\n    Delay_Us(1);<\/p>\n<p>    \/* 3-4\u6b65&#xff1a;\u518d\u6b21\u89e3\u9501\u5e8f\u5217 &#043; \u6247\u533a\u64e6\u9664\u786e\u8ba4 *\/<br \/>\n    SST_SendUnlockSequence();                    \/\/ \u6b65\u9aa44-5<br \/>\n    NOR_WRITE_BYTE(sector_address, SST_CMD_SECTOR_ERASE);  \/\/ \u6b65\u9aa46: \u6247\u533a\u5730\u5740 -&gt; 30H<\/p>\n<p>    \/* \u7b49\u5f85\u64e6\u9664\u5b8c\u6210 *\/<br \/>\n    return SST_WaitForOperationComplete(sector_address, 0xFFFF, true);<br \/>\n}<\/p>\n<p>\u5173\u952e\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u64e6\u9664\u64cd\u4f5c\u9488\u5bf9\u6574\u4e2a4KB\u6247\u533a<\/p>\n<\/li>\n<li>\n<p>\u5fc5\u987b\u4f7f\u7528\u6247\u533a\u5bf9\u9f50\u7684\u5730\u5740&#xff08;\u5730\u5740\u4f4e12\u4f4d\u4e3a0&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u64e6\u9664\u65f6\u95f4\u8f83\u957f&#xff08;\u6700\u957f25ms&#xff09;&#xff0c;\u9700\u8981\u9002\u5f53\u7b49\u5f85<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>4. \u8bbe\u5907ID\u8bfb\u53d6 (SST_ReadID)<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"644\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091809-696ca55136e38.png\" width=\"715\" \/><\/h4>\n<p>\u56fe20\u8f6f\u4ef6ID\u5165\u53e3\u5e8f\u5217&#xff1a;<\/p>\n<p>1. \u89e3\u9501\u5e8f\u5217&#xff08;5555H-&gt;AAH, 2AAAH-&gt;55H&#xff09;<br \/>\n2. \u54115555H\u5199\u516590H<br \/>\n3. \u8bfb\u53d6\u8bbe\u5907ID<br \/>\n4. \u9000\u51fa\u8f6f\u4ef6ID\u6a21\u5f0f<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0&#xff1a;<\/p>\n<p>static bool SST_ReadID(uint16_t* manufacturer_id, uint16_t* device_id)<br \/>\n{<br \/>\n    \/* 1-2\u6b65&#xff1a;\u89e3\u9501\u5e8f\u5217 &#043; \u8fdb\u5165\u8f6f\u4ef6ID\u6a21\u5f0f *\/<br \/>\n    SST_SendUnlockSequence();                    \/\/ \u89e3\u9501\u5e8f\u5217<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, SST_CMD_AUTOSELECT);  \/\/ 5555H -&gt; 90H<br \/>\n    Delay_Us(10);<\/p>\n<p>    \/* 3\u6b65&#xff1a;\u8bfb\u53d6\u5236\u9020\u5546ID\u548c\u5668\u4ef6ID *\/<br \/>\n    *manufacturer_id &#061; NOR_READ_WORD(0x0000);    \/\/ \u5b57\u5730\u57400000H -&gt; \u5236\u9020\u5546ID<br \/>\n    *device_id &#061; NOR_READ_WORD(0x0001);          \/\/ \u5b57\u5730\u57400001H -&gt; \u5668\u4ef6ID<\/p>\n<p>    \/* 4\u6b65&#xff1a;\u9000\u51fa\u8f6f\u4ef6ID\u6a21\u5f0f *\/<br \/>\n    SST_WRITE_CMD(0x0000, SST_CMD_RESET);        \/\/ \u4efb\u4f55\u5730\u5740\u5199\u5165F0H<br \/>\n    Delay_Us(10);<\/p>\n<p>    return true;<br \/>\n}<\/p>\n<p>ID\u5730\u5740\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5236\u9020\u5546ID&#xff1a;\u4ece\u5b57\u5730\u57400000H\u8bfb\u53d6&#xff08;\u8fd4\u56de0x00BF\u8868\u793aSST&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5668\u4ef6ID&#xff1a;\u4ece\u5b57\u5730\u57400001H\u8bfb\u53d6&#xff08;\u8fd4\u56de0x2781\u8868\u793aSST39VF800A&#xff09;<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e09\u3001\u72b6\u6001\u68c0\u6d4b\u673a\u5236\u8be6\u89e3<\/h3>\n<h4>\u56fe19\u5c55\u793a\u4e86\u4e09\u79cd\u7b49\u5f85\u65b9\u5f0f&#xff1a;<\/h4>\n<p>1. Toggle Bit\u68c0\u6d4b&#xff08;\u4ee3\u7801\u4e2d\u5b9e\u73b0&#xff09;<\/p>\n<p>static bool SST_CheckToggleBit(uint32_t address)<br \/>\n{<br \/>\n    volatile uint16_t* flash_addr &#061; (volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; address);<br \/>\n    uint16_t read1, read2;<\/p>\n<p>    read1 &#061; *flash_addr;    \/\/ \u7b2c\u4e00\u6b21\u8bfb\u53d6<br \/>\n    read2 &#061; *flash_addr;    \/\/ \u7b2c\u4e8c\u6b21\u8bfb\u53d6<\/p>\n<p>    \/* \u68c0\u67e5DQ6\u4f4d\u662f\u5426\u505c\u6b62\u7ffb\u8f6c *\/<br \/>\n    return ((read1 &amp; 0x0040) &#061;&#061; (read2 &amp; 0x0040));<br \/>\n}<\/p>\n<p>\u539f\u7406&#xff1a;\u5728\u7f16\u7a0b\/\u64e6\u9664\u671f\u95f4&#xff0c;DQ6\u4f4d\u4f1a\u4e0d\u65ad\u7ffb\u8f6c\u3002\u5f53\u64cd\u4f5c\u5b8c\u6210\u65f6&#xff0c;DQ6\u505c\u6b62\u7ffb\u8f6c\u3002<\/p>\n<p>2. Data# Polling\u68c0\u6d4b&#xff08;\u4ee3\u7801\u4e2d\u5b9e\u73b0&#xff09;<\/p>\n<p>static bool SST_CheckDataPolling(uint32_t address, uint16_t expected_data)<br \/>\n{<br \/>\n    volatile uint16_t* flash_addr &#061; (volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; address);<br \/>\n    uint16_t read_data;<\/p>\n<p>    read_data &#061; *flash_addr;<\/p>\n<p>    \/* \u68c0\u67e5DQ7\u4f4d\u662f\u5426\u4e0e\u671f\u671b\u6570\u636e\u5339\u914d *\/<br \/>\n    return ((read_data &amp; 0x0080) &#061;&#061; (expected_data &amp; 0x0080));<br \/>\n}<\/p>\n<p>\u539f\u7406&#xff1a;\u5728\u7f16\u7a0b\u671f\u95f4&#xff0c;\u8bfb\u53d6\u7684DQ7\u4f4d\u662f\u88ab\u5199\u5165\u6570\u636e\u7684\u53cd\u7801\u3002\u64cd\u4f5c\u5b8c\u6210\u540e&#xff0c;DQ7\u6062\u590d\u4e3a\u5199\u5165\u6570\u636e\u3002<\/p>\n<p>3. \u5185\u90e8\u5b9a\u65f6\u5668&#xff08;\u672a\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528&#xff09;<\/p>\n<ul>\n<li>\n<p>Flash\u5185\u90e8\u6709\u5b9a\u65f6\u5668\u63a7\u5236\u6700\u5927\u64cd\u4f5c\u65f6\u95f4<\/p>\n<\/li>\n<li>\n<p>\u8d85\u65f6\u540e\u81ea\u52a8\u7ec8\u6b62\u64cd\u4f5c<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u56db\u3001\u4ee3\u7801\u4e2d\u7684\u5173\u952e\u8bbe\u8ba1\u6a21\u5f0f<\/h3>\n<h4>1. \u5730\u5740\u6620\u5c04\u5904\u7406<\/h4>\n<p>\/* \u5c06Flash\u5b57\u5730\u5740\u8f6c\u6362\u4e3aSTM32\u5b57\u8282\u5730\u5740&#xff08;\u5b57\u5730\u5740 \u00d7 2&#xff09;*\/<br \/>\n#define FLASH_WORD_TO_BYTE(addr_word)    ((addr_word) &lt;&lt; 1)<\/p>\n<p>\/* \u5c06Flash\u5b57\u8282\u5730\u5740\u8f6c\u6362\u4e3a\u5b57\u5730\u5740&#xff08;\u5b57\u8282\u5730\u5740 \u00f7 2&#xff09;*\/<br \/>\n#define FLASH_BYTE_TO_WORD(addr_byte)    ((addr_byte) &gt;&gt; 1)<\/p>\n<p>\/* \u57fa\u4e8e\u5b57\u5730\u5740\u7684\u8bbf\u95ee\u5b8f *\/<br \/>\n#define NOR_READ_WORD(addr_word)         (*((volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; FLASH_WORD_TO_BYTE(addr_word))))<\/p>\n<p>\u5e94\u7528\u793a\u4f8b&#xff1a;<\/p>\n<p>\/\/ \u8bfb\u53d6\u5236\u9020\u5546ID&#xff08;\u5b57\u5730\u57400x0000&#xff09;<br \/>\nuint16_t mfr_id &#061; NOR_READ_WORD(0x0000);<br \/>\n\/\/ \u5b9e\u9645\u8bbf\u95ee\u7684STM32\u5730\u5740&#xff1a;0x60000000 &#043; (0x0000 &lt;&lt; 1) &#061; 0x60000000<\/p>\n<h4>2. \u590d\u5408\u7b49\u5f85\u7b56\u7565<\/h4>\n<p>static bool SST_WaitForOperationComplete(uint32_t address, uint16_t expected_data, bool is_erase)<br \/>\n{<br \/>\n    uint32_t timeout_us &#061; is_erase ? SST_ERASE_TIMEOUT_MS * 1000 : SST_PROGRAM_TIMEOUT_US;<\/p>\n<p>    while (elapsed_us &lt; timeout_us) {<br \/>\n        \/* \u5148\u5c1d\u8bd5Toggle Bit\u68c0\u6d4b *\/<br \/>\n        if (SST_CheckToggleBit(address)) {<br \/>\n            \/* \u518d\u4f7f\u7528Data Polling\u9a8c\u8bc1 *\/<br \/>\n            if (SST_CheckDataPolling(address, expected_data)) {<br \/>\n                \/* \u6700\u540e\u53cc\u91cd\u8bfb\u53d6\u786e\u4fdd\u7a33\u5b9a *\/<br \/>\n                uint16_t read1 &#061; *flash_addr;<br \/>\n                uint16_t read2 &#061; *flash_addr;<\/p>\n<p>                if (read1 &#061;&#061; read2) {<br \/>\n                    return true;<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/ &#8230; \u65f6\u95f4\u68c0\u67e5\u548c\u5ef6\u8fdf<br \/>\n    }<br \/>\n    return false; \/* \u8d85\u65f6 *\/<br \/>\n}<\/p>\n<p>\u8bbe\u8ba1\u601d\u60f3&#xff1a;\u7ed3\u5408\u4e24\u79cd\u68c0\u6d4b\u65b9\u6cd5&#xff0c;\u63d0\u9ad8\u53ef\u9760\u6027&#xff0c;\u907f\u514d\u8bef\u5224\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u6d4b\u8bd5\u51fd\u6570\u89e3\u6790<\/h3>\n<h4>1. \u57fa\u7840\u6d4b\u8bd5 (LZY_WRITE_TEST)<\/h4>\n<p>void LZY_WRITE_TEST(uint32_t address, uint16_t data)<br \/>\n{<br \/>\n    \/\/ 1. \u5730\u5740\u8303\u56f4\u68c0\u67e5<br \/>\n    if (address &gt; MAX_MUXED_ADDRESS) { &#8230; }<\/p>\n<p>    \/\/ 2. \u5730\u5740\u5bf9\u9f50\u68c0\u67e5&#xff08;\u5fc5\u987b\u4e3a\u5076\u6570&#xff09;<br \/>\n    if (address &amp; 0x01) { &#8230; }<\/p>\n<p>    \/\/ 3. \u8bfb\u53d6\u5f53\u524d\u503c<br \/>\n    uint16_t current_value &#061; NOR_READ_BYTE(address);<\/p>\n<p>    \/\/ 4. \u5224\u65ad\u662f\u5426\u9700\u8981\u64e6\u9664<br \/>\n    if (current_value &#061;&#061; 0xFFFF) {<br \/>\n        \/\/ \u76f4\u63a5\u7f16\u7a0b<br \/>\n        SST_ByteProgram(address, data);<br \/>\n    } else {<br \/>\n        \/\/ \u5148\u64e6\u9664\u6247\u533a<br \/>\n        uint32_t sector_base &#061; address &amp; ~(NOR_FLASH_SECTOR_SIZE &#8211; 1);<br \/>\n        SST_SectorErase(sector_base);<br \/>\n        SST_ByteProgram(address, data);<br \/>\n    }<\/p>\n<p>    \/\/ 5. \u9a8c\u8bc1\u7ed3\u679c<br \/>\n    uint16_t new_value &#061; NOR_READ_BYTE(address);<br \/>\n    \/\/ \u6bd4\u8f83\u5e76\u8f93\u51fa\u7ed3\u679c<br \/>\n}<\/p>\n<p>\u6d4b\u8bd5\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u68c0\u67e5\u662f\u5426\u5df2\u64e6\u9664&#xff08;\u503c\u4e3a0xFFFF&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u672a\u64e6\u9664\u65f6&#xff0c;\u5fc5\u987b\u5148\u64e6\u9664\u6574\u4e2a\u6247\u533a<\/p>\n<\/li>\n<li>\n<p>\u64e6\u9664\u540e\u7f16\u7a0b&#xff0c;\u5e76\u9a8c\u8bc1\u7ed3\u679c<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u5730\u5740\u7a7a\u95f4\u6d4b\u8bd5 (Test_Full_Address_Range)<\/h4>\n<p>void Test_Full_Address_Range(void)<br \/>\n{<br \/>\n    \/\/ \u6d4b\u8bd5\u4f4e\u5730\u5740<br \/>\n    LZY_WRITE_TEST(0x000000, 0x5555);<br \/>\n    LZY_WRITE_TEST(0x001000, 0xAAAA);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u4e2d\u95f4\u5730\u5740&#xff08;\u6839\u636e\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8ba1\u7b97&#xff09;<br \/>\n    uint32_t middle_addr &#061; MAX_MUXED_ADDRESS \/ 2;<br \/>\n    middle_addr &#061; middle_addr &amp; ~0x01; \/\/ \u786e\u4fdd\u5b57\u5bf9\u9f50<br \/>\n    LZY_WRITE_TEST(middle_addr, 0x1234);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u9ad8\u5730\u5740<br \/>\n    uint32_t high_addr &#061; MAX_MUXED_ADDRESS &#8211; 0x1000;<br \/>\n    high_addr &#061; high_addr &amp; ~0x01; \/\/ \u786e\u4fdd\u5b57\u5bf9\u9f50<br \/>\n    LZY_WRITE_TEST(high_addr, 0x5678);<br \/>\n}<\/p>\n<p>\u6d4b\u8bd5\u7b56\u7565&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8986\u76d6\u4f4e\u3001\u4e2d\u3001\u9ad8\u4e09\u4e2a\u5730\u5740\u533a\u57df<\/p>\n<\/li>\n<li>\n<p>\u8003\u8651\u5730\u5740\u7ebf\u914d\u7f6e\u9650\u5236&#xff08;\u590d\u7528\u6a21\u5f0f&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u786e\u4fdd\u5730\u5740\u5bf9\u9f50<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u516d\u3001\u590d\u7528\u6a21\u5f0f\u4e0b\u7684\u7279\u6b8a\u8003\u8651<\/h3>\n<h4>1. \u5730\u5740\u7ebf\u6570\u91cf\u9650\u5236<\/h4>\n<p>\/* \u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;\u5730\u5740\u901a\u8fc7\u6570\u636e\u7ebf\u4f20\u8f93&#xff0c;\u53d7\u5f15\u811a\u6570\u91cf\u9650\u5236 *\/<br \/>\n#define ADDR_BITS_USED                   19      \/* CubeMX\u4e2d\u914d\u7f6e\u7684\u590d\u7528\u5730\u5740\u7ebf\u6570\u91cf *\/<br \/>\n#define MAX_MUXED_ADDRESS                ((1UL &lt;&lt; ADDR_BITS_USED) &#8211; 1)<\/p>\n<p>\u5f71\u54cd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u914d\u7f6e19\u4f4d\u5730\u5740\u7ebf&#xff0c;\u6700\u5927\u53ef\u8bbf\u95ee\u5730\u5740\u4e3a0x7FFFF&#xff08;524,287\u5b57\u8282&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u4f46SST39VF800A\u5b9e\u9645\u670919\u6761\u5730\u5740\u7ebf&#xff08;A0-A18&#xff09;&#xff0c;\u53ef\u8bbf\u95ee1MB\u7a7a\u95f4<\/p>\n<\/li>\n<li>\n<p>\u5982\u679cSTM32\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u4e0d\u8db3&#xff0c;\u9ad8\u4f4d\u5730\u5740\u4f1a\u56de\u7ed5<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u590d\u7528\u6a21\u5f0f\u8bbf\u95ee<\/h4>\n<p>\/* \u590d\u7528\u6a21\u5f0f\u4e0b\u7684\u5730\u5740\u8bbf\u95ee\u5b8f *\/<br \/>\n#define NOR_READ_BYTE(addr_byte)         (*((volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; (addr_byte))))<\/p>\n<p>\u5de5\u4f5c\u539f\u7406&#xff1a;<\/p>\n<li>\n<p>STM32\u901a\u8fc7FMC\u7684ALE\u4fe1\u53f7\u9501\u5b58\u5730\u5740<\/p>\n<\/li>\n<li>\n<p>\u5730\u5740\u548c\u6570\u636e\u901a\u8fc7\u540c\u4e00\u7ec4\u7ebf\u5206\u65f6\u4f20\u8f93<\/p>\n<\/li>\n<li>\n<p>Flash\u5728ALE\u4e3a\u9ad8\u65f6\u9501\u5b58\u5730\u5740&#xff0c;ALE\u4e3a\u4f4e\u65f6\u8bfb\u5199\u6570\u636e<\/p>\n<\/li>\n<hr \/>\n<h3>\u4e03\u3001\u603b\u7ed3\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<h4>1. \u64cd\u4f5c\u6d41\u7a0b\u603b\u7ed3<\/h4>\n<p>\u4efb\u4f55Flash\u64cd\u4f5c &#061; \u89e3\u9501\u5e8f\u5217 &#043; \u547d\u4ee4 &#043; \u6570\u636e\/\u5730\u5740 &#043; \u72b6\u6001\u68c0\u6d4b<\/p>\n<h4>2. \u5173\u952e\u65f6\u5e8f\u8981\u6c42<\/h4>\n<ul>\n<li>\n<p>\u89e3\u9501\u5e8f\u5217&#xff1a;\u6bcf\u4e2a\u547d\u4ee4\u524d\u5fc5\u987b\u6267\u884c<\/p>\n<\/li>\n<li>\n<p>\u547d\u4ee4\u95f4\u9694&#xff1a;\u9700\u8981\u5fae\u5c0f\u5ef6\u65f6&#xff08;1-10\u03bcs&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u64cd\u4f5c\u8d85\u65f6&#xff1a;\u7f16\u7a0b\u226420\u03bcs&#xff0c;\u6247\u533a\u64e6\u9664\u226425ms<\/p>\n<\/li>\n<\/ul>\n<h4>3. \u8c03\u8bd5\u5efa\u8bae<\/h4>\n<li>\n<p>\u5148\u8bfb\u53d6ID&#xff1a;\u786e\u8ba4\u8bbe\u5907\u8fde\u63a5\u6b63\u786e<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u57fa\u672c\u8bfb\u5199&#xff1a;\u4ece\u4f4e\u5730\u5740\u5f00\u59cb<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u5730\u5740\u6620\u5c04&#xff1a;\u9a8c\u8bc1\u5b57\u5730\u5740\u5230\u5b57\u8282\u5730\u5740\u7684\u8f6c\u6362<\/p>\n<\/li>\n<li>\n<p>\u76d1\u63a7\u72b6\u6001\u4f4d&#xff1a;\u4f7f\u7528Toggle Bit\u6216Data# Polling\u8c03\u8bd5\u64cd\u4f5c\u72b6\u6001<\/p>\n<\/li>\n<h4>4. \u5e38\u89c1\u95ee\u9898\u6392\u67e5<\/h4>\n<ul>\n<li>\n<p>ID\u8bfb\u53d6\u5931\u8d25&#xff1a;\u68c0\u67e5\u786c\u4ef6\u8fde\u63a5\u3001\u65f6\u5e8f\u914d\u7f6e\u3001\u89e3\u9501\u5e8f\u5217<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u5931\u8d25&#xff1a;\u786e\u8ba4\u5730\u5740\u5df2\u64e6\u9664\u3001\u5730\u5740\u5bf9\u9f50\u3001\u8d85\u65f6\u8bbe\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u5730\u5740\u5f02\u5e38&#xff1a;\u68c0\u67e5\u5730\u5740\u7ebf\u914d\u7f6e\u3001\u590d\u7528\u6a21\u5f0f\u8bbe\u7f6e<\/p>\n<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u6df1\u5165\u7406\u89e3\u6d41\u7a0b\u56fe\u548c\u4ee3\u7801\u7684\u5bf9\u5e94\u5173\u7cfb&#xff0c;\u53ef\u4ee5\u66f4\u597d\u5730\u638c\u63e1SST39VF800A Flash\u7684\u64cd\u4f5c\u539f\u7406&#xff0c;\u5e76\u6709\u6548\u5730\u8c03\u8bd5\u548c\u4f18\u5316Flash\u8bbf\u95ee\u4ee3\u7801\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801&#xff1a;<br \/>\n\u00a0<\/p>\n<p>\/* USER CODE BEGIN Header *\/<br \/>\n\/**<br \/>\n  ******************************************************************************<br \/>\n  * &#064;file           : main.c<br \/>\n  * &#064;brief          : Main program body<br \/>\n  ******************************************************************************<br \/>\n  * &#064;attention<br \/>\n  *<br \/>\n  * Copyright (c) 2026 STMicroelectronics.<br \/>\n  * All rights reserved.<br \/>\n  *<br \/>\n  * This software is licensed under terms that can be found in the LICENSE file<br \/>\n  * in the root directory of this software component.<br \/>\n  * If no LICENSE file comes with this software, it is provided AS-IS.<br \/>\n  *<br \/>\n  ******************************************************************************<br \/>\n  *\/<br \/>\n\/* USER CODE END Header *\/<br \/>\n\/* Includes &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;*\/<br \/>\n#include &#034;main.h&#034;<br \/>\n#include &#034;usart.h&#034;<br \/>\n#include &#034;gpio.h&#034;<br \/>\n#include &#034;fmc.h&#034;<\/p>\n<p>\/* Private includes &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-*\/<br \/>\n\/* USER CODE BEGIN Includes *\/<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;stdbool.h&gt;<br \/>\n\/* USER CODE END Includes *\/<\/p>\n<p>\/* Private typedef &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;*\/<br \/>\n\/* USER CODE BEGIN PTD *\/<\/p>\n<p>\/**<br \/>\n  * &#064;brief NOR Flash Test Results Structure<br \/>\n  *\/<br \/>\ntypedef struct {<br \/>\n    bool write_test_passed;<br \/>\n    bool read_id_success;<br \/>\n    bool erase_test_passed;<br \/>\n    uint16_t manufacturer_id;<br \/>\n    uint16_t device_id;<br \/>\n    uint32_t capacity_bytes;<br \/>\n    const char* device_name;<br \/>\n} NOR_Test_Results_t;<\/p>\n<p>\/* USER CODE END PTD *\/<\/p>\n<p>\/* Private define &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;*\/<br \/>\n\/* USER CODE BEGIN PD *\/<\/p>\n<p>\/* NOR Flash Configuration &#8211; SST39VF800A Specific *\/<br \/>\n#define NOR_FLASH_BASE_ADDR              0x60000000UL<br \/>\n#define NOR_FLASH_SIZE_BYTES             (1 * 1024 * 1024)  \/* 8Mbit &#061; 1MB *\/<br \/>\n#define NOR_FLASH_SECTOR_SIZE            (4 * 1024)         \/* 2KWord &#061; 4KB sectors *\/<br \/>\n#define NOR_FLASH_BLOCK_SIZE             (64 * 1024)        \/* 32KWord &#061; 64KB blocks *\/<\/p>\n<p>\/* SST39VF800A Command Addresses (in 16-bit words from datasheet) *\/<br \/>\n#define SST_CMD_ADDR_1                   0x5555             \/* Word address 5555H *\/<br \/>\n#define SST_CMD_ADDR_2                   0x2AAA             \/* Word address 2AAAH *\/<\/p>\n<p>\/* SST39VF800A Command Codes (from Table 4) *\/<br \/>\n#define SST_CMD_UNLOCK1                  0x00AA<br \/>\n#define SST_CMD_UNLOCK2                  0x0055<br \/>\n#define SST_CMD_AUTOSELECT               0x0090<br \/>\n#define SST_CMD_PROGRAM                  0x00A0<br \/>\n#define SST_CMD_CHIP_ERASE_1             0x0080<br \/>\n#define SST_CMD_SECTOR_ERASE             0x0030<br \/>\n#define SST_CMD_RESET                    0x00F0<\/p>\n<p>\/* SST39VF800A Manufacturer and Device IDs (from Table 2) *\/<br \/>\n#define SST_MANUFACTURER_ID              0x00BF<br \/>\n#define SST39VF800A_DEVICE_ID            0x2781<\/p>\n<p>\/* Timing Parameters from datasheet *\/<br \/>\n#define SST_PROGRAM_TIMEOUT_US           20000UL    \/* 20\u03bcs max from Table 17 *\/<br \/>\n#define SST_ERASE_TIMEOUT_MS             100UL      \/* 100ms max for chip erase *\/<br \/>\n#define SST_SECTOR_ERASE_TIMEOUT_MS      25UL       \/* 25ms max for sector erase *\/<\/p>\n<p>\/* \u590d\u7528\u6a21\u5f0f\u4e0b\u7684\u5173\u952e\u5b8f\u5b9a\u4e49 *\/<br \/>\n\/* \u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;\u5730\u5740\u901a\u8fc7\u6570\u636e\u7ebf\u4f20\u8f93&#xff0c;\u9700\u8981ALE\u4fe1\u53f7\u9501\u5b58 *\/<br \/>\n#define ENABLE_ALE_LATCH()               \/\/ \u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;FSMC\u4f1a\u81ea\u52a8\u7ba1\u7406ALE<\/p>\n<p>\/* USER CODE END PD *\/<\/p>\n<p>\/* Private macro &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-*\/<br \/>\n\/* USER CODE BEGIN PM *\/<\/p>\n<p>\/* \u590d\u7528\u6a21\u5f0f\u4e0b\u7684\u5730\u5740\u6620\u5c04 *\/<br \/>\n\/*<br \/>\n * \u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;\u5730\u5740\u548c\u6570\u636e\u5171\u4eab\u540c\u4e00\u7ec4\u7ebf<br \/>\n * STM32\u7684\u5730\u5740\u603b\u7ebf\u662f\u5b57\u8282\u5730\u5740&#xff0c;\u9700\u8981\u8f6c\u6362\u4e3aFlash\u5b57\u5730\u5740<br \/>\n * \u6ce8\u610f&#xff1a;\u5728CubeMX\u4e2d\u914d\u7f6e\u4e3a19\u4f4d\u590d\u7528\u5730\u5740\u7ebf<br \/>\n *\/<br \/>\n#define ADDR_BITS_USED                   19      \/* CubeMX\u4e2d\u914d\u7f6e\u7684\u590d\u7528\u5730\u5740\u7ebf\u6570\u91cf *\/<br \/>\n#define MAX_MUXED_ADDRESS                ((1UL &lt;&lt; ADDR_BITS_USED) &#8211; 1)<\/p>\n<p>\/* \u5c06Flash\u5b57\u5730\u5740\u8f6c\u6362\u4e3aSTM32\u5b57\u8282\u5730\u5740&#xff08;\u5b57\u5730\u5740 \u00d7 2&#xff09;*\/<br \/>\n#define FLASH_WORD_TO_BYTE(addr_word)    ((addr_word) &lt;&lt; 1)<\/p>\n<p>\/* \u5c06Flash\u5b57\u8282\u5730\u5740\u8f6c\u6362\u4e3a\u5b57\u5730\u5740&#xff08;\u5b57\u8282\u5730\u5740 \u00f7 2&#xff09;*\/<br \/>\n#define FLASH_BYTE_TO_WORD(addr_byte)    ((addr_byte) &gt;&gt; 1)<\/p>\n<p>\/* \u590d\u7528\u6a21\u5f0f\u4e0b\u7684\u5730\u5740\u8bbf\u95ee\u5b8f *\/<br \/>\n\/*<br \/>\n * \u91cd\u8981&#xff1a;\u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;FSMC\u4f1a\u81ea\u52a8\u5904\u7406\u5730\u5740\/\u6570\u636e\u590d\u7528<br \/>\n * \u6211\u4eec\u53ea\u9700\u8981\u63d0\u4f9b\u5b57\u8282\u5730\u5740&#xff0c;FSMC\u4f1a\u901a\u8fc7ALE\u4fe1\u53f7\u9501\u5b58\u5730\u5740<br \/>\n * \u7136\u540e\u901a\u8fc7\u540c\u4e00\u7ec4\u7ebf\u4f20\u8f93\u6570\u636e<br \/>\n *\/<br \/>\n#define NOR_READ_BYTE(addr_byte)         (*((volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; (addr_byte))))<br \/>\n#define NOR_WRITE_BYTE(addr_byte, data)  (*((volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; (addr_byte))) &#061; (data))<\/p>\n<p>\/* \u57fa\u4e8eFlash\u5b57\u5730\u5740\u7684\u8bbf\u95ee\u5b8f *\/<br \/>\n#define NOR_READ_WORD(addr_word)         (*((volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; FLASH_WORD_TO_BYTE(addr_word))))<br \/>\n#define NOR_WRITE_WORD(addr_word, data)  (*((volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; FLASH_WORD_TO_BYTE(addr_word))) &#061; (data))<\/p>\n<p>\/* \u547d\u4ee4\u5199\u5165\u5b8f &#8211; \u4f7f\u7528Flash\u5b57\u5730\u5740 *\/<br \/>\n#define SST_WRITE_CMD(addr_word, data)   \\\\<br \/>\n    NOR_WRITE_WORD(addr_word, data)<\/p>\n<p>\/* USER CODE END PM *\/<\/p>\n<p>\/* Private variables &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;*\/<\/p>\n<p>\/* USER CODE BEGIN PV *\/<\/p>\n<p>\/* USER CODE END PV *\/<\/p>\n<p>\/* Private function prototypes &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;*\/<br \/>\nvoid SystemClock_Config(void);<br \/>\n\/* USER CODE BEGIN PFP *\/<\/p>\n<p>\/* SST39VF800A Specific Functions *\/<br \/>\nstatic bool SST_ReadID(uint16_t* manufacturer_id, uint16_t* device_id);<br \/>\nstatic bool SST_SectorErase(uint32_t sector_address);<br \/>\nstatic bool SST_ByteProgram(uint32_t address, uint16_t data);<br \/>\nstatic bool SST_CheckToggleBit(uint32_t address);<br \/>\nstatic bool SST_CheckDataPolling(uint32_t address, uint16_t expected_data);<br \/>\nstatic bool SST_WaitForOperationComplete(uint32_t address, uint16_t expected_data, bool is_erase);<br \/>\nstatic void SST_SendUnlockSequence(void);<br \/>\nstatic void Delay_Us(volatile uint32_t microseconds);<\/p>\n<p>\/* LZY Test Functions *\/<br \/>\nvoid LZY_NOR_Init(void);<br \/>\nvoid LZY_NOR_DisplayInfo(void);<br \/>\nvoid LZY_WRITE_TEST(uint32_t address, uint16_t data);<br \/>\nvoid Test_Full_Address_Range(void);<br \/>\nvoid Verify_Address_Mapping(void);<br \/>\nvoid Test_Muxed_Mode_Compatibility(void);<\/p>\n<p>\/* USER CODE END PFP *\/<\/p>\n<p>\/* Private user code &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;*\/<br \/>\n\/* USER CODE BEGIN 0 *\/<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Delay for specified microseconds (approximate)<br \/>\n  * &#064;param  microseconds: Number of microseconds to delay<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nstatic void Delay_Us(volatile uint32_t microseconds)<br \/>\n{<br \/>\n    \/* Assuming 85MHz system clock, 1us \u2248 85 cycles *\/<br \/>\n    volatile uint32_t cycles &#061; microseconds * 85;<br \/>\n    while (cycles&#8211;) {<br \/>\n        __NOP();<br \/>\n    }<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Send unlock sequence (common for all commands)<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nstatic void SST_SendUnlockSequence(void)<br \/>\n{<br \/>\n    \/* \u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;FSMC\u4f1a\u81ea\u52a8\u901a\u8fc7ALE\u9501\u5b58\u5730\u5740&#xff0c;\u7136\u540e\u4f20\u8f93\u6570\u636e *\/<\/p>\n<p>    \/* First unlock cycle &#8211; \u4f7f\u7528Flash\u5b57\u5730\u5740 *\/<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, SST_CMD_UNLOCK1);<\/p>\n<p>    \/* \u5c0f\u5ef6\u65f6\u786e\u4fdd\u547d\u4ee4\u5b8c\u6210 *\/<br \/>\n    Delay_Us(1);<\/p>\n<p>    \/* Second unlock cycle &#8211; \u4f7f\u7528Flash\u5b57\u5730\u5740 *\/<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_2, SST_CMD_UNLOCK2);<\/p>\n<p>    \/* \u5c0f\u5ef6\u65f6\u786e\u4fdd\u547d\u4ee4\u5b8c\u6210 *\/<br \/>\n    Delay_Us(1);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Check Toggle Bit (DQ6) status<br \/>\n  * &#064;param  address: \u5b57\u8282\u5730\u5740 to check<br \/>\n  * &#064;retval true if ready (stopped toggling), false if still busy<br \/>\n  *\/<br \/>\nstatic bool SST_CheckToggleBit(uint32_t address)<br \/>\n{<br \/>\n    volatile uint16_t* flash_addr &#061; (volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; address);<br \/>\n    uint16_t read1, read2;<\/p>\n<p>    \/* Read twice to check for toggling *\/<br \/>\n    read1 &#061; *flash_addr;<br \/>\n    read2 &#061; *flash_addr;<\/p>\n<p>    \/* If DQ6 stops toggling, device is ready *\/<br \/>\n    return ((read1 &amp; 0x0040) &#061;&#061; (read2 &amp; 0x0040));<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Check Data Polling (DQ7) status<br \/>\n  * &#064;param  address: \u5b57\u8282\u5730\u5740 to check<br \/>\n  * &#064;param  expected_data: Expected data value<br \/>\n  * &#064;retval true if ready (DQ7 matches), false if still busy<br \/>\n  *\/<br \/>\nstatic bool SST_CheckDataPolling(uint32_t address, uint16_t expected_data)<br \/>\n{<br \/>\n    volatile uint16_t* flash_addr &#061; (volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; address);<br \/>\n    uint16_t read_data;<\/p>\n<p>    read_data &#061; *flash_addr;<\/p>\n<p>    \/* Check DQ7 (bit 7) *\/<br \/>\n    return ((read_data &amp; 0x0080) &#061;&#061; (expected_data &amp; 0x0080));<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Wait for operation to complete using both methods<br \/>\n  * &#064;param  address: \u5b57\u8282\u5730\u5740 to monitor<br \/>\n  * &#064;param  expected_data: Expected data (for programming) or 0xFFFF (for erase)<br \/>\n  * &#064;param  is_erase: true if waiting for erase, false for program<br \/>\n  * &#064;retval true if operation completed, false if timeout<br \/>\n  *\/<br \/>\nstatic bool SST_WaitForOperationComplete(uint32_t address, uint16_t expected_data, bool is_erase)<br \/>\n{<br \/>\n    uint32_t timeout_us &#061; is_erase ? SST_ERASE_TIMEOUT_MS * 1000 : SST_PROGRAM_TIMEOUT_US;<br \/>\n    uint32_t start_time &#061; HAL_GetTick();<br \/>\n    uint32_t elapsed_us &#061; 0;<\/p>\n<p>    while (elapsed_us &lt; timeout_us) {<br \/>\n        \/* Try toggle bit first *\/<br \/>\n        if (SST_CheckToggleBit(address)) {<br \/>\n            \/* Then verify with data polling *\/<br \/>\n            if (SST_CheckDataPolling(address, expected_data)) {<br \/>\n                \/* Double-check by reading twice more as per datasheet *\/<br \/>\n                volatile uint16_t* flash_addr &#061; (volatile uint16_t*)(NOR_FLASH_BASE_ADDR &#043; address);<br \/>\n                uint16_t read1 &#061; *flash_addr;<br \/>\n                uint16_t read2 &#061; *flash_addr;<\/p>\n<p>                if (read1 &#061;&#061; read2) {<br \/>\n                    return true;<br \/>\n                }<br \/>\n            }<br \/>\n        }<\/p>\n<p>        \/* Update elapsed time *\/<br \/>\n        elapsed_us &#061; (HAL_GetTick() &#8211; start_time) * 1000;<br \/>\n        Delay_Us(10); \/* Small delay between checks *\/<br \/>\n    }<\/p>\n<p>    return false; \/* Timeout *\/<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Erase a 4KB sector in SST39VF800A<br \/>\n  * &#064;param  sector_address: Sector \u5b57\u8282\u5730\u5740 (must be sector aligned)<br \/>\n  * &#064;retval true if successful, false otherwise<br \/>\n  *\/<br \/>\nstatic bool SST_SectorErase(uint32_t sector_address)<br \/>\n{<br \/>\n    \/* Convert byte address to word address for command *\/<br \/>\n    uint16_t sector_word_addr &#061; FLASH_BYTE_TO_WORD(sector_address) &amp; 0x7FFF; \/* A14-A0 for 8Mbit device *\/<\/p>\n<p>    \/* Sector-Erase Command Sequence (6 cycles) from Table 4 *\/<br \/>\n    \/* First 3 cycles: Unlock sequence *\/<br \/>\n    SST_SendUnlockSequence();<\/p>\n<p>    \/* Fourth cycle: Setup erase command *\/<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, 0x0080);<br \/>\n    Delay_Us(1);<\/p>\n<p>    \/* Fifth and sixth cycles: Unlock sequence again *\/<br \/>\n    SST_SendUnlockSequence();<\/p>\n<p>    \/* Seventh cycle: Sector address and erase confirm *\/<br \/>\n    NOR_WRITE_BYTE(sector_address, SST_CMD_SECTOR_ERASE);<\/p>\n<p>    \/* Wait for erase completion *\/<br \/>\n    return SST_WaitForOperationComplete(sector_address, 0xFFFF, true);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Program a single word (16-bit) in SST39VF800A<br \/>\n  * &#064;param  address: \u5b57\u8282\u5730\u5740 to program (must be word-aligned)<br \/>\n  * &#064;param  data: Data to program<br \/>\n  * &#064;retval true if successful, false otherwise<br \/>\n  *\/<br \/>\nstatic bool SST_ByteProgram(uint32_t address, uint16_t data)<br \/>\n{<br \/>\n    \/* Word-Program Command Sequence (4 cycles) from Table 4 *\/<br \/>\n    \/* First 3 cycles: Unlock sequence *\/<br \/>\n    SST_SendUnlockSequence();<\/p>\n<p>    \/* Fourth cycle: Program command and data *\/<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, SST_CMD_PROGRAM);<br \/>\n    Delay_Us(1);<\/p>\n<p>    \/* Write the data to the target address *\/<br \/>\n    NOR_WRITE_BYTE(address, data);<\/p>\n<p>    \/* Wait for programming completion *\/<br \/>\n    return SST_WaitForOperationComplete(address, data, false);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  Read SST39VF800A Manufacturer and Device ID<br \/>\n  * &#064;param  manufacturer_id: Pointer to store manufacturer ID<br \/>\n  * &#064;param  device_id: Pointer to store device ID<br \/>\n  * &#064;retval true if successful, false otherwise<br \/>\n  *\/<br \/>\nstatic bool SST_ReadID(uint16_t* manufacturer_id, uint16_t* device_id)<br \/>\n{<br \/>\n    \/* Software ID Entry Command Sequence (3 cycles) *\/<br \/>\n    SST_SendUnlockSequence();<br \/>\n    SST_WRITE_CMD(SST_CMD_ADDR_1, SST_CMD_AUTOSELECT);<br \/>\n    Delay_Us(10);<\/p>\n<p>    \/* Read Manufacturer ID (at word address 0000H, A0&#061;0) *\/<br \/>\n    *manufacturer_id &#061; NOR_READ_WORD(0x0000);<\/p>\n<p>    \/* Read Device ID (at word address 0001H, A0&#061;1) *\/<br \/>\n    *device_id &#061; NOR_READ_WORD(0x0001);<\/p>\n<p>    \/* Exit Software ID mode *\/<br \/>\n    SST_WRITE_CMD(0x0000, SST_CMD_RESET);<br \/>\n    Delay_Us(10);<\/p>\n<p>    return true;<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  \u6d4b\u8bd5\u590d\u7528\u6a21\u5f0f\u517c\u5bb9\u6027<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid Test_Muxed_Mode_Compatibility(void)<br \/>\n{<br \/>\n    printf(&#034;&#061;&#061;&#061; \u6d4b\u8bd5\u590d\u7528\u6a21\u5f0f\u517c\u5bb9\u6027 &#061;&#061;&#061;\\\\n&#034;);<\/p>\n<p>    \/\/ \u68c0\u67e5CubeMX\u914d\u7f6e<br \/>\n    printf(&#034;1. CubeMX\u914d\u7f6e\u68c0\u67e5:\\\\n&#034;);<br \/>\n    printf(&#034;   &#8211; Memory type: Muxed NOR Flash\\\\n&#034;);<br \/>\n    printf(&#034;   &#8211; Data\/Address: %d bits\\\\n&#034;, ADDR_BITS_USED);<br \/>\n    printf(&#034;   &#8211; \u7406\u8bba\u6700\u5927\u5730\u5740: 0x%06lX\\\\n&#034;, MAX_MUXED_ADDRESS);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u5730\u5740\u7ebf\u662f\u5426\u5de5\u4f5c<br \/>\n    printf(&#034;\\\\n2. \u5730\u5740\u7ebf\u6d4b\u8bd5:\\\\n&#034;);<\/p>\n<p>    uint32_t test_addresses[] &#061; {<br \/>\n        0x000000,  \/\/ \u5730\u5740\u7ebf\u51680<br \/>\n        0x000002,  \/\/ A0&#061;1<br \/>\n        0x000004,  \/\/ A1&#061;1<br \/>\n        0x000008,  \/\/ A2&#061;1<br \/>\n        0x000010,  \/\/ A3&#061;1<br \/>\n        0x000020,  \/\/ A4&#061;1<br \/>\n        0x000040,  \/\/ A5&#061;1<br \/>\n        0x000080,  \/\/ A6&#061;1<br \/>\n        0x000100,  \/\/ A7&#061;1<br \/>\n        0x000200,  \/\/ A8&#061;1<br \/>\n        0x000400,  \/\/ A9&#061;1<br \/>\n        0x000800,  \/\/ A10&#061;1<br \/>\n        0x001000,  \/\/ A11&#061;1<br \/>\n        0x002000,  \/\/ A12&#061;1<br \/>\n        0x004000,  \/\/ A13&#061;1<br \/>\n        0x008000,  \/\/ A14&#061;1<br \/>\n        0x010000,  \/\/ A15&#061;1<br \/>\n        0x020000,  \/\/ A16&#061;1<br \/>\n        0x040000,  \/\/ A17&#061;1<br \/>\n        0x080000,  \/\/ A18&#061;1 (\u6700\u9ad8\u4f4d)<br \/>\n    };<\/p>\n<p>    bool all_passed &#061; true;<br \/>\n    for (int i &#061; 0; i &lt; sizeof(test_addresses)\/sizeof(test_addresses[0]); i&#043;&#043;) {<br \/>\n        uint32_t addr &#061; test_addresses[i];<\/p>\n<p>        if (addr &gt; MAX_MUXED_ADDRESS) {<br \/>\n            printf(&#034;   \u5730\u5740 0x%06lX: \u8d85\u51fa\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4\\\\n&#034;, addr);<br \/>\n            continue;<br \/>\n        }<\/p>\n<p>        \/\/ \u5c1d\u8bd5\u8bfb\u53d6\u8be5\u5730\u5740<br \/>\n        uint16_t value &#061; NOR_READ_BYTE(addr);<\/p>\n<p>        printf(&#034;   \u5730\u5740 0x%06lX (A%d): \u8bfb\u53d6\u503c 0x%04X&#034;,<br \/>\n               addr, i, value);<\/p>\n<p>        \/\/ \u68c0\u67e5\u662f\u5426\u5730\u5740\u56de\u7ed5<br \/>\n        if (addr &gt;&#061; NOR_FLASH_SIZE_BYTES) {<br \/>\n            printf(&#034; [\u8b66\u544a&#xff1a;\u8d85\u51faFlash\u7269\u7406\u8303\u56f4]\\\\n&#034;);<br \/>\n        } else {<br \/>\n            printf(&#034;\\\\n&#034;);<br \/>\n        }<\/p>\n<p>        \/\/ \u5982\u679c\u662f\u64e6\u9664\u72b6\u6001&#xff0c;\u53ef\u80fd\u662f\u6709\u6548\u7684<br \/>\n        if (value !&#061; 0xFFFF &amp;&amp; value !&#061; 0x0000) {<br \/>\n            printf(&#034;      \u6ce8\u610f&#xff1a;\u8bfb\u53d6\u5230\u975e\u9ed8\u8ba4\u503c&#xff0c;\u53ef\u80fd\u5df2\u7f16\u7a0b\\\\n&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u9ad8\u4f4d\u5730\u5740\u56de\u7ed5<br \/>\n    printf(&#034;\\\\n3. \u9ad8\u4f4d\u5730\u5740\u56de\u7ed5\u6d4b\u8bd5:\\\\n&#034;);<\/p>\n<p>    uint32_t wrap_test_addrs[] &#061; {<br \/>\n        0x100000,  \/\/ 1MB\u4f4d\u7f6e&#xff08;\u5982\u679c\u53ea\u670919\u4f4d\u5730\u5740\u7ebf&#xff0c;\u4f1a\u56de\u7ed5\u52300x000000&#xff09;<br \/>\n        0x200000,  \/\/ 2MB\u4f4d\u7f6e<br \/>\n        0x300000,  \/\/ 3MB\u4f4d\u7f6e<br \/>\n    };<\/p>\n<p>    for (int i &#061; 0; i &lt; sizeof(wrap_test_addrs)\/sizeof(wrap_test_addrs[0]); i&#043;&#043;) {<br \/>\n        uint32_t addr &#061; wrap_test_addrs[i];<br \/>\n        uint16_t value &#061; NOR_READ_BYTE(addr);<\/p>\n<p>        printf(&#034;   \u9ad8\u4f4d\u5730\u5740 0x%06lX: \u8bfb\u53d6\u503c 0x%04X&#034;, addr, value);<\/p>\n<p>        \/\/ \u8ba1\u7b97\u56de\u7ed5\u5730\u5740<br \/>\n        uint32_t wrapped_addr &#061; addr &amp; MAX_MUXED_ADDRESS;<br \/>\n        printf(&#034; (\u56de\u7ed5\u5230 0x%06lX)\\\\n&#034;, wrapped_addr);<br \/>\n    }<\/p>\n<p>    printf(&#034;\\\\n4. \u590d\u7528\u6a21\u5f0f\u7279\u5b9a\u6d4b\u8bd5:\\\\n&#034;);<\/p>\n<p>    \/\/ \u68c0\u67e5ALE\u5f15\u811a\u662f\u5426\u914d\u7f6e<br \/>\n    #ifdef FMC_Bank1_ALE_ENABLE<br \/>\n        printf(&#034;   ALE\u5f15\u811a\u5df2\u542f\u7528 (\u590d\u7528\u6a21\u5f0f)\\\\n&#034;);<\/p>\n<p>        \/\/ \u6d4b\u8bd5\u8fde\u7eed\u8bbf\u95ee\u6a21\u5f0f<br \/>\n        printf(&#034;   \u6d4b\u8bd5\u8fde\u7eed\u8bbf\u95ee&#8230;\\\\n&#034;);<br \/>\n        volatile uint16_t* base_ptr &#061; (volatile uint16_t*)NOR_FLASH_BASE_ADDR;<\/p>\n<p>        \/\/ \u8fde\u7eed\u8bfb\u53d6\u591a\u4e2a\u5730\u5740<br \/>\n        for (int i &#061; 0; i &lt; 10; i&#043;&#043;) {<br \/>\n            uint32_t offset &#061; i * 0x1000;<br \/>\n            if (offset &gt; MAX_MUXED_ADDRESS) break;<\/p>\n<p>            uint16_t val &#061; base_ptr[offset \/ 2]; \/\/ \u9664\u4ee52\u56e0\u4e3a\u662f\u6307\u9488\u504f\u79fb<br \/>\n            printf(&#034;     \u504f\u79fb 0x%04X: 0x%04X\\\\n&#034;, offset, val);<br \/>\n        }<br \/>\n    #else<br \/>\n        printf(&#034;   \u8b66\u544a&#xff1a;ALE\u5f15\u811a\u672a\u542f\u7528&#xff0c;\u53ef\u80fd\u4e0d\u662f\u771f\u6b63\u7684\u590d\u7528\u6a21\u5f0f\\\\n&#034;);<br \/>\n    #endif<\/p>\n<p>    printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  \u9a8c\u8bc1\u5730\u5740\u6620\u5c04\u7684\u6b63\u786e\u6027<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid Verify_Address_Mapping(void)<br \/>\n{<br \/>\n    printf(&#034;&#061;&#061;&#061; \u9a8c\u8bc1\u5730\u5740\u6620\u5c04 &#061;&#061;&#061;\\\\n&#034;);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u51e0\u4e2a\u5173\u952e\u5730\u5740<br \/>\n    uint32_t test_offsets[] &#061; {<br \/>\n        0x000000,      \/\/ \u8d77\u59cb\u5730\u5740<br \/>\n        0x07FFFE,      \/\/ \u7b2c\u4e00\u4e2a\u6247\u533a\u672b\u5c3e&#xff08;4KB\u5bf9\u9f50&#xff09;<br \/>\n        0x3FFFFE,      \/\/ 19\u4f4d\u5730\u5740\u7ebf\u7684\u6700\u5927\u5730\u5740&#xff08;\u5982\u679c\u914d\u7f6e\u4e3a19\u4f4d&#xff09;<br \/>\n        0x0FFFFE,      \/\/ 1MB Flash\u7684\u6700\u5927\u5730\u5740<br \/>\n    };<\/p>\n<p>    for (int i &#061; 0; i &lt; sizeof(test_offsets)\/sizeof(test_offsets[0]); i&#043;&#043;) {<br \/>\n        uint32_t byte_offset &#061; test_offsets[i];<br \/>\n        uint32_t word_offset &#061; FLASH_BYTE_TO_WORD(byte_offset);<\/p>\n<p>        printf(&#034;\u5b57\u8282\u504f\u79fb: 0x%06lX, \u5b57\u504f\u79fb: 0x%06lX\\\\n&#034;,<br \/>\n               byte_offset, word_offset);<\/p>\n<p>        \/\/ \u5c1d\u8bd5\u8bfb\u53d6<br \/>\n        uint16_t value &#061; NOR_READ_BYTE(byte_offset);<\/p>\n<p>        printf(&#034;  \u8bfb\u53d6\u503c: 0x%04X&#034;, value);<\/p>\n<p>        \/\/ \u68c0\u67e5\u662f\u5426\u8d85\u51fa\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4<br \/>\n        if (byte_offset &gt; MAX_MUXED_ADDRESS) {<br \/>\n            printf(&#034; [\u8d85\u51fa\u914d\u7f6e\u7684%d\u4f4d\u5730\u5740\u7ebf\u8303\u56f4]&#034;, ADDR_BITS_USED);<br \/>\n        }<\/p>\n<p>        \/\/ \u68c0\u67e5\u662f\u5426\u5730\u5740\u56de\u7ed5<br \/>\n        if (byte_offset &gt;&#061; NOR_FLASH_SIZE_BYTES) {<br \/>\n            printf(&#034; [\u8b66\u544a&#xff1a;\u8d85\u51faFlash\u7269\u7406\u8303\u56f4&#xff01;]\\\\n&#034;);<br \/>\n        } else {<br \/>\n            printf(&#034;\\\\n&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  LZY NOR Flash \u521d\u59cb\u5316<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid LZY_NOR_Init(void)<br \/>\n{<br \/>\n    uint16_t manufacturer_id, device_id;<\/p>\n<p>    printf(&#034;&#061;&#061;&#061; SST39VF800A Flash Init &#061;&#061;&#061;\\\\n&#034;);<\/p>\n<p>    \/\/ \u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;\u8bfb\u53d6ID\u53ef\u80fd\u9700\u8981\u7279\u6b8a\u5904\u7406<br \/>\n    printf(&#034;\u6a21\u5f0f&#xff1a;\u590d\u7528\u6a21\u5f0f (Muxed Mode)\\\\n&#034;);<br \/>\n    printf(&#034;\u914d\u7f6e\u5730\u5740\u7ebf&#xff1a;%d bits\\\\n&#034;, ADDR_BITS_USED);<\/p>\n<p>    if (SST_ReadID(&amp;manufacturer_id, &amp;device_id)) {<br \/>\n        printf(&#034;Manufacturer: 0x%04X\\\\n&#034;, manufacturer_id);<br \/>\n        printf(&#034;Device ID: 0x%04X\\\\n&#034;, device_id);<\/p>\n<p>        if (manufacturer_id &#061;&#061; SST_MANUFACTURER_ID &amp;&amp; device_id &#061;&#061; SST39VF800A_DEVICE_ID) {<br \/>\n            printf(&#034;Device: SST39VF800A 8Mbit (1MB)\\\\n&#034;);<br \/>\n            printf(&#034;\u72b6\u6001&#xff1a;\u8bbe\u5907\u8bc6\u522b\u6210\u529f&#xff01;\\\\n&#034;);<br \/>\n        } else {<br \/>\n            printf(&#034;Unknown device!\\\\n&#034;);<br \/>\n            printf(&#034;\u53ef\u80fd\u7684\u539f\u56e0&#xff1a;\\\\n&#034;);<br \/>\n            printf(&#034;  1. \u590d\u7528\u6a21\u5f0f\u914d\u7f6e\u4e0d\u6b63\u786e\\\\n&#034;);<br \/>\n            printf(&#034;  2. \u786c\u4ef6\u8fde\u63a5\u95ee\u9898\\\\n&#034;);<br \/>\n            printf(&#034;  3. \u65f6\u5e8f\u914d\u7f6e\u4e0d\u5f53\\\\n&#034;);<br \/>\n        }<br \/>\n    } else {<br \/>\n        printf(&#034;Device not found!\\\\n&#034;);<br \/>\n        printf(&#034;\u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;\u53ef\u80fd\u9700\u8981\u68c0\u67e5&#xff1a;\\\\n&#034;);<br \/>\n        printf(&#034;  1. ALE\u4fe1\u53f7\u662f\u5426\u6b63\u786e\u8fde\u63a5\\\\n&#034;);<br \/>\n        printf(&#034;  2. \u65f6\u5e8f\u914d\u7f6e\u662f\u5426\u5339\u914dFlash\u8981\u6c42\\\\n&#034;);<br \/>\n        printf(&#034;  3. \u786c\u4ef6\u8fde\u63a5\u662f\u5426\u6b63\u786e\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    printf(&#034;Base Address: 0x%08lX\\\\n&#034;, NOR_FLASH_BASE_ADDR);<br \/>\n    printf(&#034;Sector Size: %d bytes\\\\n&#034;, NOR_FLASH_SECTOR_SIZE);<br \/>\n    printf(&#034;Total Size: %d bytes (1MB)\\\\n&#034;, NOR_FLASH_SIZE_BYTES);<br \/>\n    printf(&#034;\u914d\u7f6e\u5730\u5740\u7ebf&#xff1a;%d bits (\u6700\u5927\u5730\u5740: 0x%06lX)\\\\n&#034;,<br \/>\n           ADDR_BITS_USED, MAX_MUXED_ADDRESS);<br \/>\n    printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  LZY NOR Flash \u663e\u793a\u4fe1\u606f<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid LZY_NOR_DisplayInfo(void)<br \/>\n{<br \/>\n    printf(&#034;&#061;&#061;&#061; SST39VF800A Info &#061;&#061;&#061;\\\\n&#034;);<br \/>\n    printf(&#034;Capacity: 1MB (8Mbit)\\\\n&#034;);<br \/>\n    printf(&#034;Organization: 512K x 16-bit\\\\n&#034;);<br \/>\n    printf(&#034;Sector Size: 4KB\\\\n&#034;);<br \/>\n    printf(&#034;Block Size: 64KB\\\\n&#034;);<br \/>\n    printf(&#034;Voltage: 2.7-3.6V (3.3V typical)\\\\n&#034;);<br \/>\n    printf(&#034;Address Lines: A0-A18 (19\u6761)\\\\n&#034;);<br \/>\n    printf(&#034;Data Bus: 16-bit\\\\n&#034;);<br \/>\n    printf(&#034;Interface: \u975e\u590d\u7528\u6a21\u5f0f (\u4f46STM32\u914d\u7f6e\u4e3a\u590d\u7528)\\\\n&#034;);<br \/>\n    printf(&#034;\u6ce8\u610f\u4e8b\u9879&#xff1a;\\\\n&#034;);<br \/>\n    printf(&#034;  &#8211; STM32\u914d\u7f6e\u4e3a\u590d\u7528\u6a21\u5f0f\\\\n&#034;);<br \/>\n    printf(&#034;  &#8211; \u9700\u8981\u5916\u90e8\u5730\u5740\u9501\u5b58\u5668\u6216\u7279\u6b8a\u786c\u4ef6\u8bbe\u8ba1\\\\n&#034;);<br \/>\n    printf(&#034;  &#8211; \u5730\u5740\u7ebf\u914d\u7f6e&#xff1a;%d bits\\\\n&#034;, ADDR_BITS_USED);<br \/>\n    printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief  LZY Flash \u5199\u5165\u6d4b\u8bd5\u51fd\u6570<br \/>\n  * &#064;param  address: \u8981\u5199\u5165\u7684\u5b57\u8282\u5730\u5740<br \/>\n  * &#064;param  data: \u8981\u5199\u5165\u7684\u6570\u636e&#xff08;16\u4f4d&#xff09;<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid LZY_WRITE_TEST(uint32_t address, uint16_t data)<br \/>\n{<br \/>\n    \/\/ \u68c0\u67e5\u5730\u5740\u662f\u5426\u8d85\u51fa\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4<br \/>\n    if (address &gt; MAX_MUXED_ADDRESS) {<br \/>\n        printf(&#034;\u9519\u8bef&#xff1a;\u5730\u5740 0x%08lX \u8d85\u51fa\u914d\u7f6e\u7684%d\u4f4d\u5730\u5740\u7ebf\u8303\u56f4&#xff01;\\\\n&#034;,<br \/>\n               NOR_FLASH_BASE_ADDR &#043; address, ADDR_BITS_USED);<br \/>\n        printf(&#034;\u6700\u5927\u53ef\u8bbf\u95ee\u5730\u5740&#xff1a;0x%06lX\\\\n&#034;, MAX_MUXED_ADDRESS);<br \/>\n        return;<br \/>\n    }<\/p>\n<p>    \/\/ \u786e\u4fdd\u5730\u5740\u662f\u5b57\u5bf9\u9f50\u7684&#xff08;\u5076\u6570\u5730\u5740&#xff09;<br \/>\n    if (address &amp; 0x01) {<br \/>\n        printf(&#034;\u9519\u8bef&#xff1a;\u5730\u5740\u5fc5\u987b\u5b57\u5bf9\u9f50&#xff01;0x%08lX\\\\n&#034;, NOR_FLASH_BASE_ADDR &#043; address);<br \/>\n        return;<br \/>\n    }<\/p>\n<p>    uint16_t current_value &#061; NOR_READ_BYTE(address);<\/p>\n<p>    printf(&#034;Addr: 0x%08lX, Current: 0x%04X -&gt; &#034;,<br \/>\n           NOR_FLASH_BASE_ADDR &#043; address, current_value);<\/p>\n<p>    \/* \u5982\u679c\u8981\u5199\u5165\u6570\u636e&#xff0c;\u5fc5\u987b\u5148\u68c0\u67e5\u662f\u5426\u5df2\u64e6\u9664 *\/<br \/>\n    if (current_value &#061;&#061; 0xFFFF) {<br \/>\n        \/* \u4f4d\u7f6e\u5df2\u64e6\u9664&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u7f16\u7a0b *\/<br \/>\n        if (SST_ByteProgram(address, data)) {<br \/>\n            printf(&#034;Write 0x%04X OK&#034;, data);<br \/>\n        } else {<br \/>\n            printf(&#034;Write FAIL!&#034;);<br \/>\n        }<br \/>\n    } else {<br \/>\n        \/* \u5fc5\u987b\u5148\u64e6\u9664\u6574\u4e2a\u6247\u533a *\/<br \/>\n        uint32_t sector_base &#061; address &amp; ~(NOR_FLASH_SECTOR_SIZE &#8211; 1);<\/p>\n<p>        printf(&#034;Erasing sector 0x%08lX&#8230; &#034;, NOR_FLASH_BASE_ADDR &#043; sector_base);<\/p>\n<p>        if (SST_SectorErase(sector_base)) {<br \/>\n            printf(&#034;Erased, &#034;);<br \/>\n            if (SST_ByteProgram(address, data)) {<br \/>\n                printf(&#034;Write 0x%04X OK&#034;, data);<br \/>\n            } else {<br \/>\n                printf(&#034;Write FAIL!&#034;);<br \/>\n            }<br \/>\n        } else {<br \/>\n            printf(&#034;Erase FAIL!&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/* \u91cd\u65b0\u8bfb\u53d6\u9a8c\u8bc1 *\/<br \/>\n    uint16_t new_value &#061; NOR_READ_BYTE(address);<br \/>\n    printf(&#034;, Read: 0x%04X %s\\\\n&#034;,<br \/>\n           new_value,<br \/>\n           (new_value &#061;&#061; data) ? &#034;[OK]&#034; : &#034;[FAIL]&#034;);<br \/>\n}<\/p>\n<p>\/**<br \/>\n  * &#064;brief \u6d4b\u8bd5\u5b8c\u6574\u5730\u5740\u7a7a\u95f4<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid Test_Full_Address_Range(void)<br \/>\n{<br \/>\n    printf(&#034;&#061;&#061;&#061; \u6d4b\u8bd5\u5b8c\u6574\u5730\u5740\u7a7a\u95f4 &#061;&#061;&#061;\\\\n&#034;);<\/p>\n<p>    \/\/ \u6ce8\u610f&#xff1a;\u5728\u590d\u7528\u6a21\u5f0f\u4e0b&#xff0c;\u6211\u4eec\u53ea\u80fd\u6d4b\u8bd5\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4\u5185\u7684\u5730\u5740<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u4f4e\u5730\u5740<br \/>\n    printf(&#034;1. \u6d4b\u8bd5\u4f4e\u5730\u5740\u533a\u57df:\\\\n&#034;);<br \/>\n    LZY_WRITE_TEST(0x000000, 0x5555);<br \/>\n    LZY_WRITE_TEST(0x001000, 0xAAAA);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u4e2d\u95f4\u5730\u5740<br \/>\n    printf(&#034;\\\\n2. \u6d4b\u8bd5\u4e2d\u95f4\u5730\u5740\u533a\u57df:\\\\n&#034;);<\/p>\n<p>    \/\/ \u6839\u636e\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u6570\u91cf\u786e\u5b9a\u4e2d\u95f4\u5730\u5740<br \/>\n    uint32_t middle_addr &#061; MAX_MUXED_ADDRESS \/ 2;<br \/>\n    middle_addr &#061; middle_addr &amp; ~0x01; \/\/ \u786e\u4fdd\u5b57\u5bf9\u9f50<\/p>\n<p>    if (middle_addr &lt; NOR_FLASH_SIZE_BYTES) {<br \/>\n        LZY_WRITE_TEST(middle_addr, 0x1234);<br \/>\n    } else {<br \/>\n        printf(&#034;\u4e2d\u95f4\u5730\u5740\u8d85\u51faFlash\u8303\u56f4&#xff0c;\u8df3\u8fc7\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u9ad8\u5730\u5740&#xff08;\u5728\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4\u5185&#xff09;<br \/>\n    printf(&#034;\\\\n3. \u6d4b\u8bd5\u9ad8\u5730\u5740\u533a\u57df:\\\\n&#034;);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u63a5\u8fd1\u6700\u5927\u914d\u7f6e\u5730\u5740\u7684\u4f4d\u7f6e<br \/>\n    uint32_t high_addr &#061; MAX_MUXED_ADDRESS &#8211; 0x1000;<br \/>\n    high_addr &#061; high_addr &amp; ~0x01; \/\/ \u786e\u4fdd\u5b57\u5bf9\u9f50<\/p>\n<p>    if (high_addr &lt; NOR_FLASH_SIZE_BYTES) {<br \/>\n        LZY_WRITE_TEST(high_addr, 0x5678);<br \/>\n    } else {<br \/>\n        printf(&#034;\u9ad8\u5730\u5740\u8d85\u51faFlash\u8303\u56f4&#xff0c;\u8df3\u8fc7\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u8fb9\u754c\u6761\u4ef6<br \/>\n    printf(&#034;\\\\n4. \u6d4b\u8bd5\u8fb9\u754c\u6761\u4ef6:\\\\n&#034;);<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u63a5\u8fd119\u4f4d\u5730\u5740\u7ebf\u6700\u5927\u5730\u5740\u7684\u4f4d\u7f6e<br \/>\n    uint32_t boundary_addr &#061; MAX_MUXED_ADDRESS &#8211; 0x20;<br \/>\n    boundary_addr &#061; boundary_addr &amp; ~0x01; \/\/ \u786e\u4fdd\u5b57\u5bf9\u9f50<\/p>\n<p>    if (boundary_addr &lt; NOR_FLASH_SIZE_BYTES) {<br \/>\n        LZY_WRITE_TEST(boundary_addr, 0x9ABC);<br \/>\n    } else {<br \/>\n        printf(&#034;\u8fb9\u754c\u5730\u5740\u8d85\u51faFlash\u8303\u56f4&#xff0c;\u8df3\u8fc7\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/* USER CODE END 0 *\/<\/p>\n<p>\/**<br \/>\n  * &#064;brief  The application entry point.<br \/>\n  * &#064;retval int<br \/>\n  *\/<br \/>\nint main(void)<br \/>\n{<br \/>\n  \/* MCU Configuration&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;*\/<br \/>\n  HAL_Init();<br \/>\n  SystemClock_Config();<\/p>\n<p>  \/* Initialize all configured peripherals *\/<br \/>\n  MX_GPIO_Init();<br \/>\n  MX_FMC_Init();<br \/>\n  MX_USART1_UART_Init();<\/p>\n<p>  \/* USER CODE BEGIN 2 *\/<\/p>\n<p>    \/* \u7cfb\u7edf\u4fe1\u606f *\/<br \/>\n    printf(&#034;\\\\nSTM32 &#043; SST39VF800A Flash Test\\\\n&#034;);<br \/>\n    printf(&#034;\u6a21\u5f0f&#xff1a;\u590d\u7528\u6a21\u5f0f (Muxed Mode)\\\\n&#034;);<br \/>\n    printf(&#034;\u914d\u7f6e\u5730\u5740\u7ebf&#xff1a;%d bits\\\\n&#034;, ADDR_BITS_USED);<br \/>\n    printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<\/p>\n<p>    \/* \u6d4b\u8bd5\u590d\u7528\u6a21\u5f0f\u517c\u5bb9\u6027 *\/<br \/>\n    Test_Muxed_Mode_Compatibility();<\/p>\n<p>    \/* \u521d\u59cb\u5316NOR Flash *\/<br \/>\n    LZY_NOR_Init();<\/p>\n<p>    \/* \u9a8c\u8bc1\u5730\u5740\u6620\u5c04 *\/<br \/>\n    Verify_Address_Mapping();<\/p>\n<p>    \/* \u663e\u793a\u8bbe\u5907\u4fe1\u606f *\/<br \/>\n    LZY_NOR_DisplayInfo();<\/p>\n<p>    \/* \u6d4b\u8bd5\u5b8c\u6574\u5730\u5740\u7a7a\u95f4&#xff08;\u5728\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4\u5185&#xff09; *\/<br \/>\n    Test_Full_Address_Range();<\/p>\n<p>    \/* \u521d\u59cb\u6d4b\u8bd5 *\/<br \/>\n    printf(&#034;&#061;&#061;&#061; \u521d\u59cb\u6d4b\u8bd5 &#061;&#061;&#061;\\\\n&#034;);<br \/>\n    LZY_WRITE_TEST(0x1000, 0x5555);  \/\/ \u6d4b\u8bd5\u5730\u57400x1000&#xff0c;\u5199\u51650x5555<br \/>\n    LZY_WRITE_TEST(0x2000, 0xAAAA);  \/\/ \u6d4b\u8bd5\u5730\u57400x2000&#xff0c;\u5199\u51650xAAAA<\/p>\n<p>  \/* USER CODE END 2 *\/<\/p>\n<p>  \/* Infinite loop *\/<br \/>\n  \/* USER CODE BEGIN WHILE *\/<br \/>\n  while (1)<br \/>\n  {<br \/>\n    \/* \u5faa\u73af\u6d4b\u8bd5\u4e0d\u540c\u7684\u5730\u5740\u548c\u6570\u636e *\/<br \/>\n    static uint32_t test_count &#061; 0;<\/p>\n<p>    \/\/ \u5728\u914d\u7f6e\u7684\u5730\u5740\u7ebf\u8303\u56f4\u5185\u5faa\u73af\u6d4b\u8bd5<br \/>\n    uint32_t max_test_addr &#061; MAX_MUXED_ADDRESS;<br \/>\n    if (max_test_addr &gt; NOR_FLASH_SIZE_BYTES &#8211; 2) {<br \/>\n        max_test_addr &#061; NOR_FLASH_SIZE_BYTES &#8211; 2;<br \/>\n    }<\/p>\n<p>    \/\/ \u751f\u6210\u6d4b\u8bd5\u5730\u5740&#xff08;\u5728\u5b89\u5168\u8303\u56f4\u5185&#xff09;<br \/>\n    uint32_t base_addr &#061; 0x1000 &#043; (test_count % 8) * 0x1000;<\/p>\n<p>    \/\/ \u786e\u4fdd\u5730\u5740\u5728\u8303\u56f4\u5185<br \/>\n    if (base_addr &gt; max_test_addr) {<br \/>\n        base_addr &#061; max_test_addr &#8211; 0x8000; \/\/ \u56de\u9000\u5230\u4e00\u4e2a\u5b89\u5168\u5730\u5740<br \/>\n    }<\/p>\n<p>    base_addr &#061; base_addr &amp; ~0x01; \/\/ \u786e\u4fdd\u5b57\u5bf9\u9f50<\/p>\n<p>    uint16_t test_data &#061; 0x1234 &#043; test_count * 0x1111;<\/p>\n<p>    printf(&#034;Test #%lu: &#034;, test_count);<br \/>\n    LZY_WRITE_TEST(base_addr, test_data);<\/p>\n<p>    test_count&#043;&#043;;<br \/>\n    HAL_Delay(2000);  \/\/ \u6bcf2\u79d2\u6d4b\u8bd5\u4e00\u6b21<\/p>\n<p>    \/\/ \u6bcf10\u6b21\u6d4b\u8bd5\u6253\u5370\u4e00\u6b21\u72b6\u6001<br \/>\n    if (test_count % 10 &#061;&#061; 0) {<br \/>\n        printf(&#034;\\\\n&#061;&#061;&#061; \u6d4b\u8bd5\u7edf\u8ba1 &#061;&#061;&#061;\\\\n&#034;);<br \/>\n        printf(&#034;\u5df2\u6267\u884c\u6d4b\u8bd5\u6b21\u6570: %lu\\\\n&#034;, test_count);<br \/>\n        printf(&#034;\u5f53\u524d\u6700\u5927\u53ef\u8bbf\u95ee\u5730\u5740: 0x%06lX\\\\n&#034;, max_test_addr);<br \/>\n        printf(&#034;\u914d\u7f6e\u5730\u5740\u7ebf: %d bits\\\\n&#034;, ADDR_BITS_USED);<br \/>\n        printf(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\\\\n\\\\n&#034;);<br \/>\n    }<br \/>\n  }<br \/>\n  \/* USER CODE END 3 *\/<br \/>\n}<\/p>\n<p>\/* \u5176\u4ed6\u51fd\u6570\u4fdd\u6301\u4e0d\u53d8&#8230; *\/<\/p>\n<p>\/* USER CODE BEGIN 4 *\/<\/p>\n<p>\/* USER CODE END 4 *\/<\/p>\n<p>\/**<br \/>\n  * &#064;brief System Clock Configuration<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid SystemClock_Config(void)<br \/>\n{<br \/>\n  RCC_OscInitTypeDef RCC_OscInitStruct &#061; {0};<br \/>\n  RCC_ClkInitTypeDef RCC_ClkInitStruct &#061; {0};<\/p>\n<p>  \/** Configure the main internal regulator output voltage<br \/>\n  *\/<br \/>\n  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);<\/p>\n<p>  \/** Initializes the RCC Oscillators according to the specified parameters<br \/>\n  * in the RCC_OscInitTypeDef structure.<br \/>\n  *\/<br \/>\n  RCC_OscInitStruct.OscillatorType &#061; RCC_OSCILLATORTYPE_HSE;<br \/>\n  RCC_OscInitStruct.HSEState &#061; RCC_HSE_ON;<br \/>\n  RCC_OscInitStruct.PLL.PLLState &#061; RCC_PLL_ON;<br \/>\n  RCC_OscInitStruct.PLL.PLLSource &#061; RCC_PLLSOURCE_HSE;<br \/>\n  RCC_OscInitStruct.PLL.PLLM &#061; RCC_PLLM_DIV2;<br \/>\n  RCC_OscInitStruct.PLL.PLLN &#061; 85;<br \/>\n  RCC_OscInitStruct.PLL.PLLP &#061; RCC_PLLP_DIV2;<br \/>\n  RCC_OscInitStruct.PLL.PLLQ &#061; RCC_PLLQ_DIV2;<br \/>\n  RCC_OscInitStruct.PLL.PLLR &#061; RCC_PLLR_DIV2;<br \/>\n  if (HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) !&#061; HAL_OK)<br \/>\n  {<br \/>\n    Error_Handler();<br \/>\n  }<\/p>\n<p>  \/** Initializes the CPU, AHB and APB buses clocks<br \/>\n  *\/<br \/>\n  RCC_ClkInitStruct.ClockType &#061; RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK<br \/>\n                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;<br \/>\n  RCC_ClkInitStruct.SYSCLKSource &#061; RCC_SYSCLKSOURCE_PLLCLK;<br \/>\n  RCC_ClkInitStruct.AHBCLKDivider &#061; RCC_SYSCLK_DIV1;<br \/>\n  RCC_ClkInitStruct.APB1CLKDivider &#061; RCC_HCLK_DIV1;<br \/>\n  RCC_ClkInitStruct.APB2CLKDivider &#061; RCC_HCLK_DIV1;<\/p>\n<p>  if (HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_4) !&#061; HAL_OK)<br \/>\n  {<br \/>\n    Error_Handler();<br \/>\n  }<br \/>\n}<\/p>\n<p>\/* USER CODE BEGIN 4 *\/<\/p>\n<p>\/* USER CODE END 4 *\/<\/p>\n<p>\/**<br \/>\n  * &#064;brief  This function is executed in case of error occurrence.<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid Error_Handler(void)<br \/>\n{<br \/>\n  \/* USER CODE BEGIN Error_Handler_Debug *\/<br \/>\n    printf(&#034;\\\\n[ERROR] Error_Handler called! System halted.\\\\n&#034;);<br \/>\n    __disable_irq();<br \/>\n    while (1)<br \/>\n    {<br \/>\n        \/\/ Flash LED rapidly to indicate error<br \/>\n        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_0);<br \/>\n        HAL_Delay(100);<br \/>\n    }<br \/>\n  \/* USER CODE END Error_Handler_Debug *\/<br \/>\n}<br \/>\n#ifdef USE_FULL_ASSERT<br \/>\n\/**<br \/>\n  * &#064;brief  Reports the name of the source file and the source line number<br \/>\n  *         where the assert_param error has occurred.<br \/>\n  * &#064;param  file: pointer to the source file name<br \/>\n  * &#064;param  line: assert_param error line source number<br \/>\n  * &#064;retval None<br \/>\n  *\/<br \/>\nvoid assert_failed(uint8_t *file, uint32_t line)<br \/>\n{<br \/>\n  \/* USER CODE BEGIN 6 *\/<br \/>\n    printf(&#034;[ERROR] Assert failed: file %s, line %d\\\\n&#034;, file, (int)line);<br \/>\n  \/* USER CODE END 6 *\/<br \/>\n}<br \/>\n#endif \/* USE_FULL_ASSERT *\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u7f51\u76d8\u5206\u4eab\u7684\u6587\u4ef6&#xff1a;STM32G474VET6NOR FLASH \u9a8c\u8bc1.zip<br \/>\n\u94fe\u63a5: https:\/\/pan.baidu.com\/s\/1323CdUaAsV1m6juSMh9i9g?pwdpbbn \u63d0\u53d6\u7801: pbbn\u00a0<br \/>\n&#8211;\u6765\u81ea\u767e\u5ea6\u7f51\u76d8\u8d85\u7ea7\u4f1a\u5458v4\u7684\u5206\u4eabCUBE MAX\u914d\u7f6e&#xff1a;\u672c\u6587\u5c06\u901a\u8fc7\u5206\u6790\u63d0\u4f9b\u7684\u4ee3\u7801\u548c\u6d41\u7a0b\u56fe&#xff0c;\u8be6\u7ec6\u89e3\u91caSTM32\u4e0eSST39VF800A Flash\u5b58\u50a8\u5668\u4e4b\u95f4\u7684\u64cd\u4f5c\u6d41\u7a0b&#xff0c;\u7279\u522b\u662f\u5b57\u7f16\u7a0b\u3001\u6247\u533a\u64e6\u9664\u548c\u8bbe\u5907ID\u8bfb\u53d6<\/p>\n","protected":false},"author":2,"featured_media":61811,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[87,78],"topic":[],"class_list":["post-61818","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-87","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/61818.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u901a\u8fc7\u7f51\u76d8\u5206\u4eab\u7684\u6587\u4ef6&#xff1a;STM32G474VET6NOR FLASH \u9a8c\u8bc1.zip \u94fe\u63a5: https:\/\/pan.baidu.com\/s\/1323CdUaAsV1m6juSMh9i9g?pwdpbbn \u63d0\u53d6\u7801: pbbn\u00a0 --\u6765\u81ea\u767e\u5ea6\u7f51\u76d8\u8d85\u7ea7\u4f1a\u5458v4\u7684\u5206\u4eabCUBE MAX\u914d\u7f6e&#xff1a;\u672c\u6587\u5c06\u901a\u8fc7\u5206\u6790\u63d0\u4f9b\u7684\u4ee3\u7801\u548c\u6d41\u7a0b\u56fe&#xff0c;\u8be6\u7ec6\u89e3\u91caSTM32\u4e0eSST39VF800A Flash\u5b58\u50a8\u5668\u4e4b\u95f4\u7684\u64cd\u4f5c\u6d41\u7a0b&#xff0c;\u7279\u522b\u662f\u5b57\u7f16\u7a0b\u3001\u6247\u533a\u64e6\u9664\u548c\u8bbe\u5907ID\u8bfb\u53d6\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/61818.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-18T09:18:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091808-696ca5502a960.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61818.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/61818.html\",\"name\":\"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-18T09:18:10+00:00\",\"dateModified\":\"2026-01-18T09:18:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/61818.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/61818.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61818.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/61818.html","og_locale":"zh_CN","og_type":"article","og_title":"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u901a\u8fc7\u7f51\u76d8\u5206\u4eab\u7684\u6587\u4ef6&#xff1a;STM32G474VET6NOR FLASH \u9a8c\u8bc1.zip \u94fe\u63a5: https:\/\/pan.baidu.com\/s\/1323CdUaAsV1m6juSMh9i9g?pwdpbbn \u63d0\u53d6\u7801: pbbn\u00a0 --\u6765\u81ea\u767e\u5ea6\u7f51\u76d8\u8d85\u7ea7\u4f1a\u5458v4\u7684\u5206\u4eabCUBE MAX\u914d\u7f6e&#xff1a;\u672c\u6587\u5c06\u901a\u8fc7\u5206\u6790\u63d0\u4f9b\u7684\u4ee3\u7801\u548c\u6d41\u7a0b\u56fe&#xff0c;\u8be6\u7ec6\u89e3\u91caSTM32\u4e0eSST39VF800A Flash\u5b58\u50a8\u5668\u4e4b\u95f4\u7684\u64cd\u4f5c\u6d41\u7a0b&#xff0c;\u7279\u522b\u662f\u5b57\u7f16\u7a0b\u3001\u6247\u533a\u64e6\u9664\u548c\u8bbe\u5907ID\u8bfb\u53d6","og_url":"https:\/\/www.wsisp.com\/helps\/61818.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-18T09:18:10+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260118091808-696ca5502a960.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"19 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/61818.html","url":"https:\/\/www.wsisp.com\/helps\/61818.html","name":"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-18T09:18:10+00:00","dateModified":"2026-01-18T09:18:10+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/61818.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/61818.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/61818.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"STM32G474VET6\u9a71\u52a8SST39VF800A Flash\u64cd\u4f5c\u4ee3\u7801\u5b9e\u73b0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=61818"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61818\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/61811"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=61818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=61818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=61818"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=61818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}