Developing firmware for NodeMCU with Visual Studio

This tutorial shows how to use VisualGDB to create a basic C++ WiFi HTTP server running on the NodeMCU platform.We will program and debug it via the on-board USB-to-UART connection using the GDB stub included in the ESP8266 SDK.

Before you begin, install VisualGDB 5.2 or later.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:01-prjname
  2. Proceed with the default project type:02-prjtype
  3. On the next page select the ESP8266 toolchain and proceed with the regular ESP8266 device. Ensure the “Enable UART GDB Stub” checkbox is checked:03-device
  4. On the Sample Selection page select “HTTP Server (RTOS SDK)” and click “next”:04-rtos
  5. Connect the board to a USB port on your computer:board
  6. Open Device Manager and locate the port number corresponding to the NodeMCU board:05-comport
  7. Go back to the VisualGDB Project Wizard and choose “Bootloader + GDB Stub” as the debug method. Specify the COM port that corresponds to the board and check the “Do not show the ‘reset to bootloader’ message” checkbox. Ensure that “Bootloader reset delay” is set to 50 msec:06-debugWarning: if your debug settings do not show the “Initialization Data File” setting, you are using an old ESP8266 toolchain that is not compatible with NodeMCU. In this case please update your toolchain via Tools->Manage VisualGDB Packages.
  8. Press “Finish” to generate the project. Ensure it builds without errors:07-build
  9. Press F5 to start debugging. VisualGDB will automatically restart your NodeMCU board into the bootloader mode and program it over UART:08-program
  10. Once the programming is complete, the firmware will start and display the IP address of the HTTP server:09-debug
  11. Connect to the “ESP8266_VisualGDB_RTOS” WiFi network and open the IP address of the board in your browser: 10-hello
  12. Congratulations! Your NodeMCU works. Try setting a breakpoint in the ServerTask() function where it parses the HTTP request sent by the browser and refresh the page. The breakpoint will hit and you will be able to step through your firmware:11-bkpt