STM32 Nucleo-H743Z


This example shows how to build an HTTP server using Mongoose Library and run it on an STM32 Nucleo-H743Z development board with FreeRTOS and lwIP.

The source code for this tutorial is located at

A big part of this example is a regular STM32CubeIDE project (a lot of generated files, FreeRTOS and lwIP sources, etc.). Project structure will vary depending on the STM32CubeIDE version and how much of the project was generated using the STM32CubeMX tool. Old versions used to have the Inc and Src directories right on the root of the project, while newer versions put those under a Core directory. Also, we may find specific configuration options like the IP address in Inc/main.h, while newer auto-generated versions use specific directories; for example the IP address is inside the MX_LWIP_Init() function, in file lwip.c, under the LWIP directory.

Mongoose-related functions are located in Src/web_server.c

Below is a general process outline:

  • Set IP address, network mask and gateway in Inc/main.h
  • Build the example (see below) and run it on a development board
  • The firmware initializes the network, and turns on a green LED if the initialization was successful, a red one otherwise
  • If you see a red LED turned on, make sure that your Ethernet cable is properly connected to the board
  • After initialization, the application starts Mongoose's event loop and blinks a blue LED
  • Once the blue LED starts blinking - the web server is ready
  • Open your web browser and navigate to the board IP address, you should see a "Hello, world" page

Build options

There are (at least) two options to build the example:

  1. Using the make command
  2. Using the STM32CubeIDE IDE

Option 1: make

  • Follow the Build Tools tutorial to setup your development environment.
  • Start a terminal, navigate to the project folder, and from there run
    make build
  • When build finishes, run
    make flash

Done! Now the firmware is flashed and the board should signal its state via an LED indicator (green or red).

Option 2: STM32CubeIDE

STM32CubeIDE is an IDE software provided by STMicroelectronics. We'll be importing the project so it has to be present in your filesystem, so first run make to clone the git repository; unless you've already tried Option 1 above.

  • Start STM32CubeIDE
  • Choose File -> Import..., then open General and select Existing Projects into Workspace:STMCube open project
  • Pick a project directory as Root directory, make sure that NUCLEO-H743Zx-simple-web-server is checked and click Finish:finish pic
  • After import, you'll probably have to close the "Information Center" window so you can actually see the project. Click on the project in the Project Explorer tab, now click on the hammer icon to build the project, then on the green arrow icon to flash the project. You can also right click on the project and select Run As -> STM32 C/C++ Application:run as pic
  • Done! The firmware should light the LEDs

Debug output

During execution, Mongoose can print debug information. There are several ways to receive this information. This example re-routes stdout to the SWV ITM Console. This allows us to see the output of printf() and similar functions directly in STM32CubeIDE. For this, you need to do the following:

  1. Choose Run -> Debug configurations...: debug configurations
  2. Under STM32 C/C++ Application select the NUCLEO-H743Zx-simple-web-server configuration. Note: if you don't see this configuration, close the dialog and start the debug session via Debug as -> STM Application to create it: Debug as..
  3. Go to the Debugger tab
  4. Make sure you are using SWD mode (and not JTAG). Check Enabled in the Serial Wire Viewer section
  5. Update the Core clock setting, set it to 400MHz
  6. Click Apply and then click Debug to start the debug session. You will probably be asked to switch to the "Debug" perspective, do it.
  7. Once the application stops at the beginning of the main function, open the SWV Console (Window->Show View->SWV->SWV ITM Data Console)
  8. If there is not already a "port 0" tab, click Add port and add port 0 SWV ITM Data Console pic
  9. Click Configure trace and verify port 0 is enabled, or enable it Configure trace pic Port 0 is enabled pic
  10. Click Start trace Start trace pic
  11. Resume program execution
  12. You should see something like this in the console window:
    1970-01-01 00:00:00  I web_server.c:30:server    Starting Mongoose v7.4
    1970-01-01 00:00:00  I mongoose.c:3297:mg_listen 1 accepting on (port 80)
  13. Done! Now you can use the printf() function or the LOG() macro to output required information

Custom application

In order to create your own Mongoose-enabled application you have several ways:

  1. The obvious way, is to add the required functionality to this example. The sample includes all standard HAL Drivers. As you can see in the Src/web_server.c file, the BSP_LED_On() function is used to turn on an LED. In the same way, you can have access to all the HAL functions.

  2. If, for some reason, you can't use this example as a base (e.g.: you have your own big project to which you need to add Mongoose), you can do the following:

    • Add FreeRTOS and lwIP to your project (via Device Configuration tool or manually, depending on your project type)
    • Initialize FreeRTOS and lwIP. Read this STM article.
    • Add the mongoose.c (and .h if you want) file(s) to your project
    • Add Mongoose-specific configuration flags
    • Add the following defines in the lwipopts.h file:
      #define LWIP_SOCKET                     1
      #define LWIP_POSIX_SOCKETS_IO_NAMES     0
      #define SO_REUSE                        0
    • Add MG_ARCH=MG_ARCH_FREERTOS_LWIP to the preprocessor symbols (Properties->C/C++ Build->Settings->Preprocessor)preprocessor symbols pic
    • Enable float usage for printf (Properties->C/C++ Build->Settings->MCU Settings->Use float with printf)preprocessor symbols pic
    • Done! Now write code similar to that in Src/web_server.c (read Mongoose documentation) and let the magic begin
  3. If you want to evaluate STM and Mongoose as fast and simple as possible, but you have a board that is not covered by any of our examples and tutorials, try to use the LwIP_HTTP_Server_Netconn_RTOS example: it supports a lot of boards.

    LwIP_HTTP_Server_Netconn_RTOS example pic
    • Copy the example to your workspace
    • Add mongoose.c and web_server.c to your project
    • Add the same Mongoose-specific configuration flags as in point 2
    • Comment out netconn initialization (probably in the StartThread() function) and call start_mongoose() instead
    • That's it! Your application should build and run Mongoose.