-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDwt.cpp
More file actions
41 lines (33 loc) · 762 Bytes
/
Dwt.cpp
File metadata and controls
41 lines (33 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Dwt.cpp
*
* Created on: Jul 29, 2025
* Author: admin
*/
#include "Dwt.h"
#if defined(DWT) && defined(DWT_BASE)
/**
* @brief DWT initialization (called once).
*/
__STATIC_INLINE void DWT_Init(void)
{
// Enable core debug timers
SET_BIT(CoreDebug->DEMCR, CoreDebug_DEMCR_TRCENA_Msk);
// Unlock write access to DWT registers (required for STM32H7)
#ifdef STM32H7
DWT->LAR = 0xC5ACCE55; // Unlock access for STM32H7
#endif
// Reset and enable the cycle counter
DWT->CYCCNT = 0U;
SET_BIT(DWT->CTRL, DWT_CTRL_CYCCNTENA_Msk);
}
Dwt::Dwt()
{
DWT_Init();
}
bool Dwt::isAvailable() noexcept
{
return (READ_BIT(CoreDebug->DEMCR, CoreDebug_DEMCR_TRCENA_Msk) &&
READ_BIT(DWT->CTRL, DWT_CTRL_CYCCNTENA_Msk));
}
#endif /* DWT is exists */