Skip to content

Commit

Permalink
add can socket support
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Bee <[email protected]>
  • Loading branch information
PeterBee97 committed Mar 15, 2024
1 parent 6462572 commit 29f8fed
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
9 changes: 9 additions & 0 deletions boards/arm/stm32/doublecan/configs/can/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
# CONFIG_NSH_DISABLE_WGET is not set
# CONFIG_NSH_DISABLE_XD is not set
# CONFIG_STM32_USE_LEGACY_PINMAP is not set
CONFIG_ALLOW_GPL_COMPONENTS=y
CONFIG_ANALOG=y
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="doublecan"
Expand All @@ -90,6 +91,11 @@ CONFIG_BOARD_INITTHREAD_STACKSIZE=2048
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=5483
CONFIG_BUILTIN=y
CONFIG_CAN=y
CONFIG_CANUTILS_CANDUMP=y
CONFIG_CANUTILS_CANLIB=y
CONFIG_CANUTILS_CANSEND=y
CONFIG_CANUTILS_SLCAN=y
CONFIG_CAN_EXTID=y
CONFIG_CAN_LOOPBACK=y
CONFIG_DEBUG_FULLOPT=y
Expand Down Expand Up @@ -124,6 +130,7 @@ CONFIG_NET_CAN=y
CONFIG_NET_CAN_EXTID=y
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_STATISTICS=y
CONFIG_NET_TCP=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=5
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
Expand All @@ -140,6 +147,7 @@ CONFIG_PTHREAD_STACK_MIN=2048
CONFIG_RAM_SIZE=65536
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_HAVE_PARENT=y
Expand All @@ -153,6 +161,7 @@ CONFIG_STM32_ADC1=y
CONFIG_STM32_CAN1=y
CONFIG_STM32_CAN1_REMAP1=y
CONFIG_STM32_CAN2=y
CONFIG_STM32_CAN_SOCKET=y
CONFIG_STM32_CAN_TSEG1=13
CONFIG_STM32_CAN_TSEG2=2
CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
Expand Down
4 changes: 4 additions & 0 deletions boards/arm/stm32/doublecan/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ ifeq ($(CONFIG_STM32_CAN_CHARDRIVER),y)
CSRCS += stm32_can.c
endif

ifeq ($(CONFIG_STM32_CAN_SOCKET),y)
CSRCS += stm32_cansock.c
endif

ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
Expand Down
12 changes: 12 additions & 0 deletions boards/arm/stm32/doublecan/src/doublecan.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,17 @@ int board_usbmsc_initialize(int port);
int stm32_can_setup(void);
#endif

/****************************************************************************
* Name: stm32_cansock_setup
*
* Description:
* Initialize CAN and register the CAN SOCKET device
*
****************************************************************************/

#ifdef CONFIG_STM32_CAN_SOCKET
int stm32_cansock_setup(void);
#endif

#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_STM32_DOUBLECAN_SRC_DOUBLECAN_H */
12 changes: 11 additions & 1 deletion boards/arm/stm32/doublecan/src/stm32_appinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int board_app_initialize(uintptr_t arg)
ret = board_composite_initialize(0);
#endif

#ifdef CONFIG_STM32_CAN
#ifdef CONFIG_STM32_CAN_CHARDRIVER
/* Initialize CAN and register the CAN driver. */

ret = stm32_can_setup();
Expand All @@ -97,6 +97,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif

#ifdef CONFIG_STM32_CAN_SOCKET
/* Initialize CAN and register the CAN SOCKET driver. */

ret = stm32_cansock_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
}
#endif

#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */

Expand Down
88 changes: 88 additions & 0 deletions boards/arm/stm32/doublecan/src/stm32_cansock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/****************************************************************************
* boards/arm/stm32/doublecan/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_can.h"

#ifdef CONFIG_CAN

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/* Configuration ************************************************************/

#ifdef CONFIG_STM32_CAN1
# define CAN1_PORT 1
#endif
#ifdef CONFIG_STM32_CAN2
# define CAN2_PORT 2
#endif

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: stm32_cansock_setup
*
* Description:
* Initialize CAN socket interface
*
****************************************************************************/

int stm32_cansock_setup(void)
{
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
int ret;

/* Call stm32_cansockinitialize() to get an instance of the CAN interface */
#if defined(CONFIG_STM32_CAN1)
ret = stm32_cansockinitialize(CAN1_PORT);
if (ret < 0)
{
canerr("ERROR: Failed to get CAN interface %d\n", ret);
return ret;
}
#endif

#if defined(CONFIG_STM32_CAN2)
ret = stm32_cansockinitialize(CAN2_PORT);
if (ret < 0)
{
canerr("ERROR: Failed to get CAN interface %d\n", ret);
return ret;
}
#endif

return OK;
#else
return -ENODEV;
#endif
}

#endif /* CONFIG_CAN */

0 comments on commit 29f8fed

Please sign in to comment.