diff options
author | Dmitriy Lisin <d.lisin@thirdpin.ru> | 2018-07-04 16:55:44 +0300 |
---|---|---|
committer | Dmitriy Lisin <d.lisin@thirdpin.ru> | 2018-07-04 16:55:44 +0300 |
commit | 8687cfa242c188b569b0c12b7d8338d1d9a55b62 (patch) | |
tree | f437cede38cf6394cd4c40dd0515f024d872ebf7 | |
parent | b95599607a9191043a400064dd2e1cacaebaae32 (diff) |
IMPR: [systick] Added RCC init and changed config
-rw-r--r-- | cm3cpp_config_template.h | 7 | ||||
-rw-r--r-- | cm3cpp_systick.cpp | 14 |
2 files changed, 16 insertions, 5 deletions
diff --git a/cm3cpp_config_template.h b/cm3cpp_config_template.h index c152bd7..9ad1a2a 100644 --- a/cm3cpp_config_template.h +++ b/cm3cpp_config_template.h @@ -7,9 +7,8 @@ #define CM3CPP_ENABLE_CUSTOM_SYSTICK_SOURCE 1 //*** Or you can use custom systick source (like timer) #if (CM3CPP_ENABLE_CUSTOM_SYSTICK_SOURCE == 1) -#define CM3CPP_INT_SOURCE TIM1 -#define CM3CPP_SYSTICK_INT_FUNC tim1_isr -#define CM3CPP_SYSTICK_CLOCK 30000000 * 2 +#define CM3CPP_TIMER_N 12 +#define CM3CPP_SYSTICK_CLOCK (30000000 * 2) #define CM3CPP_SYSTICK_CLOCK_DIV 1000 // 1 kHz #define CM3CPP_SYSTICK_PERIOD 0xffff #else @@ -18,7 +17,7 @@ #endif //*** User assert function define -#define CM3CPP_ASSERT( x ) if( ( x ) == 0 ) user_assert_func( __FILE__, __LINE__ ) +#define CM3_ASSERT( x ) if( ( x ) == 0 ) user_assert_func( __FILE__, __LINE__ ) //*** This option enable destructors for classes using a heap allocation // inside. If you can't destruct an object it prevents a memory leak. diff --git a/cm3cpp_systick.cpp b/cm3cpp_systick.cpp index 3fc76ea..8b3f0f9 100644 --- a/cm3cpp_systick.cpp +++ b/cm3cpp_systick.cpp @@ -24,6 +24,18 @@ SYSTICK implementation, public interface */ #include "cm3cpp_systick.h" + +#define __EXPAND2(a,b) a ## b +#define __EXPAND3(a,b,c) a ## b ## c + +#define __INT_SOURCE(n) __EXPAND2(TIM, n) +#define __RCC(n) __EXPAND2(rcc_periph_clken::RCC_TIM, n) +#define __SYSTICK_INT_FUNC(n) __EXPAND3(tim, n, _isr) + +#define CM3CPP_INT_SOURCE __INT_SOURCE(CM3CPP_TIMER_N) +#define CM3CPP_INT_SOURCE_RCC __RCC(CM3CPP_TIMER_N) +#define CM3CPP_SYSTICK_INT_FUNC __SYSTICK_INT_FUNC(CM3CPP_TIMER_N) + #if CM3CPP_ENABLE_CUSTOM_SYSTICK_SOURCE == 1 extern "C" { void CM3CPP_SYSTICK_INT_FUNC(void); @@ -62,10 +74,10 @@ void delay_systick(uint32_t ms) while((get_counter() - time) < ms); } - void init(uint32_t clock_div) { #if CM3CPP_ENABLE_CUSTOM_SYSTICK_SOURCE == 1 + rcc_periph_clock_enable(CM3CPP_INT_SOURCE_RCC); timer_reset(CM3CPP_INT_SOURCE); timer_set_mode(CM3CPP_INT_SOURCE, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); timer_set_prescaler(CM3CPP_INT_SOURCE, (CM3CPP_SYSTICK_CLOCK / clock_div) - 1); |