From 983df071c38ec6cc1e8b45944aa0e5e863d9fc00 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 5 Aug 2015 13:55:20 -0600 Subject: [PATCH] STM32V7 MCAN: CAN FD mode depends on support from the upper half driver, so it is now global CAN configuration --- arch/arm/src/samv7/Kconfig | 4 ++++ arch/arm/src/samv7/sam_mcan.c | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/samv7/Kconfig b/arch/arm/src/samv7/Kconfig index 6f0c74bfb62..25c768f9bca 100644 --- a/arch/arm/src/samv7/Kconfig +++ b/arch/arm/src/samv7/Kconfig @@ -1349,11 +1349,13 @@ config SAMV7_MCAN0_ISO11899_1 config SAMV7_MCAN0_FD bool "FD" + depends on CAN_FD ---help--- Enable FD mode config SAMV7_MCAN0_FD_BSW bool "FD with fast bit rate switching" + depends on CAN_FD ---help--- Enable FD mode with fast bit rate switching mode. @@ -1656,11 +1658,13 @@ config SAMV7_MCAN1_ISO11899_1 config SAMV7_MCAN1_FD bool "FD" + depends on CAN_FD ---help--- Enable FD mode config SAMV7_MCAN1_FD_BSW bool "FD with fast bit rate switching" + depends on CAN_FD ---help--- Enable FD mode with fast bit rate switching mode. diff --git a/arch/arm/src/samv7/sam_mcan.c b/arch/arm/src/samv7/sam_mcan.c index f0eb9b5e938..1204387ec91 100644 --- a/arch/arm/src/samv7/sam_mcan.c +++ b/arch/arm/src/samv7/sam_mcan.c @@ -1405,12 +1405,13 @@ static void mcan_buffer_reserve(FAR struct sam_mcan_s *priv) * Description: * In the CAN FD format, the coding of the DLC differs from the standard * CAN format. The DLC codes 0 to 8 have the same coding as in standard - * CAN, the codes 9 to 15, which in standard CAN all code a data field of - * 8 bytes, are encoded. + * CAN. But the codes 9 to 15 all imply a data field of 8 bytes with + * standard CAN. In CAN FD mode, the values 9 to 15 are encoded to values + * in the range 12 to 64. * * Input Parameter: * priv - A pointer to the private data structure for this MCAN peripheral - * dlc - the DLC to convert to a byte count + * dlc - the DLC to convert to a byte count, OR * nbytes - the byte count to convert to a DLC * * Returned Value: @@ -1422,6 +1423,7 @@ static uint8_t mcan_dlc2bytes(FAR struct sam_mcan_s *priv, uint8_t dlc) { if (dlc > 8) { +#ifdef CONFIG_CAN_FD if (priv->config->mode == MCAN_ISO11898_1_MODE) { return 8; @@ -1447,6 +1449,9 @@ static uint8_t mcan_dlc2bytes(FAR struct sam_mcan_s *priv, uint8_t dlc) return 64; } } +#else + return 8; +#endif } return dlc; @@ -1459,6 +1464,7 @@ static uint8_t mcan_bytes2dlc(FAR struct sam_mcan_s *priv, uint8_t nbytes) { return nbytes; } +#ifdef CONFIG_CAN_FD else if (priv->mode == MCAN_ISO11898_1_MODE) { return 8; @@ -1491,6 +1497,12 @@ static uint8_t mcan_bytes2dlc(FAR struct sam_mcan_s *priv, uint8_t nbytes) { return 15; } +#else + else + { + return 8; + } +#endif } #endif @@ -2956,6 +2968,7 @@ static int mcan_hw_initialize(struct sam_mcan_s *priv) cmr = MCAN_CCCR_CMR_ISO11898_1; break; +#ifdef CONFIG_CAN_FD case MCAN_FD_MODE: regval |= MCAN_CCCR_CME_FD; cmr = MCAN_CCCR_CMR_FD; @@ -2965,6 +2978,7 @@ static int mcan_hw_initialize(struct sam_mcan_s *priv) regval |= MCAN_CCCR_CME_FD_BSW; cmr = MCAN_CCCR_CMR_FD_BSW; break; +#endif } /* Set the initial CAN mode */