Skip to content

Commit

Permalink
boards/nucleo-g431rb: add SocketCAN example
Browse files Browse the repository at this point in the history
  • Loading branch information
raiden00pl authored and JacobCrabill committed May 24, 2022
1 parent d530842 commit 69372b7
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
56 changes: 56 additions & 0 deletions boards/arm/stm32/nucleo-g431rb/configs/cansock/defconfig
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions boards/arm/stm32/nucleo-g431rb/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 **********************************************************/
Expand Down Expand Up @@ -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 */
22 changes: 22 additions & 0 deletions boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <syslog.h>

#include <nuttx/board.h>
#include <nuttx/fs/fs.h>

#ifdef CONFIG_USERLED
# include <nuttx/leds/userled.h>
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
}
57 changes: 57 additions & 0 deletions boards/arm/stm32/nucleo-g431rb/src/stm32_cansock.c
Original file line number Diff line number Diff line change
@@ -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 <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;
}

0 comments on commit 69372b7

Please sign in to comment.