diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index cd0d32ec31e1cc5408824bfeb7d80385a55da4f2..056f3cddb529d41ed8d86ad9cfc01d3c7542e1c8 100644 --- a/ch32v003fun/ch32v003fun.c +++ b/ch32v003fun/ch32v003fun.c @@ -802,7 +802,7 @@ asm volatile( bne a1, a2, 1b\n\ 2:\n" ); - SysTick->CTLR = 1; + SETUP_SYSTICK_HCLK // set mepc to be main as the root app. asm volatile( diff --git a/ch32v003fun/ch32v003fun.h b/ch32v003fun/ch32v003fun.h index f75a27e42006f9456ba80395ef8cfc792cc6d9a7..3273ce8f888eec7cf43c9ec18db05435b8b33724 100644 --- a/ch32v003fun/ch32v003fun.h +++ b/ch32v003fun/ch32v003fun.h @@ -4819,8 +4819,19 @@ static inline uint32_t __get_SP(void) extern "C" { #endif +// You can use SYSTICK_USE_HCLK, if you do, you will have a high-resolution +// however it will limit your max delay to 44 seconds before it will wrap +// around. You must also call SETUP_SYSTICK_HCLK. + +#ifdef SYSTICK_USE_HCLK +#define DELAY_US_TIME ((SYSTEM_CORE_CLOCK)/1000000) +#define DELAY_MS_TIME ((SYSTEM_CORE_CLOCK)/1000) +#define SETUP_SYSTICK_HCLK SysTick->CTLR = 5; +#else // Use systick = hclk/8 #define DELAY_US_TIME ((SYSTEM_CORE_CLOCK)/8000000) #define DELAY_MS_TIME ((SYSTEM_CORE_CLOCK)/8000) +#define SETUP_SYSTICK_HCLK SysTick->CTLR = 1; +#endif #if defined(__riscv) || defined(__riscv__) || defined( CH32V003FUN_BASE )