libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
mac_stm32fxx7.h
Go to the documentation of this file.
1/** @defgroup ethernet_mac_stm32fxx7_defines MAC STM32Fxx7 Defines
2 *
3 * @brief <b>Defined Constants and Types for the Ethernet MAC for STM32Fxx7
4 * chips</b>
5 *
6 * @ingroup ETH
7 *
8 * @version 1.0.0
9 *
10 * @author @htmlonly &copy; @endhtmlonly 2013 Frantisek Burian <BuFran@seznam.cz>
11 *
12 * @date 1 September 2013
13 *
14 * LGPL License Terms @ref lgpl_license
15 */
16/*
17 * This file is part of the libopencm3 project.
18 *
19 * Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
20 *
21 * This library is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU Lesser General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public License
32 * along with this library. If not, see <http://www.gnu.org/licenses/>.
33 */
34
35#ifndef LIBOPENCM3_ETHERNET_H
36#define LIBOPENCM3_ETHERNET_H
37
40
41/*****************************************************************************/
42/* Module definitions */
43/*****************************************************************************/
44
45/*****************************************************************************/
46/* Register definitions */
47/*****************************************************************************/
48
49/**@{*/
50
51#define ETH_MACCR MMIO32(ETHERNET_BASE + 0x00)
52#define ETH_MACFFR MMIO32(ETHERNET_BASE + 0x04)
53#define ETH_MACHTHR MMIO32(ETHERNET_BASE + 0x08)
54#define ETH_MACHTLR MMIO32(ETHERNET_BASE + 0x0C)
55#define ETH_MACMIIAR MMIO32(ETHERNET_BASE + 0x10)
56#define ETH_MACMIIDR MMIO32(ETHERNET_BASE + 0x14)
57#define ETH_MACFCR MMIO32(ETHERNET_BASE + 0x18)
58#define ETH_MACVLANTR MMIO32(ETHERNET_BASE + 0x1C)
59#define ETH_MACRWUFFR MMIO32(ETHERNET_BASE + 0x28)
60#define ETH_MACPMTCSR MMIO32(ETHERNET_BASE + 0x2C)
61#define ETH_MACDBGR MMIO32(ETHERNET_BASE + 0x34) /* Not on STM32F1 */
62#define ETH_MACSR MMIO32(ETHERNET_BASE + 0x38)
63#define ETH_MACIMR MMIO32(ETHERNET_BASE + 0x3C)
64
65/* i=[0..3] */
66#define ETH_MACAHR(i) MMIO32(ETHERNET_BASE + 0x40+(i)*8)
67/* i=[0..3] */
68#define ETH_MACALR(i) MMIO32(ETHERNET_BASE + 0x44+(i)*8)
69
70/* Ethernet MMC registers */
71#define ETH_MMCCR MMIO32(ETHERNET_BASE + 0x100)
72#define ETH_MMCRIR MMIO32(ETHERNET_BASE + 0x104)
73#define ETH_MMCTIR MMIO32(ETHERNET_BASE + 0x108)
74#define ETH_MMCRIMR MMIO32(ETHERNET_BASE + 0x10C)
75#define ETH_MMCTIMR MMIO32(ETHERNET_BASE + 0x110)
76#define ETH_MMCTGFSCCR MMIO32(ETHERNET_BASE + 0x14C)
77#define ETH_MMCTGFMSCCR MMIO32(ETHERNET_BASE + 0x150)
78#define ETH_MMCTGFCR MMIO32(ETHERNET_BASE + 0x168)
79#define ETH_MMCRFCECR MMIO32(ETHERNET_BASE + 0x194)
80#define ETH_MMCRFAECR MMIO32(ETHERNET_BASE + 0x198)
81#define ETH_MMCRGUFCR MMIO32(ETHERNET_BASE + 0x1C4)
82
83/* Ethernet IEEE 1588 time stamp registers */
84#define ETH_PTPTSCR MMIO32(ETHERNET_BASE + 0x700)
85#define ETH_PTPSSIR MMIO32(ETHERNET_BASE + 0x704)
86#define ETH_PTPTSHR MMIO32(ETHERNET_BASE + 0x708)
87#define ETH_PTPTSLR MMIO32(ETHERNET_BASE + 0x70C)
88#define ETH_PTPTSHUR MMIO32(ETHERNET_BASE + 0x710)
89#define ETH_PTPTSLUR MMIO32(ETHERNET_BASE + 0x714)
90#define ETH_PTPTSAR MMIO32(ETHERNET_BASE + 0x718)
91#define ETH_PTPTTHR MMIO32(ETHERNET_BASE + 0x71C)
92#define ETH_PTPTTLR MMIO32(ETHERNET_BASE + 0x720)
93#define ETH_PTPTSSR MMIO32(ETHERNET_BASE + 0x728) /* Not on STM32F1 */
94#define ETH_PTPPPSCR MMIO32(ETHERNET_BASE + 0x72C) /* Not on STM32F1 */
95
96/* Ethernet DMA registers */
97#define ETH_DMABMR MMIO32(ETHERNET_BASE + 0x1000)
98#define ETH_DMATPDR MMIO32(ETHERNET_BASE + 0x1004)
99#define ETH_DMARPDR MMIO32(ETHERNET_BASE + 0x1008)
100#define ETH_DMARDLAR MMIO32(ETHERNET_BASE + 0x100C)
101#define ETH_DMATDLAR MMIO32(ETHERNET_BASE + 0x1010)
102#define ETH_DMASR MMIO32(ETHERNET_BASE + 0x1014)
103#define ETH_DMAOMR MMIO32(ETHERNET_BASE + 0x1018)
104#define ETH_DMAIER MMIO32(ETHERNET_BASE + 0x101C)
105#define ETH_DMAMFBOCR MMIO32(ETHERNET_BASE + 0x1020)
106#define ETH_DMARSWTR MMIO32(ETHERNET_BASE + 0x1024) /* Not on STM32F1 */
107#define ETH_DMACHTDR MMIO32(ETHERNET_BASE + 0x1048)
108#define ETH_DMACHRDR MMIO32(ETHERNET_BASE + 0x104C)
109#define ETH_DMACHTBAR MMIO32(ETHERNET_BASE + 0x1050)
110#define ETH_DMACHRBAR MMIO32(ETHERNET_BASE + 0x1054)
111
112/* Ethernet Buffer Descriptors */
113#define ETH_DES(n, base) MMIO32((base) + (n)*4)
114#define ETH_DES0(base) ETH_DES(0, base)
115#define ETH_DES1(base) ETH_DES(1, base)
116#define ETH_DES2(base) ETH_DES(2, base)
117#define ETH_DES3(base) ETH_DES(3, base)
118
119/* Ethernet Extended buffer Descriptors */
120#define ETH_DES4(base) ETH_DES(4, base)
121#define ETH_DES5(base) ETH_DES(5, base)
122#define ETH_DES6(base) ETH_DES(6, base)
123#define ETH_DES7(base) ETH_DES(7, base)
124
125/*****************************************************************************/
126/* Register values */
127/*****************************************************************************/
128
129/*---------------------------------------------------------------------------*/
130/* MACCR --------------------------------------------------------------------*/
131
132#define ETH_MACCR_RE (1<<2)
133#define ETH_MACCR_TE (1<<3)
134#define ETH_MACCR_DC (1<<4)
135
136#define ETH_MACCR_BL_SHIFT 5
137#define ETH_MACCR_BL (3 << ETH_MACCR_BL_SHIFT)
138#define ETH_MACCR_BL_MIN10 (0 << ETH_MACCR_BL_SHIFT)
139#define ETH_MACCR_BL_MIN8 (1 << ETH_MACCR_BL_SHIFT)
140#define ETH_MACCR_BL_MIN4 (2 << ETH_MACCR_BL_SHIFT)
141#define ETH_MACCR_BL_MIN1 (3 << ETH_MACCR_BL_SHIFT)
142
143#define ETH_MACCR_APCS (1<<7)
144#define ETH_MACCR_RD (1<<9)
145#define ETH_MACCR_IPCO (1<<10)
146#define ETH_MACCR_DM (1<<11)
147#define ETH_MACCR_LM (1<<12)
148#define ETH_MACCR_ROD (1<<13)
149#define ETH_MACCR_FES (1<<14)
150#define ETH_MACCR_CSD (1<<16)
151
152#define ETH_MACCR_IFG_SHIFT 17
153#define ETH_MACCR_IFG (7<<ETH_MACCR_IFG_SHIFT)
154
155#define ETH_MACCR_JD (1<<22)
156#define ETH_MACCR_WD (1<<23)
157#define ETH_MACCR_CSTF (1<<25) /* Not on STM32F1 */
158
159/*---------------------------------------------------------------------------*/
160/* MACFFR -------------------------------------------------------------------*/
161#define ETH_MACFFR_PM (1<<0)
162#define ETH_MACFFR_HU (1<<1)
163#define ETH_MACFFR_HM (1<<2)
164#define ETH_MACFFR_DAIF (1<<3)
165#define ETH_MACFFR_PAM (1<<4)
166#define ETH_MACFFR_BFD (1<<5)
167
168#define ETH_MACFFR_PCF_SHIFT 6
169#define ETH_MACFFR_PCF (3<<ETH_MACFFR_PCF_SHIFT)
170#define ETH_MACFFR_PCF_DISABLE (0<<ETH_MACFFR_PCF_SHIFT)
171#define ETH_MACFFR_PCF_NOPAUSE (1<<ETH_MACFFR_PCF_SHIFT)
172#define ETH_MACFFR_PCF_ALL (2<<ETH_MACFFR_PCF_SHIFT)
173#define ETH_MACFFR_PCF_PASS (3<<ETH_MACFFR_PCF_SHIFT)
174
175#define ETH_MACFFR_SAIF (1<<8)
176#define ETH_MACFFR_SAF (1<<9)
177#define ETH_MACFFR_HPF (1<<10)
178#define ETH_MACFFR_RA (1<<31)
179
180/*---------------------------------------------------------------------------*/
181/* MACMIIAR -----------------------------------------------------------------*/
182
183#define ETH_MACMIIAR_MB (1<<0)
184#define ETH_MACMIIAR_MW (1<<1)
185
186#define ETH_MACMIIAR_CR_SHIFT 2
187#define ETH_MACMIIAR_CR (7<<ETH_MACMIIAR_CR_SHIFT)
188/* For HCLK 60-100 MHz */
189#define ETH_MACMIIAR_CR_HCLK_DIV_42 (0<<ETH_MACMIIAR_CR_SHIFT)
190/* For HCLK 100-150 MHz */
191#define ETH_MACMIIAR_CR_HCLK_DIV_62 (1<<ETH_MACMIIAR_CR_SHIFT)
192/* For HCLK 20-35 MHz */
193#define ETH_MACMIIAR_CR_HCLK_DIV_16 (2<<ETH_MACMIIAR_CR_SHIFT)
194/* For HCLK 35-60 MHz */
195#define ETH_MACMIIAR_CR_HCLK_DIV_26 (3<<ETH_MACMIIAR_CR_SHIFT)
196/* For HCLK 150-168 MHz */
197#define ETH_MACMIIAR_CR_HCLK_DIV_102 (4<<ETH_MACMIIAR_CR_SHIFT)
198
199#define ETH_MACMIIAR_MR_SHIFT 6
200#define ETH_MACMIIAR_MR (0x1F << ETH_MACMIIAR_MR_SHIFT)
201
202#define ETH_MACMIIAR_PA_SHIFT 11
203#define ETH_MACMIIAR_PA (0x1F << ETH_MACMIIAR_MR_SHIFT)
204
205/*---------------------------------------------------------------------------*/
206/* MACMIIDR------------------------------------------------------------------*/
207
208#define ETH_MACMIIDR_MD 0xFFFF
209
210/*---------------------------------------------------------------------------*/
211/* MACFCR -------------------------------------------------------------------*/
212#define ETH_MACFCR_FCB (1<<0)
213#define ETH_MACFCR_BPA (1<<0)
214#define ETH_MACFCR_TFCE (1<<1)
215#define ETH_MACFCR_RFCE (1<<2)
216#define ETH_MACFCR_UPFD (1<<3)
217
218#define ETH_MACFCR_PLT_SHIFT 4
219#define ETH_MACFCR_PLT (0x03 << ETH_MACFCR_PLT_SHIFT)
220#define ETH_MACFCR_PLT_4 (0 << ETH_MACFCR_PLT_SHIFT)
221#define ETH_MACFCR_PLT_28 (1 << ETH_MACFCR_PLT_SHIFT)
222#define ETH_MACFCR_PLT_144 (2 << ETH_MACFCR_PLT_SHIFT)
223#define ETH_MACFCR_PLT_256 (3 << ETH_MACFCR_PLT_SHIFT)
224
225#define ETH_MACFCR_ZQPD (1<<7)
226
227#define ETH_MACFCR_PT_SHIFT 16
228#define ETH_MACFCR_PT (0xFFFF << ETH_MACFCR_PT)
229
230/*---------------------------------------------------------------------------*/
231/* MACVLANTR ----------------------------------------------------------------*/
232#define ETH_MACVLANTR_VLANTI_SHIFT 0
233#define ETH_MACVLANTR_VLANTI (0xFFFF << ETH_MACVLANTR_VLANTI_SHIFT)
234#define ETH_MACVLANTR_VLANTC (1<<16)
235
236/*---------------------------------------------------------------------------*/
237/* MACPMTCSR ----------------------------------------------------------------*/
238
239#define ETH_MACPMTCSR_PD (1<<0)
240#define ETH_MACPMTCSR_MPE (1<<1)
241#define ETH_MACPMTCSR_WFE (1<<2)
242#define ETH_MACPMTCSR_MPR (1<<5)
243#define ETH_MACPMTCSR_WFR (1<<6)
244#define ETH_MACPMTCSR_GU (1<<9)
245#define ETH_MACPMTCSR_WFFRPR (1<<31)
246
247/*---------------------------------------------------------------------------*/
248/* MACDBGR -------------------------------------------------------------------*/
249
250/* Not on STM32F1 */
251#define ETH_MACDBGR_MMRPEA (1<<0)
252#define ETH_MACDBGR_MSFRWCS (3<<1)
253#define ETH_MACDBGR_RFWRA (1<<4)
254
255#define ETH_MACDBGR_RFRCS_SHIFT 5
256#define ETH_MACDBGR_RFRCS (3<<ETH_MACDBGR_RFRCS_SHIFT)
257#define ETH_MACDBGR_RFRCS_IDLE (0<<ETH_MACDBGR_RFRCS_SHIFT)
258#define ETH_MACDBGR_RFRCS_RDATA (1<<ETH_MACDBGR_RFRCS_SHIFT)
259#define ETH_MACDBGR_RFRCS_RSTAT (2<<ETH_MACDBGR_RFRCS_SHIFT)
260#define ETH_MACDBGR_RFRCS_FLUSH (3<<ETH_MACDBGR_RFRCS_SHIFT)
261
262#define ETH_MACDBGR_RFFL_SHIFT 8
263#define ETH_MACDBGR_RFFL (3<<ETH_MACDBGR_RFFL_SHIFT)
264#define ETH_MACDBGR_RFFL_EMPTY (0<<ETH_MACDBGR_RFFL_SHIFT)
265#define ETH_MACDBGR_RFFL_BELOW (1<<ETH_MACDBGR_RFFL_SHIFT)
266#define ETH_MACDBGR_RFFL_ABOVE (2<<ETH_MACDBGR_RFFL_SHIFT)
267#define ETH_MACDBGR_RFFL_FULL (3<<ETH_MACDBGR_RFFL_SHIFT)
268
269#define ETH_MACDBGR_MMTEA (1<<16)
270
271#define ETH_MACDBGR_MTFCS_SHIFT 17
272#define ETH_MACDBGR_MTFCS (3 << ETH_MACDBGR_MTFCS_SHIFT)
273#define ETH_MACDBGR_MTFCS_IDLE (0 << ETH_MACDBGR_MTFCS_SHIFT)
274#define ETH_MACDBGR_MTFCS_WAIT (1 << ETH_MACDBGR_MTFCS_SHIFT)
275#define ETH_MACDBGR_MTFCS_PAUSE (2 << ETH_MACDBGR_MTFCS_SHIFT)
276#define ETH_MACDBGR_MTFCS_TRANSFER (3 << ETH_MACDBGR_MTFCS_SHIFT)
277
278#define ETH_MACDBGR_MTP (1<<19)
279
280#define ETH_MACDBGR_TFRS_SHIFT 20
281#define ETH_MACDBGR_TFRS (3<<ETH_MACDBGR_TFRS_SHIFT)
282#define ETH_MACDBGR_TFRS_IDLE (0<<ETH_MACDBGR_TFRS_SHIFT)
283#define ETH_MACDBGR_TFRS_READ (1<<ETH_MACDBGR_TFRS_SHIFT)
284#define ETH_MACDBGR_TFRS_WAIT (2<<ETH_MACDBGR_TFRS_SHIFT)
285#define ETH_MACDBGR_TFRS_FLUSH (3<<ETH_MACDBGR_TFRS_SHIFT)
286
287#define ETH_MACDBGR_TFWA (1<<22)
288#define ETH_MACDBGR_TFNE (1<<24)
289#define ETH_MACDBGR_TFF (1<<25)
290
291/*---------------------------------------------------------------------------*/
292/* MACSR --------------------------------------------------------------------*/
293
294/* Ethernet MAC interrupt status register ETH_MACSR bits */
295#define ETH_MACSR_PMTS (1<<3)
296#define ETH_MACSR_MMCS (1<<4)
297#define ETH_MACSR_MMCRS (1<<5)
298#define ETH_MACSR_MMCTS (1<<6)
299#define ETH_MACSR_TSTS (1<<9)
300
301
302/*---------------------------------------------------------------------------*/
303/* MACIMR -------------------------------------------------------------------*/
304
305#define ETH_MACIMR_PMTIM (1<<3)
306#define ETH_MACIMR_TSTIM (1<<9)
307
308/*---------------------------------------------------------------------------*/
309/* MACA0HR ------------------------------------------------------------------*/
310
311#define ETH_MACA0HR_MACA0H (0xFFFF<<0)
312#define ETH_MACA0HR_MO (1<<31)
313
314/*---------------------------------------------------------------------------*/
315/* MACA1HR, MACA2HR, MACA3HR ------------------------------------------------*/
316
317#define ETH_MACAHR_MACAH (0xFFFF<<0)
318#define ETH_MACAHR_MBC_ALL (63<<24)
319#define ETH_MACAHR_MBC_0 (1<<24)
320#define ETH_MACAHR_MBC_1 (1<<25)
321#define ETH_MACAHR_MBC_2 (1<<26)
322#define ETH_MACAHR_MBC_3 (1<<27)
323#define ETH_MACAHR_MBC_4 (1<<28)
324#define ETH_MACAHR_MBC_5 (1<<29)
325#define ETH_MACAHR_SA (1<<30)
326#define ETH_MACAHR_AE (1<<31)
327
328/*---------------------------------------------------------------------------*/
329/* MMCCR --------------------------------------------------------------------*/
330
331#define ETH_MMCCR_CR (1<<0)
332#define ETH_MMCCR_CSR (1<<1)
333#define ETH_MMCCR_ROR (1<<2)
334#define ETH_MMCCR_MCF (1<<3)
335#define ETH_MMCCR_MCP (1<<4) /* Not on STM32F1 */
336#define ETH_MMCCR_MCFHP (1<<5) /* Not on STM32F1 */
337
338
339/*---------------------------------------------------------------------------*/
340/* MMCRIR -------------------------------------------------------------------*/
341
342#define ETH_MMCRIR_RFCES (1<<5)
343#define ETH_MMCRIR_RFAES (1<<6)
344#define ETH_MMCRIR_RGUFS (1<<17)
345
346/*---------------------------------------------------------------------------*/
347/* MMCTIR -------------------------------------------------------------------*/
348
349#define ETH_MMCTIR_TGFSCS (1<<14)
350#define ETH_MMCTIR_TGFMSCS (1<<15)
351#define ETH_MMCTIR_TGFS (1<<21)
352
353/*---------------------------------------------------------------------------*/
354/* MMCRIMR ------------------------------------------------------------------*/
355
356#define ETH_MMCRIMR_RFCEM (1<<5)
357#define ETH_MMCRIMR_RFAEM (1<<6)
358#define ETH_MMCRIMR_RGUFM (1<<17)
359
360/*---------------------------------------------------------------------------*/
361/* MMCTIMR ------------------------------------------------------------------*/
362
363#define ETH_MMCTIMR_TGFSCS (1<<14)
364#define ETH_MMCTIMR_TGFMSCS (1<<15)
365#define ETH_MMCTIMR_TGFS (1<<21)
366
367/*---------------------------------------------------------------------------*/
368/* PTPTSCR ------------------------------------------------------------------*/
369
370#define ETH_PTPTSCR_TSE (1<<0)
371#define ETH_PTPTSCR_TSFCU (1<<1)
372#define ETH_PTPTSCR_TSSTI (1<<2)
373#define ETH_PTPTSCR_TSSTU (1<<3)
374#define ETH_PTPTSCR_TSITE (1<<4)
375#define ETH_PTPTSCR_TTSARU (1<<5)
376
377/* Not on STM32F1 */
378#define ETH_PTPTSCR_TSSARFE (1<<8)
379#define ETH_PTPTSCR_TSSSR (1<<9)
380#define ETH_PTPTSCR_TSPTPPSV2E (1<<10)
381#define ETH_PTPTSCR_TSSPTPOEFE (1<<11)
382#define ETH_PTPTSCR_TSSIPV6FE (1<<12)
383#define ETH_PTPTSCR_TSSIPV4FE (1<<13)
384#define ETH_PTPTSCR_TSSEME (1<<14)
385#define ETH_PTPTSCR_TSSMRME (1<<15)
386
387#define ETH_PTPTSCR_TSCNT_SHIFT 16
388#define ETH_PTPTSCR_TSCNT (3 << ETH_PTPTSCR_TSCNT_SHIFT)
389#define ETH_PTPTSCR_TSCNT_ORD (0 << ETH_PTPTSCR_TSCNT_SHIFT)
390#define ETH_PTPTSCR_TSCNT_BOUND (1 << ETH_PTPTSCR_TSCNT_SHIFT)
391#define ETH_PTPTSCR_TSCNT_ETETC (2 << ETH_PTPTSCR_TSCNT_SHIFT)
392#define ETH_PTPTSCR_TSCNT_PTPTC (3 << ETH_PTPTSCR_TSCNT_SHIFT)
393
394#define ETH_PTPTSCR_TSPFFMAE (1<<18)
395
396
397/*---------------------------------------------------------------------------*/
398/* PTPSSIR ------------------------------------------------------------------*/
399
400#define ETH_PTPSSIR_STSSI 0xFF
401
402/*---------------------------------------------------------------------------*/
403/* PTPTSLR ------------------------------------------------------------------*/
404
405#define ETH_PTPTSLR_STSS 0x7FFFFFFF
406#define ETH_PTPTSLR_STPNS (1<<31)
407
408/*---------------------------------------------------------------------------*/
409/* PTPTSLUR -----------------------------------------------------------------*/
410
411#define ETH_PTPTSLUR_TSUSS 0x7FFFFFFF
412#define ETH_PTPTSLUR_TSUPNS (1<<31)
413
414/*---------------------------------------------------------------------------*/
415/* PTPTSSR ------------------------------------------------------------------*/
416
417/* Not on STM32F1 */
418#define ETH_PTPTSSR_TSSO (1<<0)
419#define ETH_PTPTSSR_TSTTR (1<<1)
420
421
422/*---------------------------------------------------------------------------*/
423/* PTPPPSCR -----------------------------------------------------------------*/
424
425/* Not on STM32F1 */
426#define ETH_PTPPPSCR_PPSFREQ_MASK (0x0F<<0)
427#define ETH_PTPPPSCR_PPSFREQ_1HZ (0x00<<0)
428#define ETH_PTPPPSCR_PPSFREQ_2HZ (0x01<<0)
429#define ETH_PTPPPSCR_PPSFREQ_4HZ (0x02<<0)
430#define ETH_PTPPPSCR_PPSFREQ_8HZ (0x03<<0)
431#define ETH_PTPPPSCR_PPSFREQ_16HZ (0x04<<0)
432#define ETH_PTPPPSCR_PPSFREQ_32HZ (0x05<<0)
433#define ETH_PTPPPSCR_PPSFREQ_64HZ (0x06<<0)
434#define ETH_PTPPPSCR_PPSFREQ_128HZ (0x07<<0)
435#define ETH_PTPPPSCR_PPSFREQ_256HZ (0x08<<0)
436#define ETH_PTPPPSCR_PPSFREQ_512HZ (0x09<<0)
437#define ETH_PTPPPSCR_PPSFREQ_1024HZ (0x0A<<0)
438#define ETH_PTPPPSCR_PPSFREQ_2048HZ (0x0B<<0)
439#define ETH_PTPPPSCR_PPSFREQ_4096HZ (0x0C<<0)
440#define ETH_PTPPPSCR_PPSFREQ_8192HZ (0x0D<<0)
441#define ETH_PTPPPSCR_PPSFREQ_16384HZ (0x0E<<0)
442#define ETH_PTPPPSCR_PPSFREQ_32768HZ (0x0F<<0)
443
444
445/*---------------------------------------------------------------------------*/
446/* DMABMR -------------------------------------------------------------------*/
447
448#define ETH_DMABMR_SR (1<<0)
449#define ETH_DMABMR_DA (1<<1)
450
451#define ETH_DMABMR_DSL_SHIFT 2
452#define ETH_DMABMR_DSL (0x1F << ETH_DMABR_DSL_SHIFT)
453
454#define ETH_DMABMR_EDFE (1<<7)
455
456#define ETH_DMABMR_PBL_SHIFT 8
457#define ETH_DMABMR_PBL (0x3F << ETH_DMABR_PBL_SHIFT)
458
459#define ETH_DMABMR_PM_SHIFT 14
460#define ETH_DMABMR_PM (0x03 << ETH_DMABMR_PM_SHIFT)
461#define ETH_DMABMR_PM_1_1 (0 << ETH_DMABMR_PM_SHIFT)
462#define ETH_DMABMR_PM_2_1 (1 << ETH_DMABMR_PM_SHIFT)
463#define ETH_DMABMR_PM_3_1 (2 << ETH_DMABMR_PM_SHIFT)
464#define ETH_DMABMR_PM_4_1 (3 << ETH_DMABMR_PM_SHIFT)
465
466#define ETH_DMABMR_FB (1<<16)
467
468#define ETH_DMABMR_RDP_SHIFT 17
469#define ETH_DMABMR_RDP (0x3F << ETH_DMABMR_RDP_SHIFT)
470
471#define ETH_DMABMR_USP (1<<23)
472#define ETH_DMABMR_FPM (1<<24)
473#define ETH_DMABMR_AAB (1<<25)
474#define ETH_DMABMR_MB (1<<26) /* Not on STM32F1 */
475
476/*---------------------------------------------------------------------------*/
477/* DMASR --------------------------------------------------------------------*/
478
479#define ETH_DMASR_TS (1<<0)
480#define ETH_DMASR_TPSS (1<<1)
481#define ETH_DMASR_TBUS (1<<2)
482#define ETH_DMASR_TJTS (1<<3)
483#define ETH_DMASR_ROS (1<<4)
484#define ETH_DMASR_TUS (1<<5)
485#define ETH_DMASR_RS (1<<6)
486#define ETH_DMASR_RBUS (1<<7)
487#define ETH_DMASR_RPSS (1<<8)
488#define ETH_DMASR_RWTS (1<<9)
489#define ETH_DMASR_ETS (1<<10)
490#define ETH_DMASR_FBES (1<<13)
491#define ETH_DMASR_ERS (1<<14)
492#define ETH_DMASR_AIS (1<<15)
493#define ETH_DMASR_NIS (1<<16)
494
495#define ETH_DMASR_RPS_SHIFT 17
496#define ETH_DMASR_RPS (7<<ETH_DMASR_RPS_SHIFT)
497#define ETH_DMASR_RPS_STOP (0<<ETH_DMASR_RPS_SHIFT)
498#define ETH_DMASR_RPS_FETCH (1<<ETH_DMASR_RPS_SHIFT)
499#define ETH_DMASR_RPS_WAIT (3<<ETH_DMASR_RPS_SHIFT)
500#define ETH_DMASR_RPS_SUSPEND (4<<ETH_DMASR_RPS_SHIFT)
501#define ETH_DMASR_RPS_CLOSE (5<<ETH_DMASR_RPS_SHIFT)
502#define ETH_DMASR_RPS_TRANSFER (7<<ETH_DMASR_RPS_SHIFT)
503
504#define ETH_DMASR_TPS_SHIFT 20
505#define ETH_DMASR_TPS (7<<ETH_DMASR_TPS_SHIFT)
506#define ETH_DMASR_TPS_STOP (0<<ETH_DMASR_TPS_SHIFT)
507#define ETH_DMASR_TPS_FETCH (1<<ETH_DMASR_TPS_SHIFT)
508#define ETH_DMASR_TPS_WAIT (2<<ETH_DMASR_TPS_SHIFT)
509#define ETH_DMASR_TPS_TRANSFER (3<<ETH_DMASR_TPS_SHIFT)
510#define ETH_DMASR_TPS_SUSPEND (6<<ETH_DMASR_TPS_SHIFT)
511#define ETH_DMASR_TPS_CLOSE (7<<ETH_DMASR_TPS_SHIFT)
512
513#define ETH_DMASR_EBS_SHIFT 23
514#define ETH_DMASR_EBS (7<<ETH_DMASR_EBS_SHIFT)
515
516#define ETH_DMASR_MMCS (1<<27)
517#define ETH_DMASR_PMTS (1<<28)
518#define ETH_DMASR_TSTS (1<<29)
519
520/*---------------------------------------------------------------------------*/
521/* DMAOMR -------------------------------------------------------------------*/
522
523#define ETH_DMAOMR_SR (1<<1)
524#define ETH_DMAOMR_OSF (1<<2)
525
526#define ETH_DMAOMR_RTC_SHIFT 3
527#define ETH_DMAOMR_RTC (3 << ETH_DMAOMR_RTC_SHIFT)
528#define ETH_DMAOMR_RTC_64 (0 << ETH_DMAOMR_RTC_SHIFT)
529#define ETH_DMAOMR_RTC_32 (1 << ETH_DMAOMR_RTC_SHIFT)
530#define ETH_DMAOMR_RTC_96 (2 << ETH_DMAOMR_RTC_SHIFT)
531#define ETH_DMAOMR_RTC_128 (3 << ETH_DMAOMR_RTC_SHIFT)
532
533#define ETH_DMAOMR_FUGF (1<<6)
534#define ETH_DMAOMR_FEF (1<<7)
535#define ETH_DMAOMR_ST (1<<13)
536
537#define ETH_DMAOMR_TTC_SHIFT 14
538#define ETH_DMAOMR_TTC (0x07 << ETH_DMAOMR_TTC_SHIFT)
539#define ETH_DMAOMR_TTC_64 (0 << ETH_DMAOMR_TTC_SHIFT)
540#define ETH_DMAOMR_TTC_128 (1 << ETH_DMAOMR_TTC_SHIFT)
541#define ETH_DMAOMR_TTC_192 (2 << ETH_DMAOMR_TTC_SHIFT)
542#define ETH_DMAOMR_TTC_256 (3 << ETH_DMAOMR_TTC_SHIFT)
543#define ETH_DMAOMR_TTC_40 (4 << ETH_DMAOMR_TTC_SHIFT)
544#define ETH_DMAOMR_TTC_32 (5 << ETH_DMAOMR_TTC_SHIFT)
545#define ETH_DMAOMR_TTC_24 (6 << ETH_DMAOMR_TTC_SHIFT)
546#define ETH_DMAOMR_TTC_16 (7 << ETH_DMAOMR_TTC_SHIFT)
547
548#define ETH_DMAOMR_FTF (1<<20)
549#define ETH_DMAOMR_TSF (1<<21)
550#define ETH_DMAOMR_DFRF (1<<24)
551#define ETH_DMAOMR_RSF (1<<25)
552#define ETH_DMAOMR_DTCEFD (1<<26)
553
554/*----------------------------------------------------------------------------*/
555/* DMAIER --------------------------------------------------------------------*/
556
557#define ETH_DMAIER_TIE (1<<0)
558#define ETH_DMAIER_TPSIE (1<<1)
559#define ETH_DMAIER_TBUIE (1<<2)
560#define ETH_DMAIER_TJTIE (1<<3)
561#define ETH_DMAIER_ROIE (1<<4)
562#define ETH_DMAIER_TUIE (1<<5)
563#define ETH_DMAIER_RIE (1<<6)
564#define ETH_DMAIER_RBUIE (1<<7)
565#define ETH_DMAIER_RPSIE (1<<8)
566#define ETH_DMAIER_RWTIE (1<<9)
567#define ETH_DMAIER_ETIE (1<<10)
568#define ETH_DMAIER_FBEIE (1<<13)
569#define ETH_DMAIER_ERIE (1<<14)
570#define ETH_DMAIER_AISE (1<<15)
571#define ETH_DMAIER_NISE (1<<16)
572
573/*---------------------------------------------------------------------------*/
574/* DMAMFBOCR ----------------------------------------------------------------*/
575
576#define ETH_DMAMFBOCR_MFC_SHIFT 0
577#define ETH_DMAMFBOCR_MFC (0xFFFF << ETH_DMAMFBOCR_MFC_SHIFT)
578#define ETH_DMAMFBOCR_OMFC (1<<16)
579#define ETH_DMAMFBOCR_MFA (0x7FF << ETH_DMAMFBOCR_MFA_SHIFT)
580#define ETH_DMAMFBOCR_OFOC (1<<28)
581
582/*---------------------------------------------------------------------------*/
583/* DMARSWTR -----------------------------------------------------------------*/
584
585/* Not on STM32F1 */
586#define ETH_DMARSWTR_RSWTC 0xFF
587
588/*---------------------------------------------------------------------------*/
589/*---------------------------------------------------------------------------*/
590/*---------------------------------------------------------------------------*/
591/* DMA Tx Descriptor */
592
593#define ETH_DES_STD_SIZE 16
594#define ETH_DES_EXT_SIZE 32
595/*---------------------------------------------------------------------------*/
596/* TDES0 --------------------------------------------------------------------*/
597
598#define ETH_TDES0_DB (1<<0)
599#define ETH_TDES0_UF (1<<1)
600#define ETH_TDES0_ED (1<<2)
601
602#define ETH_TDES0_CC_SHIFT 3
603#define ETH_TDES0_CC (0x0F << ETH_TDES0_CC_SHIFT)
604
605#define ETH_TDES0_VF (1<<7)
606#define ETH_TDES0_EC (1<<8)
607#define ETH_TDES0_LCO (1<<9)
608#define ETH_TDES0_NC (1<<10)
609#define ETH_TDES0_LCA (1<<11)
610#define ETH_TDES0_IPE (1<<12)
611#define ETH_TDES0_FF (1<<13)
612#define ETH_TDES0_JT (1<<14)
613#define ETH_TDES0_ES (1<<15)
614#define ETH_TDES0_IHE (1<<16)
615#define ETH_TDES0_TTSS (1<<17)
616#define ETH_TDES0_TCH (1<<20)
617#define ETH_TDES0_TER (1<<21)
618
619#define ETH_TDES0_CIC_SHIFT 22
620#define ETH_TDES0_CIC (3<<ETH_TDES0_CIC_SHIFT)
621#define ETH_TDES0_CIC_DISABLED (0<<ETH_TDES0_CIC_SHIFT)
622#define ETH_TDES0_CIC_IP (1<<ETH_TDES0_CIC_SHIFT)
623#define ETH_TDES0_CIC_IPPL (2<<ETH_TDES0_CIC_SHIFT)
624#define ETH_TDES0_CIC_IPPLPH (3<<ETH_TDES0_CIC_SHIFT)
625
626#define ETH_TDES0_TTSE (1<<25)
627#define ETH_TDES0_DP (1<<26)
628#define ETH_TDES0_DC (1<<27)
629#define ETH_TDES0_FS (1<<28)
630#define ETH_TDES0_LS (1<<29)
631#define ETH_TDES0_IC (1<<30)
632#define ETH_TDES0_OWN (1<<31)
633
634/*---------------------------------------------------------------------------*/
635/* TDES1 --------------------------------------------------------------------*/
636
637#define ETH_TDES1_TBS1_SHIFT 0
638#define ETH_TDES1_TBS1 (0x1FFF<<ETH_TDES1_TBS1_SHIFT)
639
640#define ETH_TDES1_TBS2_SHIFT 16
641#define ETH_TDES1_TBS2 (0x1FFF<<ETH_TDES1_TBS1_SHIFT)
642
643/*---------------------------------------------------------------------------*/
644/*---------------------------------------------------------------------------*/
645/*---------------------------------------------------------------------------*/
646/* DMA Rx Descriptor */
647
648/*---------------------------------------------------------------------------*/
649/* RDES0 --------------------------------------------------------------------*/
650
651#define ETH_RDES0_PCE (1<<0)
652#define ETH_RDES0_ESA (1<<0)
653#define ETH_RDES0_CE (1<<1)
654#define ETH_RDES0_DE (1<<2)
655#define ETH_RDES0_RE (1<<3)
656#define ETH_RDES0_RWT (1<<4)
657#define ETH_RDES0_FT (1<<5)
658#define ETH_RDES0_LCO (1<<6)
659#define ETH_RDES0_IPHCE (1<<7)
660#define ETH_RDES0_TSV (1<<7)
661#define ETH_RDES0_LS (1<<8)
662#define ETH_RDES0_FS (1<<9)
663#define ETH_RDES0_VLAN (1<<10)
664#define ETH_RDES0_OE (1<<11)
665#define ETH_RDES0_LE (1<<12)
666#define ETH_RDES0_SAF (1<<13)
667#define ETH_RDES0_DCE (1<<14)
668#define ETH_RDES0_ES (1<<15)
669
670#define ETH_RDES0_FL_SHIFT 16
671#define ETH_RDES0_FL (0x3FFF<<ETH_RDES0_FL_SHIFT)
672
673#define ETH_RDES0_AFM (1<<30)
674#define ETH_RDES0_OWN (1<<31)
675
676/*---------------------------------------------------------------------------*/
677/* RDES1 --------------------------------------------------------------------*/
678
679#define ETH_RDES1_RBS1_SHIFT 0
680#define ETH_RDES1_RBS1 (0x1FFF<<ETH_RDES1_RBS1_SHIFT)
681
682#define ETH_RDES1_RCH (1<<14)
683#define ETH_RDES1_RER (1<<15)
684
685#define ETH_RDES1_RBS2_SHIFT 16
686#define ETH_RDES1_RBS2 (0x1FFF<<ETH_RDES1_RBS2_SHIFT)
687
688#define ETH_RDES1_DIC (1<<31)
689
690/*---------------------------------------------------------------------------*/
691/* RDES4 --------------------------------------------------------------------*/
692
693#define ETH_RDES4_IPPT_SHIFT 0
694#define ETH_RDES4_IPPT (7<<ETH_RDES4_IPPT_SHIFT)
695#define ETH_RDES4_IPPT_UNKNOWN (0<<ETH_RDES4_IPPT_SHIFT)
696#define ETH_RDES4_IPPT_UDP (1<<ETH_RDES4_IPPT_SHIFT)
697#define ETH_RDES4_IPPT_TCP (2<<ETH_RDES4_IPPT_SHIFT)
698#define ETH_RDES4_IPPT_ICMP (3<<ETH_RDES4_IPPT_SHIFT)
699
700#define ETH_RDES4_IPHE (1<<3)
701#define ETH_RDES4_IPPE (1<<4)
702#define ETH_RDES4_IPCB (1<<5)
703#define ETH_RDES4_IPV4PR (1<<6)
704#define ETH_RDES4_IPV6PR (1<<7)
705
706#define ETH_RDES4_PMT_SHIFT 8
707#define ETH_RDES4_PMT (0x0F<<ETH_RDES4_PMT_SHIFT)
708#define ETH_RDES4_PMT_NO (0x00<<ETH_RDES4_PMT_SHIFT)
709#define ETH_RDES4_PMT_SYNC (0x01<<ETH_RDES4_PMT_SHIFT)
710#define ETH_RDES4_PMT_FOLLOW (0x02<<ETH_RDES4_PMT_SHIFT)
711#define ETH_RDES4_PMT_DLYRQ (0x03<<ETH_RDES4_PMT_SHIFT)
712#define ETH_RDES4_PMT_DLYRSP (0x04<<ETH_RDES4_PMT_SHIFT)
713#define ETH_RDES4_PMT_PDLYRQ (0x05<<ETH_RDES4_PMT_SHIFT)
714#define ETH_RDES4_PMT_PDLYRSP (0x06<<ETH_RDES4_PMT_SHIFT)
715#define ETH_RDES4_PMT_PDLYRSPFUP (0x07<<ETH_RDES4_PMT_SHIFT)
716
717#define ETH_RDES4_PFT (1<<12)
718#define ETH_RDES4_PV (1<<13)
719
720/*****************************************************************************/
721/* API definitions */
722/*****************************************************************************/
723
730};
731
732/*****************************************************************************/
733/* API Functions */
734/*****************************************************************************/
735
737
738void eth_smi_write(uint8_t phy, uint8_t reg, uint16_t data);
739uint16_t eth_smi_read(uint8_t phy, uint8_t reg);
740void eth_smi_bit_op(uint8_t phy, uint8_t reg, uint16_t bits, uint16_t mask);
741void eth_smi_bit_clear(uint8_t phy, uint8_t reg, uint16_t clearbits);
742void eth_smi_bit_set(uint8_t phy, uint8_t reg, uint16_t setbits);
743
744void eth_set_mac(const uint8_t *mac);
745void eth_desc_init(uint8_t *buf, uint32_t nTx, uint32_t nRx, uint32_t cTx,
746 uint32_t cRx, bool isext);
747bool eth_tx(uint8_t *ppkt, uint32_t n);
748bool eth_rx(uint8_t *ppkt, uint32_t *len, uint32_t maxlen);
749
750void eth_init(uint8_t phy, enum eth_clk clock);
751void eth_start(void);
752
754
755void eth_irq_enable(uint32_t reason);
756void eth_irq_disable(uint32_t reason);
757bool eth_irq_is_pending(uint32_t reason);
758bool eth_irq_ack_pending(uint32_t reason);
759
760
762
763/*
764 * Usage:
765 * rcc_periph_reset_pulse(RCC_ETHMAC);
766 * [ init gpio pins ]
767 * rcc_periph_reset_pulse(RCC_ETHMAC);
768 * phy_init(0);
769 * eth_init(0, ETH_CLK_025_035MHZ);
770 * eth_set_mac(mac);
771 * eth_desc_init(buffer, &eth_buffer[0], ETH_TXBUFNB, ETH_RXBUFNB,
772 * ETH_TX_BUF_SIZE, ETH_RX_BUF_SIZE, false);
773 * eth_start();
774 * for (;;)
775 * eth_tx(frame,sizeof(frame));
776 */
777
778/**@}*/
779
780#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
#define ETH_MACMIIAR_CR_HCLK_DIV_102
void eth_irq_enable(uint32_t reason)
Enable the Ethernet IRQ.
bool eth_irq_ack_pending(uint32_t reason)
Check if IRQ is pending, and acknowledge it.
#define ETH_MACMIIAR_CR_HCLK_DIV_42
bool eth_tx(uint8_t *ppkt, uint32_t n)
Transmit packet.
#define ETH_MACMIIAR_CR_HCLK_DIV_16
void eth_enable_checksum_offload(void)
Enable checksum offload feature.
void eth_desc_init(uint8_t *buf, uint32_t nTx, uint32_t nRx, uint32_t cTx, uint32_t cRx, bool isext)
Initialize buffers and descriptors.
Definition: mac_stm32fxx7.c:73
void eth_irq_disable(uint32_t reason)
Disable the Ethernet IRQ.
void eth_smi_write(uint8_t phy, uint8_t reg, uint16_t data)
Write 16-bit register to the PHY.
bool eth_rx(uint8_t *ppkt, uint32_t *len, uint32_t maxlen)
Receive packet.
#define ETH_MACMIIAR_CR_HCLK_DIV_62
uint16_t eth_smi_read(uint8_t phy, uint8_t reg)
Read the 16-bit register from the PHY.
void eth_init(uint8_t phy, enum eth_clk clock)
Initialize ethernet.
void eth_smi_bit_clear(uint8_t phy, uint8_t reg, uint16_t clearbits)
Clear bits in the register.
bool eth_irq_is_pending(uint32_t reason)
Check if IRQ is pending.
void eth_set_mac(const uint8_t *mac)
Set MAC to the PHY.
Definition: mac_stm32fxx7.c:50
void eth_start(void)
Start the Ethernet DMA processing.
void eth_smi_bit_set(uint8_t phy, uint8_t reg, uint16_t setbits)
Set bits in the register.
eth_clk
#define ETH_MACMIIAR_CR_HCLK_DIV_26
void eth_smi_bit_op(uint8_t phy, uint8_t reg, uint16_t bits, uint16_t mask)
Process the bit-operation on PHY register.
@ ETH_CLK_150_168MHZ
@ ETH_CLK_100_150MHZ
@ ETH_CLK_035_060MHZ
@ ETH_CLK_060_100MHZ
@ ETH_CLK_025_035MHZ