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.

MSP-EXP432E401Y: Send character/string to putty using TCP connection and ethernet

Part Number: MSP-EXP432E401Y


Hi,

I am trying to send a string through ethernet using a TCP connection. I based my code off the tcp echo example and the etherenet_with_lwip example. I dont seem to be getting the characters to show on my putty. I am trying to send the string hello world.

//*****************************************************************************
//
// enet_lwip.c - Sample WebServer Application using 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.
//
//
//*****************************************************************************

#include <stdbool.h>
#include <stdint.h>
#include "ti/devices/msp432e4/driverlib/driverlib.h"
#include "ti/devices/msp432e4/inc/msp.h"
#include "ustdlib.h"
#include "uartstdio.h"
#include "pinout.h"
#include "locator.h"
#include "lwiplib.h"
#include "lwip/apps/httpd.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Ethernet with lwIP (enet_lwip)</h1>

//*****************************************************************************

//*****************************************************************************
//
// 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;
static struct tcp_pcb *echo_pcb;
//*****************************************************************************
//
// The system clock frequency.
//
//*****************************************************************************
uint32_t g_ui32SysClock;

//*****************************************************************************
//
// 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;

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************
//
// 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);

//
// Display the string.
//
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
{
//
// 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.
//
}
}

//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTick_Handler(void)
{
//
// Call the lwIP timer handler.
//
lwIPTimer(SYSTICKMS);

//
// Tell the application to change the state of the LED (in other words
// blink).
//
g_bLED = true;
}
static struct tcp_pcb *echo_pcb;

enum echo_states
{
ES_NONE = 0,
ES_ACCEPTED,
ES_RECEIVED,
ES_CLOSING
};

struct echo_state
{
u8_t state;
u8_t retries;
struct tcp_pcb *pcb;
/* pbuf (chain) to recycle */
struct pbuf *p;
};

err_t echo_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
err_t echo_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
void echo_error(void *arg, err_t err);
err_t echo_poll(void *arg, struct tcp_pcb *tpcb);
err_t echo_sent(void *arg, struct tcp_pcb *tpcb, u16_t len);
void echo_send(struct tcp_pcb *tpcb, struct echo_state *es);
void echo_close(struct tcp_pcb *tpcb, struct echo_state *es);

//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************
int
main(void)
{
uint32_t ui32User0, ui32User1;
uint8_t pui8MACArray[8];

//
// 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.
//
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 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 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.
//

ip4_addr_t local;
ip4_addr_t netmask;
ip4_addr_t gateway;


IP4_ADDR(&local, 19, 1, 168, 192);
IP4_ADDR(&netmask, 0, 255, 255, 255);
IP4_ADDR(&gateway, 1, 1, 168 ,192);

lwIPInit(g_ui32SysClock, pui8MACArray, local.addr, netmask.addr, gateway.addr, IPADDR_USE_STATIC);


//
// Setup the device locator service.
//

tcp_init();

echo_pcb = tcp_new();
err_t err;

err = tcp_bind(echo_pcb, IP_ADDR_ANY, 7);

char a[] = "hello world";
char *ptr1 = &a;

tcp_write(echo_pcb , ptr1, 11,TCP_WRITE_FLAG_COPY );
tcp_output(echo_pcb);


MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);

}

  • Hi,

    I will run this on my side and look into it.

    Srinivas

  • Hi,

    I managed to ping the MSP432 using my PC. I am having problems with the tcp_bind function? it it not outputting ERR_OK. Now that I am able to ping my device. I was wondering how I can send a data to a specific port and see the output on putty. 

    //*****************************************************************************
    //
    // enet_lwip.c - Sample WebServer Application using lwIP.
    //
    //

    //*****************************************************************************

    //*****************************************************************************
    //
    // 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;
    static struct tcp_pcb *modem_pcb;
    //*****************************************************************************
    //
    // The system clock frequency.
    //
    //*****************************************************************************
    uint32_t g_ui32SysClock;

    //*****************************************************************************
    //
    // 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;

    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif

    //*****************************************************************************
    //
    // 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);

    //
    // Display the string.
    //
    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
    {
    //
    // 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.
    //
    }
    }

    //*****************************************************************************
    //
    // The interrupt handler for the SysTick interrupt.
    //
    //*****************************************************************************
    void
    SysTick_Handler(void)
    {
    //
    // Call the lwIP timer handler.
    //
    lwIPTimer(SYSTICKMS);

    //
    // Tell the application to change the state of the LED (in other words
    // blink).
    //
    g_bLED = true;
    }

    err_t echo_accept(void *arg, struct tcp_pcb *newpcb, err_t err);

    //*****************************************************************************
    //
    // This example demonstrates the use of the Ethernet Controller.
    //
    //*****************************************************************************
    int

    main(void)
    {
    uint32_t ui32User0, ui32User1;
    uint8_t pui8MACArray[8];

    //
    // 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.
    //
    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN |
    SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_480), 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 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.
    //
    ip4_addr_t local;
    ip4_addr_t netmask;
    ip4_addr_t gateway;


    IP4_ADDR(&local, 50, 168, 168, 192);
    IP4_ADDR(&netmask, 0, 255, 255, 255);
    IP4_ADDR(&gateway, 1, 168, 168 ,192);

    lwIPInit(g_ui32SysClock, pui8MACArray, local.addr, netmask.addr, gateway.addr, IPADDR_USE_STATIC);
    tcp_init();


    modem_pcb = tcp_new();

    // tcp_connect(modem_pcb, local.addr, 20001, NULL);
    //sys_check_timeouts();


    // void tcp_arg(struct tcp_pcb * pcb, void * arg);
    //
    //

    if (modem_pcb = !NULL){
    {
    err_t err;

    err = tcp_bind(modem_pcb, local.addr ,20001);
    if (err == ERR_OK)
    {
    modem_pcb = tcp_listen(modem_pcb);  // it is not getting to this point in the code
    tcp_accept(modem_pcb, echo_accept);
    }
    else
    {
    /* abort? output diagnostic? */
    }
    }
    }

    tcp_connect(modem_pcb, &local, 20001, NULL );

    char string[] = 'hello world';
    char *ptr1 = &string;

    // tcp_sent(modem_pcb, NULL);
    // tcp_sndbuf(modem_pcb);
    //
    // tcp_write(modem_pcb, ptr1, 11,TCP_WRITE_FLAG_MORE);
    // tcp_output(modem_pcb);


    //

    // Setup the device locator service.
    //
    // LocatorInit();
    // LocatorMACAddrSet(pui8MACArray);
    // LocatorAppTitleSet("MSP432E4 enet_io");

    //
    // Initialize a sample httpd server.
    //


    //
    // 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.
    //
    while(1)
    {

    // tcp_write(modem_pcb, ptr1, 11,TCP_WRITE_FLAG_COPY);
    // tcp_output(modem_pcb);
    //
    // Wait till the SysTick Interrupt indicates to change the state of the
    // LED.
    //
    while(g_bLED == false)
    {
    }

    //
    // Clear the flag.
    //
    g_bLED = false;

    //
    // Toggle the LED.
    //
    MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
    (MAP_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
    GPIO_PIN_1));
    }
    }

**Attention** This is a public forum