zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.96k stars 6.68k forks source link

NXP IMXRT Clock Configuration Through Devicetree #70252

Open danielb-tkjcy3rq opened 8 months ago

danielb-tkjcy3rq commented 8 months ago

Is your feature request related to a problem? Please describe. I'm currently working on a project using a custom board based on imxrt1170 MCU (Zephyr version 3.5.0). My project is a multicore project which uses both Cortex M4 and Cortex M7 cores. The CM7 will run the main application and uses Ethernet while the CM4 is only used for implementing some lighting protocols and doesn't have network.

The issue I saw was that Ethernet on the CM7 stops working when in multicore projects, but works fine if I just use the CM7 (the CM4 is never kicked). I traced the issue to soc/arm/nxp_imx/rt/soc_rt11xx.c:clock_init(). What is happening is that the CM7 boots first, configures the clocks (including Ethernet clocks) and then kicks the CM4. The CM4 then calls clock_init() again as part of its initialisation and re-cofigures the clock, but this time, without Ethernet because it isn't enabled for the CM4 project. This then breaks Ethernet for the CM7. Code snippet from clock_init:

/ Init System Pll2 pfd3. /

ifdef CONFIG_ETH_MCUX

CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd3, 24);

else

CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd3, 32);

endif

In addition to the issue above, there is the hardcoded clock configs in soc_rt11xx.c. As it currently stands, changing the core frequency or any of the PLLs has to be done by modifying soc_rt11xx.c. This limits the use of the same Zephyr checkout for multiple boards with different clock requirements.

Describe the solution you'd like I thought about making clock_init 'weak' and override it somewhere in my application but I don't think I can't immediately see how I can do that.

For the second issue of hardcoded clock config, I think allowing users to set that in devicetrees would be ideal.

Describe alternatives you've considered For the moment I just modified soc_rt11xx.c to set the clock configurations I want and put the call to clock_init in conditional compilation so it doesn't get called in the case of CM4. This will obviously stop working when I upgrade Zephyr so it isn't ideal.

Additional context Add any other context or graphics (drag-and-drop an image) about the feature request here.

danieldegrasse commented 7 months ago

Hi @danielb-tkjcy3rq - I agree that this is an issue we can solve with devicetree. Long term, I would look at #72102 as a potential solution. Short term, we could make the imxrt11xx clock init function weak (a similar approach has been used for other iMX RT SOCs). Would this work for your use case?