樊春春 преди 2 години
родител
ревизия
d66a02e28f

+ 1 - 1
MiddleWare/lwip-2.0.2/port/STM32F4xx/UCOS_II/ethernetif.c

@@ -129,7 +129,7 @@ static void low_level_init(struct netif *netif)
     //     for (i = 0; i < ETH_RXBUFNB; i++)
     //     {
 
-    //         ETH_DMARxDescTransmitITConfig(&DMARxDscrTab[i], ENABLE);
+    //         ETHDM(&DMARxDscrTab[i], ENABLE);
     //     }
     // }
 

+ 4 - 2
User/Bsp/armfly_bsp.c

@@ -14,8 +14,10 @@ void bsp_init(void)
 
     uart1_init();
     uart3_init();
-    enet_system_setup();
-    lwip_stack_init();
+
+    eth_init();
+    // dm9k_init();
+    lwip_setup();
     // can初始化
     can_network_init();
 }

+ 1 - 1
User/Bsp/armfly_bsp.h

@@ -2,6 +2,7 @@
 #define _ARMFLY_H__
 
 #include "can.h"
+#include "dm9k.h"
 #include "fly_param.h"
 #include "interface.h"
 #include "netconf.h"
@@ -9,5 +10,4 @@
 #include "timer.h"
 #include "uart1.h"
 #include "uart3.h"
-
 #endif

+ 124 - 15
User/Bsp/eth/stm32f4x7_phy.c

@@ -8,8 +8,8 @@
 ETH_InitTypeDef     ETH_InitStructure;
 __IO uint32_t       EthStatus = 0;
 extern struct netif gnetif;
-static void         dm9161_gpio_config(void);
-static void         dm9161_mac_dma_config(void);
+static void         phy_gpio_config(void);
+static void         phy_mac_dma_config(void);
 static void         nvic_configuration(void);
 
 /**
@@ -20,6 +20,7 @@ static void         nvic_configuration(void);
 void ETH_Delay10ms(uint32_t nCount)
 {
     // OSTimeDly(10 * nCount);
+    USE_Delay(10 * nCount);
 }
 
 /*!
@@ -28,15 +29,15 @@ void ETH_Delay10ms(uint32_t nCount)
     \param[out] none
     \retval     none
 */
-void enet_system_setup(void)
+void eth_init(void)
 {
     nvic_configuration();
 
     /* configure the GPIO ports for ethernet pins */
-    dm9161_gpio_config();
+    phy_gpio_config();
 
     /* configure the ethernet MAC/DMA */
-    dm9161_mac_dma_config();
+    phy_mac_dma_config();
 
     /* Get Ethernet link status*/
     if (ETH_ReadPHYRegister(ETHERNET_PHY_ADDRESS, PHY_SR) & 1)
@@ -47,8 +48,7 @@ void enet_system_setup(void)
     /* Configure the PHY to generate an interrupt on change of link status */
     Eth_Link_PHYITConfig(ETHERNET_PHY_ADDRESS);
 
-    ETH_DMAITConfig(ETH_DMA_IT_R, ENABLE);
-    ETH_DMAITConfig(ETH_DMA_IT_NIS, ENABLE);
+    ETH_DMAITConfig(ETH_DMA_IT_R | ETH_DMA_IT_NIS, ENABLE);
 }
 
 /*!
@@ -57,7 +57,7 @@ void enet_system_setup(void)
     \param[out] none
     \retval     none
 */
