From b571d2e5e49dcdb909d11c723504078747db300b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 14 Oct 2025 15:34:21 +0200 Subject: [PATCH] drivers/can: fix sending of RTR frames with nonzero DLC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The message passed to the write can have `cm.hdr.ch_rtr` set and if nonzero DLC is specified in the frame then invalid number of bytes is removed from the buffer as RTR frames do not have any data even when DLC is nonzero. This was tested on SAMv7 (mcan). With this change a custom RTR can be sent. Signed-off-by: Karel Kočí --- drivers/can/can.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/can/can.c b/drivers/can/can.c index 08dc85c1a49..0e584569b13 100644 --- a/drivers/can/can.c +++ b/drivers/can/can.c @@ -675,8 +675,16 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, * CAN message at sutibal. */ - msg = (FAR struct can_msg_s *)&buffer[nsent]; - nbytes = can_dlc2bytes(msg->cm_hdr.ch_dlc); + msg = (FAR struct can_msg_s *)&buffer[nsent]; + if (msg->cm_hdr.ch_rtr) + { + nbytes = 0; + } + else + { + nbytes = can_dlc2bytes(msg->cm_hdr.ch_dlc); + } + msglen = CAN_MSGLEN(nbytes); if (nsent + msglen > buflen)