1 <!-- HTML header for doxygen 1.8.20-->
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
5 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
7 <meta name="generator" content="Doxygen 1.9.4"/>
8 <meta name="viewport" content="width=device-width, initial-scale=1"/>
9 <title>Raspberry Pi Pico SDK: pico_flash</title>
10 <!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
11 <script type="text/javascript" src="jquery.js"></script>
12 <script type="text/javascript" src="dynsections.js"></script>
13 <link href="navtree.css" rel="stylesheet" type="text/css"/>
14 <script type="text/javascript" src="resize.js"></script>
15 <script type="text/javascript" src="navtreedata.js"></script>
16 <script type="text/javascript" src="navtree.js"></script>
17 <link href="search/search.css" rel="stylesheet" type="text/css"/>
18 <script type="text/javascript" src="search/searchdata.js"></script>
19 <script type="text/javascript" src="search/search.js"></script>
20 <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
21 <link href="doxygen.css" rel="stylesheet" type="text/css" />
22 <link href="normalise.css" rel="stylesheet" type="text/css"/>
23 <link href="main.css" rel="stylesheet" type="text/css"/>
24 <link href="styles.css" rel="stylesheet" type="text/css"/>
27 <div class="navigation-mobile">
28 <div class="logo--mobile">
29 <a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
31 <div class="navigation-toggle">
32 <span class="line-1"></span>
36 <span class="line-3"></span>
39 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
41 <a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
42 <span style="display: inline-block; margin-top: 10px;">
46 <div class="navigation-footer">
47 <img src="logo-mobile.svg" alt="Raspberry Pi">
48 <a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
50 <!-- <div class="search">
52 <input type="search" name="search" id="search" placeholder="Search">
53 <input type="submit" value="Search">
56 <!-- Generated by Doxygen 1.9.4 -->
57 <script type="text/javascript">
58 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
59 var searchBox = new SearchBox("searchBox", "search",'Search','.html');
62 <script type="text/javascript" src="menudata.js"></script>
63 <script type="text/javascript" src="menu.js"></script>
64 <script type="text/javascript">
65 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
67 initMenu('',true,false,'search.php','Search');
68 $(document).ready(function() { init_search(); });
72 <div id="main-nav"></div>
74 <div id="side-nav" class="ui-resizable side-nav-resizable">
76 <div id="nav-tree-contents">
77 <div id="nav-sync" class="sync"></div>
80 <div id="splitbar" style="-moz-user-select:none;"
81 class="ui-resizable-handle">
84 <script type="text/javascript">
85 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
86 $(document).ready(function(){initNavTree('group__pico__flash.html',''); initResizable(); });
89 <div id="doc-content">
90 <!-- window showing the filter options -->
91 <div id="MSearchSelectWindow"
92 onmouseover="return searchBox.OnSearchSelectShow()"
93 onmouseout="return searchBox.OnSearchSelectHide()"
94 onkeydown="return searchBox.OnSearchSelectKey(event)">
97 <!-- iframe showing the search results (closed by default) -->
98 <div id="MSearchResultsWindow">
99 <iframe src="javascript:void(0)" frameborder="0"
100 name="MSearchResults" id="MSearchResults">
105 <div class="summary">
106 <a href="#func-members">Functions</a> </div>
107 <div class="headertitle"><div class="title">pico_flash<div class="ingroups"><a class="el" href="group__high__level.html">High Level APIs</a></div></div></div>
109 <div class="contents">
111 <p>High level flash API.
112 <a href="#details">More...</a></p>
113 <table class="memberdecls">
114 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
115 Functions</h2></td></tr>
116 <tr class="memitem:ga2ad3247806ca16dec03e655eaec1775f"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a> (void)</td></tr>
117 <tr class="memdesc:ga2ad3247806ca16dec03e655eaec1775f"><td class="mdescLeft"> </td><td class="mdescRight">Initialize a core such that the other core can lock it out during <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>. <a href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">More...</a><br /></td></tr>
118 <tr class="separator:ga2ad3247806ca16dec03e655eaec1775f"><td class="memSeparator" colspan="2"> </td></tr>
119 <tr class="memitem:gaed14b762cb5fd483995bd36fc8ad338d"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">flash_safe_execute_core_deinit</a> (void)</td></tr>
120 <tr class="memdesc:gaed14b762cb5fd483995bd36fc8ad338d"><td class="mdescLeft"> </td><td class="mdescRight">De-initialize work done by <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a>. <a href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">More...</a><br /></td></tr>
121 <tr class="separator:gaed14b762cb5fd483995bd36fc8ad338d"><td class="memSeparator" colspan="2"> </td></tr>
122 <tr class="memitem:ga679076dc10c5beb73d5f1abdb52d6735"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> (void(*func)(void *), void *param, uint32_t enter_exit_timeout_ms)</td></tr>
123 <tr class="memdesc:ga679076dc10c5beb73d5f1abdb52d6735"><td class="mdescLeft"> </td><td class="mdescRight">Execute a function with IRQs disabled and with the other core also not executing/reading flash. <a href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">More...</a><br /></td></tr>
124 <tr class="separator:ga679076dc10c5beb73d5f1abdb52d6735"><td class="memSeparator" colspan="2"> </td></tr>
125 <tr class="memitem:gaee44bd9bc42463f0521535825e8d90b2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">get_flash_safety_helper</a> (void)</td></tr>
126 <tr class="memdesc:gaee44bd9bc42463f0521535825e8d90b2"><td class="mdescLeft"> </td><td class="mdescRight">Internal method to return the flash safety helper implementation. <a href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">More...</a><br /></td></tr>
127 <tr class="separator:gaee44bd9bc42463f0521535825e8d90b2"><td class="memSeparator" colspan="2"> </td></tr>
129 <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
130 <p >High level flash API. </p>
131 <p >Flash cannot be erased or written to when in XIP mode. However the system cannot directly access memory in the flash address space when not in XIP mode.</p>
132 <p >It is therefore critical that no code or data is being read from flash while flash is been written or erased.</p>
133 <p >If only one core is being used, then the problem is simple - just disable interrupts; however if code is running on the other core, then it has to be asked, nicely, to avoid flash for a bit. This is hard to do if you don't have complete control of the code running on that core at all times.</p>
134 <p >This library provides a <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> method which calls a function back having successfully gotten into a state where interrupts are disabled, and the other core is not executing or reading from flash.</p>
135 <p >How it does this is dependent on the supported environment (Free RTOS SMP or pico_multicore). Additionally the user can provide their own mechanism by providing a strong definition of <a class="el" href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">get_flash_safety_helper()</a>.</p>
136 <p >Using the default settings, flash_safe_execute will only call the callback function if the state is safe otherwise returning an error (or an assert depending on PICO_FLASH_ASSERT_ON_UNSAFE).</p>
137 <p >There are conditions where safety would not be guaranteed:</p>
139 <li>FreeRTOS smp with <code>configNUM_CORES=1</code> - FreeRTOS still uses pico_multicore in this case, so <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> cannot know what the other core is doing, and there is no way to force code execution between a FreeRTOS core and a non FreeRTOS core.</li>
140 <li>FreeRTOS non SMP with pico_multicore - Again, there is no way to force code execution between a FreeRTOS core and a non FreeRTOS core.</li>
141 <li>pico_multicore without <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init()</a> having been called on the other core - The <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> method does not know if code is executing on the other core, so it has to assume it is. Either way, it is not able to intervene if <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init()</a> has not been called on the other core.</li>
143 <p >Fortunately, all is not lost in this situation, you may:</p>
145 <li>Set PICO_FLASH_ASSUME_CORE0_SAFE=1 to explicitly say that core 0 is never using flash.</li>
146 <li>Set PICO_FLASH_ASSUME_CORE1_SAFE=1 to explicitly say that core 1 is never using flash. </li>
148 <h2 class="groupheader">Function Documentation</h2>
149 <a id="ga679076dc10c5beb73d5f1abdb52d6735" name="ga679076dc10c5beb73d5f1abdb52d6735"></a>
150 <h2 class="memtitle"><span class="permalink"><a href="#ga679076dc10c5beb73d5f1abdb52d6735">◆ </a></span>flash_safe_execute()</h2>
152 <div class="memitem">
153 <div class="memproto">
154 <table class="memname">
156 <td class="memname">int flash_safe_execute </td>
158 <td class="paramtype">void(*)(void *) </td>
159 <td class="paramname"><em>func</em>, </td>
162 <td class="paramkey"></td>
164 <td class="paramtype">void * </td>
165 <td class="paramname"><em>param</em>, </td>
168 <td class="paramkey"></td>
170 <td class="paramtype">uint32_t </td>
171 <td class="paramname"><em>enter_exit_timeout_ms</em> </td>
179 </div><div class="memdoc">
181 <p>Execute a function with IRQs disabled and with the other core also not executing/reading flash. </p>
182 <dl class="params"><dt>Parameters</dt><dd>
183 <table class="params">
184 <tr><td class="paramname">func</td><td>the function to call </td></tr>
185 <tr><td class="paramname">param</td><td>the parameter to pass to the function </td></tr>
186 <tr><td class="paramname">enter_exit_timeout_ms</td><td>the timeout for each of the enter/exit phases when coordinating with the other core</td></tr>
190 <dl class="section return"><dt>Returns</dt><dd>PICO_OK on success (the function will have been called). PICO_ERROR_TIMEOUT on timeout (the function may have been called). PICO_ERROR_NOT_PERMITTED if safe execution is not possible (the function will not have been called). PICO_ERROR_INSUFFICIENT_RESOURCES if the method fails due to dynamic resource exhaustion (the function will not have been called) </dd></dl>
191 <dl class="section note"><dt>Note</dt><dd>if PICO_FLASH_ASSERT_ON_UNSAFE is 1, this function will assert in debug mode vs returning PICO_ERROR_NOT_PERMITTED </dd></dl>
195 <a id="gaed14b762cb5fd483995bd36fc8ad338d" name="gaed14b762cb5fd483995bd36fc8ad338d"></a>
196 <h2 class="memtitle"><span class="permalink"><a href="#gaed14b762cb5fd483995bd36fc8ad338d">◆ </a></span>flash_safe_execute_core_deinit()</h2>
198 <div class="memitem">
199 <div class="memproto">
200 <table class="memname">
202 <td class="memname">bool flash_safe_execute_core_deinit </td>
204 <td class="paramtype">void </td>
205 <td class="paramname"></td><td>)</td>
209 </div><div class="memdoc">
211 <p>De-initialize work done by <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a>. </p>
212 <dl class="section return"><dt>Returns</dt><dd>true on success </dd></dl>
216 <a id="ga2ad3247806ca16dec03e655eaec1775f" name="ga2ad3247806ca16dec03e655eaec1775f"></a>
217 <h2 class="memtitle"><span class="permalink"><a href="#ga2ad3247806ca16dec03e655eaec1775f">◆ </a></span>flash_safe_execute_core_init()</h2>
219 <div class="memitem">
220 <div class="memproto">
221 <table class="memname">
223 <td class="memname">bool flash_safe_execute_core_init </td>
225 <td class="paramtype">void </td>
226 <td class="paramname"></td><td>)</td>
230 </div><div class="memdoc">
232 <p>Initialize a core such that the other core can lock it out during <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>. </p>
233 <dl class="section note"><dt>Note</dt><dd>This is not necessary for FreeRTOS SMP, but should be used when launching via <a class="el" href="group__pico__multicore.html#ga46ea5e2efc181aba1d4d1de06a375c59">multicore_launch_core1</a> </dd></dl>
234 <dl class="section return"><dt>Returns</dt><dd>true on success; there is no need to call <a class="el" href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">flash_safe_execute_core_deinit()</a> on failure. </dd></dl>
238 <a id="gaee44bd9bc42463f0521535825e8d90b2" name="gaee44bd9bc42463f0521535825e8d90b2"></a>
239 <h2 class="memtitle"><span class="permalink"><a href="#gaee44bd9bc42463f0521535825e8d90b2">◆ </a></span>get_flash_safety_helper()</h2>
241 <div class="memitem">
242 <div class="memproto">
243 <table class="memname">
245 <td class="memname"><a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> * get_flash_safety_helper </td>
247 <td class="paramtype">void </td>
248 <td class="paramname"></td><td>)</td>
252 </div><div class="memdoc">
254 <p>Internal method to return the flash safety helper implementation. </p>
255 <p >Advanced users can provide their own implementation of this function to perform different inter-core coordination before disabling XIP mode.</p>
256 <dl class="section return"><dt>Returns</dt><dd>the <a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> </dd></dl>
260 </div><!-- contents -->
261 </div><!-- doc-content -->
263 <script src="main.js"></script>