0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

STM32F103C8のサイクル数(クロックカウンター)を測る

Last updated at Posted at 2021-06-15

x Mbed NUCLEO-F103RB Mbed2 リビジョン172

目的
ある意味タイマーのテスト

1000usの時は、64612カウントで
1000倍すると約64Mhz

参考



# include "mbed.h"

//Serial pc(SERIAL_TX, SERIAL_RX); //767
//RawSerial pc(PA_2, PA_3); //010
Serial pc(PA_9, PA_10); // tx, rx 103

int main()
{

    pc.printf("\r\n103\r\n"); //767

    pc.printf("1000us\r\n"); //767
    for (int ii=0;ii<5;ii++) {

        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

        uint32_t startTime = DWT->CYCCNT;

        //DWT_CYCCNT
        wait_us(1000);

        uint32_t time = DWT->CYCCNT;

        pc.printf("%d\r\n",time-startTime); //767

        //1秒待つ
        wait_ms(1000);
    }//for

    pc.printf("2000us\r\n"); //767
    for (int ii=0;ii<5;ii++) {

        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

        uint32_t startTime = DWT->CYCCNT;

        //DWT_CYCCNT
        wait_us(2000);

        uint32_t time = DWT->CYCCNT;

        pc.printf("%d\r\n",time-startTime); //767

        //1秒待つ
        wait_ms(1000);
    }//for


}//main

//容量削減
//void error(const char* format, ...){}




dwtsssss1.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?