Undefined reference to

Hello!

Can somebody say what im doing wrong
I have project in STM32Cube with lwip and freertos
Im trying to add new thread(as new task) with exist principles and cant do it

  /* Definitions for TCPip */
osThreadId_t mtcpConHandle;
const osThreadAttr_t mtcpCon_attributes = {
  .name = "mtcpCon",
  .stack_size = 384 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};

void mstartTcpCon(void *argument);

int main(void)
{

/* creation of TCPip connection*/
  mtcpConHandle = osThreadNew(mstartTcpCon, NULL, &mtcpCon_attributes);
  while (1)
  {
    
  }
 
}
void mstarTcpCon(void *argument)
{

}

And at build I have got the following make errors:
main.o: in function ‘main’
undefined reference to ‘mstartTcpCon’
As I created project by cube I dont think that problem with project structure

You need to add the source file where is mstartTcpCon is implemented to your build or project.

Sorry, fixed, mstarTcpCon is already in main, partly declared here

and in that the point

The definition is mstarTcpCon (missing t in start)

Thanks a lot!!! Finally build

yet another question to that
The target of mstartTcpCon is to connect to the sever(PC) within TCPIP
In that function I use netconn API within FreeRTOS and I create connection(socket), connect to server and send data
But in proctice I have en Error after netconn_connect

Please help
Here the source code of that function:

void mstartTcpCon(void *argument)
{	
	ip_addr_t server_ip;
	    struct netconn *conn, *newconn;
	    err_t err, accept_err;
	    struct netbuf *buf;
	    uint8_t *data;
	    uint8_t mas[8] = {1,2,3,4,5,6,7,8};
	    u16_t len = 8;
	    data = &mas[0];
	    IP4_ADDR(&server_ip, 169, 254, 44, 141);
	    conn = netconn_new(NETCONN_TCP);

	    if (conn != NULL)
	    {
	    	err = netconn_bind(conn, NULL, 80);
	    	if (err == ERR_OK)
	    	{
	    		err = netconn_connect(conn, &server_ip, 80);
	    	 
	        if(err == ERR_OK)
	        {
	        	err =  netconn_write(conn, data, len, NETCONN_DONTBLOCK);

	        if (err == ERR_OK)
	        {

	            netconn_listen(conn);

	            while (1)
	            {

	            	accept_err = netconn_accept(conn, &newconn);


	            	if (accept_err == ERR_OK)
	                {

	            		while (netconn_recv(newconn, &buf) == ERR_OK)
	                    {
	                        do
	                        {
	                            netbuf_data(buf, (void *)&data, &len);

	                            if(data[0] == 0xAA && len >= 2) data[1] = ~data[0];

	                            netconn_write(newconn, data, len, NETCONN_COPY);
	                        }
	                        while (netbuf_next(buf) >= 0);

	                        netbuf_delete(buf);
	                    }


	                    netconn_close(newconn);
	                    netconn_delete(newconn);
	                }
	            }

	        }

	        }}
	        else
	        {
	            netconn_delete(newconn);
	        }
	    }
	    vTaskDelete(NULL);
}

