Hi,
I’m proting mbed os to a custom stm32f407 board, and follow the guide from TM32F407VET6 black board project. The link is : STM32F407VET6_Hello - Using low cost STM32F407VET6 boards with mbed. | Mbed.
Now I encounter a problem on ethernet interface. The pin connection of my board is the same as the ethernet module mentioned in that page. I run the demo code of TCP socket, and find the net.connect hangs up for a few seconds and return “-3004”. The socked connection is not established. Is there anyone know how to solve it?
Thanks.
Blockquote
#include “mbed.h”
#include “EthernetInterface.h”
// Network interface
EthernetInterface net;
uint8_t ip[4] = {192, 168, 25, 5};
uint8_t subnet[4] = {255, 255, 255, 0};
uint8_t gateway[4] = {192, 168, 25, 1};
const SocketAddress IP(ip, NSAPI_IPv4);
const SocketAddress SUBNET(subnet, NSAPI_IPv4);
const SocketAddress GATEWAY(gateway, NSAPI_IPv4);
// Socket demo
int main()
{
// Bring up the ethernet interface
printf(“Ethernet socket example\n”);
// net.connect();
net.set_network(IP, SUBNET, GATEWAY);
nsapi_error_t status = net.connect();
// Show the network address
SocketAddress a;
net.get_ip_address(&a);
printf("IP address: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
// Open a socket on the network interface, and create a TCP connection to mbed.org
TCPSocket socket;
socket.open(&net);
net.gethostbyname("ifconfig.io", &a);
a.set_port(6789);
socket.connect(a);
// Send a simple http request
char sbuffer[] = "GET / HTTP/1.1\r\nHost: ifconfig.io\r\n\r\n";
int scount = socket.send(sbuffer, sizeof sbuffer);
printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n") - sbuffer, sbuffer);
// Recieve a simple http response and print out the response line
char rbuffer[64];
int rcount = socket.recv(rbuffer, sizeof rbuffer);
printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n") - rbuffer, rbuffer);
// Close the socket to return its memory and bring down the network interface
socket.close();
// Bring down the ethernet interface
net.disconnect();
printf("Done\n");
}