Open melvinvdb opened 1 month ago
Hi @melvinvdb! We appreciate you submitting your first issue for our open-source project. 🌟
Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙
Thank you for the detailed bug report. Are you able to submit a pull request for the initialization fix already tested?
Created a tested pull request!
@melvinvdb What is the clock source for the mcp25xxfd? Is it stable after reset?
@melvinvdb Ping?
Sorry for the late reply our project has put a lower priority on this. I've checked and the clock source stays stable even when resetting. The mcp has it's own clock at 40 mhz. This clock automatically starts when power is applied (even before any spi command is given). The 40 mhz clock isn't interrupted when resetting the mcp. Resetting doesn't seem to have any effect on the clock.
1st issue:
We're using the NRF53 with MCP25186. After mcu reboot the can_mcp251xfd sometimes fails to initialize. This will not show up in the uart logs (2nd issue), instead you will notice that no interrupts are generated when CAN messages are received. The interrupt pin will never go low. The issue lies in the reset sequence: https://github.com/zephyrproject-rtos/zephyr/blob/4b6d3f1e16ea8ccccbf85f1eaf7efd0caea11766/drivers/can/can_mcp251xfd.c#L1573 This reset method has no delay and will immediately continue with reading the MCP251XFD_REG_CON register: https://github.com/zephyrproject-rtos/zephyr/blob/4b6d3f1e16ea8ccccbf85f1eaf7efd0caea11766/drivers/can/can_mcp251xfd.c#L1603-L1606 This will set
ret
to-EINVAL
but in thegoto done
this will be overwritten (part of 2nd issue): https://github.com/zephyrproject-rtos/zephyr/blob/4b6d3f1e16ea8ccccbf85f1eaf7efd0caea11766/drivers/can/can_mcp251xfd.c#L1674-L1678The solution is to add a
k_msleep(5);
to the bottom of themcp251xfd_reset
function. This makes the MCP2518 to always successfully initialize on MCU reboot.2nd issue:
In
mcp251xfd_init
, if any of the following register configuration fails this will not be noticed by the system/uart log and will silently continue:The whole function returns success as long as
can_set_timing
succeeds! To me this initialization function needs a redesign. This is not up to standard.To Reproduce Logs and console output Reproduction might be difficult. We seem to have this issue on our custom board with an nrf5340 and mcp251863. It seems to always happen after doing:
sys_reboot(SYS_REBOOT_COLD)
I've added the following code to can_mcp251xfd.c to debug the MCP registers (place at the bottom):
This should result in the following registers (WORKING situation):
On initialization failure they look like:
Again, this is caused by a failure to read on: https://github.com/zephyrproject-rtos/zephyr/blob/4b6d3f1e16ea8ccccbf85f1eaf7efd0caea11766/drivers/can/can_mcp251xfd.c#L1603 Which causes the whole initialization sequence to be silently skipped.
Expected behavior First of to not fail the initialization of mcp251863. Second to not silently continue if initialization fails.
Impact This is a showstopper for us. I'm currently trying to find out how to detect and correct this without modifying the zephyr code base.
Environment (please complete the following information):