This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM2432: Profinet LWIP and TFTP

Part Number: AM2432


Tool/software:

Hi,

I am using AM2432 with Profinet from the Industrial SDK 09.02.00.24.

I am porting code implemented on an AM2432 project that uses EthernetIP on my project on a AM2432 that uses Profinet.
The code creates a TFTP server, using the SDK source file inside mcu_plus_sdk/source/networking/lwip/lwip-stack/src/apps/tftp/tftp.c.
On the project that uses EthernetIP everything works correctly, while on the project that uses Profinet I get no response at all.
I noticed that when calling the function tftp_init_common in the SDK source tftp.c, in the EthernetIP project I can follow the execution of the udp functions (e. g. udp_new_ip_typeudp_bind, ...) with Step Into, that shows the source code implemented in mcu_plus_sdk/source/networking/lwip/lwip-stack/src/core/udp.c and declared in mcu_plus_sdk/source/networking/lwip/lwip-stack/src/include/lwip/udp.h, while in the Profinet project I can see that the functions are declared in the same file of EthernetIP but it seems that I can't see the source code where they are implemented.

In any case, on the Profinet project I still get no error message when I run the same functions and the same code, but when i send the TFTP request the module does not respond.

Are Profinet and EthernetIP using the same LWIP source code? What can I do to better understand my problem?

Thank you,

Best Regards,

