summaryrefslogtreecommitdiff
path: root/docs/Pack/html/algorithmFunc.html
blob: 0f4d48693fd3fa11ba5552da6343a24d55912cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Algorithm Functions</title>
<title>CMSIS-Pack: Algorithm Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-Pack
   &#160;<span id="projectnumber">Version 1.6.0</span>
   </div>
   <div id="projectbrief">Delivery Mechanism for Software Packs</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('algorithmFunc.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Algorithm Functions </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Blank Check</p>
<p>The following functions are available for creating new Flash programming algorithms: </p>
<table class="doxtable">
<tr>
<th>Function Name </th><th>Indication </th><th>Description  </th></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#BlankCheck">BlankCheck</a> </td><td>optional </td><td>Check and compare patterns. </td></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#EraseChip">EraseChip</a> </td><td>optional </td><td>Delete entire Flash memory content. </td></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#EraseSector">EraseSector</a> </td><td>mandatory </td><td>Delete Flash memory content of a specific sector. </td></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#Init">Init</a> </td><td>mandatory </td><td>Initialize and prepare device for Flash programming. </td></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#ProgramPage">ProgramPage</a> </td><td>mandatory </td><td>Write the application into the Flash memory. </td></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#UnInit">UnInit</a> </td><td>mandatory </td><td>De-initialize the microcontroller after one of the Flash programming steps. </td></tr>
<tr>
<td><a class="el" href="algorithmFunc.html#Verify">Verify</a> </td><td>optional </td><td>Compare Flash memory content with the program code. </td></tr>
</table>
<p>The following diagrams show how the functions of the <b>Flash Programming Algorithms</b> are executed by a development tool.</p>
<p>The <b>Flash Erase</b> sequence is executed to erase the Flash content.</p>
<div class="image">
<img src="FlashErase.png" alt="FlashErase.png"/>
<div class="caption">
Flash Erase</div></div>
<p> The <b>Flash Program</b> sequence is executed to program the Flash memory.</p>
<div class="image">
<img src="FlashProgram.png" alt="FlashProgram.png"/>
<div class="caption">
Flash Program</div></div>
<p> The <b>Flash Verify</b> sequence is executed to verify the content after flash programming.</p>
<div class="image">
<img src="FlashVerify.png" alt="FlashVerify.png"/>
<div class="caption">
Flash Verify</div></div>
 <p>&#160;</p>
<hr/>
<h1><a class="anchor" id="BlankCheck"></a>
BlankCheck</h1>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> BlankCheck (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sz, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> pat);</div>
</div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">adr</td><td>Block start address </td></tr>
    <tr><td class="paramname">sz</td><td>Block size in bytes </td></tr>
    <tr><td class="paramname">pat</td><td>Pattern to compare </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>0 when the block content is equal to the pattern pat.</li>
<li>1 when the block content differs from the pattern pat.</li>
</ul>
</dd></dl>
<p>The function <b>BlankCheck</b> can be used to check whether the specified block is empty, or whether the content is equal to a specific pattern defined in the argument <em>pat</em>.</p>
<p>The argument <em>adr</em> specifies the start address of the block that is to be verified.</p>
<p>The argument <em>sz</em> specifies the size of the block that is to be verified.</p>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> BlankCheck (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sz, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> pat) {</div>
<div class="line"> </div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> i, j, k;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Recalculate address for External SDRAM addresses</span></div>
<div class="line">  <span class="keywordflow">if</span> (adr &gt;= SDRAM_START)</div>
<div class="line">    adr = adr - SDRAM_START + USER_OFFSET;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">for</span> (i = 0; i &lt; sz; i += 256) {</div>
<div class="line">    <span class="comment">// Read 256 bytes</span></div>
<div class="line">    ReadPage_HW (adr+i, 256, &amp;rd_buf[0]);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Determine size to compare</span></div>
<div class="line">    <span class="keywordflow">if</span> ((sz-i) &gt;= 256) k = 256;</div>
<div class="line">    <span class="keywordflow">else</span>               k = (sz-i);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Check up to 256 bytes if equal to pattern &quot;pat&quot;</span></div>
<div class="line">    <span class="keywordflow">for</span> (j = 0; j &lt; k; j++)</div>
<div class="line">      <span class="keywordflow">if</span> (rd_buf[j] != pat) <span class="keywordflow">return</span> (1); <span class="comment">// Memory is not blank</span></div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (0);                           <span class="comment">// Memory is blank</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>&#160;</p>
<hr/>
<h1><a class="anchor" id="EraseChip"></a>
EraseChip</h1>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> EraseChip (<span class="keywordtype">void</span>);</div>
</div><!-- fragment --> <dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>0 on success.</li>
<li>1 on failure.</li>
</ul>
</dd></dl>
<p>The function <b>EraseChip</b> deletes the content of the entire Flash memory. It is invoked whenever the uVision menu <b>Flash</b> - <b>Erase</b> is used, or whenever an attempt is made to download the program to Flash and the option <b>Erase Full Chip</b> has been set in the <b>Flash Download Setup</b> dialog. If this function is missing in the Flash Programming Algorithm, the <a class="el" href="algorithmFunc.html#EraseSector">EraseSector</a> function is executed until the entire content of the Flash memory area has been deleted.</p>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> EraseChip (<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line">  FLASH-&gt;CR |=  FLASH_MER;                      <span class="comment">// Mass Erase Enabled</span></div>
<div class="line">  FLASH-&gt;CR |=  FLASH_STRT;                     <span class="comment">// Start Erase</span></div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">while</span> (FLASH-&gt;SR &amp; FLASH_BSY) {</div>
<div class="line">    IWDG-&gt;KR = 0xAAAA;                          <span class="comment">// Reload IWDG</span></div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  FLASH-&gt;CR &amp;= ~FLASH_MER;                      <span class="comment">// Mass Erase Disabled</span></div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (0);                                   <span class="comment">// Done</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>&#160;</p>
<hr/>
<h1><a class="anchor" id="EraseSector"></a>
EraseSector</h1>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> EraseSector (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr);</div>
</div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">adr</td><td>Sector address </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>0 on success.</li>
<li>1 on failure.</li>
</ul>
</dd></dl>
<p>The function <b>EraseSector</b> deletes the content of the sector starting at the address specified by the argument <em>adr</em>. The function is invoked whenever the uVision menu <b>Flash</b> - <b>Erase</b> is used, or whenever an attempt is made to download the program to Flash and the option <b>Erase Sectors</b> has been set in the <b>Flash Download Setup</b> dialog.</p>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> EraseSector (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr) {</div>
<div class="line"> </div>
<div class="line">  FLASH-&gt;CR |=  FLASH_PER;                      <span class="comment">// Page Erase Enabled</span></div>
<div class="line">  FLASH-&gt;AR  =  adr;                            <span class="comment">// Page Address</span></div>
<div class="line">  FLASH-&gt;CR |=  FLASH_STRT;                     <span class="comment">// Start Erase</span></div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">while</span> (FLASH-&gt;SR &amp; FLASH_BSY) {</div>
<div class="line">    IWDG-&gt;KR = 0xAAAA;                          <span class="comment">// Reload IWDG</span></div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  FLASH-&gt;CR &amp;= ~FLASH_PER;                      <span class="comment">// Page Erase Disabled</span></div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (0);                                   <span class="comment">// Done</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>&#160;</p>
<hr/>
<h1><a class="anchor" id="Init"></a>
Init</h1>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> Init (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> clk, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fnc);</div>
</div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">adr</td><td>Device base address </td></tr>
    <tr><td class="paramname">clk</td><td>Clock frequency (Hz) </td></tr>
    <tr><td class="paramname">fnc</td><td>Function code </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>0 on success.</li>
<li>1 on failure.</li>
</ul>
</dd></dl>
<p>The function <b>Init</b> initializes the microcontroller for Flash programming. It is invoked whenever an attempt is made to download the program to Flash.</p>
<p>The argument <em>adr</em> specifies the base address of the device.</p>
<p>The argument <em>clk</em> specifies the clock frequency for prgramming the device.</p>
<p>The argument <em>fnc</em> is a number:</p>
<ul>
<li>1 stands for Erase.</li>
<li>2 stands for Program.</li>
<li>3 stands for Verify.</li>
</ul>
<p>Thus, different initialization sections can be implemented for each individual Flash programming step.</p>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> Init (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> clk, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fnc) {</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Zero Wait State</span></div>
<div class="line">  FLASH-&gt;ACR  = 0x00000000;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Unlock Flash</span></div>
<div class="line">  FLASH-&gt;KEYR = FLASH_KEY1;</div>
<div class="line">  FLASH-&gt;KEYR = FLASH_KEY2;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Test if IWDG is running (IWDG in HW mode)</span></div>
<div class="line">  <span class="keywordflow">if</span> ((FLASH-&gt;OBR &amp; 0x04) == 0x00) {</div>
<div class="line">    <span class="comment">// Set IWDG time out to ~32.768 second</span></div>
<div class="line">    IWDG-&gt;KR  = 0x5555; <span class="comment">// Enable write access to IWDG_PR and IWDG_RLR</span></div>
<div class="line">    IWDG-&gt;PR  = 0x06;   <span class="comment">// Set prescaler to 256</span></div>
<div class="line">    IWDG-&gt;RLR = 4095;   <span class="comment">// Set reload value to 4095</span></div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (0);</div>
<div class="line">}</div>
</div><!-- fragment --><p>&#160;</p>
<hr/>
<h1><a class="anchor" id="ProgramPage"></a>
ProgramPage</h1>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> ProgramPage (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sz, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buf);</div>
</div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">adr</td><td>Page start address </td></tr>
    <tr><td class="paramname">sz</td><td>Page size </td></tr>
    <tr><td class="paramname">buf</td><td>Data to be written </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>0 on success.</li>
<li>1 on failure.</li>
</ul>
</dd></dl>
<p>The function <b>ProgramPage</b> is used to write code into the Flash memory. It is invoked to download a program to Flash. As Flash memory is typically organized in blocks or pages, the parameters to the function <b>ProgramPage</b> must not cross alignment boundaries of these flash pages. The page size is specified in the struct FlashDevice with the value <b>Program Page Size</b>.</p>
<p>The argument <em>adr</em> specifies the start address of the page that is to be programmed. It is aligned by the host programming system to a start address of a flash page.</p>
<p>The argument <em>sz</em> specifies the data size in the data buffer. The host programming system ensures that page boundaries are not crossed.</p>
<p>The argument <em>buf</em> points to the data buffer containing the data to be programmed.</p>
<dl class="section note"><dt>Note</dt><dd>The host programming system ensures that the argument <em>adr</em> + <em>sz</em> never crosses any page boundary. The function <b>ProgramPage</b> does therefore not require any provisions for that.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> ProgramPage (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sz, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buf) {</div>
<div class="line"> </div>
<div class="line">  sz = (sz + 1) &amp; ~1;                           <span class="comment">// Adjust size for Half Words</span></div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">while</span> (sz) {</div>
<div class="line"> </div>
<div class="line">    FLASH-&gt;CR |=  FLASH_PG;                     <span class="comment">// Programming Enabled</span></div>
<div class="line"> </div>
<div class="line">    M16(adr) = *((<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> *)buf);        <span class="comment">// Program Half Word</span></div>
<div class="line">    <span class="keywordflow">while</span> (FLASH-&gt;SR &amp; FLASH_BSY);</div>
<div class="line"> </div>
<div class="line">    FLASH-&gt;CR &amp;= ~FLASH_PG;                     <span class="comment">// Programming Disabled</span></div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Check for Errors</span></div>
<div class="line">    <span class="keywordflow">if</span> (FLASH-&gt;SR &amp; (FLASH_PGERR | FLASH_WRPRTERR)) {</div>
<div class="line">      FLASH-&gt;SR |= FLASH_PGERR | FLASH_WRPRTERR;</div>
<div class="line">      <span class="keywordflow">return</span> (1);                               <span class="comment">// Failed</span></div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Go to next Half Word</span></div>
<div class="line">    adr += 2;</div>
<div class="line">    buf += 2;</div>
<div class="line">    sz  -= 2;</div>
<div class="line"> </div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (0);                                   <span class="comment">// Done</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>&#160;</p>
<hr/>
<h1><a class="anchor" id="UnInit"></a>
UnInit</h1>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> UnInit (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fnc);</div>
</div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">fnc</td><td>Function code </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>0 on success.</li>
<li>1 on failure.</li>
</ul>
</dd></dl>
<p>The function <b>UnInit</b> de-initializes the microcontroller and is invoked at the end of an erasing, programming, or verifying step.</p>
<p>The argument <em>fnc</em> is a number:</p>
<ul>
<li>1 stands for Erase.</li>
<li>2 stands for Program.</li>
<li>3 stands for Verify.</li>
</ul>
<p>Thus, different de-initialization sections can be implemented for each individual Flash programming step.</p>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> UnInit (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fnc) {</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Lock Flash</span></div>
<div class="line">  FLASH-&gt;CR |=  FLASH_LOCK;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (0);</div>
<div class="line">}</div>
</div><!-- fragment --><p>&#160;</p>
<hr/>
<h1><a class="anchor" id="Verify"></a>
Verify</h1>
<div class="fragment"><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> Verify (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sz, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buf);</div>
</div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">adr</td><td>Start address </td></tr>
    <tr><td class="paramname">sz</td><td>Size in bytes </td></tr>
    <tr><td class="paramname">buf</td><td>Data to be compared </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status information:<ul>
<li>the sum of (adr+sz) - on success.</li>
<li>any other number - on failure, and represents the failing address.</li>
</ul>
</dd></dl>
<p>The function <b>Verify</b> compares the content of the Flash memory with the program code <em>*buf</em>.</p>
<p>The argument <em>adr</em> specifies the start address for the verification.</p>
<p>The argument <em>sz</em> specifies the size of the verification.</p>
<p>The argument <em>buf</em> points to the buffer containing the data to be verified.</p>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> Verify (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> adr, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sz, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buf) {</div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> i, adr_dest, in_page_ofs;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span> (adr &lt; block_size) {               <span class="comment">// Verifying 2-nd level bootloader data</span></div>
<div class="line">    adr_dest = adr + page_usr_size;     <span class="comment">// skip page 0 of block 0</span></div>
<div class="line">  } <span class="keywordflow">else</span> {                              <span class="comment">// Verifying program data</span></div>
<div class="line">    FindBlock(adr, 0);</div>
<div class="line">    adr_dest  = nand_block_offset + (adr &amp; (block_size-1));</div>
<div class="line">  }</div>
<div class="line">  in_page_ofs = adr_dest &amp; (page_usr_size-1);</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span> (ReadPage_HW(adr_dest, page_usr_size, data_buf)) <span class="keywordflow">return</span> (1);</div>
<div class="line">  <span class="keywordflow">for</span> (i=0; i&lt;sz; i++)</div>
<div class="line">    <span class="keywordflow">if</span> (buf[i] != data_buf[i+in_page_ofs])</div>
<div class="line">      <span class="keywordflow">break</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">return</span> (adr+i);</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="flashAlgorithm.html">Flash Programming</a></li>
    <li class="footer">Generated on Wed Jul 10 2019 15:21:00 for CMSIS-Pack Version 1.6.0 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 
	-->
	</li>
  </ul>
</div>
</body>
</html>