2018-06-28 06:04 AM
Hello, im generating default ethernet codes from CubeMX. im using freertos+lwip and i set static ip. All other lwip settings are default. My clock config:
My default lwIP settings:
My default FreeRtos settings:
And i use simple below iperf codes for test.
void iperfthread(void *arg) { ethernetif_input(&gnetif); } void iperf_test_start(void) { sys_thread_new(''iperfthread'', iperfthread, NULL, 128, osPriorityRealtime ); } static err_t iperf_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { LWIP_UNUSED_ARG(arg); if (err == ERR_OK && p != NULL) { tcp_recved(pcb, p->tot_len); pbuf_free(p); } else if (err != ERR_OK && p != NULL) { pbuf_free(p); } if (err == ERR_OK && p == NULL) { tcp_arg(pcb, NULL); tcp_sent(pcb, NULL); tcp_recv(pcb, NULL); tcp_close(pcb); } return ERR_OK; } static err_t iperf_accept(void *arg, struct tcp_pcb *pcb, err_t err) { LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(err); tcp_arg(pcb, NULL); tcp_sent(pcb, NULL); tcp_recv(pcb, iperf_recv); return ERR_OK; } void iperf_init(void) { struct tcp_pcb *pcb; pcb = tcp_new(); tcp_bind(pcb, IP_ADDR_ANY, 5001); // bind to iperf port pcb = tcp_listen(pcb); tcp_accept(pcb, iperf_accept); } �?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
im creating simple thread for iperf task. And this is my main
int main(void) { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_RTC_Init(); MX_TIM1_Init(); /* USER CODE BEGIN 2 */ MX_LWIP_Init(); iperf_init(); iperf_test_start(); /* USER CODE END 2 */ /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* USER CODE BEGIN WHILE */ while (1) { } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Test results are so bad. 11-12Mbits/sec.
For nucleo board the speed is 15 Mbps
How can i fix and increase it ?
#cubemx #ethernet #lwip #iperf #discovery Note: this post was migrated and contained many threaded conversations, some content may be missing.2018-06-29 07:40 AM
TCP_MSS is set to 536 bytes. I would increase it to 1460 bytes as the TCP header takes 20 bytes + IP header 20 bytes.
This would fit the Ehernet MTU of 1500 bytes.
The goal is to increase the packet size and reduce time spent on processing headers (to lower the number of packets).
Try to collect some Wireshark traces to prove what packet size is really used.
I have never tested the TCP_MSS value on the STM32. This is general approach to TCP based communication
2018-07-02 12:13 AM
I tried your advice. Its so logical. But there is no change. Unlike, it fixes the speed 191 Kbits/sec after some times. When i manually restart it reaches 15 Mbits/sec again. Is there a problem about buffers or etc. ?
2018-07-02 12:27 AM
I wonder if the change of the MSS really change the packet size. I would capture wireshark traces to see it.
They suggest some improvements here but I have not tested it (I use Ethernet on STM32 sporadically, for pretty low tyransfer):
2018-07-02 12:51 AM
CubeMx default settings allows 1426 bytes for TCP_MSS and i used this value. The below captures for 5.23 Mbits/sec iperf result on disco board.
Wireshark capture :
https://files.fm/down.php?i=5ggqauys
P.S: thank you for document i will investigate on it
2018-07-02 01:22 AM
Could you please check speed/duplex settings between the STM32 and the device the STM32 is connected to (switch?)
2018-07-02 01:28 AM
They should match on both sides of the link (STM32 settings shall match the device setting on the opposite site of the link).
2018-07-02 02:09 AM
I had connected it to 10/100 switch but after your reply i have tested it directly to pc(10/100) still 5-6 Mbps. STM32 setting is auto neg.
2018-07-02 03:13 AM
Both sides of the link should use the same setting of the speed / duplex.
Usually the PC has auto-negotiation configured. If the LWIP has manual settings of 100/full you need to check what PC defaulted to.
The best practice is use auto settings on both sides of the link. If only one side uses auto but the second one uses manual (100/full) you will never know what settings are really used. It&39s a part of the FLP process.
Again, use manual setting on both sides. Check what LWIP is using, then set the same values manually on the PC. I would not rely on auto on one side and manual setting on the other side.
I see a lot of TCP DUP from STM32 and wonder what is the root cause. First wanted to ensure if the PHY layer works fine (we cannot have full duplex on the one side and half on the other side).
The second, I would check the LWIP version and bugs. As far as I remeber the CubeMX used pretty old version (maybe I am wrong).