新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 9G-STM32 LwIP測試過程簡介

        9G-STM32 LwIP測試過程簡介

        作者: 時間:2016-11-29 來源:網絡 收藏
        一,準備STM32 LwIP軟件包

        1,在http://www.st.com/mcu/devicedocs-STM32F107RC-110.html
        下載lwIP TCP/IP stack demonstration for STM32F107xx connectivity line microcontrollers軟件包
        an3102.zip
        http://www.st.com/stonline/products/support/micro/files/an3102.zip

        2,在http://www.st.com/mcu/devicedocs-STM32F107RC-110.html
        下載lwIP TCP/IP stack demonstration for STM32F107xx connectivity line microcontrollers文檔
        16620.pdf
        http://www.st.com/stonline/products/literature/an/16620.pdf

        3,有關STM32F107VC-PKT的PCB和SCH和測試代碼見下面連接:STM32F107VC_SCH.pdf
        STM32F107VC_PCB.pdfSTM32107_LK_SelfTest.zip

        本文引用地址:http://www.104case.com/article/201611/323206.htm

        二,建立STM32 LwIP開發工程

        1,把an3102.zip解壓到D:works形成工程文件夾:D:worksSTM32F107_ETH_LwIP_V1.0.0 ;

        2,進入到目錄D:worksSTM32F107_ETH_LwIP_V1.0.0ProjectEWARMv5,雙擊Project.eww打開工程;

        3,在EWARM中的Project->make 編譯通過整個項目。

        三,修改STM32 LwIP開發工程

        1,打開Project->Options ,在Category中選擇Debugger的setup驅動用J-Link/J-Trace,在J-Link/J-Trace
        中選擇connection的SWD接口;

        2,對STM32F107VC-PKT開發板加上5V的直流電源,把J-LINK用USB線連接到PC的USB口上,執行Project->Download and Debug
        下載代碼到板子后,執行Debug->Go 。

        四,修改STM32 LwIP開發源碼

        1,在D:worksSTM32F107_ETH_LwIP_V1.0.0Projectsrcmain.c 的53行后添加如下代碼:

        /* Output a message on Hyperterminal using printf function */
        printf("");
        printf("*** STM32F107VC-PKT V1.0 Build byyuanxihua@21cn.comon ("__DATE__ " - " __TIME__ ")");
        printf("*** STM32F107VC-PKT V1.0 Rebooting ...");

        2,在D:worksSTM32F107_ETH_LwIP_V1.0.0Projectsrcstm32f107.c 的包含頭文件中添加:
        #include "stdio.h"

        在第30行選擇用MII模式:
        #define MII_MODE /* MII mode for STM3210C-EVAL Board (MB784) (check jumpers setting) */
        //#define RMII_MODE /* RMII mode for STM3210C-EVAL Board (MB784) (check jumpers setting) */

        在54行后添加:
        USART_InitTypeDef USART_InitStructure;

        在125行后添加:

        /* Configure the com port */
        /* USARTx configuration ------------------------------------------------------*/
        /* USARTx configured as follow:
        - BaudRate = 115200 baud
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
        */
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No ;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

        STM_EVAL_COMInit(COM1, &USART_InitStructure);
        }

        /**
        * @brief Retargets the C library printf function to the USART.
        * @param None
        * @retval : None
        */
        int fputc(int ch, FILE *f)
        {
        /* Write a character to the USART */
        USART_SendData(USART2, (uint8_t) ch);

        /* Loop until the end of transmission */
        while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
        {
        }

        return ch;
        }
        /**
        * @brief Get a key from the HyperTerminal
        * @param None
        * @retval : The Key Pressed
        */
        int fgetc(FILE *f)
        {
        /* Waiting for user input */
        while ( USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
        return (uint8_t)USART2->DR;

        在341-344行修改為:
        /* ADC Channel10 config --------------------------------------------------------*/
        /* Relative to STM32F107VC-PKT Board */
        /* Configure PC.00 (ADC Channel10) as analog input -------------------------*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

        在375-376行修改為:
        /* ADC1 regular channel10 configuration */
        ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_13Cycles5);

        3,在D:worksSTM32F107_ETH_LwIP_V1.0.0Projectsrcetconf.c 中的119-121行和316-318行把
        IP地址都修改如下:
        IP4_ADDR(&ipaddr, 192, 168, 1, 8);
        IP4_ADDR(&netmask, 255, 255, 255, 0);
        IP4_ADDR(&gw, 192, 168, 1, 1);

        4,在D:worksSTM32F107_ETH_LwIP_V1.0.0Utilitieslwip-1.3.1portlwipopts.h中把
        #define LWIP_DHCP 1
        修改成:
        #define LWIP_DHCP 0

        5,在D:worksSTM32F107_ETH_LwIP_V1.0.0UtilitiesSTM32_EVALSTM3210C_EVALstm3210c_eval.h中把
        #define LED1_GPIO_PIN GPIO_Pin_7
        修改成:
        #define LED1_GPIO_PIN GPIO_Pin_13

        #define LED2_GPIO_PIN GPIO_Pin_13
        修改成:
        #define LED2_GPIO_PIN GPIO_Pin_14

        #define LED3_GPIO_PIN GPIO_Pin_3
        修改成:
        #define LED3_GPIO_PIN GPIO_Pin_15


        #define COMn 1
        修改成
        #define COMn 2


        6,同樣執行Project->Download and Debug 下載代碼到板子后,執行Debug->Go 可以全速仿真運行。

        五,演示STM32 LwIP開發工程

        1,用交叉網線連接STM32F107VC-PKT到PC的網口,用交叉串口線連接RS232到PC的串口中,再對板子用5V上電
        復位啟動工作;
        2,可以在串口終端上用115200 8N1的格式看到:
        *** STM32F107VC-PKT V1.0 Build byyuanxihua@21cn.comon (Jan 12 2010 - 12:43:08)
        *** STM32F107VC-PKT V1.0 Rebooting ...
        3,在PC的IE瀏覽器中輸入:http://192.168.1.8/回車刷新可以訪問到板子,看到Home page主頁:
        STM32F107 Webserver Demo
        Based on the lwIP TCP/IP stack
        4,點擊Led control從Home page切換LED控制,任意勾上或者去掉LED1-3,再按SEND,可以看到板子的LED相應的
        被控制亮或者滅;
        5,點擊ADC status bar從Led control頁面切換到ADC采集,旋轉板子上的RV1,可以看到STM32F107 ADC status bar
        上綠色的滾動條被ADC的輸入電壓控制增減;
        6,在SecureCRT 5.1終端中可以以telnet協議訪問192.168.1.8,端口就是23,連接上了會顯示:
        Hello. What is your name? ,你輸入字符串YUANXIHUA,馬上會回復Hello YUANXIHUA



        關鍵詞: STM32LwIP測試過

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 兴城市| 许昌县| 沈丘县| 洛隆县| 乌拉特后旗| 明光市| 广河县| 耿马| 黄山市| 县级市| 涞源县| 砀山县| 沙洋县| 郁南县| 焦作市| 清丰县| 图们市| 郑州市| 永泰县| 曲阜市| 昔阳县| 江华| 廊坊市| 武隆县| 绥宁县| 垦利县| 若羌县| 贵港市| 运城市| 桃源县| 丹阳市| 都江堰市| 湖州市| 芦山县| 淮安市| 淮阳县| 阿坝县| 景泰县| 房山区| 阜新| 朝阳区|