TCP/IP - STM32F767ZI-Nucleo - Cannot manage to make it work - ETH
Hello,
Today and for the past days I am struggling trying to setup a TCP/IP server on the STM32F767Zi-Nucleo board..
The IP address is set to :
192.168.0.10
The mast address is set to :
255.255.255.0
The gateway address is set to :
192.168.0.1
My local machine show an IP address : 192.168.1.95
From my PC I am able to ping the board (w/ delay ~.025ms)
The main function is defined as :
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
osKernelInitialize();
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
osKernelStart();
while (1)
{
}
}The task is defined as :
void StartDefaultTask(void *argument)
{
MX_LWIP_Init();
printf("Entered task\n");
tcp_echoserver_init();
for(;;)
{
}
}And the server initialization :
void tcp_echoserver_init(void) {
local = netconn_new(NETCONN_TCP);
if (local == NULL) {
printf("Setup local connection failed\n");
return;
}
printf("Local connection initialized\n");
err_t err;
err = netconn_bind(local, IP_ADDR_ANY, 7); // open port 7 || WILL BE CHANGED
struct netbuf *buf = netbuf_new();
void *data;
uint16_t len;
if (err == ERR_OK) {
printf("Connection binded to port 7\n");
err = netconn_listen(local); // set listening mode
if (err != ERR_OK) printf("listen issue\n");
printf("Port 7 is in listening mode\n");
printf("Socket : %d\n", local->socket); // -1 is a problem
while (1) {
printf("Accepting..\n");
err = netconn_accept(local, &remote);
if (err == ERR_OK) {
printf("Accepted!\n");
while ((err = netconn_recv(remote, &buf)) == ERR_OK) {
do {
netbuf_data(buf, &data, &len);
netconn_write(remote, data, len, NETCONN_COPY);
} while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
netconn_close(remote);
netconn_delete(remote);
}
}
} else {
printf("Bind issue\n");
netconn_delete(remote);
}
}In my ioc file the clock is configured : 
I didn’t showed the rest since only this part is manually configurable.
LWIP Config :
Version 2.12 and DHCP disabled

The rest is at default configuration
I also turned on RTOS :
API : CMSIS v2
FreeRTOS version 10.2.1
CMSIS-RTOS 2.0
The ETH port is enabled in RMII with global interrupt (w/o wake-up interrupt EXTI line 19)
RCC is Crystal/Ceramic Resonator HSE, rest of configuration unchanged
And SYS :
Debug to Serial Wire with timebase source TIM1 (as RTOS wont use Systick)
When launching debug session I got the following output in ITM console I got the following output :
Entered task
Local connection initialized
Connection binded to port 7
Port 7 is in listening mode
Socket : -1
Accepting..For output to work. change write function from
__attribute__((weak))
int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}to
//__attribute__((weak))
int _write(int file, char *ptr, int len)
{
/* Implement your write code here, this is used by puts and printf for example */
for(int i = 0 ; i < len ; i++) ITM_SendChar((*ptr++));
return len;
// int DataIdx;
//
// for (DataIdx = 0; DataIdx < len; DataIdx++)
// {
// __io_putchar(*ptr++);
// }
// return len;
}From there I simply though : “Hey let’s use netcat or whatever and just connect.�?

Or setting a C project that going to communicate with the board (as it is my final goal)
client.c
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
void func(int sockfd)
{
char buff[MAX];
int n;
for (;;) {
bzero(buff, sizeof(buff));
printf("Enter the string : ");
n = 0;
while ((buff[n++] = getchar()) != '\n')
;
write(sockfd, buff, sizeof(buff));
bzero(buff, sizeof(buff));
read(sockfd, buff, sizeof(buff));
printf("From Server : %s", buff);
if ((strncmp(buff, "exit", 4)) == 0) {
printf("Client Exit...\n");
break;
}
}
}
int main()
{
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
exit(0);
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n");
exit(0);
}
else
printf("connected to the server..\n");
// function for chat
func(sockfd);
// close the socket
close(sockfd);
}server.c
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
// Function designed for chat between client and server.
void func(int sockfd)
{
char buff[MAX];
int n;
// infinite loop for chat
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents
printf("From client: %s\t To client : ", buff);
bzero(buff, MAX);
n = 0;
// copy server message in the buffer
while ((buff[n++] = getchar()) != '\n')
;
// and send that buffer to client
write(sockfd, buff, sizeof(buff));
// if msg contains "Exit" then server exit and chat ended.
if (strncmp("exit", buff, 4) == 0) {
printf("Server Exit...\n");
break;
}
}
}
// Driver function
int main()
{
int sockfd, connfd, len;
struct sockaddr_in servaddr, cli;
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
exit(0);
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0) {
printf("socket bind failed...\n");
exit(0);
}
else
printf("Socket successfully binded..\n");
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0) {
printf("Listen failed...\n");
exit(0);
}
else
printf("Server listening..\n");
len = sizeof(cli);
// Accept the data packet from client and verification
connfd = accept(sockfd, (SA*)&cli, &len);
if (connfd < 0) {
printf("server acccept failed...\n");
exit(0);
}
else
printf("server acccept the client...\n");
// Function for chatting between client and server
func(connfd);
// After chatting close the socket
close(sockfd);
}gcc server.c -o server && gcc client.c -o client

When changing client server address fomr 127.0.01 to 192.168.0.10 and port from 8080 to 7

So… PC-wise it seems to work. But the connection is never accepted on the board.
I also tried to use the project from the git :
LwIP_HTTP_Server_Netconn_RTOS under STM32CubeF7-master/Projects/STM32F767ZI-Nucleo/Applications/LwIP/LwIP_HTTP_Server_Netconn_RTOS
removed the line #define USE_LCD and #define USE_DHCP
changing the IP by the one I set on my board. Still have no result. Trying to access the webpage at 192.168.0.10:80 shows “Unable to connect�? from e.g. Firefox
I also tried to use MBED /w their IDE, still get no results.
I've only been working with STM board since like... 3-4 month on only 2projects, the one only involved USART & i2C communication (way easier). That's for my background w/ MCUs :)
Thanks a lot !
Nicolas
