-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added HCD for stm32f4/f7. Updated porting documentation. #2468
base: master
Are you sure you want to change the base?
Conversation
…w to port for a host driver.
/*--------------------------------------------------------------------+ | ||
* Weak HAL functions | ||
*--------------------------------------------------------------------+*/ | ||
void HAL_HCD_MspInit(HCD_HandleTypeDef *handle) |
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.
This PR looks great, much needed in my opinion, but these two functions (MspInit and Deinit) shouldn't be here, they should be taken care of in board_init() and not part of this driver.
I think it would be sufficient to have just hcd_stm32.c as it will also work on h series processors. |
|
||
/* Open a IN pipe for the control endpoint manually since tinyUSB does not do so */ | ||
if (pipes[i].ep_type == EP_TYPE_CTRL && pipes[i].ep_dir == TUSB_DIR_OUT) { | ||
return open_control_in_pipe(pipes[i].dev_addr, pipes[i].ep_num, ep_desc->wMaxPacketSize); |
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.
open_control_in_pipe. is basically duplicate code, could be made generic to eliminate the duplicate code.
case URB_NOTREADY: | ||
/* Re-send the request when we have received a NAK via the out pipe, | ||
otherwise we might get stuck at waiting for nothing. */ | ||
if (pipes[i].ep_dir == TUSB_DIR_OUT) { |
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.
tinyUSB already has retry mech built in. seems like you should just report failure and let the stack do the retries.
|
||
switch (urb_state) { | ||
case URB_IDLE: | ||
return; |
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.
This callback should always invoke the hcd_event_xfer_complete function with success or a failure. Calling Submit without some kind of response causes the usb stack to hang.
void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *handle) | ||
{ | ||
(void) handle; | ||
is_port_connected = true; |
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.
is_port_connected should be set in the connect/disconnect callbacks.
is_port_connected = false; | ||
/* We do not depend on the USB device re-attaching itself. Hence, whenever a deattchment happens, | ||
we mark the flag to wait for the host driver restarting. */ | ||
is_waiting_usbh_restart = true; |
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.
It shouldn't the application responsibility to restart the usb stack when someone unplugs a usb device. I believe the is_waiting_usbh_restart flag should not exist.
/*--------------------------------------------------------------------+ | ||
* Extra specific functions | ||
*--------------------------------------------------------------------+*/ | ||
bool hcd_start(uint8_t rhport) |
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.
As far as I can tell, hcd_start is not a tinyusb interface function. This code should be in hcd_init()
uint8_t i = 0; | ||
|
||
/* Make sure the pipes are cleared when starting a new enumeration */ | ||
if (dev_addr == 0 && ep_desc->bmAttributes.xfer == EP_TYPE_CTRL) { |
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.
memset the pipes on open? this should be on close.
|
||
void hcd_device_close(uint8_t rhport, uint8_t dev_addr) | ||
{ | ||
(void) rhport; |
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.
clear the pipes in here, and I have also found that the used hhcd.hc[] pipes need to be re-inited as well, don't know why stm doesn't have an api to close an endpoint.
Thanks for your effort to make HCD works on SMT32.
Anyway it's a good starting point. |
Special thanks to Prodrive Technologies for giving me time to create this and push it back to the community.