娇小w搡bbbb搡bbb,《第一次の人妻》,中国成熟妇女毛茸茸,边啃奶头边躁狠狠躁视频免费观看

歷史上的今天

今天是:2025年04月22日(星期二)

正在發生

2018年04月22日 | STM32移植LWIP網線熱插入網絡不通的解決辦法

發布者:美麗花朵 來源: eefocus關鍵字:STM32  移植  LWIP網線  熱插入網絡 手機看文章 掃描二維碼
隨時隨地手機看文章

開發背景:

1、主芯片—STM32F207VCT6;

2、TCP/IP協議棧—LWIP,依托ST例程移植;

3、操作系統—無(裸機);

異常現象:

1、網線不插入的情況下先給設備上電,之后再插入網線無法ping通;(如果上電前網線插入,網絡正常);

2、網絡已經正常的情況下,電腦PC端修改傳輸模式(比如從原來的100M全雙工修改為10M全雙工)導致網絡不通;


原因分析:

1、針對第一種異常情況,是由于上電時網線未插入,導致ETH初始化部分未能成功完成,之后即使再插入網線,程序中沒有再次進行初始化的邏輯補充,從而導致網絡異常;

2、針對第二種情況,情況是上電時完成了ETH的初始化并與PC協商成功,此時網絡正常。但當PC端修改傳輸模式后,程序中未能執行再次協商與MAC的初始化工作,導致網絡異常;


解決方法:

首先,要明確上述問題的關鍵點所在,所有的異常均是網線的拔插導致(PC端修改連接傳輸方式時也相當于網線的拔掉重插),因此主程序中必須要有對當前網絡連接與斷開的檢測或者利用PHY芯片的中斷引腳;

其次,無論利用輪詢或是PHY中斷配置引腳,根本的原理都是一樣的,就是感知到網絡的連接與斷開,下面給出采用的查詢方式:


void Eth_Link_ITHandler(struct netif *netif)

{

/* Check whether the link interrupt has occurred or not */

if(((ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_MISR)) & PHY_LINK_STATUS) != 0){/*檢測插拔中斷*/

uint16_t status = ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_BSR);

if(status & (PHY_AutoNego_Complete | PHY_Linked_Status)){/*檢測到網線連接*/

if(EthInitStatus == 0){/*之前未成功初始化過*/

/*Reinit PHY*/

ETH_Reinit();

}

else{/*之前已經成功初始化*/

/*set link up for re link callbalk function*/

netif_set_link_up(netif);

}

}

else{/*網線斷開*/\

/*set link down for re link callbalk function*/

netif_set_link_down(netif);

}

}

}

備注說明:將該檢測函數放入主循環,程序中標注的部分為解決網線熱拔插問題的關鍵點。

1、標注紅色的部分執行的條件是檢測到網線插入且之前ETH部分未成功初始化過(即之前一直處在上電但網線未插入)的情況,此時需要對ETH重新初始化,從而解決異常現象的第一種情況,具體執行內容為:

/**

* @brief : first time power on but init failed, do again

* @param : None

*

* @retval : None

* @author : xuk

*/

void ETH_Reinit(void){

/* Configure Ethernet */

EthInitStatus =ETH_Init(Ð_InitStructure, DP83848_PHY_ADDRESS);

}

其中ETH_InitStructure已設為全局結構體;

2、標注藍色部分的執行條件是已經成功初始化過ETH,但之后出現了網線的拔插情況,此時需要在每次檢測到網絡連接時重新進行自協商并初始化MAC,具體的執行流程如下介紹:

A、檢測到該條件時,首先調用:

netif_set_link_up(netif);

netif_set_link_down(netif);

B、追溯兩個函數的定義處,如下:

#if LWIP_NETIF_LINK_CALLBACK

/**

* Called by a driver when its link goes up

*/

void netif_set_link_up(struct netif *netif )

{

netif->flags |= NETIF_FLAG_LINK_UP;

#if LWIP_DHCP

if (netif->dhcp) {

dhcp_network_changed(netif);

}

#endif /* LWIP_DHCP */

#if LWIP_AUTOIP

if (netif->autoip) {

autoip_network_changed(netif);

}

#endif /* LWIP_AUTOIP */

if (netif->flags & NETIF_FLAG_UP) {

#if LWIP_ARP

/* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */

if (netif->flags & NETIF_FLAG_ETHARP) {

etharp_gratuitous(netif);

}

#endif /* LWIP_ARP */

#if LWIP_IGMP

/* resend IGMP memberships */

if (netif->flags & NETIF_FLAG_IGMP) {

igmp_report_groups( netif);

}

#endif /* LWIP_IGMP */

}

NETIF_LINK_CALLBACK(netif);

}

