boards/arm64/imx9/imx93-evk: Add PWM support utilizing flexio-pwm

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen 2024-04-02 10:01:41 +03:00 committed by Xiang Xiao
parent 47f37e84ba
commit 193d490f77
6 changed files with 136 additions and 0 deletions

View File

@ -32,6 +32,7 @@ CONFIG_FS_ROMFS=y
CONFIG_HAVE_CXX=y CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=8192 CONFIG_IDLETHREAD_STACKSIZE=8192
CONFIG_IMX9_FLEXIO1_PWM=y
CONFIG_IMX9_GPIO_IRQ=y CONFIG_IMX9_GPIO_IRQ=y
CONFIG_IMX9_UART1=y CONFIG_IMX9_UART1=y
CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INIT_ENTRYPOINT="nsh_main"
@ -41,6 +42,8 @@ CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PWM=y
CONFIG_PWM_NCHANNELS=4
CONFIG_RAMLOG=y CONFIG_RAMLOG=y
CONFIG_RAM_SIZE=134217728 CONFIG_RAM_SIZE=134217728
CONFIG_RAM_START=0x80000000 CONFIG_RAM_START=0x80000000

View File

@ -31,6 +31,20 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* FLEXIO to PWM pin muxings */
/* EVK signals
* GPIO_IO04 -> FLEXIO1_04
* GPIO_IO05 -> FLEXIO1_05
* GPIO_IO06 -> FLEXIO1_06
* GPIO_IO07 -> FLEXIO1_07
*/
#define FLEXIO1_PWM0_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO04_FLEXIO1_FLEXIO04, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6, 0)
#define FLEXIO1_PWM1_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO05_FLEXIO1_FLEXIO05, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6, 0)
#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)
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/

View File

@ -26,4 +26,8 @@ ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += imx9_appinit.c CSRCS += imx9_appinit.c
endif endif
ifeq ($(CONFIG_PWM),y)
CSRCS += imx9_pwm.c
endif
include $(TOPDIR)/boards/Board.mk include $(TOPDIR)/boards/Board.mk

View File

@ -55,5 +55,17 @@
int imx9_bringup(void); int imx9_bringup(void);
#endif #endif
/****************************************************************************
* Name: imx9_pwm_setup
*
* Description:
* Initialize PWM outputs
*
****************************************************************************/
#if defined(CONFIG_PWM)
int imx9_pwm_setup(void);
#endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM64_IMX9_IMX93_EVK_SRC_IMX93_EVK_H */ #endif /* __BOARDS_ARM64_IMX9_IMX93_EVK_SRC_IMX93_EVK_H */

View File

@ -57,6 +57,16 @@ int imx9_bringup(void)
} }
#endif #endif
#ifdef CONFIG_PWM
/* Configure PWM outputs */
ret = imx9_pwm_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed initialize PWM outputs: %d\n", ret);
}
#endif
UNUSED(ret); UNUSED(ret);
return OK; return OK;
} }

View File

@ -0,0 +1,93 @@
/****************************************************************************
* boards/arm64/imx9/imx93-evk/src/imx9_pwm.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 <nuttx/timers/pwm.h>
#include <arch/board/board.h>
#include <errno.h>
#include "imx9_flexio_pwm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: imx9_pwm_setup
*
* Description:
*
* Initialize PWM and register PWM devices
*
* Input Parameters:
* None
*
* Returned Value:
* 0 on success, negated error value on error
*
****************************************************************************/
int imx9_pwm_setup(void)
{
struct pwm_lowerhalf_s *lower_half = NULL;
int ret = 0;
#ifdef CONFIG_IMX9_FLEXIO1_PWM
lower_half = imx9_flexio_pwm_init(PWM_FLEXIO1);
if (lower_half)
{
ret = pwm_register("/dev/pwm0", lower_half);
}
else
{
ret = -ENODEV;
}
if (ret < 0)
{
return ret;
}
#endif
#ifdef CONFIG_IMX9_FLEXIO2_PWM
lower_half = imx9_flexio_pwm_init(PWM_FLEXIO2);
if (lower_half)
{
ret = pwm_register("/dev/pwm1", lower_half);
}
else
{
ret = -ENODEV;
}
#endif
return ret;
}