dbg_debug_sqns.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <title>Implement debug sequences</title>
  7. <title>CMSIS-Pack: Implement debug sequences</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <link href="cmsis.css" rel="stylesheet" type="text/css" />
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <script type="text/javascript" src="printComponentTabs.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="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. $(window).load(resizeHeight);
  19. </script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/search.js"></script>
  22. <script type="text/javascript">
  23. $(document).ready(function() { searchBox.OnSelectItem(0); });
  24. </script>
  25. </head>
  26. <body>
  27. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  28. <div id="titlearea">
  29. <table cellspacing="0" cellpadding="0">
  30. <tbody>
  31. <tr style="height: 46px;">
  32. <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  33. <td style="padding-left: 0.5em;">
  34. <div id="projectname">CMSIS-Pack
  35. &#160;<span id="projectnumber">Version 1.6.3</span>
  36. </div>
  37. <div id="projectbrief">Delivery Mechanism for Software Packs</div>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. <!-- end header part -->
  44. <div id="CMSISnav" class="tabs1">
  45. <ul class="tablist">
  46. <script type="text/javascript">
  47. <!--
  48. writeComponentTabs.call(this);
  49. //-->
  50. </script>
  51. </ul>
  52. </div>
  53. <!-- Generated by Doxygen 1.8.6 -->
  54. <script type="text/javascript">
  55. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  56. </script>
  57. <div id="navrow1" class="tabs">
  58. <ul class="tablist">
  59. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  60. <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
  61. <li>
  62. <div id="MSearchBox" class="MSearchBoxInactive">
  63. <span class="left">
  64. <img id="MSearchSelect" src="search/mag_sel.png"
  65. onmouseover="return searchBox.OnSearchSelectShow()"
  66. onmouseout="return searchBox.OnSearchSelectHide()"
  67. alt=""/>
  68. <input type="text" id="MSearchField" value="Search" accesskey="S"
  69. onfocus="searchBox.OnSearchFieldFocus(true)"
  70. onblur="searchBox.OnSearchFieldFocus(false)"
  71. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  72. </span><span class="right">
  73. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  74. </span>
  75. </div>
  76. </li>
  77. </ul>
  78. </div>
  79. </div><!-- top -->
  80. <div id="side-nav" class="ui-resizable side-nav-resizable">
  81. <div id="nav-tree">
  82. <div id="nav-tree-contents">
  83. <div id="nav-sync" class="sync"></div>
  84. </div>
  85. </div>
  86. <div id="splitbar" style="-moz-user-select:none;"
  87. class="ui-resizable-handle">
  88. </div>
  89. </div>
  90. <script type="text/javascript">
  91. $(document).ready(function(){initNavTree('dbg_debug_sqns.html','');});
  92. </script>
  93. <div id="doc-content">
  94. <!-- window showing the filter options -->
  95. <div id="MSearchSelectWindow"
  96. onmouseover="return searchBox.OnSearchSelectShow()"
  97. onmouseout="return searchBox.OnSearchSelectHide()"
  98. onkeydown="return searchBox.OnSearchSelectKey(event)">
  99. <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>
  100. <!-- iframe showing the search results (closed by default) -->
  101. <div id="MSearchResultsWindow">
  102. <iframe src="javascript:void(0)" frameborder="0"
  103. name="MSearchResults" id="MSearchResults">
  104. </iframe>
  105. </div>
  106. <div class="header">
  107. <div class="headertitle">
  108. <div class="title">Implement debug sequences </div> </div>
  109. </div><!--header-->
  110. <div class="contents">
  111. <div class="textblock"><p>Most Cortex-M devices rely on Arm Debug Interface (ADI) that specifies standard interface for accessing debug functionality on the processor. However due to implementation-specific variations it can still be challenging for debug tool vendors to provide reliable debugging experience for complex devices. Device vendors can use <a class="el" href="debug_description.html#pdsc_SequenceNameEnum_pg">debug access sequences</a> to customize the debugger behavior for a particular device.</p>
  112. <p>Section <a class="el" href="debug_description.html#usage_of_sequences">Usage of debug access sequences</a> provides working example flows that can be implemented in a debugger. By overwriting the <a class="el" href="debug_description.html#default_sequences">predefined debug sequences</a> it is possible to customize the debugger operation for a specific device. The syntax and available functions are described in details in <a class="el" href="debug_description.html#writing_sequences">Writing debug access sequences</a>. This chapter explains the common cases that can be covered using debug sequences:</p>
  113. <ul>
  114. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_dbgconf">Enable device-specific debug configurations</a></li>
  115. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_errors">Ignore access errors</a></li>
  116. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_trace">Configure trace</a></li>
  117. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_reset">Implement reset for debug access</a></li>
  118. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_boot">Support bootloader operation</a></li>
  119. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_multicore">Handle debug in multi-core systems</a></li>
  120. </ul>
  121. <p>The examples provided are quite generic demonstrating the concept to follow when addressing a specific scenario. However actual implementation shall always take device specific behavior into account.</p>
  122. <h1><a class="anchor" id="dbg_sqns_dbgconf"></a>
  123. Enable device-specific debug configurations</h1>
  124. <p>The debug configuration options available in the debug IDEs mostly cover quite generic scenarios applicable to a wide set of devices and architectures, for example whether to use reset for debug connection and what type of reset, whether to stop after debug connection or not and so on. <a class="el" href="dbg_setup_access.html">Configure debug access</a> describes how to use debug descriptions to specify the configuration options available for the device and how to pre-select the default values.</p>
  125. <p>But often there is a need to provide developers with some debug configuration options that are very device-specific. This can vary from simple SWO pin and clock source selection for tracing to more complex bootloader configuration or secure debug provisioning and multi-core system debug.</p>
  126. <p>The <a class="el" href="pdsc_family_pg.html#element_debugvars">debugvars</a> element allows to define custom global debug access variables. Their values can also be made configurable via a project-specific <a class="el" href="pdsc_family_pg.html#debugvars_configfile">debug configuration file</a> (<b>*.dbgconf</b>). It is recommended to implement this file with <a class="el" href="configWizard.html">Configuration Wizard annotations</a> to enable simple graphical configuration view. <a class="el" href="debug_description.html#default_sequences">Predefined debug access sequences</a> can be overwritten where needed and use the custom debug variables. If a user-defined global access variable is not specified in the *.dbgconf file, then the value provided in the variable definition in the pdsc file is applied.</p>
  127. <p>Documentation for the <a class="el" href="pdsc_family_pg.html#element_debugvars">debugvars</a> provides an example for trace SWO pin selection via a *.dbgconf file. Below is also an example that uses a custom global debug variable <b>Dbg_CR</b> for specifying whether the program shall stop after bootloader execution or not:</p>
  128. <p><b> Use of debugvars in a pdsc file: </b></p>
  129. <div class="fragment"><div class="line">... </div>
  130. <div class="line"> &lt;debugvars configfile=<span class="stringliteral">&quot;Debug/LPC84x.dbgconf&quot;</span>&gt;&gt;</div>
  131. <div class="line"> __var Dbg_CR = 0x00000000; <span class="comment">// DBG_CR, with default value 0x00000000</span></div>
  132. <div class="line"> &lt;/debugvars&gt;</div>
  133. <div class="line"> ...</div>
  134. <div class="line"> <span class="comment">// ResetCatchSet Sequence LPC84x</span></div>
  135. <div class="line"> &lt;sequence name=<span class="stringliteral">&quot;ResetCatchSet&quot;</span>&gt;</div>
  136. <div class="line"> ... <span class="comment">// initial setup</span></div>
  137. <div class="line"> </div>
  138. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;Dbg_CR == 0x00000000&quot;</span> info=<span class="stringliteral">&quot;Stop after bootloader disabled&quot;</span>&gt;</div>
  139. <div class="line"> &lt;block&gt;</div>
  140. <div class="line"> value = Read32(DEMCR_Addr);</div>
  141. <div class="line"> Write32(DEMCR_Addr, (value | 0x00000001)); <span class="comment">// Enable Reset Vector Catch in DEMCR</span></div>
  142. <div class="line"> &lt;/block&gt;</div>
  143. <div class="line"> &lt;/control&gt;</div>
  144. <div class="line"></div>
  145. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;Dbg_CR == 0x00000001&quot;</span> info=<span class="stringliteral">&quot;Stop after bootloader enabled&quot;</span>&gt;</div>
  146. <div class="line"> &lt;block&gt;</div>
  147. <div class="line"> value = Read32(DEMCR_Addr);</div>
  148. <div class="line"> Write32(DEMCR_Addr, (value &amp;amp; (~0x00000001))); <span class="comment">// Disable Reset Vector Catch in DEMCR</span></div>
  149. <div class="line"> &lt;/block&gt;</div>
  150. <div class="line"> &lt;/control&gt;</div>
  151. <div class="line"> ...</div>
  152. <div class="line"> &lt;/sequence&gt;</div>
  153. <div class="line"> ...</div>
  154. </div><!-- fragment --><p><b>*.dbgconf file: source code</b> </p>
  155. <div class="fragment"><div class="line"><span class="comment">// &lt;&lt;&lt; Use Configuration Wizard in Context Menu &gt;&gt;&gt;</span></div>
  156. <div class="line"></div>
  157. <div class="line"><span class="comment">// &lt;h&gt;Debug Configuration</span></div>
  158. <div class="line"><span class="comment">// &lt;o.0&gt; StopAfterBootloader &lt;i&gt; Stop after Bootloader</span></div>
  159. <div class="line"><span class="comment">// &lt;/h&gt;</span></div>
  160. <div class="line">Dbg_CR = 0x00000001;</div>
  161. <div class="line"></div>
  162. <div class="line"><span class="comment">// &lt;&lt;&lt; end of configuration section &gt;&gt;&gt;</span></div>
  163. </div><!-- fragment --><p><b>*.dbgconf file: Configuration Wizard view</b></p>
  164. <div class="image">
  165. <img src="dbgconf_confWizard.png" alt="dbgconf_confWizard.png"/>
  166. </div>
  167. <p>In the same way custom debug variables can be used to provide configuration for device-specific debug registers that then can be programmed via debug sequences.</p>
  168. <h1><a class="anchor" id="dbg_sqns_errors"></a>
  169. Ignore access errors</h1>
  170. <p>In some cases the debug access errors need to be ignored to support device-specific implemenation. For that the predefined debug access sequence can be overwritten by duplicating the original code with the error handling disabled in required places using predefined debug access variable <a class="el" href="debug_description.html#__errorcontrol">__errorcontrol</a>.</p>
  171. <p>Below is an example for an NXP IMXRT1051 family:</p>
  172. <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetSystem&quot;</span>&gt;</div>
  173. <div class="line"> &lt;block&gt;</div>
  174. <div class="line"> <span class="comment">// System Control Space (SCS) offset as defined in Armv6-M/Armv7-M.</span></div>
  175. <div class="line"> __var SCS_Addr = 0xE000E000;</div>
  176. <div class="line"> __var AIRCR_Addr = SCS_Addr + 0xD0C;</div>
  177. <div class="line"> __var DHCSR_Addr = SCS_Addr + 0xDF0;</div>
  178. <div class="line"> </div>
  179. <div class="line"> __errorcontrol = 0x1; <span class="comment">// Skip errors, write to AIRCR.SYSRESETREQ may not be able to finish with OK response</span></div>
  180. <div class="line"> <span class="comment">// Execute SYSRESETREQ via AIRCR</span></div>
  181. <div class="line"> Write32(AIRCR_Addr, 0x05FA0004);</div>
  182. <div class="line"> __errorcontrol = 0x0; <span class="comment">// Honor errors again</span></div>
  183. <div class="line"> </div>
  184. <div class="line"> DAP_Delay(20000); <span class="comment">// Delay of 20ms to let reset finish. Otherwise access to DHCSR can fail with too fast debug units.</span></div>
  185. <div class="line"> &lt;/block&gt;</div>
  186. <div class="line"> </div>
  187. <div class="line"> <span class="comment">//Reset Recovery: Wait for DHCSR.S_RESET_ST bit to clear on read </span></div>
  188. <div class="line"> &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;(Read32(DHCSR_Addr) &amp;amp; 0x02000000)&quot;</span> timeout=<span class="stringliteral">&quot;500000&quot;</span>/&gt;</div>
  189. <div class="line">&lt;/sequence&gt;</div>
  190. </div><!-- fragment --><p>In this implementation the standard system reset via AIRCR temporarily disables the DAP resulting in an access error. That could cause a debugger to disconnect. To overcome this the error handling is disabled before register write (<em>__errorcontrol = 0x1;</em>) and then enabled after it again. Additionally a delay is introduced (<em>DAP_Delay(20000);</em>) to allow reset to complete. The rest of the code is same as in the default <a class="el" href="debug_description.html#resetSystem">ResetSystem</a> implementation.</p>
  191. <h1><a class="anchor" id="dbg_sqns_trace"></a>
  192. Configure trace</h1>
  193. <p>A common case that requires use of debug access sequences is trace configuration. <a class="el" href="debug_description.html#default_sequences">Predefined debug access sequences</a> have two trace-related sequences: <a class="el" href="debug_description.html#TraceStart">TraceStart</a> and <a class="el" href="debug_description.html#TraceStop">TraceStop</a> that are being called when trace is enabled in the project. The <code>TraceStart</code> sequence is executed at the end of the initial debug connection to the target and after device reset while <code>TraceStop</code> is executed at the beginning of debug disconnect.</p>
  194. <p>By default these sequences are empty and often need to be implemented in the .pdsc file to support device-specific behavior, for example to differentiate configuration for 1-pin SWO trace and 5-pin ETM trace (TPIU).</p>
  195. <p>For example:</p>
  196. <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;TraceStart&quot;</span>&gt;</div>
  197. <div class="line"> &lt;block&gt;</div>
  198. <div class="line"> <span class="comment">// obtain project trace configuration from global variable __traceout</span></div>
  199. <div class="line"> __var traceSWO = (__traceout &amp;amp; 0x1) != 0;</div>
  200. <div class="line"> __var traceTPIU = (__traceout &amp;amp; 0x2) != 0;</div>
  201. <div class="line"> &lt;/block&gt;</div>
  202. <div class="line"> </div>
  203. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;traceSWO&quot;</span>&gt;</div>
  204. <div class="line"> &lt;block&gt;</div>
  205. <div class="line"> Sequence(<span class="stringliteral">&quot;EnableTraceSWO&quot;</span>);</div>
  206. <div class="line"> &lt;/block&gt;</div>
  207. <div class="line"> &lt;/control&gt;</div>
  208. <div class="line"> </div>
  209. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;traceTPIU&quot;</span>&gt;</div>
  210. <div class="line"> &lt;block&gt;</div>
  211. <div class="line"> Sequence(<span class="stringliteral">&quot;EnableTraceTPIU&quot;</span>);</div>
  212. <div class="line"> &lt;/block&gt;</div>
  213. <div class="line"> &lt;/control&gt;</div>
  214. <div class="line">&lt;/sequence&gt;</div>
  215. </div><!-- fragment --><p>Note that the code above uses following features allowed in debug access sequences:</p>
  216. <ul>
  217. <li>read access to a predefined global debug access variable <a class="el" href="debug_description.html#__traceout">__traceout</a>.</li>
  218. <li>implements the pre-defined debug sequence <code>TraceStart</code> </li>
  219. <li>calls custom debug sequences <code>EnableTraceSWO</code> ,<code>EnableTraceTPIU</code> </li>
  220. </ul>
  221. <p>Implementation of custom debug access sequences <code>traceEnableSWO</code> and <code>traceEnableTPIU</code> is a means to better structure the sequence implementations. Their content is highly vendor and device-specific. Common functionality of such sequences is to trace on the device, configure trace clock and assign trace pin(s). But the complexity of the code varies significantly depending on the device functionalities.</p>
  222. <p>Below is a simple example of <code>EnableTraceSWO</code> for Microchip SAMS70 family, that also demonstrates the use of a user-defined global debug access variable (<code>TracePCK3</code>) configurable via a debug configuration file <code>SAMx7.dbgconf</code>. See <a class="el" href="dbg_debug_sqns.html#dbg_sqns_dbgconf">Enable device-specific debug configurations</a> for additional information about custom global debug variables and *.dbgconf file.</p>
  223. <div class="fragment"><div class="line">...</div>
  224. <div class="line">&lt;family Dfamily=<span class="stringliteral">&quot;SAMV70&quot;</span> Dvendor=<span class="stringliteral">&quot;Microchip:3&quot;</span>&gt;</div>
  225. <div class="line"> &lt;debugvars configfile=<span class="stringliteral">&quot;samv70/keil/debug/SAMx7.dbgconf&quot;</span> version=<span class="stringliteral">&quot;1.0.0&quot;</span>&gt;</div>
  226. <div class="line"> <span class="comment">// Debug Access Variables</span></div>
  227. <div class="line"> __var TracePCK3 = 0x00000000; <span class="comment">// Trace Clock Source Selection and Prescaler</span></div>
  228. <div class="line"> &lt;/debugvars&gt;</div>
  229. <div class="line"> </div>
  230. <div class="line"> &lt;sequence name=<span class="stringliteral">&quot;EnableTraceSWO&quot;</span>&gt;</div>
  231. <div class="line"> &lt;block&gt;</div>
  232. <div class="line"> Write32(0x400E06E4, 0x504D4300); <span class="comment">// Disable PMC write protection</span></div>
  233. <div class="line"> Write32(0x400E064C, TracePCK3); <span class="comment">// Select clock source and prescaler for PCK3</span></div>
  234. <div class="line"> Write32(0x400E0600, (1 &amp;lt;&amp;lt; 11)); <span class="comment">// Enable PCK3</span></div>
  235. <div class="line"> &lt;/block&gt;</div>
  236. <div class="line"> &lt;/sequence&gt;</div>
  237. <div class="line"> ...</div>
  238. </div><!-- fragment --><p>Some devices can require that trace clock is enabled already at <a class="el" href="debug_description.html#DebugDeviceUnlock">DebugDeviceUnlock</a> sequence to ensure that access to global trace components is available when reading the ROM table and processor features. In such cases corresponding functionality needs to be moved from <b>TraceStart</b> to <b>DebugDeviceUnlock</b> sequence and check if trace is enabled via the <b>__traceout</b> variable.</p>
  239. <h1><a class="anchor" id="dbg_sqns_reset"></a>
  240. Implement reset for debug access</h1>
  241. <p>This section explains reset debug sequences for systems with a single CPU. Multi-core specifics are covered in <a class="el" href="dbg_debug_sqns.html#dbg_sqns_multicore">Handle debug in multi-core systems</a>.</p>
  242. <p>Reset is an important part of debug operation and is used to bring the device into a known state from which debug connection can be reliably established. Reset also allows users to debug their code from the very beginning. In the typical case when user initiates a debug session the debugger connects to the device, and resets the processor to ensure its fresh start, and then stops the CPU before user application is started.</p>
  243. <p>Sometimes it is needed to connect to a running target ("hot debug") without any resets performed when establishing a debug connection. Since there is no resets this is out of scope for the current section.</p>
  244. <p>The figure below shows an example reset flow in a debugger (copied from <a class="el" href="debug_description.html#usage_of_sequences">Usage of debug access sequences</a>):</p>
  245. <div class="image">
  246. <img src="Reset.png" alt="Reset.png"/>
  247. </div>
  248. <p><b>CPU halt and ResetCatchSet</b></p>
  249. <p>In the flow shown above the debugger first decides whether to halt the processor after the reset or not. This decision depends on the project configuration but also on when and how the reset is requested (automatically by debugger during or after debug connect, or manually by user through IDE, etc.).</p>
  250. <p>If processor halt after reset is needed then <a class="el" href="debug_description.html#resetCatchSet">ResetCatchSet</a> sequence is executed before performing the reset operation. Default implementation of <b>ResetCatchSet</b> enables and configures Cortex-M Reset Vector Catch functionality so that the core is stopped right after reset thus allowing users to debug the program from the very start. In some cases <b>ResetCatchSet</b> needs to be overwritten, for example for <a class="el" href="dbg_debug_sqns.html#dbg_sqns_boot">Support bootloader operation</a>.</p>
  251. <p><b>Reset types</b></p>
  252. <p>There are 3 predefined reset types and a custom reset type that debugger chooses from when performing a reset. The choice depends on the project configuration and <a class="el" href="pdsc_family_pg.html#defaultResetSequence">defaultResetSequence</a> value. Corresponding reset debug sequence is executed to perform required reset type.</p>
  253. <p>The reset types are listed below with details described in the referenced documentation.</p>
  254. <ul>
  255. <li><a class="el" href="debug_description.html#resetHardware_Descr">ResetHardware</a> is a system-wide reset without debug domain executed via the dedicated debugger reset line, e.g. nRST.</li>
  256. <li><a class="el" href="debug_description.html#resetSystem_Descr">ResetSystem</a> is a software-triggered system-wide reset that preserves established debug connection.</li>
  257. <li><a class="el" href="debug_description.html#resetProcessor_Descr">ResetProcessor</a> is a software-triggered local reset for a processor only.</li>
  258. <li><b>CustomResetName</b> sequence is used when a user-defined debug sequence is assigned to the <a class="el" href="pdsc_family_pg.html#defaultResetSequence">defaultResetSequence</a> attribute. This can be implemented when very special reset type is needed that cannot be performed by modifying predefined reset types.</li>
  259. </ul>
  260. <p><a class="anchor" id="dbg_sqns_reset_catchClear"></a><b>CPU halt and ResetCatchClear</b></p>
  261. <p>After reset is performed and the processor is halted (on the breakpoint enabled in <b>ResetCatchSet</b>) the <a class="el" href="debug_description.html#resetCatchClear">ResetCatchClear</a> sequence is executed. The default implementation may need to be overwritten to support bootloader as explaine in <a class="el" href="dbg_debug_sqns.html#dbg_sqns_boot">Support bootloader operation</a>.</p>
  262. <h1><a class="anchor" id="dbg_sqns_boot"></a>
  263. Support bootloader operation</h1>
  264. <p>Systems with built-in ROM bootloader often require special handling to ensure that debug is correctly started from the user application.</p>
  265. <p>In particular the reset flow described in <a class="el" href="dbg_debug_sqns.html#dbg_sqns_reset">Implement reset for debug access</a> most likely needs special adjustments for bootloader operation. After device reset the bootloader gets executed first. The debugger needs to take that into account and stop the processor with a breakpoint just before the application is started. For some devices this is also essential because debug can be disabled during bootloader execution for asset protection purposes.</p>
  266. <p>The default implementation of <a class="el" href="debug_description.html#resetCatchSet">ResetCatchSet</a> sequence halts the core right after reset. This however would be before the bootloader is started and hence may be not relevant for application development or even not possible to debug if bootloader code is not available.</p>
  267. <p>To overcome this problem the <b>ResetCatchSet</b> sequence needs to be overwritten in the .pdsc file of the Device Family Pack (DFP). In constrast to the default implementation the Reset Vector Catch shall be disabled allowing uninterrupted bootloader execution after reset. To halt the core before the application starts the sequence additionally sets a breakpoint at the Reset Vector, where the execution jumps to after bootloader is finished.</p>
  268. <p><a class="anchor" id="example1_resetCatchSet"></a><b>Example 1: ResetCatchSet</b></p>
  269. <p>The code below gives an example for an Armv8-M system with the vector table placed at address 0x00000000:</p>
  270. <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetCatchSet&quot;</span>&gt;</div>
  271. <div class="line"> &lt;block&gt;</div>
  272. <div class="line"> __var DHCSR_Addr = 0xE000EDF0;</div>
  273. <div class="line"> __var DEMCR_Addr = 0xE000EDFC;</div>
  274. <div class="line"> __var FP_CTRL_Addr = 0xE0002000;</div>
  275. <div class="line"> __var FP_COMP0_Addr = 0xE0002008;</div>
  276. <div class="line"> __var FPB_KEY = 0x00000002;</div>
  277. <div class="line"> __var FPB_ENABLE = 0x00000001;</div>
  278. <div class="line"> __var value = 0;</div>
  279. <div class="line"> __var resetVect = 0x00000000;</div>
  280. <div class="line"> </div>
  281. <div class="line"> value = Read32(DEMCR_Addr);</div>
  282. <div class="line"> Write32(DEMCR_Addr, (value &amp;amp; ~0x00000001)); <span class="comment">// Disable Reset Vector Catch</span></div>
  283. <div class="line"> </div>
  284. <div class="line"> resetVect = Read32(0x00000004); <span class="comment">// Read Reset Vector</span></div>
  285. <div class="line"> Write32(FP_COMP0_Addr, (resetVect | FPB_ENABLE)); <span class="comment">// Set BP0 to Reset Vector (ARMv8M)</span></div>
  286. <div class="line"> Write32(FP_CTRL_Addr, (FPB_KEY | FPB_ENABLE)); <span class="comment">// Enable FPB</span></div>
  287. <div class="line"> &lt;/block&gt;</div>
  288. <div class="line"> </div>
  289. <div class="line"> &lt;block&gt;</div>
  290. <div class="line"> Read32(DHCSR_Addr); <span class="comment">// Read DHCSR to clear potentially set DHCSR.S_RESET_ST bit</span></div>
  291. <div class="line"> &lt;/block&gt;</div>
  292. <div class="line">&lt;/sequence&gt;</div>
  293. </div><!-- fragment --><p>After reset is performed and the processor is halted (on the breakpoint enabled in <b>ResetCatchSet</b>) the <a class="el" href="debug_description.html#resetCatchClear">ResetCatchClear</a> sequence is executed. There in addition to the default functionality we need to clear the breakpoint introduced in the customized <b>ResetCatchSet</b> sequence.</p>
  294. <p><a class="anchor" id="example1_resetCatchClear"></a><b>Example 1: ResetCatchClear </b></p>
  295. <p>Below is a <b>ResetCatchClear</b> function for an Armv8-M core that corresponds to the <b>ResetCatchSet</b> sequence shown in <a class="el" href="dbg_debug_sqns.html#example1_resetCatchSet">Example 1: ResetCatchSet</a>:</p>
  296. <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetCatchClear&quot;</span>&gt;</div>
  297. <div class="line"> &lt;block&gt;</div>
  298. <div class="line"> __var DEMCR_Addr = 0xE000EDFC;</div>
  299. <div class="line"> __var FP_CTRL_Addr = 0xE0002000;</div>
  300. <div class="line"> __var FP_COMP0_Addr = 0xE0002008;</div>
  301. <div class="line"> __var FPB_KEY = 0x00000002;</div>
  302. <div class="line"> __var value = 0;</div>
  303. <div class="line"> </div>
  304. <div class="line"> value = Read32(DEMCR_Addr);</div>
  305. <div class="line"> Write32(DEMCR_Addr, (value &amp;amp; ~0x00000001)); <span class="comment">// Disable Reset Vector Catch in DEMCR</span></div>
  306. <div class="line"> </div>
  307. <div class="line"> Write32(FP_COMP0_Addr, 0x00000000); <span class="comment">// Clear BP0</span></div>
  308. <div class="line"> Write32(FP_CTRL_Addr, FPB_KEY ); <span class="comment">// Disable FPB</span></div>
  309. <div class="line"> &lt;/block&gt;</div>
  310. <div class="line">&lt;/sequence&gt;</div>
  311. </div><!-- fragment --><p><a class="anchor" id="example2_resetCatchSet"></a><b>Example 2: ResetCatchSet</b></p>
  312. <p>In some cases the <b>ResetCatchSet</b> sequence shall behave differently depending on where the obtained Reset Vector is located. Such differentiation can be introduced using XML <b>&lt;control&gt;</b> element. For example Cortex-M0/M0+/M1/M3/M4 cores have a FBP/BPU limitations that doesn't allow to set an FPB breakpoint for code memory above 0x20000000. For systems that have firmware located above this address (mostly in large external flash) the debugger can just rely on the Reset Vector Catch to stop right after reset and can't jump to the reset vector. Here is corresponding debug sequence:</p>
  313. <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetCatchSet&quot;</span>&gt;</div>
  314. <div class="line"> &lt;block&gt;</div>
  315. <div class="line"> __var DHCSR_Addr = 0xE000EDF0;</div>
  316. <div class="line"> __var DEMCR_Addr = 0xE000EDFC;</div>
  317. <div class="line"> __var FPB_BKPT_H = 0x80000000;</div>
  318. <div class="line"> __var FPB_BKPT_L = 0x40000000;</div>
  319. <div class="line"> __var FPB_COMP_M = 0x1FFFFFFC;</div>
  320. <div class="line"> __var FPB_KEY = 0x00000002;</div>
  321. <div class="line"> __var FPB_ENABLE = 0x00000001;</div>
  322. <div class="line"> __var value = 0;</div>
  323. <div class="line"> __var resetVect = 0x00000000;</div>
  324. <div class="line"> </div>
  325. <div class="line"> <span class="comment">// Run over Bootloader</span></div>
  326. <div class="line"> value = Read32(DEMCR_Addr);</div>
  327. <div class="line"> Write32(DEMCR_Addr, (value &amp;amp; ~0x00000001)); <span class="comment">// Disable Reset Vector Catch</span></div>
  328. <div class="line"> </div>
  329. <div class="line"> Write32(0x40000000, 0x00000002); <span class="comment">// Map Flash to Vectors</span></div>
  330. <div class="line"> resetVect = Read32 (0x00000004); <span class="comment">// Read Reset Vector</span></div>
  331. <div class="line"> &lt;/block&gt;</div>
  332. <div class="line"> </div>
  333. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;resetVect &amp;lt; 0x20000000&quot;</span> info=<span class="stringliteral">&quot;Set and enable breakpoint&quot;</span>&gt;</div>
  334. <div class="line"> &lt;block&gt;</div>
  335. <div class="line"> <span class="comment">//determine if instruction is at upper or lower half-word in an aligned 4-byte block</span></div>
  336. <div class="line"> value = ((resetVect &amp;amp; 0x02) ? FPB_BKPT_H : FPB_BKPT_L) | (resetVect &amp;amp; FPB_COMP_M) | FPB_ENABLE ;</div>
  337. <div class="line"> Write32(0xE0002008, value); <span class="comment">// Set BP0 to Reset Vector</span></div>
  338. <div class="line"> value = FPB_KEY | FPB_ENABLE;</div>
  339. <div class="line"> Write32(0xe0002000, value); <span class="comment">// Enable FPB</span></div>
  340. <div class="line"> &lt;/block&gt;</div>
  341. <div class="line"> &lt;/control&gt;</div>
  342. <div class="line"> </div>
  343. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;resetVect &amp;gt;= 0x20000000&quot;</span> info=<span class="stringliteral">&quot;Enable reset vector catch&quot;</span>&gt;</div>
  344. <div class="line"> &lt;block&gt;</div>
  345. <div class="line"> <span class="comment">// Enable Reset Vector Catch in DEMCR</span></div>
  346. <div class="line"> value = Read32(DEMCR_Addr);</div>
  347. <div class="line"> Write32(DEMCR_Addr, (value | 0x00000001));</div>
  348. <div class="line"> &lt;/block&gt;</div>
  349. <div class="line"> &lt;/control&gt;</div>
  350. <div class="line"> </div>
  351. <div class="line"> &lt;block&gt;</div>
  352. <div class="line"> Read32(DHCSR_Addr); <span class="comment">// Read DHCSR to clear potentially set DHCSR.S_RESET_ST bit</span></div>
  353. <div class="line"> &lt;/block&gt;</div>
  354. <div class="line"> </div>
  355. <div class="line">&lt;/sequence&gt;</div>
  356. </div><!-- fragment --><p><b>Example 2: ResetCatchClear</b></p>
  357. <p>The <b>ResetCatchClear</b> sequence from <a class="el" href="dbg_debug_sqns.html#example1_resetCatchClear">Example 1</a> can also be used with the <a class="el" href="dbg_debug_sqns.html#example2_resetCatchSet">Example 2: ResetCatchSet</a> as there's no special handling additionally required.</p>
  358. <p><b>Other modifications</b></p>
  359. <p>Additionally the reset behavior can be made configurable per project via custom global debug access variables and a *.dbgconf file. See <a class="el" href="dbg_debug_sqns.html#dbg_sqns_dbgconf">Enable device-specific debug configurations</a> for additional details.</p>
  360. <p>In some cases also the reset sequences (<b>ResetSystem</b>, <b>ResetProcessor</b>, <b>ResetHardware</b>) need to be adjusted to ensure proper bootloader handling. For example for debug authentication or bootloader configuration purposes. The actual implementation is very device and use case specific.</p>
  361. <h1><a class="anchor" id="dbg_sqns_multicore"></a>
  362. Handle debug in multi-core systems</h1>
  363. <p>To correctly debug multicore systems, first of all the debug connection shall be correctly specified using <a class="el" href="pdsc_family_pg.html#element_debug">debug</a>. See <a class="el" href="dbg_setup_access.html#dbg_debug">Specify CPU debug connection</a> for description and examples.</p>
  364. <p>To achieve correct debug operation on a multi-core system often modification of the predefined debug sequences are required. The actual implementation very much depends on the particular system architecture.</p>
  365. <p>The <a class="el" href="debug_description.html#usage_of_sequences">Usage of debug access sequences</a> provides example flows for debugger operation. These flows shall be analyzed for particular system and different implementations may be required for each available core.</p>
  366. <p>Recommendations described in previous sections such as <a class="el" href="dbg_debug_sqns.html#dbg_sqns_errors">error-handling</a>, <a class="el" href="dbg_debug_sqns.html#dbg_sqns_trace">trace configuration</a>, <a class="el" href="dbg_debug_sqns.html#dbg_sqns_boot">bootloader support</a> can be applied for individual cores in the multi-core system as well. Using the <b>Pname</b> identifier in the <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> element it is possible to specify the debug access sequence for a particular core.</p>
  367. <p>The most multi-core Cortex-M systems have their CPUs intended for running different applications and not for load balancing. For simplicity we consider further such an assymmetric (AMP) dual-core system. In this system the CPUs can have either equal roles or master-slave dependancy. The roles can also be either predefined or configurable.</p>
  368. <p>Sections below explain additional use-cases specific for multi-core systems:</p>
  369. <ul>
  370. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_multicore_reset">Reset sequences</a></li>
  371. <li><a class="el" href="dbg_debug_sqns.html#dbg_sqns_multicore_debug">Debug sequences for different use cases</a></li>
  372. </ul>
  373. <h2><a class="anchor" id="dbg_sqns_multicore_reset"></a>
  374. Reset sequences</h2>
  375. <p>Multi-core devices often have quite unique reset systems that a debugger shall use correctly when connecting to a target and during debug operation. For that the default reset debug sequences (see <a class="el" href="dbg_debug_sqns.html#dbg_sqns_reset">Implement reset for debug access</a>) need to be overwritten or require processor-specific implementations. Below is an overview for different reset types:</p>
  376. <ul>
  377. <li><a class="el" href="debug_description.html#resetHardware">ResetHardware</a> is a hardware-triggered system-wide reset and should not be differentiated per individual core. However its default implementation may need to be overwritten in order to take the system configuration into account (master-slave, etc.).</li>
  378. <li><a class="el" href="debug_description.html#resetSystem">ResetSystem</a> is a software-triggered system-wide reset. It is assumed to be applied to the whole system and shouldn't be core-specific. But same as with <b>ResetHardware</b> it may require different implementation, for example to ensure correct reset in master-slave systems.</li>
  379. <li><a class="el" href="debug_description.html#resetProcessor">ResetProcessor</a> is a software-triggered local reset for the specified CPU (or if required CPU subsystem). It needs to be differentiated for each core and is done by overwriting predefined <b>ResetProcessor</b> sequence for each CPU. Custom debug access sequences can be used to simplify code structure as shown in the example below:</li>
  380. </ul>
  381. <div class="fragment"><div class="line">&lt;sequences&gt;</div>
  382. <div class="line"><span class="comment">//-- Begin: ResetProcessor Sequence for Cortex-M4</span></div>
  383. <div class="line"> &lt;sequence name=<span class="stringliteral">&quot;ResetProcessor&quot;</span> Pname=<span class="stringliteral">&quot;CM4&quot;</span>&gt;</div>
  384. <div class="line"> &lt;block&gt;</div>
  385. <div class="line"> Sequence(<span class="stringliteral">&quot;ResetProcessor_CM4&quot;</span>);</div>
  386. <div class="line"> &lt;/block&gt;</div>
  387. <div class="line"> &lt;/sequence&gt;</div>
  388. <div class="line"></div>
  389. <div class="line"><span class="comment">//-- Begin: ResetProcessor Sequence for Cortex-M0</span></div>
  390. <div class="line"> &lt;sequence name=<span class="stringliteral">&quot;ResetProcessor&quot;</span> Pname=<span class="stringliteral">&quot;CM0plus&quot;</span>&gt;</div>
  391. <div class="line"> &lt;block&gt;</div>
  392. <div class="line"> Sequence(<span class="stringliteral">&quot;ResetProcessor_CM0plus&quot;</span>);</div>
  393. <div class="line"> &lt;/block&gt;</div>
  394. <div class="line"> &lt;/sequence&gt;</div>
  395. <div class="line"> ...</div>
  396. <div class="line">&lt;/sequences&gt;</div>
  397. </div><!-- fragment --><p>In the example above the reset functionality itself is implemented in the user-defined (custom) debug sequences <code>ResetProcessor_CM0plus</code> and <code>ResetProcessor_CM4</code>.</p>
  398. <p>The same <b>Pname</b> identifier shall be used in <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> element as defined in the corresponding <a class="el" href="pdsc_family_pg.html#element_processor">processor</a> element ('CM0plus' or 'CM4' in this example).</p>
  399. <p>Following the same concept the <a class="el" href="debug_description.html#resetCatchSet">ResetCatchSet</a> and <a class="el" href="debug_description.html#resetCatchClear">ResetCatchClear</a> sequences may need to be overwritten for individual cores, as reset vectors for different cores are located in different areas and hence the breakpoint for halt after reset shall be set differently. The approach is very similar to the one described in <a class="el" href="dbg_debug_sqns.html#dbg_sqns_boot">Support bootloader operation</a>.</p>
  400. <h2><a class="anchor" id="dbg_sqns_multicore_debug"></a>
  401. Debug sequences for different use cases</h2>
  402. <p>When debugging an application running on a processor in a multi-core system, it is often required to have special control over the processors in the system. For example in a master-slave system it may be desired to debug only the application on the slave. For that debugger needs to ensure that the slave is running independent from the master. Debug-related sequence <a class="el" href="debug_description.html#debugCoreStart">DebugCoreStart</a> can be used for that. Below is an example for NXP LPC4300 family, with <b>ReleaseM0OnConnect</b> is a configuration parameter specified via *.dbgconf as explained in <a class="el" href="dbg_debug_sqns.html#dbg_sqns_dbgconf">Enable device-specific debug configurations</a>. </p>
  403. <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugCoreStart&quot;</span> Pname=<span class="stringliteral">&quot;Cortex-M0&quot;</span>&gt;</div>
  404. <div class="line"> &lt;block&gt;</div>
  405. <div class="line"> <span class="comment">// Default implementation</span></div>
  406. <div class="line"> <span class="comment">// Enable Core Debug via DHCSR</span></div>
  407. <div class="line"> Write32(0xE000EDF0, 0xA05F0001);</div>
  408. <div class="line"> &lt;/block&gt;</div>
  409. <div class="line"></div>
  410. <div class="line"> &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;ReleaseM0OnConnect&quot;</span>&gt;</div>
  411. <div class="line"> &lt;block&gt;</div>
  412. <div class="line"> <span class="comment">// Release M0 from reset</span></div>
  413. <div class="line"> Write32(0x40053104, 0x00000000); <span class="comment">// RESET_CTRL1: Clear M0APP_RST (Bit 24)</span></div>
  414. <div class="line"> &lt;/block&gt;</div>
  415. <div class="line"> &lt;/control&gt;</div>
  416. <div class="line">&lt;/sequence&gt; </div>
  417. </div><!-- fragment --> </div></div><!-- contents -->
  418. </div><!-- doc-content -->
  419. <!-- start footer part -->
  420. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  421. <ul>
  422. <li class="navelem"><a class="el" href="coresight_setup.html">Debug Setup with CMSIS-Pack</a></li><li class="navelem"><a class="el" href="dbg_setup_tutorial.html">Debug Setup Tutorial</a></li>
  423. <li class="footer">Generated on Thu Apr 9 2020 15:49:54 for CMSIS-Pack Version 1.6.3 by Arm Ltd. All rights reserved.
  424. <!--
  425. <a href="http://www.doxygen.org/index.html">
  426. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6
  427. -->
  428. </li>
  429. </ul>
  430. </div>
  431. </body>
  432. </html>