Files
MicrochipFor32/Doc/docbook/bsp__flash_8c_source.xml

64 lines
13 KiB
XML
Raw Normal View History

2022-11-24 23:56:57 +08:00
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="_bsp__flash_8c_source" xml:lang="zh">
<title>bsp_flash.c</title>
<indexterm><primary>D:/gitt/MicrochipFor32/bsp_Device/bsp_flash.c</primary></indexterm>
浏览该文件的文档.<programlisting linenumbering="unnumbered"><anchor xml:id="_bsp__flash_8c_source_1l00001"/>00001 <emphasis role="comment">/*----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00002"/>00002 <emphasis role="comment">&#32;#</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00003"/>00003 <emphasis role="comment">&#32;#&#32;&#32;Copyright&#32;(c)&#32;2022&#32;Yuankang&#32;Liang(XerolySkinner)</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00004"/>00004 <emphasis role="comment">&#32;#</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00005"/>00005 <emphasis role="comment">&#32;#&#32;&#32;本软件按原样提供,无任何明示或暗示</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00006"/>00006 <emphasis role="comment">&#32;#&#32;&#32;在任何情况下,作者都不承担任何损害赔偿责任</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00007"/>00007 <emphasis role="comment">&#32;#</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00008"/>00008 <emphasis role="comment">&#32;#&#32;&#32;使用的许可声明:</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00009"/>00009 <emphasis role="comment">&#32;#&#32;&#32;1.&#32;&#32;不得歪曲本软件的来源,你不能声称你编写了原始软件.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00010"/>00010 <emphasis role="comment">&#32;#&#32;&#32;2.&#32;&#32;免费授予以任何目的,前提是版权声明出现在所有副本中.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00011"/>00011 <emphasis role="comment">&#32;#&#32;&#32;&#32;&#32;&#32;&#32;并且版权声明和许可声明同时出现.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00012"/>00012 <emphasis role="comment">&#32;#&#32;&#32;3.&#32;&#32;你有使用,复制,修改,分发,和销售本软件的许可.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00013"/>00013 <emphasis role="comment">&#32;#&#32;&#32;4.&#32;&#32;如果你在产品中使用,产品文档中的声明是赞赏的但不是必须的.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00014"/>00014 <emphasis role="comment">&#32;#&#32;&#32;5.&#32;&#32;本通知不得从任何来源删除或更改.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00015"/>00015 <emphasis role="comment">&#32;#</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00016"/>00016 <emphasis role="comment">&#32;#&#32;&#32;Yuankang&#32;Liang(XerolySkinner)</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00017"/>00017 <emphasis role="comment">&#32;#&#32;&#32;&#32;&#32;&#32;&#32;E-mail:zabbcccbbaz@163.com</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00018"/>00018 <emphasis role="comment">&#32;#&#32;&#32;&#32;&#32;&#32;&#32;QQ:2715099320</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00019"/>00019 <emphasis role="comment">&#32;#&#32;&#32;&#32;&#32;&#32;&#32;Mobile&#32;Phone:13005636215</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00020"/>00020 <emphasis role="comment">&#32;#</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00021"/>00021 <emphasis role="comment">&#32;#&#32;&#32;All&#32;rights&#32;reserved.</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00022"/>00022 <emphasis role="comment">&#32;*/</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00023"/>00023
<anchor xml:id="_bsp__flash_8c_source_1l00035"/>00035 <emphasis role="preprocessor">#include&#32;&quot;main.h&quot;</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00036"/><link linkend="_bsp__flash_8c_1a37cd1b57193a374f9a86b6cf1277cd0a">00036</link> uint32_t&#32;<link linkend="_bsp__flash_8c_1a37cd1b57193a374f9a86b6cf1277cd0a">FlashAddr</link>&#32;=&#32;0x08010000;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;
<anchor xml:id="_bsp__flash_8c_source_1l00037"/>00037 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00038"/>00038 <emphasis role="preprocessor">#pragma&#32;pack(4)</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00043"/><link linkend="_structstruct__bsp___flash___pack">00043</link> <emphasis role="keyword">struct&#32;</emphasis><link linkend="_structstruct__bsp___flash___pack">struct_bsp_Flash_Pack</link>{
<anchor xml:id="_bsp__flash_8c_source_1l00044"/><link linkend="_structstruct__bsp___flash___pack_1aea6e531775263f158f23d2295f759dd7">00044</link> &#32;&#32;&#32;&#32;<emphasis role="keywordtype">char</emphasis>&#32;&#32;&#32;&#32;<link linkend="_structstruct__bsp___flash___pack_1aea6e531775263f158f23d2295f759dd7">Var0</link>;
<anchor xml:id="_bsp__flash_8c_source_1l00045"/><link linkend="_structstruct__bsp___flash___pack_1aff73ebf1f2eaf5930d7187aa5f502075">00045</link> &#32;&#32;&#32;&#32;<emphasis role="keywordtype">short</emphasis>&#32;&#32;&#32;<link linkend="_structstruct__bsp___flash___pack_1aff73ebf1f2eaf5930d7187aa5f502075">Var1</link>;
<anchor xml:id="_bsp__flash_8c_source_1l00046"/><link linkend="_structstruct__bsp___flash___pack_1adc2edcdadc2b2be3d18334cd196e049c">00046</link> &#32;&#32;&#32;&#32;<emphasis role="keywordtype">int</emphasis>&#32;&#32;&#32;&#32;&#32;<link linkend="_structstruct__bsp___flash___pack_1adc2edcdadc2b2be3d18334cd196e049c">Var2</link>;
<anchor xml:id="_bsp__flash_8c_source_1l00047"/><link linkend="_bsp__flash_8c_1a2c0639c4d50bba3762a4295a56a06af8">00047</link> }<link linkend="_bsp__flash_8c_1a2c0639c4d50bba3762a4295a56a06af8">bsp_Flash_Pack</link>={0,0,0};
<anchor xml:id="_bsp__flash_8c_source_1l00048"/>00048 <emphasis role="preprocessor">#pragma&#32;pack()</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00049"/>00049 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00056"/><link linkend="_bsp__flash_8c_1af1304997d797af3400074bdb68e5de1c">00056</link> <emphasis role="comment"></emphasis>uint32_t&#32;<link linkend="_bsp__flash_8c_1af1304997d797af3400074bdb68e5de1c">bsp_WriteFlashOnePage</link>(uint32_t&#32;*dat,uint32_t&#32;num){
<anchor xml:id="_bsp__flash_8c_source_1l00057"/>00057 &#32;&#32;&#32;&#32;FLASH_EraseInitTypeDef&#32;f;
<anchor xml:id="_bsp__flash_8c_source_1l00058"/>00058 &#32;&#32;&#32;&#32;uint32_t&#32;PageError&#32;=&#32;0;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//错误号7</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00059"/>00059 &#32;&#32;&#32;&#32;HAL_FLASH_Unlock();&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//解锁FLASH</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00060"/>00060 &#32;&#32;&#32;&#32;f.TypeErase&#32;=&#32;FLASH_TYPEERASE_PAGES;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//Flash擦除</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00061"/>00061 &#32;&#32;&#32;&#32;f.PageAddress&#32;=&#32;<link linkend="_bsp__flash_8c_1a37cd1b57193a374f9a86b6cf1277cd0a">FlashAddr</link>;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//擦除地址(起始页)</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00062"/>00062 &#32;&#32;&#32;&#32;f.NbPages&#32;=&#32;1;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//擦除1页</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00063"/>00063 &#32;&#32;&#32;&#32;HAL_FLASHEx_Erase(&amp;f,&amp;PageError);&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//调用擦除函数</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00064"/>00064 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">for</emphasis>(<emphasis role="keywordtype">int</emphasis>&#32;i=0;i&lt;num;i++)
<anchor xml:id="_bsp__flash_8c_source_1l00065"/>00065 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;HAL_FLASH_Program(TYPEPROGRAM_WORD,<link linkend="_bsp__flash_8c_1a37cd1b57193a374f9a86b6cf1277cd0a">FlashAddr</link>+i*4,dat[i]);&#32;&#32;&#32;<emphasis role="comment">//对FLASH烧写</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00066"/>00066 &#32;&#32;&#32;&#32;HAL_FLASH_Lock();&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//锁住FLASH</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00067"/>00067 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;PageError;}
<anchor xml:id="_bsp__flash_8c_source_1l00068"/>00068 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00075"/><link linkend="_bsp__flash_8c_1a734a679e19a8af2c7ddfa86f4310a13d">00075</link> <emphasis role="comment"></emphasis><emphasis role="keywordtype">void</emphasis>&#32;<link linkend="_bsp__flash_8c_1a734a679e19a8af2c7ddfa86f4310a13d">bsp_ReadFlash</link>(uint32_t&#32;*dat,uint32_t&#32;num){&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//读入一串数据</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00076"/>00076 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">for</emphasis>(<emphasis role="keywordtype">int</emphasis>&#32;i=0;i&lt;num;i++)
<anchor xml:id="_bsp__flash_8c_source_1l00077"/>00077 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;dat[i]=*(__IO&#32;uint32_t*)(<link linkend="_bsp__flash_8c_1a37cd1b57193a374f9a86b6cf1277cd0a">FlashAddr</link>+i*4);}
<anchor xml:id="_bsp__flash_8c_source_1l00078"/>00078 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00083"/><link linkend="_bsp__flash_8c_1aa1a1ff74b284a19aa3872b6f3d6abd11">00083</link> <emphasis role="comment"></emphasis><emphasis role="keywordtype">void</emphasis>&#32;<link linkend="_bsp__flash_8c_1aa1a1ff74b284a19aa3872b6f3d6abd11">bsp_WriteFlash_Pack</link>(<emphasis role="keywordtype">void</emphasis>){
<anchor xml:id="_bsp__flash_8c_source_1l00084"/>00084 &#32;&#32;&#32;&#32;<link linkend="_bsp__flash_8c_1af1304997d797af3400074bdb68e5de1c">bsp_WriteFlashOnePage</link>((uint32_t*)(&amp;<link linkend="_bsp__flash_8c_1a2c0639c4d50bba3762a4295a56a06af8">bsp_Flash_Pack</link>),<emphasis role="keyword">sizeof</emphasis>(<emphasis role="keyword">struct</emphasis>&#32;<link linkend="_structstruct__bsp___flash___pack">struct_bsp_Flash_Pack</link>));
<anchor xml:id="_bsp__flash_8c_source_1l00085"/>00085 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>;}
<anchor xml:id="_bsp__flash_8c_source_1l00086"/>00086 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_bsp__flash_8c_source_1l00091"/><link linkend="_bsp__flash_8c_1a45549058e1315d29263c0b26816bcffb">00091</link> <emphasis role="comment"></emphasis><emphasis role="keywordtype">void</emphasis>&#32;<link linkend="_bsp__flash_8c_1a45549058e1315d29263c0b26816bcffb">bsp_ReadFlash_Pack</link>(<emphasis role="keywordtype">void</emphasis>){
<anchor xml:id="_bsp__flash_8c_source_1l00092"/>00092 &#32;&#32;&#32;&#32;<link linkend="_bsp__flash_8c_1a734a679e19a8af2c7ddfa86f4310a13d">bsp_ReadFlash</link>((uint32_t*)(&amp;<link linkend="_bsp__flash_8c_1a2c0639c4d50bba3762a4295a56a06af8">bsp_Flash_Pack</link>),<emphasis role="keyword">sizeof</emphasis>(<emphasis role="keyword">struct</emphasis>&#32;<link linkend="_structstruct__bsp___flash___pack">struct_bsp_Flash_Pack</link>));
<anchor xml:id="_bsp__flash_8c_source_1l00093"/>00093 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>;}
</programlisting></section>