Andrea

  • Hi Andrea,

    thanks for your inquiry.

    Yes Profinet and EthernetIP use the same LWIP source code but each of them builds it's own LWIP lib based on it's specific requirements and configuration.

    Nevertheless, you should be able to debug the source code of LWIP from a Profinet project.

    - Can you try to set a break point on some basic LWIP functions (e.g. ethernet_input) and see if the debugger stops there and shows the source code? You might need to locate the source file for CCS so it can find it.

    - Would you be able to share the part of your example code where the problem is happening? I can try to debug it on my side as well.

    Kind regards,
    Kamil 

  • Hi Kamil,

    thank you for your response.
    I tried to set a breakpoint on the function tcpip_init, and indeed the execution stops there. But to set it I had to look for where the function was in memory with the Disassembly tool and set the breakpoint at the memory address I found. In this way I can't see the source code. I then saw that this function is implemented in mcu_plus_sdk/source/networking/lwip/lwip-stack/src/api/tcpip.c, I moved it in CCS and tried to set a breakpoint on the function but CCS says there is no code associated with the lines where the function is implemented. Am I doing something wrong?

    I am attaching the source code (I have removed some specific parts of our application but the affected parts are there):

    #include "lwip/tcpip.h"
    #include "lwip/apps/tftp_common.h"
    #include "lwip/apps/tftp_server.h"
    #include "string.h"
    
    typedef struct{
        const char* fname;
    }tTFTPServerFileManager;
    
    static struct tftp_context ctx;
    
    static tTFTPServerFileManager TFTPServerManager;
    
    static void TFTPServer_file_closeClbk(void* handle)
    {
        memset(&TFTPServerManager, 0x00, sizeof(TFTPServerManager));
    }
    
    static void TFTPServer_file_errorClbk(void* handle, int err, const char* msg, int size)
    {
    	return;
    }
    
    static void *TFTPServer_file_openClbk(const char* fname, const char* mode, u8_t write)
    {
        void *ptr = NULL;
    
        TFTPServerManager.fname = fname;
    
        ptr = &TFTPServerManager;
    
        return ptr;
    }
    
    static int TFTPServer_file_readClbk(void* handle, void* buf, int bytes)
    {
        return 0;
    }
    
    static int TFTPServer_file_writeClbk(void* handle, struct pbuf* p)
    {
    	DebugP_log("TFTP Write request\r\n");
    }
    
    static void TFTPServer_start(void *ptr)
    {
        struct tftp_context *arg = (struct tftp_context *)ptr;
    
        arg->close = TFTPServer_file_closeClbk;
        arg->error = TFTPServer_file_errorClbk;
        arg->open = TFTPServer_file_openClbk;
        arg->read = TFTPServer_file_readClbk;
        arg->write = TFTPServer_file_writeClbk;
    
        tftp_init_server(ptr);
    }
    
    static void TFTPServer_stop(void *ptr)
    {
        tftp_cleanup();
    }
    
    void TFTPServer_run(void)
    {
        tcpip_callback(TFTPServer_start, (void *)&ctx);
    }
    
    void TFTPServer_close(void)
    {
        tcpip_callback(TFTPServer_stop, NULL);
    }
    

    <?xml version="1.0" encoding="UTF-8"?>
    <projectSpec>
        <applicability>
            <when>
                <context
                    deviceFamily="ARM"
                    deviceId="Cortex R.AM2434_ALV"
                />
            </when>
        </applicability>
    
        <project
            title="Profinet"
            name = "profinet_am243x-titan-icss-emac_r5fss0-0_freertos_ti-arm-clang"
            products="sysconfig;com.ti.INDUSTRIAL_COMMUNICATIONS_SDK_AM243X"
            configurations="
                Debug,
                Release,
            "
            toolChain="TICLANG"
            cgtVersion="3.2.2.LTS"
            device="Cortex R.AM2434_ALV"
            deviceCore="MAIN_PULSAR_Cortex_R5_0_0"
            ignoreDefaultDeviceSettings="true"
            ignoreDefaultCCSSettings="true"
            endianness="little"
            outputFormat="ELF"
    	outputType="executable"
    
            compilerBuildOptions="
                -I${CG_TOOL_ROOT}/include/c
                -I${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source
    			-I${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/industrial_comms/common/inc
                -I${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/industrial_comms/profinet_device/stack/inc
                -I${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/industrial_comms/profinet_device/stack/inc/ext
                -I${MCU_PLUS_SDK_PATH}/source/kernel/freertos/FreeRTOS-Kernel/include
                -I${MCU_PLUS_SDK_PATH}/source/kernel/freertos/portable/TI_ARM_CLANG/ARM_CR5F
                -I${MCU_PLUS_SDK_PATH}/source/kernel/freertos/config/am243x/r5f
    			-I${MCU_PLUS_SDK_PATH}/source/networking/lwip/lwip-stack/src/include
                -I${MCU_PLUS_SDK_PATH}/source/networking/lwip/lwip-port/include
                -I${MCU_PLUS_SDK_PATH}/source/networking/lwip/lwip-port/freertos/include
                -I${MCU_PLUS_SDK_PATH}/source
    	        -I${PROJECT_SRC_DIR}
                -mcpu=cortex-r5
                -mfloat-abi=hard
                -mfpu=vfpv3-d16
                -mthumb
                -Wall
                -Werror
                -g
                -Wno-gnu-variable-sized-type-not-at-end
                -Wno-unused-function
    			-mllvm -align-all-functions=2
                -DSOC_AM243X
    			-DSOC_AM2432
                -DOSAL_FREERTOS
                -DINCLUDE_MDIO_MANUAL_MODE_WORKAROUND
    		    -DIPC_CLIENT
            "
            linkerBuildOptions="
    		    -i${COMMON_SRC_DIR}
    		    -i${BOOTLOADER_SRC_DIR}
                -i${MCU_PLUS_SDK_PATH}/source/kernel/freertos/lib
                -i${MCU_PLUS_SDK_PATH}/source/drivers/lib
    	        -i${MCU_PLUS_SDK_PATH}/source/board/lib
    			-i${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/networking/icss_timesync/lib
    	        -i${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/networking/icss_emac/lib
    	        -i${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/industrial_comms/profinet_device/stack/lib
                -i${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/industrial_comms/profinet_device/stack/lib/lwip
                -i${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/source/industrial_comms/profinet_device/stack/lib/patch
                -i${CG_TOOL_ROOT}/lib
                -m=profinet.${ConfigName}.map
                --diag_suppress=10063
                --ram_model
                --reread_libs
    			--use_memcpy=fast
                --use_memset=fast
            "
    
    		preBuildStep=""
    		postBuildStep="$(MAKE) -C ${CCS_PROJECT_DIR} -f makefile_ccs_bootimage_gen OUTNAME=${BuildArtifactFileBaseName} PROFILE=${ConfigName} INDUSTRIAL_COMMUNICATIONS_SDK_PATH=${INDUSTRIAL_COMMUNICATIONS_SDK_PATH} CG_TOOL_ROOT=${CG_TOOL_ROOT} CCS_INSTALL_DIR=${CCS_INSTALL_DIR} CCS_IDE_MODE=${CCS_IDE_MODE}"
    		cleanTarget="clean"
    
            enableSysConfigTool="true"
            sysConfigBuildOptions="
                --context r5fss0-0 --part ALV --package ALV
            "
    
            description="Profinet">
    
            <configuration name="Debug"
                compilerBuildOptions="
                    -D_DEBUG_=1
                "
                linkerBuildOptions="
                    -lfreertos.am243x.r5f.ti-arm-clang.debug.lib
                    -ldrivers.am243x.r5f.ti-arm-clang.debug.lib
    		        -lboard.am243x.r5f.ti-arm-clang.debug.lib
    		        -licss_emac.am243x.r5f.ti-arm-clang.debug.lib
    				-lkunbusapi_mii.am243x-evm.r5f.ti-arm-clang.release.lib
                    -lprofinetiodevice_mii.am243x-evm.r5f.ti-arm-clang.release.lib
                    -llwipallapps.am243x-evm.r5f.ti-arm-clang.release.lib
                    -llwipcore.am243x-evm.r5f.ti-arm-clang.release.lib
                    -lprofinet_device_irt_mii_icss_fwhal.am243x.r5f.ti-arm-clang.release.lib
    		        -llibc.a
    		        -llibsysbm.a
                "
            ></configuration>
            <configuration name="Release"
                compilerBuildOptions="
                    -Os
                "
                linkerBuildOptions="
                    -lfreertos.am243x.r5f.ti-arm-clang.release.lib
                    -ldrivers.am243x.r5f.ti-arm-clang.release.lib
                    -lboard.am243x.r5f.ti-arm-clang.release.lib
    		        -licss_emac.am243x.r5f.ti-arm-clang.release.lib
    		        -lkunbusapi_mii.am243x-evm.r5f.ti-arm-clang.release.lib
                    -lprofinetiodevice_mii.am243x-evm.r5f.ti-arm-clang.release.lib
                    -llwipallapps.am243x-evm.r5f.ti-arm-clang.release.lib
                    -llwipcore.am243x-evm.r5f.ti-arm-clang.release.lib
                    -lprofinet_device_irt_mii_icss_fwhal.am243x.r5f.ti-arm-clang.release.lib
                    -llibc.a
    		        -llibsysbm.a
                "
            ></configuration>
    		<pathVariable name="INDUSTRIAL_COMMUNICATIONS_SDK_PATH" path="../../../am243x-mcu-plus-sdk" scope="project" />
            <pathVariable name="MCU_PLUS_SDK_PATH" path="${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/mcu_plus_sdk" scope="project" />
            <pathVariable name="PROJECT_SRC_DIR" path="." scope="project" />
    		<pathVariable name="LWIP_PATH" path="${INDUSTRIAL_COMMUNICATIONS_SDK_PATH}/mcu_plus_sdk/source/networking/lwip/lwip-stack" scope="project" />
    	<file path="../main.c" openOnCreation="false" excludeFromBuild="false" action="link">
    	</file>
    	<file path="${LWIP_PATH}/src/apps/tftp/tftp.c" openOnCreation="false" targetDirectory="lwip-stack" excludeFromBuild="false" action="link">
        </file>
    	<file path="../TFTPServer.c" openOnCreation="false" excludeFromBuild="false" action="link">
    	</file>
        <file path="../linker.cmd" openOnCreation="false" excludeFromBuild="false" action="link">
        </file>
        <file path="profinet_ICSS_EMAC.syscfg" openOnCreation="false" excludeFromBuild="false" action="link">
        </file>
        <file path="../syscfg_c.rov.xs" openOnCreation="false" excludeFromBuild="false" action="copy">
        </file>
        <file path="../makefile_ccs_bootimage_gen" openOnCreation="false" excludeFromBuild="false" action="copy">
        </file>
        </project>
    </projectSpec>
    

    The main task calls TFTPServer_run and apparently it works without errors, I expect that after making the TFTP request (I use tftpd64) the callbacks TFTPServer_file_openClbk and TFTPServer_file_writeClbk are called as in the EthernetIP project, but this doesn't happen.

    Let me know if more details are needed.

    Thank you,

    Kind Regards,

    Andrea

  • Hi,

    I suspect that I cannot see the LWIP source codes because by default they are compiled in release mode for Profinet (even though I compile the SDK with gmake -s libs PROFILE=debug). In fact in the EthernetIP project the libraries are compiled in both release and debug mode, and in its projectspec the debug ones are specified.

    Is there any way I can compile LWIP libraries in debug mode also for Profinet?

    Thank you,

    Kind Regards,

    Andrea

  • Hi, are there any updates?

    Thank you,

    Best regards,

    Andrea

  • Hi Andrea,

    Sorry for the delay... We had some high priority tasks to deal with... I will look into this and give you feedback tomorrow.

    Thanks.
    Kind regards,
    Kamil

  • Hi Andrea,

    I took a look at this issue and it seems to be related to the SDK you're using... Would it be possible for you to upgrade to the newest SDK? Some improvements have been done with regards to your inquiry and you should be able to build and debug LWIP code with no problems.

    Thanks.
    Kind regards,
    Kamil

  • Hi Kamil,

    thank you for your response.

    Now by switching to the new version of Industrial SDK 11 I can correctly debug also the LWIP part, I will update you for more questions next week.

    Thank you,

    Kind Regards,

    Andrea

  • Hi Kamil,

    I did a test with the new SDK but the problem of no response after a TFTP requests with Profinet remains (although I can now follow the execution with LWIP sources).

    In my Profinet project I added a breakpoint on ethernet_input(), when I make a TFTP request two messages arrive, but in both times they are an ARP type message that is handled by the function etharp_input(), and then there are no more. 

    I did the same test with my EthernetIP, and indeed here with a breakpoint I can see when the TFTP packet is received:

    I attached Wireshark trace with Profinet and with EthernetIP,  in which:
    - TFTP Client (my laptop with Tftpd64) has 192.168.1.22
    - TFTP Server (my device AM2432 Profinet/EthernetIP) has 192.168.1.50
    - another device on the same network has 192.168.1.112
    - the gateway has 192.168.1.1

    (I temporary uploaded them here because I can't attach them here)

    What can I do to better understand the problem?

    Thank you,

    Kind Regards,

    Andrea

  • Hi, are there any updates?

    Thank you,

    Best regards,

    Andrea

  • Hi Andrea,

    Thanks for your patience during this stressful period.

    I just started looking into this issue. It looks like PROFINET stack is dropping TFTP frames. I will figure this out in details and give you a response on Monday.

    Kind regards,
    Kamil

  • Hi Andrea,

    I have sent you an email with a solution to your issue. Please test it and send me your feedback.

    Thanks.
    Kind regards,
    Kamil

  • Hi Kamil, 

    I tried the solution you provided, but I noticed that now TFTP requests are explicitly rejected by the Profinet stack (while with official library they were just ignored). Am I doing something wrong?

    Thank you,

    Kind Regards,

    Andrea

  • Hi Andrea,

    the stack, by default, should not reject your request.
    Would you please share Wireshark traces so we can look into this issue further?

    Thanks.
    Kind regards,
    Kamil