diff --git a/arch/arm/include/kinetis/kinetis_mcg.h b/arch/arm/include/kinetis/kinetis_mcg.h index b17ba6b700e..460d5564131 100644 --- a/arch/arm/include/kinetis/kinetis_mcg.h +++ b/arch/arm/include/kinetis/kinetis_mcg.h @@ -217,8 +217,10 @@ # define KINETIS_MCG_PLL_REF_MIN 8000000 /* OSCCLK/PLL_R minimum */ # define KINETIS_MCG_PLL_REF_MAX 16000000 /* OSCCLK/PLL_R maximum */ -/* TODO: The following configuration parameters have not been verified */ -#warning Unverified values from K66F +/* TODO: The following configuration parameters have not been verified. They were + * taken wholesale from the K66F. The K66F is very similar and, most likely, the + * settings are corred. + */ # define KINETIS_MCG_PLL_INTERNAL_DIVBY 2 /* The PLL clock is divided by 2 before VCO divider */ # define KINETIS_MCG_HAS_PLL_EXTRA_DIVBY 1 /* Is PLL clock divided by 1 before MCG PLL/FLL clock selection in the SIM module */ diff --git a/arch/arm/src/kinetis/chip/kinetis_k28memorymap.h b/arch/arm/src/kinetis/chip/kinetis_k28memorymap.h index 10d7d70db93..47b4c7239ff 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k28memorymap.h +++ b/arch/arm/src/kinetis/chip/kinetis_k28memorymap.h @@ -183,6 +183,12 @@ * purpose input/output module that shares the * crossbar switch slave port with the AIPS-Lite * is accessed at this address. */ +# define KINETIS_GPIO_BASE(n) (0x400ff000 + ((n) << 6)) +# define KINETIS_GPIOA_BASE 0x400ff000 /* GPIO PORTA registers */ +# define KINETIS_GPIOB_BASE 0x400ff040 /* GPIO PORTB registers */ +# define KINETIS_GPIOC_BASE 0x400ff080 /* GPIO PORTC registers */ +# define KINETIS_GPIOD_BASE 0x400ff0c0 /* GPIO PORTD registers */ +# define KINETIS_GPIOE_BASE 0x400ff100 /* GPIO PORTE registers */ /* Private Peripheral Bus (PPB) Memory Map ******************************************/ diff --git a/arch/arm/src/kinetis/chip/kinetis_k28pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k28pinmux.h index 1586d57f369..dc5400a5aa2 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k28pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k28pinmux.h @@ -82,8 +82,8 @@ /* Output clock */ -#define PIN_CLKOUT (PIN_ALT5 | PIN_PORTA | PIN6) -#define PIN_CLKOUT (PIN_ALT5 | PIN_PORTC | PIN3) +#define PIN_CLKOUT_1 (PIN_ALT5 | PIN_PORTA | PIN6) +#define PIN_CLKOUT_2 (PIN_ALT5 | PIN_PORTC | PIN3) /* Comparators */ @@ -242,8 +242,8 @@ #define PIN_FTM1_CH0_1 (PIN_ALT3 | PIN_PORTA | PIN12) #define PIN_FTM1_CH0_2 (PIN_ALT3 | PIN_PORTA | PIN8) -#define PIN_FTM1_CH0_1 (PIN_ALT3 | PIN_PORTB | PIN0) -#define PIN_FTM1_CH0_2 (PIN_ALT3 | PIN_PORTB | PIN12) +#define PIN_FTM1_CH0_3 (PIN_ALT3 | PIN_PORTB | PIN0) +#define PIN_FTM1_CH0_4 (PIN_ALT3 | PIN_PORTB | PIN12) #define PIN_FTM1_CH1_1 (PIN_ALT3 | PIN_PORTA | PIN13) #define PIN_FTM1_CH1_2 (PIN_ALT3 | PIN_PORTA | PIN9) #define PIN_FTM1_CH1_3 (PIN_ALT3 | PIN_PORTB | PIN1) @@ -752,8 +752,8 @@ #define PIN_SPI1_SIN_4 (PIN_ALT7 | PIN_PORTE | PIN1) #define PIN_SPI1_SOUT_1 (PIN_ALT2 | PIN_PORTB | PIN16) #define PIN_SPI1_SOUT_2 (PIN_ALT2 | PIN_PORTE | PIN2) -#define PIN_SPI1_SOUT_1 (PIN_ALT7 | PIN_PORTD | PIN6) -#define PIN_SPI1_SOUT_2 (PIN_ALT7 | PIN_PORTE | PIN3) +#define PIN_SPI1_SOUT_3 (PIN_ALT7 | PIN_PORTD | PIN6) +#define PIN_SPI1_SOUT_4 (PIN_ALT7 | PIN_PORTE | PIN3) #define PIN_SPI2_PCS0_1 (PIN_ALT2 | PIN_PORTB | PIN20) #define PIN_SPI2_PCS0_2 (PIN_ALT2 | PIN_PORTD | PIN11) diff --git a/arch/arm/src/kinetis/chip/kinetis_pinmux.h b/arch/arm/src/kinetis/chip/kinetis_pinmux.h index 81e35d26f56..b94133b83a8 100644 --- a/arch/arm/src/kinetis/chip/kinetis_pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_pinmux.h @@ -50,7 +50,7 @@ #if defined(KINETIS_K20) # include "chip/kinetis_k20pinmux.h" -#if defined(KINETIS_K28) +#elif defined(KINETIS_K28) # include "chip/kinetis_k28pinmux.h" #elif defined(KINETIS_K40) # include "chip/kinetis_k40pinmux.h" diff --git a/arch/arm/src/kinetis/kinetis_allocateheap.c b/arch/arm/src/kinetis/kinetis_allocateheap.c index 1eb21eeb4d9..43e47725b6a 100644 --- a/arch/arm/src/kinetis/kinetis_allocateheap.c +++ b/arch/arm/src/kinetis/kinetis_allocateheap.c @@ -48,13 +48,13 @@ #include #include -#include - #include "mpu.h" #include "up_arch.h" #include "up_internal.h" #include "kinetis_mpuinit.h" +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/arch/arm/src/kinetis/kinetis_lowputc.c b/arch/arm/src/kinetis/kinetis_lowputc.c index fa4369ffecf..670f6fb69d4 100644 --- a/arch/arm/src/kinetis/kinetis_lowputc.c +++ b/arch/arm/src/kinetis/kinetis_lowputc.c @@ -336,11 +336,11 @@ void up_lowputc(char ch) void kinetis_lowsetup(void) { -#if defined(HAVE_UART_DEVICE) ||defined(HAVE_LUART_DEVICE) +#if defined(HAVE_UART_DEVICE) || defined(HAVE_LPUART_DEVICE) uint32_t regval; #endif -#ifdef HAVE_UART_DEVICE +#ifdef HAVE_UART_DEVICE /* Enable peripheral clocking for all enabled UARTs. Clocking for UARTs * 0-3 is enabled in the SCGC4 register. */ @@ -456,18 +456,17 @@ void kinetis_lowsetup(void) #endif /* HAVE_UART_DEVICE */ #ifdef HAVE_LPUART_DEVICE - - /* Clocking Source for LPUARTs 0 selected in SIM_SOPT2 */ + /* Clocking Source for LPUART0 selected in SIM_SOPT2 */ #if defined(CONFIG_KINETIS_LPUART0) - regval = getreg32(KINETIS_SIM_SOPT2); + regval = getreg32(KINETIS_SIM_SOPT2); regval &= ~(SIM_SOPT2_LPUARTSRC_MASK); regval |= BOARD_LPUART0_CLKSRC; putreg32(regval, KINETIS_SIM_SOPT2); /* Clocking for LPUARTs 0-1 is enabled in the SCGC2 register. */ - regval = getreg32(KINETIS_SIM_SCGC2); + regval = getreg32(KINETIS_SIM_SCGC2); regval |= SIM_SCGC2_LPUART0; putreg32(regval, KINETIS_SIM_SCGC2); #endif @@ -791,9 +790,9 @@ void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, #ifdef HAVE_LPUART_DEVICE void kinetis_lpuartconfigure(uintptr_t uart_base, uint32_t baud, - uint32_t clock, unsigned int parity, - unsigned int nbits, unsigned int stop2, - bool iflow, bool oflow) + uint32_t clock, unsigned int parity, + unsigned int nbits, unsigned int stop2, + bool iflow, bool oflow) { uint32_t sbrreg; uint32_t osrreg; diff --git a/arch/arm/src/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 3805cecd912..1f61b0b72b8 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -972,7 +972,7 @@ static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg) * TCSADRAIN / TCSAFLUSH */ - kinetis_uartconfigure(priv->uartbase, priv->baud, priv->clock, + kinetis_lpuartconfigure(priv->uartbase, priv->baud, priv->clock, priv->parity, priv->bits, priv->stop2, iflow, oflow); } diff --git a/arch/arm/src/kinetis/kinetis_serialinit.c b/arch/arm/src/kinetis/kinetis_serialinit.c index 0638d360f92..ea4e1e240b9 100644 --- a/arch/arm/src/kinetis/kinetis_serialinit.c +++ b/arch/arm/src/kinetis/kinetis_serialinit.c @@ -99,7 +99,7 @@ void kinetis_earlyserialinit(void) void up_serialinit(void) { -#if defined(HAVE_UART_DEVICE) ||defined(HAVE_LUART_DEVICE) +#if defined(HAVE_UART_DEVICE) ||defined(HAVE_LPUART_DEVICE) uint32_t start = 0; #endif diff --git a/configs/freedom-k28f/README.txt b/configs/freedom-k28f/README.txt index 46bf0761678..75546f57443 100644 --- a/configs/freedom-k28f/README.txt +++ b/configs/freedom-k28f/README.txt @@ -30,6 +30,13 @@ README - Virtual serial port interface. - Open-source CMSIS-DAP software project. +Contents +======== + + o Serial Console + o LEDs and Buttons + o Configurations + Serial Console ============== @@ -134,8 +141,11 @@ Serial Console Arduino connectors. Remove R106 and R107 or R94 and R11 as necessary to prevent contention. - TGTMCU - ------ + Virtual serial port + ------------------- + + A serial port connection is available between the OpenSDA v2.2 MCU and + pins PTC24 and PTC25 of the K28 MCU: ----- --------------- ------------------------------- GPIO LPUART FUNCTION BOARD CONFIGURATION @@ -143,3 +153,50 @@ Serial Console PTC25 LPUART0_RX PTC25 LPUART0_RX_TGTMCU PTC24 LPUART0_TX PTC24 LPUART0_TX_TGTMCU ----- --------------- ------------------------------- + + Default Console + --------------- + + Unless otherwise noted, LPUART0 (the virtual serial port) is the console + used in all Freedom-K28F configurations. + + RGB LED + ------- + An RGB LED is connected through GPIO as shown below: + + LED K28 + ------ ------------------------------------------------------- + RED PTE6 + GREEN PTE7 + BLUE PTE8 + + If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board + the Freedom K28. Usage of these LEDs is defined in include/board.h and + src/k28_leds.c. The following definitions describe how NuttX controls the + LEDs: + + SYMBOL Meaning LED state + RED GREEN BLUE + ------------------- ----------------------- ----------------- + LED_STARTED NuttX has been started OFF OFF OFF + LED_HEAPALLOCATE Heap has been allocated OFF OFF ON + LED_IRQSENABLED Interrupts enabled OFF OFF ON + LED_STACKCREATED Idle stack created OFF ON OFF + LED_INIRQ In an interrupt (no change) + LED_SIGNAL In a signal handler (no change) + LED_ASSERTION An assertion failed (no change) + LED_PANIC The system has crashed FLASH OFF OFF + LED_IDLE K28 is in sleep mode (Optional, not used) + + Buttons + ------- + Two push button switches, SW2 and SW3, are available on the FRDM-K28F + board. SW2 is connected to PTA4 and SW3 is connected to PTD0. + Beside the general purpose IO function, both SW2 and SW3 can be used + as a low-leakage wakeup (LLWU) source. + + Switch GPIO Function + --------- --------------------------------------------------------------- + SW2 PTA4/NMI_B + SW3 PTD0/LLWU_P12 + diff --git a/configs/freedom-k28f/include/board.h b/configs/freedom-k28f/include/board.h index d8d15f88364..3c9cc1d2928 100644 --- a/configs/freedom-k28f/include/board.h +++ b/configs/freedom-k28f/include/board.h @@ -45,6 +45,8 @@ #ifndef __ASSEMBLY__ # include # include + +# include #endif /************************************************************************************ @@ -52,7 +54,7 @@ ************************************************************************************/ /* Clocking *************************************************************************/ -/* The Freedom K28F uses a 12Mhz external Oscillator. The Kinetis MCU startup from an +/* The Freedom K28F uses a 12MHz external Oscillator. 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 @@ -70,16 +72,16 @@ * produce a KINETIS_MCG_PLL_REF_MIN >= PLLIN <=KINETIS_MCG_PLL_REF_MAX reference * clock to the PLL. * - * PLL Input frequency: PLLIN = REFCLK / PRDIV = 12 Mhz / 1 = 12 MHz - * PLL Output frequency: PLLOUT = PLLIN * VDIV = 12 Mhz * 30 = 360 MHz - * MCG Frequency: PLLOUT = 180 Mhz = 360 MHz / KINETIS_MCG_PLL_INTERNAL_DIVBY + * PLL Input frequency: PLLIN = REFCLK / PRDIV = 12 MHz / 1 = 12 MHz + * PLL Output frequency: PLLOUT = PLLIN * VDIV = 12 MHz * 25 = 300 MHz + * MCG Frequency: PLLOUT = 150 MHz = 300 MHz / KINETIS_MCG_PLL_INTERNAL_DIVBY * * PRDIV register value is the divider minus KINETIS_MCG_C5_PRDIV_BASE. * VDIV register value is offset by KINETIS_MCG_C6_VDIV_BASE. */ -#define BOARD_PRDIV 1 /* PLL External Reference Divider */ -#define BOARD_VDIV 30 /* PLL VCO Divider (frequency multiplier) */ +#define BOARD_PRDIV 1 /* PLL External Reference Divider */ +#define BOARD_VDIV 25 /* PLL VCO Divider (frequency multiplier) */ /* Define additional MCG_C2 Setting */ @@ -88,7 +90,7 @@ #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/KINETIS_MCG_PLL_INTERNAL_DIVBY) +#define BOARD_MCG_FREQ (BOARD_PLLOUT_FREQ / KINETIS_MCG_PLL_INTERNAL_DIVBY) /* SIM CLKDIV1 dividers */ @@ -109,11 +111,11 @@ #define BOARD_SOPT2_PLLFLLSEL SIM_SOPT2_PLLFLLSEL_MCGPLLCLK #define BOARD_SOPT2_FREQ BOARD_MCG_FREQ -/* N.B. The above BOARD_SOPT2_FREQ precludes use of USB with a 12 Mhz Xtal +/* N.B. The above BOARD_SOPT2_FREQ precludes use of USB with a 12 MHz Xtal * Divider output clock = Divider input clock × [ (USBFRAC+1) / (USBDIV+1) ] * SIM_CLKDIV2_FREQ = BOARD_SOPT2_FREQ × [ (USBFRAC+1) / (USBDIV+1) ] - * 48Mhz = 168Mhz X [(1 + 1) / (6 + 1)] - * 48Mhz = 168Mhz / (6 + 1) * (1 + 1) + * 48MHz = 168MHz X [(1 + 1) / (6 + 1)] + * 48MHz = 168MHz / (6 + 1) * (1 + 1) */ #if (BOARD_MCG_FREQ == 168000000L) @@ -126,8 +128,8 @@ /* Divider output clock = Divider input clock * ((PLLFLLFRAC+1)/(PLLFLLDIV+1)) * SIM_CLKDIV3_FREQ = BOARD_SOPT2_FREQ × [ (PLLFLLFRAC+1) / (PLLFLLDIV+1)] - * 90 Mhz = 180 Mhz X [(0 + 1) / (1 + 1)] - * 90 Mhz = 180 Mhz / (1 + 1) * (0 + 1) + * 90 MHz = 180 MHz X [(0 + 1) / (1 + 1)] + * 90 MHz = 180 MHz / (1 + 1) * (0 + 1) */ #define BOARD_SIM_CLKDIV3_PLLFLLFRAC 1 @@ -146,10 +148,10 @@ /* Kinetis does not have pullups on their Freedom-K28F board * So allow the board config to enable them. + * REVISIT: This was cloned from the K66F. Need to check the K28F schematic. */ #define BOARD_SDHC_ENABLE_PULLUPS 1 -#warning REVISIT /* SDHC clocking ********************************************************************/ @@ -345,7 +347,24 @@ * PTE22 LPUART4_CTS N/C * ----- --------------- ------------------------------- * - * Arduino RS-232 Shield + * Virtual serial port + * ------------------- + * + * A serial port connection is available between the OpenSDA v2.2 MCU and + * pins PTC24 and PTC25 of the K28 MCU: + * + * ----- --------------- ------------------------------- + * GPIO LPUART FUNCTION BOARD CONFIGURATION + * ----- --------------- ------------------------------- + * PTC25 LPUART0_RX PTC25 LPUART0_RX_TGTMCU + * PTC24 LPUART0_TX PTC24 LPUART0_TX_TGTMCU + * ----- --------------- ------------------------------- + */ + +#define PIN_LPUART0_RX PIN_LPUART0_RX_5 /* PTC25 */ +#define PIN_LPUART0_TX PIN_LPUART0_TX_5 /* PTC24 + +/* Arduino RS-232 Shield * --------------------- * * ----- --------------- ------------------------------- @@ -358,18 +377,11 @@ * Note: PTA24 and PTA25 are shared between Micro SD Card circuit and * Arduino connectors. Remove R106 and R107 or R94 and R11 as necessary to * prevent contention. - * - * TGTMCU - * ------ - * - * ----- --------------- ------------------------------- - * GPIO LPUART FUNCTION BOARD CONFIGURATION - * ----- --------------- ------------------------------- - * PTC25 LPUART0_RX PTC25 LPUART0_RX_TGTMCU - * PTC24 LPUART0_TX PTC24 LPUART0_TX_TGTMCU - * ----- --------------- ------------------------------- */ +#define PIN_LPUART2_RX PIN_LPUART2_RX_1 /* PTA25 */ +#define PIN_LPUART2_TX PIN_LPUART2_TX_1 /* PTA24 */ + /* I2C */ #ifdef CONFIG_KINETIS_I2C0 @@ -394,4 +406,66 @@ #endif #endif +/* LED definitions ******************************************************************/ +/* The Freedom K28F has a single RGB LED driven by the K28F as follows: + * + * LED K28 + * ------ ------------------------------------------------------- + * RED PTE6 + * BLUE PTE7 + * GREEN PTE8 + * + * 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 + * the Freedom K28F. The following definitions describe how NuttX controls + * the LEDs: + * + * 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 /* K28 is in sleep mode (Not used) */ + +/* Button definitions ***************************************************************/ +/* Two push buttons, SW2 and SW3, are available on FRDM-K28F board, where SW2 is + * connected to PTA4 and SW3 is connected to PTD0. 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. + * + * Switch GPIO Function + * --------- --------------------------------------------------------------- + * SW2 PTA4/NMI_B + * SW3 PTA4/NMI_B + */ + +#define BUTTON_SW2 0 +#define BUTTON_SW3 1 +#define NUM_BUTTONS 2 + +#define BUTTON_SW2_BIT (1 << BUTTON_SW2) +#define BUTTON_SW3_BIT (1 << BUTTON_SW3) + #endif /* __CONFIGS_FREEDOM_K28F_INCLUDE_BOARD_H */ diff --git a/configs/freedom-k28f/nsh/defconfig b/configs/freedom-k28f/nsh/defconfig index 3cb34a6836d..ba3ec6c7ad8 100644 --- a/configs/freedom-k28f/nsh/defconfig +++ b/configs/freedom-k28f/nsh/defconfig @@ -10,7 +10,6 @@ CONFIG_ARCH_BOARD_FREEDOM_K28F=y CONFIG_ARCH_CHIP_KINETIS=y CONFIG_ARCH_CHIP_MK28FN2M0VMI15=y CONFIG_ARCH_STACKDUMP=y -CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y CONFIG_BOARD_LOOPSPERMSEC=6024 CONFIG_BUILTIN=y CONFIG_DEBUG_FULLOPT=y @@ -19,10 +18,10 @@ CONFIG_DISABLE_POLL=y CONFIG_EXAMPLES_NSH=y CONFIG_HOST_WINDOWS=y CONFIG_INTELHEX_BINARY=y +CONFIG_KINETIS_LPUART0=y CONFIG_KINETIS_SERIALBRK_BSDCOMPAT=y -CONFIG_KINETIS_UART0=y -CONFIG_KINETIS_UARTFIFOS=y CONFIG_KINETIS_UART_BREAKS=y +CONFIG_LPUART0_SERIAL_CONSOLE=y CONFIG_MAX_TASKS=16 CONFIG_MAX_WDOGPARMS=2 CONFIG_NFILE_DESCRIPTORS=8 @@ -45,5 +44,4 @@ CONFIG_SPI=y CONFIG_START_DAY=2 CONFIG_START_MONTH=5 CONFIG_TASK_NAME_SIZE=0 -CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/configs/freedom-k28f/src/freedom-k28f.h b/configs/freedom-k28f/src/freedom-k28f.h index ef2fc08bcbd..427ce07972c 100644 --- a/configs/freedom-k28f/src/freedom-k28f.h +++ b/configs/freedom-k28f/src/freedom-k28f.h @@ -48,6 +48,32 @@ ****************************************************************************/ /* Freedom-K28F GPIOs *******************************************************/ +/* An RGB LED is connected through GPIO as shown below: + * + * LED K28 + * ------ ------------------------------------------------------- + * RED PTE6 + * GREEN PTE7 + * BLUE PTE8 + */ + +#define GPIO_LED_R (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTE | PIN6) +#define GPIO_LED_G (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTE | PIN7) +#define GPIO_LED_B (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTE | PIN8) + +/* Two push buttons, SW2 and SW3, are available on FRDM-K28F board, where SW2 is + * connected to PTA4 and SW3 is connected to PTD0. 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. + * + * Switch GPIO Function + * --------- --------------------------------------------------------------- + * SW2 PTA4/NMI_B + * SW3 PTD0/LLWU_P12 + */ + +#define GPIO_SW2 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTA | PIN4) +#define GPIO_SW3 (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTD | PIN0) /**************************************************************************** * Public Types diff --git a/configs/freedom-k28f/src/k28_autoleds.c b/configs/freedom-k28f/src/k28_autoleds.c index 02329cbb787..bbffd41c24b 100644 --- a/configs/freedom-k28f/src/k28_autoleds.c +++ b/configs/freedom-k28f/src/k28_autoleds.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/freedom-k28f/src/k28_autoleds.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -33,21 +33,65 @@ * ****************************************************************************/ +/* The Freedom K28F has a single RGB LED driven by the K28F as follows: + * + * LED K28 + * ------ ------------------------------------------------------- + * RED PTE6 + * BLUE PTE7 + * GREEN PTE8 + * + * + * If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board + * the Freedom K28F. The following definitions describe how NuttX controls + * the LEDs: + * + * SYMBOL Meaning LED state + * RED GREEN BLUE + * ------------------- ----------------------- ----------------- + * LED_STARTED NuttX has been started OFF OFF OFF + * LED_HEAPALLOCATE Heap has been allocated OFF OFF ON + * LED_IRQSENABLED Interrupts enabled OFF OFF ON + * LED_STACKCREATED Idle stack created OFF ON OFF + * LED_INIRQ In an interrupt (no change) + * LED_SIGNAL In a signal handler (no change) + * LED_ASSERTION An assertion failed (no change) + * LED_PANIC The system has crashed FLASH OFF OFF + * LED_IDLE K28 is in sleep mode (Optional, not used) + */ + /**************************************************************************** * Included Files ****************************************************************************/ #include +#include +#include #include #include +#include "chip.h" #include "kinetis.h" #include "freedom-k28f.h" +#include + #ifdef CONFIG_ARCH_LEDS +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Summary of all possible settings */ + +#define LED_NOCHANGE 0 /* LED_IRQSENABLED, LED_INIRQ, LED_SIGNAL, LED_ASSERTION */ +#define LED_OFF_OFF_OFF 1 /* LED_STARTED */ +#define LED_OFF_OFF_ON 2 /* LED_HEAPALLOCATE */ +#define LED_OFF_ON_OFF 3 /* LED_STACKCREATED */ +#define LED_ON_OFF_OFF 4 /* LED_PANIC */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -56,13 +100,15 @@ * Name: board_autoled_initialize * * Description: - * Initialize LED GPIOs so that LEDs can be controlled. + * Initialize the on-board LED * ****************************************************************************/ void board_autoled_initialize(void) { - kinetis_pinconfig(GPIO_LED); + kinetis_pinconfig(GPIO_LED_R); + kinetis_pinconfig(GPIO_LED_G); + kinetis_pinconfig(GPIO_LED_B); } /**************************************************************************** @@ -71,9 +117,34 @@ void board_autoled_initialize(void) void board_autoled_on(int led) { - if (led != 2) + if (led != LED_NOCHANGE) { - kinetis_gpiowrite(GPIO_LED, (led != 0)); + bool redoff = true; + bool greenoff = true; + bool blueoff = true; + + switch (led) + { + default: + case LED_OFF_OFF_OFF: + break; + + case LED_OFF_OFF_ON: + blueoff = false; + break; + + case LED_OFF_ON_OFF: + greenoff = false; + break; + + case LED_ON_OFF_OFF: + redoff = false; + break; + } + + kinetis_gpiowrite(GPIO_LED_R, redoff); + kinetis_gpiowrite(GPIO_LED_G, greenoff); + kinetis_gpiowrite(GPIO_LED_B, blueoff); } } @@ -83,9 +154,11 @@ void board_autoled_on(int led) void board_autoled_off(int led) { - if (led != 2) + if (led == LED_ON_OFF_OFF) { - kinetis_gpiowrite(GPIO_LED, false); + kinetis_gpiowrite(GPIO_LED_R, true); + kinetis_gpiowrite(GPIO_LED_G, true); + kinetis_gpiowrite(GPIO_LED_B, true); } } diff --git a/configs/freedom-k28f/src/k28_userleds.c b/configs/freedom-k28f/src/k28_userleds.c index e329b006e2a..7545c504440 100644 --- a/configs/freedom-k28f/src/k28_userleds.c +++ b/configs/freedom-k28f/src/k28_userleds.c @@ -39,12 +39,18 @@ #include +#include #include #include +#include + +#include "chip.h" #include "kinetis.h" #include "freedom-k28f.h" +#include + #ifndef CONFIG_ARCH_LEDS /**************************************************************************** @@ -57,7 +63,9 @@ void board_userled_initialize(void) { - kinetis_pinconfig(GPIO_LED); + kinetis_pinconfig(GPIO_LED_R); + kinetis_pinconfig(GPIO_LED_G); + kinetis_pinconfig(GPIO_LED_B); } /**************************************************************************** @@ -66,10 +74,26 @@ void board_userled_initialize(void) void board_userled(int led, bool ledon) { - if (led == BOARD_LED) + uint32_t ledcfg; + + if (led == BOARD_LED_R) { - kinetis_gpiowrite(GPIO_LED, ledon); + ledcfg = GPIO_LED_R; } + else if (led == BOARD_LED_G) + { + ledcfg = GPIO_LED_G; + } + else if (led == BOARD_LED_B) + { + ledcfg = GPIO_LED_B; + } + else + { + return; + } + + kinetis_gpiowrite(ledcfg, !ledon); /* Low illuminates */ } /**************************************************************************** @@ -78,7 +102,11 @@ void board_userled(int led, bool ledon) void board_userled_all(uint8_t ledset) { - kinetis_gpiowrite(GPIO_LED, (ledset & BOARD_LED_BIT) != 0); + /* Low illuminates */ + + kinetis_gpiowrite(GPIO_LED_R, (ledset & BOARD_LED_R_BIT) == 0); + kinetis_gpiowrite(GPIO_LED_G, (ledset & BOARD_LED_G_BIT) == 0); + kinetis_gpiowrite(GPIO_LED_B, (ledset & BOARD_LED_B_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/configs/freedom-k66f/README.txt b/configs/freedom-k66f/README.txt index 5fa1c1252b4..632b662f127 100644 --- a/configs/freedom-k66f/README.txt +++ b/configs/freedom-k66f/README.txt @@ -131,10 +131,10 @@ LEDs and Buttons Beside the general purpose IO function, both SW2 and SW3 can be used as a low-leakage wakeup (LLWU) source. - Switch GPIO Function - --------- --------------------------------------------------------------- - SW2 PTD11/LLWU_P25/SPI2_PCS0/SDHC0_CLKIN/LPUART0_CTS/FB_A19 - SW3 PTA10/LLWU_P22/FTM2_CH0/MII0_RXD2/FTM2_QD_PHA/TPM2_CH0/TRACE_D0 + Switch GPIO Function + --------- --------------------------------------------------------------- + SW2 PTD11/LLWU_P25/SPI2_PCS0/SDHC0_CLKIN/LPUART0_CTS/FB_A19 + SW3 PTA10/LLWU_P22/FTM2_CH0/MII0_RXD2/FTM2_QD_PHA/TPM2_CH0/TRACE_D0 Networking Support ==================