arch/stm32h7: Add FDCAN SocketCAN driver

Adds an FDCAN driver for STM32H7 MCUs using the SocketCAN interface
This commit is contained in:
JacobCrabill 2022-04-15 15:11:52 -07:00 committed by Mateusz Szafoni
parent 4fa21c4719
commit f406afdc42
7 changed files with 4391 additions and 6 deletions

View File

@ -17,6 +17,8 @@ config ARCH_CHIP_STM32H743AG
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_G
select STM32H7_IO_CONFIG_A
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 1024 Kb FLASH, 1024K Kb SRAM,
UFBGA169
@ -35,6 +37,8 @@ config ARCH_CHIP_STM32H743BG
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_G
select STM32H7_IO_CONFIG_B
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 1024 Kb FLASH, 1024K Kb SRAM,
LQFP208
@ -44,6 +48,8 @@ config ARCH_CHIP_STM32H743BI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_B
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
LQFP208
@ -53,6 +59,8 @@ config ARCH_CHIP_STM32H743IG
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_G
select STM32H7_IO_CONFIG_I
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 1024 Kb FLASH, 1024K Kb SRAM,
LQFP176 or UFBGA176
@ -62,6 +70,8 @@ config ARCH_CHIP_STM32H743II
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_I
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
LQFP176 or UFBGA176
@ -71,6 +81,8 @@ config ARCH_CHIP_STM32H743VG
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_G
select STM32H7_IO_CONFIG_V
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 1024 Kb FLASH, 1024K Kb SRAM,
LQFP100 or TFBGA100
@ -80,6 +92,8 @@ config ARCH_CHIP_STM32H743VI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_V
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
LQFP100 or TFBGA100
@ -89,6 +103,8 @@ config ARCH_CHIP_STM32H743XG
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_G
select STM32H7_IO_CONFIG_X
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 1024 Kb FLASH, 1024K Kb SRAM,
TFBGA240
@ -98,6 +114,8 @@ config ARCH_CHIP_STM32H743XI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_X
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
TFBGA240
@ -107,6 +125,8 @@ config ARCH_CHIP_STM32H743ZG
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_G
select STM32H7_IO_CONFIG_Z
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 1024 Kb FLASH, 1024K Kb SRAM,
LQFP144
@ -116,6 +136,8 @@ config ARCH_CHIP_STM32H743ZI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_Z
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
LQFP144
@ -125,6 +147,8 @@ config ARCH_CHIP_STM32H747XI
select STM32H7_STM32H7X7XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_X
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
Dual core STM32 H7 Cortex M7+M4, 2048 Kb FLASH, 1024K Kb SRAM
TFBGA240
@ -134,6 +158,8 @@ config ARCH_CHIP_STM32H753AI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_A
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
with cryptographic accelerator, UFBGA169
@ -152,6 +178,8 @@ config ARCH_CHIP_STM32H753II
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_I
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
with cryptographic accelerator, LQFP176/UFBGA176
@ -161,6 +189,8 @@ config ARCH_CHIP_STM32H753VI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_V
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
with cryptographic accelerator, LQFP100/TFBGA100
@ -179,6 +209,8 @@ config ARCH_CHIP_STM32H753ZI
select STM32H7_STM32H7X3XX
select STM32H7_FLASH_CONFIG_I
select STM32H7_IO_CONFIG_Z
select STM32H7_HAVE_FDCAN1
select STM32H7_HAVE_FDCAN2
---help---
STM32 H7 Cortex M7, 2048 Kb FLASH, 1024K Kb SRAM,
with cryptographic accelerator, LQFP144
@ -365,6 +397,14 @@ config STM32H7_HAVE_SPI6
bool
default n
config STM32H7_HAVE_FDCAN1
bool
default n
config STM32H7_HAVE_FDCAN2
bool
default n
# These "hidden" settings are the OR of individual peripheral selections
# indicating that the general capability is required.
@ -372,8 +412,11 @@ config STM32H7_ADC
bool
default n
config STM32H7_CAN
config STM32H7_FDCAN
bool
select NET_CAN_HAVE_CANFD
select NET_CAN_EXTID
select NET_CAN_HAVE_TX_DEADLINE
default n
config STM32H7_DAC
@ -566,6 +609,18 @@ config STM32H7_WWDG
default n
select WATCHDOG
config STM32H7_FDCAN1
bool "FDCAN1"
select STM32H7_FDCAN
default n
depends on STM32H7_HAVE_FDCAN1
config STM32H7_FDCAN2
bool "FDCAN2"
select STM32H7_FDCAN
default n
depends on STM32H7_HAVE_FDCAN2
menu "STM32H7 I2C Selection"
config STM32H7_I2C1
@ -1832,7 +1887,7 @@ config STM32H7_DMACAPABLE_ASSUME_CACHE_ALIGNED
This option configures the stm32_dmacapable to not disqualify
DMA operations on memory that is not dcache aligned based solely
on the starting address and byte count.
Use this when ALL buffer extents are known to be aligned, but the
the count does not use the complete buffer.
@ -5326,6 +5381,114 @@ config STM32H7_QENCODER_SAMPLE_EVENT_8
endchoice
endmenu
endmenu # QEncoder Driver
menu "FDCAN Driver Configuration"
depends on STM32H7_FDCAN1 || STM32H7_FDCAN2
menu "FDCAN1 Configuration"
depends on STM32H7_FDCAN1
config FDCAN1_BITRATE
int "CAN bitrate"
depends on !NET_CAN_CANFD
default 1000000
config FDCAN1_ARBI_BITRATE
int "CAN FD Arbitration phase bitrate"
depends on NET_CAN_CANFD
default 1000000
config FDCAN1_DATA_BITRATE
int "CAN FD Data phase bitrate"
depends on NET_CAN_CANFD
default 4000000
endmenu # STM32H7_FDCAN1
menu "FDCAN2 Configuration"
depends on STM32H7_FDCAN2
config FDCAN2_BITRATE
int "CAN bitrate"
depends on !NET_CAN_CANFD
default 1000000
config FDCAN2_ARBI_BITRATE
int "CAN FD Arbitration phase bitrate"
depends on NET_CAN_CANFD
default 1000000
config FDCAN2_DATA_BITRATE
int "CAN FD Data phase bitrate"
depends on NET_CAN_CANFD
default 4000000
endmenu # STM32H7_FDCAN2
config STM32H7_FDCAN_REGDEBUG
bool "Enable register dump debugging"
depends on DEBUG_CAN_INFO
depends on DEBUG_NET_INFO
default n
---help---
Output detailed register-level CAN device debug information.
Requires also CONFIG_DEBUG_CAN_INFO and CONFIG_DEBUG_NET_INFO.
config STM32H7_FDCAN_LOOPBACK
bool "Enable FDCAN loopback mode"
default n
---help---
Enable the FDCAN local loopback mode for testing purposes.
Requires a further choice of internal or external loopback mode.
TODO: Enable separately for FDCAN1 and FDCAN2
choice
prompt "FDCAN Loopback Mode"
depends on STM32H7_FDCAN_LOOPBACK
default STM32H7_FDCAN_LOOPBACK_INTERNAL
config STM32H7_FDCAN_LOOPBACK_INTERNAL
bool "Internal loopback mode"
---help---
Enable internal loopback mode, where both Tx and Rx are
disconnected from the CAN bus. This can be used for a "Hot Selftest",
meaning the FDCAN can be used without affecting a running CAN bus.
All transmitted frames are treated as received frames and processed
accordingly.
config STM32H7_FDCAN_LOOPBACK_EXTERNAL
bool "External loopback mode"
---help---
Enable external loopback mode, where the Rx pin is disconnected from
the CAN bus but the Tx pin remains connected.
All transmitted frames are treated as received frames and processed
accordingly.
endchoice # CAN Loopback Mode
choice
prompt "FDCAN WorkQueue Selection"
default STM32H7_FDCAN_LPWORK
config STM32H7_FDCAN_LPWORK
bool "Use LP work queue"
---help---
Use the low-priority (LP) work queue for reception and transmission
of new frames and for processing of transmission timeouts.
config STM32H7_FDCAN_HPWORK
bool "Use HP work queue"
---help---
Use the high-priority (HP) work queue for reception and transmission
of new frames and for processing of transmission timeouts.
endchoice
endmenu # FDCAN Driver
endif # ARCH_CHIP_STM32H7

