故障现象 在netcon下 TCP客户端或服务器端程序均不能正常工作。
硬件平台EVA-407
PHY:DP83848
软件平台:
STM32Cubemx
LWIP 2.0版
FREERTOS
我在stm32CubeMx 在针脚配置中
选定如下功能
lwip及 freertos 均用默认配置
产生代码并编译后,
自已编写如下用户代码 这是参照以往的官方例程
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configura
tion----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* init code for LWIP */
MX_LWIP_Init();
/* Initialize tcp echo server */
tcpecho_init();
/* USER CODE END 2 */
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
static void tcpecho_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err;
LWIP_UNUSED_ARG(arg);
/* Create a new connection identifier. */
conn = netconn_new(NETCONN_TCP);
if (conn!=NULL)
{
/* Bind connection to well known port number 7. */
err = netconn_bind(conn, NULL, 8080);
if (err == ERR_OK)
{
/* Tell connection to go into listening mode. */
netconn_listen(conn);
while (1)
{
/* Grab new connection. */
err= netconn_accept(conn, newconn);
/* Process the new connection. */
if (newconn)
{
struct netbuf *buf;
void *data;
u16_t len;
while ((err = netconn_recv(newconn, buf)) != NULL)
{
do
{
netbuf_data(buf, data, len);
netconn_write(newconn, data, len, NETCONN_COPY);
}
while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
/* Close connection and discard connection identifier. */
netconn_close(newconn);
netconn_delete(newconn);
}
}
}
else
{
printf(" can not bind TCP netconn");
}
}
else
{
printf("can not create TCP netconn");
}
}
/*-----------------------------------------------------------------------------------*/
void tcpecho_init(void)
{
sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, tskIDLE_PRIORITY + 3);
}
运行后用网络调试助手可以连接上
开发板,但数据回送。
如果我将开发板开成TCP的客户端 ,则无法联上服务器。
ping 开发板的92.168.1.10是可以ping通的。
我查不到原因,希望能得到指 导,或都是有stm32Cubemx4.26版本下的tcp客户端和服务器端的例程供参考以便查原因。