Author Topic: PIC18F2550 USB project  (Read 1366 times)

0 Members and 1 Guest are viewing this topic.

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
PIC18F2550 USB project
« on: September 22, 2017, 08:38:54 PM »
I've searched in the threads here and googled this topic as well.
What I found was some random asm code thrown around and confusing jargons.


If you be so kind and answer these questions(you don't have to answer all of them), I'm sure i'll understand.


  • Do I have to install a usb-port listener/custom USB firmware on the OS to listen to/understand what the chip is sending ?
  • Do I need an external physical "usb-communicator" hardware between the chip and the usb port of the PC for them to communicate ?
  • Could someone point me a certain book that could be useful ? and would be a huge plus if it uses pic18 chips for examples.(I code in C)
  • Could someone point me the page in the datasheet where it explains this further, because the word USB word return 562 results in the datasheet and i don't know where to start.
  • Do you have some sort of a skeleton C project for this ?

About point 3, I did have a pdf book previously, I forgot it's name and lost the printed hard copy, when I moved, it would be really nice if you pointed me to a free/downloadable book.


Thank you so much, in advance  :)
« Last Edit: September 30, 2017, 12:02:25 AM by MAD MACRO »
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 1018
  • Country: gb
Re: PIC18F2550 USB project
« Reply #1 on: September 22, 2017, 09:00:47 PM »
I have been meaning to do something similar with an old joystick...

with a google I found

 http://www.waitingforfriday.com/?p=451

looks quite relevant.

 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #2 on: September 22, 2017, 09:37:39 PM »
I like his code and his comments are very helpful, I feel lost without reading the datasheet, but i'm gonna give it a good reading first.

Thank you  :-+
 

Online stj

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: gb
Re: PIC18F2550 USB project
« Reply #3 on: September 23, 2017, 07:04:37 AM »
i made one of these:
http://kentie.net/article/sunkbd/

you can see from the schematic just how little you actually need to add!!
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #4 on: September 23, 2017, 07:33:26 AM »
Do I have to install a usb-port listener/custom USB firmware on the OS to listen to/understand what the chip is sending ?
Are you talking about a "driver"?

Completely depends on the device class you're targeting. If you wanted to make a USB device that appeared as an HID keyboard, no, there's no drivers to write. If you wanted to build a USB scanner that implemented a TWAIN interface, yes, you'd probably need to write a driver, as that's not a class-compliant device. Many people abuse the "HID Generic" spec to avoid having to write drivers, and instead, talk to the HID device directly from their application (using Hid.dll on Windows, or rawhid on Linux, etc). My preferred option is a Vendor-class (0xff) device, with WinUSB support to make the process driverless.

Do I need an external physical "usb-communicator" hardware between the chip and the usb port of the PC for them to communicate ?
No. The PIC18F2550 has a USB interface (I assume you knew this when you selected this chip, no?)

Could someone point me a certain book that could be useful ? and would be a huge plus if it uses pic18 chips for examples.(I code in C)
I think your biggest roadblock won't be the firmware running on the MCU, but rather, the fact that you don't seem to understand much about computer software. I feel like someone who has cursory knowledge of software development on computers would ask questions more in line with "does anyone know of a good user-mode .NET library for USB communication in Windows?" or something like that. I mean, you didn't even mention which operating system you're using — any sort of software interfacing is going to vary widely by the OS.

Could someone point me the page in the datasheet where it explains this further, because the word USB word return 562 results in the datasheet and i don't know where to start.
Now I feel like you're just trolling us. The Table of Contents on the 6th page of the datasheet lists "17.0 Universal Serial Bus (USB)" and going to that chapter reveals information about the USB interface on the chip.

I think you think USB is something like RS-232, where you toggle a few bits in a register, and then you can start spewing bytes out the port. Wrong. There's device, class, and endpoint descriptors, control, interrupt, bulk, and isochronous endpoints. Your device has to be able to properly respond to host requests for these descriptors (all the chapter 9 stuff). You don't generally program the USB peripheral using a datasheet; instead, you use the manufacturer's USB stack — their library that handles all the low-level control-transfer details, and exposes and endpoint interface to you, the developer, to customize. Most people working on the PIC stuff start with Microchip's MLA library, which includes several USB examples. However, be prepared for an up-hill climb — this stuff can be challenging to wrap your head around.
« Last Edit: September 23, 2017, 07:38:37 AM by funkathustra »
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #5 on: September 23, 2017, 08:14:28 PM »
i made one of these:
http://kentie.net/article/sunkbd/

