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
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
itself is locates in
source directory as well. Board network
configuration (e.g. IP address) can be found in
First of all, set IP address, network mask and gateway suitable for your
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.
There are (at least) two options to build the sample:
- Make command
- Using MCUXpresso IDE software
Option 1 - make
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
- 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
File -> Open Projects from File System...
- Pick project directory as
Import source, make sure, that
nxp-frdmk66f-freertosis checked and click
- Check if you have required SDK installed, if not
Install New Plugin SDKs
- In board list choose
- Once wizard is complete, you should see installed SDK
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
Run -> Resumeto continue.
- Switch to
Consoletab to see example output
- Once LED started to blink - navigate to its address to see "Hello, world!" page
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.cfile, 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
Redlibconsider switching to
Redliblacks 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
mongoose.hfiles 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
MG_ARCH=MG_ARCH_FREERTOS_LWIPto preprocessor symbols (
- 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
- Add the same mongoose specific configuration flags as described in Build your own application section
- Comment out
stack_initfunction and call
- Should work! Welcome to Mongoose.