This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 6e2db9bed139537a5bcb6c2da36342631eb29725 Author: Michal Lenc <[email protected]> AuthorDate: Sat Jun 26 11:55:09 2021 +0200 boards/arm/imxrt/teensy-4.x: added board level support for FlexPWM driver Signed-off-by: Michal Lenc <[email protected]> --- .../arm/imxrt/teensy-4.x/configs/pwm-4.1/defconfig | 57 ++++++++ boards/arm/imxrt/teensy-4.x/include/board.h | 5 + boards/arm/imxrt/teensy-4.x/src/Makefile | 4 + boards/arm/imxrt/teensy-4.x/src/imxrt_bringup.c | 9 ++ boards/arm/imxrt/teensy-4.x/src/imxrt_flexpwm.c | 151 +++++++++++++++++++++ boards/arm/imxrt/teensy-4.x/src/teensy-4.h | 12 ++ 6 files changed, 238 insertions(+) diff --git a/boards/arm/imxrt/teensy-4.x/configs/pwm-4.1/defconfig b/boards/arm/imxrt/teensy-4.x/configs/pwm-4.1/defconfig new file mode 100644 index 0000000..565e1c0 --- /dev/null +++ b/boards/arm/imxrt/teensy-4.x/configs/pwm-4.1/defconfig @@ -0,0 +1,57 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="teensy-4.x" +CONFIG_ARCH_BOARD_TEENSY_4X=y +CONFIG_ARCH_CHIP="imxrt" +CONFIG_ARCH_CHIP_IMXRT=y +CONFIG_ARCH_CHIP_MIMXRT1062DVL6A=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV7M_DCACHE=y +CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y +CONFIG_ARMV7M_ICACHE=y +CONFIG_ARMV7M_USEBASEPRI=y +CONFIG_BOARD_LOOPSPERMSEC=104926 +CONFIG_BUILTIN=y +CONFIG_EXAMPLES_PWM=y +CONFIG_EXAMPLES_PWM_DEVPATH="/dev/pwm1" +CONFIG_EXAMPLES_PWM_DURATION=10 +CONFIG_EXAMPLES_PWM_DUTYPCT1=30 +CONFIG_EXAMPLES_PWM_DUTYPCT2=80 +CONFIG_EXAMPLES_PWM_FREQUENCY=4000 +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_IMXRT_FLEXPWM2=y +CONFIG_IMXRT_FLEXPWM2_MOD1=y +CONFIG_IMXRT_FLEXPWM2_MOD2=y +CONFIG_IMXRT_LPUART1=y +CONFIG_INTELHEX_BINARY=y +CONFIG_IOB_NBUFFERS=24 +CONFIG_IOB_NCHAINS=24 +CONFIG_LIBC_FLOATINGPOINT=y +CONFIG_LPUART1_SERIAL_CONSOLE=y +CONFIG_MAX_TASKS=16 +CONFIG_MM_IOB=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PWM=y +CONFIG_PWM_MULTICHAN=y +CONFIG_PWM_NCHANNELS=2 +CONFIG_RAM_SIZE=1048576 +CONFIG_RAM_START=0x20200000 +CONFIG_SCHED_HPWORK=y +CONFIG_SIG_DEFAULT=y +CONFIG_START_DAY=14 +CONFIG_START_MONTH=3 +CONFIG_SYSTEM_NSH=y +CONFIG_TEENSY_41=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WQUEUE_NOTIFIER=y diff --git a/boards/arm/imxrt/teensy-4.x/include/board.h b/boards/arm/imxrt/teensy-4.x/include/board.h index ec9f415..0814c2d 100644 --- a/boards/arm/imxrt/teensy-4.x/include/board.h +++ b/boards/arm/imxrt/teensy-4.x/include/board.h @@ -276,6 +276,11 @@ #define GPIO_FLEXCAN3_TX (GPIO_FLEXCAN3_TX_3|IOMUX_CAN_DEFAULT) /* GPIO_EMC_36 */ #define GPIO_FLEXCAN3_RX (GPIO_FLEXCAN3_RX_3|IOMUX_CAN_DEFAULT) /* GPIO_EMC_37 */ +/* FlexPWM */ + +#define GPIO_FLEXPWM2_MOD1_A (GPIO_FLEXPWM2_PWMA00_1|IOMUX_PWM_DEFAULT) /* GPIO_EMC_06 */ +#define GPIO_FLEXPWM2_MOD2_A (GPIO_FLEXPWM2_PWMA01_1|IOMUX_PWM_DEFAULT) /* GPIO_EMC_08 */ + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/boards/arm/imxrt/teensy-4.x/src/Makefile b/boards/arm/imxrt/teensy-4.x/src/Makefile index d15a030..631a070 100644 --- a/boards/arm/imxrt/teensy-4.x/src/Makefile +++ b/boards/arm/imxrt/teensy-4.x/src/Makefile @@ -46,6 +46,10 @@ ifeq ($(CONFIG_IMXRT_FLEXCAN),y) CSRCS += imxrt_flexcan.c endif +ifeq ($(CONFIG_IMXRT_FLEXPWM),y) +CSRCS += imxrt_flexpwm.c +endif + ifeq ($(CONFIG_IMXRT_ENET),y) CSRCS += imxrt_ethernet.c endif diff --git a/boards/arm/imxrt/teensy-4.x/src/imxrt_bringup.c b/boards/arm/imxrt/teensy-4.x/src/imxrt_bringup.c index b91b7ef..4674436 100644 --- a/boards/arm/imxrt/teensy-4.x/src/imxrt_bringup.c +++ b/boards/arm/imxrt/teensy-4.x/src/imxrt_bringup.c @@ -163,6 +163,15 @@ int imxrt_bringup(void) } #endif +#ifdef CONFIG_IMXRT_FLEXPWM + ret = imxrt_pwm_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: imxrt_pwm_setup() failed: %d\n", ret); + return ret; + } +#endif + #ifdef CONFIG_VIDEO_FB /* Initialize and register the framebuffer driver */ diff --git a/boards/arm/imxrt/teensy-4.x/src/imxrt_flexpwm.c b/boards/arm/imxrt/teensy-4.x/src/imxrt_flexpwm.c new file mode 100644 index 0000000..fe17cb8 --- /dev/null +++ b/boards/arm/imxrt/teensy-4.x/src/imxrt_flexpwm.c @@ -0,0 +1,151 @@ +/**************************************************************************** + * boards/arm/imxrt/teensy-4.x/src/imxrt_flexpwm.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/board.h> +#include <nuttx/timers/pwm.h> + +#include <arch/board/board.h> + +#include "imxrt_flexpwm.h" +#include "teensy-4.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#ifdef CONFIG_PWM + +extern struct pwm_lowerhalf_s *imxrt_pwminitialize(int pwm); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: imxrt_pwm_setup + * + * Description: + * Initialize PWM and register the PWM device. + * + ****************************************************************************/ + +int imxrt_pwm_setup(void) +{ + struct pwm_lowerhalf_s *pwm; + int ret; + +#ifdef CONFIG_IMXRT_FLEXPWM1 + /* Call imxrt_pwminitialize() to get an instance of the PWM interface */ + + pwm = imxrt_pwminitialize(1); + if (!pwm) + { + aerr("ERROR: Failed to get the IMXRT PWM lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm0" */ + + ret = pwm_register("/dev/pwm0", pwm); + if (ret < 0) + { + aerr("ERROR: pwm_register failed: %d\n", ret); + return ret; + } + +#endif +#ifdef CONFIG_IMXRT_FLEXPWM2 + /* Call imxrt_pwminitialize() to get an instance of the PWM interface */ + + pwm = imxrt_pwminitialize(2); + if (!pwm) + { + aerr("ERROR: Failed to get the IMXRT PWM lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm1" */ + + ret = pwm_register("/dev/pwm1", pwm); + if (ret < 0) + { + aerr("ERROR: pwm_register failed: %d\n", ret); + return ret; + } + +#endif +#ifdef CONFIG_IMXRT_FLEXPWM3 + /* Call imxrt_pwminitialize() to get an instance of the PWM interface */ + + pwm = imxrt_pwminitialize(3); + if (!pwm) + { + aerr("ERROR: Failed to get the IMXRT PWM lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm2" */ + + ret = pwm_register("/dev/pwm2", pwm); + if (ret < 0) + { + aerr("ERROR: pwm_register failed: %d\n", ret); + return ret; + } + +#endif +#ifdef CONFIG_IMXRT_FLEXPWM4 + /* Call imxrt_pwminitialize() to get an instance of the PWM interface */ + + pwm = imxrt_pwminitialize(4); + if (!pwm) + { + aerr("ERROR: Failed to get the IMXRT PWM lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm3" */ + + ret = pwm_register("/dev/pwm3", pwm); + if (ret < 0) + { + aerr("ERROR: pwm_register failed: %d\n", ret); + return ret; + } + +#endif + + UNUSED(ret); + return OK; +} + +#endif /* CONFIG_PWM */ diff --git a/boards/arm/imxrt/teensy-4.x/src/teensy-4.h b/boards/arm/imxrt/teensy-4.x/src/teensy-4.h index 1f0a8bc..849dd77 100644 --- a/boards/arm/imxrt/teensy-4.x/src/teensy-4.h +++ b/boards/arm/imxrt/teensy-4.x/src/teensy-4.h @@ -163,6 +163,18 @@ int imxrt_can_setup(void); #endif /**************************************************************************** + * Name: imxrt_pwm_setup + * + * Description: + * Initialize PWM and register the PWM device. + * + ****************************************************************************/ + +#ifdef CONFIG_IMXRT_FLEXPWM +int imxrt_pwm_setup(void); +#endif + +/**************************************************************************** * Name: imxrt_adc_initialize * * Description:
