2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* boards/arm/stm32/stm3220g-eval/src/stm32_can.c
|
2012-03-10 01:15:45 +01:00
|
|
|
*
|
2021-03-19 12:39:00 +01:00
|
|
|
* 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
|
2012-03-10 01:15:45 +01:00
|
|
|
*
|
2021-03-19 12:39:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-03-10 01:15:45 +01:00
|
|
|
*
|
2021-03-19 12:39:00 +01:00
|
|
|
* 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.
|
2012-03-10 01:15:45 +01:00
|
|
|
*
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2012-03-10 01:15:45 +01:00
|
|
|
* Included Files
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2012-03-10 01:15:45 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2017-05-12 16:23:16 +02:00
|
|
|
#include <nuttx/can/can.h>
|
2012-03-10 01:15:45 +01:00
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
#include "chip.h"
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_arch.h"
|
2012-03-10 01:15:45 +01:00
|
|
|
|
|
|
|
#include "stm32.h"
|
|
|
|
#include "stm32_can.h"
|
2015-12-29 22:44:56 +01:00
|
|
|
#include "stm3220g-eval.h"
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
#ifdef CONFIG_CAN
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2012-03-10 01:15:45 +01:00
|
|
|
* Pre-processor Definitions
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2021-03-19 12:39:00 +01:00
|
|
|
|
|
|
|
/* Configuration ************************************************************/
|
2012-03-10 01:15:45 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_STM32_CAN1) && defined(CONFIG_STM32_CAN2)
|
|
|
|
# warning "Both CAN1 and CAN2 are enabled. Assuming only CAN1."
|
|
|
|
# undef CONFIG_STM32_CAN2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_CAN1
|
|
|
|
# define CAN_PORT 1
|
|
|
|
#else
|
|
|
|
# define CAN_PORT 2
|
|
|
|
#endif
|
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2012-03-10 01:15:45 +01:00
|
|
|
* Public Functions
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2016-12-06 15:51:37 +01:00
|
|
|
* Name: stm32_can_setup
|
2012-03-10 01:15:45 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-12-06 15:51:37 +01:00
|
|
|
* Initialize CAN and register the CAN device
|
2012-03-10 01:15:45 +01:00
|
|
|
*
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
int stm32_can_setup(void)
|
2012-03-10 01:15:45 +01:00
|
|
|
{
|
2016-12-06 15:51:37 +01:00
|
|
|
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
|
2012-03-10 01:15:45 +01:00
|
|
|
struct can_dev_s *can;
|
|
|
|
int ret;
|
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
/* Call stm32_caninitialize() to get an instance of the CAN interface */
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
can = stm32_caninitialize(CAN_PORT);
|
|
|
|
if (can == NULL)
|
2012-03-10 01:15:45 +01:00
|
|
|
{
|
2016-12-06 15:51:37 +01:00
|
|
|
canerr("ERROR: Failed to get CAN interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
/* Register the CAN driver at "/dev/can0" */
|
2012-03-10 01:15:45 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
ret = can_register("/dev/can0", can);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
canerr("ERROR: can_register failed: %d\n", ret);
|
|
|
|
return ret;
|
2012-03-10 01:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2016-12-06 15:51:37 +01:00
|
|
|
#else
|
|
|
|
return -ENODEV;
|
|
|
|
#endif
|
2012-03-10 01:15:45 +01:00
|
|
|
}
|
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
#endif /* CONFIG_CAN */
|