mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 20:44:39 +08:00
stm32f7: add SocketCAN support
This commit is contained in:
@@ -6047,6 +6047,21 @@ endmenu # Timer Configuration
|
||||
menu "CAN driver configuration"
|
||||
depends on STM32F7_CAN
|
||||
|
||||
choice
|
||||
prompt "CAN character driver or SocketCAN support"
|
||||
default STM32F7_CAN_CHARDRIVER
|
||||
|
||||
config STM32F7_CAN_CHARDRIVER
|
||||
bool "STM32F7 CAN character driver support"
|
||||
select ARCH_HAVE_CAN_ERRORS
|
||||
select CAN
|
||||
|
||||
config STM32F7_CAN_SOCKET
|
||||
bool "STM32F7 CAN SocketCAN support"
|
||||
select NET_CAN_HAVE_ERRORS
|
||||
|
||||
endchoice # CAN character driver or SocketCAN support
|
||||
|
||||
config STM32F7_CAN1_BAUD
|
||||
int "CAN1 BAUD"
|
||||
default 250000
|
||||
|
||||
@@ -155,10 +155,14 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
|
||||
CHIP_CSRCS += stm32_qencoder.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32F7_CAN),y)
|
||||
ifeq ($(CONFIG_STM32F7_CAN_CHARDRIVER),y)
|
||||
CHIP_CSRCS += stm32_can.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32F7_CAN_SOCKET),y)
|
||||
CHIP_CSRCS += stm32_can_sock.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32F7_SAI),y)
|
||||
CHIP_CSRCS += stm32_sai.c
|
||||
endif
|
||||
|
||||
@@ -103,6 +103,8 @@ extern "C"
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_caninitialize
|
||||
*
|
||||
@@ -119,6 +121,26 @@ extern "C"
|
||||
|
||||
struct can_dev_s;
|
||||
struct can_dev_s *stm32_caninitialize(int port);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32F7_CAN_SOCKET
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_cansockinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the selected CAN port as SocketCAN interface
|
||||
*
|
||||
* Input Parameters:
|
||||
* Port number (for hardware that has multiple CAN interfaces)
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_cansockinitialize(int port);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -76,8 +76,13 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
|
||||
CSRCS += stm32_qencoder.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CAN),y)
|
||||
ifeq ($(CONFIG_STM32F7_CAN),y)
|
||||
ifeq ($(CONFIG_STM32F7_CAN_CHARDRIVER),y)
|
||||
CSRCS += stm32_can.c
|
||||
endif
|
||||
ifeq ($(CONFIG_STM32F7_CAN_SOCKET),y)
|
||||
CSRCS += stm32_cansock.c
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/boards/Board.mk
|
||||
|
||||
@@ -312,10 +312,18 @@ int stm32_qencoder_initialize(const char *devpath, int timer);
|
||||
* Name: stm32_can_setup
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32F7_CAN
|
||||
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
|
||||
int stm32_can_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_cansock_setup
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32F7_CAN_SOCKET
|
||||
int stm32_cansock_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32f7_gpio_initialize
|
||||
****************************************************************************/
|
||||
|
||||
@@ -184,7 +184,7 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CAN
|
||||
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
|
||||
ret = stm32_can_setup();
|
||||
if (ret < 0)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32f7/nucleo-144/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"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#if !defined(CONFIG_STM32F7_CAN1) && !defined(CONFIG_STM32F7_CAN2)
|
||||
# error "No CAN is enable. Please eneable at least one CAN device"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_cansock_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize CAN socket interface
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_cansock_setup(void)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
UNUSED(ret);
|
||||
|
||||
#ifdef CONFIG_STM32F7_CAN1
|
||||
/* Call stm32_caninitialize() to get an instance of the CAN interface */
|
||||
|
||||
ret = stm32_cansockinitialize(1);
|
||||
if (ret < 0)
|
||||
{
|
||||
canerr("ERROR: Failed to get CAN interface %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32F7_CAN2
|
||||
/* Call stm32_caninitialize() to get an instance of the CAN interface */
|
||||
|
||||
ret = stm32_cansockinitialize(2);
|
||||
if (ret < 0)
|
||||
{
|
||||
canerr("ERROR: Failed to get CAN interface %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user