News

Code Small with C# in .NET nanoFramework for Embedded Systems

The .NET Foundation announced a new open source project under its direction, the .NET nanoFramework, which allows for C# coding in Visual Studio for constrained embedded devices.

That means use cases such as:

  • IoT sensors
  • Wearables
  • Academic proofs of concept
  • Robotics
  • Hobbyist/makers creations
  • Industrial equipment

Because code targeting microcontrollers for embedded devices requires a tiny footprint, the platform uses a reduced version of the .NET Common Language Runtime (CLR), a subset of the .NET Base Class Libraries (BCL) and only the most common Universal Windows Platform (UWP) APIs.

Getting more technical, unique features of the .NET nanoFramework are said to include:

  • Can run on resource-constrained devices with as low as 256kB of flash and 64kB of RAM.
  • Runs directly on bare metal. Currently ARM Cortex-M and ESP32 devices are supported.
  • Supports common embedded peripherals and interconnects like GPIO, UART, SPI, I2C, USB, networking.
  • Provides multithreading support natively.
  • Support for energy-efficient operation such as devices running on batteries.
  • Support for Interop code allowing developers to easily write libraries that have both managed (C#) and native code (C/C++).
  • No manual memory management because of its simpler mark-and-sweep garbage collector.
  • Execution constrains to catch device lockups and crashes.

That "uniqueness" was emphasized by the foundation because it readily acknowledged there are other options for embedded systems programming, including Microsoft offerings such as Azure Sphere and Azure RTOS, but those require C/C++.

When using C#, the foundation said, the smallest target developers could aim for is the Raspberry Pi.

As far as third-party options, the foundation said, "none are open source. And none of those allows coding for Expressif ESP32; or ST Microelectronics STM32F0/L0/F4 (to name just a few); or Texas Instruments CC3220 and CC1352; or NXP MIMXRT1060 EVK; or any other new target device that can easily be added."

Debugging in Visual Studio with the .NET nanoFramework
[Click on image for larger view.] Debugging in Visual Studio with the .NET nanoFramework (source: VS Marketplace).

The .NET nanoFramework picks up where the .NET Micro Framework (NETMF), left off, as that 13-year-old project was last updated some four years ago.

Wikipedia says, "On 23 January 2017, after numerous attempts to revive .NET Microframework project and bring it to community governance and a period of work 'in the dark,' a group of embedded systems developers publicly announced .NET nanoFramework as spin-off of .NET Micro Framework."

While community contributors have been driving development of the framework for years, the foundation said being put under its umbrella will hopefully: increase visibility; provide easier access to related .NET teams such as Visual Studio, VS extensibility and .NET project system; and provide tighter integration with the .NET ecosystem.

"We have already started walking down this path with conversations with the .NET Core IoT team, so the first visible changes are due shortly," the foundation's José Simões said in a Sept. 28 blog post.

Development of the .NET nanoFramework is carried out on GitHub and it can be used in Visual Studio 2019 with an extension available in the Visual Studio Marketplace. The extension has been installed 2,848 times as of this writing. There's also a VS 2017 extension.

"Developers can harness a powerful and familiar Microsoft Visual Studio IDE and their .NET C# knowledge to quickly write code without having to worry about the low-level hardware intricacies of a microcontroller," the project says. "Desktop .NET developers will feel at home and are able to use their skills in embedded systems, enlarging the pool of qualified embedded developers."

Getting started guides are available here and Discord discussions can be found here. Discord shows 771 members, with 89 online at the time of this writing. Code samples are available here.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Mastering Blazor Authentication and Authorization

    At the Visual Studio Live! @ Microsoft HQ developer conference set for August, Rockford Lhotka will explain the ins and outs of authentication across Blazor Server, WebAssembly, and .NET MAUI Hybrid apps, and show how to use identity and claims to customize application behavior through fine-grained authorization.

  • Linear Support Vector Regression from Scratch Using C# with Evolutionary Training

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the linear support vector regression (linear SVR) technique, where the goal is to predict a single numeric value. A linear SVR model uses an unusual error/loss function and cannot be trained using standard simple techniques, and so evolutionary optimization training is used.

  • Low-Code Report Says AI Will Enhance, Not Replace DIY Dev Tools

    Along with replacing software developers and possibly killing humanity, advanced AI is seen by many as a death knell for the do-it-yourself, low-code/no-code tooling industry, but a new report belies that notion.

  • Vibe Coding with Latest Visual Studio Preview

    Microsoft's latest Visual Studio preview facilitates "vibe coding," where developers mainly use GitHub Copilot AI to do all the programming in accordance with spoken or typed instructions.

  • Steve Sanderson Previews AI App Dev: Small Models, Agents and a Blazor Voice Assistant

    Blazor creator Steve Sanderson presented a keynote at the recent NDC London 2025 conference where he previewed the future of .NET application development with smaller AI models and autonomous agents, along with showcasing a new Blazor voice assistant project demonstrating cutting-edge functionality.

Subscribe on YouTube