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.

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

Last updated at Posted at 2021-06-15

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

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

参考



# include "mbed.h"

Serial pc(SERIAL_TX, SERIAL_RX); //767
//RawSerial pc(PA_2, PA_3); //010


int main()
{

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

//    volatile uint32_t start = 0;
//    volatile uint32_t stop = 0;
//    volatile uint32_t ivar[50] = {};
//    volatile uint32_t cnt[50] = {};
//
//
//    while (1) {
//
//CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
//DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
//
//
//    start = DWT->CYCCNT;   // 開始時サイクル数
//    ivar[0] = start;       // 計測したい処理
//
//    uint32_t startTime = DWT->CYCCNT;
//
//    //DWT_CYCCNT
//    wait_us(200);
//
//    uint32_t time = DWT->CYCCNT;
//
//    stop = DWT->CYCCNT;    // 終了時サイクル数
//    cnt[0] = stop - start; // 処理にかかったサイクル数
//
//
//       pc.printf("%d\r\n",time-startTime); //767
//
//    //1秒待つ
//        wait_ms(1000);
//    }//while

    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, ...){}




dwtssssss.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?