-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
144 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef __AT32F421_DELAY_H | ||
#define __AT32F421_DELAY_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* includes ------------------------------------------------------------------*/ | ||
#include "at32f421.h" | ||
|
||
/* exported functions ------------------------------------------------------- */ | ||
/** | ||
* @brief initialize delay function | ||
* @param none | ||
* @retval none | ||
*/ | ||
void delay_init(void); | ||
|
||
/** | ||
* @brief inserts a delay time. | ||
* @param nus: specifies the delay time length, in microsecond. | ||
* @retval none | ||
*/ | ||
void delay_us(uint32_t nus); | ||
|
||
/** | ||
* @brief inserts a delay time. | ||
* @param nms: specifies the delay time length, in milliseconds. | ||
* @retval none | ||
*/ | ||
void delay_ms(uint16_t nms); | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __AT32F421_DELAY_H */ | ||
|
4 changes: 2 additions & 2 deletions
4
Libraries/debug/debug.h → Libraries/bsp/inc/at32f421_printf.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* includes ------------------------------------------------------------------*/ | ||
#include "at32f421_delay.h" | ||
|
||
#define STEP_DELAY_MS 50 | ||
|
||
/* delay variable */ | ||
static __IO uint32_t fac_us; | ||
static __IO uint32_t fac_ms; | ||
|
||
|
||
/** | ||
* @brief initialize delay function | ||
* @param none | ||
* @retval none | ||
*/ | ||
void delay_init() | ||
{ | ||
/* configure systick */ | ||
systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV); | ||
fac_us = system_core_clock / (1000000U); | ||
fac_ms = fac_us * (1000U); | ||
} | ||
|
||
|
||
/** | ||
* @brief inserts a delay time. | ||
* @param nus: specifies the delay time length, in microsecond. | ||
* @retval none | ||
*/ | ||
void delay_us(uint32_t nus) | ||
{ | ||
uint32_t temp = 0; | ||
SysTick->LOAD = (uint32_t)(nus * fac_us); | ||
SysTick->VAL = 0x00; | ||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk ; | ||
do | ||
{ | ||
temp = SysTick->CTRL; | ||
}while((temp & 0x01) && !(temp & (1 << 16))); | ||
|
||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; | ||
SysTick->VAL = 0x00; | ||
} | ||
|
||
/** | ||
* @brief inserts a delay time. | ||
* @param nms: specifies the delay time length, in milliseconds. | ||
* @retval none | ||
*/ | ||
void delay_ms(uint16_t nms) | ||
{ | ||
uint32_t temp = 0; | ||
while(nms) | ||
{ | ||
if(nms > STEP_DELAY_MS) | ||
{ | ||
SysTick->LOAD = (uint32_t)(STEP_DELAY_MS * fac_ms); | ||
nms -= STEP_DELAY_MS; | ||
} | ||
else | ||
{ | ||
SysTick->LOAD = (uint32_t)(nms * fac_ms); | ||
nms = 0; | ||
} | ||
SysTick->VAL = 0x00; | ||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; | ||
do | ||
{ | ||
temp = SysTick->CTRL; | ||
}while((temp & 0x01) && !(temp & (1 << 16))); | ||
|
||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; | ||
SysTick->VAL = 0x00; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pack: | ||
- Misc/ArteryTek.AT32F421_DFP.2.1.0.pack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters