Full Zhi T507 implementation SPI to CAN-full process detailed

The full-awaited T507 processor itself does not support CAN function, what is the way to implement CAN function?

We know that the FETT507-C core board is to support the SPI interface, but the bottom plate does not take the interface, so Xiaobian intends to double the SPI interface and make a SPI CAN to implement CAN function.

The method used herein is to achieve SPI to CAN function by adding MCP2515 driving and configuration.

First, select pin

First confirm the pin to be used, because the Freako embedded T507 development board defaults to the SPI, so it is necessary to use the pin of the SPI function, but also the interrupt pin for the CAN module.

SPI requires four pins, CS0, CLK, MOSI, MISO, and the CAN module requires an interrupt pin. Interrupt pins can use a pin with an interrupt function. Open the flying-based T507 core board pin multiplexed T507 core board pin, first confirm which pins can be used to do SPI, we search for SPI to find two groups of pins

Because PC3, PC4 and start-related are not considered using SPI0, we use SPI1 and SPI1, the pin used by SPI1, the audio will not be used by the pins used by the audio interface. So our interrupt pin is also selected from the pin used by audio, we choose PH 9 (the user can choose the pin of the interrupt function according to the actual situation).

The pins we need have been identified (3 pins), now in software modification

Second, related equipment

First check the equipment tree, the equipment trees used in this time are as follows:

KERNEL / Linux-4.9 / Arch / ARM64 / Boot / DTS / SUNXI / OKT507-C_MMON.DTSI

KERNEL / Linux-4.9 / Arch / Arm64 / Boot / DTS / SUNXI / SUN50IW9P1.DTSI

KERNEL / Linux-4.9 / Arch / ARM64 / Boot / DTS / Sunxi / Sun50IW9P1-PinCtrl.dtsi

KERNEL / Linux-4.9 / Arch / ARM64 / Boot / DTS / SUNXI / SUN50IW9P1-CLK.DTSI

Third, remove the original configuration of the selected pin

From the core board pin function multiplexing table, you can see that the selected pin is originally configured:

Sun50iw9p1-pinctrl.dtsi Search PH5 pins, you can see AHUB_DAUDIO3_PINS_A and AHUB_DAUDIO3_PINS_B are used for audio, using grep “AHUB_DAUDIO3_PINS_A” in the device tree path ./ -nr instructions can be found, there is called in sun50iw9p1.dtsi:

Open Sun 50iW9p1.dtsi, you can see that there is a call in the AHUB_DAUDIO3 node, set the status to disabled (default is a disablded state)

The disabled set in this equipment tree continues to find the superior device tree of the device tree: OKT507-C-Common.dtsi. Okt507-c-common.dtsi has open settings, you need to turn off the AHUB_DAUDIO3, status = “disabled”. PH 5, PH 6, PH 7, PH8, and PH9 are all released.

Fourth, configure SPI1

4.1 Enable SPI1 configuration

Search for SPI1 related content, you can see in Sun50IW9p1.dtsi

This is a registration of SPI1, change Status to Okay, where the relevant pin is configured.

4.2 Clock and pin configuration of SPI1

Clock: We can see the contents of CLK_PLL_PERIPH0 and CLK_SPI1 by viewing sun50iw9p1-clk.dtsi, and we use the default configuration. Not map here, you can check it yourself.

Pin: We look at Sun50iW9p1-PinCtrl.dtsi to see the contents of SPI1_Pins_a, SPI1_PINS_B, and SPI1_Pins_C, using pins to pH 5, pH 6, pH7, pH8.

V. Configure SPI to CAN equipment

5.1 Add Device

Add the SPI to the CAN related nodes after the SPI0 node in OKT507-COMMON.DTSI, add the content as follows:

spi1: spi @ 05011000 {pinctrl-0 = <& spi1_pins_a & spi1_pins_b>; pinctrl-1 = <& spi1_pins_c>; spi_slave_mode = <0>; status = “okay”; can0: can @ 0 {compatible = “microchip, mcp2515”; pinctrl- names = “default”; pinctrl-0 = <& mcp2515_int>; reg = <0>; spi-max-frequency = <1000000>; clocks = <& clk_osc8m>; interrupt-parent = <& pio>; interrupts = ; STATUS = “okay”;};}; in which interrupt pin configuration, please modify it according to the actual configured pin.

5.2 clock configuration

We used the clock and interrupt pins when registering CAN, and the pH9 can be used when the front is turned off, but the 8M clock CLK_OSC8M we use is not registered.

Open Sun 50IW9P1-CLK.DTSI, add CLK_OSC8M to CLK_OSC48M

CLK_OSC8M: OSC8M {# clock-cells = <0>; compatible = “allwinner, fixed-clock”; clock-frequency = <8000000>; clock-output-name = “OSC8M”;

If you are 24M crystal, you can also register CLK_OSC24M, CLOCK-FREQUENCY is changed to 24000000

5.3 Interrupt Pin Configuration

Add in OKT507-CMMon.dtsi, search in the device tree: PIO: PINCTRL @ 0300B000, add the following configuration to the node.

MCP2515_INT: CAN0 @ 0 {Allwinner, Pins = “PH9”; Allwinner, PNAME = “MCP2515_INT”; Allwinner, Function = “IRQ”; Allwinner, Muxsel = <6>; allwinner, drive = <1>; allwinner, punl = <0>;

5.4 MCP2515 Drive Configuration

At this point, we have completed the modifications in the equipment tree, we add the MCP2515 driver configuration, drive to Kernel / Linux-4.9 / Drivers / Net / CAN / SPI /, you can see mcp251x.c, we can open this directory Config_can_mcp251x has been configured in the makefile file in the Makefile file.

Enter the kernel / linux-4.9 directory, execute the following:

Makesun50iw9p1smp_longan_defconfigmakememenuconfigarch = ARM64

Enter the graphical configuration interface, we add MCP2515 compilation, and each level is selected as follows:

[*] NetWorkingSupport —> <*> canbussubsystemsupport —> CANDEVICEDRIVERS —> canspiinterface —> <*> microchipmcp251xspicancontrollers

The content in front of the front, “*” is compiled into the kernel through the space bar, “M” is compiled into a module, and the empty is not compiled. Compiled into the kernel here

After the modification is complete, press the ESC button to exit, and finally select YES Save Configure to .config.

Modify completion, follow the manual to compile the source code, generate the mirror

Note:

After configuring menuconfig, use ./build.sh kernel single-step compile the kernel, use this .config if it is fully compiled, it will re-put the sun50iw9p1smp_longan_defconfig to .config, the previous configuration will not Take effect. Therefore, after modification of MenuConfig, save .config wants to make a backup, need to rename the file before full compilation, will rename it to sun50iw9p1smp_longan_defconfig, and replace the same name file from KERNEL / Linux-4.9 / Arch / Arm64 / Configs, CAN test

Boot compiled metals into the core board and copy the relevant test tools in the data to the root directory of the T507 development board.

The hardware is connected to the SPI, and the PC is connected, using USB to CAN to plug in computer

Start T507 Development Board Perform the following program to test:

ifconfigcan0down / iplinksetcan0uptypecanbitrate125000triple-SamplingonifConfigcan0UP / Cansendcan0123 # 12345678 // Send Data / CANDUMPCAN0 // Receive Data

Seven, hardware modification method

Transplantation using SPI to CAN modules on Freon embedded T507 development board

First, go to the C132 / U18 two devices on the T507 development board, and then connect the SPI to the module to the T507 development board by flying way, the connection mode is as follows:

The 5V main power supply of the SPI to CAN can be obtained on R194 and R199 below the audio, and the location is as follows: