Hello, I am new to the TinyCLR OS, but am having some issues with getting the USB to work. When mounting a USB drive (that is formated in FAT32, MBR) I get an exception. I have tried a lot of things but nothing has worked. I get the same result on the DEV board as well as our own device. Please Help.
Code:
public bool usbA_En_Dis(char E_D)
{
var _Enable = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PB10);
_Enable.SetDriveMode(GpioPinDriveMode.Output);
No dice, the enable pin is turning power on to the USB, which the system would not detect the device if it didn’t stay on, which it is detecting it meaning the pin is staying low. I did reference it better to ensure this isn’t the problem just in case but it still gives an exception when trying to mount the drive.
I have also tried the GHI code (found here: USBHost fails) and it still throughs an exception when mounting, I am truly lost as to what could be causing this.
Exception thrown: ‘System.InvalidOperationException’ in GHIElectronics.TinyCLR.IO.dll
Yes, it is a custom board, we enable a relay to make the USB active. This part I know is working because if I do not enable the pin it won’t detect a usb drive connected/disconnected (the connect and disconnect events are working)
The system is powered by a external power supply, so power shouldn’t be the issue, First thing I did was check power in the system (great minds think alike), gets 5V with 2A available. I do not have a powered USB hub readily available but will have to give it a try.
using System;
using System.Collections;
using System.Text;
using System.Threading;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.IO;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.UsbHost;
using System.Diagnostics;
namespace USB_Proto
{
public interface IFLP
{
bool usbA_En_Dis(char E_D);
void usbHostController();
}
}
using System;
using System.Collections;
using System.Text;
using System.Threading;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.IO;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.UsbHost;
using System.Diagnostics;
namespace USB_Proto
{
public class Program
{
static IFLP usbDevice = new FLP200();
static void Main()
{
try
{
usbDevice.usbA_En_Dis('E'); //Enable Power to USB port.
usbDevice.usbHostController();
while (true) { }
}
catch(Exception exc)
{
Debug.WriteLine(exc.ToString());
}
}
}
I figured it out, the drive I reformatted to MBR, but did not setup a simple volume on it so it was not accessible. In disk manager setup a simplevolume and no more exception. Thank you for the help.
I noticed While (true) {} in your Main. Not a good practice if you are doing any threading or event handling. Better to use Thread.Sleep(Timeout.Infinite);
You don’t want your main thread to be competing for resources with your other threads.