ST意法半导体
直播中

刘芳

7年用户 1272经验值
私信 关注
[问答]

如何使用或启用STM32CubeIDE DWT?

我有一块 STM32L031K6 Nucleo 板……
我想使用 DWT.. 但我变成了这个错误:
  • ../Core/Src/../Inc/stm32_delay.h:35:30: error: 'DWT' undeclared (first use in this function)
  •    uint32_t clk_cycle_start = DWT->CYCCNT;
如何使用或启用 DWT?我使用 STM32CubeIDE...
我的功能:
  • #ifndef INC_STM32_DELAY_H_
  • #define INC_STM32_DELAY_H_
  • #ifdef __cplusplus
  • extern "C" {
  • #endif
  • #ifndef __STM32L0xx_HAL_H
  • #include "stm32l0xx_hal.h"
  • #endif
  • /**
  • * @brief  Initializes DWT_Cycle_Count for DWT_Delay_us function
  • * @return Error DWT counter
  • *         1: DWT counter Error
  • *         0: DWT counter works
  • */
  • uint32_t DWT_Delay_Init(void);
  • /**
  • * @brief  This function provides a delay (in microseconds)
  • * @param  microseconds: delay in microseconds
  • */
  • __STATIC_INLINE void DWT_Delay_us(volatile uint32_t microseconds)
  • {
  •   uint32_t clk_cycle_start = DWT->CYCCNT;
  •   /* Go to number of cycles for system */
  •   microseconds *= (HAL_RCC_GetHCLKFreq() / 1000000);
  •   /* Delay till end */
  •   while ((DWT->CYCCNT - clk_cycle_start) < microseconds);
  • }
  • #ifdef __cplusplus
  • }
  • #endif
  • #endif /* INC_STM32_DELAY_H_ */
多谢你们..









回帖(1)

雷友水

2023-1-30 11:46:27
可以肯定的是,L031 缺少任何 32 位定时器,ST 在这方面并不真正理解对 32 位处理器的期望。
更敏锐的工程师至少会放入一个 32 位计数器来处理关键路径/传播问题,并构建一个不太复杂的计时单元组合。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分