Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usb error more informative to user. Refactored vartypes of device's serial. #559

Closed
wants to merge 6 commits into from

Conversation

theg4sh
Copy link

@theg4sh theg4sh commented Feb 18, 2017

A little change to inform user about problems during device search or open.

src/usb.c Outdated Show resolved Hide resolved
src/usb.c Outdated Show resolved Hide resolved
src/usb.c Outdated Show resolved Hide resolved
* Refactored declaration of device's serial,
  muilttypes casted to uint8_t[STLINK_SERIAL_SIZE].
* Added search by env STLINK_SERIAL.
* Reusage serial parsing code - stlink_parse_serial (outbuf-unsafe)
  changes in tools/flash_opts.c, gdbserver/gdb-server.c, usb.c (env)
@theg4sh theg4sh changed the title Usb processing error more informative to user. Usb error more informative to user. Refactored vartypes of device's serial. Feb 28, 2017
Copy link
Author

@theg4sh theg4sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, review the last changes.

@xor-gate
Copy link
Member

I'm closing this PR as it is not 100% what we want because there is a mixture of hex/binary serial numbers and needs to be resolved in a generic way by writing a hex2bin/bin2hex implementation or using a existing one (e.g https://raw.githubusercontent.com/xor-gate/stlink2/master/src/utils/hexstr.c).

@xor-gate xor-gate closed this Mar 18, 2017
@theg4sh
Copy link
Author

theg4sh commented Mar 19, 2017

@xor-gate, got it.
I did the same conclusion earlier, so, that's why I didn't push any commits.

Could you, please, take a look for branch https://github.com/theg4sh/stlink/tree/libusb_minimize
There I did changes with serial, so, it structured and always converted to binary and then compared.
Functions: stlink_serial_convert, stlink_serial_init, stlink_serial_clear.

Also, I found that all usb devices walked by 3 times per tool run, e.g. 'st-info --probe', so, did change regarding this - in branch stlink devices initialized once and then used prepared pointer to get next stlink device.
Functions used to iterate stlink devices: stlink_init_devices, stlink_device_next, stlink_devices_rewind and stlink_free_devices.
So, it could be possible to clear sources from non-DRY code.
Please, note, that branch is not clear now.

In other hand, devices iterated for both versions - v1 and v2. I guess, it could be good for DRY, but stlinkv1 uses similar, but not the same backend callbacks.
I want to know your opinion regarding that modifications and will continue to work on it if you approved it.

@xor-gate
Copy link
Member

xor-gate commented Mar 19, 2017

Looks good why so many info is necessary if you normalize to just a string (ascii, or asciihex). Directly converting inline after probe would be more friendly from API point of view.

+    enum stlink_serial_format_type {
+        STSERIALF_UNKNOWN=0,
+        STSERIALF_BINARY,
+        STSERIALF_HEX,
+        STSERIALF_ASCII
+    };

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants