Creating a basic HTTP server with STM32F7-Discovery
This tutorial shows how to create a very basic HTTP server project with the STM32F7-Discovery board using the lwIP library and VisualGDB. Before you begin, install Visual Studio and VisualGDB 5.1 or later.
- Start Visual Studio and open the VisualGDB Embedded Project Wizard:
- Proceed with the default “new embedded binary” setting:
- On the next page of the wizard select the ARM toolchain and choose the STM32F746NG device used on the STM32F7-Discovery board. If you are using a different board, you would need to copy the hardware setup functions from the examples for that board (more details in the end of this tutorial).
- On the Sample Selection page choose the “HTTP Server” example and press “Next”:
- Finally select a debug method that works with your board. For most STM32 boards you can simply select OpenOCD and plug the board in to get the settings auto-detected:
- Press “Finish” to generate your project. Build it with Ctrl-Shift-B:
- Ensure the on-board ST-Link is connected to your computer and that the Ethernet port is connected to a network with a valid DHCP server:
- Start debugging by pressing F5. Observe how the board reports the IP address it gets via the semihosting window:
- Open your browser and go to the address of the board:
- Set a breakpoint after the call to the netconn_recv() and refresh the page in your browser. Hover the mouse over the inbuf variable to find out the address of the payload buffer:
- Copy the payload buffer address to the Memory window to see the contents of the request received from the browser:
- Now we will quickly go through the components used by the server example. The project relies on the STM32 HAL library, FreeRTOS library for multi-threading support and the lwIP library for the network functionality. You can add and remove references to these frameworks via VisualGDB Project Properties: You can configure various settings of those frameworks by editing stm32f7xx_hal_conf.h, FreeRTOSConfig.h and lwipopts.h.
- The central point of the application is the MainThread() function. It calls the netconn API functions such as netconn_accept() that are similar to the normal socket functions. You can use the Code Map provided by the Clang IntelliSense to quickly visualize the relations between the functions:
- If you want to target a different board, you need to replace the SystemClock_Config() function in the main file and the entire ethernetif.c file with the ones from an Ethernet example for your board. Note that ethernetif.c files from non-RTOS examples are not compatible with the RTOS-based examples.