Skip to content

Conversation

thenguyenyf
Copy link
Contributor

@thenguyenyf thenguyenyf commented Dec 9, 2024

This PR to initial support for UHC driver on Renesas RA boards.

@zephyrbot
Copy link

zephyrbot commented Dec 9, 2024

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-hal_renesas DNM This PR should not be merged (Do Not Merge) labels Dec 9, 2024
@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch 6 times, most recently from 9356bc5 to 68f0507 Compare December 23, 2024 03:07
@thenguyenyf thenguyenyf marked this pull request as ready for review December 23, 2024 04:28
@zephyrbot zephyrbot added platform: Renesas RA Renesas Electronics Corporation, RA area: Samples Samples area: USB Universal Serial Bus labels Dec 23, 2024
@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch from 68f0507 to 00f6cce Compare December 23, 2024 09:53
tmon-nordic
tmon-nordic previously approved these changes Jan 9, 2025
@fabiobaltieri fabiobaltieri added DNM (manifest) This PR should not be merged (controlled by action-manifest) and removed DNM This PR should not be merged (Do Not Merge) labels Feb 4, 2025
@facchinm facchinm mentioned this pull request Feb 6, 2025
16 tasks
@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch from 00f6cce to 3ce519d Compare February 17, 2025 08:58
@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch from a6ca200 to 02541db Compare August 25, 2025 06:28
@zephyrbot zephyrbot requested a review from JarmouniA August 25, 2025 06:29
@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch from 02541db to 26c8de6 Compare August 25, 2025 06:52
@thenguyenyf
Copy link
Contributor Author

Last push to rebase and solve conflict

@thenguyenyf
Copy link
Contributor Author

Hello @jfischer-no. Is there any chance this PR could be merged? All review items have been fixed but this PR is still blocked due to your change request. Could you please review and verify?

@jfischer-no
Copy link
Contributor

Hello @jfischer-no. Is there any chance this PR could be merged? All review items have been fixed but this PR is still blocked due to your change request. Could you please review and verify?

Hello @thenguyenyf #82730 (comment) still not addressed, , there is not reason to add board overlays.

@thenguyenyf
Copy link
Contributor Author

Hello @jfischer-no. Is there any chance this PR could be merged? All review items have been fixed but this PR is still blocked due to your change request. Could you please review and verify?

Hello @thenguyenyf #82730 (comment) still not addressed, , there is not reason to add board overlays.

Hello @jfischer-no . Please verify it

@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch from 9c56d39 to 9a10f10 Compare September 23, 2025 16:07
@thenguyenyf
Copy link
Contributor Author

Last push just to rebase main

@thenguyenyf
Copy link
Contributor Author

Hello @jfischer-no. Is there any chance this PR could be merged? All review items have been fixed but this PR is still blocked due to your change request. Could you please review and verify?

Hello @thenguyenyf #82730 (comment) still not addressed, , there is not reason to add board overlays.

Hello @jfischer-no . Please verify it

Hello @jfischer-no . Could you please revisit and verify this change?

Comment on lines 70 to 71
struct uhc_renesas_ra_evt event = {.type = UHC_RENESAS_RA_EVT_HAL,
.hal_evt = p_args->event};
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

int err;

err = R_USBH_XferStart(&priv->uhc_ctrl, xfer->udev->addr, xfer->ep, buffer_tail, len);

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}

static int uhc_renesas_ra_edpt_open(const struct device *dev, uint8_t dev_addr, uint8_t attrib,
uint8_t ep, uint8_t max_packet_size)
Copy link
Contributor

Choose a reason for hiding this comment

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

static int uhc_renesas_ra_edpt_open(const struct device *dev,
				    const uint8_t dev_addr, const uint8_t attrib,
				    const uint8_t ep, const uint8_t mps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return -EINVAL;
}

