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.
Tool/software:
Dear Team,
I want to implement client server integration on AM2634 eval board,
currently i'm using mcu_plus_sdk_am263x_09_02_00_56 and enet_cpsw_rawhttpserver as base source code for client implementation,
/-------------------------------------- Base source code --------------------------------/
while (false == App_isNetworkUp(netif_default))
{
//DebugP_log("Waiting for network UP ...\r\n");
sys_check_timeouts();
const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);
if (recvdEventsMask != AppEventId_NONE)
{
App_handleEvent(recvdEventsMask);
}
}
DebugP_log("Network is UP ...\r\n");
ClockP_sleep(1);
// AppTcp_startServer();
// tcpecho_raw_init();
// httpd_init(); // base http app not used, because its client integration
app_altcp(); // my client base function this function is define at the last
while (1)
{
sys_check_timeouts();
ClockP_usleep(1000);
const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);
if (recvdEventsMask != AppEventId_NONE)
{
App_handleEvent(recvdEventsMask);
}
}
App_shutdownNetworkStack();
EnetApp_driverDeInit();
EventP_destruct(&hEvent);
return 0;
}
/------------------ Rest of source code is same as in existing example--------------/
void app_altcp()
{
uint8_t status;
ip_addr_t myIPaddr;
IP_ADDR4(&myIPaddr, 192, 168, 1, 200);
ip_addr_t DestIPaddr;
IP_ADDR4(&DestIPaddr, 192, 168, 1, 2);
pcb_altcp = altcp_new(altcpblock);
altcp_bind(pcb_altcp, &myIPaddr, 2024); // bind with ip and port
status = altcp_connect(pcb_altcp, &DestIPaddr, app_port, connected);
if(status == 0)
{
DebugP_log("connect =%d \r\n", status);
}
else
{
altcp_close(pcb_altcp);
}
}
void connected(void *arg, struct altcp_pcb *conn, err_t err)
{
uint8_t dataptr[14] = "Hello Ethernet";
uint8_t apiflags;
DebugP_log("Connected data ...\r\n");
altcp_write(pcb_altcp, dataptr, 14, TCP_WRITE_FLAG_COPY);
altcp_recv(pcb_altcp, recved);
}
void recved(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err)
{
static int k;
if ((err != ERR_OK) || (p != NULL) )
{
/* error or closed by other side? */
if (p != NULL)
{
k++;
/* Inform TCP that we have taken the data. */
altcp_recved(conn, p->tot_len);
strncpy(buffer, (char*) p->payload, p->len);
DebugP_log("buffer = %s %d\r\n", buffer, k);
pbuf_free(p);
}
else
{
pbuf_free(p);
}
}
}
In above code I'm able to connect with server and sending data to server but problem is in receiving
in receiving Data is copy from p->payload to buffer after that its coming in this function mutiple times and pbuf_free try to free the allocated memory but its crash the code.
kindly check what wrong in this, I thing some issue in
const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);
if (recvdEventsMask != AppEventId_NONE)
{
App_handleEvent(recvdEventsMask);
please guide me how to solve this problem
Hi Vikas,
I was trying to pick the above code snippet but seems like there are some more changes as well since Im running into build issues.
Meanwhile I have some questions, can you help me answer them (and also share what additional changes I need on my end to build an example similar to you):
1. Any specific reason why you are using the alt layer APIs instead of the general tcp APIs such as tcp_recv not being used.
2. Can you add basic checks before calling pbuf_free to check if the pbuf is already filled or freed. Also please try to ensure that the pbuf_free happens only once (it is not repeated in the application as well as the lwip-stack). In the past we have seen this causing crashes as well.
Regards,
Shaunak
Dear Shaunak,
1. I tried general UDP API also but there is some other issue "sending is working but not able to receive in UDP"
2. I tried that also but the result was same, pointer continuously coming in receive function however server not sending data
compilation error should not be there because i'm adding these function in App_main.c
/------------------ UDP client code ------------------------------/
void app_udp()
{
err_t err;
/* 1. Create a new UDP control block */
upcb = udp_new();
/* Bind the block to module's IP and port */
ip_addr_t myIPaddr;
IP_ADDR4(&myIPaddr, 192, 168, 1, 200);
udp_bind(upcb, &myIPaddr, 2024);
/* configure destination IP address and port */
ip_addr_t DestIPaddr;
IP_ADDR4(&DestIPaddr, 192, 168, 1, 2);
err = udp_connect(upcb, &DestIPaddr, 2024);
if (err == ERR_OK) {
/* 2. Send message to server */
udpClient_send();
/* 3. Set a receive callback for the upcb */
udp_recv(upcb, udp_receive_callback, NULL);
} else {
udp_remove(upcb);
}
}
static void udpClient_send(void) {
struct pbuf *txBuf;
char data[100];
uint8_t status=0;
int len = sprintf(data, "Vikas Sending UPD message %d\n", counter);
/* allocate pbuf from pool*/
txBuf = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
if (txBuf != NULL) {
/* copy data to pbuf */
pbuf_take(txBuf, data, len);
/* send udp data */
status = udp_send(upcb, txBuf);
DebugP_log("Send PKT vikas status = %d\r\n", status);
/* free pbuf */
pbuf_free(txBuf);
}
}
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p,const ip_addr_t *addr, u16_t port)
{
struct test_udp_rxdata *ctr = (struct test_udp_rxdata *)arg;
/* Copy the data from the pbuf */
strncpy(buffer, (char*) p->payload, p->len);
DebugP_log("Received PKT viaks\r\n");
/*increment message count */
counter++;
// ctr->rx_cnt++;
// ctr->rx_bytes += p->tot_len;
/* Free receive pbuf */
if (p != NULL) {
pbuf_free(p);
}
}
/-----------------------------------------------------------------------------------------------------------/
Hi Vikas,
1. Can you share more details about the "crash". Where exactly does the program crash, can you share your CCS function call-stack screenshot to help me understand where it fails.
2. In your CCS expression window, please search for "lwip_stats" and check if you can spot any errors in "mem" or other sub-section. If it is an error or crash related to memory, it will increment the relevant error counters there.
3. Can you share your complete application as im running into build issues if I just use the above pasted code snippets.
Regards,
Shaunak
pbuf_free: p->ref > 0ASSERT: 29.778086s: /nightlybuilds/mcupsdk_internal/jenkins/mcu_plus_sdk_am263x_09_02_00_56/source/networking/lwip/lwip-stack/src/core/pbuf.c:pbuf_free:755: 0 failed !!!
how can share the code?
Hi Vikas,
This is an assert coming from the Lwip-stack trying to free up a pbuf which has never been referenced. Our doubt above was correct. We are incorrectly freeing up a pbuf which was never referenced. Can you check your lwip-stats to see if you have any memory related issues? The pbuf_free function expects the pbuf to be referenced atleast once in the pbuf packet chain, which is not happening in this case.
One thing that can be also tried is, from your example.syscfg, increase the number of lwip packet pools and match it to the DMA packet pools (else it will give syscfg errors). Next inside lwip-config/am263x/lwippools.h, increase the number of packet pools.
Then recompile the lwip-stack using the following command in your mcu_plus_sdk folder:
## Add PROFILE=debug incase you want a debug lib gmake -sj -f makefile.am263x lwip-contrib-freertos_r5f.ti-arm-clang gmake -sj -f makefile.am263x lwip-freertos_r5f.ti-arm-clang gmake -sj -f makefile.am263x lwipif-cpsw-freertos_r5f.ti-arm-clang
After these 2 changes, you can recompile your application. This will take care of the scenario where we are lacking the required number of packets from lwip.
Also, one question, what is the rate at which you send UDP packets to the AM263x?
From my understanding, It definitely seems like a memory corruption issue.
Regards,
Shaunak