Skip to content

Commit 80b9fc3

Browse files
leocafonsoacassis
authored andcommitted
boards/arduino-r4-minima: Add PWM support using GPT timer
- Added PWM support on Arduino R4 Minima board. This board has 5 PWM channels available using the GPT timer from the RA4M1 microcontroller. - Added a pwm config file to enable PWM supporting GTP2 GTIOCB on P102. Signed-off-by: leocafonso <leocafonso@gmail.com>
1 parent 2667f51 commit 80b9fc3

7 files changed

Lines changed: 213 additions & 0 deletions

File tree

boards/arm/ra4/arduino-r4-minima/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,20 @@
55

66
if ARCH_BOARD_ARDUINO_R4_MINIMA
77

8+
config ARDUINO_R4_MINIMA_PWM_CHANNEL
9+
int "PWM channel number"
10+
default 0 if RA_GPT0_PWM
11+
default 1 if RA_GPT1_PWM
12+
default 2 if RA_GPT2_PWM
13+
default 3 if RA_GPT3_PWM
14+
default 4 if RA_GPT4_PWM
15+
default 5 if RA_GPT5_PWM
16+
default 6 if RA_GPT6_PWM
17+
default 7 if RA_GPT7_PWM
18+
range 0 7
19+
depends on PWM && RA_PWM
20+
---help---
21+
Selects the PWM channel number that will be used to perform the PWM
22+
test. See apps/examples/pwm.
23+
824
endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# This file is autogenerated: PLEASE DO NOT EDIT IT.
3+
#
4+
# You can use "make menuconfig" to make any modifications to the installed .config file.
5+
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
6+
# modifications.
7+
#
8+
CONFIG_ARCH="arm"
9+
CONFIG_ARCH_BOARD="arduino-r4-minima"
10+
CONFIG_ARCH_BOARD_ARDUINO_R4_MINIMA=y
11+
CONFIG_ARCH_CHIP="ra4"
12+
CONFIG_ARCH_CHIP_R7FA4M1ABxxFM=y
13+
CONFIG_ARCH_CHIP_RA4=y
14+
CONFIG_ARCH_STACKDUMP=y
15+
CONFIG_BOARD_LOOPSPERMSEC=6965
16+
CONFIG_BUILTIN=y
17+
CONFIG_EXAMPLES_PWM=y
18+
CONFIG_FS_PROCFS=y
19+
CONFIG_HAVE_CXX=y
20+
CONFIG_HAVE_CXXINITIALIZE=y
21+
CONFIG_INIT_ENTRYPOINT="nsh_main"
22+
CONFIG_INTELHEX_BINARY=y
23+
CONFIG_NSH_ARCHINIT=y
24+
CONFIG_NSH_BUILTIN_APPS=y
25+
CONFIG_NSH_DISABLE_IFUPDOWN=y
26+
CONFIG_NSH_FILEIOSIZE=512
27+
CONFIG_NSH_READLINE=y
28+
CONFIG_PREALLOC_TIMERS=4
29+
CONFIG_RAM_SIZE=32768
30+
CONFIG_RAM_START=0x20000000
31+
CONFIG_RA_GPT2=y
32+
CONFIG_RA_GPT2_OUTPUTB=y
33+
CONFIG_RA_GPT2_PWM=y
34+
CONFIG_RR_INTERVAL=200
35+
CONFIG_SCHED_WAITPID=y
36+
CONFIG_SCI2_SERIAL_CONSOLE=y
37+
CONFIG_START_DAY=28
38+
CONFIG_START_MONTH=6
39+
CONFIG_START_YEAR=2013
40+
CONFIG_SYSTEM_NSH=y
41+
CONFIG_TASK_NAME_SIZE=32

boards/arm/ra4/arduino-r4-minima/include/board.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@
7777
#define GPIO_SCI9_RX GPIO_RXD9_MISO9_SCL9_1 /* P110 */
7878
#define GPIO_SCI9_TX GPIO_TXD9_MOSI9_SDA9_1 /* P109 */
7979

80+
/* PWM Pins *****************************************************************/
81+
82+
/* PWM output pins:
83+
* D3 - P104
84+
* D5 - P102
85+
* D6 - P106
86+
* D9 - P303
87+
* D10 - P112
88+
* D11 - P109
89+
*/
90+
#define GPIO_GPT1_GTIOCB GPIO_GPT_GTIOC1B_P104
91+
#define GPIO_GPT2_GTIOCB GPIO_GPT_GTIOC2B_P102
92+
#define GPIO_GPT0_GTIOCB GPIO_GPT_GTIOC0B_P106
93+
#define GPIO_GPT7_GTIOCB GPIO_GPT_GTIOC7B_P303
94+
#define GPIO_GPT3_GTIOCB GPIO_GPT_GTIOC3B_P112
95+
#define GPIO_GPT1_GTIOCA GPIO_GPT_GTIOC1A_P109
96+
8097
/* LED pin selections */
8198

