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 for Converge360.

comments powered by Disqus


Subscribe on YouTube