keatis / dwt_delay

Microseconds delay lib for STM32 (or whatever ARM) based on DWT
MIT License
80 stars 28 forks source link

Cortex M7 support #4

Open mhanuel26 opened 5 years ago

mhanuel26 commented 5 years ago

Hi, I cannot make it work under STM32F769, perhaps the unlocking sequence.

void DWT_Init(void)
{
    if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) {
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        DWT->LAR = 0xC5ACCE55;
        DWT->CYCCNT = 0;
        DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
    }
}

I have place the init after SystemClock_Config such

  SystemClock_Config();
  DWT_Init();

What am I missing?

Thanks,

mhanuel26 commented 5 years ago

The problem seems to be the if clause if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) { For some reason it returns false, such as if it was been enable.

arkadiuszmakarenko commented 4 years ago

I have this in F730 and seems to work as expected: `void DWT_Init(void) {

DWT->LAR = 0xC5ACCE55;
    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    DWT->CYCCNT = 0;
    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

}`

keatis commented 3 years ago

Thanks for pointing this out! I'd suggest to make explicit initialization on STM32F7 without condition. And as it turned out to work ok, i'd rather remake that if condition some day, when i get F7 on hands to experiment. Thanks again for sharing your experience!