From df1dce3738a08212393ad36cdce62155c1137887 Mon Sep 17 00:00:00 2001 From: Vincent Dupont Date: Mon, 6 Feb 2017 12:45:16 +0100 Subject: [PATCH] squash can_stm32: adapt to new auto-init system --- boards/nucleo-f091/Makefile.dep | 4 ++ boards/nucleo-f091/include/can_conf.h | 62 ------------------ boards/nucleo-f207/Makefile.dep | 4 ++ .../include/candev_stm32_params.h | 65 ++++++++++--------- sys/auto_init/can/auto_init_can.c | 5 ++ sys/auto_init/can/auto_init_can_stm32.c | 57 ++++++++++++++++ 6 files changed, 103 insertions(+), 94 deletions(-) delete mode 100644 boards/nucleo-f091/include/can_conf.h rename boards/nucleo-f207/include/can_conf.h => cpu/stm32_common/include/candev_stm32_params.h (50%) create mode 100644 sys/auto_init/can/auto_init_can_stm32.c diff --git a/boards/nucleo-f091/Makefile.dep b/boards/nucleo-f091/Makefile.dep index 76e2dc17b45c2..748425fdb61a1 100644 --- a/boards/nucleo-f091/Makefile.dep +++ b/boards/nucleo-f091/Makefile.dep @@ -1 +1,5 @@ +ifneq (,$(filter can,$(USEMODULE))) + CFLAGS += -DCAN_DLL_NUMOF=1 +endif + include $(RIOTBOARD)/nucleo-common/Makefile.dep diff --git a/boards/nucleo-f091/include/can_conf.h b/boards/nucleo-f091/include/can_conf.h deleted file mode 100644 index 761b2c9bc064d..0000000000000 --- a/boards/nucleo-f091/include/can_conf.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2016 OTA keys S.A. - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup boards_nucleo-f091 Nucleo-F091 - * @ingroup boards - * @brief Board specific files for the nucleo-f091 board - * @{ - * - * @file - * @brief CAN specific definitions for the nucleo-f091 board - * - * @author Vincent Dupont - */ - -#ifndef CAN_CONF_H -#define CAN_CONF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "can/config.h" - -#include "candev_stm32.h" - -const static candev_stm32_conf_t can_config_candev_stm32[] = { - { - .channel = CANDEV_STM32_CHANNEL_0, - .rx_pin = GPIO_PIN(PORT_A, 11), - .tx_pin = GPIO_PIN(PORT_A, 12), - .af = GPIO_AF4, - .irqn = CEC_CAN_IRQn, - .ttcm = 0, - .abom = 1, - .awum = 1, - .nart = 0, - .rflm = 0, - .txfp = 0, - }, -}; - -#define CANDEV_STM32_NUMOF (sizeof(can_config_candev_stm32) / sizeof(candev_stm32_conf_t)) -#define CAN_DLL_NUMOF CANDEV_STM32_NUMOF - -const static can_iface_t candev_ifnum[] = { - { CAN_DRIVER_STM32, 0 }, -}; - -#ifdef __cplusplus -} -#endif - -#endif /* CAN_CONF_H */ - -/** @} */ - diff --git a/boards/nucleo-f207/Makefile.dep b/boards/nucleo-f207/Makefile.dep index 76e2dc17b45c2..55b775e118298 100644 --- a/boards/nucleo-f207/Makefile.dep +++ b/boards/nucleo-f207/Makefile.dep @@ -1 +1,5 @@ +ifneq (,$(filter can,$(USEMODULE))) + CFLAGS += -DCAN_DLL_NUMOF=2 +endif + include $(RIOTBOARD)/nucleo-common/Makefile.dep diff --git a/boards/nucleo-f207/include/can_conf.h b/cpu/stm32_common/include/candev_stm32_params.h similarity index 50% rename from boards/nucleo-f207/include/can_conf.h rename to cpu/stm32_common/include/candev_stm32_params.h index 59f942c610dd9..108a6570d7543 100644 --- a/boards/nucleo-f207/include/can_conf.h +++ b/cpu/stm32_common/include/candev_stm32_params.h @@ -1,37 +1,37 @@ /* - * Copyright (C) 2016 OTA keys S.A. + * Copyright (C) 2016 OTA keys S.A. * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. */ /** - * @defgroup boards_nucleo-f207 Nucleo-F207 - * @ingroup boards - * @brief Board specific files for the nucleo-f207 board + * @ingroup cpu_stm32_common * @{ * * @file - * @brief CAN specific definitions for the nucleo-f207 board + * @brief STM32 CAN controller driver (bxCAN) default parameters * * @author Vincent Dupont + * @} */ -#ifndef CAN_CONF_H -#define CAN_CONF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "can/config.h" +#ifndef CANDEV_STM32_PARAMS_H +#define CANDEV_STM32_PARAMS_H +#include "can/device.h" #include "candev_stm32.h" -const static candev_stm32_conf_t can_config_candev_stm32[] = { +const static candev_stm32_conf_t candev_stm32_conf[] = { { .channel = CANDEV_STM32_CHANNEL_0, +#if defined(CPU_FAM_STM32F0) + .rx_pin = GPIO_PIN(PORT_A, 11), + .tx_pin = GPIO_PIN(PORT_A, 12), + .af = GPIO_AF4, + .irqn = CEC_CAN_IRQn, +#else .rx_pin = GPIO_PIN(PORT_D, 0), .tx_pin = GPIO_PIN(PORT_D, 1), .af = GPIO_AF9, @@ -39,6 +39,7 @@ const static candev_stm32_conf_t can_config_candev_stm32[] = { .rx0_irqn = CAN1_RX0_IRQn, .rx1_irqn = CAN1_RX1_IRQn, .sce_irqn = CAN1_SCE_IRQn, +#endif .ttcm = 0, .abom = 1, .awum = 1, @@ -46,6 +47,8 @@ const static candev_stm32_conf_t can_config_candev_stm32[] = { .rflm = 0, .txfp = 0, }, +#if (defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)) \ + && (CAN_DLL_NUMOF >= 2) { .channel = CANDEV_STM32_CHANNEL_1, .rx_pin = GPIO_PIN(PORT_B, 5), @@ -61,22 +64,20 @@ const static candev_stm32_conf_t can_config_candev_stm32[] = { .nart = 0, .rflm = 0, .txfp = 0, - } -}; - -#define CANDEV_STM32_NUMOF (sizeof(can_config_candev_stm32) / sizeof(candev_stm32_conf_t)) -#define CAN_DLL_NUMOF CANDEV_STM32_NUMOF - -const static can_iface_t candev_ifnum[] = { - { CAN_DRIVER_STM32, 0 }, - { CAN_DRIVER_STM32, 1 }, + }, +#endif }; -#ifdef __cplusplus -} +const static candev_params_t candev_stm32_params[] = { + { + .name = "can_stm32_0", + }, +#if (defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)) \ + && (CAN_DLL_NUMOF >= 2) + { + .name = "can_stm32_1", + } #endif +}; -#endif /* CAN_CONF_H */ - -/** @} */ - +#endif /* CANDEV_STM32_PARAMS_H */ diff --git a/sys/auto_init/can/auto_init_can.c b/sys/auto_init/can/auto_init_can.c index c5f9dfa1fcbe8..0c8cfe8d18696 100644 --- a/sys/auto_init/can/auto_init_can.c +++ b/sys/auto_init/can/auto_init_can.c @@ -53,4 +53,9 @@ void auto_init_candev(void) extern void auto_init_can_native(void); auto_init_can_native(); #endif + +#ifdef MODULE_CAN_STM32 + extern void auto_init_can_stm32(void); + auto_init_can_stm32(); +#endif } diff --git a/sys/auto_init/can/auto_init_can_stm32.c b/sys/auto_init/can/auto_init_can_stm32.c new file mode 100644 index 0000000000000..8b4214777f5f3 --- /dev/null +++ b/sys/auto_init/can/auto_init_can_stm32.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 OTA keys S.A. + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup auto_init + * @{ + * @file + * @brief initializes stm32 can device + * + * @author Vincent Dupont + * @} + */ + +#ifdef MODULE_CAN_STM32 +#include "can/device.h" +#include "candev_stm32_params.h" + +#define CANDEV_STM32_NUMOF ((sizeof(candev_stm32_params) / sizeof(candev_params_t))) + +#ifndef CANDEV_STM32_STACKSIZE +#define CANDEV_STM32_STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) +#endif + +#ifndef CANDEV_STM32_BASE_PRIORITY +#define CANDEV_STM32_BASE_PRIORITY (THREAD_PRIORITY_MAIN - CANDEV_STM32_NUMOF - 2) +#endif + +static candev_dev_t candev_dev_stm32[CANDEV_STM32_NUMOF]; +static char _can_stm32_stacks[CANDEV_STM32_NUMOF][CANDEV_STM32_STACKSIZE]; +static candev_stm32_t candev_stm32[CANDEV_STM32_NUMOF]; + +void auto_init_can_stm32(void) { + + for (size_t i = 0; i < CANDEV_STM32_NUMOF; i++) { + candev_stm32_init(&candev_stm32[i], &candev_stm32_conf[i]); + candev_dev_stm32[i].dev = (candev_t *)&candev_stm32[i]; + candev_dev_stm32[i].name = candev_stm32_params[i].name; +#ifdef MODULE_CAN_TRX + candev_dev_stm32[i].trx = candev_stm32_params[i].trx; +#endif +#ifdef MODULE_CAN_PM + candev_dev_stm32[i].rx_inactivity_timeout = candev_stm32_params[i].rx_inactivity_timeout; + candev_dev_stm32[i].tx_wakeup_timeout = candev_stm32_params[i].tx_wakeup_timeout; +#endif + + can_device_init(_can_stm32_stacks[i], CANDEV_STM32_STACKSIZE, CANDEV_STM32_BASE_PRIORITY + i, + candev_stm32_params[i].name, &candev_dev_stm32[i]); + } +} +#else +typedef int dont_be_pedantic; +#endif