usb_desc_endpoint_t ep0_desc = {.bLength = sizeof(usb_desc_endpoint_t),
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable definition should be at the top of a block. Please fix style.
Why is the name ep0_desc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. The name was changed to ep_desc

Copy link
Contributor

Choose a reason for hiding this comment

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

There is now unnecessary type conversion, please change it to

	const struct uhc_renesas_ra_config *config = dev->config;
	usb_desc_endpoint_t ep_desc = {
		.bDescriptorType = USB_DT_ENDPOINT,
		.bEndpointAddress = ep,
		.bmAttributes = {attrib},
		.wMaxPacketSize = mps,
		.bInterval = 0,
	};
	fsp_err_t err;

Comment on lines +16 to +19
bus-wait-cycles:
type: int
description: Specifies CPU bus access wait cycles

Copy link
Contributor

Choose a reason for hiding this comment

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

Stray change? I do not think it is UHC relevant. Where is it used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This commit adds a new property that is already exclusively used in the HAL driver configuration. Devicetree should be used to configure drivers in Zephyr. The HAL driver or HAL module must not depend on anything from Zephyr. You have to fix it, see https://github.com/zephyrproject-rtos/zephyr/tree/main/modules, also there is no obligation to use HAL drivers.

static const struct uhc_renesas_ra_config uhc_config_##n = { \
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(DT_INST_PARENT(n)), \
.make_thread = uhc_renesas_ra_create_thread_##n, \
.udev_count = DT_PROP_OR(DT_INST_PARENT(node_id), usb_devices_count, 10), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it a DT property and why does it need to be configured per instance? I see it only used in the shim driver. Why is 10 default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This HWIP only support up to 10 devices connected to. So, the 0xb or higher address is invalid for this driver.

Copy link
Contributor

Choose a reason for hiding this comment

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

why does it need to be configured per instance? Are there SoC variants where it has a different value?

@jfischer-no jfischer-no requested review from josuah and removed request for JarmouniA and nashif September 25, 2025 19:49
@thenguyenyf thenguyenyf force-pushed the support_renesas_ra_uhc branch from 9a10f10 to dc43286 Compare September 26, 2025 02:46
Minh Hoang and others added 4 commits September 26, 2025 02:53
First commit to support UHC driver for Renesas RA family

Signed-off-by: Minh Hoang <[email protected]>
Signed-off-by: The Nguyen <[email protected]>
Add device node to support UHC on Renesas RA SoCs

Signed-off-by: Minh Hoang <[email protected]>
Signed-off-by: The Nguyen <[email protected]>
Enable USB host support on Renesas RA boards

Signed-off-by: Minh Hoang <[email protected]>
Signed-off-by: The Nguyen <[email protected]>
Support USBH shell sample for renesas,ra-uhc

Signed-off-by: The Nguyen <[email protected]>
Copy link

@thenguyenyf
Copy link
Contributor Author

Hello @jfischer-no . Could you please re-visit this PR and verify the change request?

Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Hello all.
Some few practical details which you might be interested in before pursuing.

Comment on lines +369 to +376
int ret;

ret = uhc_xfer_append(dev, xfer);
if (ret == 0) {
uhc_renesas_ra_xfer_request();
}

return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is completely valid code, having the "success" exit of the function at the end helps with debugging (i.e. users trying to understand a bug they encounter).

How about flipping the ret == 0 for ret != 0 even if it uses one more line?

Suggested change
int ret;
ret = uhc_xfer_append(dev, xfer);
if (ret == 0) {
uhc_renesas_ra_xfer_request();
}
return ret;
int ret;
ret = uhc_xfer_append(dev, xfer);
if (ret != 0) {
return ret;
}
uhc_renesas_ra_xfer_request();
return 0;

Comment on lines +628 to +631
if (priv->first_xfer != NULL) {
uhc_xfer_free(dev, priv->first_xfer);
priv->first_xfer = NULL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering: is it required to also uhc_xfer_free(dev, priv->last_xfer);?
I did not follow the entire logic to be able to tell, so maybe this is not needed.

{
struct uhc_renesas_ra_evt event = {.type = UHC_RENESAS_RA_EVT_XFER};

k_msgq_put(&uhc_msgq, &event, K_NO_WAIT);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the event queue is full, this could fail as it is K_NO_WAIT, in particular under heavy load.

It could be interesting to add a LOG_WRN(), an __ASSERT_NO_MSG() or return the error, to help with troubleshooting.

.hal_evt = p_args->event,
};

k_msgq_put(&uhc_msgq, &event, K_NO_WAIT);
Copy link
Contributor

@josuah josuah Oct 16, 2025

Choose a reason for hiding this comment

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

Here too in case that's something you wanted to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Samples Samples area: USB Universal Serial Bus platform: Renesas RA Renesas Electronics Corporation, RA

Projects

None yet

Development

Successfully merging this pull request may close these issues.