This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c19b5eeb8d8f37394c79ff85876c7ba6d846fc12 Author: David <dvosah...@gmail.com> AuthorDate: Mon Jan 16 14:29:31 2023 +0100 Add support of CAN character device for tm4c1294 launchpad. --- boards/arm/tiva/tm4c1294-launchpad/Kconfig | 42 +++++++ boards/arm/tiva/tm4c1294-launchpad/include/board.h | 12 ++ boards/arm/tiva/tm4c1294-launchpad/src/Makefile | 4 + .../tm4c1294-launchpad/src/tm4c1294-launchpad.h | 18 ++- .../arm/tiva/tm4c1294-launchpad/src/tm4c_bringup.c | 22 ++++ boards/arm/tiva/tm4c1294-launchpad/src/tm4c_can.c | 136 +++++++++++++++++++++ 6 files changed, 233 insertions(+), 1 deletion(-) diff --git a/boards/arm/tiva/tm4c1294-launchpad/Kconfig b/boards/arm/tiva/tm4c1294-launchpad/Kconfig index ec8c2464fa..6b28e98da6 100644 --- a/boards/arm/tiva/tm4c1294-launchpad/Kconfig +++ b/boards/arm/tiva/tm4c1294-launchpad/Kconfig @@ -72,4 +72,46 @@ config TM4C1294_LAUNCHPAD_TIMER_ALTCLK endif # TM4C1294_LAUNCHPAD_TIMER endif # TIVA_TIMER32_PERIODIC +config TM4C1294_LAUNCHPAD_JUMPERS_CAN + bool "Use CAN jumpers configuration" + default n + select TIVA_UART2 + ---help--- + If set, NuttX will assume the jumpers JP4 and JP5 are set in CAN configuration. + This means UART2 will be connected to the ICDI serial port. + +choice + prompt "UART2 Rx pin selection" + depends on TIVA_UART2 + default TM4C1294_LAUNCHPAD_UART2_RX_A6 + +config TM4C1294_LAUNCHPAD_UART2_RX_A6 + bool "Use A6 as UART Rx pin" + default n + depends on TIVA_UART2 && !TM4C1294_LAUNCHPAD_JUMPERS_CAN + +config TM4C1294_LAUNCHPAD_UART2_RX_D4 + bool "Use D4 as UART Rx pin" + default n + depends on TIVA_UART2 + +endchoice # UART2 Rx pin selection + +choice + prompt "UART2 Tx pin selection" + default TM4C1294_LAUNCHPAD_UART2_TX_A7 + depends on TIVA_UART2 + +config TM4C1294_LAUNCHPAD_UART2_TX_A7 + bool "Use A7 as UART Tx pin" + default n + depends on TIVA_UART2 && !TM4C1294_LAUNCHPAD_JUMPERS_CAN + +config TM4C1294_LAUNCHPAD_UART2_TX_D5 + bool "Use D5 as UART Tx pin" + default n + depends on TIVA_UART2 + +endchoice # UART2 Tx pin selection + endif # ARCH_BOARD_TM4C1294_LAUNCHPAD diff --git a/boards/arm/tiva/tm4c1294-launchpad/include/board.h b/boards/arm/tiva/tm4c1294-launchpad/include/board.h index 159f4be6b8..a7b57c1907 100644 --- a/boards/arm/tiva/tm4c1294-launchpad/include/board.h +++ b/boards/arm/tiva/tm4c1294-launchpad/include/board.h @@ -190,6 +190,18 @@ #define GPIO_EN0_LED1 GPIO_EN0_LED1_1 #define GPIO_EN0_LED2 GPIO_EN0_LED2_1 +#if CONFIG_TM4C1294_LAUNCHPAD_UART2_RX_D4 +#define GPIO_UART2_RX GPIO_UART2_RX_2 +#elif CONFIG_TM4C1294_LAUNCHPAD_UART2_RX_A6 +#define GPIO_UART2_RX GPIO_UART2_RX_1 +#endif + +#if CONFIG_TM4C1294_LAUNCHPAD_UART2_TX_D5 +#define GPIO_UART2_TX GPIO_UART2_TX_2 +#elif CONFIG_TM4C1294_LAUNCHPAD_UART2_TX_A7 +#define GPIO_UART2_TX GPIO_UART2_TX_1 +#endif + /* Control pins for BOOST-CC2564MODA plugged into BoosterPack1 * * --- ------------ diff --git a/boards/arm/tiva/tm4c1294-launchpad/src/Makefile b/boards/arm/tiva/tm4c1294-launchpad/src/Makefile index 87e3452492..db6912670a 100644 --- a/boards/arm/tiva/tm4c1294-launchpad/src/Makefile +++ b/boards/arm/tiva/tm4c1294-launchpad/src/Makefile @@ -36,6 +36,10 @@ ifeq ($(CONFIG_TIVA_ETHERNET),y) CSRCS += tm4c_ethernet.c endif +ifeq ($(CONFIG_TIVA_CAN),y) +CSRCS += tm4c_can.c +endif + ifeq ($(CONFIG_DK_TM4C129X_TIMER),y) CSRCS += tm4c_timer.c endif diff --git a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c1294-launchpad.h b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c1294-launchpad.h index 0836d16df8..b9792254d7 100644 --- a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c1294-launchpad.h +++ b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c1294-launchpad.h @@ -41,7 +41,7 @@ #if !defined(CONFIG_TIVA_HCIUART) || !defined(CONFIG_BLUETOOTH_UART) # undef HAVE_HCIUART -#elif defined(CONFIG_TIVA_UART0_HCIUART) +#elif defined(CONFIG_TIVA_UART0_HCIUART) && !defined(TM4C1294_LAUNCHPAD_JUMPERS_CAN) # define HCIUART_SERDEV HCIUART0 #elif defined(CONFIG_TIVA_UART1_HCIUART) # define HCIUART_SERDEV HCIUART1 @@ -77,6 +77,10 @@ # undef HAVE_I2CTOOL #endif +/* Define the procfs mounting point */ + +#define TIVA_PROCFS_MOUNTPOINT "/proc" + /* LED definitions **********************************************************/ /* The EK-TM4C1294XL has a four green LEDs. @@ -211,6 +215,18 @@ int tm4c_bringup(void); int tiva_timer_configure(void); #endif +/**************************************************************************** + * Name: tm4c_can_setup + * + * Description: + * Initialize CAN modules and register the CAN driver. + * + ****************************************************************************/ + +#ifdef CONFIG_TIVA_CAN +int tm4c_can_setup(void); +#endif + /**************************************************************************** * Name: hciuart_dev_initialize * diff --git a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_bringup.c b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_bringup.c index 1288ea5ad0..5d73175e37 100644 --- a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_bringup.c +++ b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_bringup.c @@ -31,6 +31,7 @@ #include <nuttx/i2c/i2c_master.h> #include <nuttx/sensors/qencoder.h> #include <arch/board/board.h> +#include <nuttx/fs/fs.h> #include <nuttx/timers/pwm.h> @@ -305,6 +306,17 @@ int tm4c_bringup(void) tm4c_i2ctool(); +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, TIVA_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at %s: %d\n", + TIVA_PROCFS_MOUNTPOINT, ret); + } +#endif + #ifdef HAVE_PWM /* Register PWM drivers */ @@ -317,6 +329,16 @@ int tm4c_bringup(void) tm4c_qei(); #endif +#ifdef CONFIG_TIVA_CAN + /* Initialize CAN module and register the CAN driver(s) */ + + ret = tm4c_can_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: tm4c_can_setup failed %d\n", ret); + } +#endif + #ifdef HAVE_TIMER /* Initialize the timer driver */ diff --git a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_can.c b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_can.c new file mode 100644 index 0000000000..5649a4ca4f --- /dev/null +++ b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_can.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * boards/arm/tiva/tm4c1294-launchpad/src/tm4c_can.c + * Based heavily on tiva_can.c from the tm4c1293-launchpad board + * + * 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 <errno.h> +#include <debug.h> + +#include <nuttx/can/can.h> +#include <arch/board/board.h> + +#include "chip.h" +#include "arm_internal.h" + +#include "tiva_can.h" +#include "tm4c1294-launchpad.h" + +#include "tiva_enableclks.h" +#include "tiva_gpio.h" +#include "hardware/tiva_pinmap.h" + +#ifdef CONFIG_CAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tm4c_can_setup + * + * Description: + * Initialize CAN and register the CAN device + * + ****************************************************************************/ + +int tm4c_can_setup(void) +{ +#ifdef CONFIG_TIVA_CAN + int ret; + +# ifdef CONFIG_TIVA_CAN0 + tiva_can0_enableclk(); + + ret = tiva_configgpio(GPIO_CAN0_RX); + + if (ret < 0) + { + goto configgpio_error; + } + + ret = tiva_configgpio(GPIO_CAN0_TX); + + if (ret < 0) + { + goto configgpio_error; + } + + /* Call tiva_can_initialize() to get an instance of CAN interface 0 + * and register it. + */ + + ret = tiva_can_initialize("/dev/can0", 0); + if (ret < 0) + { + canerr("ERROR: Failed to get/register CAN interface 0\n"); + return ret; + } +# endif /* CONFIG_TIVA_CAN0 */ + +# ifdef CONFIG_TIVA_CAN1 + tiva_can1_enableclk(); + + ret = tiva_configgpio(GPIO_CAN1_RX); + + if (ret < 0) + { + goto configgpio_error; + } + + ret = tiva_configgpio(GPIO_CAN1_TX); + + if (ret < 0) + { + goto configgpio_error; + } + + /* Call tiva_can_initialize() to get an instance of CAN interface 1 + * and register it. + */ + + ret = tiva_can_initialize("/dev/can1", 1); + if (ret < 0) + { + canerr("ERROR: Failed to get/register CAN interface 1\n"); + return ret; + } +# endif /* CONFIG_TIVA_CAN1 */ + + return OK; + +configgpio_error: + canerr("ERROR: failed to configure CAN GPIO pin.\n"); + return ret; +#else + return -ENODEV; +#endif +} + +#endif /* CONFIG_CAN */ +