-
Notifications
You must be signed in to change notification settings - Fork 511
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
[rtl872x] Fixes USB serial port not being connectable on AMD based Windows #2625
Conversation
@YutingYou Do we have to implement |
@avtolstoy I reviewed their new CDC example, it doesn't make use of this callback, so I leave it |
I'll take a look at a few things later today:
|
b0cf99c
to
bd00aa9
Compare
|
OK, I'll try it on my P2. |
So, looks like some internals of the various USB stack state structs did change and for example our hack in bootloader with |
Yeah, some data structure does change in the new stack, for example, the callback register structure. |
@avtolstoy changing |
@YutingYou I'll make the changes to this branch, almost done verifying the rest of the 'internal' accesses to USB stack. |
bd00aa9
to
b92b435
Compare
I think with the latest commit this should be working correctly now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SDK patch changes themselves are a bit too over my head, so I will not comment on those.
I will say that I can use my photon 2 with my AMD windows machine and open USB CDC terminal with it. It enumerates under windows in bootloader DFU mode (although I didnt flash anything on windows)
I have some comments on the other changes just to help me understand how we interact with the RTK USB stack:
Bootloader changes:
- The bootloader uses USB for DFU, so usb stack is initialized in
HAL_DFU_USB_Init()
- The call chain is
Device::attach()
-->RtlUsbDriver::attach()
--> and finally realtek SDKusbd_init()
- The SDK
usbd_init()
call presumably creates a task(s?) for USB. - We store that task handle and context pointer in
rtw_create_task()
in the bootloader osdependencies file. - When the bootloader wants to run USB to enable DFU, it manually executes the RTK USB task via
HAL_DFU_Process()
- Part of the USB task in the SDK relies on
rtw_down_sema()
- When the SDK calls
rtw_down_sema()
we check the semaphore pointer and compare it to the USB task semaphore pointer. - We know the pointers address by looking into the USB task context (presumably some class or structure) at a magic offset. That offset has changed in the newest SDK as presumably that class/struct has as well.
- If the USB task cannot acquire the semaphore, then instead of blocking or waiting, exit out of the
rtw_usb_task()
function and re-run the loop again (presumably until the semaphore can be acquired)
Device OS changes
- The system implements all the functions in
usbd_class_driver_t
structure and passes that to the RTK SDK USB whenattach()
is called:
usbd_register_class(&classDrv_);
- When the SDK calls one of these functions, we store a pointer to the internal
usb_dev_t
structure of the USB stack - That structure has a member
void *pcd
that we are interested in accessing, hence the change in offset (and the note that we know the structure type so we could access it that way). - Not exactly sure what this pointer is, but I can see we do use it in things like
flushEndpoint
andstallEndpoint
da8bf08
to
23e8fa2
Compare
TODO
Most likely at the very least the above definitions need to be adjusted due to internal USB stack struct changes.
Problem
We found the USB request Get Line Coding couldn't get a response on the AMD Windows PC, the symptom could be that we can't open the com port on a serial tool software on the AMD Windows PC.
By enabling the low level USB log in
hw_config.c
we can see the last log when P2 got stuck, that is a race condition to access TxFIFO between EP3 and EP0.
Solution
Realtek helped to release a new patch and USB stack for us to fix this issue.
TODO
This patch not only fixes the USB issue, but also provides some new APIs and callbacks. If necessary, we can further improve the USB driver.
Steps to Test
References
[CH109872]
Completeness