boards/arm/stm32f7: move CAN init logic to a common directory

move CAN init logic to a common directory
This commit is contained in:
raiden00pl 2024-10-20 12:57:58 +02:00 committed by Xiang Xiao
parent 6657f2abb7
commit b606c17619
22 changed files with 105 additions and 408 deletions

View file

@ -1,5 +1,5 @@
/****************************************************************************
* boards/arm/stm32f7/nucleo-f746zg/src/stm32_cansock.c
* boards/arm/stm32f7/common/include/stm32_can_setup.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -18,66 +18,54 @@
*
****************************************************************************/
#ifndef __BOARDS_ARM_STM32F7_COMMON_INCLUDE_STM32_CAN_SETUP_H
#define __BOARDS_ARM_STM32F7_COMMON_INCLUDE_STM32_CAN_SETUP_H
/****************************************************************************
* 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
* Public Types
****************************************************************************/
/****************************************************************************
* Name: stm32_cansock_setup
*
* Description:
* Initialize CAN socket interface
*
* Public Data
****************************************************************************/
int stm32_cansock_setup(void)
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
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;
}
#else
#define EXTERN extern
#endif
#ifdef CONFIG_STM32F7_CAN2
/* Call stm32_caninitialize() to get an instance of the CAN interface */
/****************************************************************************
* Inline Functions
****************************************************************************/
ret = stm32_cansockinitialize(2);
if (ret < 0)
{
canerr("ERROR: Failed to get CAN interface %d\n", ret);
goto errout;
}
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: stm32_can_setup
****************************************************************************/
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
int stm32_can_setup(void);
#endif
errout:
return ret;
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __BOARDS_ARM_STM32F7_COMMON_INCLUDE_STM32_CAN_SETUP_H */

View file

@ -1,5 +1,5 @@
/****************************************************************************
* boards/arm/stm32f7/nucleo-f722ze/src/stm32_cansock.c
* boards/arm/stm32f7/common/include/stm32_cansock_setup.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -18,66 +18,54 @@
*
****************************************************************************/
#ifndef __BOARDS_ARM_STM32F7_COMMON_INCLUDE_STM32_CANSOCK_SETUP_H
#define __BOARDS_ARM_STM32F7_COMMON_INCLUDE_STM32_CANSOCK_SETUP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include "stm32_can.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
#if !defined(CONFIG_STM32F7_CAN1) && !defined(CONFIG_STM32F7_CAN2)
# error "No CAN is enable. Please eneable at least one CAN device"
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Functions
* Inline Functions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* 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;
}
#ifdef CONFIG_STM32F7_CAN_SOCKET
int stm32_cansock_setup(void);
#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;
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __BOARDS_ARM_STM32F7_COMMON_INCLUDE_STM32_CANSOCK_SETUP_H */

View file

@ -32,4 +32,13 @@ if(CONFIG_AUDIO_CS4344)
list(APPEND SRCS stm32_cs4344.c)
endif()
if(CONFIG_STM32F7_CAN)
if(CONFIG_STM32F7_CAN_CHARDRIVER)
list(APPEND SRCS stm32_can.c)
endif()
if(CONFIG_STM32F7_CAN_SOCKET)
list(APPEND SRCS stm32_cansock.c)
endif()
endif()
target_sources(board PRIVATE ${SRCS})

View file

@ -32,6 +32,15 @@ ifeq ($(CONFIG_AUDIO_CS4344),y)
CSRCS += stm32_cs4344.c
endif
ifeq ($(CONFIG_STM32F7_CAN),y)
ifeq ($(CONFIG_STM32F7_CAN_CHARDRIVER),y)
CSRCS += stm32_can_setup.c
endif
ifeq ($(CONFIG_STM32F7_CAN_SOCKET),y)
CSRCS += stm32_cansock_setup.c
endif
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

View file

@ -1,5 +1,5 @@
/****************************************************************************
* boards/arm/stm32f7/nucleo-f722ze/src/stm32_can.c
* boards/arm/stm32f7/common/src/stm32_can_setup.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -31,7 +31,6 @@
#include <nuttx/can/can.h>
#include "stm32_can.h"
#include "nucleo-f722ze.h"
#ifdef CONFIG_CAN

View file

@ -1,5 +1,5 @@
/****************************************************************************
* boards/arm/stm32f7/nucleo-f767zi/src/stm32_cansock.c
* boards/arm/stm32f7/common/src/stm32_cansock_setup.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with

View file

@ -8,6 +8,7 @@
# CONFIG_ARCH_FPU is not set
# CONFIG_STM32F7_USE_LEGACY_PINMAP is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD="nucleo-f722ze"
CONFIG_ARCH_BOARD_NUCLEO_F722ZE=y
CONFIG_ARCH_BUTTONS=y

View file

@ -10,6 +10,7 @@
# CONFIG_NET_IPv4 is not set
# CONFIG_STM32F7_USE_LEGACY_PINMAP is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD="nucleo-f722ze"
CONFIG_ARCH_BOARD_NUCLEO_F722ZE=y
CONFIG_ARCH_BUTTONS=y

View file

@ -76,15 +76,6 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
CSRCS += stm32_qencoder.c
endif
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
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
CSRCS += stm32_composite.c
endif

View file

@ -325,22 +325,6 @@ int stm32_bbsram_int(void);
int stm32_qencoder_initialize(const char *devpath, int timer);
#endif
/****************************************************************************
* Name: stm32_can_setup
****************************************************************************/
#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
****************************************************************************/

