boards/nucleo-g431rb: add CAN example

This commit is contained in:
raiden00pl 2022-01-15 13:56:50 +01:00 committed by Xiang Xiao
parent 499c7ce4f5
commit 4e1df81fa8
6 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,58 @@
#
# 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_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS 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=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BOARD_NUCLEO_G431RB_USE_HSE=y
CONFIG_BUILTIN=y
CONFIG_CAN=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_INTELHEX_BINARY=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=22528
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=10
CONFIG_START_YEAR=2014
CONFIG_STDIO_BUFFER_SIZE=512
CONFIG_STM32_FDCAN1=y
CONFIG_STM32_FDCAN1_BITRATE=250000
CONFIG_STM32_FDCAN1_NTSEG1=13
CONFIG_STM32_FDCAN1_NTSEG2=2
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_USART2=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USART2_SERIAL_CONSOLE=y

View File

@ -247,6 +247,15 @@
#define BOARD_TIM17_FREQUENCY (STM32_PCLK2_FREQUENCY)
#define BOARD_TIM20_FREQUENCY (STM32_PCLK2_FREQUENCY)
#ifdef CONFIG_STM32_FDCAN
# ifdef CONFIG_BOARD_NUCLEO_G431RB_USE_HSE
# define STM32_CCIPR_FDCANSRC (RCC_CCIPR_FDCANSEL_HSE)
# define STM32_FDCAN_FREQUENCY (STM32_HSE_FREQUENCY)
# else
# error For now FDCAN supported only if HSE enabled
# endif
#endif
/* LED definitions **********************************************************/
/* The NUCLEO-G431RB has four user LEDs.
@ -329,6 +338,11 @@
#define GPIO_TIM1_CH3NOUT GPIO_TIM1_CH3NOUT_1 /* PB1 */
#define GPIO_TIM1_CH4OUT GPIO_TIM1_CH4OUT_2 /* PC3 */
/* CAN configuration ********************************************************/
#define GPIO_FDCAN1_RX GPIO_FDCAN1_RX_2 /* PB8 */
#define GPIO_FDCAN1_TX GPIO_FDCAN1_TX_2 /* PB9 */
/* DMA channels *************************************************************/
/* ADC */

View File

@ -55,6 +55,10 @@ ifeq ($(CONFIG_MATH_CORDIC),y)
CSRCS += stm32_cordic.c
endif
ifeq ($(CONFIG_STM32_FDCAN_CHARDRIVER),y)
CSRCS += stm32_can.c
endif
DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)

View File

@ -155,4 +155,16 @@ int stm32_foc_setup(void);
int stm32_cordic_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_STM32_FDCAN_CHARDRIVER
int stm32_can_setup(void);
#endif
#endif /* __BOARDS_ARM_STM32_NUCLEO_G431RB_SRC_NUCLEO_G431RB_H */

View File

@ -149,6 +149,16 @@ int stm32_bringup(void)
}
#endif
#ifdef CONFIG_STM32_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
UNUSED(ret);
return OK;
}

View File

@ -0,0 +1,90 @@
/****************************************************************************
* boards/arm/stm32/nucleo-g431rb/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 <errno.h>
#include <debug.h>
#include <nuttx/can/can.h>
#include <arch/board/board.h>
#include "chip.h"
#include "arm_arch.h"
#include "stm32.h"
#include "stm32_fdcan.h"
#include "nucleo-g431rb.h"
#ifdef CONFIG_CAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#if !defined(CONFIG_STM32_FDCAN1)
# error "No CAN is enable. Please eneable at least one CAN device"
#endif
/****************************************************************************
* 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;
/* 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;
}
#endif /* CONFIG_CAN */