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

Added HCD for stm32f4/f7. Updated porting documentation. #2468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

supersmiler
Copy link

  • Added HCD for stm32f4
  • Added HCD for stm32f7
  • Added documentation on how to port the host side.

Special thanks to Prodrive Technologies for giving me time to create this and push it back to the community.

/*--------------------------------------------------------------------+
* Weak HAL functions
*--------------------------------------------------------------------+*/
void HAL_HCD_MspInit(HCD_HandleTypeDef *handle)
Copy link
Contributor

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.

@cdesjardins
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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)
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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.

@HiFiPhile
Copy link
Collaborator

Thanks for your effort to make HCD works on SMT32.

  • Both F4 and F7 use synopsys dwc2 IP, so they should be generalized
  • Implementation shouldn't base on ST's HAL driver, as you can see there is no HAL dependency in dcd_dwc2.c

Anyway it's a good starting point.

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

Successfully merging this pull request may close these issues.

None yet

3 participants