summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/stm32/stm32_lowputc.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-10-04 16:58:10 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-10-04 16:58:10 +0000
commitd977e1c8ff3fa9f8186a0f0e65612d0d2bf2309b (patch)
treed72bcaa2ba53438cfe9d95fe22f2932ba9615558 /nuttx/arch/arm/src/stm32/stm32_lowputc.c
parent7b77e67704cb94a9576c0b06638542dc0f760c3a (diff)
downloadpx4-nuttx-d977e1c8ff3fa9f8186a0f0e65612d0d2bf2309b.tar.gz
px4-nuttx-d977e1c8ff3fa9f8186a0f0e65612d0d2bf2309b.tar.bz2
px4-nuttx-d977e1c8ff3fa9f8186a0f0e65612d0d2bf2309b.zip
Misc clocking fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2119 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/stm32/stm32_lowputc.c')
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_lowputc.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_lowputc.c b/nuttx/arch/arm/src/stm32/stm32_lowputc.c
index 0f649bbd7..da6cdc138 100644
--- a/nuttx/arch/arm/src/stm32/stm32_lowputc.c
+++ b/nuttx/arch/arm/src/stm32/stm32_lowputc.c
@@ -149,17 +149,38 @@
* usartdiv = fCK / (16 * baud)
*
* Where fCK is the input clock to the peripheral (PCLK1 for USART2, 3, 4, 5
- * or PCLK2 for USART1)
+ * or PCLK2 for USART1). Example, fCK=72MHz baud=115200, usartdiv=39.0625=39 1/16th;
*
- * First calculate (NOTE: all stand baud values are even so dividing by two
- * does not lose precision):
+ * First calculate:
*
* usartdiv32 = 32 * usartdiv = fCK / (baud/2)
+ *
+ * (NOTE: all standard baud values are even so dividing by two does not
+ * lose precision). Eg. (same fCK and buad), usartdiv32 = 1250
*/
#define STM32_USARTDIV32 (STM32_APBCLOCK / (STM32_CONSOLE_BAUD >> 1))
+
+/* The mantissa is then usartdiv32 * 32:
+ *
+ * mantissa = 32 * usartdiv32
+ *
+ * Eg. usartdiv32=1250, mantissa = 39
+ */
+
#define STM32_MANTISSA (STM32_USARTDIV32 >> 5)
+
+/* And the fraction:
+ *
+ * fraction = (usartdiv32 - mantissa*32 + 1) / 2
+ *
+ * Eg., (1,250 - 39*32 + 1)/2 = 1 (or 0.0625)
+ */
+
#define STM32_FRACTION ((STM32_USARTDIV32 - (STM32_MANTISSA << 5) + 1) >> 1)
+
+/* And, finally, the BRR value is: */
+
#define STM32_BRR_VALUE ((STM32_MANTISSA << USART_BRR_MANT_SHIFT) | (STM32_FRACTION << USART_BRR_FRAC_SHIFT))
/**************************************************************************