/**

* Called by a driver when its link goes down

*/

void netif_set_link_down(struct netif *netif )

{

netif->flags &= ~NETIF_FLAG_LINK_UP;

NETIF_LINK_CALLBACK(netif);

}

/**

* Ask if a link is up

*/

u8_t netif_is_link_up(struct netif *netif)

{

return (netif->flags & NETIF_FLAG_LINK_UP) ? 1 : 0;

}

/**

* Set callback to be called when link is brought up/down

*/

voidnetif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif ))

{

if (netif) {

netif->link_callback = link_callback;

}

}

#endif /* LWIP_NETIF_LINK_CALLBACK */

注意:I:從上述看出,若要這兩個函數有效編譯,則必須定義宏LWIP_NETIF_LINK_CALLBACK 為1,請自行設置;

II:函數netif_set_link_callback的作用是指定網絡連接發生改變時的回調函數;

III:詳細的講一下主要思路,Eth_Link_ITHandler執行中檢測到網線拔插時分別調用netif_set_link_up(netif)、netif_set_link_down(netif);這兩個函數的調用會引發netif_set_link_callback的執行,從而執行指定的網絡連接或斷開的回調函數;

Ⅳ:通過netif_set_link_callback該函數在LWIP初始化的時候指定網絡連接變化的回調函數,可放置如下位置:


void LwIP_Init(void){

......

......

......

......

/*set the link up or link down callback function - xuk*/

netif_set_link_callback(&netif,eth_re_link);

}


其中,回調函數eth_re_link的具體內容如下,實現網絡拔插后的重新自協商與MAC初始化:

/**

* @brief : process the relink of eth

* @param : netif - - specify the ETH netif

*

* @retval : none

* @author : xuk

*/

voideth_re_link(struct netif *netif){

__IO uint32_t tickstart = 0;

uint32_t regvalue = 0, tmpreg = 0;

if(netif_is_link_up(netif)){/*link up process*/

if(ETH_InitStructure.ETH_AutoNegotiation == ETH_AutoNegotiation_Enable){/*AutoNegotiation_Enable*/

/* Enable Auto-Negotiation */

ETH_WritePHYRegister(DP83848_PHY_ADDRESS, PHY_BCR, PHY_AutoNegotiation);

/* Wait until the auto-negotiation will be completed */

do

{

tickstart++;

} while (!(ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_BSR) & PHY_AutoNego_Complete) && (tickstart < (uint32_t)PHY_READ_TO));

/* Return ERROR in case of timeout */

if(tickstart == PHY_READ_TO)

{

// return ETH_ERROR;

}

/* Reset Timeout counter */

tickstart = 0;

/* Read the result of the auto-negotiation */

regvalue = ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_SR);

/* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */

if((regvalue & PHY_DUPLEX_STATUS) != (uint32_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;

}

}

else{/*AutoNegotiation_Disable*/

if(!ETH_WritePHYRegister(DP83848_PHY_ADDRESS, PHY_BCR, ((uint16_t)(ETH_InitStructure.ETH_Mode >> 3) |

(uint16_t)(ETH_InitStructure.ETH_Speed >> 1))))

{

/* Return ERROR in case of write timeout */

// return ETH_ERROR;

}

/* Delay to assure PHY configuration */

// _eth_delay_(PHY_CONFIG_DELAY);

}

/*------------------------ 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 IPCO 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_InitStructure.ETH_Watchdog |

ETH_InitStructure.ETH_Jabber |

ETH_InitStructure.ETH_InterFrameGap |

ETH_InitStructure.ETH_CarrierSense |

ETH_InitStructure.ETH_Speed |

ETH_InitStructure.ETH_ReceiveOwn |

ETH_InitStructure.ETH_LoopbackMode |

ETH_InitStructure.ETH_Mode |

ETH_InitStructure.ETH_ChecksumOffload |

ETH_InitStructure.ETH_RetryTransmission |

ETH_InitStructure.ETH_AutomaticPadCRCStrip |

ETH_InitStructure.ETH_BackOffLimit |

ETH_InitStructure.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_InitStructure.ETH_ReceiveAll |

ETH_InitStructure.ETH_SourceAddrFilter |

ETH_InitStructure.ETH_PassControlFrames |

ETH_InitStructure.ETH_BroadcastFramesReception |

ETH_InitStructure.ETH_DestinationAddrFilter |

ETH_InitStructure.ETH_PromiscuousMode |

ETH_InitStructure.ETH_MulticastFramesFilter |

ETH_InitStructure.ETH_UnicastFramesFilter);

/*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/

/* Write to ETHERNET MACHTHR */

ETH->MACHTHR = (uint32_t)ETH_InitStructure.ETH_HashTableHigh;

/* Write to ETHERNET MACHTLR */

ETH->MACHTLR = (uint32_t)ETH_InitStructure.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_InitStructure.ETH_PauseTime << 16) |

