Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: can: shell: sending CAN FD frames with non-even DLC <=> nbytes relationship sends garbage at frame data end #73309

Closed
henrikbrixandersen opened this issue May 26, 2024 · 0 comments · Fixed by #73310
Assignees
Labels
area: CAN bug The issue is a bug, or the PR is fixing a bug

Comments

@henrikbrixandersen
Copy link
Member

henrikbrixandersen commented May 26, 2024

Describe the bug
Sending CAN FD frames with non-even DLC <=> nbytes relationship using the Zephyr CAN shell sends garbage at frame data end.

To Reproduce
Steps to reproduce the behavior:

  1. Using the Zephyr CAN shell, send a CAN FD frame with 10 data bytes defined on the shell command line (e.g. can send can0 -f 040 00 11 22 33 44 55 66 77 88 99)
  2. Notice that the CAN shell will (correctly) enqueue a CAN frame with a DLC of 9 meaning 12 bytes to be transferred. This is due to CAN FD not supporting arbitrary frame data lengths.
  3. Notice, however, that the CAN shell will incorrectly use the number of bytes in the output labelled DLC (e.g. enqueuing CAN frame #3 with standard (11-bit) CAN ID 0x040, RTR 0, CAN FD 1, BRS 0, DLC 12)
  4. Using a CAN analyser, notice that the last two bytes of the CAN FD frame payload contains garbage.

Expected behavior

  • The shell output should print the correct DLC (not the number of bytes).
  • The shell should zerorise the CAN frame to ensure no garbage bytes are sent at the end of the frame.

Impact
Annoyance, confusion.

Logs and console output

uart:~$ can mode can_loopback0 normal loopback fd 
setting mode 0x00000005
uart:~$ can filter add can_loopback0 040
adding filter with standard (11-bit) CAN ID 0x040, CAN ID mask 0x7ff
filter ID: 0
uart:~$ can start can_loopback0 
starting can_loopback0
uart:~$ can send can_loopback0 -f 040 00 11 22 33 44 55 66 77 88 99
enqueuing CAN frame #0 with standard (11-bit) CAN ID 0x040, RTR 0, CAN FD 1, BRS 0, DLC 12
CAN frame #0 successfully sent
(00000)  --       040  [12]  00 11 22 33 44 55 66 77 88 99 7b ab 

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK 0.16.5-1
  • Commit SHA: 3a3f25c
@henrikbrixandersen henrikbrixandersen added bug The issue is a bug, or the PR is fixing a bug area: CAN labels May 26, 2024
@henrikbrixandersen henrikbrixandersen self-assigned this May 26, 2024
henrikbrixandersen added a commit to henrikbrixandersen/zephyr that referenced this issue May 26, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
henrikbrixandersen added a commit to henrikbrixandersen/zephyr that referenced this issue May 26, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
henrikbrixandersen added a commit that referenced this issue May 27, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: #73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
henrikbrixandersen added a commit that referenced this issue May 27, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: #73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
henrikbrixandersen added a commit to vestas-wind-systems/zephyr that referenced this issue May 27, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit fb4f67b)
henrikbrixandersen added a commit to vestas-wind-systems/zephyr that referenced this issue May 27, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit 6a070ee)
henrikbrixandersen added a commit to vestas-wind-systems/zephyr that referenced this issue May 27, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit fb4f67b)
henrikbrixandersen added a commit to vestas-wind-systems/zephyr that referenced this issue May 27, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit 6a070ee)
henrikbrixandersen added a commit that referenced this issue May 29, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: #73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit fb4f67b)
henrikbrixandersen added a commit that referenced this issue May 29, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: #73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit 6a070ee)
jhedberg pushed a commit that referenced this issue Jun 2, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: #73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit fb4f67b)
jhedberg pushed a commit that referenced this issue Jun 2, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: #73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit 6a070ee)
crazyskady pushed a commit to crazyskady/zephyr that referenced this issue Jun 6, 2024
Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
crazyskady pushed a commit to crazyskady/zephyr that referenced this issue Jun 6, 2024
Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
karstenkoenig pushed a commit to karstenkoenig/zephyr that referenced this issue Jun 19, 2024
…ding

Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit fb4f67b)
karstenkoenig pushed a commit to karstenkoenig/zephyr that referenced this issue Jun 19, 2024
… not bytes

Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit 6a070ee)
masz-nordic pushed a commit to masz-nordic/zephyr that referenced this issue Jul 12, 2024
…ding

Zerorise the CAN frame before filling in data to ensure all data bytes are
initialized.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit fb4f67b)
(cherry picked from commit 921137f)
masz-nordic pushed a commit to masz-nordic/zephyr that referenced this issue Jul 12, 2024
… not bytes

Print the raw DLC when enqueuing a CAN frame for sending, not the
corresponding number of bytes.

Fixes: zephyrproject-rtos#73309

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit 6a070ee)
(cherry picked from commit 72dede5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CAN bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
1 participant