各位大神好, 我现在在用stm32f107vct6这款芯片,PHY使用的是Realtek8201CP,MII模式。现在GPIO都已经初始化好了,上电后link灯亮了 但是网络不通,之前开发板用的是DP83848YB这个PHY,而且使用的是RMII模式,现在自己的硬件电路换了个PHY,也更换成 MII模式,在网上看了一些资料,说是需要更改三个寄存器: ////// 修改三个寄存器 /** @defgroup PHY_status_register * @{ */ /* The PHY status register value change from a PHY to another so the user have to update this value depending on the used external PHY */ /** * @brief For LAN8700 */ //#define PHY_SR 31 /*!< Tranceiver Status Register */ /** * @brief For DP83848 */ //#define PHY_SR 16 /*!< Tranceiver Status Register */ /** * @brief For DM9161 */ #define PHY_SR 17 /*!< Tranceiver Status Register */ /* The Speed and Duplex mask values change from a PHY to another so the user have to update this value depending on the used external PHY */ /** * @brief For LAN8700 */ //#define PHY_Speed_Status ((u16)0x0004) /*!< Configured information of Speed: 10Mbps */ //#define PHY_Duplex_Status ((u16)0x0010) /*!< Configured information of Duplex: Full-duplex */ /** * @brief For DP83848 */ //#define PHY_Speed_Status ((u16)0x0002) /*!< Configured information of Speed: 10Mbps */ //#define PHY_Duplex_Status ((u16)0x0004) /*!< Configured information of Duplex: Full-duplex */ /** * @brief For DM9161 */ #define PHY_Speed_Status ((u16)0x3000) /*!< Configured information of Speed: 10Mbps */ #define PHY_Duplex_Status ((u16)0xA000) /*!< Configured information of Duplex: Full-duplex */ 还有就是根据自己板子的硬件连接确定 PHY_ADDRESS,由RX0-RX3和CSR这几个脚组成PHYADDR0-4 芯片复位时,会锁存这5个脚的电平,作为芯片地址,以后就找这个作访问了。 所以,如果你是悬空的话,认为是0,一定要接1才认为是1我的是悬空的,都是00 //#define DP83848_PHY /* Ethernet pins mapped on STM3210C-EVAL Board */ #define PHY_ADDRESS 0x00 /* Relative to STM3210C-EVAL Board */ 改完上面几个地方就可以使用了 //// 上边内容是在网上看得资料,但是看了一下Realtek的资料,感觉自己没找到信息。 PHY_ADDRESS 意思是RX0-RX3和CSR这几个引脚不悬空就为0吗? PHY_SR 17 /*!< Tranceiver Status Register */ 这个寄存器没有找到呢? #define PHY_Speed_Status ((u16)0x3000) /*!< Configured information of Speed: 10Mbps */ #define PHY_Duplex_Status ((u16)0xA000) /*!< Configured information of Duplex: Full-duplex */ 这两个寄存器是配置寄存器吗? 求指导。。。 |
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //库文件,内初始化GPIO用到的结构体
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
/* ETHERNET pins configuration */
/* AF Output Push Pull:
- ETH_MII_MDIO : PA2
- ETH_MII_MDC : PC1
- ETH_MII_TXD2: PC2
- ETH_MII_TX_EN : PB11
- ETH_MII_TXD0 : PB12
- ETH_MII_TXD1: PB13
- ETH_MII_PPS_OUT: PB5 //PB5?aSPI1_MOSI
- ETH_MII_TXD3: PB8 */
/* Configure PA2 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PC1, PC2 and PC3 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure PB5, PB8, PB11, PB12 and PB13 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 | //PB5aSPI1_MOSI
GPIO_Pin_12 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/**************************************************************/
/* For Remapped Ethernet pins */
/*************************************************************/
/* Input (Reset Value):
- ETH_MII_CRS CRS: PA0
- ETH_MII_RX_CLK / ETH_RMII_REF_CLK: PA1
//- ETH_MII_COL: PA3
- ETH_MII_RX_DV / ETH_RMII_CRS_DV: PD8 //RX_DV A7DT?? 2?ê???ó3é?
- ETH_MII_TX_CLK: PC3
- ETH_MII_RXD0 / ETH_RMII_RXD0: PD9 //RXD0C4
- ETH_MII_RXD1 / ETH_RMII_RXD1: PD10 //RXD1C5
- ETH_MII_RXD2: PD11 //RXD2B0
- ETH_MII_RXD3: PD12 //RXD3B1
- ETH_MII_RX_ER: PB10 */
/* ETHERNET pins remapp in STM3210C-EVAL board: RX_DV and RxD[3:0] */
GPIO_PinRemapConfig(GPIO_Remap_ETH, ENABLE);
/* Configure PA0, PA1 £?PA3 and PA7 as input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_7;//GPIO_Pin_3
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PB0, PB1 and PB10 as input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure PC3, PC4 and PC5 as input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* ADC Channel14 config --------------------------------------------------------*/
/* Relative to STM3210D-EVAL Board */
/* Configure PC.04 (ADC Channel14) as analog input -------------------------*/
/*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);*/
/* MCO pin configuration------------------------------------------------- */
/* Configure MCO (PA8) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*-------------------------------------------------*/
/*函数名:以太网配置 */
/*参 数:无 */
/*返回值:无 */
/*-------------------------------------------------*/
void Ethernet_Configuration(void)
{
ETH_InitTypeDef ETH_InitStructure; //库文件,初始化以太网用到的结构体
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx | RCC_AHBPeriph_ETH_MAC_Rx, ENABLE);
//GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_RMII);//该函数设置以太网接口为RMII
GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_MII);//该函数设置以太网接口为MII
//程序思路利用PLL3时钟为MCO提供RMII需要的50M时钟
//系统初始化STM32主时钟为72M的时候,PLL3被设置为了外部25M晶振5分频 25/5=5M
RCC_PLL3Config(RCC_PLL3Mul_10);//PLL3倍频10倍 5*10=50M
RCC_PLL3Cmd(ENABLE);//使能PLL3时钟
while (RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET)//等待PLL3使能成功
{}
RCC_MCOConfig(RCC_MCO_PLL3CLK);//选择MCO的时钟源为PLL3
ETH_DeInit(); //复位以太网外设寄存器到默认值,先使能,在禁止,已恢复默认值
ETH_SoftwareReset();//软件复位,通过设置ETH->DMABMR寄存器的位0实现
while (ETH_GetSoftwareResetStatus() == SET);//等待软复位成功
ETH_StructInit(Ð_InitStructure);//初始化结构体ETH_InitStructure各个成员为默认值
//ETH_InitStructure结构体内成员较多,填充外默认值后,修改一些关键成员,以适应当前的需要
ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable; //开启网络自适应功能
ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable; //关闭反馈
ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable; //关闭重传功能
ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable; //关闭自动去除PDA/CRC功能
ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable; //关闭接收所有的帧
ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;//允许接收所有广播帧
ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable; //关闭混合模式的地址过滤
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;//对于组播地址使用完美地址过滤
ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect; //对单播地址使用完美地址过滤
#if !CHECKSUM_GEN_ICMP //判断是否开启硬件校验,关闭软件校验
ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable; //开启ipv4和TCP/UDP/ICMP的帧校验和卸载
#endif
//当我们使用帧校验和卸载功能的时候,一定要使能存储转发模式,存储转发模式中要保证整个帧存储在FIFO中,
//这样MAC能插入/识别出帧校验值,当真校验正确的时候DMA就可以处理帧,否则就丢弃掉该帧
ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable; //开启丢弃TCP/IP错误帧
ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable; //开启接收数据的存储转发模式
ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable; //开启发送数据的存储转发模式
ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable; //禁止转发错误帧
ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable; //不转发过小的好帧
ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable; //打开处理第二帧功能
ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable; //开启DMA传输的地址对齐功能
ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable; //开启固定突发功能
ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat; //DMA发送的最大突发长度为32个节拍
ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat; //DMA接收的最大突发长度为32个节拍
ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1;
ETH_Init(Ð_InitStructure,PHY_ADDRESS); //配置ETH
ETH_DMAITConfig(ETH_DMA_IT_NIS|ETH_DMA_IT_R,ENABLE); //使能以太网接收中断
}
评分
查看全部评分