This example shows how to build HTTP server using Mongoose library and run it on NXP FRDMK66F development board with FreeRTOS and LWIP.

The source code for this tutorial is located at https://github.com/mongoose-examples/nxp-frdmk66f-freertos

Project structure

In general, the most of the example is regular MCUXpresso IDE project (a lot of generated files, FreeRTOS and LWIP sources etc). Mongoose related functions are located in files source/web_server.c and source/web_server.h. Mongoose itself is locates in source directory as well. Board network configuration (e.g. IP address) can be found in source/web_server.h

General description

First of all, set IP address, network mask and gateway suitable for your network in source/web_server.h file. Default address is Build the sample and run it on development board (see next section). After initialization application starts mongoose events loop and blinks one of board's LED. Once LED started to blink - web server is ready. Open your web browser and navigate to board IP address, you should see hello, world page.

Build options

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

  1. Make command
  2. Using MCUXpresso IDE software

Option 1 - make

Building with make is pretty straightforward for whose, who familiar with this command.

  1. Open terminal
  2. Navigate to project folder
  3. Make sure to have docker installed on your system
  4. Run make build command
  5. Flash board using your favorite tool
  6. Done! See LEDs status to understand application status

Option 2 - MCUXpresso IDE

MCUXpresso IDE is a standard software, provided by NXP Semiconductors. To build this sample with MCUXpresso IDE you need to do the following steps:

  1. Start MCUXpresso IDE
  2. Choose File -> Open Projects from File System...
  3. Pick project directory as Import source, make sure, that nxp-frdmk66f-freertos is checked and click Finish
  4. Check if you have required SDK installed, if not
    • Press Install New Plugin SDKs
    • In board list choose frdmk66f and press Install
    • Once wizard is complete, you should see installed SDK
  5. Choose Debug As -> SEGGER J-Link probes, to build and flash application
  6. You can be asked to choose the board to use
  7. Execution will pause in the beginning of main function, choose Run -> Resume to continue.
  8. Switch to Console tab to see example output
  9. Once LED started to blink - navigate to its address to see "Hello, world!" page

Custom application

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

  1. The obvious way, is to add required functionality to this example. The sample includes all standard HAL Drivers. As you can see, in source/web_server.c file, HAL function is used to turn on LED. In the same way, you can have access to all HAL functions.
  2. If, for any reason, you can't use this example as a base (for ex, you have you own big project to which you need to add mongoose) you can do the following:
    • First of all, if your project uses Redlib consider switching to Newlib (or NewlibNano) - Redlib lacks functions and Mongoose functionality can be limited.
    • If project uses NewLib - enable float usage for printf (Properties->C/C++ Build->Settings->MCU Settings->Enable print float)
    • Add FreeRTOS and LWIP to your project and write (or copy from this example) initialization code
    • Add mongoose.c and mongoose.h files to your project
    • Add mongoose specific configuration flags
    • Add the following defines in 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 preprocessor symbols (Properties->C/C++ Build->Settings->Preprocessor)
    • That's it. Now write code similar to one from source/web_server.c (read Mongoose documentation) and let the magic begin

Modify SDK example

If you want to evaluate NXP and Mongoose and fast and simple as possible, but you don't have NXP FRDMK66F board (but do have another) try to use lwip_tcp_echo_freertos example: it supports a lot of boards.

  1. Copy example to your workspace, choose Newlib while importing
  2. Add mongoose.c and web_server.c to project
  3. Add the same mongoose specific configuration flags as described in Build your own application section
  4. Comment out tcpecho_init(); line in stack_init function and call mg_run_server() instead
  5. Should work! Welcome to Mongoose.