2024-07-10 12:07 AM - edited 2024-07-10 12:14 AM
The main function code is as follows:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
loop_cnt++;
//HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
if(13 == ((loop_cnt >> 4) & 0x0f))
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
else if (15 == ((loop_cnt >> 4) & 0x0f))
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
HAL_IWDG_Refresh(&hiwdg);
if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_13))
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);
}
else
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_SET);
}
//print_log("w5500 link STA %d\r\n", (Read_W5500_1Byte(PHYCFGR)&LINK));
#if 1
if((getPHYCFGR() & 0x01) != link_state)
{
link_state = (getPHYCFGR() & 0x01);
if((getPHYCFGR() & 0x01) == 0)
{
beep_voice(1, 200);
close(2);
S_State[2] = 0;
close(3);
S_State[3] = 0;
close(4);
S_State[4] = 0;
close(5);
S_State[5] = 0;
}
else
{
beep_voice(2, 50);
print_log("w5500 link\r\n");
}
}
else if(memcmp(gSystemParam.deviceIp, gSystemParam.gateway, 3) == 0) // check gateway
{
//tmpTciks = g64msTicks;
// handle webserver
do_http(0);
//print_log("do_http %lld\r\n", g64msTicks - tmpTciks);
//tmpTciks = g64msTicks;
// handle NTP services
//ntpServices();
//print_log("ntpServices %lld\r\n", g64msTicks - tmpTciks);
//tmpTciks = g64msTicks;
netAppServices();
//read_net_app();
//print_log("netAppServices %lld\r\n", g64msTicks - tmpTciks);
}
// handle uart message, include uart1 uart2 uart3
cmdMachine();
#endif
}
After commenting out do_http(0); on line 54, the program cannot start. What is the problem?
The do_http function code is as follows:
char rx_buf[MAX_URI_SIZE] = {0};
void do_http(uint8_t sn)
{
unsigned short len;
st_http_request *http_request;
memset(rx_buf,0x00,MAX_URI_SIZE);
http_request = (st_http_request*)rx_buf; // struct of http request
/* http service start */
switch(getSn_SR(sn))
{
case SOCK_INIT:
//listen(sn);
break;
case SOCK_LISTEN:
break;
case SOCK_ESTABLISHED:
//case SOCK_CLOSE_WAIT:
if(getSn_IR(sn) & Sn_IR_CON)
{
setSn_IR(sn, Sn_IR_CON);
}
if ((len = getSn_RX_RSR(sn)) > 0)
{
len = recv(sn, (unsigned char*)http_request, len);
*(((unsigned char*)http_request)+len) = 0;
//proc_http(sn, (unsigned char*)http_request); // request is processed
disconnect(sn);
//printf("SOCK_ESTABLISHED %04x\r\n", len);
}
break;
case SOCK_CLOSE_WAIT:
if ((len = getSn_RX_RSR(sn)) > 0)
{
//printf("close wait: %d\r\n",len);
len = recv(sn, (unsigned char*)http_request, len);
*(((unsigned char*)http_request)+len) = 0;
//proc_http(sn, (unsigned char*)http_request); // request is processed
//printf("SOCK_CLOSE_WAIT %04x\r\n", len);
}
disconnect(sn);
break;
case SOCK_CLOSED:
len = gSystemParam.webServerPort[1];
len *= 256;
len += gSystemParam.webServerPort[0];
socket(sn, Sn_MR_TCP, len, 0x00); /* reinitialize the socket */
break;
default:
break;
}// end of switch
}
2024-07-10 01:02 AM
I'd suppose it does start.
Replace rhe function call with a HAL_Delay(100) and see if it "works" again.
2024-07-10 01:15 AM - edited 2024-07-10 01:17 AM
"the program cannot start"
What "program"? What do you mean by "start"?
A line in the "future" generally shouldn't affect a line before it.
Do you get compilation errors? Do you get errors when flashing? Do you get errors when debugging?
Or does the binary run, but doesn't do what you want it to do? If so, what is the desired/expected behavior vs what is the observed behavior? Does it hang in a loop? Hardfault errors?
2024-07-10 01:28 AM
No, it doesn't work. The segger RTT viewer doesn't has any output.
2024-07-10 01:31 AM
Under normal circumstances, SEGGER RTT viewer has output and w5500 will connect to the server. However, after commenting out do_http(0), RTT viewer has no output and w5500 will not connect to the server. If you enter debug mode, you will find that the code is executing normally.
2024-07-10 04:19 AM
What server? I don't have my crystal ball at hand.
If the program doesn't do what you want when commenting out the line, then don't comment it out.
2024-07-10 04:32 AM
@BOEINGNG wrote:Under normal circumstances, SEGGER RTT viewer has output and w5500 will connect to the server. However, after commenting out do_http(0), RTT viewer has no output and w5500 will not connect to the server..
But it seems that all your RTT output, and all your w5500 stuff is inside do_http(0) - so it obviously won't happen if you don't call that function?
:thinking_face: