# dwt_delay
Microseconds delay lib based on DWT for STM32 or whatever ARM supporting it.
Just include `dwt_delay.h` in your project, call `DWT_Init()` and then use delays as needed.
Depending on MCU used, you may need to include another header file (with MCU peripherals defines) in `dwt_delay.h`.
The `stm32f1xx.h` is included by default, allowing STM32F1xx to start out of the box.
If you don't use STM32 MCU or CubeMX, read a section at the end.
Functions are named as DWT_* to be HAL-alike. Feel free to do whatever you like with this lib,
change names, indents, coding style, use it in LHC firmware.
## Example
```c
/* main.c */
#include "dwt_delay.h"
void main (void)
{
// Init section of your code
DWT_Init();
while(1) {
// Delay for 42us
DWT_Delay(42);
}
}
```
## Notes on Cortex-M0/0+/1
Unfortunately, these are not supported, since cores have no access to DWT. CMSIS library states:
```
Cortex-M0/0+/1 Core Debug Registers are only accessible over DAP and not via processor
```
You may want a delay function based on hardware timer instead.
## What about Cortex-M35/55/85?
I don't have any of these to check, but in theory they are supported.
Anyway you have to change `CoreDebug` to `DCB`, because `CoreDebug` is deprecated in these cores.
Hence, init sequence should be something like:
```c
DCB->DEMCR |= DCB_DEMCR_TRCENA_Msk;
```
## I'm not with STM but need microsec delays
There's an option to try! Also suits those, who use STM32, but dont use HAL/LL libs.
Include a CMSIS header file according to your core in `dwt_delay.c` and change `SystemCoreClock`
variable to whatever you probably have in the project representing clock frequency (in Hz).
Something like this:
```c
// In dwt_delay.c
#include "dwt_delay.h"
#include "core_cm4.h" // CMSIS header
#define SystemCoreClock NameOfTheGlobalVariableInYourProject_or_AnotherDefine
// or at least
#define SystemCoreClock 48000000UL // Clock is 48Mhz
...
```
## Changelog
- **2018-01-06**
This lib emerged.
- **2019-02-19**
Overflow check added.
- **2019-03-26**
Typo in definition fixed. Got back to short and simpler function.
- **2023-11-21**
Now it is MIT License. Added warning for Cortex-M0/0+/1 and notes regarding other Cortex-M cores.
AI技术控
- 粉丝: 623
- 资源: 236
最新资源
- C#通讯类库,支持西门子200,300,1200,1500等plc通讯,plc端不用书写代码,可以将该部分类库嵌入到C#开发架构当中,融入自己原来的框架,可以实现单值读写,可以将DB数据一次性读写进类
- sentinel客户端
- java+ssm+Vue病人跟踪治疗信息网站+毕设大作业项目源码.zip
- java+ssm+Vue毕业设计论文和答辩ppt_选题网站+毕设大作业项目源码.zip
- java+ssm+Vue大学生兼职跟踪网站+毕设大作业项目源码.zip
- 汽车动力系统整套设计参考资料,包含动力各系统设计规范 资料完整全面,主要包括发动机系统、冷却散热系统、变速箱、传动轴、供油等系统的设计规范 非学院派资料,全部为实战工程师编写,是设计工程师、开发工程
- 宿舍管理信息系统【控制台+MySQL】(Java课设)
- 学校商户管理信息系统【控制台+MySQL】(Java课设)
- 奖学金管理系统【控制台+MySQL】(Java课设)
- 《采用 IoT oneM2M 技术的 5G 遥控智能机器人小车》计算机、自动化、电子信息等相关专业毕业设计&大作业 (源码、说明、论文、数据集一站式服务,拿来就能用的绝对好资源)。
- 视觉滤波跟踪算法三部曲之ECO-HC跟踪 , 超越ECO,ECO-HC跟踪算法降维部分原来HOG+CN的42维特征降到13维,其他部分类似,实验结果ECO-HC超过了大部分深度学习方法,而且lunwe
- 《包括跟踪汽车和行人的 MOT、获取车牌内容的对象检测和图像分类、获取斑马线的语义分割、获取车道面积的传统方法等》计算机、自动化、电子信息等相关专业毕业设计&大作业 (源码、说明、论文、数据集一站式服
- java+ssm+Vue电影院在线售票网站+毕设大作业项目源码.zip
- java+ssm+Vue房屋出租出售网站+毕设大作业项目源码.zip
- java+ssm+Vue大学生社团网站+毕设大作业项目源码.zip
- 《跟踪黑线以及路标形式的标记的自动驾驶汽车的代码、文档和演示》计算机、自动化、电子信息等相关专业毕业设计&大作业 (源码、说明、论文、数据集一站式服务,拿来就能用的绝对好资源)。
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