cancel
Showing results for 
Search instead for 
Did you mean: 

Strange variable behavior in struct, TCP / lwIP

LCE
Principal II

Heyho,

I have a super-stable TCP-audio-streaming server on a H733 here, using custom ETH driver and lwIP, no OS.

But I recently found that in a struct which is used for handling / storing the TCP connection, the variable to store the port number "u16Port" (used in lwIP's tcp_bind() to set the TCP port) changes as soon as data is transmitted.

It's really crazy: u16Port has the init value before and after the connection is accepted, but as soon as data is transmitted, it changes all the time (checked via UART and http REST). When data transfer stops, it keeps the latest wrong value, after TCP connection is closed,  u16Port has the init value again.

All other values in the struct do NOT change and their values make sense.

I have tried to set the struct to volatile, use another memory area, align, but still changing.

I just checked it with the STM32CubeIDE debugger under Live Expressions, there I see the same change.

I admit I have no idea how I can check where this variable is modified.

How can I find out where the variable is modified?

Any ideas what's happening?

 

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* struct for handling TCP
 *	CONTROL
 */
struct s_sTcpStreamControl
{
	struct tcp_pcb *pPcbListen;
	struct tcp_pcb *pPcbStream;

	uint16_t u16Port;
	uint16_t u16Dummy;

	sTcpStreamConnection_t *psCon;

	sTcpStreamCounters_t sCnt;

	uint32_t u32RxdBytes;

	uint8_t u8CtlState;
	uint8_t u8SrvActive;
	uint8_t u8SrvStop;
	uint8_t u8SrvAcptStartPeriph;
};

typedef struct s_sTcpStreamControl sTcpStreamControl_t;

...

/* A2IP = audio to IP control */
sTcpStreamControl_t sTcpStreamCtrlA2Ip;

 

1 ACCEPTED SOLUTION

Accepted Solutions
LCE
Principal II

Okay, got it:

in the tcp_sent callback I chose the wrong struct to connect to the argument pointer.

Ouch.

1. interesting that this was otherwise working so well

2. sometimes it helps to talk to oneself in public :D

View solution in original post

2 REPLIES 2
LCE
Principal II

I just switched places inside the struct between u16Port and u16Dummy.

Now u16Port keeps its init value as it should, and u16Dummy increases by 20 with each TCP packet. :D

LCE
Principal II

Okay, got it:

in the tcp_sent callback I chose the wrong struct to connect to the argument pointer.

Ouch.

1. interesting that this was otherwise working so well

2. sometimes it helps to talk to oneself in public :D