新闻中心

EEPW首页>嵌入式系统>设计应用> 9G-STM32 LwIP测试过程简介

9G-STM32 LwIP测试过程简介

作者: 时间:2016-11-29 来源:网络 收藏
一,准备STM32LwIP软件包

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

本文引用地址://m.amcfsurvey.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中把
#defineLED1_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测试过

评论


技术专区

关闭