-static void dm9161_mac_dma_config(void)
+static void phy_mac_dma_config(void)
 {
 
     /* Reset ETHERNET on AHB Bus */
@@ -165,7 +165,7 @@ static void nvic_configuration(void)
     \param[out] none
     \retval     none
 */
-static void dm9161_gpio_config(void)
+static void phy_gpio_config(void)
 {
     /* Enable SYSCFG clock */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
@@ -237,12 +237,121 @@ uint32_t Eth_Link_PHYITConfig(uint16_t PHYAddress)
 }
 
 /**
- * @note   ETH_Get_Link_Status
- * @brief  Get Ethernet link status
- * @param  None
+ * @brief  Link callback function, this function is called on change of link status.
+ * @param  The network interface
  * @retval None
  */
-uint8_t ETH_Get_Link_Status(void)
+void ETH_link_callback(struct netif *netif)
 {
-    return (ETH_ReadPHYRegister(ETHERNET_PHY_ADDRESS, PHY_BSR) & PHY_Linked_Status);
-}
+    __IO uint32_t timeout = 0;
+    uint32_t      tmpreg;
+    uint16_t      RegValue;
+    ip4_addr_t    ipaddr;
+    ip4_addr_t    netmask;
+    ip4_addr_t    gw;
+
+    if (netif_is_link_up(netif))
+    {
+        /* Restart the auto-negotiation */
+        if (ETH_InitStructure.ETH_AutoNegotiation != ETH_AutoNegotiation_Disable)
+        {
+            /* Reset Timeout counter */
+            timeout = 0;
+
+            /* Enable auto-negotiation */
+            ETH_WritePHYRegister(ETHERNET_PHY_ADDRESS, PHY_BCR, PHY_AutoNegotiation);
+
+            /* Wait until the auto-negotiation will be completed */
+            do
+            {
+                timeout++;
+            } while (!(ETH_ReadPHYRegister(ETHERNET_PHY_ADDRESS, PHY_BSR) & PHY_AutoNego_Complete) && (timeout < (uint32_t)PHY_READ_TO));
+
+            /* Reset Timeout counter */
+            timeout = 0;
+
+            /* Read the result of the auto-negotiation */
+            RegValue = ETH_ReadPHYRegister(ETHERNET_PHY_ADDRESS, PHY_SR);
+
+            /* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */
+            if ((RegValue & PHY_DUPLEX_STATUS) != (uint16_t)RESET)
+            {
+                /* Set Ethernet duplex mode to Full-duplex following the auto-negotiation */
+                ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex;
+            }
+            else
+            {
+                /* Set Ethernet duplex mode to Half-duplex following the auto-negotiation */
+                ETH_InitStructure.ETH_Mode = ETH_Mode_HalfDuplex;
+            }
+            /* Configure the MAC with the speed fixed by the auto-negotiation process */
+            if (RegValue & PHY_SPEED_STATUS)
+            {
+                /* Set Ethernet speed to 10M following the auto-negotiation */
+                ETH_InitStructure.ETH_Speed = ETH_Speed_10M;
+            }
+            else
+            {
+                /* Set Ethernet speed to 100M following the auto-negotiation */
+                ETH_InitStructure.ETH_Speed = ETH_Speed_100M;
+            }
+
+            /*------------------------ ETHERNET MACCR Re-Configuration --------------------*/
+            /* Get the ETHERNET MACCR value */
+            tmpreg = ETH->MACCR;
+
+            /* Set the FES bit according to ETH_Speed value */
+            /* Set the DM bit according to ETH_Mode value */
+            tmpreg |= (uint32_t)(ETH_InitStructure.ETH_Speed | ETH_InitStructure.ETH_Mode);
+
+            /* Write to ETHERNET MACCR */
+            ETH->MACCR = (uint32_t)tmpreg;
+
+            _eth_delay_(ETH_REG_WRITE_DELAY);
+
+            tmpreg     = ETH->MACCR;
+            ETH->MACCR = tmpreg;
+        }
+
+        /* Restart MAC interface */
+        ETH_Start();
+
+#ifdef USE_DHCP
+        ipaddr.addr  = 0;
+        netmask.addr = 0;
+        gw.addr      = 0;
+        DHCP_state   = DHCP_START;
+#else
+        IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
+        IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
+        IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+#endif /* USE_DHCP */
+
+        netif_set_addr(&gnetif, &ipaddr, &netmask, &gw);
+
+        /* When the netif is fully configured this function must be called.*/
+        netif_set_up(&gnetif);
+
+        /* 打印调试信息 */
+        printf("LwIP Network Cable is now connected \r\n");
+
+#ifndef USE_DHCP
+        /* Display static IP address */
+        printf("LwIP Static IP address = %d.%d.%d.%d  \r\n", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
+#endif /* USE_DHCP */
+    }
+    else
+    {
+        ETH_Stop();
+#ifdef USE_DHCP
+        DHCP_state = DHCP_LINK_DOWN;
+        dhcp_stop(netif);
+#endif /* USE_DHCP */
+
+        /*  When the netif link is down this function must be called.*/
+        netif_set_down(&gnetif);
+
+        /* 打印调试信息 */
+        printf("LwIP Network Cable is unplugged \r\n");
+    }
+}

+ 1 - 2
User/Bsp/eth/stm32f4x7_phy.h

@@ -13,9 +13,8 @@
 /* Ethernet Flags for EthStatus variable */
 #define ETH_INIT_FLAG 0x01
 #define ETH_LINK_FLAG 0x10
-void                 enet_system_setup(void);
+void                 eth_init(void);
 uint32_t             Eth_Link_PHYITConfig(uint16_t PHYAddress);
-void                 Eth_Link_EXTIConfig(void);
 void                 Eth_Link_ITHandler(uint16_t PHYAddress);
 void                 ETH_link_callback(struct netif *netif);
 extern __IO uint32_t EthStatus; /* 提供给主程序使用 */

+ 42 - 16
User/Bsp/interface/interface.c

@@ -23,10 +23,11 @@ Gpio_Clock clock_info[] = {
     {.type = kUart3, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_USART3},
     {.type = kCAN1, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN1},
     {.type = kCAN2, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN2},
-    {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC},
-    {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Tx},
-    {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Rx},
-    {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_PTP},
+    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC},
+    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Tx},
+    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Rx},
+    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_PTP},
+    {.type = kEthernet_dm9k, .RCC_AXBPeriph = RCC_AHB3Periph, .AF_Clock = RCC_AHB3Periph_FSMC},
     // {.type = kPMU, .AXBPeriph_Clock = RCU_PMU},
     {.type = kDMA1, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_DMA1},
     // //    {.type = kTIMER1,   .AXBPeriph_Clock = RCU_TIMER1},
