STM32F207 und LwIP

Gast #3529799
Lesenswert?

Hallo,

ich entwickle zur Zeit eine Applikation mit einem STM32F207ZGT6 und em 
TI DP83848.
Der PHY ist per RMII angschlossen, Takt kommt aus dem PLL über MCO1, bei 
der Beschaltung wurde sich stark an das Development board(UM1057) von ST 
gerichtet, es wurden nur mitunter andere Pins für die AF genutzt.
Auch wurde die Link-Detection weggelassen, es gibt keine Verbindung 
zwischen PHY-Int und einem Pin des STM32.
Nun gibt es in der AN3384(LwIP TCP/IP stack demonstration for STM32F2x7) 
eine Implementation des Ethernet MACs in Verbindung mit dem auch bei mir 
verwendeten PHY.
Ich habe mir also den Source-Code herunter geladen und die Stand-Alone 
Lösung in mein Projekt übernommen(ich nutze EmBlocks mit ARM-gcc). Nur 
bekomme ich den STM32 nicht dazu, Daten an den PHY zu senden, auf TXD0, 
TXD1 und TX_EN ist dauerhaft 0, MDIO funktioniert und auf den 
Empfangsleitungen(RXD0, RXD1) kommen Daten an.
Hier die Haupt-Initialisierung:
1
#include "stm32f2xx_conf.h"
2

3
#include "FSMC.h"
4
#include "stm32f2x7_eth.h"
5
#include "netconf.h"
6
//#include "stm32f2x7_eth_bsp.h"
7

8
#define SYSTEMTICK_PERIOD_MS  10
9
#define DP83848_PHY_ADDRESS 0x01
10
/* Specific defines for EXTI line, used to manage Ethernet link status */
11
#define ETH_LINK_EXTI_LINE             EXTI_Line14
12
#define ETH_LINK_EXTI_PORT_SOURCE      EXTI_PortSourceGPIOB
13
#define ETH_LINK_EXTI_PIN_SOURCE       EXTI_PinSource14
14
#define ETH_LINK_EXTI_IRQn             EXTI15_10_IRQn
15
/* PB14 */
16
#define ETH_LINK_PIN                   GPIO_Pin_14
17
#define ETH_LINK_GPIO_PORT             GPIOB
18
#define ETH_LINK_GPIO_CLK              RCC_AHB1Periph_GPIOB
19
/* PHY registers */
20
#define PHY_MICR                  0x11 /* MII Interrupt Control Register */
21
#define PHY_MICR_INT_EN           ((uint16_t)0x0002) /* PHY Enable interrupts */
22
#define PHY_MICR_INT_OE           ((uint16_t)0x0001) /* PHY Enable output interrupt events */
23
#define PHY_MISR                  0x12 /* MII Interrupt Status and Misc. Control Register */
24
#define PHY_MISR_LINK_INT_EN      ((uint16_t)0x0020) /* Enable Interrupt on change of link status */
25
#define PHY_LINK_STATUS           ((uint16_t)0x2000) /* PHY link status interrupt mask */
26

27
__IO uint32_t LocalTime = 0;
28
__IO uint8_t EthLinkStatus = 0;
29

30
void SendString(USART_TypeDef * usart, char * text)
31
{
32
    while(*text != 0)
33
    {
34
        while (USART_GetFlagStatus (usart, USART_FLAG_TXE)== RESET);
35
        USART_SendData(usart, *text);
36
        text++;
37
    }
38
}
39

40
void Delay2(unsigned long a)
41
{
42
    while(a > 0) a--;
43
}
44

45
void InitUart()
46
{
47
    GPIO_InitTypeDef GPIO_InitStructure;
48
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
49
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
50

51
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
52
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
53
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
54
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
55
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
56
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
57
    GPIO_Init(GPIOA, &GPIO_InitStructure);
58

59
    /* RX Pin */
60
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
61
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
62
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
63
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
64
    GPIO_Init(GPIOA, &GPIO_InitStructure);
65

66
    USART_InitTypeDef USART_InitStructure;
67

68
    USART_InitStructure.USART_BaudRate = 57600;
69
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
70
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
71
    USART_InitStructure.USART_Parity = USART_Parity_No;
72
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
73
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
74

75
    USART_Init(USART1, &USART_InitStructure);
76

77
    USART_Cmd(USART1, ENABLE);
78
}
79

