{"id":295210,"date":"2019-11-26T09:00:38","date_gmt":"2019-11-26T09:00:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295210"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295210","title":{"rendered":"\u0421\u0447\u0451\u0442\u0447\u0438\u043a DWT"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/476582\/\">\u041c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043e\u0431 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0432\u0435\u0449\u0438\u0446\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0439 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 \u043c\u043e\u0434\u0443\u043b\u044f DWT (Data Watchpoint and Trace unit) \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0443 stm32.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043c\u043e\u0434\u0443\u043b\u044c DWT \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u043e\u0432\u0438\u043d\u0430 (\u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/infocenter.arm.com\/help\/topic\/com.arm.doc.ddi0337h\/DDI0337H_cortex_m3_r2p0_trm.pdf\">\u0442\u0443\u0442<\/a> \u0441\u0442\u0440. 75), \u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043e\u043d \u0437\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u0440\u0435\u0447\u044c \u043d\u0435 \u043e \u043c\u043e\u0434\u0443\u043b\u0435 \u0432 \u0446\u0435\u043b\u043e\u043c, \u0430 \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u2014 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u0442\u0430\u043a\u0442\u043e\u0432 (\u0434\u0430\u043b\u0435\u0435 \u0441\u0447\u0451\u0442\u0447\u0438\u043a DWT).<\/p>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438, \u0441\u0447\u0451\u0442\u0447\u0438\u043a DWT \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e 32-\u0445 \u0431\u0438\u0442\u043d\u044b\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0447\u043a\u0443 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0442\u0430\u043a\u0442\u043e\u043c. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u043e\u0436\u0435\u043c \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043a\u0443\u0441\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u0442\u0430\u043a\u0442\u0430\u0445, \u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434\u043d\u044b\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438. \u042d\u0442\u043e\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439.<\/p>\n<p>  \u0427\u0442\u043e\u0431 \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u2026<\/p>\n<pre><code class=\"cpp\">  #define    DWT_CYCCNT    *(volatile uint32_t*)0xE0001004   #define    DWT_CONTROL   *(volatile uint32_t*)0xE0001000   #define    SCB_DEMCR     *(volatile uint32_t*)0xE000EDFC    char str[16] = {0,};   uint32_t count_tic = 0;    SCB_DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;\/\/ \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DWT   DWT_CONTROL|= DWT_CTRL_CYCCNTENA_Msk; \/\/ \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a   DWT_CYCCNT = 0;\/\/ \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a    \/\/ \u0437\u0434\u0435\u0441\u044c \u043a\u0443\u0441\u043e\u043a \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b    count_tic = DWT_CYCCNT; \/\/ \u043a\u043e\u043b-\u0432\u043e \u0442\u0430\u043a\u0442\u043e\u0432   snprintf(str, 16, &quot;Takt %lu\\n&quot;, count_tic);   HAL_UART_Transmit(&huart1, (uint8_t*)str, strlen(str), 1000); <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/istarik.ru\/uploads\/images\/00\/00\/01\/2019\/10\/09\/d1687b.png\" alt=\"image\"\/><br \/>  <i>\u0418\u0437\u043c\u0435\u0440\u0438\u043b HAL_Delay(1000) \u043d\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0435 72\u041c\u0413\u0446.<\/i><\/p>\n<p>  \u0414\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434\u043d\u044b\u0445 \u043f\u0430\u0443\u0437 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b <b>delay_micros.h<\/b>\u2026<\/p>\n<pre><code class=\"cpp\">#ifndef __DELAY_US_H__ #define __DELAY_US_H__  #ifdef __cplusplus  extern &quot;C&quot; { #endif  \/******************************************************************************\/ \/* \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 *\/ #include &quot;main.h&quot;  \/\/#define DWT_CONTROL *(volatile unsigned long *)0xE0001000 \/\/#define SCB_DEMCR   *(volatile unsigned long *)0xE000EDFC  \/******************************************************************************\/ \/* inline func *\/ __STATIC_INLINE void DWT_Init(void) { \tCoreDebug-&gt;DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; \/\/ \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a \tDWT-&gt;CTRL |= DWT_CTRL_CYCCNTENA_Msk;   \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a }  __STATIC_INLINE void delay_us(uint32_t us) { \tuint32_t us_count_tic =  us * (SystemCoreClock \/ 1000000U); \tDWT-&gt;CYCCNT = 0U; \twhile(DWT-&gt;CYCCNT &lt; us_count_tic); }  #ifdef __cplusplus } #endif #endif \/\/__DELAY_US_H__ <\/code><\/pre>\n<p>  \u2026 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442. <\/p>\n<p>  \u0412 main.c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u043a\u043b\u044e\u0434\u2026<\/p>\n<pre><code class=\"cpp\">#include &quot;delay_micros.h&quot; <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u2026<\/p>\n<pre><code class=\"cpp\">DWT_Init(); <\/code><\/pre>\n<p>  \u0410 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a\u2026<\/p>\n<pre><code class=\"cpp\">delay_us(100); \/\/ 100 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434 <\/code><\/pre>\n<p>  \u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"https:\/\/github.com\/stDstm\/Example_STM32F103\/tree\/master\/delay_micros_one_file\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  \u042d\u0442\u043e \u0432\u0441\u0451.<\/p><\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/476582\/\"> https:\/\/habr.com\/ru\/post\/476582\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/476582\/\">\u041c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043e\u0431 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0432\u0435\u0449\u0438\u0446\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0439 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 \u043c\u043e\u0434\u0443\u043b\u044f DWT (Data Watchpoint and Trace unit) \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0443 stm32.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-295210","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295210"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295210\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}