1
0
Fork 0
forked from nuttx/nuttx-update

boards/nrf5340-dk: add PWM configuration

This commit is contained in:
raiden00pl 2023-03-13 14:33:41 +01:00 committed by Petro Karashchenko
parent 93ac27ff63
commit 38631bd560
6 changed files with 188 additions and 0 deletions

View file

@ -0,0 +1,56 @@
#
# 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_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_STANDARD_SERIAL is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="nrf5340-dk"
CONFIG_ARCH_BOARD_NRF5340_DK=y
CONFIG_ARCH_CHIP="nrf53"
CONFIG_ARCH_CHIP_NRF5340=y
CONFIG_ARCH_CHIP_NRF5340_CPUAPP=y
CONFIG_ARCH_CHIP_NRF53=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_STDARG_H=y
CONFIG_BOARD_LOOPSPERMSEC=5500
CONFIG_BUILTIN=y
CONFIG_EXAMPLES_PWM=y
CONFIG_EXPERIMENTAL=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_MM_REGIONS=2
CONFIG_NRF53_PWM0=y
CONFIG_NRF53_PWM0_CH0=y
CONFIG_NRF53_PWM0_CH1=y
CONFIG_NRF53_PWM0_CH2=y
CONFIG_NRF53_PWM0_CH3=y
CONFIG_NRF53_PWM_MULTICHAN=y
CONFIG_NRF53_UART0=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PWM=y
CONFIG_PWM_MULTICHAN=y
CONFIG_PWM_NCHANNELS=4
CONFIG_RAM_SIZE=524288
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=26
CONFIG_START_MONTH=3
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_UART0_SERIAL_CONSOLE=y

View file

@ -127,4 +127,18 @@
GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(20))
#endif
/* PWM Pins *****************************************************************/
/* PWM 0:
* PWM0 CH0 - P1.10
* PWM0 CH1 - P1.11
* PWM0 CH2 - P1.12
* PWM0 CH3 - P1.13
*/
#define NRF53_PWM0_CH0_PIN (GPIO_MCUSEL_APP | GPIO_OUTPUT | GPIO_PORT1 | GPIO_PIN(10))
#define NRF53_PWM0_CH1_PIN (GPIO_MCUSEL_APP | GPIO_OUTPUT | GPIO_PORT1 | GPIO_PIN(11))
#define NRF53_PWM0_CH2_PIN (GPIO_MCUSEL_APP | GPIO_OUTPUT | GPIO_PORT1 | GPIO_PIN(12))
#define NRF53_PWM0_CH3_PIN (GPIO_MCUSEL_APP | GPIO_OUTPUT | GPIO_PORT1 | GPIO_PIN(13))
#endif /* __BOARDS_ARM_NRF53_NRF5340_DK_INCLUDE_BOARD_H */

View file

@ -42,4 +42,8 @@ CSRCS += nrf53_timer.c
endif
endif
ifeq ($(CONFIG_PWM),y)
CSRCS += nrf53_pwm.c
endif
include $(TOPDIR)/boards/Board.mk

View file

@ -94,5 +94,17 @@ int nrf53_bringup(void);
int nrf53_timer_driver_setup(const char *devpath, int timer);
#endif
/****************************************************************************
* Name: nrf53_pwm_setup
*
* Description:
* Initialize PWM driver.
*
****************************************************************************/
#ifdef CONFIG_PWM
int nrf53_pwm_setup(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_NRF53_NRF5340_DK_SRC_NRF53_NRF5340_DK_H */

View file

@ -99,6 +99,18 @@ int nrf53_bringup(void)
}
#endif
#ifdef CONFIG_PWM
/* Configure PWM driver */
ret = nrf53_pwm_setup();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize PWM driver: %d\n",
ret);
}
#endif
#ifdef CONFIG_NRF53_SOFTDEVICE_CONTROLLER
ret = nrf53_sdc_initialize();

View file

@ -0,0 +1,90 @@
/****************************************************************************
* boards/arm/nrf53/nrf5340-dk/src/nrf53_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 <debug.h>
#include <errno.h>
#include <stddef.h>
#include <nuttx/timers/pwm.h>
#include <arch/board/board.h>
#include "nrf53_pwm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define NRF53_PWM (0)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nrf53_pwm_setup
*
* Description:
* Initialize PWM and register the PWM device.
*
****************************************************************************/
int nrf53_pwm_setup(void)
{
static bool initialized = false;
struct pwm_lowerhalf_s *pwm = NULL;
int ret = OK;
/* Have we already initialized? */
if (!initialized)
{
/* Call nrf53_pwminitialize() to get an instance of the PWM interface */
pwm = nrf53_pwminitialize(NRF53_PWM);
if (!pwm)
{
aerr("ERROR: Failed to get the NRF53 PWM lower half\n");
ret = -ENODEV;
goto errout;
}
/* Register the PWM driver at "/dev/pwm0" */
ret = pwm_register("/dev/pwm0", pwm);
if (ret < 0)
{
aerr("ERROR: pwm_register failed: %d\n", ret);
goto errout;
}
/* Now we are initialized */
initialized = true;
}
errout:
return ret;
}