While this is generally for Advanced Users, others may be up for the challenge.

Using the Marshal class from within TinyCLR OS can be like a magic wand for users with the knowledge to harness its power. Advanced users can directly access the SITCore processor, and make it do special “magic tricks”.

A good example demonstrating this is when working with SD cards.  Some SD cards don’t always play nicely with processors, because of the frequency of the signal. This could be because a circuits design might place the SD card reader too far away from the processor or lower-cost slower SD cards.

Using the Marshall class, we can directly access the processor and slow down the clock speed of the SD reader. We do exactly that here in the sample code below:

const int SD_CLOCK_ADDRESS_REG = 0x00000004;

var clock_divider = 4; // 0,1,2,3 are 25MHz, 4: 12MHz, 5: 10MHz, 6: 8MHz...
Marshal.WriteInt32((IntPtr)SD_CLOCK_ADDRESS_REG, clock_divider);

The Marshall class methods are essential in providing a bridge between managed and unmanaged code.