cancel
Showing results for 
Search instead for 
Did you mean: 

Two KSZ8851SNL on STM32, working like a hub

Jack3
Senior II

I have two KSZ8851SNL connected to an STM32H7 board.

In a certain operating mode, I would like to make a 'transparent' connection (on link level) between the two interfaces, so the board with the two interfaces acts like a simple hub.

So if I receive a packet on interface 1, I send it to 2, and the other way around.

This works, if I connect two devices that talk to each other (talking modbus-TCP slave and master).

It works partially when I connect a PC (windows 10) and a HMI device.

I can use ftp and see the disk contents on the device in a windows file explorer.

Then I can drag and drop files, but only if they are small, like up to 2kB, sometimes up to 7kB. Then the connection just times out.

One problem with this KSZ8851 chip is that I need to flush the queue after I received (and read) data, otherwise it stops working, it's state machine locks up.

But it may flush new received data, which may be the culprit here.

So basically, I'm trying to make a 'transparent' connection like this:

while (1)
{
    pRXLength = ksz8851_Receive(&KSZ8851_interface_0, pRXData, MAX_FRAMELEN);
    // Pass if packet is > size of headers: ETH(14) + IP(20) + TCP(20)
    if (pRXLength > MB_HDR_OFFSET)
    {
        // We need to do this for this to keep the KSZ8851 statemachine alive
        ksz8851snl_reset_rx(&KSZ8851_interface_0);
        ksz8851_Send(&KSZ8851_interface_1, pRXData, pRXLength);
    }
 
    pRXLength = ksz8851_Receive(&KSZ8851_interface_1, pRXData, MAX_FRAMELEN);
    // Pass if packet is > size of headers: ETH(14) + IP(20) + TCP(20)
    if (pRXLength > MB_HDR_OFFSET)
    {
        // We need to do this for this to keep the KSZ8851 statemachine alive
        ksz8851snl_reset_rx(&KSZ8851_interface_1);
        ksz8851_Send(&KSZ8851_interface_0, pRXData, pRXLength);
    }
}
 

Would this in theory work?

My code is here:

https://github.com/bkht/KSZ8851SNL_no_LwIP

