OpenNuvoton / M2351BSP

M2351 BSP
15 stars 9 forks source link

Measuring Execution Time of a Piece of Code #5

Closed user01-weeve closed 5 years ago

user01-weeve commented 5 years ago

Hi, I 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. Below is the piece of code I tried: uint32_t clock_cycles_counter; volatile unsigned int DWT_CYCCNT = (uint32_t )0xE0001004; //address of the register volatile unsigned int DWT_CONTROL = (uint32_t )0xE0001000; //address of the register volatile unsigned int SCB_DEMCR = (uint32_t )0xE000EDFC; //address of the register // configure and start the clock cycles counter clock_cycles_counter = 0; SCB_DEMCR = SCB_DEMCR | 0x01000000; DWT_CYCCNT = 0; DWT_CONTROL |= 1; ////// //////Code to be measured ///// // stop and get the counter value DWT_CONTROL &= ~1; clock_cycles_counter = DWT_CYCCNT;

// print the counter value printf("counter %d\n\r", clock_cycles_counter);

Always get '0'. Is the peripheral address mapped in above program correct? Has anyone tried another way to measure the time? Thank in advance

wschang0 commented 5 years ago

M2351 doesn’t support DWT cycle counter. The clock source of SysTick could be the same as CPU. Therefore, you could use SysTick timer for cycle count.

From: user01-weeve [mailto:notifications@github.com] Sent: Tuesday, March 19, 2019 11:31 PM To: OpenNuvoton/M2351BSP Cc: Subscribed Subject: [OpenNuvoton/M2351BSP] Measuring Execution Time of a Piece of Code (#5)

Hi, I 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. Below is the piece of code I tried: uint32_t clock_cycles_counter; volatile unsigned int DWT_CYCCNT = (uint32_t )0xE0001004; //address of the register volatile unsigned int DWT_CONTROL = (uint32_t )0xE0001000; //address of the register volatile unsigned int SCB_DEMCR = (uint32_t )0xE000EDFC; //address of the register // configure and start the clock cycles counter clock_cycles_counter = 0; SCB_DEMCR = SCB_DEMCR | 0x01000000; DWT_CYCCNT = 0; DWT_CONTROL |= 1; ////// //////Code to be measured ///// // stop and get the counter value DWT_CONTROL &= ~1; clock_cycles_counter = DWT_CYCCNT;

// print the counter value printf("counter %d\n\r", clock_cycles_counter);

Always get '0'. Is the peripheral address mapped in above program correct? Has anyone tried another way to measure the time? Thank in advance

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://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 threadhttps://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=.

=========================================================================================== The 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.