Overview
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 192.168.0.10
.
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:
- Make command
- Using MCUXpresso IDE software
Option 1 - make
Building with make
is pretty straightforward for whose, who familiar with this command.
- Open terminal
- Navigate to project folder
- Make sure to have docker installed on your system
- Run
make build
command - Flash board using your favorite tool
- 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:
- Start MCUXpresso IDE
- Choose
File -> Open Projects from File System...
- Pick project directory as
Import source
, make sure, thatnxp-frdmk66f-freertos
is checked and clickFinish
- Check if you have required SDK installed, if not
- Press
Install New Plugin SDKs
- In board list choose
frdmk66f
and pressInstall
- Once wizard is complete, you should see installed SDK
- Press
- Choose
Debug As -> SEGGER J-Link probes
, to build and flash application - You can be asked to choose the board to use
- Execution will pause in the beginning of
main
function, chooseRun -> Resume
to continue. - Switch to
Console
tab to see example output - 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:
- 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. - 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 toNewlib
(orNewlibNano
) -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
andmongoose.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
- First of all, if your project uses
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.
- Copy example to your workspace, choose
Newlib
while importing - Add
mongoose.c
andweb_server.c
to project - Add the same mongoose specific configuration flags as described in Build your own application section
- Comment out
tcpecho_init();
line instack_init
function and callmg_run_server()
instead - Should work! Welcome to Mongoose.