This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/DP83848J: STM32F107RC with DP83848J can't establish ethernet link correctly

Part Number: DP83848J

Tool/software: TI C/C++ Compiler

In my project i use stm32f107rc with  DP83848J to establish ethernet communication,it's happend an problem.I config the DP83848J in RMII mode,and i can read the link status is ok from DP83848J register 0x10,but the j45 link led does't light and computer can't find the connection either,I check the speed on both  DP83848J and stm32f107rc side,It's matched,so i don't what the problem is

  • Hi user,

    Can you share a schematic of your design please? Can you also provide all registers of DP83848J when connected to the computer?

    Best Regards,
  • Hi rob;

       thanks for your reply,the attachment is the schematic and sourcecode,the register i used register BCR (0x00),register BSR(0x01),register PHYSTS(0x10), RBR(0x17) ,all register i used is in function " ETH_Init"  in stm32_eth.c file, I check the link Status in BSR it's feedback "1",so i think the chip must work normally.i use RMII mode.

    MT STM32F107 Control Board.pdf

    uint32_t ETH_Init(ETH_InitTypeDef* ETH_InitStruct, uint16_t PHYAddress)
    {
      uint32_t RegValue = 0;
      __IO uint32_t i = 0;
      RCC_ClocksTypeDef  rcc_clocks;
      uint32_t hclk = 60000000;
      __IO uint32_t timeout = 0;
    	
      /* Check the parameters */
      /* MAC --------------------------*/ 
      assert_param(IS_ETH_AUTONEGOTIATION(ETH_InitStruct->ETH_AutoNegotiation));
      assert_param(IS_ETH_WATCHDOG(ETH_InitStruct->ETH_Watchdog));
      assert_param(IS_ETH_JABBER(ETH_InitStruct->ETH_Jabber));
      assert_param(IS_ETH_INTER_FRAME_GAP(ETH_InitStruct->ETH_InterFrameGap));
      assert_param(IS_ETH_CARRIER_SENSE(ETH_InitStruct->ETH_CarrierSense));
      assert_param(IS_ETH_SPEED(ETH_InitStruct->ETH_Speed));
      assert_param(IS_ETH_RECEIVE_OWN(ETH_InitStruct->ETH_ReceiveOwn));
      assert_param(IS_ETH_LOOPBACK_MODE(ETH_InitStruct->ETH_LoopbackMode));
      assert_param(IS_ETH_DUPLEX_MODE(ETH_InitStruct->ETH_Mode));
      assert_param(IS_ETH_CHECKSUM_OFFLOAD(ETH_InitStruct->ETH_ChecksumOffload));
      assert_param(IS_ETH_RETRY_TRANSMISSION(ETH_InitStruct->ETH_RetryTransmission));
      assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(ETH_InitStruct->ETH_AutomaticPadCRCStrip));
      assert_param(IS_ETH_BACKOFF_LIMIT(ETH_InitStruct->ETH_BackOffLimit));
      assert_param(IS_ETH_DEFERRAL_CHECK(ETH_InitStruct->ETH_DeferralCheck));
      assert_param(IS_ETH_RECEIVE_ALL(ETH_InitStruct->ETH_ReceiveAll));
      assert_param(IS_ETH_SOURCE_ADDR_FILTER(ETH_InitStruct->ETH_SourceAddrFilter));
      assert_param(IS_ETH_CONTROL_FRAMES(ETH_InitStruct->ETH_PassControlFrames));
      assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(ETH_InitStruct->ETH_BroadcastFramesReception));
      assert_param(IS_ETH_DESTINATION_ADDR_FILTER(ETH_InitStruct->ETH_DestinationAddrFilter));
      assert_param(IS_ETH_PROMISCUOUS_MODE(ETH_InitStruct->ETH_PromiscuousMode));
      assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(ETH_InitStruct->ETH_MulticastFramesFilter));  
      assert_param(IS_ETH_UNICAST_FRAMES_FILTER(ETH_InitStruct->ETH_UnicastFramesFilter));
      assert_param(IS_ETH_PAUSE_TIME(ETH_InitStruct->ETH_PauseTime));
      assert_param(IS_ETH_ZEROQUANTA_PAUSE(ETH_InitStruct->ETH_ZeroQuantaPause));
      assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(ETH_InitStruct->ETH_PauseLowThreshold));
      assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(ETH_InitStruct->ETH_UnicastPauseFrameDetect));
      assert_param(IS_ETH_RECEIVE_FLOWCONTROL(ETH_InitStruct->ETH_ReceiveFlowControl));
      assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(ETH_InitStruct->ETH_TransmitFlowControl));
      assert_param(IS_ETH_VLAN_TAG_COMPARISON(ETH_InitStruct->ETH_VLANTagComparison));
      assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(ETH_InitStruct->ETH_VLANTagIdentifier));
      /* DMA --------------------------*/
      assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame));
      assert_param(IS_ETH_RECEIVE_STORE_FORWARD(ETH_InitStruct->ETH_ReceiveStoreForward));
      assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(ETH_InitStruct->ETH_FlushReceivedFrame));
      assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(ETH_InitStruct->ETH_TransmitStoreForward));
      assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(ETH_InitStruct->ETH_TransmitThresholdControl));
      assert_param(IS_ETH_FORWARD_ERROR_FRAMES(ETH_InitStruct->ETH_ForwardErrorFrames));
      assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(ETH_InitStruct->ETH_ForwardUndersizedGoodFrames));
      assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(ETH_InitStruct->ETH_ReceiveThresholdControl));
      assert_param(IS_ETH_SECOND_FRAME_OPERATE(ETH_InitStruct->ETH_SecondFrameOperate));
      assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(ETH_InitStruct->ETH_AddressAlignedBeats));
      assert_param(IS_ETH_FIXED_BURST(ETH_InitStruct->ETH_FixedBurst));
      assert_param(IS_ETH_RXDMA_BURST_LENGTH(ETH_InitStruct->ETH_RxDMABurstLength));
      assert_param(IS_ETH_TXDMA_BURST_LENGTH(ETH_InitStruct->ETH_TxDMABurstLength)); 
      assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(ETH_InitStruct->ETH_DescriptorSkipLength));  
      assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(ETH_InitStruct->ETH_DMAArbitration));       
      /*-------------------------------- MAC Config ------------------------------*/   
      /*---------------------- ETHERNET MACMIIAR Configuration -------------------*/
      /* Get the ETHERNET MACMIIAR value */
    	tmpreg = ETH->MACMIIAR;
    	/* Clear CSR Clock Range CR[2:0] bits */
    	tmpreg &= MACMIIAR_CR_MASK;
    	/* Get hclk frequency value */
    	RCC_GetClocksFreq(&rcc_clocks);  
    	hclk = rcc_clocks.HCLK_Frequency; /*0x044AA200*/
      
    	/* Set CR bits depending on hclk value */
    	if((hclk >= 20000000)&&(hclk < 35000000))
    	{
    		/* CSR Clock Range between 20-35 MHz */
    		tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div16;
    	}
    	else if((hclk >= 35000000)&&(hclk < 60000000))
    	{
    		/* CSR Clock Range between 35-60 MHz */ 
    		tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div26;    
    	} 
    	else if((hclk >= 60000000)&&(hclk <= 72000000))
    	{
    		/* ((hclk >= 60000000)&&(hclk <= 72000000)) */
    		/* CSR Clock Range between 60-72 MHz */   
    		tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;    
    	}
     
    	/*配置MDC的时钟频率,与DP83848进行通讯*/
    	/* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
    	ETH->MACMIIAR = (uint32_t)tmpreg; 
      
    //	for(;temp<=32;temp++)
    //	{
    //		status=ETH_ReadPHYRegister(temp, 0X17);
    //	}
    	
    	status=ETH_ReadPHYRegister(PHYAddress, PHY_BCR);
      
    	/*-------------------- PHY initialization and configuration ----------------*/
    	/* Put the PHY in reset mode */
    	if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_Reset)))
    	{
    		/* Return ERROR in case of write timeout */
    		return ETH_ERROR;
    	}
      
    	/* Enable Auto-Negotiation */
    	if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_AutoNegotiation)))
        {
          /* Return ERROR in case of write timeout */
          return ETH_ERROR;
        }
      
    	status=ETH_ReadPHYRegister(PHYAddress, PHY_BCR);
      
    	/* Delay to assure PHY reset */
    	_eth_delay_(PHY_ResetDelay);
      
    	/*判断是否配置为自动*/
    	if(ETH_InitStruct->ETH_AutoNegotiation != ETH_AutoNegotiation_Disable)
    	{  
    		/* We wait for linked satus... */
    		do
    		{
    			timeout++;
    		} while (!(ETH_ReadPHYRegister(PHYAddress, PHY_BSR) & PHY_Linked_Status) && (timeout < PHY_READ_TO));
    		/* Return ERROR in case of timeout */
       
    		if(timeout == PHY_READ_TO)
    		{
    			return ETH_ERROR;
    		}
    		/* Reset Timeout counter */
    		timeout = 0;
        
    		/* Enable Auto-Negotiation */
    		if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_AutoNegotiation)))
    		{
    			/* Return ERROR in case of write timeout */
    			return ETH_ERROR;
    		}
        
    		/* Wait until the autonegotiation will be completed */
    		do
    		{
    			timeout++;
    		} while (!(ETH_ReadPHYRegister(PHYAddress, PHY_BSR) & PHY_AutoNego_Complete) && (timeout < (uint32_t)PHY_READ_TO));  
        
    		/* Return ERROR in case of timeout */
    		if(timeout == PHY_READ_TO)
    		{
    			return ETH_ERROR;
    		}
    		/* Reset Timeout counter */
    		timeout = 0;
        
    		/* Read the result of the autonegotiation */
    		RegValue = ETH_ReadPHYRegister(PHYAddress, PHY_SR);
      
    		/* Configure the MAC with the Duplex Mode fixed by the autonegotiation process */
    		if((RegValue & PHY_Duplex_Status) != (uint32_t)RESET)
    		{
    			/* Set Ethernet duplex mode to FullDuplex following the autonegotiation */
    			ETH_InitStruct->ETH_Mode = ETH_Mode_FullDuplex;    
    		}
    		else
    		{
    			/* Set Ethernet duplex mode to HalfDuplex following the autonegotiation */
    			ETH_InitStruct->ETH_Mode = ETH_Mode_HalfDuplex;           
    		}
       
    		/* Configure the MAC with the speed fixed by the autonegotiation process */
    		if(RegValue & PHY_Speed_Status)
    		{  
    			/* Set Ethernet speed to 10M following the autonegotiation */    
    			ETH_InitStruct->ETH_Speed = ETH_Speed_10M; 
    		}
    		else
    		{   
    			/* Set Ethernet speed to 100M following the autonegotiation */ 
    			ETH_InitStruct->ETH_Speed = ETH_Speed_100M;      
    		}
    	
    		/*0x17 RMII and Bypass Register*/
    		status=ETH_ReadPHYRegister(PHYAddress, 0x17);
    		/* Enable Auto-Negotiation */
    	  
    		if(!(ETH_WritePHYRegister(PHYAddress, 0x17, status|0X20)))
    		{
    			/* Return ERROR in case of write timeout */
    			return ETH_ERROR;
    		}
    		status=ETH_ReadPHYRegister(PHYAddress, 0x17);
    	   
    	   
    		status=ETH_ReadPHYRegister(PHYAddress, 0X18);
    		/* LED Direct Control Register,1 = Drive value of SPDLED bit onto LED_SPEED output,  Drive value of LNKLED bit onto LED_LINK output*/
    		if(!(ETH_WritePHYRegister(PHYAddress, 0X18, status|0x30)))
    		{
    			/* Return ERROR in case of write timeout */
    			return ETH_ERROR;
    		}
    		status=ETH_ReadPHYRegister(PHYAddress, 0X18);
    
    	    status=ETH_ReadPHYRegister(PHYAddress, 0x19);
    		/*LED配置成MODE1*/
    		if(!(ETH_WritePHYRegister(PHYAddress, 0x19, status|0x20)))
    		{
    		  /* Return ERROR in case of write timeout */
    		  return ETH_ERROR;
    		}
    		
    		status=ETH_ReadPHYRegister(PHYAddress, 0x19);
      }
    	else
    	{
    		if(!ETH_WritePHYRegister(PHYAddress, PHY_BCR, ((uint16_t)(ETH_InitStruct->ETH_Mode >> 3) |
                                                       (uint16_t)(ETH_InitStruct->ETH_Speed >> 1))))
    		{
    			/* Return ERROR in case of write timeout */
    			return ETH_ERROR;
    		}
    		
    		/* Delay to assure PHY configuration */
    		_eth_delay_(PHY_ConfigDelay);
    	}
      
      
      /*------------------------ ETHERNET MACCR Configuration --------------------*/
      /* Get the ETHERNET MACCR value */  
      tmpreg = ETH->MACCR;
      /* Clear WD, PCE, PS, TE and RE bits */
      tmpreg &= MACCR_CLEAR_MASK;
      /* Set the WD bit according to ETH_Watchdog value */
      /* Set the JD: bit according to ETH_Jabber value */
      /* Set the IFG bit according to ETH_InterFrameGap value */ 
      /* Set the DCRS bit according to ETH_CarrierSense value */  
      /* Set the FES bit according to ETH_Speed value */ 
      /* Set the DO bit according to ETH_ReceiveOwn value */ 
      /* Set the LM bit according to ETH_LoopbackMode value */ 
      /* Set the DM bit according to ETH_Mode value */ 
      /* Set the IPC bit according to ETH_ChecksumOffload value */                   
      /* Set the DR bit according to ETH_RetryTransmission value */ 
      /* Set the ACS bit according to ETH_AutomaticPadCRCStrip value */ 
      /* Set the BL bit according to ETH_BackOffLimit value */ 
      /* Set the DC bit according to ETH_DeferralCheck value */                          
      tmpreg |= (uint32_t)(ETH_InitStruct->ETH_Watchdog | 
                      ETH_InitStruct->ETH_Jabber | 
                      ETH_InitStruct->ETH_InterFrameGap |
                      ETH_InitStruct->ETH_CarrierSense |
                      ETH_InitStruct->ETH_Speed | 
                      ETH_InitStruct->ETH_ReceiveOwn |
                      ETH_InitStruct->ETH_LoopbackMode |
                      ETH_InitStruct->ETH_Mode | 
                      ETH_InitStruct->ETH_ChecksumOffload |    
                      ETH_InitStruct->ETH_RetryTransmission | 
                      ETH_InitStruct->ETH_AutomaticPadCRCStrip | 
                      ETH_InitStruct->ETH_BackOffLimit | 
                      ETH_InitStruct->ETH_DeferralCheck);
      /* Write to ETHERNET MACCR */
      ETH->MACCR = (uint32_t)tmpreg;
      
      /*----------------------- ETHERNET MACFFR Configuration --------------------*/ 
      /* Set the RA bit according to ETH_ReceiveAll value */
      /* Set the SAF and SAIF bits according to ETH_SourceAddrFilter value */
      /* Set the PCF bit according to ETH_PassControlFrames value */
      /* Set the DBF bit according to ETH_BroadcastFramesReception value */
      /* Set the DAIF bit according to ETH_DestinationAddrFilter value */
      /* Set the PR bit according to ETH_PromiscuousMode value */
      /* Set the PM, HMC and HPF bits according to ETH_MulticastFramesFilter value */
      /* Set the HUC and HPF bits according to ETH_UnicastFramesFilter value */
      /* Write to ETHERNET MACFFR */  
      ETH->MACFFR = (uint32_t)(ETH_InitStruct->ETH_ReceiveAll | 
                              ETH_InitStruct->ETH_SourceAddrFilter |
                              ETH_InitStruct->ETH_PassControlFrames |
                              ETH_InitStruct->ETH_BroadcastFramesReception | 
                              ETH_InitStruct->ETH_DestinationAddrFilter |
                              ETH_InitStruct->ETH_PromiscuousMode |
                              ETH_InitStruct->ETH_MulticastFramesFilter |
                              ETH_InitStruct->ETH_UnicastFramesFilter); 
      /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
      /* Write to ETHERNET MACHTHR */
      ETH->MACHTHR = (uint32_t)ETH_InitStruct->ETH_HashTableHigh;
      /* Write to ETHERNET MACHTLR */
      ETH->MACHTLR = (uint32_t)ETH_InitStruct->ETH_HashTableLow;
      /*----------------------- ETHERNET MACFCR Configuration --------------------*/
      /* Get the ETHERNET MACFCR value */  
      tmpreg = ETH->MACFCR;
      /* Clear xx bits */
      tmpreg &= MACFCR_CLEAR_MASK;
      
      /* Set the PT bit according to ETH_PauseTime value */
      /* Set the DZPQ bit according to ETH_ZeroQuantaPause value */
      /* Set the PLT bit according to ETH_PauseLowThreshold value */
      /* Set the UP bit according to ETH_UnicastPauseFrameDetect value */
      /* Set the RFE bit according to ETH_ReceiveFlowControl value */
      /* Set the TFE bit according to ETH_TransmitFlowControl value */  
      tmpreg |= (uint32_t)((ETH_InitStruct->ETH_PauseTime << 16) | 
                       ETH_InitStruct->ETH_ZeroQuantaPause |
                       ETH_InitStruct->ETH_PauseLowThreshold |
                       ETH_InitStruct->ETH_UnicastPauseFrameDetect | 
                       ETH_InitStruct->ETH_ReceiveFlowControl |
                       ETH_InitStruct->ETH_TransmitFlowControl); 
      /* Write to ETHERNET MACFCR */
      ETH->MACFCR = (uint32_t)tmpreg;
      /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
      /* Set the ETV bit according to ETH_VLANTagComparison value */
      /* Set the VL bit according to ETH_VLANTagIdentifier value */  
      ETH->MACVLANTR = (uint32_t)(ETH_InitStruct->ETH_VLANTagComparison | 
                                 ETH_InitStruct->ETH_VLANTagIdentifier); 
           
      /*-------------------------------- DMA Config ------------------------------*/
      /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
      /* Get the ETHERNET DMAOMR value */  
      tmpreg = ETH->DMAOMR;
      /* Clear xx bits */
      tmpreg &= DMAOMR_CLEAR_MASK;
      
      /* Set the DT bit according to ETH_DropTCPIPChecksumErrorFrame value */
      /* Set the RSF bit according to ETH_ReceiveStoreForward value */
      /* Set the DFF bit according to ETH_FlushReceivedFrame value */
      /* Set the TSF bit according to ETH_TransmitStoreForward value */
      /* Set the TTC bit according to ETH_TransmitThresholdControl value */
      /* Set the FEF bit according to ETH_ForwardErrorFrames value */
      /* Set the FUF bit according to ETH_ForwardUndersizedGoodFrames value */
      /* Set the RTC bit according to ETH_ReceiveThresholdControl value */
      /* Set the OSF bit according to ETH_SecondFrameOperate value */
      tmpreg |= (uint32_t)(ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame | 
                      ETH_InitStruct->ETH_ReceiveStoreForward |
                      ETH_InitStruct->ETH_FlushReceivedFrame |
                      ETH_InitStruct->ETH_TransmitStoreForward | 
                      ETH_InitStruct->ETH_TransmitThresholdControl |
                      ETH_InitStruct->ETH_ForwardErrorFrames |
                      ETH_InitStruct->ETH_ForwardUndersizedGoodFrames |
                      ETH_InitStruct->ETH_ReceiveThresholdControl |                                   
                      ETH_InitStruct->ETH_SecondFrameOperate); 
      /* Write to ETHERNET DMAOMR */
      ETH->DMAOMR = (uint32_t)tmpreg;
      
      /*----------------------- ETHERNET DMABMR Configuration --------------------*/ 
      /* Set the AAL bit according to ETH_AddressAlignedBeats value */
      /* Set the FB bit according to ETH_FixedBurst value */
      /* Set the RPBL and 4*PBL bits according to ETH_RxDMABurstLength value */
      /* Set the PBL and 4*PBL bits according to ETH_TxDMABurstLength value */
      /* Set the DSL bit according to ETH_DesciptorSkipLength value */
      /* Set the PR and DA bits according to ETH_DMAArbitration value */         
      ETH->DMABMR = (uint32_t)(ETH_InitStruct->ETH_AddressAlignedBeats | 
                              ETH_InitStruct->ETH_FixedBurst |
                              ETH_InitStruct->ETH_RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
                              ETH_InitStruct->ETH_TxDMABurstLength | 
                             (ETH_InitStruct->ETH_DescriptorSkipLength << 2) |
                              ETH_InitStruct->ETH_DMAArbitration |
                              ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */  
    						  
    	
    						  
    						  
      /* Return Ethernet configuration success */
      return ETH_SUCCESS;
    }
    

  •  rob:

         thanks for your reply,here is my schemastic and source code,thanks.

    uint32_t ETH_Init(ETH_InitTypeDef* ETH_InitStruct, uint16_t PHYAddress)

    {
    uint32_t RegValue = 0;
    __IO uint32_t i = 0;
    RCC_ClocksTypeDef rcc_clocks;
    uint32_t hclk = 60000000;
    __IO uint32_t timeout = 0;

    /* Check the parameters */
    /* MAC --------------------------*/
    assert_param(IS_ETH_AUTONEGOTIATION(ETH_InitStruct->ETH_AutoNegotiation));
    assert_param(IS_ETH_WATCHDOG(ETH_InitStruct->ETH_Watchdog));
    assert_param(IS_ETH_JABBER(ETH_InitStruct->ETH_Jabber));
    assert_param(IS_ETH_INTER_FRAME_GAP(ETH_InitStruct->ETH_InterFrameGap));
    assert_param(IS_ETH_CARRIER_SENSE(ETH_InitStruct->ETH_CarrierSense));
    assert_param(IS_ETH_SPEED(ETH_InitStruct->ETH_Speed));
    assert_param(IS_ETH_RECEIVE_OWN(ETH_InitStruct->ETH_ReceiveOwn));
    assert_param(IS_ETH_LOOPBACK_MODE(ETH_InitStruct->ETH_LoopbackMode));
    assert_param(IS_ETH_DUPLEX_MODE(ETH_InitStruct->ETH_Mode));
    assert_param(IS_ETH_CHECKSUM_OFFLOAD(ETH_InitStruct->ETH_ChecksumOffload));
    assert_param(IS_ETH_RETRY_TRANSMISSION(ETH_InitStruct->ETH_RetryTransmission));
    assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(ETH_InitStruct->ETH_AutomaticPadCRCStrip));
    assert_param(IS_ETH_BACKOFF_LIMIT(ETH_InitStruct->ETH_BackOffLimit));
    assert_param(IS_ETH_DEFERRAL_CHECK(ETH_InitStruct->ETH_DeferralCheck));
    assert_param(IS_ETH_RECEIVE_ALL(ETH_InitStruct->ETH_ReceiveAll));
    assert_param(IS_ETH_SOURCE_ADDR_FILTER(ETH_InitStruct->ETH_SourceAddrFilter));
    assert_param(IS_ETH_CONTROL_FRAMES(ETH_InitStruct->ETH_PassControlFrames));
    assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(ETH_InitStruct->ETH_BroadcastFramesReception));
    assert_param(IS_ETH_DESTINATION_ADDR_FILTER(ETH_InitStruct->ETH_DestinationAddrFilter));
    assert_param(IS_ETH_PROMISCUOUS_MODE(ETH_InitStruct->ETH_PromiscuousMode));
    assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(ETH_InitStruct->ETH_MulticastFramesFilter));
    assert_param(IS_ETH_UNICAST_FRAMES_FILTER(ETH_InitStruct->ETH_UnicastFramesFilter));
    assert_param(IS_ETH_PAUSE_TIME(ETH_InitStruct->ETH_PauseTime));
    assert_param(IS_ETH_ZEROQUANTA_PAUSE(ETH_InitStruct->ETH_ZeroQuantaPause));
    assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(ETH_InitStruct->ETH_PauseLowThreshold));
    assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(ETH_InitStruct->ETH_UnicastPauseFrameDetect));
    assert_param(IS_ETH_RECEIVE_FLOWCONTROL(ETH_InitStruct->ETH_ReceiveFlowControl));
    assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(ETH_InitStruct->ETH_TransmitFlowControl));
    assert_param(IS_ETH_VLAN_TAG_COMPARISON(ETH_InitStruct->ETH_VLANTagComparison));
    assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(ETH_InitStruct->ETH_VLANTagIdentifier));
    /* DMA --------------------------*/
    assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame));
    assert_param(IS_ETH_RECEIVE_STORE_FORWARD(ETH_InitStruct->ETH_ReceiveStoreForward));
    assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(ETH_InitStruct->ETH_FlushReceivedFrame));
    assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(ETH_InitStruct->ETH_TransmitStoreForward));
    assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(ETH_InitStruct->ETH_TransmitThresholdControl));
    assert_param(IS_ETH_FORWARD_ERROR_FRAMES(ETH_InitStruct->ETH_ForwardErrorFrames));
    assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(ETH_InitStruct->ETH_ForwardUndersizedGoodFrames));
    assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(ETH_InitStruct->ETH_ReceiveThresholdControl));
    assert_param(IS_ETH_SECOND_FRAME_OPERATE(ETH_InitStruct->ETH_SecondFrameOperate));
    assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(ETH_InitStruct->ETH_AddressAlignedBeats));
    assert_param(IS_ETH_FIXED_BURST(ETH_InitStruct->ETH_FixedBurst));
    assert_param(IS_ETH_RXDMA_BURST_LENGTH(ETH_InitStruct->ETH_RxDMABurstLength));
    assert_param(IS_ETH_TXDMA_BURST_LENGTH(ETH_InitStruct->ETH_TxDMABurstLength));
    assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(ETH_InitStruct->ETH_DescriptorSkipLength));
    assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(ETH_InitStruct->ETH_DMAArbitration));
    /*-------------------------------- MAC Config ------------------------------*/
    /*---------------------- ETHERNET MACMIIAR Configuration -------------------*/
    /* Get the ETHERNET MACMIIAR value */
    tmpreg = ETH->MACMIIAR;
    /* Clear CSR Clock Range CR[2:0] bits */
    tmpreg &= MACMIIAR_CR_MASK;
    /* Get hclk frequency value */
    RCC_GetClocksFreq(&rcc_clocks);
    hclk = rcc_clocks.HCLK_Frequency; /*0x044AA200*/

    /* Set CR bits depending on hclk value */
    if((hclk >= 20000000)&&(hclk < 35000000))
    {
    /* CSR Clock Range between 20-35 MHz */
    tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div16;
    }
    else if((hclk >= 35000000)&&(hclk < 60000000))
    {
    /* CSR Clock Range between 35-60 MHz */
    tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div26;
    }
    else if((hclk >= 60000000)&&(hclk <= 72000000))
    {
    /* ((hclk >= 60000000)&&(hclk <= 72000000)) */
    /* CSR Clock Range between 60-72 MHz */
    tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;
    }

    /*配置MDC的时钟频率,与DP83848进行通讯*/
    /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
    ETH->MACMIIAR = (uint32_t)tmpreg;

    // for(;temp<=32;temp++)
    // {
    // status=ETH_ReadPHYRegister(temp, 0X17);
    // }

    status=ETH_ReadPHYRegister(PHYAddress, PHY_BCR);

    /*-------------------- PHY initialization and configuration ----------------*/
    /* Put the PHY in reset mode */
    if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_Reset)))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }

    /* Enable Auto-Negotiation */
    if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_AutoNegotiation)))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }

    status=ETH_ReadPHYRegister(PHYAddress, PHY_BCR);

    /* Delay to assure PHY reset */
    _eth_delay_(PHY_ResetDelay);

    /*判断是否配置为自动*/
    if(ETH_InitStruct->ETH_AutoNegotiation != ETH_AutoNegotiation_Disable)
    {
    /* We wait for linked satus... */
    do
    {
    timeout++;
    } while (!(ETH_ReadPHYRegister(PHYAddress, PHY_BSR) & PHY_Linked_Status) && (timeout < PHY_READ_TO));
    /* Return ERROR in case of timeout */

    if(timeout == PHY_READ_TO)
    {
    return ETH_ERROR;
    }
    /* Reset Timeout counter */
    timeout = 0;

    /* Enable Auto-Negotiation */
    if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_AutoNegotiation)))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }

    /* Wait until the autonegotiation will be completed */
    do
    {
    timeout++;
    } while (!(ETH_ReadPHYRegister(PHYAddress, PHY_BSR) & PHY_AutoNego_Complete) && (timeout < (uint32_t)PHY_READ_TO));

    /* Return ERROR in case of timeout */
    if(timeout == PHY_READ_TO)
    {
    return ETH_ERROR;
    }
    /* Reset Timeout counter */
    timeout = 0;

    /* Read the result of the autonegotiation */
    RegValue = ETH_ReadPHYRegister(PHYAddress, PHY_SR);

    /* Configure the MAC with the Duplex Mode fixed by the autonegotiation process */
    if((RegValue & PHY_Duplex_Status) != (uint32_t)RESET)
    {
    /* Set Ethernet duplex mode to FullDuplex following the autonegotiation */
    ETH_InitStruct->ETH_Mode = ETH_Mode_FullDuplex;
    }
    else
    {
    /* Set Ethernet duplex mode to HalfDuplex following the autonegotiation */
    ETH_InitStruct->ETH_Mode = ETH_Mode_HalfDuplex;
    }

    /* Configure the MAC with the speed fixed by the autonegotiation process */
    if(RegValue & PHY_Speed_Status)
    {
    /* Set Ethernet speed to 10M following the autonegotiation */
    ETH_InitStruct->ETH_Speed = ETH_Speed_10M;
    }
    else
    {
    /* Set Ethernet speed to 100M following the autonegotiation */
    ETH_InitStruct->ETH_Speed = ETH_Speed_100M;
    }

    /*0x17 RMII and Bypass Register*/
    status=ETH_ReadPHYRegister(PHYAddress, 0x17);
    /* Enable Auto-Negotiation */

    if(!(ETH_WritePHYRegister(PHYAddress, 0x17, status|0X20)))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }
    status=ETH_ReadPHYRegister(PHYAddress, 0x17);


    status=ETH_ReadPHYRegister(PHYAddress, 0X18);
    /* LED Direct Control Register,1 = Drive value of SPDLED bit onto LED_SPEED output, Drive value of LNKLED bit onto LED_LINK output*/
    if(!(ETH_WritePHYRegister(PHYAddress, 0X18, status|0x30)))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }
    status=ETH_ReadPHYRegister(PHYAddress, 0X18);

    status=ETH_ReadPHYRegister(PHYAddress, 0x19);
    /*LED配置成MODE1*/
    if(!(ETH_WritePHYRegister(PHYAddress, 0x19, status|0x20)))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }

    status=ETH_ReadPHYRegister(PHYAddress, 0x19);
    }
    else
    {
    if(!ETH_WritePHYRegister(PHYAddress, PHY_BCR, ((uint16_t)(ETH_InitStruct->ETH_Mode >> 3) |
    (uint16_t)(ETH_InitStruct->ETH_Speed >> 1))))
    {
    /* Return ERROR in case of write timeout */
    return ETH_ERROR;
    }

    /* Delay to assure PHY configuration */
    _eth_delay_(PHY_ConfigDelay);
    }


    /*------------------------ ETHERNET MACCR Configuration --------------------*/
    /* Get the ETHERNET MACCR value */
    tmpreg = ETH->MACCR;
    /* Clear WD, PCE, PS, TE and RE bits */
    tmpreg &= MACCR_CLEAR_MASK;
    /* Set the WD bit according to ETH_Watchdog value */
    /* Set the JD: bit according to ETH_Jabber value */
    /* Set the IFG bit according to ETH_InterFrameGap value */
    /* Set the DCRS bit according to ETH_CarrierSense value */
    /* Set the FES bit according to ETH_Speed value */
    /* Set the DO bit according to ETH_ReceiveOwn value */
    /* Set the LM bit according to ETH_LoopbackMode value */
    /* Set the DM bit according to ETH_Mode value */
    /* Set the IPC bit according to ETH_ChecksumOffload value */
    /* Set the DR bit according to ETH_RetryTransmission value */
    /* Set the ACS bit according to ETH_AutomaticPadCRCStrip value */
    /* Set the BL bit according to ETH_BackOffLimit value */
    /* Set the DC bit according to ETH_DeferralCheck value */
    tmpreg |= (uint32_t)(ETH_InitStruct->ETH_Watchdog |
    ETH_InitStruct->ETH_Jabber |
    ETH_InitStruct->ETH_InterFrameGap |
    ETH_InitStruct->ETH_CarrierSense |
    ETH_InitStruct->ETH_Speed |
    ETH_InitStruct->ETH_ReceiveOwn |
    ETH_InitStruct->ETH_LoopbackMode |
    ETH_InitStruct->ETH_Mode |
    ETH_InitStruct->ETH_ChecksumOffload |
    ETH_InitStruct->ETH_RetryTransmission |
    ETH_InitStruct->ETH_AutomaticPadCRCStrip |
    ETH_InitStruct->ETH_BackOffLimit |
    ETH_InitStruct->ETH_DeferralCheck);
    /* Write to ETHERNET MACCR */
    ETH->MACCR = (uint32_t)tmpreg;

    /*----------------------- ETHERNET MACFFR Configuration --------------------*/
    /* Set the RA bit according to ETH_ReceiveAll value */
    /* Set the SAF and SAIF bits according to ETH_SourceAddrFilter value */
    /* Set the PCF bit according to ETH_PassControlFrames value */
    /* Set the DBF bit according to ETH_BroadcastFramesReception value */
    /* Set the DAIF bit according to ETH_DestinationAddrFilter value */
    /* Set the PR bit according to ETH_PromiscuousMode value */
    /* Set the PM, HMC and HPF bits according to ETH_MulticastFramesFilter value */
    /* Set the HUC and HPF bits according to ETH_UnicastFramesFilter value */
    /* Write to ETHERNET MACFFR */
    ETH->MACFFR = (uint32_t)(ETH_InitStruct->ETH_ReceiveAll |
    ETH_InitStruct->ETH_SourceAddrFilter |
    ETH_InitStruct->ETH_PassControlFrames |
    ETH_InitStruct->ETH_BroadcastFramesReception |
    ETH_InitStruct->ETH_DestinationAddrFilter |
    ETH_InitStruct->ETH_PromiscuousMode |
    ETH_InitStruct->ETH_MulticastFramesFilter |
    ETH_InitStruct->ETH_UnicastFramesFilter);
    /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
    /* Write to ETHERNET MACHTHR */
    ETH->MACHTHR = (uint32_t)ETH_InitStruct->ETH_HashTableHigh;
    /* Write to ETHERNET MACHTLR */
    ETH->MACHTLR = (uint32_t)ETH_InitStruct->ETH_HashTableLow;
    /*----------------------- ETHERNET MACFCR Configuration --------------------*/
    /* Get the ETHERNET MACFCR value */
    tmpreg = ETH->MACFCR;
    /* Clear xx bits */
    tmpreg &= MACFCR_CLEAR_MASK;

    /* Set the PT bit according to ETH_PauseTime value */
    /* Set the DZPQ bit according to ETH_ZeroQuantaPause value */
    /* Set the PLT bit according to ETH_PauseLowThreshold value */
    /* Set the UP bit according to ETH_UnicastPauseFrameDetect value */
    /* Set the RFE bit according to ETH_ReceiveFlowControl value */
    /* Set the TFE bit according to ETH_TransmitFlowControl value */
    tmpreg |= (uint32_t)((ETH_InitStruct->ETH_PauseTime << 16) |
    ETH_InitStruct->ETH_ZeroQuantaPause |
    ETH_InitStruct->ETH_PauseLowThreshold |
    ETH_InitStruct->ETH_UnicastPauseFrameDetect |
    ETH_InitStruct->ETH_ReceiveFlowControl |
    ETH_InitStruct->ETH_TransmitFlowControl);
    /* Write to ETHERNET MACFCR */
    ETH->MACFCR = (uint32_t)tmpreg;
    /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
    /* Set the ETV bit according to ETH_VLANTagComparison value */
    /* Set the VL bit according to ETH_VLANTagIdentifier value */
    ETH->MACVLANTR = (uint32_t)(ETH_InitStruct->ETH_VLANTagComparison |
    ETH_InitStruct->ETH_VLANTagIdentifier);

    /*-------------------------------- DMA Config ------------------------------*/
    /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
    /* Get the ETHERNET DMAOMR value */
    tmpreg = ETH->DMAOMR;
    /* Clear xx bits */
    tmpreg &= DMAOMR_CLEAR_MASK;

    /* Set the DT bit according to ETH_DropTCPIPChecksumErrorFrame value */
    /* Set the RSF bit according to ETH_ReceiveStoreForward value */
    /* Set the DFF bit according to ETH_FlushReceivedFrame value */
    /* Set the TSF bit according to ETH_TransmitStoreForward value */
    /* Set the TTC bit according to ETH_TransmitThresholdControl value */
    /* Set the FEF bit according to ETH_ForwardErrorFrames value */
    /* Set the FUF bit according to ETH_ForwardUndersizedGoodFrames value */
    /* Set the RTC bit according to ETH_ReceiveThresholdControl value */
    /* Set the OSF bit according to ETH_SecondFrameOperate value */
    tmpreg |= (uint32_t)(ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame |
    ETH_InitStruct->ETH_ReceiveStoreForward |
    ETH_InitStruct->ETH_FlushReceivedFrame |
    ETH_InitStruct->ETH_TransmitStoreForward |
    ETH_InitStruct->ETH_TransmitThresholdControl |
    ETH_InitStruct->ETH_ForwardErrorFrames |
    ETH_InitStruct->ETH_ForwardUndersizedGoodFrames |
    ETH_InitStruct->ETH_ReceiveThresholdControl |
    ETH_InitStruct->ETH_SecondFrameOperate);
    /* Write to ETHERNET DMAOMR */
    ETH->DMAOMR = (uint32_t)tmpreg;

    /*----------------------- ETHERNET DMABMR Configuration --------------------*/
    /* Set the AAL bit according to ETH_AddressAlignedBeats value */
    /* Set the FB bit according to ETH_FixedBurst value */
    /* Set the RPBL and 4*PBL bits according to ETH_RxDMABurstLength value */
    /* Set the PBL and 4*PBL bits according to ETH_TxDMABurstLength value */
    /* Set the DSL bit according to ETH_DesciptorSkipLength value */
    /* Set the PR and DA bits according to ETH_DMAArbitration value */
    ETH->DMABMR = (uint32_t)(ETH_InitStruct->ETH_AddressAlignedBeats |
    ETH_InitStruct->ETH_FixedBurst |
    ETH_InitStruct->ETH_RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
    ETH_InitStruct->ETH_TxDMABurstLength |
    (ETH_InitStruct->ETH_DescriptorSkipLength << 2) |
    ETH_InitStruct->ETH_DMAArbitration |
    ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */




    /* Return Ethernet configuration success */
    return ETH_SUCCESS;
    }

  • Hi user,

    you posted your question a second time in a new thread. I am closing this thread. We will continue discussion in new thread.

    Best Regards,