RIOT-OS / RIOT

RIOT - The friendly OS for IoT
https://riot-os.org
GNU Lesser General Public License v2.1
4.96k stars 1.99k forks source link

STM32L4: CAN support #13258

Closed Ciusss89 closed 4 years ago

Ciusss89 commented 4 years ago

Description

I'm trying to use a Nucleo-l476rg with CAN transceiver MCP2551:

TODO:

  1. Add the missing feature to the board profile:

    diff --git a/boards/nucleo-l476rg/Makefile.features b/boards/nucleo-l476rg/Makefile.features
    index b61dd0e29b48..eb91dc27bc15 100644
    --- a/boards/nucleo-l476rg/Makefile.features
    +++ b/boards/nucleo-l476rg/Makefile.features
    @@ -3,6 +3,7 @@ CPU_MODEL = stm32l476rg
    
    # Put defined MCU peripherals here (in alphabetical order)
    FEATURES_PROVIDED += periph_adc
    +FEATURES_PROVIDED += periph_can
    FEATURES_PROVIDED += periph_dma
    FEATURES_PROVIDED += periph_i2c
    FEATURES_PROVIDED += periph_pwm
  2. Set the the ch number:
    ~/mcu/RIOT (2020.01-branch) $ git diff cpu/stm32_common/include/candev_stm32.h
    diff --git a/cpu/stm32_common/include/candev_stm32.h b/cpu/stm32_common/include/candev_stm32.h
    index 5a277c799076..3acd738431b8 100644
    --- a/cpu/stm32_common/include/candev_stm32.h
    +++ b/cpu/stm32_common/include/candev_stm32.h
    @@ -41,7 +41,7 @@ extern "C" {
    #define CANDEV_STM32_CHAN_NUMOF 3
    #elif defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)
    #define CANDEV_STM32_CHAN_NUMOF 2
    -#elif defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3) || DOXYGEN
    +#elif defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3) || defined(CPU_FAM_STM32L4) || DOXYGEN
    /** Number of channels in the device (up to 3) */
    #define CANDEV_STM32_CHAN_NUMOF 1
  3. Makefile:
## App name
#
APPLICATION = gtip-test-can

## Target
#
BOARD ?= nucleo-l476rg #nucleo-f413zh #nucleo-l476rg

## This has to be the absolute path to the RIOT base directory:
#
RIOTBASE ?= $(CURDIR)/../../RIOT/

## Chose the debug level: LOG_NONE, LOG_WARNING, LOG_ERROR, LOG_DEBUG, LOG_ALL
CFLAGS += -DLOG_LEVEL=LOG_DEBUG

CFLAGS += -DDEVELHELP

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

# Modules to include:
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps

USEMODULE += conn_can
USEMODULE += can_isotp
USEMODULE += conn_can_isotp_multi
USEMODULE += can_pm
USEMODULE += can_trx

FEATURES_REQUIRED += periph_can
FEATURES_REQUIRED += periph_gpio_irq

CFLAGS += -DGNRC_PKTBUF_SIZE=4096
CFLAGS += -DCAN_PKT_BUF_SIZE=64
CFLAGS += -DCAN_ROUTER_MAX_FILTER=32

CFLAGS += -I$(CURDIR)
include $(RIOTBASE)/Makefile.include
  1. Iusse log:
    
    ~/mcu/gtip-riotos/test_04 (master) $ make clean all
    Building application "gtip-test-can" for "nucleo-l476rg" with MCU "stm32l4".

"make" -C /home/giuseppe/mcu/RIOT/boards/nucleo-l476rg "make" -C /home/giuseppe/mcu/RIOT/boards/common/nucleo "make" -C /home/giuseppe/mcu/RIOT/core "make" -C /home/giuseppe/mcu/RIOT/cpu/stm32l4 "make" -C /home/giuseppe/mcu/RIOT/cpu/cortexm_common "make" -C /home/giuseppe/mcu/RIOT/cpu/cortexm_common/periph "make" -C /home/giuseppe/mcu/RIOT/cpu/stm32_common "make" -C /home/giuseppe/mcu/RIOT/cpu/stm32_common/periph "make" -C /home/giuseppe/mcu/RIOT/cpu/stm32l4/periph "make" -C /home/giuseppe/mcu/RIOT/drivers "make" -C /home/giuseppe/mcu/RIOT/drivers/can_trx "make" -C /home/giuseppe/mcu/RIOT/drivers/periph_common "make" -C /home/giuseppe/mcu/RIOT/sys "make" -C /home/giuseppe/mcu/RIOT/sys/auto_init "make" -C /home/giuseppe/mcu/RIOT/sys/auto_init/can In file included from /home/giuseppe/mcu/RIOT/sys/auto_init/can/auto_init_periph_can.c:21: /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:42:21: error: 'RCC_APB1ENR_CAN1EN' undeclared here (not in a function); did you mean 'RCC_APB1ENR1_CAN1EN'? 42 | .rcc_mask = RCC_APB1ENR_CAN1EN, | ^~~~~~ | RCC_APB1ENR1_CAN1EN /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:43:10: error: 'can_conf_t' {aka 'const struct '} has no member named 'can_master' 43 | .can_master = CAN1, | ^~~~~~ In file included from /home/giuseppe/mcu/RIOT/cpu/stm32l4/include/cpu_conf.h:31, from /home/giuseppe/mcu/RIOT/core/include/thread.h:125, from /home/giuseppe/mcu/RIOT/sys/include/can/common.h:37, from /home/giuseppe/mcu/RIOT/drivers/include/can/candev.h:35, from /home/giuseppe/mcu/RIOT/sys/include/can/device.h:27, from /home/giuseppe/mcu/RIOT/sys/auto_init/can/auto_init_periph_can.c:20: /home/giuseppe/mcu/RIOT/cpu/stm32l4/include/vendor/stm32l476xx.h:1350:29: error: initialization of 'long unsigned int' from 'CAN_TypeDef ' {aka 'struct '} makes integer from pointer without a cast [-Werror=int-conversion] 1350 | #define CAN1 ((CAN_TypeDef ) CAN1_BASE) | ^ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:43:23: note: in expansion of macro 'CAN1' 43 | .can_master = CAN1, | ^~~~ /home/giuseppe/mcu/RIOT/cpu/stm32l4/include/vendor/stm32l476xx.h:1350:29: note: (near initialization for 'candev_conf[0].rx_pin') 1350 | #define CAN1 ((CAN_TypeDef ) CAN1_BASE) | ^ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:43:23: note: in expansion of macro 'CAN1' 43 | .can_master = CAN1, | ^~~~ In file included from /home/giuseppe/mcu/RIOT/sys/auto_init/can/auto_init_periph_can.c:21: /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:44:10: error: 'can_conf_t' {aka 'const struct '} has no member named 'master_rcc_mask' 44 | .master_rcc_mask = RCC_APB1ENR_CAN1EN, | ^~~~~~~ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:45:10: error: 'can_conf_t' {aka 'const struct '} has no member named 'first_filter' 45 | .first_filter = 0, | ^~~~ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:46:10: error: 'can_conf_t' {aka 'const struct '} has no member named 'nb_filters' 46 | .nb_filters = 14, | ^~~~~~ In file included from /home/giuseppe/mcu/RIOT/cpu/stm32l4/include/periph_cpu.h:23, from /home/giuseppe/mcu/RIOT/boards/nucleo-l476rg/include/periph_conf.h:26, from /home/giuseppe/mcu/RIOT/boards/common/nucleo/include/board_nucleo.h:25, from /home/giuseppe/mcu/RIOT/boards/common/nucleo64/include/board.h:25, from /home/giuseppe/mcu/RIOT/sys/include/xtimer.h:41, from /home/giuseppe/mcu/RIOT/sys/include/can/device.h:31, from /home/giuseppe/mcu/RIOT/sys/auto_init/can/auto_init_periph_can.c:20: /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/periph_cpu_common.h:161:29: error: initialized field overwritten [-Werror=override-init] 161 | #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) | ^ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:48:19: note: in expansion of macro 'GPIO_PIN' 48 | .rx_pin = GPIO_PIN(PORT_D, 0), | ^~~~ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/periph_cpu_common.h:161:29: note: (near initialization for 'candev_conf[0].rx_pin') 161 | #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) | ^ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:48:19: note: in expansion of macro 'GPIO_PIN' 48 | .rx_pin = GPIO_PIN(PORT_D, 0), | ^~~~ In file included from /home/giuseppe/mcu/RIOT/sys/auto_init/can/auto_init_periph_can.c:21: /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:50:15: error: initialized field overwritten [-Werror=override-init] 50 | .af = GPIO_AF9, | ^~~~ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:50:15: note: (near initialization for 'candev_conf[0].af') /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:55:20: error: initialized field overwritten [-Werror=override-init] 55 | .tx_irqn = CAN1_TX_IRQn, | ^~~~ /home/giuseppe/mcu/RIOT/cpu/stm32_common/include/can_params.h:55:20: note: (near initialization for 'candev_conf[0].tx_irqn') cc1: all warnings being treated as errors make[4]: [/home/giuseppe/mcu/RIOT/Makefile.base:109: /home/giuseppe/mcu/gtip-riotos/test_04/bin/nucleo-l476rg/auto_init_can/auto_init_periph_can.o] Error 1 make[3]: [/home/giuseppe/mcu/RIOT/Makefile.base:29: ALL--/home/giuseppe/mcu/RIOT/sys/auto_init/can] Error 2 make[2]: [/home/giuseppe/mcu/RIOT/Makefile.base:29: ALL--/home/giuseppe/mcu/RIOT/sys/auto_init] Error 2 make[1]: [/home/giuseppe/mcu/RIOT/Makefile.base:29: ALL--/home/giuseppe/mcu/RIOT/sys] Error 2 make: *** [/home/giuseppe/mcu/gtip-riotos/test_04/../../RIOT//Makefile.include:540: /home/giuseppe/mcu/gtip-riotos/test_04/bin/nucleo-l476rg/application_gtip-test-can.a] Error 2 ~/mcu/gtip-riotos/test_04 (master) $



5. Issues / missing feature 
    - the [candev_conf](https://github.com/RIOT-OS/RIOT/blob/master/cpu/stm32_common/include/can_params.h) missing the right setup for my target.
if my hypothesis is right I can try to fix it adding the support for stm32l4 target.

<!--
Example: Cannot build gnrc_networking application for samr21-xpro board.
-->

#### Steps to reproduce the issue
<!--
Try to describe as precisely as possible here the steps required to reproduce
the issue. Here you can also describe your hardware configuration, the network
setup, etc.
-->

#### Expected results
<!--
Example: The gnrc_networking application builds on samr21-xpro.
-->

#### Actual results
<!--
Please paste or specifically describe the actual output.
-->

#### Versions
<!--
Operating system: Mac OSX, Linux, Vagrant VM
Build environment: GCC, CLang versions (you can run the following command from
the RIOT base directory: make print-versions).
-->

<!-- Thanks for contributing! -->
PeterKietzmann commented 4 years ago

@JannesVolkens might be interested.