80
uint8_t  InitMAC()
81
{
82
    GPIO_InitTypeDef GPIO_InitStructure;
83
    ETH_InitTypeDef ETH_InitStructure;
84
    RCC_ClocksTypeDef RCC_Clocks;
85

86
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
87
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
88
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
89

90
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH);
91
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH);
92
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH);
93
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO);
94
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
95
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
96
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7 | GPIO_Pin_8;
97
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
98
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
99
    GPIO_Init(GPIOA, &GPIO_InitStructure);
100

101
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_ETH);
102
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_ETH);
103
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH);
104
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
105
    GPIO_Init(GPIOB, &GPIO_InitStructure);
106

107
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH);
108
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH);
109
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH);
110
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
111
    GPIO_Init(GPIOC, &GPIO_InitStructure);
112

113

114
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC, ENABLE);
115
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
116
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC_Tx, ENABLE);
117
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
118
    RCC_AHB1PeriphClockCmd(ETH_LINK_GPIO_CLK, ENABLE);
119
    SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
120

121

122
    // Set PLL3 clock output to 50MHz
123
    RCC_MCO1Config(RCC_MCO1Source_PLLCLK, RCC_MCO1Div_2);
124

125
    /* Reset ETHERNET on AHB Bus */
126
    ETH_DeInit();
127

128
    // Software reset
129
    ETH_SoftwareReset();
130
    GPIO_SetBits(GPIOA, GPIO_Pin_6);
131
    // Wait for software reset
132
    while (ETH_GetSoftwareResetStatus() == SET);
133
    GPIO_ResetBits(GPIOA, GPIO_Pin_6);
134

135
    // ETHERNET Configuration ------------------------------------------------------
136
    // Call ETH_StructInit if you don't like to configure all ETH_InitStructure parameter
137
    ETH_StructInit(&ETH_InitStructure);
138

139
    /* Fill ETH_InitStructure parametrs */
140
    /*------------------------   MAC   -----------------------------------*/
141
    ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable  ;
142
    ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
143
    ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
144
    ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
145
    ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable;
146
    ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
147
    ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
148
    ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
149
    ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
150
    #ifdef CHECKSUM_BY_HARDWARE
151
    ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable;
152
    #endif
153

154
    /*------------------------   DMA   -----------------------------------*/
155

156
    /* When we use the Checksum offload feature, we need to enable the Store and Forward mode:
157
    the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum,
158
    if the checksum is OK the DMA can handle the frame otherwise the frame is dropped */
159
    ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable;
160
    ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
161
    ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
162

163
    ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
164
    ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
165
    ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;
166
    ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
167
    ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable;
168
    ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
169
    ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
170
    ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1;
171

172
    /* Configure Ethernet */
173
    if(ETH_Init(&ETH_InitStructure, DP83848_PHY_ADDRESS) == 0)
174
    {
175
        GPIO_SetBits(GPIOA, GPIO_Pin_6);
176
    }
177

178
    /* Enable the Ethernet Rx Interrupt */
179
    ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R, ENABLE);
180
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
181
    RCC_GetClocksFreq(&RCC_Clocks);
182
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
183
    /* Configure the PHY to generate an interrupt on change of link status */
184
    //Eth_Link_PHYITConfig(DP83848_PHY_ADDRESS);
185

186
  return SUCCESS;
187

188
}
189

190
void Time_Update(void)
191
{
192
    LocalTime += SYSTEMTICK_PERIOD_MS;
193
}
194

195
/**
196
  * @brief  Configures and enable the Ethernet global interrupt.
197
  * @param  None
198
  * @retval None
199
  */
