Skip to content

Commit eb39c48

Browse files
committed
Add EMAC driver for GD32_F307VG
1 parent 55a4261 commit eb39c48

File tree

3 files changed

+754
-0
lines changed

3 files changed

+754
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 Gigadevice
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "gd32f30x.h"
18+
19+
/**
20+
* Initializes the HW pin for enet
21+
*
22+
*/
23+
void enet_bsp_init(void)
24+
{
25+
/* Enable GPIOs clocks */
26+
rcu_periph_clock_enable(RCU_GPIOA);
27+
rcu_periph_clock_enable(RCU_GPIOB);
28+
rcu_periph_clock_enable(RCU_GPIOC);
29+
rcu_periph_clock_enable(RCU_AF);
30+
31+
gpio_para_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_8);
32+
rcu_pll2_config(RCU_PLL2_MUL10);
33+
rcu_osci_on(RCU_PLL2_CK);
34+
rcu_osci_stab_wait(RCU_PLL2_CK);
35+
rcu_ckout0_config(RCU_CKOUT0SRC_CKPLL2);
36+
gpio_ethernet_phy_select(GPIO_ENET_PHY_RMII);
37+
38+
/** ETH GPIO Configuration
39+
RMII_REF_CLK ----------------------> PA1
40+
RMII_MDIO -------------------------> PA2
41+
RMII_MDC --------------------------> PC1
42+
RMII_MII_CRS_DV -------------------> PA7
43+
RMII_MII_RXD0 ---------------------> PC4
44+
RMII_MII_RXD1 ---------------------> PC5
45+
RMII_MII_TX_EN --------------------> PB11
46+
RMII_MII_TXD0 ---------------------> PB12
47+
RMII_MII_TXD1 ---------------------> PB13
48+
*/
49+
/* PA1: ETH_RMII_REF_CLK */
50+
gpio_para_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_1);
51+
/* PA2: ETH_MDIO */
52+
gpio_para_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_2);
53+
/* PA7: ETH_RMII_CRS_DV */
54+
gpio_para_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_7);
55+
56+
/* PB11: ETH_RMII_TX_EN */
57+
gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_11);
58+
/* PB12: ETH_RMII_TXD0 */
59+
gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_12);
60+
/* PB13: ETH_RMII_TXD1 */
61+
gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_13);
62+
63+
/* PC1: ETH_MDC */
64+
gpio_para_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_1);
65+
/* PC4: ETH_RMII_RXD0 */
66+
gpio_para_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_4);
67+
/* PC5: ETH_RMII_RXD1 */
68+
gpio_para_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_5);
69+
70+
/* Enable the Ethernet global Interrupt */
71+
nvic_irq_enable(ENET_IRQn, 0x7, 0);
72+
73+
/* Enable ETHERNET clock */
74+
rcu_periph_clock_enable(RCU_ENET);
75+
rcu_periph_clock_enable(RCU_ENETTX);
76+
rcu_periph_clock_enable(RCU_ENETRX);
77+
}

0 commit comments

Comments
 (0)