8299
#define GPIO_L_LED (gpio_pinset_t){ PORT1,PIN11, (GPIO_OUPUT | GPIO_LOW_DRIVE | GPIO_OUTPUT_LOW)} /* P111 */

boards/arm/ra4/arduino-r4-minima/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ else()
2626
list(APPEND SRCS ra4m1_userleds.c)
2727
endif()
2828

29+
if(CONFIG_PWM)
30+
list(APPEND SRCS ra4m1_pwm.c)
31+
endif()
32+
2933
target_sources(board PRIVATE ${SRCS})
3034

3135
set_property(GLOBAL PROPERTY LD_SCRIPT

boards/arm/ra4/arduino-r4-minima/src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ ifeq ($(CONFIG_BOARDCTL),y)
3232
CSRCS += ra4m1_appinit.c
3333
endif
3434

35+
ifeq ($(CONFIG_PWM),y)
36+
CSRCS += ra4m1_pwm.c
37+
endif
38+
3539
include $(TOPDIR)/boards/Board.mk

boards/arm/ra4/arduino-r4-minima/src/ra4m1_bringup.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
# define HAVE_LEDS 1
4646
#endif
4747

48+
#ifdef CONFIG_PWM
49+
extern int ra4m1_pwm_setup(void);
50+
#endif
51+
4852
/****************************************************************************
4953
* Public Functions
5054
****************************************************************************/
@@ -75,6 +79,16 @@ int ra4m1_bringup(void)
7579
}
7680
#endif
7781

82+
#ifdef CONFIG_PWM
83+
/* Initialize PWM and register the PWM device. */
84+
85+
ret = ra4m1_pwm_setup();
86+
if (ret < 0)
87+
{
88+
syslog(LOG_ERR, "ERROR: ra4m1_pwm_setup() failed: %d\n", ret);
89+
}
90+
#endif
91+
7892
UNUSED(ret);
7993
return OK;
8094
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/****************************************************************************
2+
* boards/arm/ra4/arduino-r4-minima/src/ra4m1_pwm.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <sys/types.h>
30+
#include <errno.h>
31+
#include <debug.h>
32+
33+
#include <nuttx/board.h>
34+
#include <nuttx/timers/pwm.h>
35+
36+
#include <arch/board/board.h>
37+
38+
#include "ra_pwm.h"
39+
40+
/****************************************************************************
41+
* Pre-processor Definitions
42+
****************************************************************************/
43+
44+
/* Configuration ************************************************************/
45+
46+
/* PWM.
47+
* There are no dedicated PWM output pins available to the user for PWM
48+
* testing.
49+
*/
50+
51+
#ifndef CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL
52+
# if defined(CONFIG_RA4M1_PWM_CHAN0)
53+
# warning Assuming PWM channel 0
54+
# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 0
55+
# elif defined(CONFIG_RA4M1_PWM_CHAN1)
56+
# warning Assuming PWM channel 1
57+
# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 1
58+
# elif defined(CONFIG_RA4M1_PWM_CHAN2)
59+
# warning Assuming PWM channel 2
60+
# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 2
61+
# elif defined(CONFIG_RA4M1_PWM_CHAN3)
62+
# warning Assuming PWM channel 3
63+
# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 3
64+
# endif
65+
#endif
66+
67+
#if defined(CONFIG_PWM) && defined(CONFIG_RA_PWM)
68+
69+
/****************************************************************************
70+
* Public Functions
71+
****************************************************************************/
72+
73+
/****************************************************************************
74+
* Name: ra4m1_pwm_setup
75+
*
76+
* Description:
77+
* Initialize PWM and register the PWM device.
78+
*
79+
****************************************************************************/
80+
81+
int ra4m1_pwm_setup(void)
82+
{
83+
static bool initialized = false;
84+
struct pwm_lowerhalf_s *pwm;
85+
int ret;
86+
87+
/* Have we already initialized? */
88+
89+
if (!initialized)
90+
{
91+
/* Call ra_pwminitialize() to get an instance of the PWM interface */
92+
93+
pwm = ra_pwminitialize(CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL);
94+
if (!pwm)
95+
{
96+
_err("ERROR: Failed to get the RA4M1 PWM lower half\n");
97+
return -ENODEV;
98+
}
99+
100+
/* Register the PWM driver at "/dev/pwm0" */
101+
102+
ret = pwm_register("/dev/pwm0", pwm);
103+
if (ret < 0)
104+
{
105+
aerr("ERROR: pwm_register failed: %d\n", ret);
106+
return ret;
107+
}
108+
109+
/* Now we are initialized */
110+
111+
initialized = true;
112+
}
113+
114+
return OK;
115+
}
116+
117+
#endif /* CONFIG_PWM */

0 commit comments

Comments
 (0)