MCP2515 on Aria G25 (AT91SAM9G25)

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

gdp
Posts: 3
Joined: Fri Oct 23, 2015 2:58 pm

MCP2515 on Aria G25 (AT91SAM9G25)

Fri Oct 23, 2015 3:30 pm

I am trying to get a MCP2515 CAN Controller chip working using the MCP251x drivers on the Acme Systems Aria G25 module.

Initially I was trying to follow this guide: http://www.cageman.net/?page_id=66

However this guide was written for Linux 2.6.39 and I am using Linux 3.18.14, therefore I need to declare the configuration for the settings in the DTS file. After some googling I located a post on this forum by amrbekhit: discussions/viewtopic.php/f,12/t,23167.html along with the google group posts he links in his post I made these additions to the DTS file:

Code: Select all

	clocks {
		#address-cells = <1>;
		#size-cells = <1>;
		ranges;

		main_clock: clk@0 {
			compatible = "atmel,osc", "fixed-clock";
				clock-frequency = <12000000>;
		};
		
		main_xtal { 
			clock-frequency = <12000000>; 
		}; 
		
		mcp251x_clock: clk@1 {
			compatible = "fixed-clock";
			#clock-cells = <0>;
			clock-frequency = <16000000>; // 16MHz
		};

	};

...


			spi0: spi@f0000000 {
				status = "okay";
				cs-gpios = <&pioA 14 0>, <&pioA 7 0>, <0>, <0>;
				
				can0: can@0 {
					compatible = "microchip,mcp2515";
					 reg = <0>;
					 spi-max-frequency= <10000000>; // 10MHz
					 clock-names = <&mcp251x_clock>, "mcp251x_clock";
					 interrupt-parent = <&pioA>; 
					 interrupts = <3 0x2>;
      				};
	
				device@1 {
					compatible = "spidev";
					// spi-max-frequency = <50000000>;  // 50 MHz
					spi-max-frequency = <5000000>;	    // 5 MHz
					reg = <1>;
				};
			};
Then looking at the output of

Code: Select all

root@acmeboard:~# dmesg | grep 'spi\|can\|mcp'                                  
atmel_spi f0000000.spi: version: 0x212                                          
atmel_spi f0000000.spi: Using dma0chan0 (tx) and dma0chan1 (rx) for DMA transfes
atmel_spi f0000000.spi: Atmel SPI Controller at 0xf0000000 (irq 34)             
atmel_spi f0000000.spi: registered master spi32766 (dynamic)                    
spi spi32766.0: setup: bpw 8 mode 0x0 -> csr0 00000002                          
spi spi32766.0: setup mode 0, 8 bits/w, 10000000 Hz max --> 0                   
atmel_spi f0000000.spi: registered child spi32766.0                             
spi spi32766.1: setup: bpw 8 mode 0x0 -> csr1 00000002                          
spi spi32766.1: setup mode 0, 8 bits/w, 5000000 Hz max --> 0                    
atmel_spi f0000000.spi: registered child spi32766.1                             
mcp251x: probe of spi32766.0 failed with error -2                               
can: controller area network core (rev 20120528 abi 9)                          
can: raw protocol (rev 20120528)                                                
can: broadcast manager protocol (rev 20120528 t)                                
can: netlink gateway (rev 20130117) max_hops=1 
I get the error mcp251x: probe of spi32766.0 failed with error -2

I also cannot see an MCP2515 interupt:

Code: Select all

root@acmeboard:~# cat /proc/interrupts                                          
           CPU0                                                                 
 16:      14311  atmel-aic   1  pmc, at91_tick, at91_rtc, ttyS0                 
 17:          0       PMC  17  main_rc_osc                                      
 18:          0       PMC   0  main_osc                                         
 19:          0       PMC  16  mainck                                           
 20:          0       PMC   1  clk-plla                                         
 21:          1       PMC   6  clk-utmi                                         
 22:          0       PMC   3  clk-master                                       
 23:     207409  atmel-aic  17  tc_clkevt                                       
 24:        993  atmel-aic  20  at_hdmac                                        
 25:          0  atmel-aic  21  at_hdmac                                        
 28:      92236  atmel-aic  12  f0008000.mmc                                    
 34:          0  atmel-aic  13  f0000000.spi                                    
 36:          0  atmel-aic  24  eth0                                            
 37:          0  atmel-aic  22  ehci_hcd:usb1                                   
Err:          0  
These problems are similar to the ones in the google group amrbekhit linked: https://groups.google.com/forum/#!msg/a ... 697jxGhqwJ
However as suggested in the group changing the clock node definition does not fix the problems.

Any help with this would be much appreciated.

Thanks.
gdp
Posts: 3
Joined: Fri Oct 23, 2015 2:58 pm

Re: MCP2515 on Aria G25 (AT91SAM9G25)

