boards/arm/stm32/nucleo-f446re: added support for CAN driver
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
parent
65a7ecec09
commit
d889350822
@ -549,3 +549,12 @@ Configurations
|
||||
Pin 33 PA10 USART1_TX some RS-232 converters
|
||||
Pin 20 GND
|
||||
Pin 8 U5V
|
||||
|
||||
can:
|
||||
----
|
||||
This is basically an nsh configuration (see above) with added support
|
||||
for CAN driver. Both CAN 1 (RX: PB_8, TX: PB_9) and CAN 2 (RX: PB_5, TX: PB_6)
|
||||
are turn on.
|
||||
|
||||
Functionality of CAN driver can be tested by calling application
|
||||
"can" in NuttShell. This application sends 100 messages over CAN 1.
|
||||
|
61
boards/arm/stm32/nucleo-f446re/configs/can/defconfig
Normal file
61
boards/arm/stm32/nucleo-f446re/configs/can/defconfig
Normal file
@ -0,0 +1,61 @@
|
||||
#
|
||||
# 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_STM32_FLASH_PREFETCH is not set
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-f446re"
|
||||
CONFIG_ARCH_BOARD_NUCLEO_F446RE=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32"
|
||||
CONFIG_ARCH_CHIP_STM32=y
|
||||
CONFIG_ARCH_CHIP_STM32F446R=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=8499
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_EXAMPLES_CAN=y
|
||||
CONFIG_EXAMPLES_CAN_NMSGS=100
|
||||
CONFIG_EXAMPLES_CAN_WRITE=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_NFILE_DESCRIPTORS=8
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=131072
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_START_DAY=14
|
||||
CONFIG_START_MONTH=10
|
||||
CONFIG_START_YEAR=2014
|
||||
CONFIG_STM32_CAN1=y
|
||||
CONFIG_STM32_CAN2=y
|
||||
CONFIG_STM32_CRC=y
|
||||
CONFIG_STM32_JTAG_SW_ENABLE=y
|
||||
CONFIG_STM32_OTGFS=y
|
||||
CONFIG_STM32_PWR=y
|
||||
CONFIG_STM32_USART2=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=0
|
||||
CONFIG_TESTING_OSTEST=y
|
||||
CONFIG_USART2_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -46,16 +46,13 @@
|
||||
#endif
|
||||
|
||||
#include <stm32.h>
|
||||
#include <arch/board/nucleo-f446re.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Clocking *******************************************************************/
|
||||
|
||||
#include <arch/board/nucleo-f446re.h>
|
||||
|
||||
/* DMA Channel/Stream Selections **********************************************/
|
||||
/* DMA Channel/Stream Selections ********************************************/
|
||||
|
||||
/* Stream selections are arbitrary for now but might become important in the
|
||||
* future is we set aside more DMA channels/streams.
|
||||
@ -74,7 +71,7 @@
|
||||
#define DMACHAN_SPI2_RX DMAMAP_SPI2_RX
|
||||
#define DMACHAN_SPI2_TX DMAMAP_SPI2_TX
|
||||
|
||||
/* Alternate function pin selections ******************************************/
|
||||
/* Alternate function pin selections ****************************************/
|
||||
|
||||
/* USART1:
|
||||
* RXD: PA10 CN9 pin 3, CN10 pin 33
|
||||
@ -156,6 +153,14 @@
|
||||
#define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_1
|
||||
#define GPIO_SPI2_SCK GPIO_SPI2_SCK_2
|
||||
|
||||
/* CAN */
|
||||
|
||||
#define GPIO_CAN1_RX GPIO_CAN1_RX_2
|
||||
#define GPIO_CAN1_TX GPIO_CAN1_TX_2
|
||||
|
||||
#define GPIO_CAN2_RX GPIO_CAN2_RX_2
|
||||
#define GPIO_CAN2_TX GPIO_CAN2_TX_2
|
||||
|
||||
/* LEDs
|
||||
*
|
||||
* The Nucleo F446RE and F411RE boards provide a single user LED, LD2. LD2
|
||||
@ -208,8 +213,8 @@
|
||||
|
||||
/* Buttons
|
||||
*
|
||||
* B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32
|
||||
* microcontroller.
|
||||
* B1 USER: the user button is connected to the I/O PC13 (pin 2) of
|
||||
* the STM32 microcontroller.
|
||||
*/
|
||||
|
||||
#define BUTTON_USER 0
|
||||
|
@ -39,6 +39,10 @@ CSRCS += stm32_ajoystick.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CAN),y)
|
||||
CSRCS += stm32_can.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NSH_LIBRARY),y)
|
||||
CSRCS += stm32_appinit.c
|
||||
endif
|
||||
|
@ -260,6 +260,18 @@ void stm32_usbinitialize(void);
|
||||
int stm32_adc_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_can_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize CAN and register the CAN device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_CAN
|
||||
int stm32_can_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_ajoy_initialize
|
||||
*
|
||||
|
@ -133,6 +133,16 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CAN
|
||||
/* Initialize CAN and register the CAN driver. */
|
||||
|
||||
ret = stm32_can_setup();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
|
@ -85,8 +85,8 @@ void stm32_boardinitialize(void)
|
||||
|
||||
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
|
||||
/* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not
|
||||
* disabled, and 3) the weak function stm32_usbinitialize() has been brought
|
||||
* into the build.
|
||||
* disabled, and 3) the weak function stm32_usbinitialize() has been
|
||||
* broughtvinto the build.
|
||||
*/
|
||||
|
||||
stm32_usbinitialize();
|
||||
@ -111,12 +111,10 @@ void stm32_boardinitialize(void)
|
||||
void board_late_initialize(void)
|
||||
{
|
||||
/* Perform NSH initialization here instead of from the NSH. This
|
||||
* alternative NSH initialization is necessary when NSH is ran in user-space
|
||||
* but the initialization function must run in kernel space.
|
||||
* alternative NSH initialization is necessary when NSH is ran in
|
||||
* user-space but the initialization function must run in kernel space.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_LIB_BOARDCTL)
|
||||
board_app_initialize(0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
116
boards/arm/stm32/nucleo-f446re/src/stm32_can.c
Normal file
116
boards/arm/stm32/nucleo-f446re/src/stm32_can.c
Normal file
@ -0,0 +1,116 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/nucleo-f446re/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_can.h"
|
||||
#include "nucleo-f446re.h"
|
||||
|
||||
#ifdef CONFIG_CAN
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#if !defined(CONFIG_STM32_CAN1) && !defined(CONFIG_STM32_CAN2)
|
||||
# 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;
|
||||
|
||||
#ifdef CONFIG_STM32_CAN1
|
||||
|
||||
/* Call stm32_caninitialize() to get an instance of the CAN interface */
|
||||
|
||||
can = stm32_caninitialize(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;
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef CONFIG_STM32_CAN2
|
||||
|
||||
/* Call stm32_caninitialize() to get an instance of the CAN interface */
|
||||
|
||||
can = stm32_caninitialize(2);
|
||||
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;
|
||||
}
|
||||
|
||||
#endif
|
||||
UNUSED(ret);
|
||||
UNUSED(can);
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_CAN */
|
Loading…
Reference in New Issue
Block a user