---
title: "Initializing the http server on the W5500"
url: "https://maker.wiznet.io/forum/15552"
markdown_url: "https://maker.wiznet.io/forum/15552/md"
type: "Forum topic"
category: "IO Modules"
author: "spacecow"
created: "2025-01-31T17:59:36+09:00"
last_activity: "2025-01-31T19:48:18+09:00"
language: "en"
tags: ["C/C++", "W5500", "STM32"]
views: 3
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Initializing the http server on the W5500

## Question

Asked by spacecow on 2025-01-31 in IO Modules.

Hello everyone!

I am trying to initialize an http server on an STM32 G474 microcontroller using the W5500 network chip and the WIZNET standard library. In general, the Internet is full of tutorials on this topic, and on this forum too. But believe me, I've studied most of them, and I've only partially solved my problem, so I decided to ask for help here.

I am developing a bootloader for a home project that could provide the user with a web interface to perform some functions. There were no problems with initializing the TCP socket, the chip is pinging, everything is fine. There is a problem with the web page display. This is how I initialize the server:

```c
void http_server_init()
{
	uint8_t http_rx_buff[2048];
	uint8_t http_tx_buff[2048];
	uint8_t socknumlist[] = {0, 1, 2, 3, 4};

	httpServer_init(http_tx_buff,http_rx_buff,5, socknumlist);
	reg_httpServer_cbfunc(NULL, NULL);
	reg_httpServer_webContent((uint8_t*)"index.html", (uint8_t*)webpage);
}
```

I initialize the network chip like this:

```c
void w5500_init(void)
{
reg_wizchip_cs_cbfunc(cs_select, cs_deselect);
reg_wizchip_spi_cbfunc(spi_readbyte, spi_writebyte);

//Reset W5500
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);
HAL_Delay(1); // delay 1ms
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);
HAL_Delay(1600); // delay 1600ms

//Write net settings
ctlnetwork(CN_SET_NETINFO, (void*)&gSetNetInfo); // set net info
HAL_Delay(500);
ctlnetwork(CN_GET_NETINFO, (void*)&gGetNetInfo); // get net info

if(Success == validSetNetInfoResult(&gSetNetInfo, &gGetNetInfo)) // compare
{
	printf("Net info set success!\n");
}
else
{
	printf("Net info set failed!\n");
}

uint8_t buffer_size_8channel_tx_rx[16] = {2, 2, 2, 2, 2, 2, 2, 2, // 8 channel tx
2, 2, 2, 2, 2, 2, 2, 2}; // 8 channel rx

if(ctlwizchip(CW_INIT_WIZCHIP,(void*)buffer_size_8channel_tx_rx))
{
	printf("buffer size set failed!\n");
}

if(socket(1,Sn_MR_TCP,5555,SF_TCP_NODELAY | SF_IO_NONBLOCK) == 1)
{
	printf("TCP Socket open!\n");
}
else
{
	printf("TCP Socket NOT open!\n");
}

}
```

In the body of the infinite loop of the main function, I do this:

```c
for(uint16_t i = 0; i < sizeof(sock_n); i++)
{
	httpServer_run(i);
}
```

In addition, in Carmine Noviello's book on stm32 microcontrollers, in the chapter on the http server, it was said that periodically I have to call the httpServer_time_handler function for the server to work correctly. I initialized the timer, and when it is interrupted, I call a callback function containing the instruction I need.:

```c
void MySysTickCallback(void)
{
	httpServer_time_handler();
}
```

Interrupt:

```c
void TIM1_CC_IRQHandler(void)
{
	HAL_TIM_IRQHandler(&htim1);
	MySysTickCallback();
}
```

I have briefly described my problem, and I am asking for help. I am attaching my project for CudeIDE to the post. Take a look at it, please. I really hope that together with you I will be able to complete my bootloader project, which will be able to expose the firmware over Ethernet.

Attachments:

- [boot.zip](https://maker.wiznet.io/forum/getAttach.asp?aidx=181)

## Replies

### Reply 1 by spacecow, 2025-01-31

I think I can report some small successes.

1. I have reduced the number of working sockets to two.
2. Based on the new number of sockets, I changed the sizes of the data buffers;
3. I was unable to set up a timer overflow interrupt. I don't know why, it's never caused me any problems before. Therefore, I decided to call the httpServer_time_handler function from the interrupt of the system timer. It's probably not very good, but I needed to get at least some kind of performance.

Now my code looks like this:

```c
void http_server_init()
{
	uint8_t http_rx_buff[4096];                             //New buffer size
	uint8_t http_tx_buff[4096];

	uint8_t socknumlist[] = {0, 1};                        //New sock number

	httpServer_init(http_tx_buff,http_rx_buff,2,socknumlist); //Init teo socket''s
	reg_httpServer_cbfunc(NULL, NULL);
	reg_httpServer_webContent((uint8_t*)"index.html", (uint8_t*)webpage);
}
```

```c
void SysTick_Handler(void)
{
	HAL_IncTick();
	MySysTickCallback(); //httpServer_time_handler - in this callback function
}
```

```c
void w5500_init(void)
{
	reg_wizchip_cs_cbfunc(cs_select, cs_deselect);
	reg_wizchip_spi_cbfunc(spi_readbyte, spi_writebyte);

	//Reset chip
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);
	HAL_Delay(1); // delay 1ms
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);
	HAL_Delay(1600); // delay 1600ms

	//Write and read net settings
	ctlnetwork(CN_SET_NETINFO, (void*)&gSetNetInfo); // set net info
	HAL_Delay(500);
	ctlnetwork(CN_GET_NETINFO, (void*)&gGetNetInfo); // get net info

	if(Success == validSetNetInfoResult(&gSetNetInfo, &gGetNetInfo)) // compare
	{
		printf("Net info set success!\n");
	}
	else
	{
		printf("Net info set failed!\n");
	}

/*
uint8_t buffer_size_8channel_tx_rx[16] = {2, 2, 2, 2, 2, 2, 2, 2, // 8 channel tx
2, 2, 2, 2, 2, 2, 2, 2}; // 8 channel rx
*/
	
	//New buffer settings
	uint8_t buffer_size_8channel_tx_rx[4] = {8, 8, // 8 channel tx
	8, 8}; // 8 channel rx


	if(ctlwizchip(CW_INIT_WIZCHIP,(void*)buffer_size_8channel_tx_rx))
	{
		printf("buffer size set failed!\n");
	}

	if(socket(1,Sn_MR_TCP,5555,SF_TCP_NODELAY | SF_IO_NONBLOCK) == 1)
	{
		printf("TCP Socket open!\n");
	}
	else
	{
		printf("TCP Socket NOT open!\n");
	}
}
```

Now my web page is displayed! I made it as simple as possible so as not to strain the memory, but it still loads quite slowly (about 5 seconds, or maybe a little more).

If anyone knows, can you tell me if it is possible to speed up the loading of a web page? In addition, I want to send data to the microcontroller at the touch of a button. I'll find the code for the page, but tell me, which command can I parse or track the data coming from the web page? Thank you in advance for your answers.

---

Source: https://maker.wiznet.io/forum/15552