You should add the necessary details (which error(code) ?) if you want some help.
Also it’s very helpful to know what you’re trying to achieve.
(I wonder that you first connect to a server as client and afterwards changing the role being the server.)
Please note that is a lwIP issue which is not part of FreeRTOS. FreeRTOS comes with it’s own (optional) TCP stack.
Did you try one of the probably provided STcube lwIP demos/examples first to get in touch with it ?
Hint: Please enclose code blocks in 3 tildas (~~~) or 3 backticks (```) and try to align/format the code for better readability :slight_smile:

Sorry, the previous en error was cause of absence of server
Now connection established but when I send data I cant see it in Wireshark
and in debug mode I have Err_Ok after data transmission. At PC side server in listen

void mstartTcpCon(void *argument)
{	
	ip_addr_t server_ip;
	ip_addr_t client_ip;
	    struct netconn *conn, *newconn;
	    err_t err, accept_err;
	    struct netbuf *buf;
	    struct netbuf *buf2;
	    uint8_t *data;
	    uint8_t mas[8] = {1,2,3,4,5,6,7,8};

	    u16_t len = 8;


	    //data = &mas[0];
	    IP4_ADDR(&server_ip, 169, 254, 44, 141);
	    IP4_ADDR(&client_ip, 169, 254, 44, 138);
	    conn = netconn_new(NETCONN_TCP);

	    if (conn != NULL)
	    {
	    	//err = netconn_bind(conn, IP4_ADDR_ANY, 56547);
	    	err = netconn_bind(conn, &client_ip, 56547);
	    	if (err == ERR_OK)
	    	{
	    		err = netconn_connect(conn, &server_ip, 56547);
	    
	       }
	     }
	     else
	     {
	        netconn_delete(newconn);
	     }
	    }
	    vTaskDelete(NULL);
}

Wireshark absence of data transfer from slave here:

Again:

What is slave here ? The client resp. your application ?
Where is the send call with the data you want to transfer to the (server) peer?
There is no TCP transfer (start) in the Wireshark logs.
You should check the return and/or error codes of the networking API calls.
They usually give some well documented information on failure. See the lwIP docs for the details.

Thanks fro your support. In debug mode I see that I have only ERR_OK from netconn API.
I simpify the code and have got the following:

void mstartTcpCon(void *argument)
{	
	ip_addr_t server_ip;
	ip_addr_t client_ip;

   
	    struct netconn *conn;//, *newconn;
	    err_t err;//, accept_err;
	    struct netbuf *buf2;
	    uint8_t *data;
	    uint8_t mas[8];

	    u16_t len = 8;
	    IP4_ADDR(&server_ip, 169, 254, 44, 141);
	    IP4_ADDR(&client_ip, 169, 254, 44, 138);
	    conn = netconn_new(NETCONN_TCP);

	    if (conn != NULL)
	    {
	    	err = netconn_bind(conn, &client_ip, 56547);
	    	if (err == ERR_OK)
	    	{
	    	 err = netconn_connect(conn, &server_ip, 56547);
	    	 if(err == ERR_OK)
	        {

	        	mas[0] = 0x31;
	        	mas[1] = 0x32;
	        	mas[2] = 0x33;
	        	mas[3] = 0x34;
	        	mas[4] = 0x35;
	        	mas[5] = 0x36;
	        	mas[6] = 0x37;
	        	mas[7] = 0x38;
	        	buf2 = netbuf_new();
	        	netbuf_alloc(buf2,len);
	        	netbuf_ref(buf2, mas, len);
	        	
	        	err =  netconn_write(conn, mas, len,  NETCONN_NOCOPY);
	        	

	        if (err == ERR_OK)
	        {

	        	netbuf_free(buf2);
	        	netbuf_delete(buf2);
	        	netconn_close(conn);
	        	netconn_delete(conn);
	        
	        }}
	        else
	        {
	        	netconn_close(conn);
	            netconn_delete(conn);
	        }
	    }
	    vTaskDelete(NULL);
	}

	///

}

And wireshark log which I cant recognize

At the PC(server) side I see the connetion, receiving, but the data is mpty string and size of data decreased in 2 bytes, - I send 8 bytes and receive 6.
Why I cant see it in wireshark maybe cause of W10?
Also I cant see any ARP

So finally you have your application somehow working, netconn_write returns OK and you receive only 6 bytes instead of 8 and the data is wrong, right ?
Did you check the received bytes ? Are they partially wrong or completely junk ?
I wonder why the connection establishment IS traced by Wireshark and the data transfer is not. That’s strange and shouldn’t happen. Is there some wrong/unwanted filtering configured in Wireshark ? Without Wireshark you’ll probably have a hard time investigating networking issues. It’s an inevitable tool.
Is your ethernet driver known to work ?
Did you verify your setup / board with a lwIP demo/example application known to work ?
If the software is provided by ST as is you should ask them for support.
I don’t think the issue is related to FreeRTOS and also I’m not familiar with lwIP and can’t help with it.
Good luck !

Finally Ive got working TCP, but while integration it in exist project I have some problem
Project based on queues and then I create new queue I stopped on xQueueReceive
And when I trying to paste new code into existing queue I also have problem
Here the existing queue:

void startUartTx(void *argument)
{
 
 UART_HandleTypeDef* uart = uartM3g;
 osMessageQueueId_t qu = quMsgM3gHandle;
 struct netbuf *buffer;
  err_t err;
 /* Infinite loop */
 for( ; ; )
 {
   MessageNode msgNode;
   xQueueReceive(qu, &msgNode, portMAX_DELAY);
   vPortEnterCritical();
   HAL_UART_Transmit(uart, (uint8_t*)msgNode.message, msgNode.size, 1000);
   //xQueueSend(qu, &msgNode, portMAX_DELAY);


   buffer = netbuf_new();
  	//netbuf_alloc(buffer,sizeof(msgNode));
  	netbuf_alloc(buffer,5);
  	//netbuf_ref(buf2, data, len);
  	buffer->p->payload = msgNode.message;
  	buffer->p->len = 5;//msgNode.size;
  	err =  netconn_write(conn, buffer->p->payload, buffer->p->len,  NETCONN_COPY);// NETCONN_DONTBLOCK);
  	netbuf_delete(buffer);
   msg_free(&msgNode);
      vPortExitCritical();
      osDelay(1);

  // vTaskResume(TCPTxHandle);
 }

}

There I stoping in на buffer->p->len = 5, with any value of buffer size.
In debug mode I see that I stopped in while of the following functions:

void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */
  struct
  {
    uint32_t r0;
    uint32_t r1;
    uint32_t r2;
    uint32_t r3;
    uint32_t r12;
    uint32_t lr;
    uint32_t pc;
    uint32_t psr;
  } *stack_ptr;               

  asm(
    "TST lr, #4 \n"           
    "ITE EQ \n"              
    "MRSEQ %[ptr], MSP  \n"   
    "MRSNE %[ptr], PSP  \n"   
    : [ptr] "=r" (stack_ptr)
  );
  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
}

Please help, I dont understand how work in FreeRTOS with queues instead of tasks

It seems you are mixing the CMSIS and FreeRTOS API. You need to use one of them.

If you want to use FreeRTOS Queue API, here is the documentation: FreeRTOS - FreeRTOS queue API functions, including source code functions to create queues, send messages on queues, receive messages on queues, peek queues, use queues in interrupts.

If you want to use CMSIS API, here is the documentation: Message Queue

Thanks.

In addition the critical section covers by far too much code. You really should try to understand what you’re glueing together. Otherwise it’s a road to nowhere…