• AVR Freaks

Hot!Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch

Author
PhreakShow
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2011/05/13 01:35:01
  • Location: 0
  • Status: offline
2019/11/28 06:16:21 (permalink)
0

Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch

Hi.
 
I am using the ethernet starter kit (the first version DM320004) and the sample project "CAN to ethernet bridge" as basis. The code is working fine, the only adjustment I made was disabling DHCP server and client, and set the IP manually to 192.168.1.60. Ping is working, everything ok.
 
Now I want the same project to run on different hardware. Three major differences there:
PIC32MX795F512H instead of the 512L, MII instead of RMII, and a KSZ8873 instead of the DP83848 PHY.
 
I changed the defines for using RMII and set the new processor type, the code compiles after disabling a few accessses to pins that the 64-pin device does not have, I think it was an LED and a button. I also set the PHY address to 3, because it is connected to port 3 of the KSZ. Code compiles without error.
 
But I cannot ping the PIC. I can see activity on the RX lines between PIC and KSZ while pinging, and it stops after I stop pinging, but there is neither an answer nor activity on the TX lines. I also get a link LED on the desktop switch, where I connected the magjack and port 2 of the KSZ. There's a clean 25MHz clock between PIC and KSZ, between pin 55 "ETXCLK" and pin 26 "SMTXC3" on the KSZ.
 
How would you start debugging this? I stepped through the code and there's the "MACInit()" call, which tries to set loopback and isolate, but the latter is not supported on the KSZ. So I bypassed the PHY stuff, sending success back to the caller.
 
Thanks
post edited by PhreakShow - 2019/11/28 07:14:30
#1

7 Replies Related Threads

    ncrews
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2019/08/12 13:50:13
    • Location: 0
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/11/28 10:45:27 (permalink)
    0
    Start with PHY Address at 0, not 3. PHY 0 is the broadcast address that will communicate with any PHY regardless of its address. I'm doubting that your PHY address is 3. I know the KSZ, but not your model. On the KSZ and LAN models of PHY that I have used, the address is set via bootstrap.
     
    More generally, I suggest focusing your troubleshooting efforts first on the communication between the MAC and PHY. For example: 
    * Can you read and write to the PHY registers? The first 7 registers are standard rather than vendor-specific.
    * What Ethernet source are you using to test it? If you have control of it and can monitor the line, then I'd also say put the PHY into "echo" mode and check that it is able to bounce back packets to the sender.
    #2
    PhreakShow
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2011/05/13 01:35:01
    • Location: 0
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/11/28 14:40:13 (permalink)
    0
    The PHY's address on port 3 is not mentioned among the other ports, I just assumed it to be 3. Changed it to 0, without a change.
     
    I am also not sure if I can read the PHY's registers. In the stack provided, there's a function _PhyDetectReset(), which tries to communicate with the PHY. One of the first calls within this function is:
     
    bmcon.w=EthMIIMReadReg(PHY_REG_BMCON, _PhyAdd); // read the BMCON register
     
    bmcon.w yields 0 for every member of the enum. I wondered if it is communicating at all. Then I added another line:
     
    bmstat.w=EthMIIMReadReg(PHY_REG_BMSTAT, _PhyAdd); // read the BMSTAT register
     
    This yields 1 for every member. And now I am confused... if communication failed, why would it yield 1.
     
    Actually I am confused a bit more. Why does the MAC have to configure the PHY in the first place? And, furthermore, it seems to me the registers of port 3 (where my PIC is connected to) doesnt seem to be accessible over MIIM.
     
    http://ww1.microchip.com/downloads/en/DeviceDoc/KSZ8873MML-Integrated-3-Port-10-100-Managed-Switch-with-PHY-DS00002776A.pdf
     
    My ethernet source right now is a 16-port switch I have at my desktop, it is connected to my router and my PC. I doubt that the KSZ8873 is capable of echo mode, at least the word does not appear in the datasheet. Or is it the same as loopback mode?
    #3
    PhreakShow
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2011/05/13 01:35:01
    • Location: 0
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/11/28 15:01:08 (permalink)
    0
    As I cannot edit my post:
     
    I just dug deeper into this brilliant sample project. At the press of a button, I can have it ping my router once per second. I disabled the check for button presses and had it ping it continuously once per sec.
    Then I fired up Wireshark at my PC and I am receiving the arp requests of my PIC, going to my router:
     
    11 0.591413 80:1f:12:86:d9:b9 Broadcast ARP 60 Who has 192.168.1.1? Tell 192.168.1.60
     
    In my opinion, the outgoing traffic seems to be switched correctly to my network?
    #4
    ric
    Super Member
    • Total Posts : 27979
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/11/28 15:14:08 (permalink)
    0
    PhreakShow
    As I cannot edit my post:

    Sorry, I can't help with your real problem, but I can explain this one.
    It is because of the live URL to a pdf file on the Microchip website that you posted. If you "break" the link while editing, you CAN edit the post.
    See: How to avoid errors when editing posts
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    PhreakShow
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2011/05/13 01:35:01
    • Location: 0
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/12/02 06:09:44 (permalink)
    0
    The weird thing is: It seems to work for outgoing packets.
     
    I can see ARP requests coming from the board, and I can see UDP broadcasts (the ones with with DHCP/power events).
     
    And I can see data going from the KSZ to the PIC, but it seems like it is not reacting to it?
    #6
    PhreakShow
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2011/05/13 01:35:01
    • Location: 0
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/12/04 10:58:42 (permalink)
    0
    Another Update:
     
    I measured all traces going between the PIC and the KSZ, they are ok. There's TX and RX clock, there's data on all 4+4 data lines, RXERR is tied directly to ground, I can see packets being transmitted.
     
    But there's a function call to  res=EthRxGetBuffer(&pNewPkt, &pRxPktStat) in MACGetHeader(), located in the ETHPIC32IntMac.c file, that seems to be part of the problem. res is always equal to ETH_RES_PACKET_QUEUED.
     
    I read in the forum, das this might occur if the packet is crippled, because of bad soldering or a wrong ERXERR pin. But I checked for these issues, soldering and error pin are ok.
     
     
    #7
    PhreakShow
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2011/05/13 01:35:01
    • Location: 0
    • Status: offline
    Re: Migrate Ethernet Starter Kit sample project to different PIC32 with KSZ8873 switch 2019/12/13 16:58:31 (permalink)
    0
    A small update:
     
    I designed a small board with just the PIC32, a KSZ8081MNX PHY, a magjack, and the neccessary power supply bits.
     
    The connection between PIC and PHY is the same, although on the KSZ8873 the names are crossed, i.e. all TX pins go to RX pins and vice versa. With the PHY, the connections are not crossed. The KSZ is in PHY mode, and the datasheet confirms that in this case the signals have to be crossed.
     
    The KSZ does not support TX/RX error, so they are tied low. With the PHY, the lines are connected. That is the only difference. And the exact same code that refuses to answer pings, works on the new board I designed.
     
    Not sure why this is the case, though. Port3 of the KSZ8873 does not allow access to MIIM registers, but with the PHY, this access is possible. Could this be the problem, that the PIC's stack need access to the MIIM registers?
    Then I'd have to swap the PIC to port 1 of the KSZ, set it to PHY mode, and connect the IC i had on port 1 to port 3?
     
    What do you think, could this be the problem?
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5