stm32/mphalport: Use MCU regs to detect if cycle counter is started.
Instead of using a dedicated variable in RAM it's simpler to use the relevant bits in the DWT register.
This commit is contained in:
parent
b833f170c3
commit
bc3a5f1917
@ -7,8 +7,6 @@
|
||||
#include "usb.h"
|
||||
#include "uart.h"
|
||||
|
||||
bool mp_hal_ticks_cpu_enabled = false;
|
||||
|
||||
// this table converts from HAL_StatusTypeDef to POSIX errno
|
||||
const byte mp_hal_status_to_errno_table[4] = {
|
||||
[HAL_OK] = 0,
|
||||
@ -90,7 +88,7 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
|
||||
}
|
||||
|
||||
void mp_hal_ticks_cpu_enable(void) {
|
||||
if (!mp_hal_ticks_cpu_enabled) {
|
||||
if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
#if defined(__CORTEX_M) && __CORTEX_M == 7
|
||||
// on Cortex-M7 we must unlock the DWT before writing to its registers
|
||||
@ -98,7 +96,6 @@ void mp_hal_ticks_cpu_enable(void) {
|
||||
#endif
|
||||
DWT->CYCCNT = 0;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
mp_hal_ticks_cpu_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,9 @@ void mp_hal_set_interrupt_char(int c); // -1 to disable
|
||||
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
|
||||
#define mp_hal_delay_us_fast(us) mp_hal_delay_us(us)
|
||||
|
||||
extern bool mp_hal_ticks_cpu_enabled;
|
||||
void mp_hal_ticks_cpu_enable(void);
|
||||
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
||||
if (!mp_hal_ticks_cpu_enabled) {
|
||||
if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) {
|
||||
mp_hal_ticks_cpu_enable();
|
||||
}
|
||||
return DWT->CYCCNT;
|
||||
|
Loading…
Reference in New Issue
Block a user