From cb0f0b690e7b2fb33094df89b8f84141a7b7f377 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 18 Jul 2011 14:19:04 -0400 Subject: Add DELAY_US_MULT, for use in generalizing delay_us(). The delay_us() implementation multiplies its specified delay target by a fixed constant in order to turn it into a busy-loop. This magic number doesn't work properly when the clock configuration isn't the same as a stock LeafLabs board. Add DELAY_US_MULT to the MCU-specific configuration in stm32.h in order to allow other chips to use delay_us(). --- libmaple/delay.h | 10 ++-------- libmaple/stm32.h | 7 +++++++ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'libmaple') diff --git a/libmaple/delay.h b/libmaple/delay.h index 56611a5..dd68ec6 100644 --- a/libmaple/delay.h +++ b/libmaple/delay.h @@ -4,6 +4,7 @@ */ #include "libmaple_types.h" +#include "stm32.h" #ifndef _DELAY_H_ #define _DELAY_H_ @@ -11,17 +12,10 @@ /** * @brief Delay the given number of microseconds. * - * Note that this function currently assumes you are on a LeafLabs - * board, and will only work properly if you follow the LeafLabs RCC - * configuration. - * * @param us Number of microseconds to delay. */ static inline void delay_us(uint32 us) { - /* TODO this makes unwarranted assumptions about the RCC - * config; add a hook so users can make their own decisions. */ - /* So (2^32)/12 micros max, or less than 6 minutes */ - us *= 12; + us *= DELAY_US_MULT; /* fudge for function call overhead */ us--; diff --git a/libmaple/stm32.h b/libmaple/stm32.h index d7e946e..9d2ed99 100644 --- a/libmaple/stm32.h +++ b/libmaple/stm32.h @@ -32,11 +32,16 @@ /* SRAM size, in bytes */ #define SRAM_SIZE 0x5000 + /* Multiplier to convert microseconds into loop iterations in + * delay_us() (See delay.h) */ + #define DELAY_US_MULT 12 + #elif defined(MCU_STM32F103ZE) /* e.g., LeafLabs Maple Native */ #define NR_GPIO_PORTS 7 #define SRAM_SIZE 0x10000 + #define DELAY_US_MULT 12 #elif defined(MCU_STM32F103CB) /* e.g., LeafLabs Maple Mini */ @@ -47,12 +52,14 @@ #define NR_GPIO_PORTS 3 #define SRAM_SIZE 0x5000 + #define DELAY_US_MULT 12 #elif defined(MCU_STM32F103RE) /* e.g., LeafLabs Maple RET6 edition */ #define NR_GPIO_PORTS 4 #define SRAM_SIZE 0x10000 + #define DELAY_US_MULT 12 #else -- cgit v1.2.3