diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-08-13 16:11:26 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-08-13 16:11:26 +0000 |
commit | afd96ea0af98714eba7b76edb58be5f27cf20b44 (patch) | |
tree | 32e19b3a42d7169b396651bb35037b6aa0c73b5b /nuttx | |
parent | d212c46891d73fec2a1bbc4069d5fecfc360b8f1 (diff) | |
download | px4-nuttx-afd96ea0af98714eba7b76edb58be5f27cf20b44.tar.gz px4-nuttx-afd96ea0af98714eba7b76edb58be5f27cf20b44.tar.bz2 px4-nuttx-afd96ea0af98714eba7b76edb58be5f27cf20b44.zip |
Add Kinetis clocking logic and some UART logic. Add K60 Tower configuration
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3876 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/arch/arm/src/kinetis/Make.defs | 6 | ||||
-rw-r--r-- | nuttx/arch/arm/src/kinetis/kinetis_clockconfig.c | 373 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/kinetis/kinetis_config.h | 168 | ||||
-rw-r--r-- | nuttx/arch/arm/src/kinetis/kinetis_internal.h | 26 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/kinetis/kinetis_lowputc.c | 263 | ||||
-rw-r--r-- | nuttx/arch/arm/src/kinetis/kinetis_mcg.c | 139 | ||||
-rw-r--r-- | nuttx/arch/arm/src/kinetis/kinetis_mcg.h | 8 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/kinetis/kinetis_start.c | 42 | ||||
-rw-r--r-- | nuttx/arch/arm/src/kinetis/kinetis_uart.h | 4 | ||||
-rw-r--r-- | nuttx/configs/kwikstik-k40/README.txt | 92 | ||||
-rwxr-xr-x | nuttx/configs/kwikstik-k40/include/board.h | 32 | ||||
-rwxr-xr-x | nuttx/configs/twr-k60n512/include/board.h | 168 |
13 files changed, 1095 insertions, 228 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index e2960e4ff..98cd099d1 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2000,3 +2000,5 @@ hkwilton). * arch/arm/src/kinetis: Added header files defining all Kinetis registers and bit fields within all Kinetis registers. + * configs/twr-k60n512: This will (eventually) provide support for the Kinetis + K60 Tower board. diff --git a/nuttx/arch/arm/src/kinetis/Make.defs b/nuttx/arch/arm/src/kinetis/Make.defs index 8f2c67aa1..d0c9d94b6 100644 --- a/nuttx/arch/arm/src/kinetis/Make.defs +++ b/nuttx/arch/arm/src/kinetis/Make.defs @@ -57,10 +57,10 @@ endif # Required Kinetis files CHIP_ASRCS = -#CHIP_CSRCS = kinetis_allocateheap.c kinetis_can.c kinetis_gpio.c kinetis_lowputc.c \ +#CHIP_CSRCS = kinetis_allocateheap.c kinetis_can.c kinetis_gpio.c \ # kinetis_serial.c kinetis_spi.c kinetis_ssp.c kinetis_timerisr.c -CHIP_CSRCS = kinetis_clrpend.c kinetis_idle.c kinetis_irq.c kinetis_mcg.c kinetis_start.c \ - kinetis_wdog.c +CHIP_CSRCS = kinetis_clockconfig.c kinetis_clrpend.c kinetis_idle.c kinetis_irq.c \ + kinetis_lowputc.c kinetis_start.c kinetis_wdog.c # Configuration-dependent Kinetis files diff --git a/nuttx/arch/arm/src/kinetis/kinetis_clockconfig.c b/nuttx/arch/arm/src/kinetis/kinetis_clockconfig.c new file mode 100644 index 000000000..11e5af48f --- /dev/null +++ b/nuttx/arch/arm/src/kinetis/kinetis_clockconfig.c @@ -0,0 +1,373 @@ +/****************************************************************************
+ * arch/arm/src/kinetis/kinetis_clockconfig.c
+ * arch/arm/src/chip/kinetis_clockconfig.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <arch/board/board.h>
+
+#include "up_arch.h"
+
+#include "kinetis_internal.h"
+#include "kinetis_mcg.h"
+#include "kinetis_sim.h"
+#include "kinetis_fmc.h"
+#include "kinetis_llwu.h"
+
+/****************************************************************************
+ * Private Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_BOOT_RAMFUNCS
+# error "CONFIG_BOOT_RAMFUNCS must be defined for this logic"
+#endif
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void __ramfunc__
+kinesis_setdividers(uint32_t div1, uint32_t div2, uint32_t div3, uint32_t div4);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: kinesis_portclocks
+ *
+ * Description:
+ * Enable all of the port clocks
+ *
+ ****************************************************************************/
+
+static inline void kinesis_portclocks(void)
+{
+ uint32_t regval;
+
+ /* Enable all of the port clocks */
+
+ regval = getreg32(KINETIS_SIM_SCGC5);
+ regval |= (SIM_SCGC5_PORTA | SIM_SCGC5_PORTB | SIM_SCGC5_PORTC |
+ SIM_SCGC5_PORTD | SIM_SCGC5_PORTE);
+ putreg32(regval, KINETIS_SIM_SCGC5);
+}
+
+/****************************************************************************
+ * Name: kinesis_setdividers
+ *
+ * Description:
+ * "This routine must be placed in RAM. It is a workaround for errata e2448.
+ * Flash prefetch must be disabled when the flash clock divider is changed.
+ * This cannot be performed while executing out of flash. There must be a
+ * short delay after the clock dividers are changed before prefetch can be
+ * re-enabled."
+ *
+ ****************************************************************************/
+
+static void __ramfunc__
+kinesis_setdividers(uint32_t div1, uint32_t div2, uint32_t div3, uint32_t div4)
+{
+ uint32_t regval;
+ int i;
+
+ /* Save the current value of the Flash Access Protection Register */
+
+ regval = getreg32(KINETIS_FMC_PFAPR);
+
+ /* Set M0PFD through M7PFD to 1 to disable prefetch */
+
+ putreg32(FMC_PFAPR_M7PFD | FMC_PFAPR_M6PFD | FMC_PFAPR_M5PFD |
+ FMC_PFAPR_M4PFD | FMC_PFAPR_M3PFD | FMC_PFAPR_M2PFD |
+ FMC_PFAPR_M1PFD | FMC_PFAPR_M0PFD,
+ KINETIS_FMC_PFAPR);
+
+ /* Set clock dividers to desired value */
+
+ putreg32(SIM_CLKDIV1_OUTDIV1(div1) | SIM_CLKDIV1_OUTDIV2(div2) |
+ SIM_CLKDIV1_OUTDIV3(div3) | SIM_CLKDIV1_OUTDIV4(div4),
+ KINETIS_SIM_CLKDIV1);
+
+ /* Wait for dividers to change */
+
+ for (i = 0 ; i < div4 ; i++);
+
+ /* Re-store the saved value of FMC_PFAPR */
+
+ putreg32(regval, KINETIS_FMC_PFAPR);
+}
+
+/****************************************************************************
+ * Name: kinetis_pllconfig
+ *
+ * Description:
+ * Initialize the PLL using the settings in board.h. This assumes that
+ * the MCG is in default FLL Engaged Internal (FEI mode) out of reset.
+ *
+ ****************************************************************************/
+
+void kinetis_pllconfig(void)
+{
+ uint32_t regval32;
+ uint8_t regval8;
+
+ /* Transition to FLL Bypassed External (FBE) mode */
+
+#ifdef BOARD_EXTCLOCK
+ /* IRCS = 0 (Internal Reference Clock Select)
+ * LP = 0 (Low Power Select)
+ * EREFS = 0 (External Reference Select)
+ * HGO = 0 (High Gain Oscillator Select)
+ * RANGE = 0 (Oscillator of 32 kHz to 40 kHz)
+ */
+
+ putreg8(0, KINETIS_MCG_C2);
+#else
+ /* Enable external oscillator:
+ *
+ * IRCS = 0 (Internal Reference Clock Select)
+ * LP = 0 (Low Power Select)
+ * EREFS = 1 (External Reference Select)
+ * HGO = 1 (High Gain Oscillator Select)
+ * RANGE = 2 (Oscillator of 8 MHz to 32 MHz)
+ */
+
+ putreg8(MCG_C2_EREFS | MCG_C2_HGO | MCG_C2_RANGE_VHIGH, KINETIS_MCG_C2);
+#endif
+
+ /* Released latched state of oscillator and GPIO */
+
+ regval32 = getreg32(KINETIS_SIM_SCGC4);
+ regval32 |= SIM_SCGC4_LLWU;
+ putreg32(regval32, KINETIS_SIM_SCGC4);
+
+ regval8 = getreg8(KINETIS_LLWU_CS);
+ regval8 |= LLWU_CS_ACKISO;
+ putreg8(regval8, KINETIS_LLWU_CS);
+
+ /* Select external oscillator and Reference Divider and clear IREFS to
+ * start the external oscillator.
+ *
+ * IREFSTEN = 0 (Internal Reference Stop Enable)
+ * IRCLKEN = 0 (Internal Reference Clock Enable)
+ * IREFS = 0 (Internal Reference Select)
+ * FRDIV = 3 (FLL External Reference Divider, RANGE!=0 divider=256)
+ * CLKS = 2 (Clock Source Select, External reference clock)
+ */
+
+ putreg8(MCG_C1_FRDIV_DIV256 | MCG_C1_CLKS_EXTREF, KINETIS_MCG_C1);
+
+ /* If we aren't using an oscillator input we don't need to wait for the
+ * oscillator to initialize
+ */
+
+#ifndef BOARD_EXTCLOCK
+ while ((getreg8(KINETIS_MCG_S) & MCG_S_OSCINIT) == 0);
+#endif
+
+ /* Wait for Reference clock Status bit to clear */
+
+ while ((getreg8(KINETIS_MCG_S) & MCG_S_IREFST) != 0);
+
+ /* Wait for clock status bits to show that the clock source is the
+ * external reference clock.
+ */
+
+ while ((getreg8(KINETIS_MCG_S) & MCG_S_CLKST_MASK) != MCG_S_CLKST_EXTREF);
+
+ /* We are now in FLL Bypassed External (FBE) mode. Configure PLL
+ * reference clock divider:
+ *
+ * PLLCLKEN = 0
+ * PLLSTEN = 0
+ * PRDIV = Determined by PLL reference clock frequency
+ *
+ * Either the external clock or crystal frequency is used to select the
+ * PRDIV value. Only reference clock frequencies are supported that will
+ * produce a 2MHz reference clock to the PLL.
+ */
+
+ putreg8(MCG_C5_PRDIV(BOARD_PRDIV), KINETIS_MCG_C5);
+
+ /* Ensure that MCG_C6 is at the reset default of 0: LOLIE disabled, PLL
+ * disabled, clk monitor disabled, PLL VCO divider cleared.
+ */
+
+ putreg8(0, KINETIS_MCG_C6);
+
+ /* Set system options dividers based on settings from the board.h file.
+ *
+ * MCG = PLL
+ * Core = MCG / BOARD_OUTDIV1
+ * bus = MCG / BOARD_OUTDIV1
+ * FlexBus = MCG / BOARD_OUTDIV1
+ * Flash clock = MCG/2 / BOARD_OUTDIV1
+ */
+
+ kinesis_setdividers(BOARD_OUTDIV1, BOARD_OUTDIV2, BOARD_OUTDIV3, BOARD_OUTDIV4);
+
+ /* Set the VCO divider, VDIV, is defined in the board.h file. VDIV
+ * selects the amount to divide the VCO output of the PLL. The VDIV bits
+ * establish the multiplication factor applied to the reference clock
+ * frequency. Also set
+ *
+ * LOLIE = 0 (Loss of Lock Interrrupt Enable)
+ * PLLS = 1 (PLL Select)
+ * CME = 0 (Clock Monitor Enable)
+ */
+
+ putreg8(MCG_C6_PLLS | MCG_C6_VDIV(BOARD_VDIV), KINETIS_MCG_C6);
+
+ /* Wait for the PLL status bit to set */
+
+ while ((getreg8(KINETIS_MCG_S) & MCG_S_PLLST) == 0);
+
+ /* Wait for the PLL LOCK bit to set */
+
+ while ((getreg8(KINETIS_MCG_S) & MCG_S_LOCK) == 0);
+
+ /* We are now running in PLL Bypassed External (PBE) mode. Transition to
+ * PLL Engaged External (PEE) mode by setting CLKS to 0
+ */
+
+ regval8 = getreg8(KINETIS_MCG_C1);
+ regval8 &= ~MCG_C1_CLKS_MASK;
+ putreg8(regval8, KINETIS_MCG_C1);
+
+ /* Wait for clock status bits to update */
+
+ while ((getreg8(KINETIS_MCG_S) & MCG_S_CLKST_MASK) != MCG_S_CLKST_PLL);
+
+ /* We are now running in PLL Engaged External (PEE) mode. */
+}
+
+/****************************************************************************
+ * Name: kinetis_traceconfig
+ *
+ * Description:
+ * Enable trace clocks.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_KINETIS_TRACE
+static inline void kinetis_traceconfig(void)
+{
+ uint32_t regval;
+
+ /* Set the trace clock to the core clock frequency in the SIM SOPT2 register */
+
+ regval = getreg32(KINETIS_SIM_SOPT2);
+ regval |= SIM_SOPT2_TRACECLKSEL;
+ putreg32(regval, KINETIS_SIM_SOPT2);
+
+ /* Enable the TRACE_CLKOUT pin function on PTA6 (alt7 function) */
+
+ kinetis_gpioconfig(GPIO_TRACE);
+}
+#else
+# define kinetis_traceconfig()
+#endif
+
+/****************************************************************************
+ * Name: kinetis_fbconfig
+ *
+ * Description:
+ * Enable FlexBus clocking.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_KINETIS_FLEXBUS
+static inline void kinetis_fbconfig(void)
+{
+ uint32_t regval;
+
+ /* Enable the clock to the FlexBus module */
+
+ regval = getreg32(KINETIS_SIM_SCGC7);
+ regval |= SIM_SCGC7_FLEXBUS;
+ putreg32(regval, KINETIS_SIM_SCGC7);
+
+ /* Enable the FB_CLKOUT function on PTC3 (alt5 function) */
+
+ kinetis_gpioconfig(GPIO_FBCLKOUT);
+}
+#else
+# define kinetis_fbconfig()
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: kinetis_clockconfig
+ *
+ * Description:
+ * Called to initialize the Kinetis chip. This does whatever setup is
+ * needed to put the MCU in a usable state. This includes the
+ * initialization of clocking using the settings in board.h.
+ *
+ ****************************************************************************/
+
+void kinetis_clockconfig(void)
+{
+ /* Enable all of the port clocks */
+
+ kinesis_portclocks();
+
+ /* Configure the PLL based on settings in the board.h file */
+
+ kinetis_pllconfig();
+
+ /* For debugging, we will normally want to enable the trace clock and/or
+ * the FlexBus clock.
+ */
+
+ kinetis_traceconfig();
+ kinetis_fbconfig();
+}
+
diff --git a/nuttx/arch/arm/src/kinetis/kinetis_config.h b/nuttx/arch/arm/src/kinetis/kinetis_config.h new file mode 100755 index 000000000..aa05e8fda --- /dev/null +++ b/nuttx/arch/arm/src/kinetis/kinetis_config.h @@ -0,0 +1,168 @@ +/************************************************************************************
+ * arch/arm/src/kinetis/kinetis_config.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_KINETISXX_KINETIS_CONFIG_H
+#define __ARCH_ARM_SRC_KINETISXX_KINETIS_CONFIG_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include <arch/board/board.h>
+
+#include "chip.h"
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+/* Configuration *********************************************************************/
+/* Make that no unsupport UARTs are enabled */
+
+#ifndef KINETIS_NISO7816
+# define KINETIS_NISO7816 0
+#endif
+
+#if (KINETIS_NISO7816 + KINETIS_NUART) < 6
+# undef CONFIG_KINETIS_UART5
+# if (KINETIS_NISO7816 + KINETIS_NUART) < 5
+# undef CONFIG_KINETIS_UART4
+# if (KINETIS_NISO7816 + KINETIS_NUART) < 4
+# undef CONFIG_KINETIS_UART3
+# if (KINETIS_NISO7816 + KINETIS_NUART) < 3
+# undef CONFIG_KINETIS_UART2
+# if (KINETIS_NISO7816 + KINETIS_NUART) < 2
+# undef CONFIG_KINETIS_UART1
+# if (KINETIS_NISO7816 + KINETIS_NUART) < 1
+# undef CONFIG_KINETIS_UART0
+# endif
+# endif
+# endif
+# endif
+# endif
+#endif
+
+/* Are any UARTs enabled? */
+
+#undef HAVE_UART
+#if defined(CONFIG_KINETIS_UART0) || defined(CONFIG_KINETIS_UART1) || \
+ defined(CONFIG_KINETIS_UART2) || defined(CONFIG_KINETIS_UART3) || \
+ defined(CONFIG_KINETIS_UART5)
+# define HAVE_UART 1
+#endif
+
+/* Is there a serial console? There should be at most one defined. It could be on
+ * any UARTn, n=0,1,2,3,4,5
+ */
+
+#if defined(CONFIG_UART0_SERIAL_CONSOLE) && defined(CONFIG_KINETIS_UART0)
+# undef CONFIG_UART1_SERIAL_CONSOLE
+# undef CONFIG_UART2_SERIAL_CONSOLE
+# undef CONFIG_UART3_SERIAL_CONSOLE
+# undef CONFIG_UART4_SERIAL_CONSOLE
+# undef CONFIG_UART5_SERIAL_CONSOLE
+# define HAVE_CONSOLE 1
+#elif defined(CONFIG_UART1_SERIAL_CONSOLE) && defined(CONFIG_KINETIS_UART1)
+# undef CONFIG_UART0_SERIAL_CONSOLE
+# undef CONFIG_UART2_SERIAL_CONSOLE
+# undef CONFIG_UART3_SERIAL_CONSOLE
+# undef CONFIG_UART4_SERIAL_CONSOLE
+# undef CONFIG_UART5_SERIAL_CONSOLE
+# define HAVE_CONSOLE 1
+#elif defined(CONFIG_UART2_SERIAL_CONSOLE) && defined(CONFIG_KINETIS_UART2)
+# undef CONFIG_UART0_SERIAL_CONSOLE
+# undef CONFIG_UART1_SERIAL_CONSOLE
+# undef CONFIG_UART3_SERIAL_CONSOLE
+# undef CONFIG_UART4_SERIAL_CONSOLE
+# undef CONFIG_UART5_SERIAL_CONSOLE
+# define HAVE_CONSOLE 1
+#elif defined(CONFIG_UART3_SERIAL_CONSOLE) && defined(CONFIG_KINETIS_UART3)
+# undef CONFIG_UART0_SERIAL_CONSOLE
+# undef CONFIG_UART1_SERIAL_CONSOLE
+# undef CONFIG_UART2_SERIAL_CONSOLE
+# undef CONFIG_UART4_SERIAL_CONSOLE
+# undef CONFIG_UART5_SERIAL_CONSOLE
+# define HAVE_CONSOLE 1
+#elif defined(CONFIG_UART4_SERIAL_CONSOLE) && defined(CONFIG_KINETIS_UART4)
+# undef CONFIG_UART0_SERIAL_CONSOLE
+# undef CONFIG_UART1_SERIAL_CONSOLE
+# undef CONFIG_UART2_SERIAL_CONSOLE
+# undef CONFIG_UART3_SERIAL_CONSOLE
+# undef CONFIG_UART5_SERIAL_CONSOLE
+# define HAVE_CONSOLE 1
+#elif defined(CONFIG_UART5_SERIAL_CONSOLE) && defined(CONFIG_KINETIS_UART5)
+# undef CONFIG_UART0_SERIAL_CONSOLE
+# undef CONFIG_UART1_SERIAL_CONSOLE
+# undef CONFIG_UART2_SERIAL_CONSOLE
+# undef CONFIG_UART3_SERIAL_CONSOLE
+# undef CONFIG_UART4_SERIAL_CONSOLE
+# define HAVE_CONSOLE 1
+#else
+# undef CONFIG_UART0_SERIAL_CONSOLE
+# undef CONFIG_UART1_SERIAL_CONSOLE
+# undef CONFIG_UART2_SERIAL_CONSOLE
+# undef CONFIG_UART3_SERIAL_CONSOLE
+# undef CONFIG_UART4_SERIAL_CONSOLE
+# undef CONFIG_UART5_SERIAL_CONSOLE
+# undef HAVE_CONSOLE
+#endif
+
+/* Check UART flow control (Not yet supported) */
+
+# undef CONFIG_UART0_FLOWCONTROL
+# undef CONFIG_UART1_FLOWCONTROL
+# undef CONFIG_UART2_FLOWCONTROL
+# undef CONFIG_UART3_FLOWCONTROL
+# undef CONFIG_UART4_FLOWCONTROL
+# undef CONFIG_UART5_FLOWCONTROL
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Data
+ ************************************************************************************/
+
+/************************************************************************************
+ * Inline Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+#endif /* __ARCH_ARM_SRC_KINETISXX_KINETIS_CONFIG_H */
diff --git a/nuttx/arch/arm/src/kinetis/kinetis_internal.h b/nuttx/arch/arm/src/kinetis/kinetis_internal.h index 8f6a911a3..7b0383cdf 100644 --- a/nuttx/arch/arm/src/kinetis/kinetis_internal.h +++ b/nuttx/arch/arm/src/kinetis/kinetis_internal.h @@ -310,6 +310,32 @@ EXTERN void kinetis_clockconfig(void); EXTERN void kinetis_lowsetup(void); +/****************************************************************************** + * Name: kinetis_uartreset + * + * Description: + * Reset a UART. + * + ******************************************************************************/ + +#ifdef HAVE_UART_DEVICE +EXTERN void kinetis_uartreset(uintptr_t uart_base); +#endif + +/****************************************************************************** + * Name: kinetis_uartconfigure + * + * Description: + * Configure a UART as a RS-232 UART. + * + ******************************************************************************/ + +#ifdef HAVE_UART_DEVICE +EXTERN void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baudrate, + unsigned int parity, unsigned int nbits, + bool stop2); +#endif + /************************************************************************************ * Name: kinetis_wddisable * diff --git a/nuttx/arch/arm/src/kinetis/kinetis_lowputc.c b/nuttx/arch/arm/src/kinetis/kinetis_lowputc.c new file mode 100755 index 000000000..e403d4706 --- /dev/null +++ b/nuttx/arch/arm/src/kinetis/kinetis_lowputc.c @@ -0,0 +1,263 @@ +/************************************************************************** + * arch/arm/src/kinetis/kinetis_lowputc.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************/ + +/************************************************************************** + * Included Files + **************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> + +#include <arch/irq.h> +#include <arch/board/board.h> + +#include "up_internal.h" +#include "up_arch.h" + +#include "kinetis_config.h" +#include "kinetis_internal.h" +#include "kinetis_uart.h" + +/************************************************************************** + * Private Definitions + **************************************************************************/ + +/* Select UART parameters for the selected console */ + +#if defined(CONFIG_UART0_SERIAL_CONSOLE) +# define CONSOLE_BASE KINETIS_UART0_BASE +# define CONSOLE_BAUD CONFIG_UART0_BAUD +# define CONSOLE_BITS CONFIG_UART0_BITS +# define CONSOLE_PARITY CONFIG_UART0_PARITY +# define CONSOLE_2STOP CONFIG_UART0_2STOP +#elif defined(CONFIG_UART1_SERIAL_CONSOLE) +# define CONSOLE_BASE KINETIS_UART1_BASE +# define CONSOLE_BAUD CONFIG_UART1_BAUD +# define CONSOLE_BITS CONFIG_UART1_BITS +# define CONSOLE_PARITY CONFIG_UART1_PARITY +# define CONSOLE_2STOP CONFIG_UART1_2STOP +#elif defined(CONFIG_UART2_SERIAL_CONSOLE) +# define CONSOLE_BASE KINETIS_UART2_BASE +# define CONSOLE_BAUD CONFIG_UART2_BAUD +# define CONSOLE_BITS CONFIG_UART2_BITS +# define CONSOLE_PARITY CONFIG_UART2_PARITY +# define CONSOLE_2STOP CONFIG_UART2_2STOP +#elif defined(CONFIG_UART3_SERIAL_CONSOLE) +# define CONSOLE_BASE KINETIS_UART3_BASE +# define CONSOLE_BAUD CONFIG_UART3_BAUD +# define CONSOLE_BITS CONFIG_UART3_BITS +# define CONSOLE_PARITY CONFIG_UART3_PARITY +# define CONSOLE_2STOP CONFIG_UART3_2STOP +#elif defined(CONFIG_UART4_SERIAL_CONSOLE) +# define CONSOLE_BASE KINETIS_UART4_BASE +# define CONSOLE_BAUD CONFIG_UART4_BAUD +# define CONSOLE_BITS CONFIG_UART4_BITS +# define CONSOLE_PARITY CONFIG_UART4_PARITY +# define CONSOLE_2STOP CONFIG_UART4_2STOP +#elif defined(CONFIG_UART5_SERIAL_CONSOLE) +# define CONSOLE_BASE KINETIS_UART5_BASE +# define CONSOLE_BAUD CONFIG_UART5_BAUD +# define CONSOLE_BITS CONFIG_UART5_BITS +# define CONSOLE_PARITY CONFIG_UART5_PARITY +# define CONSOLE_2STOP CONFIG_UART5_2STOP +#elif defined(HAVE_CONSOLE) +# error "No CONFIG_UARTn_SERIAL_CONSOLE Setting" +#endif + +/* Get word length setting for the console */ +# warning "Missing logic" + +/* Get parity setting for the console */ +# warning "Missing logic" + +/* Get stop-bit setting for the console and UART0-3 */ +# warning "Missing logic" + +/* Select a divider to produce the UART CLK */ +# warning "Missing logic" + +/************************************************************************** + * Private Types + **************************************************************************/ + +/************************************************************************** + * Private Function Prototypes + **************************************************************************/ + +/************************************************************************** + * Global Variables + **************************************************************************/ + +/************************************************************************** + * Private Variables + **************************************************************************/ + +/************************************************************************** + * Private Functions + **************************************************************************/ + +/************************************************************************** + * Public Functions + **************************************************************************/ + +/************************************************************************** + * Name: up_lowputc + * + * Description: + * Output one byte on the serial console + * + **************************************************************************/ + +void up_lowputc(char ch) +{ +#if defined HAVE_UART && defined HAVE_CONSOLE +# warning "Missing logic" +#endif +} + +/************************************************************************** + * Name: kinetis_lowsetup + * + * Description: + * This performs basic initialization of the UART used for the serial + * console. Its purpose is to get the console output availabe as soon + * as possible. + * + * The UART0/1/2/3 peripherals are configured using the following registers: + * 1. Power: In the PCONP register, set bits PCUART0/1/2/3. + * On reset, UART0 and UART 1 are enabled (PCUART0 = 1 and PCUART1 = 1) + * and UART2/3 are disabled (PCUART1 = 0 and PCUART3 = 0). + * 2. Peripheral clock: In the PCLKSEL0 register, select PCLK_UART0 and + * PCLK_UART1; in the PCLKSEL1 register, select PCLK_UART2 and PCLK_UART3. + * 3. Baud rate: In the LCR register, set bit DLAB = 1. This enables access + * to registers DLL and DLM for setting the baud rate. Also, if needed, + * set the fractional baud rate in the fractional divider + * 4. UART FIFO: Use bit FIFO enable (bit 0) in FCR register to + * enable FIFO. + * 5. Pins: Select UART pins through the PINSEL registers and pin modes + * through the PINMODE registers. UART receive pins should not have + * pull-down resistors enabled. + * 6. Interrupts: To enable UART interrupts set bit DLAB = 0 in the LCRF + * register. This enables access to IER. Interrupts are enabled + * in the NVIC using the appropriate Interrupt Set Enable register. + * 7. DMA: UART transmit and receive functions can operate with the + * GPDMA controller. + * + **************************************************************************/ + +void kinetis_lowsetup(void) +{ +#ifdef HAVE_UART + uint32_t regval; + + /* Step 1: Enable power for all console UART and disable power for + * other UARTs + */ + +# warning "Missing logic" + + /* Step 2: Enable peripheral clocking for the console UART and disable + * clocking for all other UARTs + */ + +# warning "Missing logic" + + /* Configure UART pins for the selected CONSOLE */ + +#if defined(CONFIG_UART0_SERIAL_CONSOLE) + kinetis_configgpio(GPIO_UART0_TXD); + kinetis_configgpio(GPIO_UART0_RXD); +#elif defined(CONFIG_UART1_SERIAL_CONSOLE) + kinetis_configgpio(GPIO_UART1_TXD); + kinetis_configgpio(GPIO_UART1_RXD); +#elif defined(CONFIG_UART2_SERIAL_CONSOLE) + kinetis_configgpio(GPIO_UART2_TXD); + kinetis_configgpio(GPIO_UART2_RXD); +#elif defined(CONFIG_UART3_SERIAL_CONSOLE) + kinetis_configgpio(GPIO_UART3_TXD); + kinetis_configgpio(GPIO_UART3_RXD); +#elif defined(CONFIG_UART4_SERIAL_CONSOLE) + kinetis_configgpio(GPIO_UART3_TXD); + kinetis_configgpio(GPIO_UART3_RXD); +#elif defined(CONFIG_UART5_SERIAL_CONSOLE) + kinetis_configgpio(GPIO_UART3_TXD); + kinetis_configgpio(GPIO_UART3_RXD); +#endif + + /* Configure the console (only) */ + +#if defined(HAVE_CONSOLE) && !defined(CONFIG_SUPPRESS_UART_CONFIG) + + kinetis_uartconfigure(CONSOLE_BASE, CONSOLE_BAUD, CONSOLE_PARITY, + CONSOLE_BITS, CONSOLE_2STOP); +#endif +#endif /* HAVE_UART */ +} + +/****************************************************************************** + * Name: kinetis_uartreset + * + * Description: + * Reset a UART. + * + ******************************************************************************/ + +#ifdef HAVE_UART_DEVICE +void kinetis_uartreset(uintptr_t uart_base) +{ +# warning "Missing logic" +} +#endif + +/****************************************************************************** + * Name: kinetis_uartconfigure + * + * Description: + * Configure a UART as a RS-232 UART. + * + ******************************************************************************/ + +#ifdef HAVE_UART_DEVICE +void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baudrate, + unsigned int parity, unsigned int nbits, + bool stop2) +{ +# warning "Missing logic" +} +#endif + + + diff --git a/nuttx/arch/arm/src/kinetis/kinetis_mcg.c b/nuttx/arch/arm/src/kinetis/kinetis_mcg.c deleted file mode 100644 index c02b0a49c..000000000 --- a/nuttx/arch/arm/src/kinetis/kinetis_mcg.c +++ /dev/null @@ -1,139 +0,0 @@ -/****************************************************************************
- * arch/arm/src/kinetis/kinetis_mcg.c
- * arch/arm/src/chip/kinetis_mcg.c
- *
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include "up_arch.h"
-
-#include "kinetis_internal.h"
-#include "kinetis_mcg.h"
-#include "kinetis_sim.h"
-#include "kinetis_fmc.h"
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-#ifndef CONFIG_BOOT_RAMFUNCS
-# error "CONFIG_BOOT_RAMFUNCS must be defined for this logic"
-#endif
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static void __ramfunc__
-kinesis_setdividers(uint32_t div1, uint32_t div2, uint32_t div3, uint32_t div4);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: kinesis_setdividers
- *
- * Description:
- * "This routine must be placed in RAM. It is a workaround for errata e2448.
- * Flash prefetch must be disabled when the flash clock divider is changed.
- * This cannot be performed while executing out of flash. There must be a
- * short delay after the clock dividers are changed before prefetch can be
- * re-enabled."
- *
- ****************************************************************************/
-
-static void __ramfunc__
-kinesis_setdividers(uint32_t div1, uint32_t div2, uint32_t div3, uint32_t div4)
-{
- uint32_t regval;
- int i;
-
- /* Save the current value of the Flash Access Protection Register */
-
- regval = getreg32(KINETIS_FMC_PFAPR);
-
- /* Set M0PFD through M7PFD to 1 to disable prefetch */
-
- putreg32(FMC_PFAPR_M7PFD | FMC_PFAPR_M6PFD | FMC_PFAPR_M5PFD |
- FMC_PFAPR_M4PFD | FMC_PFAPR_M3PFD | FMC_PFAPR_M2PFD |
- FMC_PFAPR_M1PFD | FMC_PFAPR_M0PFD,
- KINETIS_FMC_PFAPR);
-
- /* Set clock dividers to desired value */
-
- putreg32(SIM_CLKDIV1_OUTDIV1(div1) | SIM_CLKDIV1_OUTDIV2(div2) |
- SIM_CLKDIV1_OUTDIV3(div3) | SIM_CLKDIV1_OUTDIV4(div4),
- KINETIS_SIM_CLKDIV1);
-
- /* Wait for dividers to change */
-
- for (i = 0 ; i < div4 ; i++);
-
- /* Re-store saved value of FMC_PFAPR */
-
- putreg32(regval, KINETIS_FMC_PFAPR);
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/************************************************************************************
- * Name: kinetis_clockconfig
- *
- * Description:
- * Called to initialize the Kinetis chip. This does whatever setup is needed to
- * put the MCU in a usable state. This includes the initialization of clocking
- * using the settings in board.h.
- *
- ************************************************************************************/
-
-void kinetis_clockconfig(void)
-{
-#warning "Missing logic"
-}
-
diff --git a/nuttx/arch/arm/src/kinetis/kinetis_mcg.h b/nuttx/arch/arm/src/kinetis/kinetis_mcg.h index cb6d22c4a..6f0ba652c 100644 --- a/nuttx/arch/arm/src/kinetis/kinetis_mcg.h +++ b/nuttx/arch/arm/src/kinetis/kinetis_mcg.h @@ -133,8 +133,8 @@ /* MCG Control 5 Register */ #define MCG_C5_PRDIV_SHIFT (0) /* Bits 0-4: PLL External Reference Divider */ -#define MCG_C5_PRDIV_MASK (31 << PRDIV_SHIFT) -# define MCG_C5_PRDIV(n) (((n)-1) << PRDIV_SHIFT) /* Divide factor n=1..25 */ +#define MCG_C5_PRDIV_MASK (31 << MCG_C5_PRDIV_SHIFT) +# define MCG_C5_PRDIV(n) (((n)-1) << MCG_C5_PRDIV_SHIFT) /* Divide factor n=1..25 */ #define MCG_C5_PLLSTEN (1 << 5) /* Bit 5: PLL Stop Enable */ #define MCG_C5_PLLCLKEN (1 << 6) /* Bit 6: PLL Clock Enable */ /* Bit 7: Reserved */ @@ -142,8 +142,8 @@ /* MCG Control 6 Register */ #define MCG_C6_VDIV_SHIFT (0) /* Bits 0-4: VCO Divider */ -#define MCG_C6_VDIV_MASK (31 << PRDIV_SHIFT) -# define MCG_C6_VDIV(n) (((n)-24) << PRDIV_SHIFT) /* Divide factor n=24..55 */ +#define MCG_C6_VDIV_MASK (31 << MCG_C6_VDIV_SHIFT) +# define MCG_C6_VDIV(n) (((n)-24) << MCG_C6_VDIV_SHIFT) /* Divide factor n=24..55 */ #define MCG_C6_CME (1 << 5) /* Bit 5: Clock Monitor Enable */ #define MCG_C6_PLLS (1 << 6) /* Bit 6: PLL Select */ #define MCG_C6_LOLIE (1 << 7) /* Bit 7: Loss of Lock Interrrupt Enable */ diff --git a/nuttx/arch/arm/src/kinetis/kinetis_start.c b/nuttx/arch/arm/src/kinetis/kinetis_start.c index 403424da2..1baa5e626 100755 --- a/nuttx/arch/arm/src/kinetis/kinetis_start.c +++ b/nuttx/arch/arm/src/kinetis/kinetis_start.c @@ -69,20 +69,6 @@ ****************************************************************************/ /**************************************************************************** - * Name: showprogress - * - * Description: - * Print a character on the UART to show boot status. - * - ****************************************************************************/ - -#ifdef CONFIG_DEBUG -# define showprogress(c) up_lowputc(c) -#else -# define showprogress(c) -#endif - -/**************************************************************************** * Public Functions ****************************************************************************/ @@ -103,12 +89,6 @@ void __start(void) kinetis_wddisable(); - /* Configure the uart so that we can get debug output as soon as possible */ - - kinetis_clockconfig(); - kinetis_lowsetup(); - showprogress('A'); - /* Clear .bss. We'll do this inline (vs. calling memset) just to be * certain that there are no issues with the state of global variables. */ @@ -117,7 +97,6 @@ void __start(void) { *dest++ = 0; } - showprogress('B'); /* Move the intialized data section from his temporary holding spot in * FLASH into the correct place in SRAM. The correct place in SRAM is @@ -129,7 +108,6 @@ void __start(void) { *dest++ = *src++; } - showprogress('C'); /* Copy any necessary code sections from FLASH to RAM. The correct * destination in SRAM is geive by _sramfuncs and _eramfuncs. The @@ -143,26 +121,28 @@ void __start(void) *dest++ = *src++; } #endif - showprogress('E'); - - /* Perform early serial initialization */ + /* Perform clock and Kinetis module initialization */ + + kinetis_clockconfig(); + + /* Configure the uart and perform early serial initialization so that we + * can get debug output as soon as possible. + */ + kinetis_lowsetup(); #ifdef CONFIG_USE_EARLYSERIALINIT up_earlyserialinit(); #endif - showprogress('F'); - /* Initialize onboard resources */ + /* Initialize other on-board resources */ kinetis_boardinitialize(); - showprogress('G'); - showprogress('\r'); - showprogress('\n'); /* Show reset status */ - dbg("Reset status: %02x:%02x\n", getreg8(KINETIS_SMC_SRSH), getreg8(KINETIS_SMC_SRSL)); + dbg("Reset status: %02x:%02x\n", + getreg8(KINETIS_SMC_SRSH), getreg8(KINETIS_SMC_SRSL)); /* Then start NuttX */ diff --git a/nuttx/arch/arm/src/kinetis/kinetis_uart.h b/nuttx/arch/arm/src/kinetis/kinetis_uart.h index af28dcbfc..f407bb7de 100644 --- a/nuttx/arch/arm/src/kinetis/kinetis_uart.h +++ b/nuttx/arch/arm/src/kinetis/kinetis_uart.h @@ -408,7 +408,7 @@ # define UART_PFIFO_RXFIFOSIZE_8 (2 << UART_PFIFO_RXFIFOSIZE_SHIFT) /* 8 */ # define UART_PFIFO_RXFIFOSIZE_16 (3 << UART_PFIFO_RXFIFOSIZE_SHIFT) /* 16 */ # define UART_PFIFO_RXFIFOSIZE_32 (4 << UART_PFIFO_RXFIFOSIZE_SHIFT) /* 32 */ -# define UART_PFIFO_RXFIFOSIZE_16 (5 << UART_PFIFO_RXFIFOSIZE_SHIFT) /* 64 */ +# define UART_PFIFO_RXFIFOSIZE_64 (5 << UART_PFIFO_RXFIFOSIZE_SHIFT) /* 64 */ # define UART_PFIFO_RXFIFOSIZE_128 (6 << UART_PFIFO_RXFIFOSIZE_SHIFT) /* 128 */ #define UART_PFIFO_RXFE (1 << 3) /* Bit 3: Receive FIFO Enable */ #define UART_PFIFO_TXFIFOSIZE_SHIFT (4) /* Bits 4-6: Transmit FIFO. Buffer Depth */ @@ -418,7 +418,7 @@ # define UART_PFIFO_TXFIFOSIZE_8 (2 << UART_PFIFO_TXFIFOSIZE_SHIFT) /* 8 */ # define UART_PFIFO_TXFIFOSIZE_16 (3 << UART_PFIFO_TXFIFOSIZE_SHIFT) /* 16 */ # define UART_PFIFO_TXFIFOSIZE_32 (4 << UART_PFIFO_TXFIFOSIZE_SHIFT) /* 32 */ -# define UART_PFIFO_TXFIFOSIZE_16 (5 << UART_PFIFO_TXFIFOSIZE_SHIFT) /* 64 */ +# define UART_PFIFO_TXFIFOSIZE_64 (5 << UART_PFIFO_TXFIFOSIZE_SHIFT) /* 64 */ # define UART_PFIFO_TXFIFOSIZE_128 (6 << UART_PFIFO_TXFIFOSIZE_SHIFT) /* 128 */ #define UART_PFIFO_TXFE (1 << 7) /* Bit 7: Transmit FIFO Enable */ diff --git a/nuttx/configs/kwikstik-k40/README.txt b/nuttx/configs/kwikstik-k40/README.txt index d24a5a473..9b479905d 100644 --- a/nuttx/configs/kwikstik-k40/README.txt +++ b/nuttx/configs/kwikstik-k40/README.txt @@ -254,55 +254,49 @@ KwikStik-K40-specific Configuration Options Individual subsystems can be enabled: - CONFIG_KINETIS_UART0 - CONFIG_KINETIS_UART1 - CONFIG_KINETIS_UART2 - CONFIG_KINETIS_UART3 - CONFIG_KINETIS_UART4 - CONFIG_KINETIS_UART5 - CONFIG_KINETIS_ETHERNET (K60 only) - CONFIG_KINETIS_RNGB (K60 only) - CONFIG_KINETIS_FLEXCAN0 - CONFIG_KINETIS_FLEXCAN1 - CONFIG_KINETIS_SPI0 - CONFIG_KINETIS_SPI1 - CONFIG_KINETIS_SPI2 - CONFIG_KINETIS_I2C0 - CONFIG_KINETIS_I2C1 - CONFIG_KINETIS_I2S - CONFIG_KINETIS_DAC0 - CONFIG_KINETIS_DAC1 - CONFIG_KINETIS_ADC0 - CONFIG_KINETIS_ADC1 - CONFIG_KINETIS_CMP - CONFIG_KINETIS_VREF - CONFIG_KINETIS_SDHC - CONFIG_KINETIS_FTM0 - CONFIG_KINETIS_FTM1 - CONFIG_KINETIS_FTM2 - CONFIG_KINETIS_LPTIMER - CONFIG_KINETIS_RTC - CONFIG_KINETIS_SLCD (K40 only) - CONFIG_KINETIS_EWM - CONFIG_KINETIS_CMT - CONFIG_KINETIS_USBOTG - CONFIG_KINETIS_USBDCD - CONFIG_KINETIS_LLWU - CONFIG_KINETIS_REGFILE - CONFIG_KINETIS_TSI - CONFIG_KINETIS_PORTA - CONFIG_KINETIS_PORTB - CONFIG_KINETIS_PORTC - CONFIG_KINETIS_PORTD - CONFIG_KINETIS_PORTE - CONFIG_KINETIS_FTFL - CONFIG_KINETIS_DMA - CONFIG_KINETIS_DMAMUX - CONFIG_KINETIS_CRC - CONFIG_KINETIS_PDB - CONFIG_KINETIS_PIT - CONFIG_KINETIS_FLEXBUS - CONFIG_KINETIS_MPU + CONFIG_KINETIS_TRACE -- Enable trace clocking on power up. + CONFIG_KINETIS_FLEXBUS -- Enable flexbus clocking on power up. + CONFIG_KINETIS_UART0 -- Support UART0 + CONFIG_KINETIS_UART1 -- Support UART1 + CONFIG_KINETIS_UART2 -- Support UART2 + CONFIG_KINETIS_UART3 -- Support UART3 + CONFIG_KINETIS_UART4 -- Support UART4 + CONFIG_KINETIS_UART5 -- Support UART5 + CONFIG_KINETIS_ETHERNET -- Support Ethernet (K60 only) + CONFIG_KINETIS_RNGB -- Support the random number generator(K60 only) + CONFIG_KINETIS_FLEXCAN0 -- Support FlexCAN0 + CONFIG_KINETIS_FLEXCAN1 -- Support FlexCAN1 + CONFIG_KINETIS_SPI0 -- Support SPI0 + CONFIG_KINETIS_SPI1 -- Support SPI1 + CONFIG_KINETIS_SPI2 -- Support SPI2 + CONFIG_KINETIS_I2C0 -- Support I2C0 + CONFIG_KINETIS_I2C1 -- Support I2C1 + CONFIG_KINETIS_I2S -- Support I2S + CONFIG_KINETIS_DAC0 -- Support DAC0 + CONFIG_KINETIS_DAC1 -- Support DAC1 + CONFIG_KINETIS_ADC0 -- Support ADC0 + CONFIG_KINETIS_ADC1 -- Support ADC1 + CONFIG_KINETIS_CMP -- Support CMP + CONFIG_KINETIS_VREF -- Support VREF + CONFIG_KINETIS_SDHC -- Support SD host controller + CONFIG_KINETIS_FTM0 -- Support FlexTimer 0 + CONFIG_KINETIS_FTM1 -- Support FlexTimer 1 + CONFIG_KINETIS_FTM2 -- Support FlexTimer 2 + CONFIG_KINETIS_LPTIMER -- Support the low power timer + CONFIG_KINETIS_RTC -- Support RTC + CONFIG_KINETIS_SLCD -- Support the segment LCD (K40 only) + CONFIG_KINETIS_EWM -- Support the external watchdog + CONFIG_KINETIS_CMT -- Support Carrier Modulator Transmitter + CONFIG_KINETIS_USBOTG -- Support USB OTG (see also CONFIG_USBHOST and CONFIG_USBDEV) + CONFIG_KINETIS_USBDCD -- Support the USB Device Charger Detection module + CONFIG_KINETIS_LLWU -- Support the Low Leakage Wake-Up Unit + CONFIG_KINETIS_TSI -- Support the touch screeen interface + CONFIG_KINETIS_FTFL -- Support FLASH + CONFIG_KINETIS_DMA -- Support DMA + CONFIG_KINETIS_CRC -- Support CRC + CONFIG_KINETIS_PDB -- Support the Programmable Delay Block + CONFIG_KINETIS_PIT -- Support Programmable Interval Timers + CONFIG_ARMV7M_MPU -- Support the MPU Kinetis K40 specific device driver settings diff --git a/nuttx/configs/kwikstik-k40/include/board.h b/nuttx/configs/kwikstik-k40/include/board.h index be47b9ebf..85f2afeb5 100755 --- a/nuttx/configs/kwikstik-k40/include/board.h +++ b/nuttx/configs/kwikstik-k40/include/board.h @@ -51,6 +51,38 @@ ************************************************************************************/ /* Clocking *************************************************************************/ +/* The Kwikstik-K40 has a 4MHz crystal on board */ + +#undef BOARD_EXTCLOCK /* Crystal */ +#define BOARD_EXTAL_FREQ 4000000 /* 4MHz crystal frequency (REFCLK) */ +#define BOARD_XTAL32_FREQ 32768 /* 32KHz RTC Oscillator */ + +/* PLL Configuration. NOTE: Only even frequency crystals are supported that will + * produce a 2MHz reference clock to the PLL. + * + * PLL Input frequency: PLLIN = REFCLK/PRDIV = 4MHz/2 = 2MHz + * PLL Output frequency: PLLOUT = PLLIN*VDIV = 2Mhz*48 = 96MHz + * MCG Frequency: PLLOUT = 96MHz + */ + +#define BOARD_PRDIV 2 /* PLL External Reference Divider */ +#define BOARD_VDIV 48 /* PLL VCO Divider (frequency multiplier) */ + +#define BOARD_PLLIN_FREQ (BOARD_EXTAL_FREQ / BOARD_PRDIV) +#define BOARD_PLLOUT_FREQ (BOARD_EXTAL_FREQ * BOARD_VDIV) +#define BOARD_MCG_FREQ BOARD_PLL_FREQ + +/* SIM CLKDIV1 dividers */ + +#define BOARD_OUTDIV1 1 /* Core = MCG, 96MHz */ +#define BOARD_OUTDIV2 2 /* Bus = MCG/2, 48MHz */ +#define BOARD_OUTDIV3 2 /* FlexBus = MCG/2, 48MHz */ +#define BOARD_OUTDIV4 4 /* Flash clock = MCG/4, 24MHz */ + +#define BOARD_CORECLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV1) +#define BOARD_BUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV2) +#define BOARD_FLEXBUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV3) +#define BOARD_FLASHCLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV4) /* LED definitions ******************************************************************/ diff --git a/nuttx/configs/twr-k60n512/include/board.h b/nuttx/configs/twr-k60n512/include/board.h new file mode 100755 index 000000000..3cad12ac4 --- /dev/null +++ b/nuttx/configs/twr-k60n512/include/board.h @@ -0,0 +1,168 @@ +/************************************************************************************ + * configs/twr-k60n512/include/board.h + * include/arch/board/board.h + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_BOARD_BOARD_H +#define __ARCH_BOARD_BOARD_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include <nuttx/config.h> +#ifndef __ASSEMBLY__ +# include <stdint.h> +#endif + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/* Clocking *************************************************************************/ +/* The K60 tower board uses a 50MHz external clock */ + +#define BOARD_EXTCLOCK 1 /* External clock */ +#define BOARD_EXTAL_FREQ 50000000 /* 50MHz Oscillator */ +#define BOARD_XTAL32_FREQ 32768 /* 32KHz RTC Oscillator */ + +/* PLL Configuration. Either the external clock or crystal frequency is used to + * select the PRDIV value. Only reference clock frequencies are supported that will + * produce a 2MHz reference clock to the PLL. + * + * PLL Input frequency: PLLIN = REFCLK/PRDIV = 50MHz/25 = 2MHz + * PLL Output frequency: PLLOUT = PLLIN*VDIV = 2Mhz*48 = 96MHz + * MCG Frequency: PLLOUT = 96MHz + */ + +#define BOARD_PRDIV 25 /* PLL External Reference Divider */ +#define BOARD_VDIV 48 /* PLL VCO Divider (frequency multiplier) */ + +#define BOARD_PLLIN_FREQ (BOARD_EXTAL_FREQ / BOARD_PRDIV) +#define BOARD_PLLOUT_FREQ (BOARD_EXTAL_FREQ * BOARD_VDIV) +#define BOARD_MCG_FREQ BOARD_PLL_FREQ + +/* SIM CLKDIV1 dividers */ + +#define BOARD_OUTDIV1 1 /* Core = MCG, 96MHz */ +#define BOARD_OUTDIV2 2 /* Bus = MCG/2, 48MHz */ +#define BOARD_OUTDIV3 2 /* FlexBus = MCG/2, 48MHz */ +#define BOARD_OUTDIV4 4 /* Flash clock = MCG/4, 24MHz */ + +#define BOARD_CORECLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV1) +#define BOARD_BUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV2) +#define BOARD_FLEXBUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV3) +#define BOARD_FLASHCLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV4) + +/* LED definitions ******************************************************************/ + +#define LED_STARTED 0 +#define LED_HEAPALLOCATE 1 +#define LED_IRQSENABLED 2 +#define LED_STACKCREATED 3 +#define LED_INIRQ 4 +#define LED_SIGNAL 5 +#define LED_ASSERTION 6 +#define LED_PANIC 7 + +/* Button definitions ***************************************************************/ + + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Public Function Prototypes + ************************************************************************************/ +/************************************************************************************ + * Name: kinetis_boardinitialize + * + * Description: + * All STM32 architectures must provide the following entry point. This entry point + * is called early in the intitialization -- after all memory has been configured + * and mapped but before any devices have been initialized. + * + ************************************************************************************/ + +EXTERN void kinetis_boardinitialize(void); + +/************************************************************************************ + * Button support. + * + * Description: + * up_buttoninit() must be called to initialize button resources. After + * that, up_buttons() may be called to collect the current state of all + * buttons or up_irqbutton() may be called to register button interrupt + * handlers. + * + * After up_buttoninit() has been called, up_buttons() may be called to + * collect the state of all buttons. up_buttons() returns an 8-bit bit set + * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT + * definitions in board.h for the meaning of each bit. + * + * up_irqbutton() may be called to register an interrupt handler that will + * be called when a button is depressed or released. The ID value is a + * button enumeration value that uniquely identifies a button resource. See the + * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration + * value. The previous interrupt handler address is returned (so that it may + * restored, if so desired). + * + ************************************************************************************/ + +#ifdef CONFIG_ARCH_BUTTONS +EXTERN void up_buttoninit(void); +EXTERN uint8_t up_buttons(void); +#ifdef CONFIG_ARCH_IRQBUTTONS +EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler); +#endif +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_BOARD_BOARD_H */ |