stm32f2x7_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file stm32f2x7_eth_driver.h
3  * @brief STM32F207/217 Ethernet MAC controller
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _STM32F2X7_ETH_DRIVER_H
30 #define _STM32F2X7_ETH_DRIVER_H
31 
32 //Dependencies
33 #include "core/nic.h"
34 
35 //Number of TX buffers
36 #ifndef STM32F2X7_ETH_TX_BUFFER_COUNT
37  #define STM32F2X7_ETH_TX_BUFFER_COUNT 3
38 #elif (STM32F2X7_ETH_TX_BUFFER_COUNT < 1)
39  #error STM32F2X7_ETH_TX_BUFFER_COUNT parameter is not valid
40 #endif
41 
42 //TX buffer size
43 #ifndef STM32F2X7_ETH_TX_BUFFER_SIZE
44  #define STM32F2X7_ETH_TX_BUFFER_SIZE 1536
45 #elif (STM32F2X7_ETH_TX_BUFFER_SIZE != 1536)
46  #error STM32F2X7_ETH_TX_BUFFER_SIZE parameter is not valid
47 #endif
48 
49 //Number of RX buffers
50 #ifndef STM32F2X7_ETH_RX_BUFFER_COUNT
51  #define STM32F2X7_ETH_RX_BUFFER_COUNT 6
52 #elif (STM32F2X7_ETH_RX_BUFFER_COUNT < 1)
53  #error STM32F2X7_ETH_RX_BUFFER_COUNT parameter is not valid
54 #endif
55 
56 //RX buffer size
57 #ifndef STM32F2X7_ETH_RX_BUFFER_SIZE
58  #define STM32F2X7_ETH_RX_BUFFER_SIZE 1536
59 #elif (STM32F2X7_ETH_RX_BUFFER_SIZE != 1536)
60  #error STM32F2X7_ETH_RX_BUFFER_SIZE parameter is not valid
61 #endif
62 
63 //Interrupt priority grouping
64 #ifndef STM32F2X7_ETH_IRQ_PRIORITY_GROUPING
65  #define STM32F2X7_ETH_IRQ_PRIORITY_GROUPING 3
66 #elif (STM32F2X7_ETH_IRQ_PRIORITY_GROUPING < 0)
67  #error STM32F2X7_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
68 #endif
69 
70 //Ethernet interrupt group priority
71 #ifndef STM32F2X7_ETH_IRQ_GROUP_PRIORITY
72  #define STM32F2X7_ETH_IRQ_GROUP_PRIORITY 12
73 #elif (STM32F2X7_ETH_IRQ_GROUP_PRIORITY < 0)
74  #error STM32F2X7_ETH_IRQ_GROUP_PRIORITY parameter is not valid
75 #endif
76 
77 //Ethernet interrupt subpriority
78 #ifndef STM32F2X7_ETH_IRQ_SUB_PRIORITY
79  #define STM32F2X7_ETH_IRQ_SUB_PRIORITY 0
80 #elif (STM32F2X7_ETH_IRQ_SUB_PRIORITY < 0)
81  #error STM32F2X7_ETH_IRQ_SUB_PRIORITY parameter is not valid
82 #endif
83 
84 //Transmit DMA descriptor flags
85 #define ETH_TDES0_OWN 0x80000000
86 #define ETH_TDES0_IC 0x40000000
87 #define ETH_TDES0_LS 0x20000000
88 #define ETH_TDES0_FS 0x10000000
89 #define ETH_TDES0_DC 0x08000000
90 #define ETH_TDES0_DP 0x04000000
91 #define ETH_TDES0_TTSE 0x02000000
92 #define ETH_TDES0_CIC 0x00C00000
93 #define ETH_TDES0_TER 0x00200000
94 #define ETH_TDES0_TCH 0x00100000
95 #define ETH_TDES0_TTSS 0x00020000
96 #define ETH_TDES0_IHE 0x00010000
97 #define ETH_TDES0_ES 0x00008000
98 #define ETH_TDES0_JT 0x00004000
99 #define ETH_TDES0_FF 0x00002000
100 #define ETH_TDES0_IPE 0x00001000
101 #define ETH_TDES0_LCA 0x00000800
102 #define ETH_TDES0_NC 0x00000400
103 #define ETH_TDES0_LCO 0x00000200
104 #define ETH_TDES0_EC 0x00000100
105 #define ETH_TDES0_VF 0x00000080
106 #define ETH_TDES0_CC 0x00000078
107 #define ETH_TDES0_ED 0x00000004
108 #define ETH_TDES0_UF 0x00000002
109 #define ETH_TDES0_DB 0x00000001
110 #define ETH_TDES1_TBS2 0x1FFF0000
111 #define ETH_TDES1_TBS1 0x00001FFF
112 #define ETH_TDES2_TBAP1 0xFFFFFFFF
113 #define ETH_TDES3_TBAP2 0xFFFFFFFF
114 #define ETH_TDES6_TTSL 0xFFFFFFFF
115 #define ETH_TDES7_TTSH 0xFFFFFFFF
116 
117 //Receive DMA descriptor flags
118 #define ETH_RDES0_OWN 0x80000000
119 #define ETH_RDES0_AFM 0x40000000
120 #define ETH_RDES0_FL 0x3FFF0000
121 #define ETH_RDES0_ES 0x00008000
122 #define ETH_RDES0_DE 0x00004000
123 #define ETH_RDES0_SAF 0x00002000
124 #define ETH_RDES0_LE 0x00001000
125 #define ETH_RDES0_OE 0x00000800
126 #define ETH_RDES0_VLAN 0x00000400
127 #define ETH_RDES0_FS 0x00000200
128 #define ETH_RDES0_LS 0x00000100
129 #define ETH_RDES0_IPHCE 0x00000080
130 #define ETH_RDES0_LCO 0x00000040
131 #define ETH_RDES0_FT 0x00000020
132 #define ETH_RDES0_RWT 0x00000010
133 #define ETH_RDES0_RE 0x00000008
134 #define ETH_RDES0_DBE 0x00000004
135 #define ETH_RDES0_CE 0x00000002
136 #define ETH_RDES0_PCE 0x00000001
137 #define ETH_RDES1_DIC 0x80000000
138 #define ETH_RDES1_RBS2 0x1FFF0000
139 #define ETH_RDES1_RER 0x00008000
140 #define ETH_RDES1_RCH 0x00004000
141 #define ETH_RDES1_RBS1 0x00001FFF
142 #define ETH_RDES2_RBAP1 0xFFFFFFFF
143 #define ETH_RDES3_RBAP2 0xFFFFFFFF
144 #define ETH_RDES4_PV 0x00002000
145 #define ETH_RDES4_PFT 0x00001000
146 #define ETH_RDES4_PMT 0x00000F00
147 #define ETH_RDES4_IPV6PR 0x00000080
148 #define ETH_RDES4_IPV4PR 0x00000040
149 #define ETH_RDES4_IPCB 0x00000020
150 #define ETH_RDES4_IPPE 0x00000010
151 #define ETH_RDES4_IPHE 0x00000008
152 #define ETH_RDES4_IPPT 0x00000007
153 #define ETH_RDES6_RTSL 0xFFFFFFFF
154 #define ETH_RDES7_RTSH 0xFFFFFFFF
155 
156 //C++ guard
157 #ifdef __cplusplus
158  extern "C" {
159 #endif
160 
161 
162 /**
163  * @brief Enhanced TX DMA descriptor
164  **/
165 
166 typedef struct
167 {
168  uint32_t tdes0;
169  uint32_t tdes1;
170  uint32_t tdes2;
171  uint32_t tdes3;
172  uint32_t tdes4;
173  uint32_t tdes5;
174  uint32_t tdes6;
175  uint32_t tdes7;
177 
178 
179 /**
180  * @brief Enhanced RX DMA descriptor
181  **/
182 
183 typedef struct
184 {
185  uint32_t rdes0;
186  uint32_t rdes1;
187  uint32_t rdes2;
188  uint32_t rdes3;
189  uint32_t rdes4;
190  uint32_t rdes5;
191  uint32_t rdes6;
192  uint32_t rdes7;
194 
195 
196 //STM32F207/217 Ethernet MAC driver
197 extern const NicDriver stm32f2x7EthDriver;
198 
199 //STM32F207/217 Ethernet MAC related functions
201 void stm32f2x7EthInitGpio(NetInterface *interface);
202 void stm32f2x7EthInitDmaDesc(NetInterface *interface);
203 
204 void stm32f2x7EthTick(NetInterface *interface);
205 
206 void stm32f2x7EthEnableIrq(NetInterface *interface);
207 void stm32f2x7EthDisableIrq(NetInterface *interface);
208 void stm32f2x7EthEventHandler(NetInterface *interface);
209 
211  const NetBuffer *buffer, size_t offset);
212 
214 
217 
218 void stm32f2x7EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
219 uint16_t stm32f2x7EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
220 
221 uint32_t stm32f2x7EthCalcCrc(const void *data, size_t length);
222 
223 //C++ guard
224 #ifdef __cplusplus
225  }
226 #endif
227 
228 #endif
void stm32f2x7EthEventHandler(NetInterface *interface)
STM32F207/217 Ethernet MAC event handler.
uint16_t stm32f2x7EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void stm32f2x7EthInitGpio(NetInterface *interface)
void stm32f2x7EthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
error_t stm32f2x7EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void stm32f2x7EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
Enhanced TX DMA descriptor.
const NicDriver stm32f2x7EthDriver
STM32F207/217 Ethernet MAC driver.
NIC driver.
Definition: nic.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
uint32_t stm32f2x7EthCalcCrc(const void *data, size_t length)
CRC calculation.
uint16_t regAddr
Enhanced RX DMA descriptor.
error_t stm32f2x7EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
error_t
Error codes.
Definition: error.h:40
void stm32f2x7EthTick(NetInterface *interface)
STM32F207/217 Ethernet MAC timer handler.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
void stm32f2x7EthDisableIrq(NetInterface *interface)
Disable interrupts.
uint8_t length
Definition: dtls_misc.h:140
error_t stm32f2x7EthInit(NetInterface *interface)
STM32F207/217 Ethernet MAC initialization.
error_t stm32f2x7EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Network interface controller abstraction layer.
error_t stm32f2x7EthReceivePacket(NetInterface *interface)
Receive a packet.
void stm32f2x7EthEnableIrq(NetInterface *interface)
Enable interrupts.