200
void ETH_NVIC_Config(void)
201
{
202
  NVIC_InitTypeDef   NVIC_InitStructure;
203

204
  /* 2 bit for pre-emption priority, 2 bits for subpriority */
205
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
206

207
  /* Enable the Ethernet global Interrupt */
208
  NVIC_InitStructure.NVIC_IRQChannel = ETH_IRQn;
209
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
210
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
211
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
212
  NVIC_Init(&NVIC_InitStructure);
213
}
214

215
int main(void)
216
{
217
    GPIO_InitTypeDef GPIO_InitStructure;
218

219
    SystemInit();
220

221
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
222
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
223

224
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
225
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
226
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
227
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
228
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
229
    GPIO_Init(GPIOB, &GPIO_InitStructure);
230
    GPIO_Init(GPIOA, &GPIO_InitStructure);
231

232
    GPIO_ToggleBits(GPIOA, GPIO_Pin_6);
233
    Delay2(10000000L);
234

235
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
236
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
237

238
    GPIO_SetBits(GPIOA, GPIO_Pin_6);
239
    InitUart();
240
    InitFSMC();
241
    ETH_NVIC_Config();
242
    InitMAC();
243
    GPIO_SetBits(GPIOB, GPIO_Pin_6);
244
    LwIP_Init();
245
    GPIO_ResetBits(GPIOA, GPIO_Pin_6);
246
    char text[] = "Hallo Welt!\n\0";
247
    uint16_t buffer[] = {1, 2, 3, 4, 5, 6, 7, 8, 10};
248
    uint16_t rBuffer[10];
249
    int i;
250

251
    GPIO_WriteBit(GPIOB, GPIO_Pin_6, Bit_SET);
252
    EthLinkStatus = 1;
253
    while(1)
254
    {
255
        SendString(USART1, "1");
256
        if (ETH_CheckFrameReceived())
257
        {
258
            GPIO_ToggleBits(GPIOA, GPIO_Pin_6);
259
            SendString(USART1, "Frame Recieved\n\0");
260
            /* process received ethernet packet */
261
            LwIP_Pkt_Handle();
262
        }
263
        /* handle periodic timers for LwIP */
264
        LwIP_Periodic_Handle(LocalTime);
265
        GPIO_ToggleBits(GPIOB, GPIO_Pin_6);
266
    }
267
}

Der PHY detektiert das vorhanden sein eines Links zuverlässig.
Zudem bemerke ich, dass sich der STM nach ein paar Durchläufen der 
Haupt-Schleife aufhängt.
Ich vermute, dass da irgendwelche Interrupts quer laufen, aber ich finde 
keinen Fehler.
Hat von euch jemand schon mal etwas in die Richtung gemacht, gibt es da 
irgendetwas, was ich nicht beachtet habe?

Mit freundlichen Grüßen

J.Hebeler
Gast #3529884
Lesenswert?

Hallo J (hier üblicherweise per Du),

das Spiel hatte ich vor einigen Wochen, ich musste eCos mit lwip 1.3 auf 
RMII umstellen.

>> Ich vermute, dass da irgendwelche Interrupts quer laufen
du solltest nur eine ISR brauchen. Ich tippe mal darauf, dass 
unerwartete events (interrupt nicht löschbar, Phy meldet sich nicht auf 
Diagnoseschnittstelle) nicht abgefangen sind. Deshalb s. u.

Mein Quellcode wird dir nichts bringen, aber einige Ansätze zum 
debugging kann ich dir bieten:
- teste deine Hardware, verwende dazu z.B. das vor längerem von mir 
gepostete binary
- der Phy arbeitet komplett ohne Parametrisierung, d. h. link und Daten 
(broadcast) zeigt er an, der Interrupt etc. muss funktionieren
- debugge im Treiber (ist der originale von ST nicht als mies bekannt?) 
mit printf's, der Rest ist sicherlich kein Problem

Gruß
Bernhard
Gast #3530903
Lesenswert?

