Initializing LAN9252 as a ethercat slave

Hi community…!

i am using Toradex-colibri evaluation board IMX7 like i am working on ethercat communication using spi by spidev python library
I have working code on C in that everything is working good now i converted that code into python initialization itself failed can you please help me to fix this issue like some basic code for lan9252 with toradex some sample codes

here is the code for ur reference

RESET_CTL = 0x01F8
DIGITAL_RST = 0x00000001
ETHERCAT_RST = 0x00000040

initialize / check the etc interface on SPI, return true if initialization is ok

def etc_init():
TempLong = ULONG()

Etc_Write_Reg(RESET_CTL, (DIGITAL_RST & ETHERCAT_RST)) # Need to check "AND" Operator              
time.sleep(0.3)                                                                         
TempLong.LANLong = Etc_Read_Reg(BYTE_TEST, 4)          # read test register   
                                                                              
if TempLong != 0x87654321:                                                           
    print("Bad response received from Etc Test command, data received =", TempLong.LANLong)                              
    return False                                                                                   
                                                                                        
TempLong.LANLong = Etc_Read_Reg(HW_CFG, 4)        # check also the READY flag 
                                                                              
if((TempLong.LANLong & READY) == 0 ):                                                
    print("Ready not received from Etc HW Cfg, data received =", TempLong.LANLong)                                       
    return False                                                                                   
                                                                                        
print("Etc Test Command succeeded\n")                                                
return True   

def Etc_Read_Reg(address, length):
Result = ULONG() # Initialize Result as ULONG instance
Addr = UWORD() # Initialize Addr as UWORD instance and set address
xfrbuf = (ctypes.c_uint8 * 7)() # Create buffer for SPI transfer

Addr.LANWord = address                                                                                                                                 
                                                                                                                         
xfrbuf[0] = COMM_SPI_READ  # SPI read command                                                                            
xfrbuf[1] = Addr.LANByte[1]  # Address high byte                                           
xfrbuf[2] = Addr.LANByte[0]  # Address low byte                                         
                                                                              
for i in range(length):                                                                                                                                
    xfrbuf[i + 3] = DUMMY_BYTE  # Fill dummy bytes after address bytes                                                   
                                                                                                                         
response = spi.xfer2(list(xfrbuf))  # Perform SPI transfer and receive response                    
                                                                                        
for i in range(length):                                                       
    Result.LANByte[i] = response[i + 3]  # Assign received bytes to Result.LANByte[i]                                                                  
return Result.LANLong                                                                                                    

write a directly addressable register, 4 bytes always

Address = register to write, DataOut = data to write

def Etc_Write_Reg(address, DataOut):
Data = ULONG()
Addr = UWORD()
xfrbuf = (ctypes.c_uint8 * 7)() # Create buffer for SPI transfer

Addr.LANWord = address                                                                                                   
Data.LANLong = DataOut                                                                                                   
                                                                                                   
xfrbuf[0] = COMM_SPI_WRITE     # SPI write command                                      
xfrbuf[1] = Addr.LANByte[1]    # address of the register                      
xfrbuf[2] = Addr.LANByte[0]    # to read, MsByte first                         
                                                                                                                         
for i in range(4):                                                                                                       
    xfrbuf[i+3] = Data.LANByte[i]       # Fill data bytes, lsb                                     
                                                                                        
# Transmit function                                                                  
response = spi.xfer2(list(xfrbuf))  # Perform SPI transfer and receive response

def main():
# Initialize EtherCAT interface
if not etc_init():
print(“EtherCAT initialization failed”)
return

if name == “main”:
main()

Hi @uday1012,
Unfortunately, we do not have any sample code for the same either in C or in python.