Skip to content

Conversation

@HalfSweet
Copy link
Contributor

@HalfSweet HalfSweet commented Nov 18, 2025

Improve the RCC definition for the sf32lb platform.
All RCC configurations in sf32lb have been completed, with the following additions:

  • sys-clk-src
  • peri-clk-src
  • mpi1/2-clk-src
  • usb-clk-src
  • usb-div

ck-telecom
ck-telecom previously approved these changes Nov 19, 2025
@ck-telecom ck-telecom changed the title drivers: rcc: Improve the RCC definition for the sf32lb52 platform drivers: rcc: Improve the RCC definition for the sf32lb platform Nov 20, 2025
@ck-telecom
Copy link
Contributor

ck-telecom commented Nov 20, 2025

drivers: clock_control: sf3232lb_rcc: Add RCC configuration driver
Add RCC configuration driver.

Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>

fix typo and commit format, also rebase and resovle conflicts.

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

good job on extending this, see my comments

Comment on lines 97 to 98
requires the corresponding DLL child node to be enabled. Defaults to
``peri`` if not provided.
Copy link
Member

Choose a reason for hiding this comment

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

defaults need to be justified (e.g. boot time default) per bindings rules

Comment on lines 88 to 89
requires the corresponding DLL child node to be enabled. Defaults to
``peri`` if not provided.
Copy link
Member

Choose a reason for hiding this comment

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

same

Comment on lines 79 to 80
Source used for the HPSYS peripheral clock domain. Defaults to ``hxt48`` if
not provided.
Copy link
Member

Choose a reason for hiding this comment

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

same, default actually not set

enum: ["hrc48", "hxt48", "lpclk", "dll1"]
description: |
Source used for the HPSYS system clock. When set to ``dll1`` the DLL1 child
node must be enabled. Defaults to ``hxt48`` if not provided.
Copy link
Member

Choose a reason for hiding this comment

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

same, default not set?

Comment on lines 113 to 115
Divider applied to the selected USB clock source. The divided clock must
be 60 MHz. For example, when ``clk_dll2`` runs at 240 MHz the divider must
be ``4``.
Copy link
Member

Choose a reason for hiding this comment

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

Default should not be set if its value depends on how other things are configured.

Copy link
Member

Choose a reason for hiding this comment

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

Also, why isn't this computed automatically if target clock freq is known?

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. all settings have been assigned default values and corresponding descriptions.

Comment on lines 64 to 71
enum sf32lb_sys_clk_idx {
SF32LB_SYS_CLK_IDX_HRC48,
SF32LB_SYS_CLK_IDX_HXT48,
SF32LB_SYS_CLK_IDX_LPCLK,
SF32LB_SYS_CLK_IDX_DLL1,
};

enum sf32lb_peri_clk_idx {
SF32LB_PERI_CLK_IDX_HRC48,
SF32LB_PERI_CLK_IDX_HXT48,
};

enum sf32lb_mpi_clk_idx {
SF32LB_MPI_CLK_IDX_DLL1,
SF32LB_MPI_CLK_IDX_DLL2,
SF32LB_MPI_CLK_IDX_PERI,
};

enum sf32lb_usb_clk_idx {
SF32LB_USB_CLK_IDX_SYSCLK,
SF32LB_USB_CLK_IDX_DLL2,
};
Copy link
Member

Choose a reason for hiding this comment

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

since this seems to mimic DT enums, you may consider using this approach (so everything resides on a DT header): https://wiki.st.com/stm32mpu/wiki/Clock_device_tree_configuration (ref st,clksrc). I think it's better.

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 have a slightly different perspective on this matter... While listing all data in the header file does significantly simplify the driver code, it makes editing the device tree less intuitive and prone to errors (such as misconfiguring the corresponding macro definitions).
Is there a recommended best practice for handling this scenario in Zephyr?

Copy link
Member

Choose a reason for hiding this comment

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

I don’t think there’s really a standard here, but it’s a common thing to look into other projects using devicetree to see how they have solved the same or similar problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After internal discussion, we concluded that using strings as enumerations would be preferable
I adjusted the order of the enumeration values so that each enum matches the final register setting value, making the driver code easier to read

@gmarull
Copy link
Member

gmarull commented Nov 20, 2025

note, for future this is also needed:

image

It's weird it's controlled by RTC/PMUC, maybe RTC/PMUC need a clock control sub-node, and a separate driver can manage that, and then nodes like RTC would have clocks = <&rcc_clk XXX_ENABLE_CLOCK>, <&pmuc_clk XXX_ACTUAL_CLOCK>?

Add the RCC configuration
binding on the sf32lb52 platform.
- sys-clk-src
- peri-clk-src
- mpi1/2-clk-src
- A
- usb-div

Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
Add RCC configuration driver.

Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
Add sys-clk-src.

Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
@sonarqubecloud
Copy link

Comment on lines +115 to +117
Divider applied to the selected USB clock source. The divided clock must
be 60 MHz. For example, when ``clk_dll2`` runs at 240 MHz the divider must
be ``4`` (reset default).
Copy link
Member

Choose a reason for hiding this comment

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

as said, providing default here may not be ideal if clk_dll2 is configured to other frequencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calculating the USB clock source and frequency division during compilation in C is simply too complex. Perhaps the correct allocation of the clock tree should be ensured by the person writing the device tree—when they enable the USB module, the corresponding frequency division should already be calculated. Of course, if it's not enabled, nothing happens. The default value of 4 here is merely because that's the default value after startup.

Copy link
Member

Choose a reason for hiding this comment

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

fair enough

@fabiobaltieri fabiobaltieri merged commit d70234f into zephyrproject-rtos:main Nov 25, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants