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.

EK-TM4C1294XL: How to flash code to an EK-TM4C1294XL (launchpad) using Ethernet for Ethernet firmware upgrade functionality?

Part Number: EK-TM4C1294XL

Hi,

I tried using the boot emac flash example to flash code to a TM4C1294 Launchpad to flash code using Ethernet.

I have used the same lwipopts file as in the enet)lwip example and used static ip for the bootloader example.

I have checked that the assigned static ip is actually assigned to the board by putting breakpoints in the lwipinit function present in the example code. However when I try to now flash my application program using ethernet, I am getting an error , "problem starting the BOOTP server".

What am I doing wrong?

Regards,

Apoorv

  • Hi Apoorv,
    Did it work if you change to DHCP?
  • Hi Charles.

    Thanks for the quick reply.

    I tried hosting a DHCP server, but no IP is assigned to the board for the boot emac flash example program. On the contrary, when I try to run the enet_lwip example with the same changes in lwipopts.h and lwipinit function, an IP address is assigned to the board by the dhcp server.
    That is the reason I switched to a static ip.

    Regards,
    Apoorv
  • Hi Apoorv,
    The bootloader code has to be small and efficient. Hence it does not have DHCP client implementation that gets the IP address. Instead it has a very basic BOOTP (older version of DHCP) implementation, that can only receive BOOTP packets.

    My earlier question to you whether you had it working using DHCP was based on your statement that you integrated the lwipopts file configured for static address into the boot_emac_flash example. What if you configure the lwipopts for DHCH and will it work? The boot_emac_flash by itself without any modification will not send DHCP discover/request packets to the DHCP server.
  • Hi, Charles,

    Do I need to run a bootp server on my laptop using some software (any utility for windows 10)?

    I have pasted the code for lwipopts.h which I have used. Also which file can I debug to see the bootp packets? Also, how to know which IP has been assigned ? 

    //*****************************************************************************
    //
    // lwipopts.h - Configuration file for lwIP
    //
    // Copyright (c) 2013-2017 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    //
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    //
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    //
    // This is part of revision 2.1.4.178 of the EK-TM4C1294XL Firmware Package.
    //
    //*****************************************************************************
    //
    // NOTE:  This file has been derived from the lwIP/src/include/lwip/opt.h
    // header file.
    //
    // For additional details, refer to the original "opt.h" file, and lwIP
    // documentation.
    //
    //*****************************************************************************
    
    #ifndef __LWIPOPTS_H__
    #define __LWIPOPTS_H__
    
    //*****************************************************************************
    //
    // ---------- Stellaris / lwIP Port Options ----------
    //
    //*****************************************************************************
    #define HOST_TMR_INTERVAL               100         // default is 0
    //#define DHCP_EXPIRE_TIMER_MSECS         (60 * 1000)
    //#define LWIP_HTTPD_SSI                  1
    //#define LWIP_HTTPD_CGI                  1
    #define LWIP_HTTPD_DYNAMIC_HEADERS      1
    //#define HTTPD_DEBUG                     LWIP_DBG_ON
    #if !defined(EMAC_PHY_IS_EXT_MII) && !defined(EMAC_PHY_IS_EXT_RMII)
    #define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN |      \
                             EMAC_PHY_AN_100B_T_FULL_DUPLEX)
    #define PHY_PHYS_ADDR      0
    #endif
    #if defined(EMAC_PHY_IS_EXT_MII)
    #define EMAC_PHY_CONFIG  EMAC_PHY_TYPE_EXTERNAL_MII
    #define PHY_PHYS_ADDR      1
    #endif
    #if defined(EMAC_PHY_IS_EXT_RMII)
    #define EMAC_PHY_CONFIG  EMAC_PHY_TYPE_EXTERNAL_RMII
    #define PHY_PHYS_ADDR      1
    #endif
    #define NUM_TX_DESCRIPTORS 24
    #define NUM_RX_DESCRIPTORS 8
    
    //*****************************************************************************
    //
    // ---------- Platform specific locking ----------
    //
    //*****************************************************************************
    #define SYS_LIGHTWEIGHT_PROT            1           // default is 0
    #define NO_SYS                          1           // default is 0
    //#define MEMCPY(dst,src,len)             memcpy(dst,src,len)
    //#define SMEMCPY(dst,src,len)            memcpy(dst,src,len)
    
    //*****************************************************************************
    //
    // ---------- Memory options ----------
    //
    //*****************************************************************************
    //#define MEM_LIBC_MALLOC                 0
    #define MEM_ALIGNMENT                     4
    #define MEM_SIZE                          (64 * 1024)
    //#define MEMP_OVERFLOW_CHECK             0
    //#define MEMP_SANITY_CHECK               0
    //#define MEM_USE_POOLS                   0
    //#define MEMP_USE_CUSTOM_POOLS           0
    
    //*****************************************************************************
    //
    // ---------- Internal Memory Pool Sizes ----------
    //
    //*****************************************************************************
    #define MEMP_NUM_PBUF                     48    // Default 16
    //#define MEMP_NUM_RAW_PCB                4
    //#define MEMP_NUM_UDP_PCB                4
    #define MEMP_NUM_TCP_PCB                  16    // Default 5
    //#define MEMP_NUM_TCP_PCB_LISTEN         8
    //#define MEMP_NUM_TCP_SEG                16
    //#define MEMP_NUM_REASSDATA              5
    //#define MEMP_NUM_ARP_QUEUE              30
    //#define MEMP_NUM_IGMP_GROUP             8
    #define MEMP_NUM_SYS_TIMEOUT              8
    //#define MEMP_NUM_NETBUF                 2
    //#define MEMP_NUM_NETCONN                4
    //#define MEMP_NUM_TCPIP_MSG_API          8
    //#define MEMP_NUM_TCPIP_MSG_INPKT        8
    #define PBUF_POOL_SIZE                    48    // Default 16
    
    //*****************************************************************************
    //
    // ---------- ARP options ----------
    //
    //*****************************************************************************
    //#define LWIP_ARP                        1
    //#define ARP_TABLE_SIZE                  10
    //#define ARP_QUEUEING                    1
    //#define ETHARP_TRUST_IP_MAC             1
    
    //*****************************************************************************
    //
    // ---------- IP options ----------
    //
    //*****************************************************************************
    //#define IP_FORWARD                      0
    //#define IP_OPTIONS_ALLOWED              1
    #define IP_REASSEMBLY                   0           // default is 1
    #define IP_FRAG                         0           // default is 1
    //#define IP_REASS_MAXAGE                 3
    //#define IP_REASS_MAX_PBUFS              10
    //#define IP_FRAG_USES_STATIC_BUF         1
    //#define IP_FRAG_MAX_MTU                 1500
    //#define IP_DEFAULT_TTL                  255
    
    //*****************************************************************************
    //
    // ---------- ICMP options ----------
    //
    //*****************************************************************************
    //#define LWIP_ICMP                       1
    //#define ICMP_TTL                       (IP_DEFAULT_TTL)
    
    //*****************************************************************************
    //
    // ---------- RAW options ----------
    //
    //*****************************************************************************
    //#define LWIP_RAW                        1
    //#define RAW_TTL                        (IP_DEFAULT_TTL)
    
    //*****************************************************************************
    //
    // ---------- DHCP options ----------
    //
    //*****************************************************************************
    #define LWIP_DHCP                       1           // default is 0
    //#define DHCP_DOES_ARP_CHECK             ((LWIP_DHCP) && (LWIP_ARP))
    
    //*****************************************************************************
    //
    // ---------- UPNP options ----------
    //
    //*****************************************************************************
    //#define LWIP_UPNP                       0
    
    //*****************************************************************************
    //
    // ---------- PTPD options ----------
    //
    //*****************************************************************************
    //#define LWIP_PTPD                       0
    
    //*****************************************************************************
    //
    // ---------- AUTOIP options ----------
    //
    //*****************************************************************************
    #define LWIP_AUTOIP                     1           // default is 0
    #define LWIP_DHCP_AUTOIP_COOP           ((LWIP_DHCP) && (LWIP_AUTOIP))
                                                        // default is 0
    #define LWIP_DHCP_AUTOIP_COOP_TRIES     5           // default is 9
    
    //*****************************************************************************
    //
    // ---------- SNMP options ----------
    //
    //*****************************************************************************
    //#define LWIP_SNMP                       0
    //#define SNMP_CONCURRENT_REQUESTS        1
    //#define SNMP_TRAP_DESTINATIONS          1
    //#define SNMP_PRIVATE_MIB                0
    //#define SNMP_SAFE_REQUESTS              1
    
    //*****************************************************************************
    //
    // ---------- IGMP options ----------
    //
    //*****************************************************************************
    //#define LWIP_IGMP                       0
    
    //*****************************************************************************
    //
    // ---------- DNS options -----------
    //
    //*****************************************************************************
    //#define LWIP_DNS                        0
    //#define DNS_TABLE_SIZE                  4
    //#define DNS_MAX_NAME_LENGTH             256
    //#define DNS_MAX_SERVERS                 2
    //#define DNS_DOES_NAME_CHECK             1
    //#define DNS_USES_STATIC_BUF             1
    //#define DNS_MSG_SIZE                    512
    
    //*****************************************************************************
    //
    // ---------- UDP options ----------
    //
    //*****************************************************************************
    //#define LWIP_UDP                        1
    //#define LWIP_UDPLITE                    0
    //#define UDP_TTL                         (IP_DEFAULT_TTL)
    
    //*****************************************************************************
    //
    // ---------- TCP options ----------
    //
    //*****************************************************************************
    #define LWIP_TCP                        1
    //#define TCP_TTL                         (IP_DEFAULT_TTL)
    #define TCP_WND                         4096   // default is 2048
    //#define TCP_MAXRTX                      12
    //#define TCP_SYNMAXRTX                   6
    //#define TCP_QUEUE_OOSEQ                 1
    #define TCP_MSS                        1500        // default is 128
    //#define TCP_CALCULATE_EFF_SEND_MSS      1
    #define TCP_SND_BUF                     (4 * TCP_MSS)
                                                        // default is 256, was 6 *
    //#define TCP_SND_QUEUELEN                (4 * (TCP_SND_BUF/TCP_MSS))
    //#define TCP_SNDLOWAT                    (TCP_SND_BUF/2)
    //#define TCP_LISTEN_BACKLOG              0
    //#define TCP_DEFAULT_LISTEN_BACKLOG      0xff
    
    //*****************************************************************************
    //
    // ---------- API options ----------
    //
    //*****************************************************************************
    //#define LWIP_EVENT_API                  0
    //#define LWIP_CALLBACK_API               1
    
    //*****************************************************************************
    //
    // ---------- Pbuf options ----------
    //
    //*****************************************************************************
    #define PBUF_LINK_HLEN                  16          // default is 14
    #define PBUF_POOL_BUFSIZE               512
                                  // PBUF_POOL_BUFSIZE default is
                                  // LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)
    #define ETH_PAD_SIZE                    0           // default is 0
    
    //*****************************************************************************
    //
    // ---------- Network Interfaces options ----------
    //
    //*****************************************************************************
    //#define LWIP_NETIF_HOSTNAME             0
    //#define LWIP_NETIF_API                  0
    //#define LWIP_NETIF_STATUS_CALLBACK      0
    //#define LWIP_NETIF_LINK_CALLBACK        0
    //#define LWIP_NETIF_HWADDRHINT           0
    
    //*****************************************************************************
    //
    // ---------- LOOPIF options ----------
    //
    //*****************************************************************************
    //#define LWIP_HAVE_LOOPIF                0
    //#define LWIP_LOOPIF_MULTITHREADING      1
    
    //*****************************************************************************
    //
    // ---------- Thread options ----------
    //
    //*****************************************************************************
    //#define TCPIP_THREAD_NAME              "tcpip_thread"
    //#define TCPIP_THREAD_STACKSIZE          0
    //#define TCPIP_THREAD_PRIO               1
    //#define TCPIP_MBOX_SIZE                 0
    //#define SLIPIF_THREAD_NAME             "slipif_loop"
    //#define SLIPIF_THREAD_STACKSIZE         0
    //#define SLIPIF_THREAD_PRIO              1
    //#define PPP_THREAD_NAME                "pppMain"
    //#define PPP_THREAD_STACKSIZE            0
    //#define PPP_THREAD_PRIO                 1
    //#define DEFAULT_THREAD_NAME            "lwIP"
    //#define DEFAULT_THREAD_STACKSIZE        0
    //#define DEFAULT_THREAD_PRIO             1
    //#define DEFAULT_RAW_RECVMBOX_SIZE       0
    //#define DEFAULT_UDP_RECVMBOX_SIZE       0
    //#define DEFAULT_TCP_RECVMBOX_SIZE       0
    //#define DEFAULT_ACCEPTMBOX_SIZE         0
    
    //*****************************************************************************
    //
    // ---------- Sequential layer options ----------
    //
    //*****************************************************************************
    //#define LWIP_TCPIP_CORE_LOCKING         0
    #define LWIP_NETCONN                    0           // default is 1
    
    //*****************************************************************************
    //
    // ---------- Socket Options ----------
    //
    //*****************************************************************************
    #define LWIP_SOCKET                     0           // default is 1
    //#define LWIP_COMPAT_SOCKETS             1
    //#define LWIP_POSIX_SOCKETS_IO_NAMES     1
    //#define LWIP_TCP_KEEPALIVE              0
    //#define LWIP_SO_RCVTIMEO                0
    //#define LWIP_SO_RCVBUF                  0
    //#define SO_REUSE                        0
    
    //*****************************************************************************
    //
    // ---------- Statistics options ----------
    //
    //*****************************************************************************
    //#define LWIP_STATS                      1
    //#define LWIP_STATS_DISPLAY              0
    //#define LINK_STATS                      1
    //#define ETHARP_STATS                    (LWIP_ARP)
    //#define IP_STATS                        1
    //#define IPFRAG_STATS                    (IP_REASSEMBLY || IP_FRAG)
    //#define ICMP_STATS                      1
    //#define IGMP_STATS                      (LWIP_IGMP)
    //#define UDP_STATS                       (LWIP_UDP)
    //#define TCP_STATS                       (LWIP_TCP)
    //#define MEM_STATS                       1
    //#define MEMP_STATS                      1
    //#define SYS_STATS                       1
    
    //*****************************************************************************
    //
    // ---------- PPP options ----------
    //
    //*****************************************************************************
    //#define PPP_SUPPORT                     0
    //#define PPPOE_SUPPORT                   0
    //#define PPPOS_SUPPORT                   PPP_SUPPORT
    
    #if PPP_SUPPORT
    //#define NUM_PPP                         1
    //#define PAP_SUPPORT                     0
    //#define CHAP_SUPPORT                    0
    //#define MSCHAP_SUPPORT                  0
    //#define CBCP_SUPPORT                    0
    //#define CCP_SUPPORT                     0
    //#define VJ_SUPPORT                      0
    //#define MD5_SUPPORT                     0
    //#define FSM_DEFTIMEOUT                  6
    //#define FSM_DEFMAXTERMREQS              2
    //#define FSM_DEFMAXCONFREQS              10
    //#define FSM_DEFMAXNAKLOOPS              5
    //#define UPAP_DEFTIMEOUT                 6
    //#define UPAP_DEFREQTIME                 30
    //#define CHAP_DEFTIMEOUT                 6
    //#define CHAP_DEFTRANSMITS               10
    //#define LCP_ECHOINTERVAL                0
    //#define LCP_MAXECHOFAILS                3
    //#define PPP_MAXIDLEFLAG                 100
    
    //#define PPP_MAXMTU                      1500
    //#define PPP_DEFMRU                      296
    #endif
    
    //*****************************************************************************
    //
    // ---------- checksum options ----------
    //
    //*****************************************************************************
    #define CHECKSUM_GEN_IP                 0
    #define CHECKSUM_GEN_ICMP               0
    #define CHECKSUM_GEN_UDP                0
    #define CHECKSUM_GEN_TCP                0
    #define CHECKSUM_CHECK_IP               0
    #define CHECKSUM_CHECK_UDP              0
    #define CHECKSUM_CHECK_TCP              0
    
    //*****************************************************************************
    //
    // ---------- Debugging options ----------
    //
    //*****************************************************************************
    #if 0
    #define U8_F "c"
    #define S8_F "c"
    #define X8_F "x"
    #define U16_F "u"
    #define S16_F "d"
    #define X16_F "x"
    #define U32_F "u"
    #define S32_F "d"
    #define X32_F "x"
    extern void UARTprintf(const char *pcString, ...);
    #define LWIP_DEBUG
    #endif
    
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
    #define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_WARNING
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SERIOUS
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SEVERE
    
    //#define LWIP_DBG_TYPES_ON               LWIP_DBG_ON
    #define LWIP_DBG_TYPES_ON               (LWIP_DBG_ON|LWIP_DBG_TRACE|          \
                                             LWIP_DBG_STATE|LWIP_DBG_FRESH)
    
    //#define ETHARP_DEBUG                    LWIP_DBG_ON     // default is OFF
    //#define NETIF_DEBUG                     LWIP_DBG_ON     // default is OFF
    //#define PBUF_DEBUG                      LWIP_DBG_OFF
    //#define API_LIB_DEBUG                   LWIP_DBG_OFF
    //#define API_MSG_DEBUG                   LWIP_DBG_OFF
    //#define SOCKETS_DEBUG                   LWIP_DBG_OFF
    //#define ICMP_DEBUG                      LWIP_DBG_OFF
    //#define IGMP_DEBUG                      LWIP_DBG_OFF
    //#define INET_DEBUG                      LWIP_DBG_OFF
    //#define IP_DEBUG                        LWIP_DBG_ON     // default is OFF
    //#define IP_REASS_DEBUG                  LWIP_DBG_OFF
    //#define RAW_DEBUG                       LWIP_DBG_OFF
    //#define MEM_DEBUG                       LWIP_DBG_OFF
    //#define MEMP_DEBUG                      LWIP_DBG_OFF
    //#define SYS_DEBUG                       LWIP_DBG_OFF
    //#define TCP_DEBUG                       LWIP_DBG_OFF
    //#define TCP_INPUT_DEBUG                 LWIP_DBG_OFF
    //#define TCP_FR_DEBUG                    LWIP_DBG_OFF
    //#define TCP_RTO_DEBUG                   LWIP_DBG_OFF
    //#define TCP_CWND_DEBUG                  LWIP_DBG_OFF
    //#define TCP_WND_DEBUG                   LWIP_DBG_OFF
    //#define TCP_OUTPUT_DEBUG                LWIP_DBG_OFF
    //#define TCP_RST_DEBUG                   LWIP_DBG_OFF
    //#define TCP_QLEN_DEBUG                  LWIP_DBG_OFF
    //#define UDP_DEBUG                       LWIP_DBG_ON     // default is OFF
    //#define TCPIP_DEBUG                     LWIP_DBG_OFF
    //#define PPP_DEBUG                       LWIP_DBG_OFF
    //#define SLIP_DEBUG                      LWIP_DBG_OFF
    //#define DHCP_DEBUG                      LWIP_DBG_ON     // default is OFF
    //#define AUTOIP_DEBUG                    LWIP_DBG_OFF
    //#define SNMP_MSG_DEBUG                  LWIP_DBG_OFF
    //#define SNMP_MIB_DEBUG                  LWIP_DBG_OFF
    //#define DNS_DEBUG                       LWIP_DBG_OFF
    
    #endif /* __LWIPOPTS_H__ */
    

    Also in main, the code should be stuck in while(!g_bFirmwareUpdate) loop until, magic packets are sent by LM Flash programmer, but after 1 or 2 times, the code is stuck at a location 0xfffffffe. What can be the reason for this unusual behaviour?

    //*****************************************************************************
    //
    // boot_demo_emac_flash.c - Boot Loader ethernet Demo.
    //
    // Copyright (c) 2008-2017 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    // This is part of revision 2.1.4.178 of the EK-TM4C1294XL Firmware Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_sysctl.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/flash.h"
    #include "driverlib/uart.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "utils/lwiplib.h"
    #include "utils/swupdate.h"
    #include "utils/ustdlib.h"
    
    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Boot Loader ethernet Demo (boot_demo_emac_flash)</h1>
    //!
    //! An example to demonstrate the use of remote update signaling with the
    //! flash-based Ethernet boot loader.  This application configures the Ethernet
    //! controller and acquires an IP address which is displayed on the screen
    //! along with the board's MAC address.  It then listens for a ``magic packet''
    //! telling it that a firmware upgrade request is being made and, when this
    //! packet is received, transfers control into the boot loader to perform the
    //! upgrade.
    //!
    //! This application is intended for use with flash-based ethernet boot
    //! loader (boot_emac).
    //! 
    //! The link address for this application is set to 0x4000, the link address
    //! has to be multiple of the flash erase block size(16KB=0x4000).
    //! You may change this address to a 16KB boundary higher than the last
    //! address occupied by the boot loader binary as long as you also rebuild the
    //! boot loader itself after modifying its bl_config.h file to set
    //! APP_START_ADDRESS to the same value.
    //!
    //! The boot_demo_flash application can be used along with this application to
    //! easily demonstrate that the boot loader is actually updating the on-chip
    //! flash.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // The number of SysTick ticks per second.
    //
    //*****************************************************************************
    #define TICKS_PER_SECOND 100
    
    //*****************************************************************************
    //
    // A global flag used to indicate if a remote firmware update request has been
    // received.
    //
    //*****************************************************************************
    static volatile bool g_bFirmwareUpdate = false;
    
    //*****************************************************************************
    //
    // Buffers used to hold the Ethernet MAC and IP addresses for the board.
    //
    //*****************************************************************************
    #define SIZE_MAC_ADDR_BUFFER 32
    #define SIZE_IP_ADDR_BUFFER 32
    char g_pcMACAddr[SIZE_MAC_ADDR_BUFFER];
    char g_pcIPAddr[SIZE_IP_ADDR_BUFFER];
    
    //*****************************************************************************
    //
    // A global we use to update the system clock frequency
    //
    //*****************************************************************************
    volatile uint32_t g_ui32SysClockFreq;
    
    
    
    //*****************************************************************************
    //
    // The current IP address.
    //
    //*****************************************************************************
    uint32_t g_ui32IPAddress;
    
    
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line) 
    {
    }
    #endif
    
    //*****************************************************************************
    //
    // This is the handler for this SysTick interrupt.  We use this to provide the
    // required timer call to the lwIP stack.
    //
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        //
        // Call the lwIP timer.
        //
        lwIPTimer(1000 / TICKS_PER_SECOND);
    }
    
    //*****************************************************************************
    //
    // Initialize UART0 and set the appropriate communication parameters.
    //
    //*****************************************************************************
    void
    SetupForUART(void)
    {
        //
        // We need to make sure that UART0 and its associated GPIO port are
        // enabled before we pass control to the boot loader.  The serial boot
        // loader does not enable or configure these peripherals for us if we
        // enter it via its SVC vector.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Set GPIO PA0 and PA1 as UART.
        //
        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Configure the UART for 115200, n, 8, 1
        //
        ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClockFreq, 115200,
                                (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                                 UART_CONFIG_WLEN_8));
    
        //
        // Enable the UART operation.
        //
        ROM_UARTEnable(UART0_BASE);
    }
    
    //*****************************************************************************
    //
    // This function is called by the software update module whenever a remote
    // host requests to update the firmware on this board.  We set a flag that
    // will cause the main loop to exit and transfer control to the bootloader.
    //
    // IMPORTANT:
    // Note that this callback is made in interrupt context and, since it is not
    // permitted to transfer control to the boot loader from within an interrupt,
    // we can't just call SoftwareUpdateBegin() here.
    //
    //*****************************************************************************
    void SoftwareUpdateRequestCallback(void)
    {
        g_bFirmwareUpdate = true;
    }
    
    //*****************************************************************************
    //
    // Perform the initialization steps required to start up the Ethernet controller
    // and lwIP stack.
    //
    //*****************************************************************************
    void
    SetupForEthernet(void)
    {
        uint32_t ui32User0, ui32User1;
        uint8_t pui8MACAddr[6];
    
        //
        // Configure SysTick for a 100Hz interrupt.
        //
        ROM_SysTickPeriodSet(g_ui32SysClockFreq / TICKS_PER_SECOND);
        ROM_SysTickEnable();
        ROM_SysTickIntEnable();
    
        //
        // Get the MAC address from the UART0 and UART1 registers in NV ram.
        //
        ROM_FlashUserGet(&ui32User0, &ui32User1);
    
        //
        // Convert the 24/24 split MAC address from NV ram into a MAC address
        // array.
        //
        pui8MACAddr[0] = ui32User0 & 0xff;
        pui8MACAddr[1] = (ui32User0 >> 8) & 0xff;
        pui8MACAddr[2] = (ui32User0 >> 16) & 0xff;
        pui8MACAddr[3] = ui32User1 & 0xff;
        pui8MACAddr[4] = (ui32User1 >> 8) & 0xff;
        pui8MACAddr[5] = (ui32User1 >> 16) & 0xff;
    
        //
        // Format this address into the string used by the relevant widget.
        //
        usnprintf(g_pcMACAddr, SIZE_MAC_ADDR_BUFFER,
                  "MAC: %02X-%02X-%02X-%02X-%02X-%02X",
                  pui8MACAddr[0], pui8MACAddr[1], pui8MACAddr[2], pui8MACAddr[3],
                  pui8MACAddr[4], pui8MACAddr[5]);
    
        //
        // Remember that we don't have an IP address yet.
        //
        usnprintf(g_pcIPAddr, SIZE_IP_ADDR_BUFFER, "IP: Not assigned");
    
        //
        // Initialize the lwIP TCP/IP stack.
        //
        lwIPInit(g_ui32SysClockFreq, pui8MACAddr, 0, 0, 0, IPADDR_USE_DHCP);
    
    //        lwIPInit(g_ui32SysClockFreq, pui8MACAddr,
    //                 (192u<<24) | (168u<<16) | (1u<<8) | 125u,
    //                 (255u<<24) | (255u<<16) | (255u<<8) | 0,
    //                 (192u<<24) | (168u<<16) | (1u<<8) | 1,
    //                 IPADDR_USE_STATIC);
        //
        // Start the remote software update module.
        //
        SoftwareUpdateInit(SoftwareUpdateRequestCallback);
    }
    
    
    //*****************************************************************************
    //
    // Required by lwIP library to support any host-related timer functions.
    //
    //*****************************************************************************
    void
    lwIPHostTimerHandler(void)
    {
        uint32_t ui32NewIPAddress;
    
        //
        // Get the current IP address.
        //
        ui32NewIPAddress = lwIPLocalIPAddrGet();
    
        //
        // See if the IP address has changed.
        //
        if(ui32NewIPAddress != g_ui32IPAddress)
        {
            //
            // See if there is an IP address assigned.
            //
            if(ui32NewIPAddress == 0xffffffff)
            {
                //
                // Indicate that there is no link.
                //
                //            UARTprintf("Waiting for link.\n");
            }
            else if(ui32NewIPAddress == 0)
            {
                //
                // There is no IP address, so indicate that the DHCP process is
                // running.
                //
                //            UARTprintf("Waiting for IP address.\n");
            }
            else
            {
                //
                // Display the new IP address.
                //
                //            UARTprintf("IP Address: ");
                //            DisplayIPAddress(ui32NewIPAddress);
                //            UARTprintf("\nOpen a browser and enter the IP address.\n");
            }
    
            //
            // Save the new IP address.
            //
            g_ui32IPAddress = ui32NewIPAddress;
        }
    
        //
        // If there is not an IP address.
        //
        if((ui32NewIPAddress == 0) || (ui32NewIPAddress == 0xffffffff))
        {
            //
            // Do nothing and keep waiting.
            //
        }
    }
    
    //*****************************************************************************
    //
    // Enable the USB controller
    //
    //*****************************************************************************
    void
    SetupForUSB(void)
    {
        //
        // The USB boot loader takes care of all required USB initialization so,
        // if the application itself doesn't need to use the USB controller, we
        // don't actually need to enable it here.  The only requirement imposed by
        // the USB boot loader is that the system clock is running from the PLL
        // when the boot loader is entered.
        //
    }
    
    //*****************************************************************************
    //
    // A simple application demonstrating use of the boot loader,
    //
    //*****************************************************************************
    int
    main(void)
    {
    
        //
        // Enable lazy stacking for interrupt handlers.  This allows floating-point
        // instructions to be used within interrupt handlers, but at the expense of
        // extra stack usage.
        //
        ROM_FPULazyStackingEnable();
    
        //
        // Set the system clock to run at 120MHz from the PLL
        //
        g_ui32SysClockFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                 SYSCTL_OSC_MAIN |
                                                 SYSCTL_USE_PLL |
                                                 SYSCTL_CFG_VCO_480), 120000000);
    
        //
        // Initialize the peripherals that each of the boot loader flavours
        // supports.  Since this example is intended for use with any of the
        // boot loaders and we don't know which is actually in use, we cover all
        // bases and initialize for serial, Ethernet and USB use here.
        //
    //    SetupForUART();
        SetupForEthernet();
    //    SetupForUSB();
    
        //
        // Configure Port N pin 1 as output.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
        while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)));
        GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
    
        //
        // If the Switch SW1 is not pressed then blink the LED D1 at 1 Hz rate
        // On switch SW press detection exit the blinking program and jump to
        // the flash boot loader.
        //
        while(!g_bFirmwareUpdate)
        {
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x0);
            SysCtlDelay(g_ui32SysClockFreq / 6);
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1);
            SysCtlDelay(g_ui32SysClockFreq / 6);
        }
    
        //
        // Before passing control make sure that the LED is turned OFF.
        //
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x0);
        
        //
        // Pass control to whichever flavour of boot loader the board is configured
        // with.
        //
        SoftwareUpdateBegin(g_ui32SysClockFreq);
    
        //
        // The previous function never returns but we need to stick in a return
        // code here to keep the compiler from generating a warning.
        //
        return(0);
    }
    

    I also saw the contents of location 0x0 and  0x4 which are both 0xFFFFFFFF and memory locations 0x01000000 and 0x01000004 , both contain valid addresses (they contain pointers to new SP and reset) after the exexcution of bootloadre code.

     

  • Hi Apoorv,

     The PC running the LM Flash Programmer can act as the BootP server. Please note that the MAC and IP address association for BootP is done statically meaning you will need to enter them  manually. Unlike DHCP where the IP address is dynamically leased to the client for a period of time. With that said, how do you know which IP address to associate with the MAC address of your MCU? This is why before running the boot_emac_flash you need to run another TivaWare ethernet example such as enet_lwip. The enet_lwip example uses DHCP server. Once the DHCP gives the IP address, the IP address is leased for a period of time. Before the IP address is expired, you can reuse the same IP address to associate with the MCU's MAC address for the BootP server. See below image where I enter the IP address that i got by running enet_lwip and the MAC address on my LaunchPad.

  • Hi Charles,

    Thanks for the reply.

    What is the difference between the example programs boot_emac_flash and boot_demo_emac_flash? (Is it the only difference that 1 example uses uip while other uses lwip?)

    I did exactly what you had suggested.

    I got the ip as 192.168.1.1 assigned by the DHCP server for enet_lwip example.

    Then I configured the same ip and MAC address in LM flash programmer utility. Then, I tried to program both example programs bin image (boot_emac_flash and boot_demo_emac_flash) but in both the cases, I had the same error from LM Flash Programmer : Problem starting the bootp server. What am I doing wrong here?

    Regards,

    Apoorv 

  • The boot_emac_flash is the bootloader. The boot_demo_emac_flash is the application. You must first load the boot_emac_flash into the MCU using the JTAG interface. Once it is loaded you run the boot_emac_flash so it will send out the BootP request. At the same time you configure the LM flash programmer (acting as both the BootP server and TFTF server) to transfer the application boot_demo_emac_flash via the ethernet interface.
  • Hi Charles,

    Thanks for the reply.

    Actually I shifted to the serial bootloader (example program boot_serial) and then flashed the application which I had designed successfully with some changes . The code runs successfully (both on hardware reset and flashing new code) but sometimes it gets stuck on memory location 0xfffffffe.

    Also, once I got an error in the newly modified  .cmd file : program will not fit into available memory. This is the code which I wrote for the cmd file

    /******************************************************************************
     *
     * Default Linker Command file for the Texas Instruments TM4C129ENCPDT
     *
     * This is derived from revision 15071 of the TivaWare Library.
     *
     *****************************************************************************/
    
    --retain=g_pfnVectors
    
    MEMORY
    {
        FLASH (RX) : origin = 0x00004000, length = 0x00100000
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }
    
    /* The following command line options are set as part of the CCS project.    */
    /* If you are building using the command line, or for some reason want to    */
    /* define them here, you can uncomment and modify these lines as needed.     */
    /* If you are using CCS for building, it is probably better to make any such */
    /* modifications in your CCS project and leave this file alone.              */
    /*                                                                           */
    /* --heap_size=0                                                             */
    /* --stack_size=256                                                          */
    /* --library=rtsv7M4_T_le_eabi.lib                                           */
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        .intvecs:   > 0x00004000
        .text   :   > FLASH
        .const  :   > FLASH
        .cinit  :   > FLASH
        .pinit  :   > FLASH
        .init_array : > FLASH
    
        .vtable :   > 0x20000000
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM
    }
    
    __STACK_TOP = __stack + 512;





    Also, the boot loader linker file code:
    /******************************************************************************
     *
     * bl_link_ccs.cmd - CCS linker configuration file for boot loader.
     *
     * Copyright (c) 2009-2017 Texas Instruments Incorporated.  All rights reserved.
     * Software License Agreement
     * 
     * Texas Instruments (TI) is supplying this software for use solely and
     * exclusively on TI's microcontroller products. The software is owned by
     * TI and/or its suppliers, and is protected under applicable copyright
     * laws. You may not combine this software with "viral" open-source
     * software in order to form a larger program.
     * 
     * THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
     * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
     * NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
     * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
     * DAMAGES, FOR ANY REASON WHATSOEVER.
     * 
     * This is part of revision 2.1.4.178 of the Tiva Firmware Development Package.
     *
     *****************************************************************************/
    
    --retain=Vectors
    
    /* The following command line options are set as part of the CCS project.    */
    /* If you are building using the command line, or for some reason want to    */
    /* define them here, you can uncomment and modify these lines as needed.     */
    /* If you are using CCS for building, it is probably better to make any such */
    /* modifications in your CCS project and leave this file alone.              */
    /*                                                                           */
    /* --heap_size=0                                                             */
    /* --stack_size=256                                                          */
    /* --library=rtsv7M3_T_le_eabi.lib                                           */
    
    /* System memory map */
    
    MEMORY
    {
        FLASH (RX) : origin = 0x00000000, length = 0x00010000
        SRAM (RWX) : origin = 0x20000000, length = 0x00010000
    }
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        GROUP
        {
            .intvecs
            .text
            .const
            .data
        } load = FLASH, run = 0x20000000, LOAD_START(init_load), RUN_START(init_run), SIZE(init_size)
    
        GROUP
        {
            .bss
            .stack
        } run = SRAM, RUN_START(bss_run), RUN_END(bss_end), SIZE(bss_size), RUN_END(__STACK_TOP)
    
    }
    

  • Hi Apoorv,
    In your cmd for the application you have the length equal to 0x100000. Bear in mind that your application starts at 0x4000 and therefore the available flash space for your application should be 0x100000 - 0x4000 which is 0x000FC000. Change the length to 0x000FC000 and see if that fixes the problem.

    MEMORY
    {
    FLASH (RX) : origin = 0x00004000, length = 0x00100000
  • Hi,

    I tried that but the code is still stuck at location oxfffffffe with the lr pointing towards 0xffffffff. Also I tried to flash application code using ccs . The memory location 0x0 was empty since no bootloader is preset and at location 0x4000, the appliaction ivt is present. However, memory location at stack_top points towards a location in sram (20023E34), rest all point towards valid locations in flash only.  

    Also if I do __STACK_TOP = __stack + 8192;, will this increase the stack size or do I need to make changes somewhere else also?

    The main issue is that sometimes the whole program runs successfully, while sometimes, it gets stuck at memory loacation 0xfffffffe after partial running. Is this an issue because of the bootloader?
    /******************************************************************************
     *
     * Default Linker Command file for the Texas Instruments TM4C129ENCPDT
     *
     * This is derived from revision 15071 of the TivaWare Library.
     *
     *****************************************************************************/
    
    --retain=g_pfnVectors
    
    MEMORY
    {
        FLASH (RX) : origin = 0x00004000, length = 0x000FC000
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }
    
    /* The following command line options are set as part of the CCS project.    */
    /* If you are building using the command line, or for some reason want to    */
    /* define them here, you can uncomment and modify these lines as needed.     */
    /* If you are using CCS for building, it is probably better to make any such */
    /* modifications in your CCS project and leave this file alone.              */
    /*                                                                           */
    /* --heap_size=0                                                             */
    /* --stack_size=256                                                          */
    /* --library=rtsv7M4_T_le_eabi.lib                                           */
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        .intvecs:   > 0x00004000
        .text   :   > FLASH
        .const  :   > FLASH
        .cinit  :   > FLASH
        .pinit  :   > FLASH
        .init_array : > FLASH
    
        .vtable :   > 0x20000000
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM
    }
    
    __STACK_TOP = __stack + 512;








  • Some questions.

    1. What application did you run? Is this your own or the TivaWare examples like boot_demo1 or boot_demo2?

    2. Did you modify the boot_serial or you use the boot_serial as is provided by the TivaWare?

    3. The stack size you reserve seems excessive unless your application really needs that much. Normally I will think 1024 is sufficient for most cases.

    4. Did you say you try to use CCS to program the application into the flash? Please note that the CCS will erase the entire flash by default unless you change the erase option. As a result, when you program the application the bootloader starting at 0x0 is hence erased. Is this what you are seeing? If your application responds to your command such as pressing a switch to reload/update your application again it will jump to the bootloader area which is all empty now. Maybe that is the problem you have.

    Below is the default setting. You can change to "Necessary pages Only" so that the bootloader will not be erased when you program the application via CCS.

  • Hi,
    Thanks for the solution. Now I am able to successfully flash code via UART.
    However, I have 1 issue.
    Lets suppose that when the code is flashed 50 percent via UART, I disconnect the plug (i.e. flash a corrupt code). This means the application program is corrupt and it wont jump to bootloader when gpio is connected to ground . This brings me to a state, where I have to flash the correct application program once again via JTAG in location 0x4000. Can this be prevented?

    Regards,
    Apoorv
  • Hi Apoorv,
    The TivaWare bootloader is built to check if the application is valid by checking the first two locations of the application image. The first two locations are the stack pointer and the reset handler address. If these two locations do not contain valid values such as all 0xF's then it will force an update of the application. Another way is by forcing a pin so force a bootloader update. In your case, if the application is partially updated meaning the first two locations are already valid then you can still force an update by using a pin.
  • Hi Charles,

    I jumped back to an ethernet based bootloader after successfully configuring the UART bootloader.

    First, I flashed boot_emac_flash at mem location 0x0 and boot_demo_emac_flash at memory location 0x4000 using jtag and tried to write the same file at the location 0x4000 using ethernet.

    I again got the same error (Unable to start bootp server) in LM Flash programmer. Then I tried switching to another utility eflash.c and which was giving error in bootp_server.c in line no 459 which was to create a bootp packet for the server.To, make changes to this eflash file, I compiled it using make utility in cygwin.

    Then, I changed the bootp server port in the eflash.c to 50000(i.e. some random port) bootp client mode to 50002 and tftp server port to 50004 and I was successfully able to send MAGIC packets to udp port 9, and the LED on board stopped blinking, i.e. code succesfully branched to bootloader. But the upgrade did'nt happen(because in the bootloader, the configures udp ports were 67.68 and 69 resp.).

    So, I again changed the ports in bootloader code to 50000, 50002 and 50004 resp. and again ran the eflash utility. But, the eflash utility again gives an error: failed to create bootp server socket.

    Does this mean that the ports configured in the boot_emac _flash are conflicting with the eflash utility?

    Also, for the whole time dhcp server was on. Can this be a problem?

    Also, I tried doing netstat -a and found this:(192.168.1.150 is my laptop ip, 192.168.1.5 is the board ip assigned by DHCP server.)

    UDP 0.0.0.0:58952 *:*
    UDP 0.0.0.0:62859 *:*
    UDP 127.0.0.1:1900 *:*
    UDP 127.0.0.1:49664 *:*
    UDP 127.0.0.1:59822 *:*
    UDP 192.168.1.150:9 *:*
    UDP 192.168.1.150:67 *:*
    UDP 192.168.1.150:67 *:*
    UDP 192.168.1.150:69 *:*
    UDP 192.168.1.150:69 *:*
    UDP 192.168.1.150:137 *:*
    UDP 192.168.1.150:138 *:*
    UDP 192.168.1.150:1900 *:*
    UDP 192.168.1.150:40000 *:*
    UDP 192.168.1.150:40004 *:*
    UDP 192.168.1.150:40006 *:*
    UDP 192.168.1.150:50000 *:*
    UDP 192.168.1.150:50003 *:*
    UDP 192.168.1.150:59820 *:*
    UDP 192.168.2.96:137 *:*
    UDP 192.168.2.96:138 *:*
    UDP 192.168.2.96:1900 *:*
    UDP 192.168.2.96:59821 *:*



    Regards,
    Apoorv

  • HI Apoorv,
    I'm closing this thread since you have posted a new thread for the same at e2e.ti.com/.../667007.