>Ich tippe mal darauf, dass
unerwartete events (interrupt nicht löschbar, Phy meldet sich nicht auf
Diagnoseschnittstelle) nicht abgefangen sind.

Da hast du recht, das nicht abgefangene Event war "ETH_IRQHandler".
Nach etwas suche habe ich endlich meinen Fehler gefunden und ich muss 
sagen, das war mal weider ein Eigentor.

Ich hatte mir mein Code aus einigen Quellen zusammen kopiert und nicht 
darauf geachtet, was ich mache. Vor allem in der Funktion 
ETH_NVIC_Config() hätte mir auffallen müssen, dass ich den Interrupt gar 
nicht abfange. Und auch in den Standalone-Beispielen von ST ist dieser 
Interrupt nicht aktiviert. Genau so wenig wie die DMA-interrupts.
Die komplette Auswertung findet periodisch in der haupt while schleife 
statt, interrupts sind gar nicht notwendig.

Hier jetzt meine Funktionierende Initialisierung:
1
#include "stm32f2xx_conf.h"
2

3
#include "FSMC.h"
4
#include "stm32f2x7_eth.h"
5
#include "netconf.h"
6
//#include "stm32f2x7_eth_bsp.h"
7

8
#define SYSTEMTICK_PERIOD_MS  10
9
#define DP83848_PHY_ADDRESS 0x01
10
/* Specific defines for EXTI line, used to manage Ethernet link status */
11
#define ETH_LINK_EXTI_LINE             EXTI_Line14
12
#define ETH_LINK_EXTI_PORT_SOURCE      EXTI_PortSourceGPIOB
13
#define ETH_LINK_EXTI_PIN_SOURCE       EXTI_PinSource14
14
#define ETH_LINK_EXTI_IRQn             EXTI15_10_IRQn
15
/* PB14 */
16
#define ETH_LINK_PIN                   GPIO_Pin_14
17
#define ETH_LINK_GPIO_PORT             GPIOB
18
#define ETH_LINK_GPIO_CLK              RCC_AHB1Periph_GPIOB
19
/* PHY registers */
20
#define PHY_MICR                  0x11 /* MII Interrupt Control Register */
21
#define PHY_MICR_INT_EN           ((uint16_t)0x0002) /* PHY Enable interrupts */
22
#define PHY_MICR_INT_OE           ((uint16_t)0x0001) /* PHY Enable output interrupt events */
23
#define PHY_MISR                  0x12 /* MII Interrupt Status and Misc. Control Register */
24
#define PHY_MISR_LINK_INT_EN      ((uint16_t)0x0020) /* Enable Interrupt on change of link status */
25
#define PHY_LINK_STATUS           ((uint16_t)0x2000) /* PHY link status interrupt mask */
26

27
__IO uint32_t LocalTime = 0;
28
__IO uint8_t EthLinkStatus = 0;
29

30
void SendString(USART_TypeDef * usart, char * text)
31
{
32
    while(*text != 0)
33
    {
34
        while (USART_GetFlagStatus (usart, USART_FLAG_TXE)== RESET);
35
        USART_SendData(usart, *text);
36
        text++;
37
    }
38
}
39

40
void Delay2(unsigned long a)
41
{
42
    while(a > 0) a--;
43
}
44

45
void InitUart()
46
{
47
    GPIO_InitTypeDef GPIO_InitStructure;
48
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
49
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
50

51
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
52
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
53
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
54
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
55
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
56
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
57
    GPIO_Init(GPIOA, &GPIO_InitStructure);
58

59
    /* RX Pin */
60
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
61
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
62
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
63
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
64
    GPIO_Init(GPIOA, &GPIO_InitStructure);
65

66
    USART_InitTypeDef USART_InitStructure;
67

68
    USART_InitStructure.USART_BaudRate = 57600;
69
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
70
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
71
    USART_InitStructure.USART_Parity = USART_Parity_No;
72
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
73
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
74

75
    USART_Init(USART1, &USART_InitStructure);
76

77
    USART_Cmd(USART1, ENABLE);
78
}
79

