Skip to content

Commit

Permalink
STM32: new config parameter UAVCAN_STM32_TIMX_INPUT_CLOCK
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Nov 27, 2017
1 parent 2d02258 commit e2c68be
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,21 @@
# error "This UAVCAN_STM32_TIMER_NUMBER is not supported yet"
# endif

# if (TIMX_INPUT_CLOCK % 1000000) != 0
# error "No way, timer clock must be divisible to 1e6. FIXME!"
/**
* UAVCAN_STM32_TIMX_INPUT_CLOCK can be used to manually override the auto-detected timer clock speed.
* This is useful at least with certain versions of ChibiOS which do not support the bit
* RCC_DKCFGR.TIMPRE that is available in newer models of STM32. In that case, if TIMPRE is active,
* the auto-detected value of TIMX_INPUT_CLOCK will be twice lower than the actual clock speed.
* Read this for additional context: http://www.chibios.com/forum/viewtopic.php?f=35&t=3870
* A normal way to use the override feature is to provide an alternative macro, e.g.:
*
* -DUAVCAN_STM32_TIMX_INPUT_CLOCK=STM32_HCLK
*
* Alternatively, the new clock rate can be specified directly.
*/
# ifdef UAVCAN_STM32_TIMX_INPUT_CLOCK
# undef TIMX_INPUT_CLOCK
# define TIMX_INPUT_CLOCK UAVCAN_STM32_TIMX_INPUT_CLOCK
# endif

extern "C" UAVCAN_STM32_IRQ_HANDLER(TIMX_IRQHandler);
Expand Down Expand Up @@ -121,7 +134,7 @@ void init()
nvicEnableVector(TIMX_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);

# if (TIMX_INPUT_CLOCK % 1000000) != 0
# error "No way, timer clock must be divisible to 1e6. FIXME!"
# error "No way, timer clock must be divisible by 1e6. FIXME!"
# endif

// Start the timer
Expand Down

0 comments on commit e2c68be

Please sign in to comment.