@@ -77,19 +78,44 @@ Interface_struct interface_info[] = {
     // {.type = kUart6, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_6, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource6, .GPIO_AF = GPIO_AF_USART6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
     // {.type = kUart6, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_USART6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
     // {.type = kUart6, .GPIOx = UART6_ENABLE_PORT, .GPIO_Pin = UART6_ENABLE_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    // ethernet
-    {.type = kEthernet, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_2, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource2, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet, .GPIOx = ETH_RESET_PORT, .GPIO_Pin = ETH_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
-    //         //    {.type = kEthernet, .GPIOx = ETH_RXER_PORT,  .GPIO_Pin = ETH_RXER_PIN,  .GPIO_Mode = GPIO_MODE_INPUT,  .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
+    // ethernet-dm9161
+    {.type = kEthernet_dm9101, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_2, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource2, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9101, .GPIOx = ETH_RESET_PORT, .GPIO_Pin = ETH_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
+    //         //    {.type = kEthernet_dm9101, .GPIOx = ETH_RXER_PORT,  .GPIO_Pin = ETH_RXER_PIN,  .GPIO_Mode = GPIO_MODE_INPUT,  .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
 
+    // ethernet-dm9k
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_0, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource0, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_8, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource8, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_9, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource9, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_15, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource15, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_8, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource8, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_9, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource9, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_12, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource12, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_15, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource15, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9k, .GPIOx = DM9K_RESET_PORT, .GPIO_Pin = DM9K_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
     //         // input
     //         {.type = kInput, .In_Type = kLDetect, .GPIOx = LDetect1_PORT, .GPIO_Pin = LDetect1_PIN, .GPIO_Mode = GPIO_MODE_INPUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
 

+ 8 - 3
User/Bsp/interface/interface.h

@@ -17,7 +17,8 @@ typedef enum
     kUart3,
     kCAN1,
     kCAN2,
-    kEthernet,
+    kEthernet_dm9101,
+    kEthernet_dm9k,
     kInput,
     kOutput,
     kPMU,
@@ -133,8 +134,12 @@ typedef struct
 #define ETH_RESET_PIN  GPIO_Pin_6
 // #define ETH_RXER_PORT GPIOG
 // #define ETH_RXER_PIN GPIO_PIN_12
-#define ETH_RESET_ON  GPIO_ResetBits(ETH_RESET_PORT, ETH_RESET_PIN)
-#define ETH_RESET_OFF GPIO_SetBits(ETH_RESET_PORT, ETH_RESET_PIN)
+#define ETH_RESET_ON    GPIO_ResetBits(ETH_RESET_PORT, ETH_RESET_PIN)
+#define ETH_RESET_OFF   GPIO_SetBits(ETH_RESET_PORT, ETH_RESET_PIN)
+#define DM9K_RESET_PORT GPIOA
+#define DM9K_RESET_PIN  GPIO_Pin_15
+#define DM9K_RESET_ON   GPIO_ResetBits(DM9K_RESET_PORT, DM9K_RESET_PIN)
+#define DM9K_RESET_OFF  GPIO_SetBits(DM9K_RESET_PORT, DM9K_RESET_PIN)
 
 // output
 #define LED0_RUN_PORT GPIOC

+ 12 - 0
User/Bsp/uart/uart1.c

@@ -11,6 +11,18 @@
 #include "uart1.h"
 #include "queue.h"
 
+//  重定义fputc函数
+#ifdef __GNUC__
+
+int _write(int fd, char *pBuffer, int size)
+{
+    while (RESET != USART_GetITStatus(USART1, USART_IT_TC))
+        ;
+    uart1_dma_send((INT8U *)pBuffer, size);
+    return size;
+}
+#endif
+
 static INT8U uart1_tx_buf[UART1_TX_LEN]  = {0};
 static INT8U uart1_rx_buf[UART1_REC_LEN] = {0};
 

+ 44 - 129
User/app/dm9k/dm9k.c

@@ -42,19 +42,12 @@
 
 #define ETH_ADDR_LEN 6
 
-/* 定义网卡的 MAC 地址 */
-static unsigned char DEF_MAC_ADDR[ETH_ADDR_LEN] = {0x00, 0x60, 0x6e, 0x90, 0x00, 0xae};
-uint8_t              SendPackOk                 = 0;
-
-uint8_t s_FSMC_Init_Ok = 0; /* 用于指示FSMC是否初始化 */
-
-//#define printk(...)
-#define printk printf
+uint8_t SendPackOk = 0;
+uint8_t is_fsmc_ok = 0; /* 用于指示FSMC是否初始化 */
 
 void dm9k_debug_test(void);
 
-static void DM9K_CtrlLinesConfig(void);
-static void DM9K_FSMCConfig(void);
+static void dm9k_fsmc(void);
 static void dm9k_initnic(void);
 
 /*
@@ -67,99 +60,22 @@ static void dm9k_initnic(void);
 */
 void dm9k_init(void)
 {
-    DM9K_CtrlLinesConfig();
-    DM9K_FSMCConfig();
+    dm9k_fsmc();
 
-    s_FSMC_Init_Ok = 1;
+    is_fsmc_ok = 1;
 
     dm9k_initnic(); /* 配置DM9000 */
 }
 
 /*
 *********************************************************************************************************
-*	函 数 名: DM9K_CtrlLinesConfig
-*	功能说明: 配置DM9000AE控制口线,FSMC管脚设置为复用功能 (For SMT32F4)
-*	形    参: 无
-*	返 回 值: 无
-*********************************************************************************************************
-*/
-static void DM9K_CtrlLinesConfig(void)
-{
-    GPIO_InitTypeDef GPIO_InitStructure;
-
-    /* 使能FSMC时钟 */
-    RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
-
-    /* 使能 GPIO时钟 */
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG, ENABLE);
-
-    /* 设置 PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
-     PD.10(D15), PD.14(D0), PD.15(D1) 为复用推挽输出 */
-
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);
-
-    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
-                                  GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
-                                  GPIO_Pin_15;
-    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
-    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
-    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
-    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
-    GPIO_Init(GPIOD, &GPIO_InitStructure);
-
-    /* 设置 PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
-     PE.14(D11), PE.15(D12) 为复用推挽输出 */
-
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_FSMC);
-
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource7, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource8, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource12, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource14, GPIO_AF_FSMC);
-    GPIO_PinAFConfig(GPIOE, GPIO_PinSource15, GPIO_AF_FSMC);
-
-    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
-                                  GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
-                                  GPIO_Pin_15;
-    GPIO_Init(GPIOE, &GPIO_InitStructure);
-
-    /* 设置 PD.13(A18 (RS))  为复用推挽输出 */
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FSMC);
-
-    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
-    GPIO_Init(GPIOD, &GPIO_InitStructure);
-
-    /* 设置 PG10 (CS)) 为复用推挽输出 */
-    GPIO_PinAFConfig(GPIOG, GPIO_PinSource10, GPIO_AF_FSMC);
-
-    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
-    GPIO_Init(GPIOG, &GPIO_InitStructure);
-
-    /* PA15 是DM9000_INT中断输入口(本程序未使用) */
-}
-
-/*
-*********************************************************************************************************
-*	函 数 名: DM9K_FSMCConfig
+*	函 数 名: dm9k_fsmc
 *	功能说明: 配置FSMC并口访问时序
 *	形    参: 无
 *	返 回 值: 无
 *********************************************************************************************************
 */