ETH_InitStructure.ETH_ZeroQuantaPause |

ETH_InitStructure.ETH_PauseLowThreshold |

ETH_InitStructure.ETH_UnicastPauseFrameDetect |

ETH_InitStructure.ETH_ReceiveFlowControl |

ETH_InitStructure.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_InitStructure.ETH_VLANTagComparison |

ETH_InitStructure.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_InitStructure.ETH_DropTCPIPChecksumErrorFrame |

ETH_InitStructure.ETH_ReceiveStoreForward |

ETH_InitStructure.ETH_FlushReceivedFrame |

ETH_InitStructure.ETH_TransmitStoreForward |

ETH_InitStructure.ETH_TransmitThresholdControl |

ETH_InitStructure.ETH_ForwardErrorFrames |

ETH_InitStructure.ETH_ForwardUndersizedGoodFrames |

ETH_InitStructure.ETH_ReceiveThresholdControl |

ETH_InitStructure.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_InitStructure.ETH_AddressAlignedBeats |

ETH_InitStructure.ETH_FixedBurst |

ETH_InitStructure.ETH_RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */

ETH_InitStructure.ETH_TxDMABurstLength |

(ETH_InitStructure.ETH_DescriptorSkipLength << 2) |

ETH_InitStructure.ETH_DMAArbitration |

ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */

#ifdef USE_ENHANCED_DMA_DESCRIPTORS

/* Enable the Enhanced DMA descriptors */

ETH->DMABMR |= ETH_DMABMR_EDE;

#endif /* USE_ENHANCED_DMA_DESCRIPTORS */

/* Return Ethernet configuration success */

// return ETH_SUCCESS;

// ETH_Start();

}

else{/*link down process*/

}

}

至此,對于STM32F207(裸機)- LWIP網線熱插入網絡不通遇到的問題以及解決辦法介紹完畢。


關鍵字:STM32  移植  LWIP網線  熱插入網絡 引用地址:STM32移植LWIP網線熱插入網絡不通的解決辦法

上一篇:STM32F4 LAN8720以及LWIP的移植調試記錄 (3)
下一篇:stm32CubeMX上lwip的配置問題

推薦閱讀

面對技術差距,既不能盲目悲觀,也不能被非理性情緒裹挾,而應該激發理性自強的心態與能力,通過自力更生掌握核心技術。?美國商務部日前宣布,今后7年內,將禁止該國企業向中國電信設備制造商中興通訊出售任何電子技術或通訊元件。這一事件不僅對包括中興在內的高科技企業產生影 響,而且在輿論場上引發深入討論,其中的一個關注焦點是,出口禁運觸碰到...
(圖片來源:patentlyapple.com)據外媒報道,當有消息透露,蘋果公司(Apple)正在研發半自動或完全自動駕駛汽車時,三星也透露他們在采取同樣的發展路線。但是與蘋果刻意保密工作內容不同,三星喜歡張揚。本周,三星發布了一個“2019數字駕駛艙”視頻,視頻中涵蓋了未來可應用于自動駕駛汽車的新想法。想法之一是讓外部的汽車鏡變成“車內”的視頻窗口,...
2020年4月21日,剛剛進行完品牌升級的努比亞面向全網正式召開了努比亞Play 5G手機新品發布會,在發布會上全新的努比亞將品牌對于5G移動通信終端的理解,與年輕化的形象以及為用戶量身打造的功能相匹配,帶來了集設計、游戲、攝影、潮玩于一身的全新產品——努比亞Play 5G手機 。   同時努比亞也宣告發布了多款智能生態產品,全新形象的努比亞不僅將...
4月22日消息,不久前才剛剛宣布提前復工的日本車用電子大廠瑞薩電子(Renesas)位于茨城縣的那珂(Naka)廠N3大樓再度發生火災事故。根據瑞薩官網發布的公告顯示,當地時間4月21日16:29時,位于那珂廠N3大樓(300毫米生產線)地下室的有軌電車(RGV)的配電盤發出了煙霧,隨后瑞薩員工立即將其撲滅。消防部門確認了現場,并維修了引起煙霧的配電盤后,N3大...

