add Gokit3 board support
add Gokit3 board support
This commit is contained in:
36
board/GoKit3_STM32F103C8T6/BSP/Src/dwt.c
Normal file
36
board/GoKit3_STM32F103C8T6/BSP/Src/dwt.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "dwt.h"
|
||||
|
||||
static uint32_t cpuclkfeq;
|
||||
|
||||
void dwt_delay_init(uint32_t clk)
|
||||
{
|
||||
cpuclkfeq = clk;
|
||||
DEM_CR |= DEM_CR_TRCENA;
|
||||
DWT_CYCCNT = 0u;
|
||||
DWT_CR |= DWT_CR_CYCCNTENA;
|
||||
}
|
||||
|
||||
void delay_us(uint32_t usec)
|
||||
|
||||
{
|
||||
uint32_t startts, endts, ts;
|
||||
|
||||
startts = DWT_CYCCNT;
|
||||
|
||||
ts = usec * (cpuclkfeq / (1000 * 1000));
|
||||
endts = startts + ts;
|
||||
if(endts > startts)
|
||||
{
|
||||
while(DWT_CYCCNT < endts);
|
||||
}
|
||||
else
|
||||
{
|
||||
while(DWT_CYCCNT > endts);
|
||||
while(DWT_CYCCNT < endts);
|
||||
}
|
||||
}
|
||||
|
||||
void delay_ms(__IO uint32_t nTime)
|
||||
{
|
||||
delay_us(1000 * nTime);
|
||||
}
|
Reference in New Issue
Block a user