-static void DM9K_FSMCConfig(void)
+static void dm9k_fsmc(void)
 {
     FSMC_NORSRAMInitTypeDef       FSMC_NORSRAMInitStructure;
     FSMC_NORSRAMTimingInitTypeDef p;
@@ -234,31 +150,31 @@ void dm9k_WriteReg(uint8_t reg, uint8_t writedata)
 *	返 回 值: 无
 *********************************************************************************************************
 */
-void dm9k_hash_table(void)
-{
-    uint8_t i;
-
-    /* 将MAC地址告诉uip */
-    for (i = 0; i < 6; i++)
-    {
-        uip_ethaddr.addr[i] = DEF_MAC_ADDR[i];
-    }
-
-    /* 设置 网卡 MAC 位置,来自於 MyHardware */
-    for (i = 0; i < 6; i++)
-    {
-        dm9k_WriteReg(DM9000_REG_PAR + i, DEF_MAC_ADDR[i]);
-    }
-
-    /* 清除 网卡多播设置 */
-    for (i = 0; i < 8; i++)
-    {
-        dm9k_WriteReg(DM9000_REG_MAR + i, 0x00);
-    }
-
-    /* 设置 广播包 设置 */
-    dm9k_WriteReg(DM9000_REG_MAR + 7, 0x80);
-}
+// void dm9k_hash_table(void)
+// {
+//     uint8_t i;
+
+//     /* 将MAC地址告诉uip */
+//     for (i = 0; i < 6; i++)
+//     {
+//         uip_ethaddr.addr[i] = DEF_MAC_ADDR[i];
+//     }
+
+//     /* 设置 网卡 MAC 位置,来自於 MyHardware */
+//     for (i = 0; i < 6; i++)
+//     {
+//         dm9k_WriteReg(DM9000_REG_PAR + i, DEF_MAC_ADDR[i]);
+//     }
+
+//     /* 清除 网卡多播设置 */
+//     for (i = 0; i < 8; i++)
+//     {
+//         dm9k_WriteReg(DM9000_REG_MAR + i, 0x00);
+//     }
+
+//     /* 设置 广播包 设置 */
+//     dm9k_WriteReg(DM9000_REG_MAR + 7, 0x80);
+// }
 
 /*
 *********************************************************************************************************
@@ -271,9 +187,9 @@ void dm9k_hash_table(void)
 void dm9k_reset(void)
 {
     dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET); /* 对 DM9000A 进行软件重置 */
-    bsp_DelayUS(10);                                 /* delay 10us */
+    OSTimeDly(10);                                   /* delay 10us */
     dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET); /* 对 DM9000A 进行软件重置 */