史海拾趣

問答坊 | AI 解惑

使用SignalTap II邏輯分析儀調試FPGA.pdf

使用SignalTap II邏輯分析儀調試FPGA.pdf…

查看全部問答∨

嵌入式產業前景的真相

嵌入式技術已經無處不在,從隨身攜帶的mp3、語言復讀機、手機、PDA到家庭之中的智能電視、智能冰箱、機頂盒,再到工業生產、娛樂中的機器人,無不采用嵌入式技術。各大跨國公司及國內家電巨頭如INTEL、TI、SONY、三星、TCL、聯想和康佳等都面臨著嵌 ...…

查看全部問答∨

*****ARM程序在RAM中執行跳轉出錯,懇請指教*****

各位前輩,小弟在用友善的supervivi下程序到SDRAM中執行的時候,發現如下問題: 我寫了一個測試程序:         B         SYSINIT         B         Handler ...…

查看全部問答∨

Flash Programmer下提示arm2410開發板連不PC

電腦連不上開發板,Flash Programmer提示如下: Target Communications Error:PC to Target Cable disconneted 我是一個新手,自學嵌入式,放棄原來的java開發,學了4個月的C和linux, 第一次用Realarm2410開發板, 系統windowsxpsp2克隆版 ...…

查看全部問答∨

[轉載]FPGA經驗總結

看到這篇文章寫得比較好,就轉載過來了。   時序是設計出來的  我的boss有在華為及峻龍工作的背景,自然就給我們講了一些華為及altera做邏輯的一些東西,而我們的項目規范,也基本上是按華為的那一套去做。在工作這幾個月中,給我感觸最深的是 ...…

查看全部問答∨

OTL功放電路

  首先,我是 學生黨。   以下是我在實訓中設計的一個  OTL音頻功放電路 請問一下,為什么我按照下面的電路圖接好實驗板后,要么就是沒有輸出信號,要么就是得到一些奇怪的信號(見第二張圖)?   思考了很久,試了多次 ...…

查看全部問答∨

程序移植

本人正在學習UCOS II下的LM3S6911程序移植,哪位大蝦能提供LM3S6911的UCOS的移植說明,謝謝!…

查看全部問答∨

【招聘】新加坡電子領域人才熱招!

經過幾年在國內工作的經驗積累,有沒有想過要到國外最先進的市場一試身手?各位工程師小伙伴,新加坡可以為你提供諸多充滿誘惑的新機會!另外,新加坡作為全球首選的宜居之地,更可以為你實現工作生活的長期合理規劃。 目前,幾大世界級電子領軍 ...…

查看全部問答∨

藍牙4.0意味著什么?

別地文章,請看鏈接:藍牙4.0意味著什么?…

查看全部問答∨
小廣播
設計資源 培訓 開發板 精華推薦

最新單片機文章
何立民專欄 單片機及嵌入式寶典

北京航空航天大學教授,20余年來致力于單片機與嵌入式系統推廣工作。

 
EEWorld訂閱號

 
EEWorld服務號

 
汽車開發圈

 
機器人開發圈

電子工程世界版權所有 京ICP證060456號 京ICP備10001474號-1 電信業務審批[2006]字第258號函 京公網安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
主站蜘蛛池模板: 乌恰县| 清苑县| 甘德县| 昌江| 永仁县| 唐山市| 谷城县| 邳州市| 开原市| 长葛市| 威信县| 叙永县| 宁波市| 偃师市| 从化市| 黑水县| 城步| 望奎县| 含山县| 偃师市| 浮梁县| 峡江县| 上杭县| 将乐县| 修水县| 苏尼特左旗| 潞西市| 遵义县| 阳东县| 松滋市| 鲁山县| 沈阳市| 馆陶县| 精河县| 日喀则市| 金沙县| 上高县| 南投市| 屏山县| 莱州市| 中西区|