Two WireShark captures (with and without the STM32 board in between:

Copy of a small file using a direct connection, without the board:

     70 3.797695       192.168.25.148        192.168.25.237        FTP      60     Request: noop
     71 3.797704       192.168.25.148        192.168.25.237        TCP      60     [TCP Retransmission] 51126 → 21 [PSH, ACK] Seq=1 Ack=1 Win=1022 Len=6
     72 3.800789       192.168.25.237        192.168.25.148        FTP      84     Response: 200 NOOP command successful.
     73 3.800844       192.168.25.148        192.168.25.237        TCP      54     51126 → 21 [ACK] Seq=7 Ack=31 Win=1022 Len=0
     74 3.800846       192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 73#1] 51126 → 21 [ACK] Seq=7 Ack=31 Win=1022 Len=0
     75 3.800912       192.168.25.148        192.168.25.237        FTP      61     Request: CWD /
     76 3.800915       192.168.25.148        192.168.25.237        TCP      61     [TCP Retransmission] 51126 → 21 [PSH, ACK] Seq=7 Ack=31 Win=1022 Len=7
     77 3.805507       192.168.25.237        192.168.25.148        TCP      60     21 → 51126 [ACK] Seq=31 Ack=14 Win=33501 Len=0
     78 3.814234       192.168.25.237        192.168.25.148        FTP      83     Response: 250 CWD command successful.
     79 3.814285       192.168.25.148        192.168.25.237        TCP      54     51126 → 21 [ACK] Seq=14 Ack=60 Win=1022 Len=0
     80 3.814288       192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 79#1] 51126 → 21 [ACK] Seq=14 Ack=60 Win=1022 Len=0
     81 3.814402       192.168.25.148        192.168.25.237        FTP      59     Request: PWD
     82 3.814406       192.168.25.148        192.168.25.237        TCP      59     [TCP Retransmission] 51126 → 21 [PSH, ACK] Seq=14 Ack=60 Win=1022 Len=5
     83 3.825492       192.168.25.237        192.168.25.148        FTP      63     Response: 257 "/"
     84 3.825551       192.168.25.148        192.168.25.237        TCP      54     51126 → 21 [ACK] Seq=19 Ack=69 Win=1022 Len=0
     85 3.825554       192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 84#1] 51126 → 21 [ACK] Seq=19 Ack=69 Win=1022 Len=0
     86 3.825642       192.168.25.148        192.168.25.237        FTP      61     Request: CWD /
     87 3.825644       192.168.25.148        192.168.25.237        TCP      61     [TCP Retransmission] 51126 → 21 [PSH, ACK] Seq=19 Ack=69 Win=1022 Len=7
     88 3.830270       192.168.25.237        192.168.25.148        TCP      60     21 → 51126 [ACK] Seq=69 Ack=26 Win=33489 Len=0
     89 3.839588       192.168.25.237        192.168.25.148        FTP      83     Response: 250 CWD command successful.
     90 3.839640       192.168.25.148        192.168.25.237        TCP      54     51126 → 21 [ACK] Seq=26 Ack=98 Win=1022 Len=0
     91 3.839643       192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 90#1] 51126 → 21 [ACK] Seq=26 Ack=98 Win=1022 Len=0

Copy of a small file using the two Micrels on the board:

    193 11.069002      192.168.25.148        192.168.25.237        TCP      60     [TCP Retransmission] 51022 → 21 [PSH, ACK] Seq=1 Ack=1 Win=1022 Len=6
    194 11.069069      192.168.25.148        192.168.25.237        TCP      54     51022 → 21 [FIN, ACK] Seq=7 Ack=1 Win=1022 Len=0
    195 11.069071      192.168.25.148        192.168.25.237        TCP      54     [TCP Out-Of-Order] 51022 → 21 [FIN, ACK] Seq=7 Ack=1 Win=1022 Len=0
    196 11.069386      192.168.25.148        192.168.25.237        TCP      66     51030 → 21 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=256 SACK_PERM=1
    197 11.069389      192.168.25.148        192.168.25.237        TCP      66     [TCP Out-Of-Order] 51030 → 21 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=256 SACK_PERM=1
    198 11.074372      192.168.25.237        192.168.25.148        TCP      72     21 → 51030 [SYN, ACK] Seq=0 Ack=1 Win=33580 Len=0 MSS=1460 WS=1 SACK_PERM=1
    199 11.074488      192.168.25.148        192.168.25.237        TCP      54     51030 → 21 [ACK] Seq=1 Ack=1 Win=262144 Len=0
    200 11.074502      192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 199#1] 51030 → 21 [ACK] Seq=1 Ack=1 Win=262144 Len=0
    201 11.079234      192.168.25.237        192.168.25.148        FTP      100    Response: 220 Welcome to IDAL FTP server. READY.
    202 11.079512      192.168.25.148        192.168.25.237        TCP      54     51030 → 21 [ACK] Seq=1 Ack=41 Win=261888 Len=0
    203 11.079515      192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 202#1] 51030 → 21 [ACK] Seq=1 Ack=41 Win=261888 Len=0
    204 11.080027      192.168.25.148        192.168.25.237        FTP      65     Request: USER exor
    205 11.080030      192.168.25.148        192.168.25.237        TCP      65     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=1 Ack=41 Win=261888 Len=11
    207 11.092121      192.168.25.237        192.168.25.148        FTP      96     Response: 331 User name ok, need password.
    208 11.092184      192.168.25.148        192.168.25.237        TCP      54     51030 → 21 [ACK] Seq=12 Ack=75 Win=261888 Len=0
    209 11.092187      192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 208#1] 51030 → 21 [ACK] Seq=12 Ack=75 Win=261888 Len=0
    210 11.092368      192.168.25.148        192.168.25.237        FTP      65     Request: PASS exor
    211 11.092372      192.168.25.148        192.168.25.237        TCP      65     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=12 Ack=75 Win=261888 Len=11
...
    216 11.105868      192.168.25.148        192.168.25.237        TCP      68     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=23 Ack=109 Win=261888 Len=14
    222 11.405750      192.168.25.148        192.168.25.237        TCP      68     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=23 Ack=109 Win=261888 Len=14
    223 11.405764      192.168.25.148        192.168.25.237        TCP      68     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=23 Ack=109 Win=261888 Len=14
    224 11.414376      192.168.25.237        192.168.25.148        FTP      112    Response: 502 Unrecognized or unsupported command: "OPTS".
...
    233 11.426814      192.168.25.148        192.168.25.237        TCP      61     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=42 Ack=168 Win=261888 Len=7
...
    238 11.440732      192.168.25.148        192.168.25.237        TCP      59     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=49 Ack=197 Win=261888 Len=5
...
    241 11.452219      192.168.25.148        192.168.25.237        TCP      54     [TCP Dup ACK 240#1] 51030 → 21 [ACK] Seq=54 Ack=206 Win=261888 Len=0
...
    243 11.452606      192.168.25.148        192.168.25.237        TCP      61     [TCP Retransmission] 51030 → 21 [PSH, ACK] Seq=54 Ack=206 Win=261888 Len=7
...
    299 13.769271      192.168.25.148        192.168.25.237        TCP      60     [TCP Retransmission] 51022 → 21 [FIN, PSH, ACK] Seq=1 Ack=1 Win=1022 Len=6
...
    301 13.771940      192.168.25.237        192.168.25.148        TCP      68     21 → 51022 [RST] Seq=1 Win=0 Len=0

I can see, even though I could copy the small file, it took almost 3 seconds instead of 0.04 seconds. The communication has much trouble.

0 REPLIES 0