You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
8.9KB

  1. <html>
  2. <head>
  3. <title>CMSIS Debug Support</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
  6. <meta name="ProgId" content="FrontPage.Editor.Document">
  7. <style>
  8. <!--
  9. /*-----------------------------------------------------------
  10. Keil Software CHM Style Sheet
  11. -----------------------------------------------------------*/
  12. body { color: #000000; background-color: #FFFFFF; font-size: 75%; font-family:
  13. Verdana, Arial, 'Sans Serif' }
  14. a:link { color: #0000FF; text-decoration: underline }
  15. a:visited { color: #0000FF; text-decoration: underline }
  16. a:active { color: #FF0000; text-decoration: underline }
  17. a:hover { color: #FF0000; text-decoration: underline }
  18. h1 { font-family: Verdana; font-size: 18pt; color: #000080; font-weight: bold;
  19. text-align: Center; margin-right: 3 }
  20. h2 { font-family: Verdana; font-size: 14pt; color: #000080; font-weight: bold;
  21. background-color: #CCCCCC; margin-top: 24; margin-bottom: 3;
  22. padding: 6 }
  23. h3 { font-family: Verdana; font-size: 10pt; font-weight: bold; background-color:
  24. #CCCCCC; margin-top: 24; margin-bottom: 3; padding: 6 }
  25. pre { font-family: Courier New; font-size: 10pt; background-color: #CCFFCC;
  26. margin-left: 24; margin-right: 24 }
  27. ul { list-style-type: square; margin-top: 6pt; margin-bottom: 0 }
  28. ol { margin-top: 6pt; margin-bottom: 0 }
  29. li { clear: both; margin-bottom: 6pt }
  30. table { font-size: 100%; border-width: 0; padding: 0 }
  31. th { color: #FFFFFF; background-color: #000080; text-align: left; vertical-align:
  32. bottom; padding-right: 6pt }
  33. tr { text-align: left; vertical-align: top }
  34. td { text-align: left; vertical-align: top; padding-right: 6pt }
  35. .ToolT { font-size: 8pt; color: #808080 }
  36. .TinyT { font-size: 8pt; text-align: Center }
  37. code { color: #000000; background-color: #E0E0E0; font-family: 'Courier New', Courier;
  38. line-height: 120%; font-style: normal }
  39. /*-----------------------------------------------------------
  40. Notes
  41. -----------------------------------------------------------*/
  42. p.note { font-weight: bold; clear: both; margin-bottom: 3pt; padding-top: 6pt }
  43. /*-----------------------------------------------------------
  44. Expanding/Contracting Divisions
  45. -----------------------------------------------------------*/
  46. #expand { text-decoration: none; margin-bottom: 3pt }
  47. img.expand { border-style: none; border-width: medium }
  48. div.expand { display: none; margin-left: 9pt; margin-top: 0 }
  49. /*-----------------------------------------------------------
  50. Where List Tags
  51. -----------------------------------------------------------*/
  52. p.wh { font-weight: bold; clear: both; margin-top: 6pt; margin-bottom: 3pt }
  53. table.wh { width: 100% }
  54. td.whItem { white-space: nowrap; font-style: italic; padding-right: 6pt; padding-bottom:
  55. 6pt }
  56. td.whDesc { padding-bottom: 6pt }
  57. /*-----------------------------------------------------------
  58. Keil Table Tags
  59. -----------------------------------------------------------*/
  60. table.kt { border: 1pt solid #000000 }
  61. th.kt { white-space: nowrap; border-bottom: 1pt solid #000000; padding-left: 6pt;
  62. padding-right: 6pt; padding-top: 4pt; padding-bottom: 4pt }
  63. tr.kt { }
  64. td.kt { color: #000000; background-color: #E0E0E0; border-top: 1pt solid #A0A0A0;
  65. padding-left: 6pt; padding-right: 6pt; padding-top: 2pt;
  66. padding-bottom: 2pt }
  67. /*-----------------------------------------------------------
  68. -----------------------------------------------------------*/
  69. -->
  70. </style>
  71. </head>
  72. <body>
  73. <h1>CMSIS Debug Support</h1>
  74. <hr>
  75. <h2>Cortex-M3 ITM Debug Access</h2>
  76. <p>
  77. The Cortex-M3 incorporates the Instrumented Trace Macrocell (ITM) that provides together with
  78. the Serial Viewer Output trace capabilities for the microcontroller system. The ITM has
  79. 32 communication channels which are able to transmit 32 / 16 / 8 bit values; two ITM
  80. communication channels are used by CMSIS to output the following information:
  81. </p>
  82. <ul>
  83. <li>ITM Channel 0: used for printf-style output via the debug interface.</li>
  84. <li>ITM Channel 31: is reserved for RTOS kernel awareness debugging.</li>
  85. </ul>
  86. <h2>Debug IN / OUT functions</h2>
  87. <p>CMSIS provides following debug functions:</p>
  88. <ul>
  89. <li>ITM_SendChar (uses ITM channel 0)</li>
  90. <li>ITM_ReceiveChar (uses global variable)</li>
  91. <li>ITM_CheckChar (uses global variable)</li>
  92. </ul>
  93. <h3>ITM_SendChar</h3>
  94. <p>
  95. <strong>ITM_SendChar</strong> is used to transmit a character over ITM channel 0 from
  96. the microcontroller system to the debug system. <br>
  97. Only a 8 bit value is transmitted.
  98. </p>
  99. <pre>
  100. static __INLINE uint32_t ITM_SendChar (uint32_t ch)
  101. {
  102. /* check if debugger connected and ITM channel enabled for tracing */
  103. if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) &amp;&amp;
  104. (ITM-&gt;TCR & ITM_TCR_ITMENA) &amp;&amp;
  105. (ITM-&gt;TER & (1UL &lt;&lt; 0)) )
  106. {
  107. while (ITM-&gt;PORT[0].u32 == 0);
  108. ITM-&gt;PORT[0].u8 = (uint8_t)ch;
  109. }
  110. return (ch);
  111. }</pre>
  112. <h3>ITM_ReceiveChar</h3>
  113. <p>
  114. ITM communication channel is only capable for OUT direction. For IN direction
  115. a globel variable is used. A simple mechansim detects if a character is received.
  116. The project to test need to be build with debug information.
  117. </p>
  118. <p>
  119. The globale variable <strong>ITM_RxBuffer</strong> is used to transmit a 8 bit value from debug system
  120. to microcontroller system. <strong>ITM_RxBuffer</strong> is 32 bit wide to enshure a proper handshake.
  121. </p>
  122. <pre>
  123. extern volatile int ITM_RxBuffer; /* variable to receive characters */
  124. </pre>
  125. <p>
  126. A dedicated bit pattern is used to determin if <strong>ITM_RxBuffer</strong> is empty
  127. or contains a valid value.
  128. </p>
  129. <pre>
  130. #define ITM_RXBUFFER_EMPTY 0x5AA55AA5 /* value identifying ITM_RxBuffer is ready for next character */
  131. </pre>
  132. <p>
  133. <strong>ITM_ReceiveChar</strong> is used to receive a 8 bit value from the debug system. The function is nonblocking.
  134. It returns the received character or '-1' if no character was available.
  135. </p>
  136. <pre>
  137. static __INLINE int ITM_ReceiveChar (void) {
  138. int ch = -1; /* no character available */
  139. if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
  140. ch = ITM_RxBuffer;
  141. ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
  142. }
  143. return (ch);
  144. }
  145. </pre>
  146. <h3>ITM_CheckChar</h3>
  147. <p>
  148. <strong>ITM_CheckChar</strong> is used to check if a character is received.
  149. </p>
  150. <pre>
  151. static __INLINE int ITM_CheckChar (void) {
  152. if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
  153. return (0); /* no character available */
  154. } else {
  155. return (1); /* character available */
  156. }
  157. }</pre>
  158. <h2>ITM Debug Support in uVision</h2>
  159. <p>
  160. uVision uses in a debug session the <strong>Debug (printf) Viewer</strong> window to
  161. display the debug data.
  162. </p>
  163. <p>Direction microcontroller system -&gt; uVision:</p>
  164. <ul>
  165. <li>
  166. Characters received via ITM communication channel 0 are written in a printf style
  167. to <strong>Debug (printf) Viewer</strong> window.
  168. </li>
  169. </ul>
  170. <p>Direction uVision -&gt; microcontroller system:</p>
  171. <ul>
  172. <li>Check if <strong>ITM_RxBuffer</strong> variable is available (only performed once).</li>
  173. <li>Read character from <strong>Debug (printf) Viewer</strong> window.</li>
  174. <li>If <strong>ITM_RxBuffer</strong> empty write character to <strong>ITM_RxBuffer</strong>.</li>
  175. </ul>
  176. <p class="Note">Note</p>
  177. <ul>
  178. <li><p>Current solution does not use a buffer machanism for trasmitting the characters.</p>
  179. </li>
  180. </ul>
  181. <h2>RTX Kernel awareness in uVision</h2>
  182. <p>
  183. uVision / RTX are using a simple and efficient solution for RTX Kernel awareness.
  184. No format overhead is necessary.<br>
  185. uVsion debugger decodes the RTX events via the 32 / 16 / 8 bit ITM write access
  186. to ITM communication channel 31.
  187. </p>
  188. <p>Following RTX events are traced:</p>
  189. <ul>
  190. <li>Task Create / Delete event
  191. <ol>
  192. <li>32 bit access. Task start address is transmitted</li>
  193. <li>16 bit access. Task ID and Create/Delete flag are transmitted<br>
  194. High byte holds Create/Delete flag, Low byte holds TASK ID.
  195. </li>
  196. </ol>
  197. </li>
  198. <li>Task switch event
  199. <ol>
  200. <li>8 bit access. Task ID of current task is transmitted</li>
  201. </ol>
  202. </li>
  203. </ul>
  204. <p class="Note">Note</p>
  205. <ul>
  206. <li><p>Other RTOS information could be retrieved via memory read access in a polling mode manner.</p>
  207. </li>
  208. </ul>
  209. <p class="MsoNormal"><span lang="EN-GB">&nbsp;</span></p>
  210. <hr>
  211. <p class="TinyT">Copyright © KEIL - An ARM Company.<br>
  212. All rights reserved.<br>
  213. Visit our web site at <a href="http://www.keil.com">www.keil.com</a>.
  214. </p>
  215. </body>
  216. </html>