View File

@ -57,6 +57,10 @@ ifeq ($(CONFIG_STM32H7_ADC),y)
CHIP_CSRCS += stm32_adc.c
endif
ifeq ($(CONFIG_STM32H7_FDCAN),y)
CHIP_CSRCS += stm32_fdcan_sock.c
endif
ifeq ($(CONFIG_STM32H7_BBSRAM),y)
CHIP_CSRCS += stm32_bbsram.c
endif

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,7 @@
#include "chip.h"
#include "stm32_gpio.h"
#include "stm32_fdcan_sock.h"
#include "stm32_fmc.h"
#include "stm32_i2c.h"
#include "stm32_spi.h"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
/****************************************************************************
* arch/arm/src/stm32h7/stm32_fdcan_sock.h
*
* 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.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32H7_STM32_FDCAN_SOCK_H
#define __ARCH_ARM_SRC_STM32H7_STM32_FDCAN_SOCK_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "hardware/stm32_fdcan.h"
#ifdef CONFIG_STM32H7_FDCAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#ifndef CONFIG_NETDEV_LATEINIT
/****************************************************************************
* Function: arm_netinitialize
*
* Description:
* Initialize the first network interface. If there is more than one
* interface in the chip, then board-specific logic will have to provide
* this function to determine which, if any, CAN interfaces should be
* initialized. Also prototyped in up_internal.h.
*
* Input Parameters:
* None
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
* Called very early in the initialization sequence.
*
****************************************************************************/
void arm_netinitialize(void);
#else
/****************************************************************************
* Function: stm32_fdcansockinitialize
*
* Description:
* Initialize the CAN controller and driver
*
* Input Parameters:
* intf - In the case where there are multiple CAN interfaces, this value
* identifies which CAN interface is to be initialized.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/
int stm32_fdcansockinitialize(int intf);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_STM32H7_FDCAN */
#endif /* __ARCH_ARM_SRC_STM32H7_STM32_FDCAN_SOCK_H */

View File

@ -432,13 +432,15 @@ static inline void rcc_enableapb1(void)
regval |= RCC_APB1LENR_I2C3EN;
#endif
/* TODO: ... */
putreg32(regval, STM32_RCC_APB1LENR); /* Enable APB1L peripherals */
regval = getreg32(STM32_RCC_APB1HENR);
/* TODO: ... */
#ifdef CONFIG_STM32H7_FDCAN
/* FDCAN clock enable */
regval |= RCC_APB1HENR_FDCANEN;
#endif
putreg32(regval, STM32_RCC_APB1HENR); /* Enable APB1H peripherals */
}