mikroSDK Reference Manual
stm32h5xx_eth_driver.h
Go to the documentation of this file.
1
31#ifndef _STM32H5XX_ETH_DRIVER_H
32#define _STM32H5XX_ETH_DRIVER_H
33
34//Dependencies
35#include "core/nic.h"
36
37//Number of TX buffers
38#ifndef STM32H5XX_ETH_TX_BUFFER_COUNT
39 #define STM32H5XX_ETH_TX_BUFFER_COUNT 8
40#elif (STM32H5XX_ETH_TX_BUFFER_COUNT < 1)
41 #error STM32H5XX_ETH_TX_BUFFER_COUNT parameter is not valid
42#endif
43
44//TX buffer size
45#ifndef STM32H5XX_ETH_TX_BUFFER_SIZE
46 #define STM32H5XX_ETH_TX_BUFFER_SIZE 1536
47#elif (STM32H5XX_ETH_TX_BUFFER_SIZE != 1536)
48 #error STM32H5XX_ETH_TX_BUFFER_SIZE parameter is not valid
49#endif
50
51//Number of RX buffers
52#ifndef STM32H5XX_ETH_RX_BUFFER_COUNT
53 #define STM32H5XX_ETH_RX_BUFFER_COUNT 8
54#elif (STM32H5XX_ETH_RX_BUFFER_COUNT < 1)
55 #error STM32H5XX_ETH_RX_BUFFER_COUNT parameter is not valid
56#endif
57
58//RX buffer size
59#ifndef STM32H5XX_ETH_RX_BUFFER_SIZE
60 #define STM32H5XX_ETH_RX_BUFFER_SIZE 1536
61#elif (STM32H5XX_ETH_RX_BUFFER_SIZE != 1536)
62 #error STM32H5XX_ETH_RX_BUFFER_SIZE parameter is not valid
63#endif
64
65//Interrupt priority grouping
66#ifndef STM32H5XX_ETH_IRQ_PRIORITY_GROUPING
67 #define STM32H5XX_ETH_IRQ_PRIORITY_GROUPING 3
68#elif (STM32H5XX_ETH_IRQ_PRIORITY_GROUPING < 0)
69 #error STM32H5XX_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
70#endif
71
72//Ethernet interrupt group priority
73#ifndef STM32H5XX_ETH_IRQ_GROUP_PRIORITY
74 #define STM32H5XX_ETH_IRQ_GROUP_PRIORITY 12
75#elif (STM32H5XX_ETH_IRQ_GROUP_PRIORITY < 0)
76 #error STM32H5XX_ETH_IRQ_GROUP_PRIORITY parameter is not valid
77#endif
78
79//Ethernet interrupt subpriority
80#ifndef STM32H5XX_ETH_IRQ_SUB_PRIORITY
81 #define STM32H5XX_ETH_IRQ_SUB_PRIORITY 0
82#elif (STM32H5XX_ETH_IRQ_SUB_PRIORITY < 0)
83 #error STM32H5XX_ETH_IRQ_SUB_PRIORITY parameter is not valid
84#endif
85
86//Name of the section where to place DMA buffers
87#ifndef STM32H5XX_ETH_RAM_SECTION
88 #define STM32H5XX_ETH_RAM_SECTION ".ram_no_cache"
89#endif
90
91//ETH_MACCR register
92#define ETH_MACCR_RESERVED15 0x00008000
93
94//ETH_MMCRIMR register
95#ifndef ETH_MMCRIMR_RXLPITRCIM
96 #define ETH_MMCRIMR_RXLPITRCIM 0x08000000
97 #define ETH_MMCRIMR_RXLPIUSCIM 0x04000000
98 #define ETH_MMCRIMR_RXUCGPIM 0x00020000
99 #define ETH_MMCRIMR_RXALGNERPIM 0x00000040
100 #define ETH_MMCRIMR_RXCRCERPIM 0x00000020
101#endif
102
103//ETH_MMCTIMR register
104#ifndef ETH_MMCTIMR_TXLPITRCIM
105 #define ETH_MMCTIMR_TXLPITRCIM 0x08000000
106 #define ETH_MMCTIMR_TXLPIUSCIM 0x04000000
107 #define ETH_MMCTIMR_TXGPKTIM 0x00200000
108 #define ETH_MMCTIMR_TXMCOLGPIM 0x00008000
109 #define ETH_MMCTIMR_TXSCOLGPIM 0x00004000
110#endif
111
112//Transmit normal descriptor (read format)
113#define ETH_TDES0_BUF1AP 0xFFFFFFFF
114#define ETH_TDES1_BUF2AP 0xFFFFFFFF
115#define ETH_TDES2_IOC 0x80000000
116#define ETH_TDES2_TTSE 0x40000000
117#define ETH_TDES2_B2L 0x3FFF0000
118#define ETH_TDES2_VTIR 0x0000C000
119#define ETH_TDES2_B1L 0x00003FFF
120#define ETH_TDES3_OWN 0x80000000
121#define ETH_TDES3_CTXT 0x40000000
122#define ETH_TDES3_FD 0x20000000
123#define ETH_TDES3_LD 0x10000000
124#define ETH_TDES3_CPC 0x0C000000
125#define ETH_TDES3_SAIC 0x03800000
126#define ETH_TDES3_THL 0x00780000
127#define ETH_TDES3_TSE 0x00040000
128#define ETH_TDES3_CIC 0x00030000
129#define ETH_TDES3_FL 0x00007FFF
130
131//Transmit normal descriptor (write-back format)
132#define ETH_TDES0_TTSL 0xFFFFFFFF
133#define ETH_TDES1_TTSH 0xFFFFFFFF
134#define ETH_TDES3_OWN 0x80000000
135#define ETH_TDES3_CTXT 0x40000000
136#define ETH_TDES3_FD 0x20000000
137#define ETH_TDES3_LD 0x10000000
138#define ETH_TDES3_TTSS 0x00020000
139#define ETH_TDES3_ES 0x00008000
140#define ETH_TDES3_JT 0x00004000
141#define ETH_TDES3_FF 0x00002000
142#define ETH_TDES3_PCE 0x00001000
143#define ETH_TDES3_LOC 0x00000800
144#define ETH_TDES3_NC 0x00000400
145#define ETH_TDES3_LC 0x00000200
146#define ETH_TDES3_EC 0x00000100
147#define ETH_TDES3_CC 0x000000F0
148#define ETH_TDES3_ED 0x00000008
149#define ETH_TDES3_UF 0x00000004
150#define ETH_TDES3_DB 0x00000002
151#define ETH_TDES3_IHE 0x00000001
152
153//Transmit context descriptor
154#define ETH_TDES0_TTSL 0xFFFFFFFF
155#define ETH_TDES1_TTSH 0xFFFFFFFF
156#define ETH_TDES2_IVT 0xFFFF0000
157#define ETH_TDES2_MSS 0x00003FFF
158#define ETH_TDES3_OWN 0x80000000
159#define ETH_TDES3_CTXT 0x40000000
160#define ETH_TDES3_OSTC 0x08000000
161#define ETH_TDES3_TCMSSV 0x04000000
162#define ETH_TDES3_CDE 0x00800000
163#define ETH_TDES3_IVLTV 0x00020000
164#define ETH_TDES3_VLTV 0x00010000
165#define ETH_TDES3_VT 0x0000FFFF
166
167//Receive normal descriptor (read format)
168#define ETH_RDES0_BUF1AP 0xFFFFFFFF
169#define ETH_RDES2_BUF2AP 0xFFFFFFFF
170#define ETH_RDES3_OWN 0x80000000
171#define ETH_RDES3_IOC 0x40000000
172#define ETH_RDES3_BUF2V 0x02000000
173#define ETH_RDES3_BUF1V 0x01000000
174
175//Receive normal descriptor (write-back format)
176#define ETH_RDES0_IVT 0xFFFF0000
177#define ETH_RDES0_OVT 0x0000FFFF
178#define ETH_RDES1_OPC 0xFFFF0000
179#define ETH_RDES1_TD 0x00008000
180#define ETH_RDES1_TSA 0x00004000
181#define ETH_RDES1_PV 0x00002000
182#define ETH_RDES1_PFT 0x00001000
183#define ETH_RDES1_PMT 0x00000F00
184#define ETH_RDES1_IPCE 0x00000080
185#define ETH_RDES1_IPCB 0x00000040
186#define ETH_RDES1_IPV6 0x00000020
187#define ETH_RDES1_IPV4 0x00000010
188#define ETH_RDES1_IPHE 0x00000008
189#define ETH_RDES1_PT 0x00000007
190#define ETH_RDES2_L3L4FM 0xE0000000
191#define ETH_RDES2_L4FM 0x10000000
192#define ETH_RDES2_L3FM 0x08000000
193#define ETH_RDES2_MADRM 0x07F80000
194#define ETH_RDES2_HF 0x00040000
195#define ETH_RDES2_DAF 0x00020000
196#define ETH_RDES2_SAF 0x00010000
197#define ETH_RDES2_VF 0x00008000
198#define ETH_RDES2_ARPRN 0x00000400
199#define ETH_RDES3_OWN 0x80000000
200#define ETH_RDES3_CTXT 0x40000000
201#define ETH_RDES3_FD 0x20000000
202#define ETH_RDES3_LD 0x10000000
203#define ETH_RDES3_RS2V 0x08000000
204#define ETH_RDES3_RS1V 0x04000000
205#define ETH_RDES3_RS0V 0x02000000
206#define ETH_RDES3_CE 0x01000000
207#define ETH_RDES3_GP 0x00800000
208#define ETH_RDES3_RWT 0x00400000
209#define ETH_RDES3_OE 0x00200000
210#define ETH_RDES3_RE 0x00100000
211#define ETH_RDES3_DE 0x00080000
212#define ETH_RDES3_LT 0x00070000
213#define ETH_RDES3_ES 0x00008000
214#define ETH_RDES3_PL 0x00007FFF
215
216//Receive context descriptor
217#define ETH_RDES0_RTSL 0xFFFFFFFF
218#define ETH_RDES1_RTSH 0xFFFFFFFF
219#define ETH_RDES3_OWN 0x80000000
220#define ETH_RDES3_CTXT 0x40000000
221
222//C++ guard
223#ifdef __cplusplus
224extern "C" {
225#endif
226
227
232typedef struct
233{
234 uint32_t tdes0;
235 uint32_t tdes1;
236 uint32_t tdes2;
237 uint32_t tdes3;
239
240
245typedef struct
246{
247 uint32_t rdes0;
248 uint32_t rdes1;
249 uint32_t rdes2;
250 uint32_t rdes3;
252
253
254//STM32H5 Ethernet MAC driver
255extern const NicDriver stm32h5xxEthDriver;
256
257//STM32H5 Ethernet MAC related functions
258error_t stm32h5xxEthInit(NetInterface *interface);
259void stm32h5xxEthInitGpio(NetInterface *interface);
260void stm32h5xxEthInitDmaDesc(NetInterface *interface);
261
262void stm32h5xxEthTick(NetInterface *interface);
263
264void stm32h5xxEthEnableIrq(NetInterface *interface);
265void stm32h5xxEthDisableIrq(NetInterface *interface);
266void stm32h5xxEthEventHandler(NetInterface *interface);
267
268error_t stm32h5xxEthSendPacket(NetInterface *interface,
269 const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
270
271error_t stm32h5xxEthReceivePacket(NetInterface *interface);
272
273error_t stm32h5xxEthUpdateMacAddrFilter(NetInterface *interface);
274error_t stm32h5xxEthUpdateMacConfig(NetInterface *interface);
275
276void stm32h5xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
277 uint8_t regAddr, uint16_t data);
278
279uint16_t stm32h5xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
280 uint8_t regAddr);
281
282uint32_t stm32h5xxEthCalcCrc(const void *data, size_t length);
283
284//C++ guard
285#ifdef __cplusplus
286}
287#endif
288
289#endif
error_t
Error codes.
Definition error.h:43
Network interface controller abstraction layer.
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89
NIC driver.
Definition nic.h:283
Receive descriptor.
Definition stm32h5xx_eth_driver.h:246
Transmit descriptor.
Definition stm32h5xx_eth_driver.h:233