Main Site Documentation

Pointers in TinyCLR


#1

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: ");
System.Threading.Thread.Sleep(5000);
byte[] b = new byte[20];
PointerUsingMethod(b);
System.Diagnostics.Debug.WriteLine("End: ");
}

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

}

image


#2

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


#3

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?


#4

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.


#5

Thank you, Gus!
COOOOOOOOL!!!

but…

I followed your instruction of the calling of Interop methods, but I stuck.
http://docs.ghielectronics.com/software/tinyclr/native/interops.html

I implemented the MyNativeClass:
p01

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.
p03

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?


#6

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.


#7

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.


#8

Gus,

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.


#9

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/


#10

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


#11

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

and
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)


#12

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.


#13

@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.


#14

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.


#15

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.