View file

@ -38,6 +38,14 @@
#include "stm32_i2c.h"
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
# include "stm32_can_setup.h"
#endif
#ifdef CONFIG_STM32F7_CAN_SOCKET
# include "stm32_cansock_setup.h"
#endif
#ifdef CONFIG_STM32_ROMFS
#include "stm32_romfs.h"
#endif

View file

@ -12,6 +12,7 @@ CONFIG_ADC=y
CONFIG_ADC_FIFOSIZE=16
CONFIG_ANALOG=y
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD="nucleo-f746zg"
CONFIG_ARCH_BOARD_NUCLEO_F746ZG=y
CONFIG_ARCH_BUTTONS=y

View file

@ -74,15 +74,6 @@ if(CONFIG_SENSORS_QENCODER)
list(APPEND SRCS stm32_qencoder.c)
endif()
if(CONFIG_STM32F7_CAN)
if(CONFIG_STM32F7_CAN_CHARDRIVER)
list(APPEND SRCS stm32_can.c)
endif()
if(CONFIG_STM32F7_CAN_SOCKET)
list(APPEND SRCS stm32_cansock.c)
endif()
endif()
if(CONFIG_USBDEV_COMPOSITE)
list(APPEND SRCS stm32_composite.c)
endif()

View file

@ -76,15 +76,6 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
CSRCS += stm32_qencoder.c
endif
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
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
CSRCS += stm32_composite.c
endif

View file

@ -325,22 +325,6 @@ int stm32_bbsram_int(void);
int stm32_qencoder_initialize(const char *devpath, int timer);
#endif
/****************************************************************************
* Name: stm32_can_setup
****************************************************************************/
#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
****************************************************************************/

View file

@ -38,6 +38,14 @@
#include "stm32_i2c.h"
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
# include "stm32_can_setup.h"
#endif
#ifdef CONFIG_STM32F7_CAN_SOCKET
# include "stm32_cansock_setup.h"
#endif
#ifdef CONFIG_STM32_ROMFS
#include "stm32_romfs.h"
#endif

View file

@ -1,115 +0,0 @@
/****************************************************************************
* boards/arm/stm32f7/nucleo-f746zg/src/stm32_can.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 <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/can/can.h>
#include "stm32_can.h"
#include "nucleo-f746zg.h"
#ifdef CONFIG_CAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_STM32F7_CAN1
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
int stm32_can_setup(void)
{
#if defined(CONFIG_STM32F7_CAN1)
struct can_dev_s *can;
int ret;
/* Call stm32f7can_initialize() to get an instance of the CAN interface */
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#endif
#if defined(CONFIG_STM32F7_CAN2)
struct can_dev_s *can;
int ret;
/* Call stm32f7can_initialize() to get an instance of the CAN interface */
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can1" */
ret = can_register("/dev/can1", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN */

View file

@ -74,15 +74,6 @@ if(CONFIG_SENSORS_QENCODER)
list(APPEND SRCS stm32_qencoder.c)
endif()
if(CONFIG_STM32F7_CAN)
if(CONFIG_STM32F7_CAN_CHARDRIVER)
list(APPEND SRCS stm32_can.c)
endif()
if(CONFIG_STM32F7_CAN_SOCKET)
list(APPEND SRCS stm32_cansock.c)
endif()
endif()
if(CONFIG_USBDEV_COMPOSITE)
list(APPEND SRCS stm32_composite.c)
endif()

View file

@ -76,15 +76,6 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
CSRCS += stm32_qencoder.c
endif
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
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
CSRCS += stm32_composite.c
endif

View file

@ -325,22 +325,6 @@ int stm32_bbsram_int(void);
int stm32_qencoder_initialize(const char *devpath, int timer);
#endif
/****************************************************************************
* Name: stm32_can_setup
****************************************************************************/
#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
****************************************************************************/

View file

@ -38,6 +38,14 @@
#include "stm32_i2c.h"
#ifdef CONFIG_STM32F7_CAN_CHARDRIVER
# include "stm32_can_setup.h"
#endif
#ifdef CONFIG_STM32F7_CAN_SOCKET
# include "stm32_cansock_setup.h"
#endif
#ifdef CONFIG_STM32_ROMFS
#include "stm32_romfs.h"
#endif

View file

@ -1,115 +0,0 @@
/****************************************************************************
* boards/arm/stm32f7/nucleo-f767zi/src/stm32_can.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 <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/can/can.h>
#include "stm32_can.h"
#include "nucleo-f767zi.h"
#ifdef CONFIG_CAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_STM32F7_CAN1
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
int stm32_can_setup(void)
{
#if defined(CONFIG_STM32F7_CAN1)
struct can_dev_s *can;
int ret;
/* Call stm32f7can_initialize() to get an instance of the CAN interface */
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#endif
#if defined(CONFIG_STM32F7_CAN2)
struct can_dev_s *can;
int ret;
/* Call stm32f7can_initialize() to get an instance of the CAN interface */
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can1" */
ret = can_register("/dev/can1", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN */