Hi,
I am having a hard time for days now trying to get the MCP2518FD working on a nRF9160-DK board. This device, embedding CAN transceiver and receiver, is accessible through SPI.
I ran into several forums and some doc here and there but nothing seems to match my case.
As a context, I use the ncs v2.6.0 and a custom board (which for now is basically just the nRF9160-DK board, meaning that my dts file simply includes <nordic/nrf9160ns_sica.dtsi> and defines partitions) and then I use an overlay for the real custom devices, which is as follows (shrunk to show only relevant fields) :
&pinctrl { uart0_default: uart0_default { group1 { psels = <NRF_PSEL(UART_TX, 0, 29)>, <NRF_PSEL(UART_RTS, 0, 27)>; }; group2 { psels = <NRF_PSEL(UART_RX, 0, 28)>, <NRF_PSEL(UART_CTS, 0, 26)>; bias-pull-up; }; }; uart0_sleep: uart0_sleep { group1 { psels = <NRF_PSEL(UART_TX, 0, 29)>, <NRF_PSEL(UART_RX, 0, 28)>, <NRF_PSEL(UART_RTS, 0, 27)>, <NRF_PSEL(UART_CTS, 0, 26)>; low-power-enable; }; }; spi3_default: spi3_default { group1 { psels = <NRF_PSEL(SPIM_SCK, 0, 1)>, <NRF_PSEL(SPIM_MOSI, 0, 10)>, <NRF_PSEL(SPIM_MISO, 0, 13)>; }; }; spi3_sleep: spi3_sleep { group1 { psels = <NRF_PSEL(SPIM_SCK, 0, 1)>, <NRF_PSEL(SPIM_MOSI, 0, 10)>, <NRF_PSEL(SPIM_MISO, 0, 13)>; low-power-enable; }; }; }; / { model = "Nordic nRF9160 DK NRF9160"; compatible = "nordic,nrf9160-dk-nrf9160"; chosen { zephyr,console = &uart0; zephyr,shell-uart = &uart0; zephyr,uart-mcumgr = &uart0; zephyr,canbus = &mcp251xfd; }; /* These aliases are provided for compatibility with samples */ aliases { spi3 = &spi3; }; }; &spi3 { status = "okay"; mcp251xfd: mcp251xfd@0 { compatible = "microchip,mcp251xfd"; status = "okay"; reg = <0x0>; osc-freq = <40000000>; int-gpios = <&gpio0 16 0>; spi-max-frequency = <8000000>; bus-speed-data = <1000000>; bus-speed = <125000>; }; cs-gpios = <&gpio0 0 0>; pinctrl-0 = <&spi3_default>; pinctrl-names = "default", "sleep"; pinctrl-1 = <&spi3_sleep>; };
Which comes along with this prj.conf file (shrunk to show only relevant fields) :
# General config CONFIG_ASSERT=y CONFIG_BUILD_WITH_TFM=y CONFIG_TRUSTED_EXECUTION_NONSECURE=y # Increase memory heap CONFIG_HEAP_MEM_POOL_SIZE=4096 CONFIG_MAIN_STACK_SIZE=4096 CONFIG_SPI=y CONFIG_CAN=y CONFIG_CAN_FD_MODE=y CONFIG_CAN_MCP251XFD=y # CONFIG_CAN_MCP251XFD_READ_CRC_RETRIES=3
Just to let you know, my MCP2518FD is in fact the Mikrochip MCP2518FD clickboard but I expected to have it working without using the -DSHIELD compilation option since it only has to be seen as a SPI device.
Now that said, I am pretty new to the devicetree and Nordic dev environment. I got to understand that the main interface I will be using is the <zephyr/drivers/can.h>. But my problem pops before any manual usage of these functions. I managed to put some log in the "zephyr\drivers\can\can_mcp251xfd.c" in the mcp251xfd_init and mcp251xfd_read_crc functions (called by the very first mcp251xfd_set_mode_internal and mcp251xfd_reset functions). In the nRF Connect's Serial Terminal v1.3.1, here is the result I got :
[Sec Thread] Secure image initializing! Booting TF-M v2.0.0 mutex init spi init done int gpio init done int gpio configured int gpio callback init int gpio callback added thread initialized try reset try set mode config try read crc trial 1 crc_in : 34779 (0x87db) tx_buf content before send : 0xb0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 0x0 rx_buf content after send : 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 crc 52805 (0xce45) trial 0 crc_in : 34779 (0x87db) tx_buf content before send : 0xb0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 0x0 rx_buf content after send : 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 crc 52805 (0xce45) read_crc_reg is NULL set mode internal error code : -22 [00:00:00.371,063] <err> can_mcp251xfd: Failed to reset the device [-22] *** Booting nRF Connect SDK v3.5.99-ncs1 *** [00:00:00.371,246] <err> gck_tcu: Device mcp251xfd@0 is not ready
So from my understanding, the init function is implicitly called at boot time. SPI and GPIO init, inherited from what I specified in the overlay, work well. But when it comes to the very first SPI communication, I got a CRC error which I can't understand the origin since no complex operation is done here.
Moreover, I only wired the SPI and power pins. Whenever I also wire the P0.16 to the INT pin of my clickboard, I don't even get all this log and stop after "Booting TF-M v2.0.0", meaning I don't even boot I guess.
Feel free to ask for any additionnal information that might help.
Thank you in advance for your help.
Guillaume R