Skip to content

Commit

Permalink
boards/arm64/imx9/imx93-evk: Add PWM support utilizing flexio-pwm
Browse files Browse the repository at this point in the history
Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Apr 3, 2024
1 parent d8a0912 commit 31691ce
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
3 changes: 3 additions & 0 deletions boards/arm64/imx9/imx93-evk/configs/nsh/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CONFIG_FS_ROMFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=8192
CONFIG_IMX9_FLEXIO1_PWM=y
CONFIG_IMX9_GPIO_IRQ=y
CONFIG_IMX9_UART1=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
Expand All @@ -41,6 +42,8 @@ CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PWM=y
CONFIG_PWM_NCHANNELS=4
CONFIG_RAMLOG=y
CONFIG_RAM_SIZE=134217728
CONFIG_RAM_START=0x80000000
Expand Down
14 changes: 14 additions & 0 deletions boards/arm64/imx9/imx93-evk/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
* 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
****************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions boards/arm64/imx9/imx93-evk/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += imx9_appinit.c
endif

ifeq ($(CONFIG_PWM),y)
CSRCS += imx9_pwm.c
endif

include $(TOPDIR)/boards/Board.mk
12 changes: 12 additions & 0 deletions boards/arm64/imx9/imx93-evk/src/imx93-evk.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,17 @@
int imx9_bringup(void);
#endif

/****************************************************************************
* Name: imx9_pwm_setup
*
* Description:
* Initialize PWM outputs
*
****************************************************************************/

#if defined(CONFIG_PWM)
int imx9_pwm_setup(void);
#endif

#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM64_IMX9_IMX93_EVK_SRC_IMX93_EVK_H */
10 changes: 10 additions & 0 deletions boards/arm64/imx9/imx93-evk/src/imx9_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ int imx9_bringup(void)
}
#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);
return OK;
}
93 changes: 93 additions & 0 deletions boards/arm64/imx9/imx93-evk/src/imx9_pwm.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 31691ce

Please sign in to comment.