flashear-firmware-nanoframework

How to flash nanoFramework on ESP32 and STM32

  • 5 min

The nanoFramework firmware is the image that installs the nanoCLR on the microcontroller so it can run our C# applications.

So far, we have a development environment on our PC and a microcontroller connected via USB. We still need to make them speak the same language.

Your ESP32 (or STM32) likely comes from the factory speaking “AT Commands” or has remnants of an old Arduino program. For it to understand C# and execute our .NET code, we need to install the nanoCLR.

This process is called flashing the firmware and is similar to installing an operating system on a computer.

To do this, we will use the command-line tool nanoff that we installed in the previous entry. It takes care of downloading the correct image and writing it to the board.

The nanoCLR (Common Language Runtime) is the virtual machine that will run inside the chip. It manages memory, threads, and translates your compiled C# code into instructions that the processor understands.

Identify the serial port (COM)

The first thing is to know where our device is connected.

Connect your board to USB.

On Windows, right-click the Start button and open Device Manager.

Expand the Ports (COM & LPT) section.

You should see something like Silicon Labs CP210x USB to UART Bridge (COM3) or USB-SERIAL CH340 (COM4).

Remember that number: COM3 (in my case). That is your board’s ID right now.

Using nanoff with ESP32

The ESP32 is the simplest device to flash because everything is done through the same USB cable.

Open a terminal (PowerShell, CMD, or the integrated terminal in Visual Studio) and get ready.

Specify the platform and target

nanoff requires us to specify the target compatible with our board. We can first check the available targets:

nanoff --listtargets --platform esp32
Copied!

You will see names like ESP32_REV0, ESP32_PICO, or specific targets for different variants. Always use the name that appears in the list, as it may change as new boards are added.

  • If you have a standard ESP32 (DevKit V1): Use ESP32_REV0.
  • If you have an ESP32 with PSRAM (WROVER): Use ESP32_PSRAM_REV0.
  • If you have an ESP32-S3: Use ESP32_S3.

Once chosen, the command looks like this:

nanoff --target ESP32_REV0 --serialport COM3 --update
Copied!
  • --target ESP32_REV0: indicates the specific image we are going to install.
  • --serialport COM3: selects the board’s port (change it to yours).
  • --update: downloads the latest available version and installs it.

Upon completion, you should see the message Firmware update ended successfully.

Connection error? Press the BOOT button! Some ESP32 boards do not enter programming mode automatically. If you see nanoff stuck on “Connecting…” and then an error:

  1. Hold down the BOOT button on the board.
  2. Execute the command.
  3. When you see it starting to erase (“Erasing…”), release the button.

Configure Wi-Fi during flashing

During flashing, we can also save the Wi-Fi network configuration. This avoids writing the password directly in the application code.

Simply add the --ssid and --password flags:

nanoff --target ESP32_REV0 --serialport COM3 --update --ssid "MyHome_WiFi" --password "supersecret123"
Copied!

The device will store this data in its non-volatile configuration block. We should not assume it is encrypted: for a real product, both physical access and the credentials used must be protected.

Using nanoff with STM32

For STM32 boards (like Nucleo or Discovery), the process is usually done through the ST-LINK programmer that comes integrated on the board.

On STM32, we must also select the exact target. We can locate it with:

nanoff --listtargets --platform stm32
Copied!

Then run the update specifying the target. Depending on the board, nanoff will use the available tools and programmer.

nanoff --target TARGET_NAME --update
Copied!

If you have an STM32 board that connects via direct USB (DFU mode), you will need to use the --dfu flag.

Verify the installation

Once the console tells you it has completed successfully, it’s time to verify it in Visual Studio.

Disconnect and reconnect the board’s USB (to force a reboot).

Open Visual Studio.

Open the Device Explorer window (View > Other Windows > Device Explorer).

Now, after a few seconds of scanning, you should see your device in the list, showing information like:

  • Name: ESP32_REV0 @ COM3
  • Version: the installed nanoCLR version

If it appears there… Congratulations! You have a .NET device ready to take orders.

If the device appears but says “disconnected” or does not respond, try pressing the Reset (EN) button on the board while the Device Explorer is open.

Troubleshooting common issues

  • Permission Denied / Access Denied: Close any other program using the serial port (like the Arduino IDE Serial Monitor or Putty).
  • Wrong Target: If you flash an ESP32_S3 onto a standard ESP32, the process will fail or the chip won’t boot. Make sure you know your model correctly.
  • Reset loop: If after flashing, the board’s LED blinks very fast or the Device Explorer connects and disconnects, the power supply (USB) might not provide enough current, or you may have chosen an incompatible target.

We now have the hardware chosen, the environment installed, and the firmware flashed. We have overcome the most “arid” part of the setup. From now on, it’s all about creating code 💛.