- UID
- 1029342
- 性别
- 男
|
探究WaveShare的F407的板子好几天了,这两天一直止步于网卡模块的udp发包,因为截包工具总是收不到我代码里面发出去的数据包,我的要求是只发特定数据,不管收到的数据包
记录下整个测试过程,以便以后翻阅
使用开发板自带的例程,udp_echo_server的例子,在此基础上修改,main函数是
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured to
168 MHz, this is done through SystemInit() function which is called from
startup file (startup_stm32f4xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
#ifdef SERIAL_DEBUG
DebugComPort_Init();
#endif
/*Initialize LCD and Leds */
LCD_LED_Init();
/* configure ethernet */
ETH_BSP_Config();
/* Initilaize the LwIP stack */
LwIP_Init();
/* UDP echoserver */
udp_echoserver_init();
/* Infinite loop */
while (1)
{
/* check if any packet received */
if (ETH_CheckFrameReceived())
{
/* process received ethernet packet */
LwIP_Pkt_Handle();
}
/* handle periodic timers for LwIP */
LwIP_Periodic_Handle(LocalTime);
}
}
我发现串口不能用,可能是其初始化方式有些问题,我做了些修改
将DebugComPort_Init函数改成下面两个函数
USART_Configuration();
USART_NVIC_Config();
串口1就可以正常使用了
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(Open_USART_TX_GPIO_CLK,ENABLE);
RCC_AHB1PeriphClockCmd(Open_USART_RX_GPIO_CLK,ENABLE);
#ifdef
USART1_OPEN
RCC_APB2PeriphClockCmd(Open_USART_CLK,ENABLE);
#else
RCC_APB1PeriphClockCmd(Open_USART_CLK,ENABLE);
#endif
GPIO_PinAFConfig(Open_USART_TX_GPIO_PORT, Open_USART_TX_SOURCE, Open_USART_TX_AF);
GPIO_PinAFConfig(Open_USART_RX_GPIO_PORT, Open_USART_RX_SOURCE, Open_USART_RX_AF);
/*
* Open_USART_TX -> PA9 , Open_USART_RX -PA10
*/
GPIO_InitStructure.GPIO_Pin = Open_USART_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(Open_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open_USART_RX_PIN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(Open_USART_RX_GPIO_PORT, &GPIO_InitStructure);
/*
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
*/ |
|