2015-08-12 11:09 AM
Hi,
I am using STM32F407 with uvision4, RL-TCPnet from keil and I have a problem in the Ethernet inicialization.
When I turn on the PC and turn on the board at the same time the Ethernet doesn’t work, but if I turn on the PC and after that I turn on the board the communication works.
I have two client sockets and one server socket.
I have no hub, just the ethernet cable direct. Do anyone already have this kind of problem? The code is:int main (void){
...
//INICIALIZA TCP NET
init_TcpNet ();
socket_tcp_cliente = tcp_get_socket (TCP_TYPE_CLIENT, 0, 5, tcp_callback_OSC);
socket_tcp = tcp_get_socket (TCP_TYPE_CLIENT, 0, 5, tcp_callback_OSC);
/* Initialize TCP Socket and start listening */
socket_tcp_escrita = tcp_get_socket (TCP_TYPE_SERVER, 0, 30, tcp_callback);
if (socket_tcp_escrita != 0) {
tcp_listen (socket_tcp_escrita, 2002);
}
os_sys_init (task_init); /* Inicializa Sistema Operacional */
}
__task void timer_task (void){
os_itv_set (100);
while (1) {
timer_tick ();
tick = __TRUE;
os_itv_wait ();
}
}
*----------------------------------------------------------------------------
* Task 2: Ethernet Task Resposta
*---------------------------------------------------------------------------*/
__task void task_Resposta (void){
char estado_tcp = 0;
unsigned int indice = 0;
// os_itv_set(100);
for(;;){
estado_tcp = tcp_get_state(socket_tcp_cliente);
switch (estado_tcp) {
case TCP_STATE_FREE:
break;
case TCP_STATE_CLOSED:
Rem_IP[3] = 62;
if (tcp_connect (socket_tcp_cliente, Rem_IP, 5001, 0)){
delay_oscilografia = 100;
}else{
delay_oscilografia = 1000;
}
break;
case TCP_STATE_CONNECT:
if (tcp_check_send (socket_tcp_cliente) == __TRUE) {
sendbuf_Resposta = tcp_get_buf(1206);
sendbuf_Resposta[0] = 'O';
sendbuf_Resposta[1] = 'S';
sendbuf_Resposta[2] = 'C';
for (indice = 0; indice < 1200; indice++)
sendbuf_Resposta[indice + 3] = Oscilografia_IHM[indice];
sendbuf_Resposta[indice + 3] = 'O';
sendbuf_Resposta[indice + 4] = 'S';
sendbuf_Resposta[indice + 5] = 'C';
cont_*****_IHM ++;
tcp_send (socket_tcp_cliente, sendbuf_Resposta, 1206);
}
break;
}
// os_itv_wait();
os_dly_wait(delay_oscilografia);
}
}
/*----------------------------------------------------------------------------
* Task 5: Ethernet Tcp Task
*---------------------------------------------------------------------------*/
__task void tcp_task(void){
while (1) {
main_TcpNet();
os_tsk_pass();
}
}
U16 tcp_callback_OSC (U8 soc, U8 evt, U8 *ptr, U16 par) {
if (soc == socket_tcp) {
switch (evt) {
case TCP_EVT_CONREQ:
/* Remote host is trying to connect to our TCP socket. */
/* 'ptr' points to Remote IP, 'par' holds the remote port. */
/* Return 1 to accept connection, or 0 to reject connection */
return (1);
case TCP_EVT_ABORT:
/* Connection was aborted */
break;
case TCP_EVT_CONNECT:
/* Socket is connected to remote peer. */
break;
case TCP_EVT_CLOSE:
/* Connection has been closed */
break;
case TCP_EVT_ACK:
/* Our sent data has been acknowledged by remote peer */
break;
case TCP_EVT_DATA:
/* TCP data frame has been received, 'ptr' points to data */
/* Data length is 'par' bytes */
break;
}
}
return (0);
}
Thanks.
2015-08-13 03:06 AM
Hi,
I suggest you to submit your request in Keil forum as you are using its library not ST one-Syrine-2015-08-13 04:33 AM
Ok, I will try there too.
I am considering changing the library to one of ST.I found LwIP with examples, there is more alternatives?2015-08-13 06:29 AM
Hi,
You can find examples STM32Cube_FW_F4 under cube package:STM32Cube_FW_F4_V1.7.0\Projects\STM324x9I_EVAL\Applications\LwIPAlso have a look to andhttp://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00105446.pdf
, they will be very useful.-Syrine-2015-08-14 07:49 AM
The problem is that
my client socket will fail if the other part isn't available. It's meaningful to have a loop and regularly try again if I fail.
I tried it but only work if I call the init_tcpnet with the tcp_get_socket again.The function init_tcpnet take a lot of time and the extern watchdog (100ms) resets the microcontroller. Only for test I have removed the watchdog.In the main function it works because I put a hardware delay in the watchdog for the inicialization.Any idea about what I can do?