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.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:01-newprj
  2. Proceed with the default “new embedded binary” setting:02-binary
  3. 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).03-device
  4. On the Sample Selection page choose the “HTTP Server” example and press “Next”:04-http
  5. 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:05-debug
  6. Press “Finish” to generate your project. Build it with Ctrl-Shift-B:06-build
  7. 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:board
  8. Start debugging by pressing F5. Observe how the board reports the IP address it gets via the semihosting window:07-got-ip
  9. Open your browser and go to the address of the board:08-browser
  10. 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:08a-rqaddr
  11. Copy the payload buffer address to the Memory window to see the contents of the request received from the browser:09-request
  12. 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: 10-frameworksYou can configure various settings of those frameworks by editing stm32f7xx_hal_conf.h, FreeRTOSConfig.h and lwipopts.h.
  13. 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:codemap
  14. 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.