|
|
View previous topic :: View next topic |
Author |
Message |
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
USB CDC on FreeBSD or similar? |
Posted: Thu Apr 05, 2012 8:48 am |
|
|
I've recently built a FreeNAS system using a Chenbro ES34169 case. The case has hot-swap bays with failure LEDs for each bay. FreeNAS does software raid, so there is no hardware to control those failure LEDs, but they would be really handy!
My idea was to control those LEDs via a 18F2455 using USB CDC. I'd write some software to regularly check the drives and send status updates to the PIC, which would update the LEDs.
While I waited for the nas hardware to turn up, I built and tested a board using my Windows PC. That worked just fine.
The problem now is that the FreeNAS OS - FreeBSD 8.2 - does not correctly handle the PIC. I wasn't surprised that the default VID and PID of 0x0461 and 0x0033 respectively wouldn't be recognised. So I had the idea of trying IDs belonging to FTDI and Prolific and pretending to be a known USB-Serial adapter.
The closest I've been able to get is with the FTDI IDs. Then I get a /dev/cuaU0, but trying to echo commands to that device does nothing. The messages I get in dmesg are: Code: | ugen2.2: <CCS> at usbus2
uftdi0: <CCS SERIAL DEMO, class 2/0, rev 1.10/1.00, addr 2> on usbus2
uftdi0: allocating USB transfers failed
device_attach: uftdi0 attach returned 6
uftdi0: <CCS SERIAL DEMO, class 2/0, rev 1.10/1.00, addr 2> on usbus2
uftdi0: allocating USB transfers failed
device_attach: uftdi0 attach returned 6
uftdi0: <CCS SERIAL DEMO, class 2/0, rev 1.10/1.00, addr 2> on usbus2 |
Trying the Prolific IDs resulted in USB_DEVICE_STALLED errors, and no /dev/ device.
It seems I'm down to two choices: try to find a different VID/PID that will work, or try to get FreeBSD to accept the CCS VID/PID as a serial device. I'm wondering if anyone else has managed to do that?
Edit: mixed up some FTDI/Prolific references _________________ Andrew
Last edited by andrewg on Sun Apr 08, 2012 11:57 pm; edited 1 time in total |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Apr 05, 2012 2:36 pm |
|
|
Your problem is that you need a DRIVER to map it as a virtual com port.
Thats why it is NOT mapped as a /dev.
Try this link ;-)
http://www.ftdichip.com/Drivers/VCP.htm |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri Apr 06, 2012 7:56 am |
|
|
Thanks for the link, but that page doesn't even mention FreeBSD!
You did raise a good question; I wasn't totally sure the required support was in FreeBSD, but I was confident since the Prolific IDs resulted in getting /dev/cuaU0.
I found an actual Prolific USB-Serial adapter (which uses the exact same VID and PID as I was faking) and plugged it in. It was immediately recognised and I was able to echo characters to /dev/cuaU0 and have them appear to another computer.
So all the required OS support is there, something is missing at the PIC end, most likely in the CCS USB CDC library. At this point I think I'm going to ditch the 18F2455 and use a standlone USB-serial chip to interface to a PIC, or maybe even an Arduino! (Never used one of those before) _________________ Andrew |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Apr 06, 2012 8:03 am |
|
|
One benefit from using a USB-serial adapter is it'll free up about 1/3 of the code space since the PIC doesn't need the USB code.
Just be sure that the adapters WORK! I have 3 here, 2 don't run 'right', so it appears there's no 'standard' for them either ....arrgh....Useless Serial Bus |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Apr 08, 2012 12:31 pm |
|
|
I've used the standard CDC driver with Ubuntu linux without any problems.
Historically, I have used the standard CDC driver with several other Linux distributions, and most recognised it straight away, while a few had to be 'told' the device was just a USB CDC device, by adding the ID's to the list of supported devices. I'd suspect the same would be true with FreeBSD.
You might want to try "kldload umodem", whick will tell FreeBSD to load the USB modem module which should be the one needed for the CCS device. Try with the chip setup first with the CCS VID/PID, and then with the Microchip ID's, which are possibly more likely to be included.
Best Wishes |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sun Apr 08, 2012 11:53 pm |
|
|
@hmmpic: Thanks for those links. As I'm trying to fit this board inside a case I'm trying to reduce unnecessary cable lengths, although as it will be inside the box I guess it's less important. *I'll* know though The PCB assemblies from FTDI look like just the thing!
@Ttelmah: As far as I can tell, to add VID/PIDs to FreeBSD requires building a custom kernel, which is something I'm trying not to do. It would be a whole lot better to "just work". Since I have an actual Prolific cable to compare against, I've decided the most likely path is to replicate that, and I've had some good progress.
It turns out FreeBSD is sending some vendor-specific commands. The code to handle that goes into USB.C in the function usb_isr_tok_setup_dne: Code: | #if USB_CDC_DEVICE
case 0x21:
debug_usb(debug_putc," cdc");
usb_isr_tkn_cdc();
break;
// NEW CODE STARTS HERE
case 0x40:
if (bit_test(usb_ep0_rx_buffer[0], 7)) {
switch (usb_ep0_rx_buffer[2]) {
case 0x83:
usb_ep0_tx_buffer[0]=0;
usb_request_send_response(1);
break;
case 0x84:
usb_ep0_tx_buffer[0]=2;
usb_request_send_response(1);
break;
default:
usb_request_stall();
break;
}
} else {
usb_put_0len_0();
}
break;
// NEW CODE ENDS HERE
#endif | That's faked things enough to initialise. The problem now is that the PIC is NAKing the serial data sent to it! Weird. Must be almost there, though. _________________ Andrew |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sun Apr 15, 2012 7:21 am |
|
|
Well, I've given up on faking the Prolific. I got as far as turning on the CCS USB debugging stream and seeing what appeared to be IN packets on endpoint 2. The problem is that my logic analyser was showing OUT packets on end point 2 - which is what would be expected when sending data from the PC.
At this point I was stumped and so returned to the suggestion from Ttelmah to use umodem. The problem is that there was no umodem support in FreeNAS! FreeNAS does not build with that module by default, but does build with the lower level ucom driver, plus drivers to handle the FTDI, Prolific, plus some other USB-Serial adapters. So I have ended up having to figure out how to build my own FreeNAS, and customise it to include umodem support.
After all that, my FreeNAS now recognises when my PIC is plugged in, and it creates cuaU0 and ttyU0 devices. I've programmed my PIC as follows: Code: | void main(void) {
int1 first = TRUE;
usb_init_cs();
for (;;) {
restart_wdt();
usb_task();
if (usb_enumerated()) {
if (usb_cdc_connected()) {
if (first) first=FALSE,output_low(PIN_B2); // turns LED on
if (usb_cdc_kbhit()) {
output_float(PIN_B2); // turns LED off
usb_cdc_putc_fast(usb_cdc_getc());
}
}
}
}
} | Plug it in, the LED is off. When the serial port is opened the LED turns on, and when the first character is received the LED turns off again. It also echoes characters it receives.
This works fine on my Windows PC. It works on my FreeNAS PC up to the point where it should be sending/receiving characters. If I do: Code: | echo X > /dev/cuaU0 | the LED turns on (meaning it got as far as usb_cdc_connected), and stays on! Further echo commands block and I have to Ctrl-C them. Running "cat /dev/cuaU0" in the background stops the blocking, but no characters are displayed, and the LED doesn't turn off (meaning the PIC CDC hasn't received any characters).
I've tried "stty -f /dev/cuaU0.init raw" to try to reset things, or at least turn off flow control (which it appears to do).
I don't know what else to try, so I'm stuck again and hoping the FTDI boards I've now ordered work better!
Thanks to everyone who replied. I wouldn't have got this far without the various suggestions. _________________ Andrew |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|