-    bsp_DelayUS(10);                                 /* delay 10us */
+    OSTimeDly(10);                                   /* delay 10us */
 
     /* 基本记存器相关设置 */
     dm9k_WriteReg(DM9000_REG_IMR, DM9000_IMR_OFF);   /* 开启内存自环模式 */
@@ -341,9 +257,9 @@ void dm9k_phy_write(uint8_t phy_reg, uint16_t writedata)
 static void dm9k_initnic(void)
 {
     dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET); /* 对 DM9000A 进行软件重置 */
-    bsp_DelayUS(10);                                 /* delay 10us */
+    OSTimeDly(10);                                   /* delay 10us */
 
-    dm9k_hash_table(); /* 设置 DM9000A MAC 及 多播*/
+    // dm9k_hash_table(); /* 设置 DM9000A MAC 及 多播*/
 
     dm9k_reset(); /* 进行 DM9000A 软件设置 */
 
@@ -495,7 +411,7 @@ void dm9k_send_packet(uint8_t *p_char, uint16_t length)
     {
         while (dm9k_ReadReg(DM9000_REG_TCR) & DM9000_TCR_SET)
         {
-            bsp_DelayUS(5);
+            OSTimeDly(5);
         }
         SendPackOk = 0;
     }
@@ -579,12 +495,11 @@ uint32_t dm9k_ReadID(void)
 {
     uint8_t vid1, vid2, pid1, pid2;
 
-    if (s_FSMC_Init_Ok == 0)
+    if (is_fsmc_ok == 0)
     {
-        DM9K_CtrlLinesConfig();
-        DM9K_FSMCConfig();
+        dm9k_fsmc();
 
-        s_FSMC_Init_Ok = 1;
+        is_fsmc_ok = 1;
     }
     vid1 = dm9k_ReadReg(DM9000_REG_VID_L) & 0xFF;
     vid2 = dm9k_ReadReg(DM9000_REG_VID_H) & 0xFF;
@@ -613,9 +528,9 @@ uint32_t dm9k_ReadID(void)
 		uint16_t j;
 
 		dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET);			/* 对 DM9000A 进行软件重置 */