Fri Oct 23, 2015 5:24 pm

Fixed issue with probe failing following instructions here: https://groups.google.com/forum/#!searc ... _wRVm_q4EJ

However I now have the issue:

Code: Select all

root@acmeboard:~# ifconfig can0 up                                              
mcp251x spi32766.0 can0: bit-timing not yet defined                             
mcp251x spi32766.0: unable to set initial baudrate!                             
SIOCSIFFLAGS: Invalid argument
Running:

Code: Select all

ip link set can0 type can bitrate 125000 triple-sampling on
the command hangs. If I omit triple sampling the command executes but then ifconfig can0 up hangs.
gdp
Posts: 3
Joined: Fri Oct 23, 2015 2:58 pm

Re: MCP2515 on Aria G25 (AT91SAM9G25)

Tue Oct 27, 2015 6:25 pm

As I mentioned in my post above the command ifconfig can0 up hangs. I am able to continue to use the board by using SSH after I have run said command via the serial interface.

Using ps aux I can see that ifconfig is in state D which is uninteruptable hence the programme hangs.

Code: Select all

root      2087  0.0  0.4   1896  1112 ttyS0    D+   01:01   0:00 ifconfig can0 up
root      2088  0.0  0.0      0     0 ?        D    01:01   0:00 [irq/41-mcp251x]
root      2089  0.0  0.0      0     0 ?        S<   01:01   0:00 [mcp251x_wq]
I can also see the process irq/41-mcp251x which is also state D, this process appears to be a process that is waiting for an interrupt? From this I assume that ifconfig is hanging because it is waiting for the interrupt from the mcp251x.

If I look at /proc/interrupts after the ifconfig command has been run i see an extra line in addition to those shown in the very first post.

Code: Select all

           CPU0       
 16:       2770  atmel-aic   1  pmc, at91_tick, at91_rtc, ttyS0
 17:          0       PMC  17  main_rc_osc
 18:          0       PMC   0  main_osc
 19:          0       PMC  16  mainck
 20:          0       PMC   1  clk-plla
 21:          1       PMC   6  clk-utmi
 22:          0       PMC   3  clk-master
 23:     631605  atmel-aic  17  tc_clkevt
 24:        962  atmel-aic  20  at_hdmac
 25:          0  atmel-aic  21  at_hdmac
 28:      54059  atmel-aic  12  f0008000.mmc
 34:         14  atmel-aic  13  f0000000.spi
 36:       5151  atmel-aic  24  eth0
 37:          0  atmel-aic  22  ehci_hcd:usb1
 41:          1      GPIO   3
Err:          0
So here I can see the interrupt 41, which I assume is the one the irq/41-mcp251x process is listening for, it appears it has been triggered once. Unlike the other interrupts there is nothing in the 5th column, I couldn't find much information about what exactly the 5th column shows but I imagine it's something to do with the process/device that handles the interrupt.

The only place I declare anything to do with the interrupts is in acme-aria.dts.
I modified this slightly from my first post to conform to the recommendations in the Linux Documentation/devicetree/bindings/interrupt-controller/atmel,aic.txt which is for the atmel,at91rm9200-aic which is the one declared in at91sam9x5.dtsi.
According to the documentation:
The first cell is the IRQ number (aka "Peripheral IDentifier" on datasheet).
The second cell is used to specify flags:
bits[3:0] trigger type and level flags:
1 = low-to-high edge triggered.
2 = high-to-low edge triggered.
4 = active high level-sensitive.
8 = active low level-sensitive.
Valid combinations are 1, 2, 3, 4, 8.
Default flag for internal sources should be set to 4 (active high).
The third cell is used to specify the irq priority from 0 (lowest) to 7
(highest).
Therefore I modified the can0 declaration in the dts file to be:

Code: Select all

				can0: can@0 {
					compatible = "microchip,mcp2515";
					reg = <0>;
					spi-max-frequency= <10000000>; // 10MHz
					oscillator_frequency = <16000000>; // 16MHz 		
					//clock-names = <&mcp251x_clock>, "mcp251x_clock";
					interrupt-parent = <&pioA>; 
					interrupts = <3 2 7>;
      				};
Therefore pin A3 is being used, it is high-to-low edge triggered and is of the highest priority. Pin A3 is the pin I have physically wired to the not INT pin on the MCP2515.

From all this I believe there is something wrong with the way the interrupts are being set but I am not sure where I have gone wrong, is anyone able to help with this?
methos
Posts: 6
Joined: Fri Jan 04, 2019 5:37 pm

Re: MCP2515 on Aria G25 (AT91SAM9G25)

Tue May 21, 2019 11:07 pm

Where you ever able to resolve this issue? I am having a similar problem on the AT91SAMA5D4.

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 6 guests