From 94e87bb6e8b42abe6b3740bfe6619bc90d478dec Mon Sep 17 00:00:00 2001 From: Claudio Micheli Date: Mon, 25 May 2020 14:01:13 +0200 Subject: [PATCH] stm32: extend CAN ioctrl with NART/ABOM. Add RTR to CAN header Signed-off-by: Claudio Micheli --- arch/arm/src/stm32/stm32_can.c | 51 ++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/stm32/stm32_can.c b/arch/arm/src/stm32/stm32_can.c index 2cdeecc07d..658147936e 100644 --- a/arch/arm/src/stm32/stm32_can.c +++ b/arch/arm/src/stm32/stm32_can.c @@ -1102,6 +1102,50 @@ static int stm32can_ioctl(FAR struct can_dev_s *dev, int cmd, } break; + case CANIOC_SET_NART: + { + uint32_t regval; + ret = stm32can_enterinitmode(priv); + if (ret != 0) + { + return ret; + } + regval = stm32can_getreg(priv, STM32_CAN_MCR_OFFSET); + if (arg == 1) + { + regval |= CAN_MCR_NART; + } + else + { + regval &= ~CAN_MCR_NART; + } + stm32can_putreg(priv, STM32_CAN_MCR_OFFSET, regval); + return stm32can_exitinitmode(priv); + } + break; + + case CANIOC_SET_ABOM: + { + uint32_t regval; + ret = stm32can_enterinitmode(priv); + if (ret != 0) + { + return ret; + } + regval = stm32can_getreg(priv, STM32_CAN_MCR_OFFSET); + if (arg == 1) + { + regval |= CAN_MCR_ABOM; + } + else + { + regval &= ~CAN_MCR_ABOM; + } + stm32can_putreg(priv, STM32_CAN_MCR_OFFSET, regval); + return stm32can_exitinitmode(priv); + } + break; + /* Unsupported/unrecognized command */ default: @@ -1211,8 +1255,11 @@ static int stm32can_send(FAR struct can_dev_s *dev, regval |= msg->cm_hdr.ch_id << CAN_TIR_STID_SHIFT; } #else - regval &= ~CAN_TIR_STID_MASK; - regval |= (uint32_t)msg->cm_hdr.ch_id << CAN_TIR_STID_SHIFT; + regval |= ( ( (uint32_t) msg->cm_hdr.ch_id << CAN_TIR_STID_SHIFT) & CAN_TIR_STID_MASK ); + +#ifdef CONFIG_CAN_USE_RTR + regval |= (msg->cm_hdr.ch_rtr ? CAN_TIR_RTR : 0); +#endif #endif stm32can_putreg(priv, STM32_CAN_TIR_OFFSET(txmb), regval);