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

Add USB FS (USBFS0) support on NXP MCX N94x #84590

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

alxrey
Copy link
Contributor

@alxrey alxrey commented Jan 27, 2025

Add USB FS support on NXP mcx n94x soc:

  • Adapt USB DC Kinetis driver
  • Add usb configuration in soc devicetree

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please check the commit message as the change is made to mcxn23x file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I modified the wrong file. It's my bad.

CLOCK_EnableClock(kCLOCK_Usb0Ram);
CLOCK_EnableClock(kCLOCK_Usb0Fs);
CLOCK_EnableUsbfsClock();
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

How was this tested?

Copy link
Contributor Author

@alxrey alxrey Jan 27, 2025

Choose a reason for hiding this comment

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

With a custom board that I made...
You're right, on the FRDM board the USB0 pins are only connected to two TP. Therefore it is not pertinent to put this configuration in the board.c file.

But why all these configurations are not done in a soc.c file, "at the soc level"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We are moving to making the clock configuration board specific as these should be managed at a board level. Kindly delete this from board.c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a bit a shame because it means that if someone wants to create a custom board based on this soc, he necessarily needs to do some research how to use the HAL.
But I also understand the intention to manage it at the board level, I will remove this modification.

Copy link
Collaborator

@mmahadevan108 mmahadevan108 left a comment

Choose a reason for hiding this comment

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

Need clarification on how this was tested.

USBFS0 configuration is missing in Devicetree for NXP MCX N94x.
Add the configuration to dtsi file.

Signed-off-by: Alexandre Rey <alx.rey@icloud.com>
@mmahadevan108
Copy link
Collaborator

Please help address the CI failures

@alxrey alxrey changed the title Add frdm_mcxn947 usb support Add usb support on NXP MCX N94x Jan 28, 2025
@alxrey alxrey requested a review from mmahadevan108 January 28, 2025 09:16
@alxrey alxrey changed the title Add usb support on NXP MCX N94x Add USB FS (USBFS0) support on NXP MCX N94x Jan 28, 2025
Some NXP socs use USBFS0 macro as base address for accessing the USB
registers, rather than USB0.
It generates compile-time errors, since USB0 is not defined.
Fix by defining USB0 if USB0 is not defined and USBFS0 is.

Signed-off-by: Alexandre Rey <alx.rey@icloud.com>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if it is the best way to handle this. we could also run conditional checks on the soc used.
Opened to be discussed...

Copy link
Collaborator

Choose a reason for hiding this comment

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

@alxrey. Zephyr is USB support is going through a rework. Below is the new driver we should be using for this IP.
https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/usb/udc/udc_kinetis.c
Eventually this driver will be deprecated. I would suggest testing and using the above driver.

This is the issue that is tracking progress on the USB rework.
#42066

* In some SoC USB0 base register is defined as USBFS0
*/
#if !defined(USB0) && defined(USBFS0)
#define USB0 USBFS0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a note, #define USB0 (USB_Type *)DT_INST_REG_ADDR(0) should work as well (not tested 😄).

.base = (USB_Type *)DT_INST_REG_ADDR(n), \

@kartben kartben merged commit 033e222 into zephyrproject-rtos:main Jan 29, 2025
26 checks passed
Copy link

Hi @alxrey!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

@alxrey alxrey deleted the mcxn947-usbfs0 branch January 29, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus platform: NXP Drivers NXP Semiconductors, drivers platform: NXP NXP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants