zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.02k stars 6.17k forks source link

Atmel Sam E51 fails CAN timing test #73820

Open PeeJay opened 4 weeks ago

PeeJay commented 4 weeks ago

Describe the bug I'm developing a custom same51 board and was failing to can_set_bitrate(). After some googling I found the test suite and ran it on my board, where I discovered the can clock was set to only 4MHz by default (which is next to useless). I discovered the divider in the same5x.dtsi was set to 12, hence the low clockrate. Overriding that in the board config to 1 gives 48 MHz which is much better, but still not ideal.

To Reproduce Run the test tests/drivers/can/timing on any same51 board

Expected behavior

a CAN FD core clock of 20, 40, or 80 MHz for good node interoperability

Logs and console output Default divider of 12 (4 MHz):

*** Booting Zephyr OS build v3.6.0-5453-gc250c330c6bf ***
Running TESTSUITE can_timing
===================================================================
testing on device can@42000400 @ 4000000 Hz
Warning: CiA 601-3 recommends a CAN FD core clock of 20, 40, or 80 MHz for good node interoperability
START - test_timing
testing bitrate 10000, sample point 87.5%: sjw = 12, prop_seg = 0, phase_seg1 = 174, phase_seg2 = 25, prescaler = 2 OK, sample point error 0.0%
testing bitrate 20000, sample point 87.5%: sjw = 12, prop_seg = 0, phase_seg1 = 174, phase_seg2 = 25, prescaler = 1 OK, sample point error 0.0%
testing bitrate 50000, sample point 87.5%: sjw = 5, prop_seg = 0, phase_seg1 = 69, phase_seg2 = 10, prescaler = 1 OK, sample point error 0.0%
testing bitrate 125000, sample point 87.5%: sjw = 2, prop_seg = 0, phase_seg1 = 27, phase_seg2 = 4, prescaler = 1 OK, sample point error 0.0%
testing bitrate 250000, sample point 87.5%: sjw = 1, prop_seg = 0, phase_seg1 = 13, phase_seg2 = 2, prescaler = 1 OK, sample point error 0.0%
testing bitrate 500000, sample point 87.5%: 
    Assertion failed at WEST_TOPDIR/zephyr/tests/drivers/can/timing/src/main.c:179: test_timing_values: (sp_err <= SAMPLE_POINT_MARGIN is false)
sample point error 125 too large
 FAIL - test_timing in 0.083 seconds
===================================================================
START - test_timing_data
testing bitrate 1000000, sample point 75.0%: sjw = 1, prop_seg = 0, phase_seg1 = 2, phase_seg2 = 1, prescaler = 1 OK, sample point error 0.0%
testing bitrate 2000000, sample point 75.0%: bitrate not supported
testing bitrate 4000000, sample point 75.0%: bitrate not supported
testing bitrate 5000000, sample point 75.0%: bitrate not supported
testing bitrate 8000000, sample point 75.0%: bitrate not supported
 PASS - test_timing_data in 0.037 seconds
===================================================================
TESTSUITE can_timing failed.

------ TESTSUITE SUMMARY START ------

SUITE FAIL -  50.00% [can_timing]: pass = 1, fail = 1, skip = 0, total = 2 duration = 0.120 seconds
 - FAIL - [can_timing.test_timing] duration = 0.083 seconds
 - PASS - [can_timing.test_timing_data] duration = 0.037 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION FAILED

Divider of 1 (48 MHz):

*** Booting Zephyr OS build v3.6.0-5453-gc250c330c6bf ***
Running TESTSUITE can_timing
===================================================================
testing on device can@42000400 @ 48000000 Hz
Warning: CiA 601-3 recommends a CAN FD core clock of 20, 40, or 80 MHz for good node interoperability
START - test_timing
testing bitrate 10000, sample point 87.5%: sjw = 15, prop_seg = 0, phase_seg1 = 209, phase_seg2 = 30, prescaler = 20 OK, sample point error 0.0%
testing bitrate 20000, sample point 87.5%: sjw = 15, prop_seg = 0, phase_seg1 = 209, phase_seg2 = 30, prescaler = 10 OK, sample point error 0.0%
testing bitrate 50000, sample point 87.5%: sjw = 15, prop_seg = 0, phase_seg1 = 209, phase_seg2 = 30, prescaler = 4 OK, sample point error 0.0%
testing bitrate 125000, sample point 87.5%: sjw = 12, prop_seg = 0, phase_seg1 = 167, phase_seg2 = 24, prescaler = 2 OK, sample point error 0.0%
testing bitrate 250000, sample point 87.5%: sjw = 12, prop_seg = 0, phase_seg1 = 167, phase_seg2 = 24, prescaler = 1 OK, sample point error 0.0%
testing bitrate 500000, sample point 87.5%: sjw = 6, prop_seg = 0, phase_seg1 = 83, phase_seg2 = 12, prescaler = 1 OK, sample point error 0.0%
testing bitrate 800000, sample point 80.0%: sjw = 6, prop_seg = 0, phase_seg1 = 47, phase_seg2 = 12, prescaler = 1 OK, sample point error 0.0%
testing bitrate 1000000, sample point 75.0%: sjw = 6, prop_seg = 0, phase_seg1 = 35, phase_seg2 = 12, prescaler = 1 OK, sample point error 0.0%
 PASS - test_timing in 0.101 seconds
===================================================================
START - test_timing_data
testing bitrate 1000000, sample point 75.0%: sjw = 3, prop_seg = 0, phase_seg1 = 17, phase_seg2 = 6, prescaler = 2 OK, sample point error 0.0%
testing bitrate 2000000, sample point 75.0%: sjw = 3, prop_seg = 0, phase_seg1 = 17, phase_seg2 = 6, prescaler = 1 OK, sample point error 0.0%
testing bitrate 4000000, sample point 75.0%: sjw = 1, prop_seg = 0, phase_seg1 = 8, phase_seg2 = 3, prescaler = 1 OK, sample point error 0.0%
testing bitrate 5000000, sample point 75.0%: bitrate not supported
testing bitrate 8000000, sample point 75.0%: 
    Assertion failed at WEST_TOPDIR/zephyr/tests/drivers/can/timing/src/main.c:179: test_timing_values: (sp_err <= SAMPLE_POINT_MARGIN is false)
sample point error 84 too large
 FAIL - test_timing_data in 0.063 seconds
===================================================================
TESTSUITE can_timing failed.

------ TESTSUITE SUMMARY START ------

SUITE FAIL -  50.00% [can_timing]: pass = 1, fail = 1, skip = 0, total = 2 duration = 0.164 seconds
 - PASS - [can_timing.test_timing] duration = 0.101 seconds
 - FAIL - [can_timing.test_timing_data] duration = 0.063 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION FAILED

Environment (please complete the following information):

henrikbrixandersen commented 4 weeks ago

@PeeJay Are you able to submit a fix for the wrong CAN module clock? I do not have access to any Atmel SAM based boards.

PeeJay commented 3 weeks ago

Will do. I've now run into another issue while testing - randomly when recieving can packets I'm mostly getting <err> can_mcan: Message RAM access failure. About 1/8 are received successfully. When I connect the debugger (a Jlink) the error instantly stops. I haven't specifically enabled or disabled the MPU or cache.

henrikbrixandersen commented 1 week ago

image

Are you able to check under which of these conditions it occurs?