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.

MSP432E401Y: Hard Fault in lwIP library, trying to implement MODBUS

Part Number: MSP432E401Y


Tool/software:

Hello,

I am trying to implement modbus in a project on an MSP432E401Y.  I created a fairly simple set of handlers and callbacks using the HTTPD code in lwIP as an example.

If I run the code, the system will crash after accepting a connection (I use the command "telnet <ip> 502" to generate a connection).  I have tried to step through the code, but no hard fault occurs if it is stepped through in the debugger.  The particular hardfault is a precise bus error with the fault address of 0x99200111.  Is there any way for me to try to figure out what code caused this error?


My dummy server implementation looks like this:

/**
 * Data has been received on this pcb.
 * For HTTP 1.0, this should normally only happen once (if the request fits in one packet).
 */

static err_t MOD_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){

	USB_Send_String("MODBUS: recv();");

	if(p->next != NULL){

		USB_Send_String("MODBUS: Multi-payload over capacity;");

		return ERR_MEM;
	}

	struct MOD_Frame * frame = (struct MOD_Frame*) p->payload;


	switch(frame->function){

		case MOD_FUNC_READ_COILS:
			USB_Send_String("MODBUS: Read Coils;");
			break;
		case MOD_FUNC_READ_DISCRETE:
			USB_Send_String("MODBUS: Read Discrete;");
			break;
		case MOD_FUNC_READ_REGISTER:
			USB_Send_String("MODBUS: Read Register;");
			break;



	}


	return ERR_OK;


}


static void MOD_err(void *arg, err_t err){
	USB_Send_String("MODBUS: err();");
}

/**
 * Data has been sent and acknowledged by the remote host.
 * This means that more data can be sent.
 */
static err_t MOD_sent(void *arg, struct tcp_pcb *pcb, u16_t len){
	USB_Send_String("MODBUS: sent();");
	return ERR_OK;
}

/**
 * The poll function is called every 2nd second.
 * If there has been no data sent (which resets the retries) in 8 seconds, close.
 * If the last portion of a file has not been sent in 2 seconds, close.
 *
 * This could be increased, but we don't want to waste resources for bad connections.
 */
static err_t MOD_poll(void *arg, struct tcp_pcb *pcb){
	USB_Send_String("MODBUS: poll()");

	return ERR_OK;
}


err_t MODBUS_accept(void *arg, struct tcp_pcb *newpcb, err_t err){

	if ((err != ERR_OK) || (newpcb == NULL)) {
		USB_Send_String("MODBUS: Error in Accept;");
		return ERR_VAL;
	}

	USB_Send_String("MODBUS:  Accepted Client;");

	tcp_setprio(newpcb, 1);

	tcp_arg(newpcb, NULL);


	/* Set up the various callback functions */
	tcp_recv(newpcb, MOD_recv);
	tcp_err(newpcb, MOD_err);
	tcp_poll(newpcb, MOD_poll, 4);
	tcp_sent(newpcb, MOD_sent);

	delay_ms(100);

	return ERR_OK;

}


void init_MODBUS(){

	USB_Send_String("MODBUS: Init;");

	//Initialize TCP server
	struct tcp_pcb* conn = tcp_new_ip_type(IPADDR_TYPE_ANY);

	if(conn == NULL){
		USB_Send_String("MODBUS: tcp_new failed;");
		return;
	}


	tcp_setprio(conn, 1);	//Modbus has higher priority than HTTP...


	int err = ERR_OK;
	char errbuf[64];



	tcp_arg(conn, (void*)0);

	err = tcp_bind(conn, IP_ADDR_ANY, (502));

	if(err != ERR_OK){
		snprintf(errbuf,64,"MODBUS: TCP Bind Failure: %i;",err);
		USB_Send_String(errbuf);
		return;
	}

	conn = tcp_listen(conn);


	tcp_accept(conn,MODBUS_accept);

	USB_Send_String("MODBUS: Init Succesful;");

}



Would y'all have any advice or ideas as to why this might not work as expected?  Thank you for your time.