diff --git a/boards/arm64/imx9/imx93-evk/configs/nsh/defconfig b/boards/arm64/imx9/imx93-evk/configs/nsh/defconfig index 09f153f038c..c663f70c537 100644 --- a/boards/arm64/imx9/imx93-evk/configs/nsh/defconfig +++ b/boards/arm64/imx9/imx93-evk/configs/nsh/defconfig @@ -49,6 +49,7 @@ CONFIG_IMX9_ENET1_RGMII=y CONFIG_IMX9_ENET1_RGMII_ID=y CONFIG_IMX9_ENET=y CONFIG_IMX9_ENET_USE_OTP_MAC=y +CONFIG_IMX9_FLEXIO1_DSHOT=y CONFIG_IMX9_FLEXIO1_PWM=y CONFIG_IMX9_GPIO_IRQ=y CONFIG_IMX9_LPI2C1=y diff --git a/boards/arm64/imx9/imx93-evk/include/board.h b/boards/arm64/imx9/imx93-evk/include/board.h index bcb6fbb6261..d0fecda3b23 100644 --- a/boards/arm64/imx9/imx93-evk/include/board.h +++ b/boards/arm64/imx9/imx93-evk/include/board.h @@ -60,6 +60,20 @@ #define FLEXIO1_PWM2_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO06_FLEXIO1_FLEXIO06, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6, 0) #define FLEXIO1_PWM3_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO07_FLEXIO1_FLEXIO07, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6, 0) +/* FLEXIO to DSHOT pin muxings */ + +/* EVK signals + * GPIO_IO04 -> FLEXIO1_04 + * GPIO_IO05 -> FLEXIO1_05 + * GPIO_IO06 -> FLEXIO1_06 + * GPIO_IO07 -> FLEXIO1_07 + */ + +#define FLEXIO1_DSHOT0_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO04_FLEXIO1_FLEXIO04, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X4 | IOMUXC_PAD_PU_ON | IOMUXC_PAD_HYS_ST_ON, IOMUXC_MUX_SION_ON) +#define FLEXIO1_DSHOT1_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO05_FLEXIO1_FLEXIO05, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X4 | IOMUXC_PAD_PU_ON | IOMUXC_PAD_HYS_ST_ON, IOMUXC_MUX_SION_ON) +#define FLEXIO1_DSHOT2_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO06_FLEXIO1_FLEXIO06, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X4 | IOMUXC_PAD_PU_ON | IOMUXC_PAD_HYS_ST_ON, IOMUXC_MUX_SION_ON) +#define FLEXIO1_DSHOT3_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO07_FLEXIO1_FLEXIO07, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X4 | IOMUXC_PAD_PU_ON | IOMUXC_PAD_HYS_ST_ON, IOMUXC_MUX_SION_ON) + /* LPI2Cs */ /* TPM3 ch3 to PWM pin GPIO_IO24 muxing */ diff --git a/boards/arm64/imx9/imx93-evk/src/Makefile b/boards/arm64/imx9/imx93-evk/src/Makefile index defc57b93bb..d938b626dc0 100644 --- a/boards/arm64/imx9/imx93-evk/src/Makefile +++ b/boards/arm64/imx9/imx93-evk/src/Makefile @@ -32,6 +32,10 @@ ifeq ($(CONFIG_PWM),y) CSRCS += imx9_pwm.c endif +ifeq ($(CONFIG_DSHOT),y) +CSRCS += imx9_dshot.c +endif + ifeq ($(CONFIG_IMX9_LPI2C),y) CSRCS += imx9_i2c.c endif diff --git a/boards/arm64/imx9/imx93-evk/src/imx93-evk.h b/boards/arm64/imx9/imx93-evk/src/imx93-evk.h index d0584c113d5..072dcc50241 100644 --- a/boards/arm64/imx9/imx93-evk/src/imx93-evk.h +++ b/boards/arm64/imx9/imx93-evk/src/imx93-evk.h @@ -87,6 +87,18 @@ int imx9_bringup(void); int imx9_pwm_setup(void); #endif +/**************************************************************************** + * Name: imx9_dshot_setup + * + * Description: + * Initialize DShot outputs + * + ****************************************************************************/ + +#if defined(CONFIG_DSHOT) +int imx9_dshot_setup(void); +#endif + /**************************************************************************** * Name: imx9_i2c_setup * diff --git a/boards/arm64/imx9/imx93-evk/src/imx9_bringup.c b/boards/arm64/imx9/imx93-evk/src/imx9_bringup.c index 8a4e69b0dd9..84a73c81cab 100644 --- a/boards/arm64/imx9/imx93-evk/src/imx9_bringup.c +++ b/boards/arm64/imx9/imx93-evk/src/imx9_bringup.c @@ -104,6 +104,16 @@ int imx9_bringup(void) } #endif +#ifdef CONFIG_DSHOT + /* Configure DSHOT outputs */ + + ret = imx9_dshot_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed initialize DShot outputs: %d\n", ret); + } +#endif + #if defined(CONFIG_I2C_DRIVER) /* Configure I2C peripheral interfaces */ diff --git a/boards/arm64/imx9/imx93-evk/src/imx9_dshot.c b/boards/arm64/imx9/imx93-evk/src/imx9_dshot.c new file mode 100644 index 00000000000..062c6ac19eb --- /dev/null +++ b/boards/arm64/imx9/imx93-evk/src/imx9_dshot.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * boards/arm64/imx9/imx93-evk/src/imx9_dshot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 +#include +#include + +#include + +#include "imx9_flexio_dshot.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: imx9_dshot_setup + * + * Description: + * + * Initialize DShot and register DShot devices + * + * Input Parameters: + * None + * + * Returned Value: + * 0 on success, negated error value on error + * + ****************************************************************************/ + +int imx9_dshot_setup(void) +{ + struct dshot_lowerhalf_s *lower_half = NULL; + int ret = 0; + +#ifdef CONFIG_IMX9_FLEXIO1_DSHOT + lower_half = imx9_flexio_dshot_init(DSHOT_FLEXIO1); + + if (lower_half) + { + ret = dshot_register("/dev/dshot0", lower_half); + } + else + { + ret = -ENODEV; + } + + if (ret < 0) + { + return ret; + } +#endif + +#ifdef CONFIG_IMX9_FLEXIO2_DSHOT + lower_half = imx9_flexio_dshot_init(DSHOT_FLEXIO2); + + if (lower_half) + { + ret = dshot_register("/dev/dshot1", lower_half); + } + else + { + ret = -ENODEV; + } + + if (ret < 0) + { + return ret; + } +#endif + + return ret; +}