-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Implement nxp USB device controllers (udc_mcux) #70401
Conversation
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
Same as with the host PR, the order of commits has to be bisectable, meaning first update hal and then use it, not the other way round. |
Thanks @tmon-nordic , I have updated the commits order. Updating soc device tree firstly, enabling the udc/uhc driver secondly, then enabling the board level device tree and related clock. Please help to check whether it is OK. |
@jfischer-no, need your attention to this PR. @tmon-nordic, could you confirm the changes address your raised issue? |
Yes, the commit order seems fine now. |
#include "usb_device_config.h" | ||
#include "usb_device_mcux_drv_port.h" | ||
#include "usb_device_ehci.h" | ||
#ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED |
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.
Please remove #ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED
, it should not be necessary.
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 I explained, NXP has may platforms. Even the same USB controller IP is used, the PHY is used or not in different platforms. For example: (1) LPC54608 uses the IP3511 driver, the phy is not used; LPC55S69 uses the IP3511 driver, the phy is used. (2) RW610 uses the EHCI driver, the phy is not used; RTxxxx series uses the EHCI driver, the phy is used.
So, the MACRO is needed here.
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.
I do not care how many platforms NXP has. There is no need to include this header conditionally.
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.
why does it matter?
d54efb3
#include "usb_device_config.h" | ||
#include "usb_device_mcux_drv_port.h" | ||
#include "usb_device_ehci.h" | ||
#ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED |
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.
I do not care how many platforms NXP has. There is no need to include this header conditionally.
#ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED | ||
#define UDC_MCUX_PHY_DEFINE(n) \ | ||
static usb_phy_config_struct_t phy_config_##n = { \ | ||
.D_CAL = DT_PROP_OR(DT_INST_PHANDLE(n, phy_handle), tx_d_cal, 0), \ | ||
.TXCAL45DP = DT_PROP_OR(DT_INST_PHANDLE(n, phy_handle), tx_cal_45_dp_ohms, 0), \ | ||
.TXCAL45DM = DT_PROP_OR(DT_INST_PHANDLE(n, phy_handle), tx_cal_45_dm_ohms, 0), \ | ||
} | ||
|
||
#define UDC_MCUX_PHY_DEFINE_OR(n) \ | ||
COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST(n), phy_handle), \ | ||
(UDC_MCUX_PHY_DEFINE(n)), ()) | ||
|
||
#define UDC_MCUX_PHY_CFG_PTR_OR_NULL(n) \ | ||
.phy_config = COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST(n), phy_handle), \ | ||
(&phy_config_##n), (NULL)) | ||
#else | ||
#define UDC_MCUX_PHY_DEFINE_OR(n) | ||
#define UDC_MCUX_PHY_CFG_PTR_OR_NULL(n) | ||
#endif |
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.
Not addressed, #ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED
is not required.
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.
I don't understand. In one platform that doesn't have the PHY driver, so the usb_phy.h is not present/valid in this platform. Why should I include this file?
I use CONFIG_DT_HAS_NXP_USBPHY_ENABLED
to reduce the phy_config
here because it is not needed if the platform doesn't have this phy.
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.
I can remove all the phy related codes from the driver and put it in the soc.c of different platforms. The previous version NXP usb device controller driver (usb_dc_mcux.c) works this way.
Please let me know your thought.
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 phy initialization code is fine and belongs to the shim driver. There is nothing in phy/usb_phy.h that requires you to include it conditionally, it can always build. Therefore, all your #ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED
can be removed, resulting in much cleaner code without unnecessary #ifdef. Here it is doubly unnecessary, whatever phy is present and needs to be initialized is covered by the macros above.
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.
Hi Johann, In SDK USB stack, I cannot guarantee the usb_phy.h will not contain the soc/platform/IP level codes in future even it only contains the common C codes now. The reason is: NXP releases SDK package by platform, one platform has one package. usb_phy.h is only present in the package of platforms that have this PHY, and it is only valid/used in the platform, it is never built with the platforms that doesn't have the PHY. Without NXP SDK release's pre-building, I cannot guarantee usb_phy.h will build successfully with the platforms that doesn't have this phy forever.
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.
@MarkWangChinese Got it, can you please add a comment before #include "usb_phy.h
" that the header is not available for every package, thanks.
But, #ifdef CONFIG_DT_HAS_NXP_USBPHY_ENABLED ... #else
is not necessary here, see jfischer-no@7652d16 (https://github.com/jfischer-no/zephyr/commit/7652d1647de7dbf1cdce4b6f706605f6ea8c9e48.patch)
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.
Dev Review discussion:
@MarkWangChinese we discussed this PR with @jfischer-no in today's dev review meeting led by @MaureenHelm. He is would like to see the #ifdef removed and will approve the PR for merging. If we find later on subsequent platforms this is a problem we can address then.
Johann also re-kicked the CI so that is clean. So we will be able to merge this PR on Friday 6/14.
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.
@dleach02 @MarkWangChinese Actually let get it in, we have CI green and do not know what happens tomorrow 😃, #70401 (comment) can be followup.
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.
I have created one PR #74382, @jfischer-no please help to review.
define usbphy in DT and controller DT node ref to usbphy node. define the usbphy yaml and update ehci and ip3511 yaml for usbphy. Signed-off-by: Mark Wang <[email protected]>
udc_mcux_ehci is based on the MCUX USB controller driver (usb_device_ehci.c); udc_mcux_ip3511 is based on the MCUX USB controller driver (usb_device_lpcip3511.c); add related Kconfig and CMake; include the usb_phy.h path in modules/hal_nxp/usb/CMakeLists.txt because udc_mcux.c use it; add related macros to usb_device_config.h; update CMakeLists for udc_mcux_ehci and udc_mcux_ip3511. Signed-off-by: Mark Wang <[email protected]>
set DT node as Okay in board device tree; add board level's d-cal, txcal45dp and txcal45dm to usbphy node; enable usb clock; set USB_STACK_USE_DEDICATED_RAM for lpc55s69 and rt685; load usb.ld for lpc55s69 and rt685. Signed-off-by: Mark Wang <[email protected]>
enable next usb device stack samples (cdc_acm, mass and shell) on rt685 and mimxrt1060_evk Signed-off-by: Mark Wang <[email protected]>
Create the mcux usb device controller driver (udc_mcux.c) based on NXP SDK USB Device controller drivers (usb_device_ehci.c, usb_device_ip3511.c etc).
Support EHCI and IP3511 controllers. Shell demo's transfer function is verified on RT1060, RT685 and LPC55S69.
Edit: addresses list found in #42066