mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 21:34:07 +08:00
boards/nucleo-c092rc: add FDCAN examples
add FDCAN examples for nucleo-c092rc based on SocketCAN interface and CAN character driver interface. Signed-off-by: raiden00pl <raiden00@railab.me>
This commit is contained in:
committed by
Alan C. Assis
parent
ba00fa6478
commit
13fba11e9b
@@ -44,3 +44,15 @@ Enabled features:
|
||||
- ADC with DMA enabled using A0 and A1 pins
|
||||
|
||||
- button with software debouncing enabled (no RC filter on the board)
|
||||
|
||||
can
|
||||
---
|
||||
|
||||
Configuration with FDCAN enabled as character driver and
|
||||
``examples/can`` included as builtin application.
|
||||
|
||||
cansock
|
||||
-------
|
||||
|
||||
Configuration with FDCAN enabled as SocketCAN interface with ``candump``
|
||||
and ``cansend`` utils included as builtin applications.
|
||||
|
||||
@@ -40,7 +40,7 @@ WWDG Yes
|
||||
I2C Yes
|
||||
USART Yes
|
||||
SPI Yes
|
||||
FDCAN No
|
||||
FDCAN Yes
|
||||
USB No
|
||||
========== ======= =====
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#
|
||||
# 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_STM32F0G0L0_USE_LEGACY_PINMAP is not set
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-c092rc"
|
||||
CONFIG_ARCH_BOARD_NUCLEO_C092RC=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32f0l0g0"
|
||||
CONFIG_ARCH_CHIP_STM32C092RC=y
|
||||
CONFIG_ARCH_CHIP_STM32C092XX=y
|
||||
CONFIG_ARCH_CHIP_STM32C0=y
|
||||
CONFIG_ARCH_IRQBUTTONS=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=3997
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_CAN_ERRORS=y
|
||||
CONFIG_CAN_EXTID=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_EXAMPLES_CAN=y
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=1536
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LINE_MAX=64
|
||||
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=1536
|
||||
CONFIG_PTHREAD_MUTEX_UNSAFE=y
|
||||
CONFIG_PTHREAD_STACK_DEFAULT=1536
|
||||
CONFIG_RAM_SIZE=30720
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_START_DAY=19
|
||||
CONFIG_START_MONTH=5
|
||||
CONFIG_START_YEAR=2013
|
||||
CONFIG_STDIO_DISABLE_BUFFERING=y
|
||||
CONFIG_STM32F0L0G0_FDCAN1=y
|
||||
CONFIG_STM32F0L0G0_FDCAN1_BITRATE=250000
|
||||
CONFIG_STM32F0L0G0_FDCAN1_NTSEG1=143
|
||||
CONFIG_STM32F0L0G0_FDCAN1_NTSEG2=48
|
||||
CONFIG_STM32F0L0G0_USART2=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_USART2_SERIAL_CONSOLE=y
|
||||
@@ -0,0 +1,59 @@
|
||||
#
|
||||
# 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_STM32F0G0L0_USE_LEGACY_PINMAP is not set
|
||||
CONFIG_ALLOW_BSD_COMPONENTS=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-c092rc"
|
||||
CONFIG_ARCH_BOARD_NUCLEO_C092RC=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32f0l0g0"
|
||||
CONFIG_ARCH_CHIP_STM32C092RC=y
|
||||
CONFIG_ARCH_CHIP_STM32C092XX=y
|
||||
CONFIG_ARCH_CHIP_STM32C0=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=1024
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=3997
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_CANUTILS_CANDUMP=y
|
||||
CONFIG_CANUTILS_CANSEND=y
|
||||
CONFIG_CANUTILS_LIBCANUTILS=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_IOB_BUFSIZE=128
|
||||
CONFIG_IOB_NBUFFERS=10
|
||||
CONFIG_LINE_MAX=64
|
||||
CONFIG_NET=y
|
||||
CONFIG_NETDEV_IFINDEX=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NET_CAN=y
|
||||
CONFIG_NET_SOCKOPTS=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_RAM_SIZE=30720
|
||||
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_STM32F0L0G0_FDCAN1=y
|
||||
CONFIG_STM32F0L0G0_FDCAN1_BITRATE=250000
|
||||
CONFIG_STM32F0L0G0_FDCAN1_NTSEG1=143
|
||||
CONFIG_STM32F0L0G0_FDCAN1_NTSEG2=48
|
||||
CONFIG_STM32F0L0G0_FDCAN_SOCKET=y
|
||||
CONFIG_STM32F0L0G0_USART2=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_USART2_SERIAL_CONSOLE=y
|
||||
@@ -72,6 +72,11 @@
|
||||
#define STM32_RCC_CFGR_PPRE RCC_CFGR_PPRE_HCLK
|
||||
#define STM32_PCLK1_FREQUENCY STM32_HCLK_FREQUENCY
|
||||
|
||||
/* FDCAN1 clock is PCLK (48 MHz) */
|
||||
|
||||
#define STM32_FDCAN1_SEL RCC_CCIPR1_FDCAN1SEL_PCLK
|
||||
#define STM32_FDCAN_FREQUENCY STM32_PCLK1_FREQUENCY
|
||||
|
||||
/* LED definitions **********************************************************/
|
||||
|
||||
/* LED index values for use with board_userled() */
|
||||
@@ -153,6 +158,11 @@
|
||||
#define GPIO_USART2_RX (GPIO_USART2_RX_1|GPIO_SPEED_HIGH) /* PA3 */
|
||||
#define GPIO_USART2_TX (GPIO_USART2_TX_1|GPIO_SPEED_HIGH) /* PA2 */
|
||||
|
||||
/* FDCAN */
|
||||
|
||||
#define GPIO_FDCAN1_RX (GPIO_FDCAN1_RX_8|GPIO_SPEED_HIGH) /* PD0 */
|
||||
#define GPIO_FDCAN1_TX (GPIO_FDCAN1_TX_9|GPIO_SPEED_HIGH) /* PD1 */
|
||||
|
||||
/* DMA channels *************************************************************/
|
||||
|
||||
/* ADC */
|
||||
|
||||
@@ -40,6 +40,15 @@ if(CONFIG_ADC)
|
||||
list(APPEND SRCS stm32_adc.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_STM32F0L0G0_FDCAN)
|
||||
if(CONFIG_STM32F0L0G0_FDCAN_CHARDRIVER)
|
||||
list(APPEND SRCS stm32_can.c)
|
||||
endif()
|
||||
if(CONFIG_STM32F0L0G0_FDCAN_SOCKET)
|
||||
list(APPEND SRCS stm32_cansock.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
|
||||
|
||||
@@ -42,6 +42,15 @@ ifeq ($(CONFIG_ADC),y)
|
||||
CSRCS += stm32_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32F0L0G0_FDCAN),y)
|
||||
ifeq ($(CONFIG_STM32F0L0G0_FDCAN_CHARDRIVER),y)
|
||||
CSRCS += stm32_can.c
|
||||
endif
|
||||
ifeq ($(CONFIG_STM32F0L0G0_FDCAN_SOCKET),y)
|
||||
CSRCS += stm32_cansock.c
|
||||
endif
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path board
|
||||
VPATH += :board
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
|
||||
|
||||
@@ -62,6 +62,13 @@
|
||||
#define GPIO_BTN_USER (GPIO_INPUT | GPIO_PULLUP | GPIO_EXTI | \
|
||||
GPIO_PORTC | GPIO_PIN13)
|
||||
|
||||
/* FDCAN:
|
||||
* MCP2562FDT STBY - PD2
|
||||
*/
|
||||
|
||||
#define GPIO_FDCAN_STBY (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_MEDIUM | \
|
||||
GPIO_OUTPUT_SET | GPIO_PORTD | GPIO_PIN2)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -104,5 +111,29 @@ int stm32_bringup(void);
|
||||
int stm32_adc_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_can_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize CAN and register the CAN device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32F0L0G0_FDCAN_CHARDRIVER
|
||||
int stm32_can_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_cansock_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize CAN socket interface
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32F0L0G0_FDCAN_SOCKET
|
||||
int stm32_cansock_setup(void);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_ARM_STM32F0L0G0_NUCLEO_C092RC_SRC_NUCLEO_C092RC_H */
|
||||
|
||||
@@ -109,6 +109,26 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32F0L0G0_FDCAN_CHARDRIVER
|
||||
/* Initialize CAN and register the CAN driver. */
|
||||
|
||||
ret = stm32_can_setup();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_fdcan_setup failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32F0L0G0_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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32f0l0g0/nucleo-c092rc/src/stm32_can.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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"
|
||||
#include "nucleo-c092rc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_can_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize CAN and register the CAN device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_can_setup(void)
|
||||
{
|
||||
struct can_dev_s *can;
|
||||
int ret;
|
||||
|
||||
/* Configure STBY pin for output */
|
||||
|
||||
stm32_configgpio(GPIO_FDCAN_STBY);
|
||||
|
||||
/* Set STBY pin low */
|
||||
|
||||
stm32_gpiowrite(GPIO_FDCAN_STBY, false);
|
||||
|
||||
/* Call stm32_fdcaninitialize() to get an instance of the CAN interface */
|
||||
|
||||
can = stm32_fdcaninitialize(1);
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32f0l0g0/nucleo-c092rc/src/stm32_cansock.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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"
|
||||
#include "nucleo-c092rc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_cansock_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize CAN socket interface
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_cansock_setup(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Configure STBY pin for output */
|
||||
|
||||
stm32_configgpio(GPIO_FDCAN_STBY);
|
||||
|
||||
/* Set STBY pin low */
|
||||
|
||||
stm32_gpiowrite(GPIO_FDCAN_STBY, false);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user