• AVR Freaks

Create an Ethernet project with MPLAB Harmony that works

Author
KokuH
Starting Member
  • Total Posts : 45
  • Reward points : 0
  • Joined: 2018/05/07 08:45:14
  • Location: France
  • Status: offline
2018/09/03 02:10:12 (permalink)
0

Create an Ethernet project with MPLAB Harmony that works

Hello,
 
I have a PIC32 Ethernet Starter Kit with PIC32MX795F512L, and I would like to use Ethernet to be able to make a server client with a PC, for example: send a byte frame with TCP from the PC to the PIC32 ESK, and answer it by, yes j received your rocket.
 
To do this, I would like to use MPLAB Harmony, but every time I try I always get tons of errors (I use MPLAB X IDE v4.20 with MPLAB Harmony v2_06).
 
 Problem of message approval, so the rest of the message will be on a response to this message ...
 
#1

7 Replies Related Threads

    KokuH
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2018/05/07 08:45:14
    • Location: France
    • Status: offline
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/03 02:11:46 (permalink)
    0
    I have tried various tutorials, but none have worked for me (http://microchipdeveloper.com/wifi:wh  ,  https://www.youtube.com/watch?v=EyclfQkgLnM ) Nothing worked for me, I always hang on mistakes, like this one for example (in first example):
     
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory 'C:/microchip/harmony/v2_06/apps/Ethernet_Project/firmware/Ethernet_Project.X'
    make -f nbproject/Makefile-default.mk dist/default/production/Ethernet_Project.X.production.hex
    make[2]: Entering directory 'C:/microchip/harmony/v2_06/apps/Ethernet_Project/firmware/Ethernet_Project.X'
    ../../../../framework/tcpip/src/dnss.c: In function 'TCPIP_DNSS_Initialize':
    ../../../../framework/tcpip/src/dnss.c:233:16: error: 'TCPIP_DNS_CLIENT_MAX_HOSTNAME_LEN' undeclared (first use in this function)
    if(TCPIP_DNS_CLIENT_MAX_HOSTNAME_LEN != 0)
    ^
    ../../../../framework/tcpip/src/dnss.c:233:16: note: each undeclared identifier is reported only once for each function it appears in
    ../../../../framework/tcpip/src/dnss.c: In function 'TCPIP_OAHASH_DNSS_KeyCopy':
    ../../../../framework/tcpip/src/dnss.c:1417:37: error: 'TCPIP_DNS_CLIENT_MAX_HOSTNAME_LEN' undeclared (first use in this function)
    memset(pDnssHE->pHostName,0,TCPIP_DNS_CLIENT_MAX_HOSTNAME_LEN);
    ^
    make[2]: *** [build/default/production/_ext/1408260596/dnss.o] Error 1
    make[1]: *** [.build-conf] Error 2
    make: *** [.build-impl] Error 2
    "C:\Program Files\Microchip\xc32\v2.10\bin\xc32-gcc.exe" -g -x c -c -mprocessor=32MX795F512L -ffunction-sections -O1 -D__XC -I../src -I../src/system_config/default -I../src/default -I../../../../framework -I../src/system_config/default/framework -I../../../../framework/driver/wifi/winc1500/include -I../../../../framework/driver/wifi/winc1500/wireless_driver/include -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension/bsp/include -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension/bus_wrapper/include -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension/common/include -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension/driver/include -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension/driver/source -I../../../../framework/driver/wifi/winc1500/wireless_driver_extension/spi_flash/include -I../src/system_config/default/bsp -I../../../../third_party/rtos/FreeRTOS/Source/include -I../../../../third_party/rtos/FreeRTOS/Source/portable/MPLAB/PIC32MX -MMD -MF build/default/production/_ext/1408260596/dnss.o.d -o build/default/production/_ext/1408260596/dnss.o ../../../../framework/tcpip/src/dnss.c -DXPRJ_default=default -no-legacy-libc 
    nbproject/Makefile-default.mk:1053: recipe for target 'build/default/production/_ext/1408260596/dnss.o' failed
    make[2]: Leaving directory 'C:/microchip/harmony/v2_06/apps/Ethernet_Project/firmware/Ethernet_Project.X'
    nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
    make[1]: Leaving directory 'C:/microchip/harmony/v2_06/apps/Ethernet_Project/firmware/Ethernet_Project.X'
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
    BUILD FAILED (exit value 2, total time: 10s)

     
    Someone would have examples of projects that could be useful to me, or could I run on my mistakes?
     
    Thank you
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 19185
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/03 07:34:27 (permalink)
    5 (1)
    You can look at it the Berkeley sockets example in harmony.

    As far as your errors, as a guess I would assume you are missing a check box in MHC. Some components have dependencies of othe components. But these my not be documented, and MHC does not warn about them.
    #3
    KokuH
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2018/05/07 08:45:14
    • Location: France
    • Status: offline
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/04 02:44:05 (permalink)
    0
    Hello,

    I just tried the demos proposed by Harmony, present in tcpip_tcp_client and tcpip_tcp_server, I compiled the two and its march! but I loaded the client project to my PIC32 Ethernet Starter Kit and in fact, I do not know if it works, I executed both projects, server/client, being in the wireshark to view something but I do not see anything, then I tried on the cmd Windows to make arp -a to see the IP addresses present (I do not know that of my PIC32 ESK), to check if my hardware is present I left the RJ45 cable connected to my network (the same as my pc), then I removed the cable and I still have the same number of IP addresses, so I deduce that my card is not visible on my network !!

    It is clear I am a newcomer in the world of PIC  ! so help me by being as accurate as possible!

    Thank you
    #4
    Jim Nickerson
    User 452
    • Total Posts : 6932
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/04 06:14:34 (permalink)
    5 (1)
    KokuH
    Hello,

    I just tried the demos proposed by Harmony, present in tcpip_tcp_client and tcpip_tcp_server, I compiled the two and its march! but I loaded the client project to my PIC32 Ethernet Starter Kit and in fact, I do not know if it works, I executed both projects, server/client, being in the wireshark to view something but I do not see anything, then I tried on the cmd Windows to make arp -a to see the IP addresses present (I do not know that of my PIC32 ESK), to check if my hardware is present I left the RJ45 cable connected to my network (the same as my pc), then I removed the cable and I still have the same number of IP addresses, so I deduce that my card is not visible on my network !!

    It is clear I am a newcomer in the world of PIC  ! so help me by being as accurate as possible!

    Thank you


    I have observed Wireshark may not always display all packets on your LAN.
    For example you may have an "intelligent" switch/router that does not repeat 10 mb packets on 1 gb segments.
    To ensure all packets are seen I have found making use of a switch with a "monitor" feature to enable repeating all packets on all ports to the monitored port for example https://www.netgear.com/s.port/product/GS105E.aspx
    #5
    KokuH
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2018/05/07 08:45:14
    • Location: France
    • Status: offline
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/06 06:48:02 (permalink)
    0
    Hello, thank you for your answer,

    I have already run programs to light up leds, and it works very well, Now I just run the demo (berkeley_tcp_server.X) and make it build very well, then I created a client code on a Raspberry PI to try to get something from my PIC, but this one does not unfortunately receive nothing, here is the python code for the client (I'm sure my client code written with python works very well):
     
    import socket
    import sys

    def c():
        while 1:
            try:
                
                hote = '192.168.100.115'
                port = 9760
                Connection_PIC=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                Connection_PIC.connect((hote,port))
                print("Connection whith PIC in port {}\n".format(port))
                #------------------------------------------------------------------------------------
                msg_recv=Connection_PIC.recv(1024).decode('UTF-8')
                print(msg_recv)

            except:
                print('Connection ...')
    c()

    The rest of this message will be in another reply message because of message approval problems ...
    #6
    KokuH
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2018/05/07 08:45:14
    • Location: France
    • Status: offline
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/06 06:50:03 (permalink)
    0
    After running I do not get anything on this port, so I pinged the Windows cmd (ping 192.168.100.115) and sometimes the packets are all sent and received and sometimes some are lost!

    Here is the code of the demo that can send something:

    /*******************************************************************************
      MPLAB Harmony Application Source File
      
      Company:
        Microchip Technology Inc.
      
      File Name:
        app.c

      Summary:
        This file contains the source code for the MPLAB Harmony application.

      Description:
        This file contains the source code for the MPLAB Harmony application.  It 
        implements the logic of the application's state machine and it may call 
        API routines of other MPLAB Harmony modules in the system, such as drivers,
        system services, and middleware.  However, it does not call any of the
        system interfaces (such as the "Initialize" and "Tasks" functions) of any of
        the modules in the system or make any assumptions about when those functions
        are called.  That is the responsibility of the configuration-specific system
        files.
     *******************************************************************************/

    // DOM-IGNORE-BEGIN
    /*******************************************************************************
    Copyright (c) 2013-2014 released Microchip Technology Inc.  All rights reserved.

    Microchip licenses to you the right to use, modify, copy and distribute
    Software only when embedded on a Microchip microcontroller or digital signal
    controller that is integrated into your product or third party product
    (pursuant to the sublicense terms in the accompanying license agreement).

    You should refer to the license agreement accompanying this Software for
    additional information regarding your rights and obligations.

    SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
    EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
    MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
    IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
    CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
    OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
    INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
    CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
    SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
    (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
     *******************************************************************************/
    // DOM-IGNORE-END


    // *****************************************************************************
    // *****************************************************************************
    // Section: Included Files 
    // *****************************************************************************
    // *****************************************************************************

    #include "app.h"

    #include "tcpip/tcpip.h"

    #include <errno.h>
    #include <sys/errno.h>

    #define SERVER_PORT 9760
    // *****************************************************************************
    // *****************************************************************************
    // Section: Global Data Definitions
    // *****************************************************************************
    // *****************************************************************************

    // *****************************************************************************
    /* Application Data

      Summary:
        Holds application data

      Description:
        This structure holds the application's data.

      Remarks:
        This structure should be initialized by the APP_Initialize function.
        
        Application strings and buffers are be defined outside this structure.
     */

    APP_DATA appData;


    // *****************************************************************************
    // *****************************************************************************
    // Section: Application Callback Functions
    // *****************************************************************************
    // *****************************************************************************

    /* TODO:  Add any necessary callback functions.
     */


    // *****************************************************************************
    // *****************************************************************************
    // Section: Application Local Functions
    // *****************************************************************************
    // *****************************************************************************

    /* TODO:  Add any necessary local functions.
     */


    // *****************************************************************************
    // *****************************************************************************
    // Section: Application Initialization and State Machine Functions
    // *****************************************************************************
    // *****************************************************************************

    /*******************************************************************************
      Function:
        void APP_Initialize ( void )

      Remarks:
        See prototype in app.h.
     */

    void APP_Initialize(void) {
        /* Place the App state machine in its initial state. */
        appData.state = APP_TCPIP_WAIT_INIT;

        /* TODO: Initialize your application's state machine and other
         * parameters.
         */
    }

    /******************************************************************************
      Function:
        void APP_Tasks ( void )

      Remarks:
        See prototype in app.h.
     */

    void APP_Tasks(void) {
        SYS_STATUS tcpipStat;
        const char *netName, *netBiosName;
        int i, nNets;
        TCPIP_NET_HANDLE netH;


        SYS_CMD_READY_TO_READ();
        switch (appData.state) {
            case APP_TCPIP_WAIT_INIT:
                tcpipStat = TCPIP_STACK_Status(sysObj.tcpip);
                if (tcpipStat < 0) { // some error occurred
                    SYS_CONSOLE_MESSAGE(" APP: TCP/IP stack initialization failed!\r\n");
                    appData.state = APP_TCPIP_ERROR;
                } else if (tcpipStat == SYS_STATUS_READY) {
                    // now that the stack is ready we can check the 
                    // available interfaces
                    nNets = TCPIP_STACK_NumberOfNetworksGet();

                    for (i = 0; i < nNets; i++) {

                        netH = TCPIP_STACK_IndexToNet(i);
                        netName = TCPIP_STACK_NetNameGet(netH);
                        netBiosName = TCPIP_STACK_NetBIOSName(netH);

    #if defined(TCPIP_STACK_USE_NBNS)
                        SYS_CONSOLE_PRINT("    Interface %s on host %s - NBNS enabled\r\n", netName, netBiosName);
    #else
                        SYS_CONSOLE_PRINT("    Interface %s on host %s - NBNS disabled\r\n", netName, netBiosName);
    #endif  // defined(TCPIP_STACK_USE_NBNS)

                    }

                    appData.state = APP_TCPIP_WAIT_FOR_IP;
                }

                break;

            case APP_TCPIP_WAIT_FOR_IP:
                nNets = TCPIP_STACK_NumberOfNetworksGet();
                for (i = 0; i < nNets; i++) {
                    netH = TCPIP_STACK_IndexToNet(i);
                    if (!TCPIP_STACK_NetIsReady(netH)) {
                        return; // interface not ready yet!
                    }
                    IPV4_ADDR           ipAddr;
                    ipAddr.Val = TCPIP_STACK_NetAddress(netH);
                    SYS_CONSOLE_MESSAGE(TCPIP_STACK_NetNameGet(netH));
                    SYS_CONSOLE_MESSAGE(" IP Address: ");
                    SYS_CONSOLE_PRINT("%d.%d.%d.%d \r\n", ipAddr.v[0], ipAddr.v[1], ipAddr.v[2], ipAddr.v[3]);
                }
                // all interfaces ready. Could start transactions!!!
                appData.state = APP_BSD_INIT;
                //... etc.
                break;
            case APP_BSD_INIT:
            {
                // Initialize all client socket handles so that we don't process
                // them in the BSD_OPERATION state
                for (i = 0; i < MAX_CLIENT; i++)
                    appData.ClientSock[i] = INVALID_SOCKET;

                appData.state = APP_BSD_CREATE_SOCKET;

            }
                break;

            case APP_BSD_CREATE_SOCKET:
            {
                // Create a socket for this server to listen and accept connections on
                SOCKET tcpSkt = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
                if (tcpSkt == INVALID_SOCKET)
                    return;
                appData.bsdServerSocket = (SOCKET) tcpSkt;

                appData.state = APP_BSD_BIND;
            }
                break;

            case APP_BSD_BIND:
            {
                // Bind socket to a local port
                struct sockaddr_in addr;
                int addrlen = sizeof (struct sockaddr_in);
                addr.sin_port = SERVER_PORT;
                addr.sin_addr.S_un.S_addr = IP_ADDR_ANY;
                if (bind(appData.bsdServerSocket, (struct sockaddr*) &addr, addrlen) == SOCKET_ERROR)
                    return;

                appData.state = APP_BSD_LISTEN;
                // No break needed
            }
                break;

            case APP_BSD_LISTEN:
            {
                if (listen(appData.bsdServerSocket, MAX_CLIENT) == 0) {
                    appData.state = APP_BSD_OPERATION;
                    SYS_CONSOLE_PRINT("Waiting for Client Connection on port: %d\r\n", SERVER_PORT);
                }
            }
                break;
            case APP_BSD_OPERATION:
            {
                int length;
                struct sockaddr_in addRemote;
                int addrlen = sizeof (struct sockaddr_in);
                char rr['A'];

                for (i = 0; i < MAX_CLIENT; i++) {
                    // Accept any pending connection requests, assuming we have a place to store the socket descriptor
                    if (appData.ClientSock[i] == INVALID_SOCKET)
                        appData.ClientSock[i] = accept(appData.bsdServerSocket, (struct sockaddr*) &addRemote, &addrlen);

                    // If this socket is not connected then no need to process anything
                    if (appData.ClientSock[i] == INVALID_SOCKET)
                        continue;

                    // For all connected sockets, receive and send back the data
                    length = recv(appData.ClientSock[i], rr, sizeof (rr), 0);

                    if (length > 0) {
                        rr[length] = '\0';
                        send(appData.ClientSock[i], rr, strlen(rr), 0);
                    } else if (length == 0 || errno != EWOULDBLOCK) {
                        closesocket(appData.ClientSock[i]);
                        appData.ClientSock[i] = INVALID_SOCKET;
                    }
                    // else just wait for some more data
                }
            }
                break;
            default:
                break;
        }
    }
    /*******************************************************************************
     End of File
     */

     
    Where there is the send! he sends the variable rr
    Why do not I see anything in Wireshark and why on the console of the execution of my client code of my Raspberry I do not visualize anything too?
    #7
    KokuH
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2018/05/07 08:45:14
    • Location: France
    • Status: offline
    Re: Create an Ethernet project with MPLAB Harmony that works 2018/09/12 01:47:12 (permalink)
    0
    Hello,

    I think the code is not fully loaded! in fact, on my PIC32 ESK card there is a DEBUG LED which blinks when the program is loading, then stops when the program is fully loaded, for my part, when I load a simple program like to light an LED, the program will load and the DEBUG LED will stop blinking when it is fully charged, but when I load the berkeley_tcp_server.X program, it starts to load, the LED flashes and then freezes and stays on! so I think the code is not fully loaded! Is this a hardware problem?

    Thank you
    #8
    Jump to:
    © 2021 APG vNext Commercial Version 4.5