in IDE dependency tree / definition lookup - for porting

Post here first, or if you can't find a relevant section!
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

I thought I might task myself with a bit of a stretch goal...

Chiefly to try port arpruss' USBComposite library from the libmaple core to the STM official core.

It appears that most of the hard work is already done in that all of the USB core code is self contained in one location.

However, not having a strong, or even weak, understanding of the maple or STM USB implementations, it would be great to be able to easily see any remaining dependencies and their associated definitions directly in an IDE - yes this is probably a feat of laziness on my part, but surely it's achievable?

Would the Ardunio plugin for VSCODE help achieve this? I'm going to have a play about later - I want to completely avoid PIO BTW as I'm not happy with the conversions away from Arduino code laziness that it mandates.

Any thoughts or insight very welcome.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

OK, well with a bit of faffing about I think I've answered my own question.

If I open a project that references the library and set the board in use to be one using Roger's core, I can easily walk any of the references/definitions.

Similarly I can then open a copy and set the board to an STM one and any refs that need porting will not reference. Not ideal but a way forward at least!

Sorry for looking like such a noob, but I come from a strong notepad/vi background :D
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: in IDE dependency tree / definition lookup - for porting

Post by ag123 »

among the harder things is to understand usb itself and the generic interfacing with the usb peripheral. there is a particular library shipped by st i think. that is used in both libmaple & official core, but could be different versions. digging thru the core source codes should find it there.

st shared some quite nice online learning stuff, going though this online learning material/course helps. i've gone through some of them. pretty in depth, useful
https://www.st.com/content/st_com/en/su ... ining.html

then for the more 'intro' stuff, those 'nutshell' webs are useful
https://www.beyondlogic.org/usbnutshell/usb1.shtml
https://www.usbmadesimple.co.uk/index.html
https://www.cypress.com/file/134171/download

one of those things is to get a usb sniffer, protocol decoder
apparently wireshark can do some of that, however apparently mainly in linux
https://wiki.wireshark.org/CaptureSetup/USB

i used sniffers and managed to understand how usb-cdc acm (i.e. usb serial) works. the device descriptor (a bunch of structured data, stored on device, noremally returned with get_descriptor calls). normally advertise 3 bulk in / out endpoints. one is in, one out and the 3rd is control (but it seemed this is possibly in addition to endpoint 0 which is predefined by the standard as control endpoint for the get descriptor commands). apparently, by declaring that in the device descriptor (on the stm32) the host has some protocol stacks (i.e. drivers) which recognize these 3 bulk in / out / control channels/endpoints as usb-serial and work with them sending traffic through them. so on the device there should be codes dealing with these 3 endpoints as well. But the state transitions etc are complex and more often i got lost even trying to debug that

and oh yes get those usb device class specs docs. those are as primary as can be for the source documents. but i find apparently it is hard to connect the dots reading the specs alone. either that it is 'incomplete', or that sections details individual concepts but hardly show how they relate to each other.
https://www.usb.org/documents?search=&t ... er_page=50
Last edited by ag123 on Fri Mar 12, 2021 8:29 pm, edited 2 times in total.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

Thanks for the links, and yes I understand it's a very complex area. I've just been reading about PMA...
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: in IDE dependency tree / definition lookup - for porting

Post by ag123 »

i tried learning usb cdc adm and dug a little into hid. my usb 'sniffer' is actually, linux's built-in usb-mon
https://www.kernel.org/doc/html/latest/usb/usbmon.html
this one works with wireshark
i've got some java stuff that tries to 'decode' the usbmon log files, but they are pretty crude and primitive. if you do use linux and would like to try those out i could share those codes. i've been reluctant as this isn't really a 'plug and play' stuff, rather it often takes collecting logs in files and then trying to use the java tool to try to decode the text log files. and i'm not too sure what are the differences between linux versions and if they'd work in other versions. i.e. chances that it 'don't work' or work with problems.
wireshark is a 'off-the-shelf' solution at least to get started

usb is the 'elephant in the room', it is there 'everywhere' and is often taken for granted that they 'just work'. i think it'd payoff learning it, though the curve is steep.

oh a google search and i stumbled into this, looks like pretty good stuff
https://desowin.org/usbpcap/
https://github.com/desowin/usbpcap

this looks pretty good as well but again in linux
https://flameeyes.blog/tag/usbmon/
https://github.com/Flameeyes/usbmon-tools

there is this concept about usb that seemed a little surprising, i've not found a document that properly describe this:
apparently in usb all that IN, OUT and CONTROL data packets are first initiated by the host, i.e. the host does all the polling, nothing is initiated by the device !
if the host wants to receive data say over usb-serial (usb cdc-adm) it would tell the device IN with some additional meta data (end point etc). then the device respond to that sending the data to the host. a little surprising but it seemed that way and i'm speculating about this as i've not really dug into it or found some docs describing it.

if all these could be appropriately understood, it may be possible to play with usb otg - available on stm32f4 devices. in effect stm32f4 plays the host, could be quite a bit more involved than simply devices
Last edited by ag123 on Fri Mar 12, 2021 6:56 pm, edited 2 times in total.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: in IDE dependency tree / definition lookup - for porting

Post by ag123 »

oh btw i've been wanting to try to observe usb signals on the wire. a problem is stm32's adc max out at some 2-5 msps and even multi interleaved still won't do above about 20 msps. usb is 12mhz (and in fact stm32 use a 48mhz clock to poll it at 12 M baud per secs)

the only resort is 'logic' levels as adc can't observe it. i'm thinking one way is to simply use spi as a 'logic analyzer' as that can goto 50mhz
it is also likely to be extremely 'noisy' as each usb bus has a multitude of devices and hubs.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

I've got a hantec scope here so should be able to capture if required - not sure if I've got something clever enough to decode the stream, I assume there will be something out there in internet land.

But for the purposes of this activity, I should only really need to understand enough to translate the core specific setup, teardown, endpoint, xfers etc. It's not like I have to write new functionality.

I still expect it to take a while, but nobody else is tackling it so it seems like it would be useful, as having a composite library on F3, F4 etc would be great.

Here's the issue raised against arpruss repo ~2.5 years ago -> https://github.com/arpruss/USBComposite ... /issues/15

Naturally I understand why he would not wish to commit time to it since he doesn't use the official core. With a bit of luck the guy who started on a port might resurface...
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

I'm going to start with this BTW -> https://www.youtube.com/watch?v=rI3yBmn ... nHhQZI4Hxa
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

My mind is already blown, the IPA I'm drinking probably isn't helping :D
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: in IDE dependency tree / definition lookup - for porting

Post by BennehBoy »

ag123 wrote: Fri Mar 12, 2021 5:51 pm there is this concept about usb that seemed a little surprising, i've not found a document that properly describe this:
apparently in usb all that IN, OUT and CONTROL data packets are first initiated by the host, i.e. the host does all the polling, nothing is initiated by the device !
This concept is explained quite well in the set of videos that I linked, everything is host centric.

So when we are 'sending' data from a device, all we're really doing is dumping it into a FIFO. The stack then simply waits for the host to poll, and it responds saying 'yup got something for you' and sends the data.

It's really very clever, and certainly is taking some thought for me to try and get my head around.
Post Reply

Return to “General discussion”