STM32F407 以太网 外部提供时钟源的驱动修改错误总结

来源:互联网 发布:淘宝网一件代发赚钱吗 编辑:程序博客网 时间:2024/06/01 08:11

(1) 晕,不能放置图片

示例代码中:

void ETH_GPIO_Config(void)
{
     GPIO_InitTypeDef GPIO_InitStructure;


    /* Enable GPIOs clocks */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
                         RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE |
                         RCC_AHB1Periph_GPIOG , ENABLE);


    /* Enable SYSCFG clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


    
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOA, &GPIO_InitStructure); 



  /* MII/RMII Media interface selection --------------------------------------*/
#ifdef MII_MODE
 #ifdef PHY_CLOCK_MCO
  /* Configure MCO (PA8) */

  当不用MCU提供时钟时,直接删除该红色部分代码导致网路不通

  应该保留以下代码

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

    后面的代码需要用到前面的相关配置. 没注意到后面,直接删掉了,导致出错.


(2).以太网配置网速貌似不太好使,强制为100M的方法:

void ETH_BSP_Config(void)
{
  /* Configure the GPIO ports for ethernet pins */
  ETH_GPIO_Config();


  /* Config NVIC for Ethernet */
  ETH_NVIC_Config();


  /* Configure the Ethernet MAC/DMA */
  ETH_MACDMA_Config();


  if (EthInitStatus != 0)
  {
    printf("%s init failed! Err Num:%d.\n",__FUNCTION__,EthInitStatus);
    //delay_ms(100);
  }


  /* Configure the PHY to generate an interrupt on change of link status */
  //Eth_Link_PHYITConfig(DP83848_PHY_ADDRESS); //这里

   //ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;//这里
   ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Disable;
   ETH_InitStructure.ETH_Speed = ETH_Speed_100M;
   ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex;



    OK.搞定



0 0