you can see from the schematic just how little you actually need to add!!


Nice work, man.   :-+ I'm sure this is gonna be useful at a certain point in my project.



v Many people abuse the "HID Generic" spec to avoid having to write drivers, and instead, talk to the HID device directly from their application (using Hid.dll on Windows, or rawhid on Linux, etc). My preferred option is a Vendor-class (0xff) device, with WinUSB support to make the process driverless.
Sounds like your preferred solution is not a cross platform one.

No. The PIC18F2550 has a USB interface (I assume you knew this when you selected this chip, no?)
Yes, that's why I bought it, but USB interface here could mean many things, is it ready to understand USB signal data but it's my job to do send them right ? or is it read to communicate right on the go once i plug it correctly to starting shooting bits ? you already answered that in a later point.

I think your biggest roadblock won't be the firmware running on the MCU, but rather, the fact that you don't seem to understand much about computer software. I feel like someone who has cursory knowledge of software development on computers would ask questions more in line with "does anyone know of a good user-mode .NET library for USB communication in Windows?" or something like that. I mean, you didn't even mention which operating system you're using — any sort of software interfacing is going to vary widely by the OS.
Your assumption is wrong, i'm actually a software developer, did plenty of C++,C#/.NET,JAVA apps and some web developing as well, I know exactly what i'm talking about, but i'm talking to hardware engineers, I just didn't wanna overwhelm anyone with things they might not understand, after all it's not the same field.

I'm using Archlinux OS, XC8 compiler, pickit2 programmer.
about the .NET thingy: that crap is the bane of my existence, it's evil and bloated, and im using linux anyway, and please don't mention wine :D

Now I feel like you're just trolling us. The Table of Contents on the 6th page of the datasheet lists "17.0 Universal Serial Bus (USB)" and going to that chapter reveals information about the USB interface on the chip.
I'm not trolling anyone, i'm one of the people that dont read the table of contents, sry.

I think you think USB is something like RS-232, where you toggle a few bits in a register, and then you can start spewing bytes out the port.
Who told you can read my mind ? :D

You don't generally program the USB peripheral using a datasheet; instead, you use the manufacturer's USB stack — their library that handles all the low-level control-transfer details, and exposes and endpoint interface to you, the developer, to customize.Most people working on the PIC stuff start with Microchip's MLA library, which includes several USB examples. However, be prepared for an up-hill climb — this stuff can be challenging to wrap your head around.
Thank you so much for that info.

I've got alot of reading ahead of me. I know my questions might now sound strange, but when you don't know what you don't know, you just don't know what to ask, but I think you gave me that light at the end of the cave, thank you.





« Last Edit: September 23, 2017, 11:06:28 PM by MAD MACRO »
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #6 on: September 24, 2017, 08:28:00 AM »
You still haven't told us what you're trying to implement. If it's a class-compliant device, almost everything I've mentioned thus far will be completely irrelevant, as you won't have any choice how to implement the USB descriptors.

Can you tell us more about your project?

My preferred option is a Vendor-class (0xff) device, with WinUSB support to make the process driverless.
Sounds like your preferred solution is not a cross platform one.

Vendor-class devices can easily be opened in Linux using LibUSB, which is included in basically every Linux system I've ever seen (even on, like, wifi routers).

And, actually, I think Vendor-class devices are easier to use on Linux than HID devices are, as the kernel doesn't swallow them automatically, requiring udev rules for rawhid and stuff like that (maybe that's changed, though?)

Making your device WinUSB-compliant doesn't change at all how you interface with it on macOS or Linux. WinUSB is something you can choose to implement in your device firmware to automatically load the WinUSB driver on Windows, so you won't have to deal with INFs.

Since it sounds like you don't need to target Windows, you don't need to implement WinUSB extensions, though I personally try to stay platform-agnostic, and make sure my stuff works well on Windows, Linux, and macOS, if possible.

Your assumption is wrong, i'm actually a software developer, did plenty of C++,C#/.NET,JAVA apps and some web developing as well, I know exactly what i'm talking about

