From 81e76b96d5928a51fd78822064f693d7d4e048cf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Nov 2013 10:39:03 -0600 Subject: [PATCH] Freedom KL25Z: Add PWM support. From Alan Carvalho de Assis --- configs/freedom-kl25z/include/board.h | 20 +++++ configs/freedom-kl25z/nsh/defconfig | 38 ++++++-- configs/freedom-kl25z/src/Makefile | 2 +- configs/freedom-kl25z/src/up_pwm.c | 120 ++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 8 deletions(-) create mode 100644 configs/freedom-kl25z/src/up_pwm.c diff --git a/configs/freedom-kl25z/include/board.h b/configs/freedom-kl25z/include/board.h index 16b197937d..61ee317b87 100644 --- a/configs/freedom-kl25z/include/board.h +++ b/configs/freedom-kl25z/include/board.h @@ -133,6 +133,26 @@ # define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(15) #endif +/* PWM Configuration */ +/* TPM0 Channels */ + +#define GPIO_TPM0_CH0OUT PIN_TPM0_CH0_3 //PIN_TPM0_CH0_1 +#define GPIO_TPM0_CH1OUT PIN_TPM0_CH1_1 +#define GPIO_TPM0_CH2OUT PIN_TPM0_CH2_1 +#define GPIO_TPM0_CH3OUT PIN_TPM0_CH3_1 +#define GPIO_TPM0_CH4OUT PIN_TPM0_CH4_1 +#define GPIO_TPM0_CH5OUT PIN_TPM0_CH5_1 + +/* TPM1 Channels */ + +#define GPIO_TPM1_CH0OUT PIN_TPM1_CH0_1 +#define GPIO_TPM1_CH1OUT PIN_TPM1_CH1_1 + +/* TPM2 Channels */ + +#define GPIO_TPM1_CH0OUT PIN_TPM2_CH0_1 +#define GPIO_TPM1_CH1OUT PIN_TPM2_CH1_1 + /* LED definitions ******************************************************************/ /* The Freedom KL25Z has a single RGB LED driven by the KL25Z as follows: * diff --git a/configs/freedom-kl25z/nsh/defconfig b/configs/freedom-kl25z/nsh/defconfig index e8c86c6ddd..4abc4610d9 100644 --- a/configs/freedom-kl25z/nsh/defconfig +++ b/configs/freedom-kl25z/nsh/defconfig @@ -39,6 +39,7 @@ CONFIG_RAW_BINARY=y # Debug Options # # CONFIG_DEBUG is not set +CONFIG_ARCH_HAVE_STACKCHECK=y # CONFIG_DEBUG_SYMBOLS is not set # @@ -95,10 +96,10 @@ CONFIG_ARCH_HAVE_CMNVECTOR=y # # ARMV6M Configuration Options # -CONFIG_ARMV6M_TOOLCHAIN_BUILDROOT=y +# CONFIG_ARMV6M_TOOLCHAIN_BUILDROOT is not set # CONFIG_ARMV6M_TOOLCHAIN_CODEREDL is not set # CONFIG_ARMV6M_TOOLCHAIN_CODESOURCERYL is not set -# CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIL is not set +CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIL=y # CONFIG_GPIO_IRQ is not set # @@ -129,7 +130,9 @@ CONFIG_KL_UART0=y # CONFIG_KL_ADC1 is not set # CONFIG_KL_CMP is not set # CONFIG_KL_VREF is not set -# CONFIG_KL_TPM0 is not set +CONFIG_KL_TPM0=y +CONFIG_KL_TPM0_PWM=y +CONFIG_KL_TPM0_CHANNEL=0 # CONFIG_KL_TPM1 is not set # CONFIG_KL_TPM2 is not set # CONFIG_KL_LPTIMER is not set @@ -280,7 +283,8 @@ CONFIG_DEV_NULL=y # CONFIG_LOOP is not set # CONFIG_RAMDISK is not set # CONFIG_CAN is not set -# CONFIG_PWM is not set +CONFIG_PWM=y +# CONFIG_PWM_PULSECOUNT is not set # CONFIG_I2C is not set # CONFIG_SPI is not set # CONFIG_RTC is not set @@ -440,8 +444,6 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024 # # CONFIG_EXAMPLES_BUTTONS is not set # CONFIG_EXAMPLES_CAN is not set -# CONFIG_EXAMPLES_CC3000BASIC is not set -# CONFIG_SYSTEM_COMPOSITE is not set # CONFIG_EXAMPLES_DHCPD is not set # CONFIG_EXAMPLES_ELF is not set # CONFIG_EXAMPLES_FTPC is not set @@ -470,6 +472,11 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_OSTEST is not set # CONFIG_EXAMPLES_PASHELLO is not set # CONFIG_EXAMPLES_PIPE is not set +CONFIG_EXAMPLES_PWM=y +CONFIG_EXAMPLES_PWM_DEVPATH="/dev/pwm0" +CONFIG_EXAMPLES_PWM_FREQUENCY=100 +CONFIG_EXAMPLES_PWM_DUTYPCT=50 +CONFIG_EXAMPLES_PWM_DURATION=5 # CONFIG_EXAMPLES_POSIXSPAWN is not set # CONFIG_EXAMPLES_QENCODER is not set # CONFIG_EXAMPLES_RGMP is not set @@ -487,7 +494,6 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_UDP is not set # CONFIG_EXAMPLES_UIP is not set # CONFIG_EXAMPLES_USBSERIAL is not set -# CONFIG_SYSTEM_USBMSC is not set # CONFIG_EXAMPLES_USBTERM is not set # CONFIG_EXAMPLES_WATCHDOG is not set @@ -537,11 +543,13 @@ CONFIG_NSH_BUILTIN_APPS=y # # Disable Individual commands # +# CONFIG_NSH_DISABLE_ADDROUTE is not set # CONFIG_NSH_DISABLE_CAT is not set CONFIG_NSH_DISABLE_CD=y CONFIG_NSH_DISABLE_CP=y # CONFIG_NSH_DISABLE_CMP is not set CONFIG_NSH_DISABLE_DD=y +# CONFIG_NSH_DISABLE_DELROUTE is not set # CONFIG_NSH_DISABLE_ECHO is not set # CONFIG_NSH_DISABLE_EXEC is not set # CONFIG_NSH_DISABLE_EXIT is not set @@ -605,6 +613,14 @@ CONFIG_NSH_CONSOLE=y # System NSH Add-Ons # +# +# USB CDC/ACM Device Commands +# + +# +# USB Composite Device Commands +# + # # Custom Free Memory Command # @@ -658,6 +674,14 @@ CONFIG_READLINE_ECHO=y # USB Monitor # +# +# Stack Monitor +# + +# +# USB Mass Storage Device Commands +# + # # Zmodem Commands # diff --git a/configs/freedom-kl25z/src/Makefile b/configs/freedom-kl25z/src/Makefile index 1171413220..03f81ea5a4 100644 --- a/configs/freedom-kl25z/src/Makefile +++ b/configs/freedom-kl25z/src/Makefile @@ -67,7 +67,7 @@ CSRCS += kl_usb.c endif ifeq ($(CONFIG_PWM),y) -CSRCS += kl_pwm.c +CSRCS += up_pwm.c endif ifeq ($(CONFIG_QENCODER),y) diff --git a/configs/freedom-kl25z/src/up_pwm.c b/configs/freedom-kl25z/src/up_pwm.c new file mode 100644 index 0000000000..ffe9089011 --- /dev/null +++ b/configs/freedom-kl25z/src/up_pwm.c @@ -0,0 +1,120 @@ +/************************************************************************************ + * configs/freedom-kl25z/src/up_pwm.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Alan Carvalho de Assis + * + * 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 + +#include +#include + +#include +#include +#include + +#include "chip.h" +#include "up_arch.h" +#include "kl_pwm.h" + +/************************************************************************************ + * Definitions + ************************************************************************************/ +/* Configuration *******************************************************************/ +/* PWM + * + * The Kinetis Freedom board provides a LED on GPIO. + */ + +#ifdef CONFIG_PWM + +extern struct pwm_lowerhalf_s *kl_pwminitialize(int timer); + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: pwm_devinit + * + * Description: + * All Kinetis KL architectures must provide the following interface to work with + * examples/pwm. + * + ************************************************************************************/ + +int pwm_devinit(void) +{ + static bool initialized = false; + struct pwm_lowerhalf_s *pwm; + int ret; + + /* Have we already initialized? */ + + if (!initialized) + { + /* Call kl_pwminitialize() to get an instance of the PWM interface */ + + pwm = kl_pwminitialize(0); + if (!pwm) + { + adbg("Failed to get the KL25 PWM lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm0" */ + + ret = pwm_register("/dev/pwm0", pwm); + if (ret < 0) + { + adbg("pwm_register failed: %d\n", ret); + return ret; + } + + /* Now we are initialized */ + + initialized = true; + } + + return OK; +} + +#endif /* CONFIG_PWM */