-		bsp_DelayUS(10);								/* delay 10us */
+		OSTimeDly(10);								/* delay 10us */
 		dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET);			/* 对 DM9000A 进行软件重置 */
-		bsp_DelayUS(10);								/* delay 10us */
+		OSTimeDly(10);								/* delay 10us */
 
 		check_device  = dm9k_ReadReg(DM9000_REG_VID_L);
 		check_device |= dm9k_ReadReg(DM9000_REG_VID_H) << 8;
@@ -713,9 +628,9 @@ uint32_t dm9k_ReadID(void)
 
 		printk("DM9K_DEBUG ==> PACKET SEND & INT TEST !! \n");
 		dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET);
-		bsp_DelayUS(10);
+		OSTimeDly(10);
 		dm9k_WriteReg(DM9000_REG_NCR, DM9000_REG_RESET);
-		bsp_DelayUS(10);
+		OSTimeDly(10);
 
 		dm9k_WriteReg(DM9000_REG_IMR, DM9000_IMR_OFF | DM9000_TX_INTR);
 

+ 2 - 27
User/app/modbus/modbus.c

@@ -331,6 +331,7 @@ void modbus_slave_task(void)
         test_buf[1] = 0xBB;
         test_buf[2] = 0xAA;
         uart3_dma_send(test_buf, 3);
+        printf(test_buf);
         if ((err == OS_ERR_NONE) && (msg->len >= 2))
         {
             if ((msg->buf[0] == 0x00) && (msg->buf[1] == 0xAA) && (msg->buf[2] == 0xBB))
@@ -339,34 +340,8 @@ void modbus_slave_task(void)
                 test_buf[1] = 0xBB;
                 test_buf[2] = 0xAA;
                 uart3_dma_send(test_buf, 3);
+                printf("dsdasdasdds");
             }
         }
     }
 }
-
-void modbus_master_task(void)
-{
-    INT8U              err          = 0;
-    INT8U              test_buf[20] = {0};
-    UartFrame_TypeDef *msg;
-    while (1)
-    {
-        OSTimeDly(200);
-        iwdg_feed(UART1_DOG);
-        msg = (UartFrame_TypeDef *)OSMboxPend(uart1_mbox, 50, &err);
-        // test_buf[0] = 0x01;
-        // test_buf[1] = 0x00;
-        // test_buf[2] = 0x00;
-        // uart1_dma_send(test_buf, 3);
-        if ((err == OS_ERR_NONE) && (msg->len >= 2))
-        {
-            if ((msg->buf[0] == 0x00) && (msg->buf[1] == 0x00) && (msg->buf[2] == 0x00))
-            {
-                // test_buf[0] = 0x00;
-                // test_buf[1] = 0xBB;
-                // test_buf[2] = 0xAA;
-                // uart1_dma_send(test_buf, 3);
-            }
-        }
-    }
-}

+ 3 - 24
User/config/lwip/netconf.c

@@ -35,37 +35,14 @@ ip4_addr_t      ip_address = {0};
 #endif /* USE_DHCP */
 
 struct netif gnetif;
-/**
- * @brief  Link callback function, this function is called on change of link status.
- * @param  The network interface
- * @retval None
- */
-void ETH_link_callback(struct netif *netif)
-{
-    if (netif_is_link_up(netif))
-    {
-        /* When the netif is fully configured this function must be called.*/
-        netif_set_up(&gnetif);
-    }
-    else
-    {
-        ETH_Stop();
-#ifdef USE_DHCP
-        DHCP_state = DHCP_LINK_DOWN;
-        dhcp_stop(netif);
-#endif /* USE_DHCP */
 
-        /*  When the netif link is down this function must be called.*/
-        netif_set_down(&gnetif);
-    }
-}
 /*!
     \brief      initializes the LwIP stack
     \param[in]  none
     \param[out] none
     \retval     none
 */
