K50 and USB issue

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1487
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

K50 and USB issue

Post by Jerry Messina » Mon May 15, 2017 1:39 pm

I've been using the 2x/4xK50 for some USB projects lately, and recently ran across an issue.

Once in a while the device would just stop responding to host requests (I was using CDC at the time).
Poking around I found that the K50 was sending a STALL response to the host DATA_IN packet (which typ indicates an error), and everything just stops.

Reading through the K50 datasheet there's a note that caught my eye:

Code: Select all

The firmware should not set the UOWN bit in the same instruction cycles as any other
modifications to the BDnSTAT soft register. The UOWN bit should only be set
in a separate instruction cycle, only after all other bits in BDnSTAT (and
address/count registers) have been fully updated.
I haven't seen that note in previous datasheets, but it is in recent ones from new devices like the 16F1xxxx w/USB.

The SF USB code is based on an old version of the MLA stack and doesn't follow the note's recommendations.
Looking at newer versions of the stack C code I see they've changed it to meet the above (quite a while ago, actually).
I made that change and bingo, things started working like normal.

I don't know if this is something that only affects some devices, but the change is included for all of them...
maybe it's just not in the older datasheets.

Anyway, here's a modified USBSystem.bas file that incorporates the change. It's just knocked together, but it changes both HID and CDC to follow the recommendation above.
Attachments
USBSystem_v144.zip
(23.06 KiB) Downloaded 401 times

User avatar
David Barker
Swordfish Developer
Posts: 1216
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: K50 and USB issue

Post by David Barker » Mon May 15, 2017 2:34 pm

Thanks for that Jerry, a really important piece of work. I use USB a lot - thanks for sharing...

User avatar
David Barker
Swordfish Developer
Posts: 1216
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: K50 and USB issue

Post by David Barker » Mon May 15, 2017 2:40 pm


richardb
Posts: 316
Joined: Tue Oct 03, 2006 8:54 pm

Re: K50 and USB issue

Post by richardb » Tue Jan 23, 2018 12:57 pm

After having to reinstall my pc a little while ago I am having some issues with various modules/files.


Where should I be copying the new usb modules to in the wiki?

Richard
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1487
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: K50 and USB issue

Post by Jerry Messina » Tue Jan 23, 2018 1:58 pm

You should be able to put them in your UserLibrary folder and they'll be available to all projects.

I think it appears under 'MyDocuments\Swordfish" but I don't remember (I have everything moved around).

richardb
Posts: 316
Joined: Tue Oct 03, 2006 8:54 pm

Re: K50 and USB issue

Post by richardb » Tue Jan 23, 2018 2:16 pm

I wanted to make sure its using the new usb files. does swordfish use the user files in preference to the installed library files in program data\....usb files


(I have everything moved around). I'm intrigued where do you store them?

I would like to have all the pic includes, libs and user libs located else ware so I can easily check them into SVN.

I also recently had an issue after installing a fresh copy swordfish. The adc was locking up due to

#const _adc = $05 // 5 ADC channels available

with the 18F2553.bas file

it would be nice to have a way of keeping modified files in an easy to maintain way.
Richard
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1487
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: K50 and USB issue

Post by Jerry Messina » Tue Jan 23, 2018 5:55 pm

I don't care for the way win7 locates files all over the place and hides some of them... c:\programdata, users folders, roaming folders, etc.
I install everything in d:\swordfish, move the folders from C:, and create symbolic links back to the original locations.

I tend not to use the library folders. I put copies of everything into a project folder and use those. That way I have all the files I used to build a project and don't have to worry about things that might change.

Sometimes it's a pain doing it that way (esp. if you really want to update libraries), but I'd rather have all the originals I used.

richardb
Posts: 316
Joined: Tue Oct 03, 2006 8:54 pm

Re: K50 and USB issue

Post by richardb » Wed Jan 24, 2018 9:07 am

I tried to do something like this but the shortcuts don't seem to do the trick. Are "symbolic links" different to shortcuts?

I just get "unable to open system file"
why did you install to d: instead of just for example "c:\swordfish\compiler\"?

Richard
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1487
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: K50 and USB issue

Post by Jerry Messina » Wed Jan 24, 2018 10:47 am

why did you install to d: instead of just for example "c:\swordfish\compiler\"?
I have multiple partitions/drives setup for tools, projects (data files), etc.
I do it primarily to make it easier to backup/image different things without having to backup an entire drive.
It also allows me to move things between systems easier since I setup all my machines the same way.
Just something I started doing ages ago, and have stuck with it over the years.
Are "symbolic links" different to shortcuts?
Yes, a junction point is different than a shortcut. Junction points are a type of link that can point to a folder,
and they're transparent to programs. Probably easiest to just google the details.

NOTE: do the following at your own risk. I'm not recommending this... just showing the steps involved.

You make a link to a directory using the 'mklink' command.
Let's say you wanted to move 'C:\ProgramData\Mecanique\Swordfish' to another location, say 'D:\Programs\Swordfish'
- move all contents from 'C:\ProgramData\Mecanique\Swordfish', copying them to 'D:\Programs\Swordfish'
- delete the original folder and its contents 'C:\ProgramData\Mecanique\Swordfish'
- make a symbolic link to the new location. open a command prompt and type:
mklink /D "C:\ProgramData\Mecanique\Swordfish" "D:\Programs\Swordfish"

There are also programs to help with some of this like Junction Link Magic (http://www.rekenwonder.com/linkmagic.htm)
but you still have to move the folders yourself.

richardb
Posts: 316
Joined: Tue Oct 03, 2006 8:54 pm

Re: K50 and USB issue

Post by richardb » Wed Jan 24, 2018 11:41 am

Thanks for the reply Jerry, I spoke to a colleague and googled it and have sorted this out now and done something very similar.
so I did the following which means I have a single directory now that I can check into SVN tortiose
Swordfish was installed into C:\swordfish\compiler

the C:\ProgramData\Mecanique\Swordfish was copied to C:\Swordfish\data
the C:\ProgramData\Mecanique\Swordfish folder was deleted then the following command was run in a "administrator" dos shell

C:\>mklink /J C:\ProgramData\Mecanique\Swordfish C:\Swordfish\Data

this makes a symbolic link and allows svn to check in the data but also allows the compiler to think the files are in the correct place.

do the same with the user directory

the C:\Users\richard.benfield\Documents\Swordfish C:\Swordfish\Users
the C:\Users\richard.benfield\Documents\Swordfish was deleted then the following command was run in a "administrator" dos shell

C:\>mklink /J C:\Users\richard.benfield\Documents\Swordfish C:\Swordfish\Users

Thanks again Jerry, always so fast to give a good reply.
Hmmm..

Post Reply