Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 4 months ago.
STM32: socket.connect returns -3004
I am trying to use a STM32F407ZGT6 board with a DP83848 Ethernet PHY on a local network (mbed-os 5.12.3). The socket.connect returns -3004 (not connected to a network). 10.231.13.185 is my web server. What is wrong? Thank you for your help.
The debug part:
Ethernet socket example IP address is: 10.231.13.138 gethostbyname, 10.231.13.185:80, ret: 0 open, stat: 0 connect, stat: -3004 sent -3004 [GET /index.html HTTP/1.0] recv -3004 [] Done
The code:
<code>
- include "mbed.h"
- include "EthernetInterface.h"
/ETH GPIO Configuration
PC1 --> ETH_MDC
PA1 --> ETH_REF_CLK
PA2 --> ETH_MDIO
PA7 --> ETH_CRS_DV
PC4 --> ETH_RXD0
PC5 --> ETH_RXD1
PB11 --> ETH_TX_EN
PB12 --> ETH_TXD0
PB13 --> ETH_TXD1
- /
DigitalOut led1(PF_9); DigitalOut led2(PF_10); Serial pc(PA_9, PA_10);
void led2_thread() { while (true) { led2 = !led2; Thread::wait(1000); } }
Network interface EthernetInterface net;
Socket demo int main() { int stat; Thread thread1;
thread1.start(led2_thread);
pc.baud(115200); Bring up the ethernet interface pc.printf("\r\nEthernet socket example\r\n"); net.connect();
Show the network address const char *ip = net.get_ip_address(); pc.printf("IP address is: %s\r\n", ip ? ip : "No IP");
SocketAddress addr; nsapi_error_t ret = net.gethostbyname("10.231.13.185", &addr); Resolve and store into addr addr.set_port( 80 ); pc.printf("gethostbyname, %s:%d, ret: %d\r\n", addr.get_ip_address(), addr.get_port(), ret );
Open a socket on the network interface, and create a TCP connection TCPSocket socket; stat = socket.open(&net); pc.printf("open, stat: %d\r\n", stat );
stat = socket.connect( addr ); pc.printf("connect, stat: %d\r\n", stat );
Send a simple http request char sbuffer[] = "GET /index.html HTTP/1.0\r\n\r\n"; int scount = socket.send(sbuffer, sizeof sbuffer); pc.printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
Recieve a simple http response and print out the response line char rbuffer[640]; int rcount = socket.recv(rbuffer, sizeof rbuffer); pc.printf("recv %d [%.*s]\r\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(); pc.printf("Done\r\n"); } </code>