-void lwip_stack_init(void)
+void lwip_setup(void)
 {
     ip4_addr_t ipaddr;
     ip4_addr_t netmask;
@@ -103,11 +80,13 @@ void lwip_stack_init(void)
       初始化函数指针必须指向您的以太网netif接口的初始化函数。 以下代码说明了它的用法。*/
     netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
 
+    printf("LwIP Registers the default network interface....\r\n");
     /* 注册默认网络接口.*/
     netif_set_default(&gnetif);
 
     if (EthStatus == (ETH_INIT_FLAG | ETH_LINK_FLAG))
     {
+        printf("LwIP Finish interface....\r\n");
         gnetif.flags |= NETIF_FLAG_LINK_UP;
         /* 配置完成网卡后启动网卡*/
         netif_set_up(&gnetif);

+ 10 - 2
User/config/lwip/netconf.h

@@ -40,7 +40,7 @@ OF SUCH DAMAGE.
 
 //#define USE_DHCP       1 /* enable DHCP, if disabled static address is used */
 
-// #define USE_ETH_INTERRUPT
+#define USE_ETH_INTERRUPT
 //#define TIMEOUT_CHECK_USE_LWIP
 /* MAC address: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
 #define MAC_ADDR0 2
@@ -50,6 +50,14 @@ OF SUCH DAMAGE.
 #define MAC_ADDR4 0xD
 #define MAC_ADDR5 6
 
+/* 定义网卡的 MAC 地址 */
+#define DM9K_MAC_ADDR0 0x00
+#define DM9K_MAC_ADDR1 0x60
+#define DM9K_MAC_ADDR2 0x6e
+#define DM9K_MAC_ADDR3 0x90
+#define DM9K_MAC_ADDR4 0x00
+#define DM9K_MAC_ADDR5 0xae
+
 /* static IP address: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
 #define IP_ADDR0 192
 #define IP_ADDR1 168
@@ -88,6 +96,6 @@ OF SUCH DAMAGE.
 void dhcp_task(void *pvParameters);
 #endif /* USE_DHCP */
 
-void lwip_stack_init(void);
+void lwip_setup(void);
 
 #endif /* NETCONF_H */

+ 9 - 9
User/main.c

@@ -104,15 +104,15 @@ void init_task(void *pvParameters)
                     (void *)0,
                     (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
 
-    OSTaskCreateExt((void (*)(void *))modbus_master_task,
-                    (void *)0,
-                    (OS_STK *)&uart1_task_stk[UART1_TASK_STK_SIZE - 1],
-                    (INT8U)UART1_TASK_PRIO,
-                    (INT16U)UART1_TASK_PRIO,
-                    (OS_STK *)&uart1_task_stk[0],
-                    (INT32U)UART1_TASK_STK_SIZE,
-                    (void *)0,
-                    (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
+    // OSTaskCreateExt((void (*)(void *))modbus_master_task,
+    //                 (void *)0,
+    //                 (OS_STK *)&uart1_task_stk[UART1_TASK_STK_SIZE - 1],
+    //                 (INT8U)UART1_TASK_PRIO,
+    //                 (INT16U)UART1_TASK_PRIO,
+    //                 (OS_STK *)&uart1_task_stk[0],
+    //                 (INT32U)UART1_TASK_STK_SIZE,
+    //                 (void *)0,
+    //                 (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
 
     /* 485 modbus´Ó»úģʽ */
     OSTaskCreateExt((void (*)(void *))modbus_slave_task,

+ 2 - 1
platformio.ini

@@ -25,6 +25,7 @@ build_flags =
   -IUser/app/queue
   -IUser/app/led
   -IUser/app/modbus
+  -IUser/app/dm9k
   -IUser/app/net
   -IUser/config/lwip
   -IUser/config/ucos
@@ -56,7 +57,7 @@ build_unflags =
 
 src_filter = +<User/> 
             +<Project/GCC/> 
-            -<User/app/dm9k>
+            ; -<User/app/dm9k>
             +<Libraries/STM32F4xx_StdPeriph_Driver/src/>
             -<Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_qspi.c>
             -<Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmpi2c.c>