2016-07-01 23:42:21 +02:00
|
|
|
/************************************************************************************
|
|
|
|
* configs/freedom-k64f/include/board.h
|
|
|
|
*
|
2016-07-02 01:43:27 +02:00
|
|
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
2016-07-01 23:42:21 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
************************************************************************************/
|
|
|
|
|
2016-07-02 01:43:27 +02:00
|
|
|
#ifndef __CONFIG_FREEDOM_K64F_INCLUDE_BOARD_H
|
|
|
|
#define __CONFIG_FREEDOM_K64F_INCLUDE_BOARD_H
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Included Files
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2016-07-12 21:46:27 +02:00
|
|
|
|
2016-07-01 23:42:21 +02:00
|
|
|
#ifndef __ASSEMBLY__
|
2016-07-12 21:46:27 +02:00
|
|
|
# include <stdint.h>
|
2016-07-01 23:42:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/* Clocking *************************************************************************/
|
2016-07-02 17:04:27 +02:00
|
|
|
/* The Freedom K64F uses a 50MHz external clock from the Micrel Ethernet PHY. The
|
|
|
|
* Kinetis MCU startup from an internal digitally-controlled oscillator (DCO). Nuttx
|
|
|
|
* will enable the main external oscillator (EXTAL0/XTAL0). The external
|
|
|
|
* oscillator/resonator can range from 32.768 KHz up to 50 MHz. The default external
|
|
|
|
* source for the MCG oscillator inputs (EXTAL) is 50 MHz clock source from Micrel
|
|
|
|
* Ethernet PHY.
|
|
|
|
*/
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
#define BOARD_EXTCLOCK 1 /* External clock */
|
2016-07-06 19:03:27 +02:00
|
|
|
#define BOARD_EXTAL_FREQ 50000000 /* 50MHz Oscillator from Micrel PHY */
|
2016-07-01 23:42:21 +02:00
|
|
|
#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.
|
|
|
|
*
|
2016-07-06 19:03:27 +02:00
|
|
|
* PLL Input frequency: PLLIN = REFCLK / PRDIV = 50 Mhz / 20 = 2.5 MHz
|
|
|
|
* PLL Output frequency: PLLOUT = PLLIN * VDIV = 2.5 Mhz * 48 = 120 MHz
|
2016-07-12 23:05:35 +02:00
|
|
|
* MCG Frequency: PLLOUT = 120 MHz
|
2016-07-06 19:03:27 +02:00
|
|
|
*
|
|
|
|
* PRDIV register value is the divider minus one. So 20 -> 19
|
|
|
|
* VDIV regiser value is offset by 24. So 28 -> 24
|
2016-07-01 23:42:21 +02:00
|
|
|
*/
|
|
|
|
|
2016-07-06 19:03:27 +02:00
|
|
|
#define BOARD_PRDIV 20 /* PLL External Reference Divider */
|
|
|
|
#define BOARD_VDIV 48 /* PLL VCO Divider (frequency multiplier) */
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
#define BOARD_PLLIN_FREQ (BOARD_EXTAL_FREQ / BOARD_PRDIV)
|
|
|
|
#define BOARD_PLLOUT_FREQ (BOARD_PLLIN_FREQ * BOARD_VDIV)
|
|
|
|
#define BOARD_MCG_FREQ BOARD_PLLOUT_FREQ
|
|
|
|
|
|
|
|
/* SIM CLKDIV1 dividers */
|
|
|
|
|
2016-07-06 19:03:27 +02:00
|
|
|
#define BOARD_OUTDIV1 1 /* Core = MCG, 120 MHz */
|
|
|
|
#define BOARD_OUTDIV2 2 /* Bus = MCG / 2, 60 MHz */
|
|
|
|
#define BOARD_OUTDIV3 2 /* FlexBus = MCG / 2, 60 MHz */
|
2016-07-06 20:11:26 +02:00
|
|
|
#define BOARD_OUTDIV4 5 /* Flash clock = MCG / 5, 24 MHz */
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
#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)
|
|
|
|
|
|
|
|
/* SDHC clocking ********************************************************************/
|
|
|
|
|
|
|
|
/* SDCLK configurations corresponding to various modes of operation. Formula is:
|
|
|
|
*
|
|
|
|
* SDCLK frequency = (base clock) / (prescaler * divisor)
|
|
|
|
*
|
|
|
|
* The SDHC module is always configure configured so that the core clock is the base
|
2016-07-12 23:05:35 +02:00
|
|
|
* clock. Possible values for presscaler and divisor are:
|
|
|
|
*
|
|
|
|
* SDCLKFS: {2, 4, 8, 16, 32, 63, 128, 256}
|
|
|
|
* DVS: {1..16}
|
2016-07-01 23:42:21 +02:00
|
|
|
*/
|
|
|
|
|
2016-07-12 23:05:35 +02:00
|
|
|
/* Identification mode: Optimal 400KHz, Actual 120MHz / (32 * 10) = 375 Khz */
|
2016-07-01 23:42:21 +02:00
|
|
|
|
2016-07-12 23:05:35 +02:00
|
|
|
#define BOARD_SDHC_IDMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV32
|
|
|
|
#define BOARD_SDHC_IDMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(10)
|
2016-07-01 23:42:21 +02:00
|
|
|
|
2016-07-12 23:05:35 +02:00
|
|
|
/* MMC normal mode: Optimal 20MHz, Actual 120MHz / (2 * 3) = 20 MHz */
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
#define BOARD_SDHC_MMCMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
|
|
|
|
#define BOARD_SDHC_MMCMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3)
|
|
|
|
|
2016-07-12 23:05:35 +02:00
|
|
|
/* SD normal mode (1-bit): Optimal 20MHz, Actual 120MHz / (2 * 3) = 20 MHz */
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
#define BOARD_SDHC_SD1MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
|
|
|
|
#define BOARD_SDHC_SD1MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3)
|
|
|
|
|
2016-07-12 23:05:35 +02:00
|
|
|
/* SD normal mode (4-bit): Optimal 25MHz, Actual 120MHz / (2 * 3) = 20 MHz (with DMA)
|
|
|
|
* SD normal mode (4-bit): Optimal 20MHz, Actual 120MHz / (2 * 3) = 20 MHz (no DMA)
|
2016-07-01 23:42:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SDIO_DMA
|
|
|
|
# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
|
2016-07-12 23:05:35 +02:00
|
|
|
# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3)
|
2016-07-01 23:42:21 +02:00
|
|
|
#else
|
2016-07-12 23:05:35 +02:00
|
|
|
# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2
|
|
|
|
# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3)
|
2016-07-01 23:42:21 +02:00
|
|
|
#endif
|
|
|
|
|
2016-07-25 21:17:07 +02:00
|
|
|
/* PWM Configuration */
|
|
|
|
/* FTM0 Channels */
|
2016-07-25 22:53:28 +02:00
|
|
|
/* Channels can be modified using kinetis_k64pinmux.h */
|
2016-07-25 21:17:07 +02:00
|
|
|
|
|
|
|
#define GPIO_FTM0_CH0OUT PIN_FTM0_CH0_1
|
|
|
|
#define GPIO_FTM0_CH1OUT PIN_FTM0_CH1_1
|
|
|
|
#define GPIO_FTM0_CH2OUT PIN_FTM0_CH2_2
|
|
|
|
#define GPIO_FTM0_CH3OUT PIN_FTM0_CH3_1
|
|
|
|
#define GPIO_FTM0_CH4OUT PIN_FTM0_CH4_1
|
|
|
|
#define GPIO_FTM0_CH5OUT PIN_FTM0_CH5_1
|
|
|
|
|
2016-07-01 23:42:21 +02:00
|
|
|
/* LED definitions ******************************************************************/
|
2016-07-02 15:56:43 +02:00
|
|
|
/* The Freedom K64F has a single RGB LED driven by the K64F as follows:
|
2016-07-01 23:42:21 +02:00
|
|
|
*
|
2016-07-02 15:56:43 +02:00
|
|
|
* LED K64
|
|
|
|
* ------ -------------------------------------------------------
|
|
|
|
* RED PTB22/SPI2_SOUT/FB_AD29/CMP2_OUT
|
|
|
|
* BLUE PTB21/SPI2_SCK/FB_AD30/CMP1_OUT
|
|
|
|
* GREEN PTE26/ENET_1588_CLKIN/UART4_CTS_b/RTC_CLKOUT/USB0_CLKIN
|
2016-07-01 23:42:21 +02:00
|
|
|
*
|
2016-07-02 16:07:08 +02:00
|
|
|
* If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in any
|
|
|
|
* way. The following definitions are used to access individual LEDs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* LED index values for use with board_userled() */
|
|
|
|
|
|
|
|
#define BOARD_LED_R 0
|
|
|
|
#define BOARD_LED_G 1
|
|
|
|
#define BOARD_LED_B 2
|
|
|
|
#define BOARD_NLEDS 3
|
|
|
|
|
|
|
|
/* LED bits for use with board_userled_all() */
|
|
|
|
|
|
|
|
#define BOARD_LED_R_BIT (1 << BOARD_LED_R)
|
|
|
|
#define BOARD_LED_G_BIT (1 << BOARD_LED_G)
|
|
|
|
#define BOARD_LED_B_BIT (1 << BOARD_LED_B)
|
|
|
|
|
|
|
|
/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board
|
2016-07-02 15:56:43 +02:00
|
|
|
* the Freedom K64F. The following definitions describe how NuttX controls
|
|
|
|
* the LEDs:
|
|
|
|
*
|
2016-07-12 00:54:20 +02:00
|
|
|
* SYMBOL Meaning LED state
|
|
|
|
* RED GREEN BLUE
|
|
|
|
* ------------------- ---------------------------- ----------------- */
|
|
|
|
#define LED_STARTED 1 /* NuttX has been started OFF OFF OFF */
|
|
|
|
#define LED_HEAPALLOCATE 2 /* Heap has been allocated OFF OFF ON */
|
|
|
|
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF OFF ON */
|
|
|
|
#define LED_STACKCREATED 3 /* Idle stack created OFF ON OFF */
|
|
|
|
#define LED_INIRQ 0 /* In an interrupt (no change) */
|
|
|
|
#define LED_SIGNAL 0 /* In a signal handler (no change) */
|
|
|
|
#define LED_ASSERTION 0 /* An assertion failed (no change) */
|
|
|
|
#define LED_PANIC 4 /* The system has crashed FLASH OFF OFF */
|
|
|
|
#undef LED_IDLE /* K64 is in sleep mode (Not used) */
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
/* Button definitions ***************************************************************/
|
2016-07-02 16:18:42 +02:00
|
|
|
/* Two push buttons, SW2 and SW3, are available on FRDM-K64F board, where SW2 is
|
|
|
|
* connected to PTC6 and SW3 is connected to PTA4. Besides the general purpose
|
|
|
|
* input/output functions, SW2 and SW3 can be low-power wake up signal. Also, only
|
|
|
|
* SW3 can be a non-maskable interrupt.
|
2016-07-01 23:42:21 +02:00
|
|
|
*
|
2016-07-02 16:18:42 +02:00
|
|
|
* Switch GPIO Function
|
|
|
|
* --------- ---------------------------------------------------------------
|
|
|
|
* SW2 PTC6/SPI0_SOUT/PD0_EXTRG/I2S0_RX_BCLK/FB_AD9/I2S0_MCLK/LLWU_P10
|
|
|
|
* SW3 PTA4/FTM0_CH1/NMI_b/LLWU_P3
|
2016-07-01 23:42:21 +02:00
|
|
|
*/
|
|
|
|
|
2016-07-02 16:18:42 +02:00
|
|
|
#define BUTTON_SW2 0
|
|
|
|
#define BUTTON_SW3 1
|
2016-07-01 23:42:21 +02:00
|
|
|
|
2016-07-02 22:42:29 +02:00
|
|
|
#define BUTTON_SW2_BIT (1 << BUTTON_SW2)
|
|
|
|
#define BUTTON_SW3_BIT (1 << BUTTON_SW3)
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
/* Alternative pin resolution *******************************************************/
|
|
|
|
/* If there are alternative configurations for various pins in the
|
2016-07-02 17:04:27 +02:00
|
|
|
* kinetis_k64pinmux.h header file, those alternative pins will be labeled with a
|
2016-07-01 23:42:21 +02:00
|
|
|
* suffix like _1, _2, etc. The logic in this file must select the correct pin
|
|
|
|
* configuration for the board by defining a pin configuration (with no suffix) that
|
|
|
|
* maps to the correct alternative.
|
|
|
|
*/
|
|
|
|
|
2016-07-02 21:58:29 +02:00
|
|
|
/* The primary serial port interface signals are PTB16 UART0_RX and PTB17 UART0_TX.
|
2016-07-02 19:48:56 +02:00
|
|
|
* These signals are connected to the OpenSDAv2 circuit.
|
|
|
|
*/
|
|
|
|
|
2016-07-02 21:58:29 +02:00
|
|
|
#define PIN_UART0_RX PIN_UART0_RX_3
|
|
|
|
#define PIN_UART0_TX PIN_UART0_TX_3
|
|
|
|
|
2016-07-02 23:27:12 +02:00
|
|
|
/* An alternative serial port might use a standard serial shield mounted
|
|
|
|
* on the Freedom Board. In this case, Arduino pin D1 provides UART TX and
|
|
|
|
* pin D0 privides UART RX.
|
|
|
|
*
|
|
|
|
* The I/O headers on the FRDM-K64F board are arranged to enable
|
|
|
|
* compatibility with Arduino shield. The outer rows of pins (even numbered
|
|
|
|
* pins) on the headers, share the same mechanical spacing and placement with
|
|
|
|
* the I/O headers on the Arduino Revision 3 (R3) standard.
|
|
|
|
*
|
|
|
|
* The Arduino D0 and D1 pins then correspond to pins 2 and 4 on the J1 I/O
|
|
|
|
* connector:
|
|
|
|
*
|
|
|
|
* Arduino Pin FRDM-K64F J1 Connector
|
|
|
|
* ------------------------ -----------------------
|
|
|
|
* UART TX, Arduino D1 pin Pin 4, PTC17, UART3_TX
|
|
|
|
* UART RX, Arduino D0 pin Pin 2, PTC16, UART3_RX
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PIN_UART3_RX PIN_UART3_RX_2
|
|
|
|
#define PIN_UART3_TX PIN_UART3_TX_2
|
|
|
|
|
2016-07-01 23:42:21 +02:00
|
|
|
/************************************************************************************
|
|
|
|
* Public Data
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2016-07-02 01:43:27 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2016-07-01 23:42:21 +02:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
************************************************************************************/
|
2016-07-02 01:43:27 +02:00
|
|
|
|
2016-07-01 23:42:21 +02:00
|
|
|
/************************************************************************************
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
************************************************************************************/
|
|
|
|
|
2016-07-02 01:43:27 +02:00
|
|
|
void kinetis_boardinitialize(void);
|
2016-07-01 23:42:21 +02:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
2016-07-02 01:43:27 +02:00
|
|
|
#endif /* __CONFIG_FREEDOM_K64F_INCLUDE_BOARD_H */
|