boards/b-g431b-esc1: add SocketCAN example

This commit is contained in:
raiden00pl 2022-01-22 17:11:46 +01:00 committed by Xiang Xiao
parent bc178344a9
commit ce1c5b814e
5 changed files with 162 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_NET_ETHERNET is not set
# CONFIG_NET_IPv4 is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="b-g431b-esc1"
CONFIG_ARCH_BOARD_B_G431B_ESC1=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32G431C=y
CONFIG_ARCH_INTERRUPTSTACK=1024
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BOARD_STM32_BG431BESC1_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

View File

@ -41,9 +41,14 @@ ifeq ($(CONFIG_STM32_FOC),y)
CSRCS += stm32_foc.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

View File

@ -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 **********************************************************/
@ -157,4 +167,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_B_G431B_ESC1_SRC_B_G431B_ESC1_H */

View File

@ -28,6 +28,7 @@
#include <syslog.h>
#include <nuttx/board.h>
#include <nuttx/fs/fs.h>
#include <stm32.h>
@ -81,6 +82,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 */
@ -159,6 +171,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;
}

View File

@ -0,0 +1,57 @@
/****************************************************************************
* boards/arm/stm32/b-g431b-esc1/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 <nuttx/config.h>
#include <debug.h>
#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;
}