MCP251X can driver porting

This article records the process of porting the mcp2515 can chip driver with the spi interface. The mcp2515 chip is connected to the spi1 interface of the NUC980 through the spi interface, and the interrupt pin is connected to the PA0 interrupt. This driver migration process is mainly divided into the following steps.

Step 1: Configure linux kernel to support mcp2515 driver, configuration content:
can function configuration

[*] Networking support  ---> 
	<*>   CAN bus subsystem support  --->
		<*>   Raw CAN Protocol (raw access with CAN-ID filtering)
		<*>   Broadcast Manager CAN Protocol (with content filtering)
		CAN Device Drivers  --->
			<*> Platform CAN drivers with Netlink support
			[*]   CAN bit-timing calculation
			CAN SPI interfaces  --->
				<*> Microchip MCP251x and MCP25625 SPI CAN controllers			

spi interface configuration

Device Drivers  --->
	[*] SPI support  --->
		<*>   Nuvoton NUC980 Series SPI Port 0
			SPI0 IO port selection (Port D)  --->
			SPI0 TX/RX by PDMA or not (Use PDMA)  --->			

PortD of spi1 is respectively for PD8/SS0, PD9/MOSI, PD10/MISO, PD11/CLK, and the interrupt pin is connected to PA0.

Step 2: This sample platform does not use the device tree method, so add the device node content in the linux/arch/arm/mach-nuc980/dev.c file.

+ #include <linux/can/platform/mcp251x.h>

+ static struct mcp251x_platform_data mcp251x_info = {
    
    
+ 	.oscillator_frequency = 8000000,
+ };

#if defined(CONFIG_MTD_M25P80) || defined(CONFIG_SPI_SPIDEV)
static struct spi_board_info nuc980_spi0_board_info[] __initdata = {
    
    

+	{
    
    
+		.modalias = "mcp2515",
+		.max_speed_hz = 2*1000*1000,		//  mcp2515 时钟 2MHz
+		.irq = IRQ_EXT0_A0,				//	中断编号 PA0 引脚
+		.bus_num = 1,					//  spi 1
+		.chip_select = 0,				//  use SS0
+		.mode = SPI_MODE_0,
+		.platform_data = &mcp251x_info,
+	},
};
#endif

Step 3: Compile the kernel and burn it to the development board, confirm the configuration of the can network card

During the system boot process, the process of mcp251x to
Insert picture description here
view the contents of the CAN network card is as follows
Insert picture description here

The next blog will record the test can communication experiment process.

Guess you like

Origin blog.csdn.net/weixin_38387929/article/details/114927127