Pointers in TinyCLR

Hi Guys,

I tried to use pointer in a very simple app, but it freezes every time when I call PointerUsingMethod.
There is no exception, just the program exits from debugger.
I use G80 TH module.

using System;
using System.Collections;
using System.Text;
using System.Threading;

namespace PointerTest
class Program
static void Main()
System.Diagnostics.Debug.WriteLine("Start: ");
byte[] b = new byte[20];
System.Diagnostics.Debug.WriteLine("End: ");

    public static unsafe void PointerUsingMethod(byte[] array)
        fixed (byte* b = &array[0])



Unfortunately unsafe code cannot be used in TinyCLR at this time.

Thank you for your answer John.

So the next question is:
What if, I write a c++ method, I compile It somehow, and compile this in my TinyCLR project, and I call this method like an external method.
Is this possible?

This is one of the great features in TinyCLR. You can easily add native code to do whatever your heart desires. You even dynamically load at run time.

Thank you, Gus!


I followed your instruction of the calling of Interop methods, but I stuck.

I implemented the MyNativeClass:

I checked the two checkboxes on the TinyCLR OS tab.

After the compile I got these files, and I moved them to an other folder, as you recommended.

I downloaded the GCC, but I stuck here, how can I compile these files, and how can I import the compiled files in my visual studio project to upload to the G80TH?

I installed Ubuntu on my windows machine and done compilation that way. I admit the setup to build is a pain but once the setup is done the rest is easy.

We plan on making this easier. This deserves a video tutorial as well.

Have you experimented at all with VisualGDB for Visual Studio? It installs a full GCC compilation and GDB debugging setup into Visual Studio and works with J-Link and STLINKv2 debugging. If you haven’t tried this already, I will write something up. It’s $99 for a license but the time and aggravation savings will pay that off in the first day of use. It certainly felt that way for me. Theoretically, you could even include VGDB and TinyCLR projects in the same solution, though I have not tried that.



I installed Ubuntu, and GCC also. But I don’t know how I can compile my c++ code for TinyCLR, and I don’t know what the make file is. Please help me a little bit, because I am very interested in this hybrid solution, but I can not solve this alone.

The question for “how do I build code in GCC using make” requires a long answer and a tutorial is needed. I am sure there are many examples online but we plan on documenting this better. I hear the guys are experimenting with ideas to even automate this for you. Sorry, there is no short answer to your question. The option @mcalsyn pointed out maybe an alternative as well.

I did a quick search and here is an example http://zaidpirwani.com/1160/stm32f3discovery-arm-gcc-environment-on-windows-part-1/

1 Like

I will try to do a write-up on doing TinyCLR plus native-code in Visual GDB in the next few days.


thanx @Gus_Issa

from your provided (searches) site http://zaidpirwani.com/1160/stm32f3discovery-arm-gcc-environment-on-windows-part-1/

i’ve tried this

on http://gnuwin32.sourceforge.net/packages/make.htm
got those three files copied onto

C:\Program Files (x86)\GNU Tools Arm Embedded\7 2018-q2-update\bin

C:\Program Files (x86)\GNU Tools Arm Embedded\7 2018-q2-update\arm-none-eabi\bin

seems now MAKE is available from command prompt

another searches

Getting Started with the ARM GCC Compiler on Windows, Part 1: Installing GCC and Eclipse(http://thehackerworkshop.com/?p=391)

Getting Started with the ARM GCC Compiler on Windows, Part 2: Creating a FOSS Build Environment for the STM32F0DISCOVERY Board and Building the Demo Project(http://thehackerworkshop.com/?p=443)

Getting Started with the ARM GCC Compiler on Windows, Part 3: Making a Template Project(http://thehackerworkshop.com/?p=626)

Getting Started with the ARM GCC Compiler on Windows, Part 4: Our First Real Project(http://thehackerworkshop.com/?p=710)

Getting Started with the ARM GCC Compiler on Windows, Part 5: Debugging with OpenOCD(http://thehackerworkshop.com/?p=602)


To add a bit more detail:

If you’re on Windows, the gcc installer you want is on https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads, under Windows ZIP. When installing make sure to let it get added to the PATH.

If you want to use Linux, the easiest way I’ve found to get make is to use the Windows Subsystem for Linux. https://docs.microsoft.com/en-us/windows/wsl/install-win10 walks you through getting that setup.

Once you have it working, open the shell for your distro and install make and gcc. There are a few different packages you could choose. If you’re on ubuntu, two choices are build-essentials and make. sudo apt-get install [package] is the command to install a package.

Since the Windows filesystem is available from the Linux shell, you can browse to your folder that has the native code in it, like cd /mnt/c/Users/john/Desktop for example.

You’ll want to make sure you’ve copied the makefile and scatterfile examples from http://docs.ghielectronics.com/software/tinyclr/native/interops.html to files called makefile and scatterfile, respectively, no extension, into the directory where your code is.

Of course, as Gus mentioned, we do have plans to make all this easier in the future.

@mcalsyn - Based on your experience, would you be willing to share some pros and cons of C/C++ with Visual GDB vs C#/.Net Micro or TinyCLR with Visual Studio? I’d be happy to move this question to a different thread is that would be more appropriate.

Yeah - we can have a longer discussion on another thread. But it’s not an either/or decision. You can have the best of both worlds with native (C/C++) code as a performance/capability enhancer for TInyCLR.

As mentioned above, I’ll do an article that covers TinyCLR augmented with VisualGDB native code (potentially in the same sln file) likely before next Monday (and if I can pull it off :stuck_out_tongue_winking_eye:). But if you want to discuss the tradeoffs between native, managed, and hybrid apps, happy to do that on another thread.


Hi Guys,

Sorry for my late comment, but I was looking for some other components of the TinyCLR, and I have read that the ENC28 chip is not supported in TinyCLR, therefore I have to rollback to .NetMF 4.3.

Thanks for everybody, for the help.

@mcalsyn, if you find the time I would appreciate your proposed article covering TinyCLR augmented with VisualGDB. Thank you.

I put that aside because Gus did an excellent series on doing it natively in VS without VisualGDB. I haven’t tried those instructions yet, so I don’t know if they are easier or harder in the long-run. VGDB is $99, but I do like the fact that I don’t have to maintain my own tool-chain and all the plumbing.

I’ll consider whipping up some instructions this coming weekend if Gus’s instructions aren’t what you’re looking for.

1 Like

Thank you, it would be appreciated but only at your convenience. No rush or expectation, I know you are working on an exciting project. I would like to explore VisualGDB, as you pointed out it looks after the tool-chain allowing a focus on the code and hardware. It has been some time since I programmed at that level and I am looking for tutorials, etc. to ease back. I haven’t had the chance to try Gus’s tutorial, it is also on my list. Thanks.