From 69372b72294b91b657aaef0a4787a2674b660cd8 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Sat, 22 Jan 2022 17:12:05 +0100 Subject: [PATCH] boards/nucleo-g431rb: add SocketCAN example --- .../nucleo-g431rb/configs/cansock/defconfig | 56 ++++++++++++++++++ boards/arm/stm32/nucleo-g431rb/src/Make.defs | 5 ++ .../stm32/nucleo-g431rb/src/nucleo-g431rb.h | 22 +++++++ .../stm32/nucleo-g431rb/src/stm32_bringup.c | 22 +++++++ .../stm32/nucleo-g431rb/src/stm32_cansock.c | 57 +++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 boards/arm/stm32/nucleo-g431rb/configs/cansock/defconfig create mode 100644 boards/arm/stm32/nucleo-g431rb/src/stm32_cansock.c diff --git a/boards/arm/stm32/nucleo-g431rb/configs/cansock/defconfig b/boards/arm/stm32/nucleo-g431rb/configs/cansock/defconfig new file mode 100644 index 00000000000..44326688ccb --- /dev/null +++ b/boards/arm/stm32/nucleo-g431rb/configs/cansock/defconfig @@ -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_NET_ETHERNET is not set +# CONFIG_NET_IPv4 is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="nucleo-g431rb" +CONFIG_ARCH_BOARD_NUCLEO_G431RB=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="stm32" +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32G431R=y +CONFIG_ARCH_INTERRUPTSTACK=1024 +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LATE_INITIALIZE=y +CONFIG_BOARD_LOOPSPERMSEC=8499 +CONFIG_BOARD_NUCLEO_G431RB_USE_HSE=y +CONFIG_BUILTIN=y +CONFIG_DEFAULT_TASK_STACKSIZE=1024 +CONFIG_FS_PROCFS=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=2048 +CONFIG_INTELHEX_BINARY=y +CONFIG_IOB_BUFSIZE=128 +CONFIG_IOB_NBUFFERS=10 +CONFIG_NET=y +CONFIG_NETDEVICES=y +CONFIG_NETDEV_IFINDEX=y +CONFIG_NETDEV_LATEINIT=y +CONFIG_NET_CAN=y +CONFIG_NET_SOCKOPTS=y +CONFIG_NET_STATISTICS=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=22528 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=14 +CONFIG_START_MONTH=10 +CONFIG_START_YEAR=2014 +CONFIG_STM32_FDCAN1=y +CONFIG_STM32_FDCAN_SOCKET=y +CONFIG_STM32_JTAG_SW_ENABLE=y +CONFIG_STM32_USART2=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART2_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32/nucleo-g431rb/src/Make.defs b/boards/arm/stm32/nucleo-g431rb/src/Make.defs index 3ca40eb1344..bb60c5e55e5 100644 --- a/boards/arm/stm32/nucleo-g431rb/src/Make.defs +++ b/boards/arm/stm32/nucleo-g431rb/src/Make.defs @@ -51,9 +51,14 @@ ifeq ($(CONFIG_BOARD_STM32_IHM16M1),y) CSRCS += stm32_foc_ihm16m1.c endif +ifeq ($(CONFIG_STM32_FDCAN),y) ifeq ($(CONFIG_STM32_FDCAN_CHARDRIVER),y) CSRCS += stm32_can.c endif +ifeq ($(CONFIG_STM32_FDCAN_SOCKET),y) +CSRCS += stm32_cansock.c +endif +endif DEPPATH += --dep-path board VPATH += :board diff --git a/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h b/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h index a7a1d69f798..417eed4ede6 100644 --- a/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h +++ b/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h @@ -31,6 +31,16 @@ * Pre-processor Definitions ****************************************************************************/ +/* procfs File System */ + +#ifdef CONFIG_FS_PROCFS +# ifdef CONFIG_NSH_PROC_MOUNTPOINT +# define STM32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT +# else +# define STM32_PROCFS_MOUNTPOINT "/proc" +# endif +#endif + /* LED definitions **********************************************************/ /* LED definitions **********************************************************/ @@ -155,4 +165,16 @@ int stm32_foc_setup(void); int stm32_can_setup(void); #endif +/**************************************************************************** + * Name: stm32_cansock_setup + * + * Description: + * Initialize CAN socket interface + * + ****************************************************************************/ + +#ifdef CONFIG_STM32_FDCAN_SOCKET +int stm32_cansock_setup(void); +#endif + #endif /* __BOARDS_ARM_STM32_NUCLEO_G431RB_SRC_NUCLEO_G431RB_H */ diff --git a/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c b/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c index 6787e9e4370..02e49a1547c 100644 --- a/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c +++ b/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c @@ -28,6 +28,7 @@ #include #include +#include #ifdef CONFIG_USERLED # include @@ -71,6 +72,17 @@ int stm32_bringup(void) { int ret; +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount the PROC filesystem: %d\n", ret); + } +#endif /* CONFIG_FS_PROCFS */ + #ifdef CONFIG_INPUT_BUTTONS /* Register the BUTTON driver */ @@ -132,6 +144,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_STM32_FDCAN_SOCKET + /* Initialize CAN socket interface */ + + ret = stm32_cansock_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/boards/arm/stm32/nucleo-g431rb/src/stm32_cansock.c b/boards/arm/stm32/nucleo-g431rb/src/stm32_cansock.c new file mode 100644 index 00000000000..e446a548e26 --- /dev/null +++ b/boards/arm/stm32/nucleo-g431rb/src/stm32_cansock.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * boards/arm/stm32/nucleo-g431rb/src/stm32_cansock.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 + +#include + +#include "stm32_fdcan.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_cansock_setup + * + * Description: + * Initialize CAN socket interface + * + ****************************************************************************/ + +int stm32_cansock_setup(void) +{ + int ret; + + /* Call stm32_fdcaninitialize() to get an instance of the FDCAN interface */ + + ret = stm32_fdcansockinitialize(1); + if (ret < 0) + { + canerr("ERROR: Failed to get FDCAN interface %d\n", ret); + return ret; + } + + return OK; +}