This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32F407 Ethernet inicialization problem with Uvision4

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 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_teste_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);
}

Parents
  • 1) You have fixed IP or dynamic? And if dynamic - where is the DHCP server?

    2) Your client socket will fail if the other part isn't available. It's meaningful to have a loop and regularly try again if you fail.

    3) The server socket may also fail if you don't have any IP number.

    4) Always mind the result of different function calls, and consider what action to do based on the result. Networking normally means large requirements for reconnects etc since you can't depend on the network to be always available.

Reply
  • 1) You have fixed IP or dynamic? And if dynamic - where is the DHCP server?

    2) Your client socket will fail if the other part isn't available. It's meaningful to have a loop and regularly try again if you fail.

    3) The server socket may also fail if you don't have any IP number.

    4) Always mind the result of different function calls, and consider what action to do based on the result. Networking normally means large requirements for reconnects etc since you can't depend on the network to be always available.

Children