readme.md
1
2FreeRTOS+TCP driver for STM32H7xx.
3
4Some STM32 network settings are stored in 'stm32h7xx_hal_conf.h'.
5
6Number of DMA descriptors, for transmission and for reception.
7
8The descriptors for transmission are protected with a counting semaphore.
9By the time that a packet has been sent, the other TX descriptor becomes
10available already.
11The number of descriptors has an incluence on the performance. But that also depends on the size
12of the TCP buffers and TCP window sizes.
13
14When ETH_RX_DESC_CNT is too low, the adapter may miss incoming packets, they will be dropped.
15When ETH_RX_DESC_CNT is low, sending packets becomes slower.
16
17Here are settings give a high performance for iperf3:
18
19~~~
20/* ########################### Ethernet Configuration ######################### */
21#define ETH_TX_DESC_CNT 14U /* number of Ethernet Tx DMA descriptors */
22#define ETH_RX_DESC_CNT 8U /* number of Ethernet Rx DMA descriptors */
23~~~
24
25Two more defines that are needed:
26
27~~~
28#define HAL_ETH_MODULE_ENABLED
29#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
30~~~
31
32The following macro's are **not** used by the FreeRTOS driver:
33
34 #define ETH_MAC_ADDR0 ((uint8_t)0x02)
35 #define ETH_MAC_ADDR1 ((uint8_t)0x00)
36 ...
37
38All memory that is shared between the CPU and the DMA ETH peripheral, should be
39located in special RAM area called ".ethernet_data". This shall be declared in
40the linker file.
41
42It is possible to use the AXI SRAM for this, but RAM{1,2,3} are also connected
43to the Ethernet MAC.
44
45Here is an example of the changes to the linker file:
46
47 AXI_RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* .ethernet_data declared here. */
48 .ethernet_data :
49 {
50 PROVIDE_HIDDEN (__ethernet_data_start = .);
51 KEEP (*(SORT(.ethernet_data.*)))
52 KEEP (*(.ethernet_data*))
53 PROVIDE_HIDDEN (__ethernet_data_end = .);
54 } >AXI_RAM
55
56Here is a table of 3 types of STH32H7 :
57
58|RAM area |H747|H743|H742|Location |
59|-----------|----|----|----|----------|
60|DTCM |128k|128k|128k|0x20000000|
61|AXI-SRAM |511k|511k|384k|0x24000000|
62|SRAM1 |128k|128k|32k |0x30000000|
63|SRAM2 |128k|128k|16k |0x30020000|
64|SRAM3 |32k | 32k| - |0x30040000|
65|SRAM4 |64k |64k |64k |0x38000000|
66|Backup SRAM|4k |4k |4k |0x38800000|
67
68
69Please make sure that the addresses and lengths are correct for your model of STM32H7xx.
70If you use a memory that is not supported, it will result in a DMA errors.
71
72In FreeRTOSIPConfig.h :
73
74Define the total number of network buffer descriptors, e.g. 64:
75
76~~~
77 #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ( 64 )
78~~~
79
80It is recommended to use the zero-copy method for both reception and transmission:
81
82~~~
83 #define ipconfigZERO_COPY_RX_DRIVER ( 1 )
84 #define ipconfigZERO_COPY_TX_DRIVER ( 1 )
85~~~
86
87The copy-method also works well, may just a little slower.
88
89Checksum cal be calculated in the Ethernet MAC, which is faster than doing manual calculations:
90
91~~~
92 /* The checksums will be checked and calculated by the STM32F4x ETH peripheral. */
93 #define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM ( 1 )
94 #define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM ( 1 )
95~~~
96
97The most important DMAC registers, along with their names which are used in the reference manual:
98
99 __IO uint32_t DMAMR; // ETH_DMAMR DMA mode register
100 __IO uint32_t DMAISR; // ETH_DMAISR DMA Interrupt status register
101 __IO uint32_t DMADSR; // ETH_DMADSR DMA Debug status register
102 __IO uint32_t DMACCR; // ETH_DMACCR DMA Channel control register
103 __IO uint32_t DMACTCR; // ETH_DMACTXCR Channel Tx transmit control register
104 __IO uint32_t DMACRCR; // ETH_DMACRXCR Channel Rx receive control register
105 __IO uint32_t DMACTDLAR; // ETH_DMACTXDLAR Channel Tx descriptor list address register
106 __IO uint32_t DMACRDLAR; // ETH_DMACRXDLAR Channel Rx descriptor list address register
107 __IO uint32_t DMACTDTPR; // ETH_DMACTXDTPR Channel TX tail pointer
108 __IO uint32_t DMACRDTPR; // ETH_DMACRXDTPR Channel RX tail pointer
109 __IO uint32_t DMACTDRLR; // ETH_DMACTXRLR Channel Tx descriptor ring length register
110 __IO uint32_t DMACRDRLR; // ETH_DMACRXRLR Channel Rx descriptor ring length register
111 __IO uint32_t DMACIER; // ETH_DMACIER Channel interrupt enable register
112 __IO uint32_t DMACRIWTR; // ETH_DMACRXIWTR Channel Rx interrupt watchdog timer register
113 __IO uint32_t DMACCATDR; // ETH_DMACCATXDR Channel Tx current application transmit descriptor register
114 __IO uint32_t DMACCARDR; // ETH_DMACCARXDR Channel Rx current application receive descriptor register
115 __IO uint32_t DMACCATBR; // ETH_DMACCATXBR Channel Tx current application transmit buffer register
116 __IO uint32_t DMACCARBR; // ETH_DMACCARXBR Channel Rx current application receive buffer register
117 __IO uint32_t DMACSR; // ETH_DMACSR Channel status register
118
119
120As most EMAC's, the STM32H7 EMAC is able to put packets in multiple linked DMA segments.
121FreeRTOS+TCP never uses this feature. Each packet is stored in a single buffer called
122`NetworkBufferDescriptor_t`.
123