80
uint8_t  InitMAC()
81
{
82
    GPIO_InitTypeDef GPIO_InitStructure;
83
    ETH_InitTypeDef ETH_InitStructure;
84
    RCC_ClocksTypeDef RCC_Clocks;
85

86
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
87
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
88
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
89

90
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH);
91
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH);
92
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH);
93
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO);
94
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
95
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
96
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7 | GPIO_Pin_8;
97
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
98
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
99
    GPIO_Init(GPIOA, &GPIO_InitStructure);
100

101
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_ETH);
102
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_ETH);
103
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH);
104
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
105
    GPIO_Init(GPIOB, &GPIO_InitStructure);
106

107
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH);
108
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH);
109
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH);
110
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
111
    GPIO_Init(GPIOC, &GPIO_InitStructure);
112

113

114
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC, ENABLE);
115
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
116
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC_Tx, ENABLE);
117
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
118
    RCC_AHB1PeriphClockCmd(ETH_LINK_GPIO_CLK, ENABLE);
119
    SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
120

121

122
    // Set PLL3 clock output to 50MHz
123
    RCC_MCO1Config(RCC_MCO1Source_PLLCLK, RCC_MCO1Div_2);
124

125
    /* Reset ETHERNET on AHB Bus */
126
    ETH_DeInit();
127

128
    // Software reset
129
    ETH_SoftwareReset();
130
    GPIO_SetBits(GPIOA, GPIO_Pin_6);
131
    // Wait for software reset
132
    while (ETH_GetSoftwareResetStatus() == SET);
133
    GPIO_ResetBits(GPIOA, GPIO_Pin_6);
134

135
    // ETHERNET Configuration ------------------------------------------------------
136
    // Call ETH_StructInit if you don't like to configure all ETH_InitStructure parameter
137
    ETH_StructInit(&ETH_InitStructure);
138

139
    /* Fill ETH_InitStructure parametrs */
140
    /*------------------------   MAC   -----------------------------------*/
141
    ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable  ;
142
    ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
143
    ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
144
    ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
145
    ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable;
146
    ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
147
    ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
148
    ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
149
    ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
150
    #ifdef CHECKSUM_BY_HARDWARE
151
    ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable;
152
    #endif
153

154
    /*------------------------   DMA   -----------------------------------*/
155

156
    /* When we use the Checksum offload feature, we need to enable the Store and Forward mode:
157
    the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum,
158
    if the checksum is OK the DMA can handle the frame otherwise the frame is dropped */
159
    ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable;
160
    ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
161
    ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
162

163
    ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
164
    ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
165
    ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;
166
    ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
167
    ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable;
168
    ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
169
    ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
170
    ETH_InitStructure.ETH_DMAArbitration =  ETH_DMAArbitration_RoundRobin_RxTx_2_1;
171

172
    ETH_Init(&ETH_InitStructure, DP83848_PHY_ADDRESS);
173

174
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
175
    RCC_GetClocksFreq(&RCC_Clocks);
176
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
177

178
    return SUCCESS;
179

180
}
181

182
void Time_Update(void)
183
{
184
    LocalTime += SYSTEMTICK_PERIOD_MS;
185
}
186

187
int main(void)
188
{
189
    SystemInit();
190

191
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
192
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
193

194
    InitUart();
195
    InitFSMC();
196
    InitMAC();
197
    LwIP_Init();
198
    
199
    while(1)
200
    {
201
        if (ETH_CheckFrameReceived())
202
        {
203
            SendString(USART1, "Frame Recieved\n\0");
204
            //process received ethernet packet
205
            LwIP_Pkt_Handle();
206
        }
207
        /* handle periodic timers for LwIP */
208
        LwIP_Periodic_Handle(LocalTime);
209
    }
210
}
Ich verwende den ST Ethernet Driver V1.1.0 und lwip 1.3.0, Systemtakt 
kommt von nem 25MHz Quarz und wird per PLL auf 100MHz erhöht. Takt für 
RMII kommt aus MCO1 und ist 50Mhz.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren