boards/b-g431b-esc1: add CAN example
This commit is contained in:
parent
d3841eb753
commit
499c7ce4f5
@ -29,4 +29,8 @@ config BOARD_STM32_BG431BESC1_FOC_POT
|
||||
|
||||
endif # STM32_FOC
|
||||
|
||||
config BOARD_STM32_BG431BESC1_CANTERM
|
||||
bool "B-G431B-ESC1 use on-board CAN terminator resistor"
|
||||
default y
|
||||
|
||||
endif # ARCH_BOARD_B_G431B_ESC1
|
||||
|
@ -48,6 +48,9 @@ Configuration Sub-directories
|
||||
ENCO_Z/HALL_H3 TIM4_CH3 PB8
|
||||
BUTTON GPIO_PC10 PC10
|
||||
PWM PA15
|
||||
CAN_RX PA11
|
||||
CAN_TX PB9
|
||||
CAN_TERM PC14
|
||||
|
||||
Current shunt resistance = 0.003
|
||||
PGA gain = 16
|
||||
|
57
boards/arm/stm32/b-g431b-esc1/configs/can/defconfig
Normal file
57
boards/arm/stm32/b-g431b-esc1/configs/can/defconfig
Normal file
@ -0,0 +1,57 @@
|
||||
#
|
||||
# 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="b-g431b-esc1"
|
||||
CONFIG_ARCH_BOARD_B_G431B_ESC1=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32"
|
||||
CONFIG_ARCH_CHIP_STM32=y
|
||||
CONFIG_ARCH_CHIP_STM32G431C=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=8499
|
||||
CONFIG_BOARD_STM32_BG431BESC1_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_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
|
@ -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_STM32_BG431BESC1_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 B-G431B-ESC1 has four user LEDs.
|
||||
@ -333,4 +342,9 @@
|
||||
#define DMACHAN_USART2_TX DMAMAP_DMA12_USART2TX_0 /* DMA1 */
|
||||
#define DMACHAN_USART2_RX DMAMAP_DMA12_USART2RX_0 /* DMA1 */
|
||||
|
||||
/* CAN configuration ********************************************************/
|
||||
|
||||
#define GPIO_FDCAN1_RX GPIO_FDCAN1_RX_1 /* PA11 */
|
||||
#define GPIO_FDCAN1_TX GPIO_FDCAN1_TX_2 /* PB9 */
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_B_G431B_ESC1_INCLUDE_BOARD_H */
|
||||
|
@ -41,6 +41,10 @@ ifeq ($(CONFIG_STM32_FOC),y)
|
||||
CSRCS += stm32_foc.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)
|
||||
|
@ -88,6 +88,11 @@
|
||||
GPIO_PORTB | GPIO_PIN8)
|
||||
#endif
|
||||
|
||||
/* CAN_TERM - PC14 */
|
||||
|
||||
#define GPIO_CANTERM (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN14)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@ -140,4 +145,16 @@ int stm32_adc_setup(void);
|
||||
int stm32_foc_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_B_G431B_ESC1_SRC_B_G431B_ESC1_H */
|
||||
|
@ -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;
|
||||
}
|
||||
|
104
boards/arm/stm32/b-g431b-esc1/src/stm32_can.c
Normal file
104
boards/arm/stm32/b-g431b-esc1/src/stm32_can.c
Normal file
@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/b-g431b-esc1/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 "b-g431b-esc1.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
|
||||
|
||||
#ifdef CONFIG_BOARD_STM32_BG431BESC1_CANTERM
|
||||
# define BG431BESC1_CANTERM (true)
|
||||
#else
|
||||
# define BG431BESC1_CANTERM (false)
|
||||
#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;
|
||||
}
|
||||
|
||||
/* Configure CAN_TERM pin for output */
|
||||
|
||||
stm32_configgpio(GPIO_CANTERM);
|
||||
|
||||
/* Set CAN_TERM pin high or low */
|
||||
|
||||
stm32_gpiowrite(GPIO_CANTERM, BG431BESC1_CANTERM);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_CAN */
|
Loading…
x
Reference in New Issue
Block a user