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.

TM4C1294NCPDT: Getting into the Fault ISR while running the code

Part Number: TM4C1294NCPDT


Hi,

I am using modified enet_adc_sensor_client example. But when I am going into the debug mode, processor starts to execute FaultISR. I tried debugging the issue and when I put breakpoint at tcp_out.c file at below location I am able to get data from my board via tcpip protocol. please help me to solve the issue.

  • Hi,

      When you run the original example, did you get the fault?

      What did you modify?

  • Created a separate source file for a ethernet as i wanted to add separate file for ethernet, ADC or may be DMA. here is the code what I did.

    main.c
    
    
    
    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_emac.h"
    #include "driverlib/flash.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/adc.h"
    #include "drivers/pinout.h"
    #include "utils/lwiplib.h"
    #include "utils/ustdlib.h"
    #include "utils/uartstdio.h"
    #include "lwip/debug.h"
    #include "lwip/stats.h"
    #include "lwip/tcp.h"
    #include "lwip/inet.h"
    #include "Ethernet_Configuration.h"
    /**
     * main.c
     */
    //*****************************************************************************
    //
    // The variable g_ui32SysClock contains the system clock frequency in Hz.
    //
    //*****************************************************************************
    uint32_t g_ui32SysClock;
    //*****************************************************************************
    //
    //
    // Global flag indicating when the IP address is acquired
    //
    //*****************************************************************************//
    
    
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    int main(void)
    {
        uint32_t ui32User0, ui32User1;
        uint8_t pui8MACArray[8];
    
        char pcBuf[30];
        //
        // Make sure the main oscillator is enabled because this is required by
        // the PHY.  The system must have a 25MHz crystal attached to the OSC
        // pins. The SYSCTL_MOSC_HIGHFREQ parameter is used when the crystal
        // frequency is 10MHz or higher.
        //
        SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ);
    
        //
        // Run from the PLL at 120 MHz.
        // Note: SYSCTL_CFG_VCO_240 is a new setting provided in TivaWare 2.2.x and
        // later to better reflect the actual VCO speed due to SYSCTL#22.
        //
        g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                 SYSCTL_OSC_MAIN |
                                                 SYSCTL_USE_PLL |
                                                 SYSCTL_CFG_VCO_240), 120000000);
        //
        // Configure the device pins.
        //
        PinoutSet(true, false);
        // Configure UART.
        //
        UARTStdioConfig(0, 115200, g_ui32SysClock);
        //
        // Clear the terminal and print banner.
        //
        UARTprintf("\033[2J\033[H");
        UARTprintf("Ethernet lwIP TCP client example\n\n");
    
    
    
        //
        // Configure Port N1 for as an output for the animation LED.
        //
        MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
    
        //
        // Initialize LED to OFF (0).
        //
        MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, ~GPIO_PIN_1);
    
        //
        // Configure SysTick for a periodic interrupt.
        //
        MAP_SysTickPeriodSet(g_ui32SysClock / SYSTICKHZ);
        MAP_SysTickEnable();
        MAP_SysTickIntEnable();
    
        //
        // Configure the hardware MAC address for Ethernet Controller filtering of
        // incoming packets.  The MAC address will be stored in the non-volatile
        // USER0 and USER1 registers.
        //
        MAP_FlashUserGet(&ui32User0, &ui32User1);
        if((ui32User0 == 0xffffffff) || (ui32User1 == 0xffffffff))
        {
            //
            // We should never get here.  This is an error if the MAC address has
            // not been programmed into the device.  Exit the program.
            // Let the user know there is no MAC address
            //
            UARTprintf("No MAC programmed!\n");
            while(1)
            {
            }
        }
    
        //
        // Tell the user what we are doing just now.
        //
        UARTprintf("Waiting for IP.\n");
    
        //
        // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
        // address needed to program the hardware registers, then program the MAC
        // address into the Ethernet Controller registers.
        //
        pui8MACArray[0] = ((ui32User0 >>  0) & 0xff);
        pui8MACArray[1] = ((ui32User0 >>  8) & 0xff);
        pui8MACArray[2] = ((ui32User0 >> 16) & 0xff);
        pui8MACArray[3] = ((ui32User1 >>  0) & 0xff);
        pui8MACArray[4] = ((ui32User1 >>  8) & 0xff);
        pui8MACArray[5] = ((ui32User1 >> 16) & 0xff);
    
        //
        // Initialize the lwIP library, using DHCP.
        //
        lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_AUTOIP);
    
        //
        // Wait here until a valid IP address is obtained before
        // starting the client connection to the server.
        //
        while (g_bIPAddrValid == 0);
    
        //
        // Initialize the client.
        //
        echoClientInit();
    
        //
        // Set the interrupt priorities.  We set the SysTick interrupt to a higher
        // priority than the Ethernet interrupt to ensure that the file system
        // tick is processed if SysTick occurs while the Ethernet handler is being
        // processed.  This is very likely since all the TCP/IP and HTTP work is
        // done in the context of the Ethernet interrupt.
        //
        MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
        MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);
        // Loop forever, processing the LED blinking.  All the work is done in
        // interrupt handlers.
        //char *string = "Hello World! \n\r ";
        while(1)
        {
        //    TcpSendPacket(string);
        //    tcp_sent(tpcb, NULL);
            while(g_bLED == false || g_bconnect == false)
            {
            }
    
            //
            // Clear the flag.
            //
            g_bLED = false;
    
    
            usprintf(pcBuf," %d", 1);
            TcpSendPacket(pcBuf);
            UARTprintf("Sending device temperature %dF to the host\n", 20);
    
            //
            // Toggle the LED.
            //
            MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
                             (MAP_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
                              GPIO_PIN_1));
        }
    
    }
    
    
    
    
    
    
    
    
    Ethernet.h
    
    /*
     * Ethernet_Configuration.h
     *
     *  Created on: Jan 4, 2024
     *      Author: 320166058
     */
    
    #ifndef ETHERNET_CONFIGURATION_H_
    #define ETHERNET_CONFIGURATION_H_
    
    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_emac.h"
    #include "driverlib/flash.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/adc.h"
    #include "drivers/pinout.h"
    #include "utils/lwiplib.h"
    #include "utils/ustdlib.h"
    #include "utils/uartstdio.h"
    #include "lwip/debug.h"
    #include "lwip/stats.h"
    #include "lwip/tcp.h"
    #include "lwip/inet.h"
    
    //*****************************************************************************
    //
    // Defines for setting up the system clock.
    //
    //*****************************************************************************
    #define SYSTICKHZ               100
    #define SYSTICKMS               (1000 / SYSTICKHZ)
    
    
    //*****************************************************************************
    //
    // Interrupt priority definitions.  The top 3 bits of these values are
    // significant with lower values indicating higher priority interrupts.
    //
    //*****************************************************************************
    #define SYSTICK_INT_PRIORITY    0x80
    #define ETHERNET_INT_PRIORITY   0xC0
    
    //*****************************************************************************
    //*****************************************************************************
    //
    // The current IP address.
    //
    //*****************************************************************************
    uint32_t g_ui32IPAddress;
    //
    // Global flag indicating when the IP address is acquired
    //
    //*****************************************************************************//
    
    extern bool g_bIPAddrValid;
    //
    // Global flag indicating when the client connects to the server
    //
    //*****************************************************************************
    extern bool g_bconnect;
    
    //*****************************************************************************
    //
    // Volatile global flag to manage LED blinking, since it is used in interrupt
    // and main application.  The LED blinks at the rate of SYSTICKHZ.
    //
    //*****************************************************************************
    volatile bool g_bLED;
    
    //*****************************************************************************
    //
    // Global LwIP PCB structure and error variables.
    //
    //*****************************************************************************
    err_t err;
    
    //*****************************************************************************
    //
    // Defines for the server IP address and PORT numbers. User must change these
    // settings per their application.
    //
    //*****************************************************************************
    #define SERVER_IPADDR "169.254.180.20"
    #define SERVER_PORT 7000
    #define CLIENT_PORT 8000
    //*****************************************************************************
    
    extern uint32_t TcpSendPacket(char *string);
    extern void echoClientInit(void);
    #endif /* ETHERNET_CONFIGURATION_H_ */
    
    
    
    Ethernet.c
    
    
    
    /*
     * Ethernet_Configuration.c
     *
     *  Created on: Jan 4, 2024
     *      Author: 320166058
     */
    
    #include "Ethernet_Configuration.h"
    
    //*****************************************************************************
    //
    // Global counter to keep track the duration the connection has been idle.
    //
    bool g_bIPAddrValid =0;
    
    bool g_bconnect = 0;
    
    static struct tcp_pcb *tpcb;
    //*****************************************************************************
    //
    // Display an lwIP type IP Address.
    //
    //*****************************************************************************
    void
    DisplayIPAddress(uint32_t ui32Addr)
    {
        char pcBuf[16];
    
        //
        // Convert the IP Address into a string.
        //
        usprintf(pcBuf, "%d.%d.%d.%d", ui32Addr & 0xff, (ui32Addr >> 8) & 0xff,
                (ui32Addr >> 16) & 0xff, (ui32Addr >> 24) & 0xff);
    
        //
        // Send the IP Address string over UART.
        //
        UARTprintf(pcBuf);
    }
    
    //*****************************************************************************
    //
    // 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
            {
                g_bIPAddrValid = 1;
                //
                // Display the new IP address.
                //
                UARTprintf("IP Address: ");
                DisplayIPAddress(ui32NewIPAddress);
            }
            //
            // 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.
            //
        }
    }
    // The interrupt handler for the SysTick interrupt. Blink the LED and take ADC
    // sample every 250mS.
    //
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        //
        // Call the lwIP timer handler.
        //
        lwIPTimer(SYSTICKMS);
    
    
    
            g_bLED = true;
    
    }
    //*****************************************************************************
    //
    // Function to send TCP packets to the server
    //
    //*****************************************************************************
    uint32_t
    TcpSendPacket(char *string)
    {
        UARTprintf("\n \n Entered into the TCPSendPacket %s",string);
        UARTprintf("\n \n Entered into the TCPSendPacket %d",strlen(string));
        //
        // Queues the data pointed to by string.
        //
        err = tcp_write(tpcb, string, strlen(string), TCP_WRITE_FLAG_COPY);
    
        UARTprintf("\n \n TCP_OUTPUT Start");
        err = tcp_output(tpcb);
        UARTprintf("\n \n TCP_OUTPUT End");
    
        if (err)
        {
            UARTprintf("ERROR: Code: %d (TcpSendPacket :: tcp_write)\n", err);
            return 1;
        }
        //err = tcp_write(tpcb, string, strlen(string), TCP_WRITE_FLAG_COPY);
        //
        // Transmit the data.
        //
    
        //
        // Report any error that occurs.
        //
        if (err)
        {
            UARTprintf("ERROR: Code: %d (TcpSendPacket :: tcp_output)\n", err);
            return 1;
        }
        return 0;
    }
    //*****************************************************************************
    //
    // Callback function when the client establishes a successful connection to
    // the remote host.
    //
    //*****************************************************************************
    err_t
    connectCallback(void *arg, struct tcp_pcb *tpcb, err_t err)
    {
        char *string = "Hello World! \n\r ";
        //char *string = "0";
    
        if (err == ERR_OK)
        {
    
            UARTprintf("Connection Established.\n");
            g_bconnect = true;
    
            //
            // After connection, call the TcpSendPacket() to send
            // a greetings message
            //
           tcp_sent(tpcb, NULL);
            UARTprintf("Sending a greeting message to the Server\n");
            TcpSendPacket(string);
            return 0;
        }
        else
        {
            UARTprintf("No Connection Established.\n");
            return 1;
    
        }
    }
    
    
    //*****************************************************************************
    //
    // Function to create a LwIP client.
    //
    //*****************************************************************************
    void
    echoClientInit(void)
    {
        //
        // Create IP address structure.
        //
        struct ip_addr server_addr;
    
        //
        // Creates a new TCP connection identifier (PCB).
        //
        tpcb = tcp_new();
    
        if (tpcb != NULL)
        {
            //
            // Assign destination server IP address.
            //
            server_addr.addr = inet_addr(SERVER_IPADDR);
    
            //
            // Bind the PCB to all local IP addresses at the client port.
            //
            tcp_bind(tpcb, IP_ADDR_ANY, CLIENT_PORT);
    
            //
            // Configure destination IP address and port.
            //
            err = tcp_connect(tpcb, &server_addr, SERVER_PORT, connectCallback);
    
            if (err)
            {
                UARTprintf("ERROR: Code: %d (tcp_connect)\n", err);
            }
    
            UARTprintf("\nPCB CREATED\n");
        }
        else
        {
            memp_free(MEMP_TCP_PCB, tpcb);
            UARTprintf("PCB NOT CREATED\n");
        }
    }
    
    

  • You didn't answer my question if the original example has the same issue or not. If the only change you make is to separate the original example into separate files then it should work unless you make additional changes to the functionality. From what I see, you change to IPADDR_USE_AUTOIP as opposed to IPADDR_USE_DHCP. 

      Here is an app note to diagnose processor faults. https://www.ti.com/lit/pdf/spma043

  • Hi Charles,

    No, Original example don't have this problem, Actually I am changing my code to sample the ADC channel at 1 Mhz of frequency after that I am planning to use DMA Ping Pong mode to send those digital values into the 2 buffer. Simultaneously the buffer which is filled , i want to send it over ethernet. I didn't get any direct example of it hence I am using adc_ping_pong mode with DMA example reference + enet_adc_sensor_client example.

    Let me know if it is possible to sample 4 ADC channel at 1 MHz of frequency and send its data over ethernet. I want to post process the data at server side. So my main aim is not to miss any digital data.

  • Let me know if it is possible to sample 4 ADC channel at 1 MHz of frequency and send its data over ethernet. I want to post process the data at server side. So my main aim is not to miss any digital data.

    If ADCCLK is 16Mhz then you can achieve 1MSPS. The ADC has a 12 bit resolution. This means it takes 12 ADCCLK to complete ADC conversion of a input signal. There is addition time required for sample and hold time. See below equation from the datasheet. As you can see in table 15-4. to achieve 1MSPS, the NSH will need to be 4. When you add 4 + 12, it is 16 which is what it takes to achieve 1MSPS for one input. If your sampling frequency is 1Mhz meaning you use something like a timer at 1Mhz to trigger the ADC module to take an input sample then you can achieve 1MSPS for one input, not 4 inputs. At 1Mhz sampling frequency, you can achieve 0.25MSPS for each of the four inputs. As to your fault, I have already given you the app note for diagnosing the problem. I will suggest when you develop your application, start with a working example and then gradually add things instead of adding all the capabilities at once. This way, it is easier to debug your problem. 

    The ADC conversion frequency is a function of the Sample and Hold number, given by the following
    equation:
    FCONV = 1/((NSH + 12)*TADC)
    where:
    ■ NSH is the sample and hold width in ADC clocks
    ■ TADC is the ADC conversion clock period, which is the inverse of the ADC clock frequency FADC
    Now, the maximum allowable external source resistance (RS) also changes with the value of NSH,
    as the total settling time of the input circuitry must be fast enough to settle to within the ADC resolution
    in a single sampling interval. The input circuitry includes the external source resistance as well as
    the input resistance and capacitance of the ADC (RADC and CADC).
    The values for RS and FCONV for varying NSH values, with FADC=16MHz and FADC=32MHz are given
    in tables 18-4-a and 18-4-b.