You tricked me by using phrases like "usb-port listener" and "custom [operating system] USB firmware" instead of phrases like "Linux kernel module" or "user-space USB access" — and you still haven't told us which framework/language you want to target, though you did finally mention you were trying to get something going in Arch Linux.

Unless I'm implementing a class-compliant USB device, most custom USB projects I've worked on have been about 15% MCU firmware, and 85% desktop software, in terms of development involvement. Implementing class-compliant devices, unless you're working from an example, can be sort of complicated (unless they're basic HID devices). Plenty of small shops ignore class-compliance, and just do vendor-specific devices they can interface with directly in their software. It's hacky and terrible, but it's cheap. Totally depends on your goals.
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #7 on: September 26, 2017, 02:14:59 AM »
sry for my late reply, I have an exhausting full-time job

For now, i'm keeping it simple to learn how to deal with usb, so i'm gonna use HID API for host code, but the main project that I wanna make is to have data shown to me on the PC to deal with them, whatever the data is, the small LCD screen is not gonna help and the processing power of the PC is far more superior.


For the host code, I installed the HID API, got the example code, got it compiled, but getting seg fault on run, currently working on it.

For the firmware, i'm browsing the mla library dir for example code, but by looking at the dir names, i think they are supporting certain chips in the examples, pic24, pic18f87XX & pic18f47XX, not sure why they didn't add one example for pic18fX5XX, but i'm sure i'll figure it out.


