{"action":"created","issue":{"url":"https://api.github.com/repos/OpenNuvoton/M2351BSP/issues/5","repository_url":"https://api.github.com/repos/OpenNuvoton/M2351BSP","labels_url":"https://api.github.com/repos/OpenNuvoton/M2351BSP/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/OpenNuvoton/M2351BSP/issues/5/comments","events_url":"https://api.github.com/repos/OpenNuvoton/M2351BSP/issues/5/events","html_url":"https://github.com/OpenNuvoton/M2351BSP/issues/5","id":422799787,"node_id":"MDU6SXNzdWU0MjI3OTk3ODc=","number":5,"title":"Measuring Execution Time of a Piece of Code","user":{"login":"user01-weeve","id":48725560,"node_id":"MDQ6VXNlcjQ4NzI1NTYw","avatar_url":"https://avatars3.githubusercontent.com/u/48725560?v=4","gravatar_id":"","url":"https://api.github.com/users/user01-weeve","html_url":"https://github.com/user01-weeve","followers_url":"https://api.github.com/users/user01-weeve/followers","following_url":"https://api.github.com/users/user01-weeve/following{/other_user}","gists_url":"https://api.github.com/users/user01-weeve/gists{/gist_id}","starred_url":"https://api.github.com/users/user01-weeve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/user01-weeve/subscriptions","organizations_url":"https://api.github.com/users/user01-weeve/orgs","repos_url":"https://api.github.com/users/user01-weeve/repos","events_url":"https://api.github.com/users/user01-weeve/events{/privacy}","received_events_url":"https://api.github.com/users/user01-weeve/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-03-19T15:31:15Z","updated_at":"2019-03-20T02:17:21Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\nI am trying to figure out exact number of CPU cycles taken by a piece of code. In one of the doc, I checked in use guide, DWT counter is mentioned in a block diagram which can be used to do this. But it doesn't work.\r\nBelow is the piece of code I tried:\r\nuint32_t clock_cycles_counter;\r\nvolatile unsigned int *DWT_CYCCNT = (uint32_t *)0xE0001004; //address of the register\r\nvolatile unsigned int *DWT_CONTROL = (uint32_t *)0xE0001000; //address of the register\r\nvolatile unsigned int *SCB_DEMCR = (uint32_t *)0xE000EDFC; //address of the register\r\n// configure and start the clock cycles counter\r\nclock_cycles_counter = 0;\r\n*SCB_DEMCR = *SCB_DEMCR | 0x01000000;\r\n*DWT_CYCCNT = 0;\r\n*DWT_CONTROL |=  1;\r\n//////\r\n//////Code to be measured\r\n/////\r\n// stop and get the counter value\r\n*DWT_CONTROL &= ~1;\r\nclock_cycles_counter = *DWT_CYCCNT;\r\n\r\n// print the counter value\r\nprintf(\"counter %d\\n\\r\", clock_cycles_counter);\r\n\r\nAlways get '0'. Is the peripheral address mapped in above program correct?\r\nHas anyone tried another way to measure the time?\r\nThank in advance\r\n"},"comment":{"url":"https://api.github.com/repos/OpenNuvoton/M2351BSP/issues/comments/474657121","html_url":"https://github.com/OpenNuvoton/M2351BSP/issues/5#issuecomment-474657121","issue_url":"https://api.github.com/repos/OpenNuvoton/M2351BSP/issues/5","id":474657121,"node_id":"MDEyOklzc3VlQ29tbWVudDQ3NDY1NzEyMQ==","user":{"login":"wschang0","id":18463631,"node_id":"MDQ6VXNlcjE4NDYzNjMx","avatar_url":"https://avatars1.githubusercontent.com/u/18463631?v=4","gravatar_id":"","url":"https://api.github.com/users/wschang0","html_url":"https://github.com/wschang0","followers_url":"https://api.github.com/users/wschang0/followers","following_url":"https://api.github.com/users/wschang0/following{/other_user}","gists_url":"https://api.github.com/users/wschang0/gists{/gist_id}","starred_url":"https://api.github.com/users/wschang0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wschang0/subscriptions","organizations_url":"https://api.github.com/users/wschang0/orgs","repos_url":"https://api.github.com/users/wschang0/repos","events_url":"https://api.github.com/users/wschang0/events{/privacy}","received_events_url":"https://api.github.com/users/wschang0/received_events","type":"User","site_admin":false},"created_at":"2019-03-20T02:17:21Z","updated_at":"2019-03-20T02:17:21Z","author_association":"CONTRIBUTOR","body":"M2351 doesn’t support DWT cycle counter.\r\nThe clock source of SysTick could be the same as CPU.\r\nTherefore, you could use SysTick timer for cycle count.\r\n\r\nFrom: user01-weeve [mailto:notifications@github.com]\r\nSent: Tuesday, March 19, 2019 11:31 PM\r\nTo: OpenNuvoton/M2351BSP\r\nCc: Subscribed\r\nSubject: [OpenNuvoton/M2351BSP] Measuring Execution Time of a Piece of Code (#5)\r\n\r\n\r\nHi,\r\nI am trying to figure out exact number of CPU cycles taken by a piece of code. In one of the doc, I checked in use guide, DWT counter is mentioned in a block diagram which can be used to do this. But it doesn't work.\r\nBelow is the piece of code I tried:\r\nuint32_t clock_cycles_counter;\r\nvolatile unsigned int *DWT_CYCCNT = (uint32_t *)0xE0001004; //address of the register\r\nvolatile unsigned int *DWT_CONTROL = (uint32_t *)0xE0001000; //address of the register\r\nvolatile unsigned int *SCB_DEMCR = (uint32_t *)0xE000EDFC; //address of the register\r\n// configure and start the clock cycles counter\r\nclock_cycles_counter = 0;\r\n*SCB_DEMCR = *SCB_DEMCR | 0x01000000;\r\n*DWT_CYCCNT = 0;\r\n*DWT_CONTROL |= 1;\r\n//////\r\n//////Code to be measured\r\n/////\r\n// stop and get the counter value\r\n*DWT_CONTROL &= ~1;\r\nclock_cycles_counter = *DWT_CYCCNT;\r\n\r\n// print the counter value\r\nprintf(\"counter %d\\n\\r\", clock_cycles_counter);\r\n\r\nAlways get '0'. Is the peripheral address mapped in above program correct?\r\nHas anyone tried another way to measure the time?\r\nThank in advance\r\n\r\n—\r\nYou are receiving this because you are subscribed to this thread.\r\nReply to this email directly, view it on GitHub<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_OpenNuvoton_M2351BSP_issues_5&d=DwMCaQ&c=ue8mO8zgC4VZ4q_aNVKt8G9MC01UFDmisvMR1k-EoDM&r=aH6l7Kw2v9MTu3F0oJ3Ab6AQ_svbvBfhszKwCjHTnIo&m=-LIfvFuD2jmMAxH6McICMJdBKx4pFSkeMFB_uFav7-U&s=SsEF7WkYEaXU3aq2wm9l978g03HvAMVEKxII6ojnGH0&e=>, or mute the thread<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_ARm7j3uT7jlsSx9yM2GrNJesf2UwpIj-2Dks5vYQLDgaJpZM4b8cBZ&d=DwMCaQ&c=ue8mO8zgC4VZ4q_aNVKt8G9MC01UFDmisvMR1k-EoDM&r=aH6l7Kw2v9MTu3F0oJ3Ab6AQ_svbvBfhszKwCjHTnIo&m=-LIfvFuD2jmMAxH6McICMJdBKx4pFSkeMFB_uFav7-U&s=pUjWQHf3kXcqsDaruJ-SVrIbHX3wllgs4YrVmOKA9Ps&e=>.\r\n\r\n\r\n===========================================================================================\r\nThe privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.\r\n"}}
{"actor":{"display_login":"wschang0"}}