EDIT: was getting the seg fault, cuz of the the code is trying to communicate with a non existing usb device(hid_device handle was empty), removed all the functions except hid_init and hid_exit and it worked fine.
« Last Edit: September 26, 2017, 03:47:32 AM by MAD MACRO »
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #8 on: September 26, 2017, 06:14:22 AM »
MLA demos always target Microchip dev boards (so there's a nice out-of-box experience with on-board LEDs, push-buttons, etc working properly); the PIC18F4550 dev board is the "PICDEM USB Full Speed" so this is the USB example project you should open.

The PIC18F2550 is the little brother to the PIC18F4550, which is the "classic" PIC18 USB part. You can simply change the target selection (and patch a few lines of source code) if you want to use the smaller F2550.







Note that the project won't compile until you patch a few lines of source code for the LED, since it's on a non-existing PIC18F2550 port.
« Last Edit: September 26, 2017, 06:16:44 AM by funkathustra »
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #9 on: September 28, 2017, 01:58:11 AM »
I'm trying to find the example file, when i searched for "picdem_fs_usb.x" I found all the results in dirs after "/opt/microchip/mla/apps/usb/device/", in this dir, I found this list of dirs:
audio_microphone  cdc_basic            hid_custom                  hid_joystick  hid_ups             utilities
audio_midi        cdc_serial_emulator  hid_digitizer_multi_touch   hid_keyboard  msd_internal_flash  vendor_basic
bootloaders       composite_hid_msd    hid_digitizer_single_touch  hid_mouse     msd_sd_card_reader  vendor_throughput_test

Now, i'm lost, cuz your example is showing a led.c file, I couldn't find any led.c file under any of these projects, I used the command "find ./ -name "led.c"


I thought i'd just choose vendor_basic, this is the path to the project files:
 /opt/microchip/mla/apps/usb/device/vendor_basic/firmware/picdem_fs_usb.x
contents of the dir: https://www.dropbox.com/sh/okdxxpi28m340rb/AABhqUx_D0UEjyAEuHtTmdVWa?dl=0



system.c and system.h files seem almost like a skeleton, almost empty, I just a working example, to test..

Did I get the wrong files ?
Could we give me your example files ?
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #10 on: September 28, 2017, 03:15:24 AM »
Did I get the wrong files ?
Could we give me your example files ?

Microchip doesn't put a separate copy of source files for each project in each possible configuration for each example. That would take, like, 20 gigabytes of space. Instead, each demo (like the USB "vendor_basic" one) has platform-agnostic source files (that work on the '4550, the 'K50, the PIC32 parts, etc), plus separate, platform-specific targets (like the picdem folder you found). That doesn't even include the actual USB library source code, which is referenced from the lib folder. For what it's worth, the platform-agnostic source files for the vendor_basic demo should be in the vendor_basic folder somewhere (I think there's a src directory? Not in front of an MLA installation right now, so I can't see).

The MPLAB X projects reference all the correct source files spread across the MLA directory tree.

Why don't you just open the project in MPLAB X like I showed you? You'll be able to see all the source files that are actually part of the project, build it, debug it, and see it working on your board.

Again, you're not going to find a "skeleton C file" that is an entirely self-contained firmware source file. The USB lib alone is spread out across 20 or 30 files (mostly headers, and mostly related to descriptors and ch9 stuff).

Once you get the demo working in MPLAB X, you can modify to suit your purposes.
« Last Edit: September 28, 2017, 03:21:41 AM by funkathustra »
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #11 on: September 28, 2017, 02:53:30 PM »
Found them files when i opened the mplabx ide, they're scattered all over the place.

[RANT]
The netbeans' Makefile is not an actual Makefile, it's gonna be hard for me to understand how it all compiles.
This is why I hate about IDEs ,..making it hard and obscure for no good reason  :horse: :horse: :horse:
Only asking for a simple C project, I get this giagantic motherload of 30 file project  :rant:
[/RANT]

Thank you,funkathustra, you've been more than helpful  :-+
« Last Edit: September 28, 2017, 02:55:02 PM by MAD MACRO »
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #12 on: September 29, 2017, 03:45:26 AM »
The netbeans' Makefile is not an actual Makefile, it's gonna be hard for me to understand how it all compiles.
Did you build the project? The Makefile will be empty until the project is built. MPLAB X auto-generates Makefiles based on your project options and source/include files.

This is why I hate about IDEs ,..making it hard and obscure for no good reason  :horse: :horse: :horse:
I don't know of another clean way of doing it. I suppose they could try to parse the Makefile and change it, but that seems really unstable compared to just re-generating it.

Most developers want to focus on their project source code, not managing build environments, so that's why companies build IDEs instead of text editors. Where people get burned is when they need to do automation stuff, especially for CI projects that hit version control.

Only asking for a simple C project, I get this giagantic motherload of 30 file project  :rant:
Almost all of those files are part of the USB stack. The USB protocol specification is 650 pages. Haven't you noticed that when you plug USB devices into your computer, they magically inform the operating system what they are, who made them, and then negotiate with your operating system to load drivers and begin communicating over one or more endpoints -- with possibly multiple configurations -- without requiring any user intervention?

Why do you think that process would be trivial? How would your microcontroller "know" how to do all that stuff, and what to say back? The descriptor structures alone occupy more than a hundred lines of code in most cases.

You're welcome to copy-and-paste all the USB library files into one C source file. That would be one gross-looking C file, though.

Anyway, I'm glad you got the project source files wrangled together. Keep us updated on your progress.
« Last Edit: September 29, 2017, 03:47:02 AM by funkathustra »
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: [SOLVED] PIC18F2550 USB project
« Reply #13 on: September 30, 2017, 12:00:44 AM »
I made some steps forward..

I edited the mla example code for my clock settings, they're using an external 20MHz crystal, i'm using using an 8MHz one.
Changed clock settings to give same 48MHz  clock speed needed for usb.
Code: [Select]
#pragma config PLLDIV   = 4
#pragma config CPUDIV   = OSC1_PLL2
#pragma config USBDIV   = 2
#pragma config FOSC     = HSPLL_HS

and Changed all the pins used for buttons and leds to match my settings

compiled using XC8, but when I tried to program the chip, I stayed in a kind of a waiting/verifying mode, it was weird, because while i'm flashing the chip, the pickit2 red led is on. So I took the .hex file and flashed it myself

Nothing more reliable than good ol' shell
Code: [Select]
pk2cmd -M -PPIC18f2550  -Y  -Fpicdem_fs_usb.x.production.hex

for the host part, I want it to be as simple and reliable as it can be, So I used node-hid, which is an npm package.
All the code does is keep checking all usb devices.
Code: [Select]
var HID = require('node-hid');
var i = 1;                         //  set your counter to 1
function myLoop () {               //  create a loop function
   setTimeout(function () {        //  call a 3s setTimeout when the loop is called
       console.log(HID.devices());
       if(i++ < 100) {             //  if the counter < 100, call the loop function
  myLoop();                //  ..  again which will trigger another
       }                           //  ..  setTimeout()
   }, 1000)
}
myLoop();                           //  start the loop


This is the output, I don't think it contains my chip, because I unplugged and plugged, and got same result.
Btw, how to set my usb like productId and path, so to identify my usb in the future ?
Quote
[ { vendorId: 1240,
    productId: 51,
    path: '0007:0010:00',
    serialNumber: 'OlHoss',
    manufacturer: 'Microchip Technology Inc.',
    product: 'PICkit 2 Microcontroller Programmer',
    release: 2,
    interface: 0 },
  { vendorId: 1241,
    productId: 5635,
    path: '0006:0031:00',
    release: 784,
    interface: 0 },
  { vendorId: 1241,
    productId: 5635,
    path: '0006:0031:01',
    release: 784,
    interface: 1 },
  { vendorId: 10093,
    productId: 4448,
    path: '0003:001d:00',
    release: 1,
    interface: 0 } ]

Not that it's going to be very helpful,but I like to give a an overall view
https://imgur.com/a/nKDUy
I double checked the wiring for the USB, it's solid, It also gives me the needed 5V power needed to power the chip.

I don't understand what I did wrong, but i'll try again, but this time, i'll change the whole project to use it without the IDE and use my LCD to output whatever is going on. :-BROKE

A bit unrelated to this, but I went again to check this example, and now I remember why I didn't use it, he's using C18 compiler, a completely different world, tried to compile his code using netbeans IDE(cuz i know nothing about C18).
Problem is that I couldn't find the usb header files he used, and VC++ host code he has is useless, cuz i already have the node-hid working fine. So, dropped his example all together.  :horse:

 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: [SOLVED] PIC18F2550 USB project
« Reply #14 on: September 30, 2017, 04:31:41 AM »
for the host part, I want it to be as simple and reliable as it can be, So I used node-hid, which is an npm package [...]
This is where you probably need to learn more about USB. I suggested working with Vendor-class spec, and you've been using the vendor_basic example, which uses the Vendor, not HID, class code.

Your device isn't detectable by an HID library because your device isn't HID.

My suggestion: start with the OS-provided tools. Since it appears you're on Linux, run "lsusb" to see all attached devices --- no matter what class code.

Next problem: I looked at your picture of your breadboard, and I noticed you appear to be missing the regulator cap. The '2550 requires a 220nF-minimum capacitor to ground on the VUSB pin, as a bypass cap for its internal 3.3V regulator. In fact, you don't seem to have any decoupling capacitors, so you might be running into intermittent problems caused by noisy digital rails.

Next: IIRC, you need to drive a 4 MHz clock into the PLL, right? Why are you dividing your 8 MHz crystal by 4? Shouldn't PLLDIV = 2? Check me on that.

Also, for testing in Linux, the USB stack will print kernel messages when devices are attached/detached, so plug in your device and run something like dmesg -wH, and see the device pop up (or not).

This can help with some troubleshooting: for example, if you your device isn't pulling up D+ pin, the port on your computer won't "notice" the device, and you won't see *any* output from the kernel. But if it *is* pulling up D+, but the MCU is running at the wrong speed, you'll see error messages about descriptors. In both cases, you'd *never* see the device appear from lsusb or libusb userspace --- but by looking at kernel messages, you'll get a bit more insight as to what's going on.

Also, if all else fails, swap D+ and D-. That's probably the number one error that people commit when designing USB circuits.
« Last Edit: September 30, 2017, 04:38:49 AM by funkathustra »
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #15 on: September 30, 2017, 09:39:26 PM »
Thank you so much, this really helped <3

Quote
This is where you probably need to learn more about USB. I suggested working with Vendor-class spec, and you've been using the vendor_basic example, which uses the Vendor, not HID, class code.
Your device isn't detectable by an HID library because your device isn't HID.

All this time I was thought that the example code provided by microchip is supporting HID, dunno what exactly gave me that idea, obviously I was wrong.

Quote
My suggestion: start with the OS-provided tools. Since it appears you're on Linux, run "lsusb" to see all attached devices --- no matter what class code.
Done that, output from running "lsusb"

Quote
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 022: ID 04d8:0053 Microchip Technology, Inc.
Bus 007 Device 003: ID 276d:1160 
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 04d9:1603 Holtek Semiconductor, Inc. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 004: ID 04d8:0033 Microchip Technology, Inc. PICkit2
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
The red colored one is my chip, cuz when I disconnect it, it doesn't show, I tested it many times.

Quote
Next problem: I looked at your picture of your breadboard, and I noticed you appear to be missing the regulator cap. The '2550 requires a 220nF-minimum capacitor to ground on the VUSB pin, as a bypass cap for its internal 3.3V regulator. In fact, you don't seem to have any decoupling capacitors, so you might be running into intermittent problems caused by noisy digital rails.
Well, the recommended was 470nF for the ground VUSB pin, so I did a parallel 330nF and 120nF, resulting in 450nF, cuz I didn't have a 470nF, 450nF is OK, right ?
I already had a bypass cap of 100nF.


Quote
Next: IIRC, you need to drive a 4 MHz clock into the PLL, right? Why are you dividing your 8 MHz crystal by 4? Shouldn't PLLDIV = 2? Check me on that.
you're absolutely right, that's a brain fart, sry.

Quote
Also, for testing in Linux, the USB stack will print kernel messages when devices are attached/detached, so plug in your device and run something like dmesg -wH, and see the device pop up (or not).
ran "dmesg -wH", and the output when disconnected and reconnected:
Quote
[Sep30 04:31] usb 7-2: USB disconnect, device number 22
[  +1.766625] usb 7-2: new full-speed USB device number 23 using uhci_hcd



I think i'm on the right track here. So, I have an idea for the host code, i'm gonna use this lib(https://www.npmjs.com/package/usb), I know it's js, but coding the firmware is gonna be problematic enough for me, i'm gonna play with it, an come back with results.
« Last Edit: September 30, 2017, 10:02:10 PM by MAD MACRO »
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #16 on: October 03, 2017, 04:53:12 AM »
Done that, output from running "lsusb"
Quote
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 022: ID 04d8:0053 Microchip Technology, Inc.
Bus 007 Device 003: ID 276d:1160 
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
...
The red colored one is my chip, cuz when I disconnect it, it doesn't show, I tested it many times.
By golly, it works!

That's always satisfying to see when you're doing a USB project, since about a bazillion things need to come together for that to work.

Smooth sailing from here!

I think i'm on the right track here. So, I have an idea for the host code, i'm gonna use this lib(https://www.npmjs.com/package/usb), I know it's js, but coding the firmware is gonna be problematic enough for me, i'm gonna play with it, an come back with results.
Sounds like a great plan. NodeJS is great, and it should get you going really quickly. I checked that API, and it looks like a good way of handling things.

By the way, the MLA demo you loaded -- vendor_basic -- actually comes with corresponding demo host applications that you can build and run on your computer. If you read through the demo firmware and the app source code, you'll see how you can toggle an LED, and I believe other stuff --- read an ADC pin, and I think read some digital inputs?

It's been a while since I've looked at the demo, but I know Microchip targets Qt with LibUSB for the Linux/macOS cross-platform stuff.

I'd probably build that app first, verify I can make my LED toggle when I press the button, then dive into the NodeJS implementation.

Good luck! Almost there!
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #17 on: October 04, 2017, 06:17:54 AM »
So, I brought the whole project in one dir, netbeans didnt generate any makefiles, so I made my own makefile.
https://github.com/Macromeda/mla/tree/master/vendor_basic
The project is an exact copy of the one released my pic, not a signal line changed. It works for pic18f4550 as they intended, I made my own that works for pic18f2550 tho.

You can do it yourself by using this script inside the dir of your choice and just run it, u'd still need my makefile tho.
Code: [Select]
#!/bin/bash
mla_dir="/opt/microchip/mla/"
mkdir src inc src/bsp src/usb inc/bsp inc/usb
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/app_led_usb_status.h inc
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/app_device_vendor_basic.h inc
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/picdem_fs_usb.x/fixed_address_memory.h inc
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/picdem_fs_usb.x/io_mapping.h inc
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/picdem_fs_usb.x/system.h inc

cp ${mla_dir}bsp/picdem_fs_usb/buttons.h inc/bsp
cp ${mla_dir}bsp/picdem_fs_usb/leds.h inc/bsp

cp ${mla_dir}framework/usb/inc/usb.h inc/usb
cp ${mla_dir}framework/usb/inc/usb_ch9.h inc/usb
cp ${mla_dir}framework/usb/inc/usb_common.h inc/usb
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/usb_config.h inc/usb
cp ${mla_dir}framework/usb/inc/usb_device.h inc/usb
cp ${mla_dir}framework/usb/inc/usb_device_generic.h inc/usb
cp ${mla_dir}framework/usb/src/usb_device_local.h inc/usb
cp ${mla_dir}framework/usb/inc/usb_hal.h inc/usb
cp ${mla_dir}framework/usb/inc/usb_hal_pic18.h inc/usb

cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/app_device_vendor_basic.c src
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/app_led_usb_status.c src
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/usb_events.c src
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/main.c src
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/picdem_fs_usb.x/system.c src
cp ${mla_dir}bsp/picdem_fs_usb/buttons.c src/bsp
cp ${mla_dir}bsp/picdem_fs_usb/leds.c src/bsp
cp ${mla_dir}apps/usb/device/vendor_basic/firmware/demo_src/usb_descriptors.c src/usb
cp ${mla_dir}framework/usb/src/usb_device.c src/usb
cp ${mla_dir}framework/usb/src/usb_device_generic.c src/usb


So, for the host side, I was working on it 2 days ago, but stopped, cuz I got sick, didn't wanna post anything until I get a result, which I kinda did, but not enough tho.

Problem with node-usb is that their lib is not documented well enough, I guess they expect me to read the usblib documentation which this lib is based on, but that's just wrong.

So far I was able to reset the chip from the host side, currently reading my way into transferring data using bulk and then Isochronous.

Quote
Smooth sailing from here!
Not quite, but thanks for the confidence boost.  ^-^


Quote
By the way, the MLA demo you loaded -- vendor_basic -- actually comes with corresponding demo host applications that you can build and run on your computer. If you read through the demo firmware and the app source code, you'll see how you can toggle an LED, and I believe other stuff --- read an ADC pin, and I think read some digital inputs?

yeah, but they're using C# in visual studio 2005, did I tell you how much I hate microsoft ? but for the sake of curiosity, i'm gonna read their code to get the overall idea.



« Last Edit: October 04, 2017, 06:26:48 AM by MAD MACRO »
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #18 on: October 04, 2017, 10:23:52 AM »
So, I brought the whole project in one dir, netbeans didnt generate any makefiles, so I made my own makefile.
Why do you keep talking about NetBeans? To work with MPLAB X projects, you need MPLAB X installed. I understand that MPLAB X is built on NetBeans, but NetBeans != MPLAB X, and doesn't come with the compilers/tools needed to build projects (or, in your case, generate the Makefiles).

You would have struggled far less with this if you would just use the correct tools for it. MPLAB X generates Makefiles the first time you build the project (based on the compiler configuration you provide it). It's a free IDE that runs well in Windows, Linux, and macOS, so I don't understand your allergy to it.

Once you build the project once, the Makefiles are generated. I have personally verified that I can run "make" inside the picdem_fs_usb.x folder, and the entire firmware image builds properly.

I still have no idea why you'd want to copy-and-paste the USB library out of a central repository into each individual project you work on, unless you plan on altering the source code of the library. Whatever — it's your project, I guess.

Quote
By the way, the MLA demo you loaded -- vendor_basic -- actually comes with corresponding demo host applications that you can build and run on your computer. If you read through the demo firmware and the app source code, you'll see how you can toggle an LED, and I believe other stuff --- read an ADC pin, and I think read some digital inputs?

yeah, but they're using C# in visual studio 2005, did I tell you how much I hate microsoft ? but for the sake of curiosity, i'm gonna read their code to get the overall idea.

First of all, I suggest you get over yourself  ;D. Linux, macOS, and Windows are all great for certain things, and are terrible at other things. The best devs I know are comfortable working in all of them, and don't sit around complaining.

Next, you're also, just... wrong. There is no C# Visual Studio 2005 demo code. The vendor_basic folder has all of the test host applications in the "utilities" folder. Inside it, you will find a libusb_cross_platform_example folder, which contains a C++ LibUSB-based Qt project that should compile on Linux, macOS, and Windows. You should build and run this app, and verify you can interact with your board. The source code is trivial to understand on both the firmware and host side, so once you get it working, you should be able to hack at it for whatever project you intend on building.

There's also native Windows Visual-C++ projects -- basic_example and plug_and_play_example -- but I can tell you wouldn't go near those with a 10-foot pole.

[...] currently reading my way into transferring data using bulk and then Isochronous.
Most LibUSB-based wrappers don't have support for isochronous transfers --- including the NodeJS lib you're trying to use. FYI.
« Last Edit: October 04, 2017, 10:25:54 AM by funkathustra »
 
The following users thanked this post: MAD MACRO

Offline MAD MACRO

  • Regular Contributor
  • *
  • Posts: 55
  • Country: eg
Re: PIC18F2550 USB project
« Reply #19 on: October 04, 2017, 10:39:06 PM »
Quote
Most LibUSB-based wrappers don't have support for isochronous transfers --- including the NodeJS lib you're trying to use. FYI.

Thanks for telling me that, no more node-usb then.

Good news again, I was able to compile and run the Qt demo and it toggled the LED, hot damn :D
Thank you so much for all you help and advice  :-+


Quote
Why do you keep talking about NetBeans? To work with MPLAB X projects, you need MPLAB X installed. I understand that MPLAB X is built on NetBeans, but NetBeans != MPLAB X, and doesn't come with the compilers/tools needed to build projects (or, in your case, generate the Makefiles).

You would have struggled far less with this if you would just use the correct tools for it. MPLAB X generates Makefiles the first time you build the project (based on the compiler configuration you provide it). It's a free IDE that runs well in Windows, Linux, and macOS, so I don't understand your allergy to it.

Once you build the project once, the Makefiles are generated. I have personally verified that I can run "make" inside the picdem_fs_usb.x folder, and the entire firmware image builds properly.

I still have no idea why you'd want to copy-and-paste the USB library out of a central repository into each individual project you work on, unless you plan on altering the source code of the library. Whatever — it's your project, I guess.

First of all, I suggest you get over yourself  ;D. Linux, macOS, and Windows are all great for certain things, and are terrible at other things. The best devs I know are comfortable working in all of them, and don't sit around complaining.

When it comes to the tools I use, I take it personally, I don't like big tech companies shoving their big corp IDE into my world and making me depend on it, i'm talking about VS ofc not netbeans, netbeans is an open source made by a bunch of amateurs with no taste of design whatsoever, if they had any concern for it anyway.

Only the people who actually worked on big projects that used VS2015 and .NET will understand, the amount of crap that you need to work through in order to commit/push your code is horrendous and oh my, if you decided to download a library that could conflict with someone else's if he updates, cuz now it's harder to detect, cuz everything is hidden in a 1000xMEGALINES xml file that is filled with redundant crap, just to keep things organized.

I don't see a need for any IDE anymore, it's an overkill, text editors like sublime are more than good enough for me to get the job done.

Since getting a VID is gonna be very expensive, how much would it cost me to get a PID from a vendor that sell them ? and do you recommend any ?
« Last Edit: October 05, 2017, 04:50:10 AM by MAD MACRO »
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: PIC18F2550 USB project
« Reply #20 on: October 06, 2017, 04:21:10 AM »
Good news again, I was able to compile and run the Qt demo and it toggled the LED, hot damn :D
Thank you so much for all you help and advice  :-+
Congrats!

Since getting a VID is gonna be very expensive, how much would it cost me to get a PID from a vendor that sell them ? and do you recommend any ?

What exactly are you building? How many are you making?

If you're just playing around with hobbyist projects, just continue using the demo PID (or, seriously, just pick random numbers).

If you want to start producing something going into the wild, and you're not building a lot of units, you can sublicense a PID from Microchip. Here's the application. This is common for MCU vendors to do, and it's free. They often only let you do this for fewer-than-X products.

There's a large but finite number of PIDs that Microchip has to sublicense, so please don't abuse the system :-).

I only request PIDs when I'm actually gearing up for production of a product, just because a lot of stuff never makes it to the shelves, and I don't want to waste PIDs.
 
The following users thanked this post: MAD MACRO


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf