Skip to content

drivers: rtc: Add support for RTC for stm32n6 series#106527

Merged
aescolar merged 1 commit intozephyrproject-rtos:mainfrom
basilegrunersmile:stm32n6_rtc_support
Apr 27, 2026
Merged

drivers: rtc: Add support for RTC for stm32n6 series#106527
aescolar merged 1 commit intozephyrproject-rtos:mainfrom
basilegrunersmile:stm32n6_rtc_support

Conversation

@basilegrunersmile
Copy link
Copy Markdown
Contributor

@basilegrunersmile basilegrunersmile commented Mar 30, 2026

This PR aims to add support for RTC on stm32n6 series.
Related Feature Request : #100667
It also provides an overlay for RTC sample for Nucleo n657x0 Q

Comment thread drivers/rtc/rtc_stm32.c Outdated
Comment on lines +557 to +560
#ifdef CONFIG_SOC_SERIES_STM32N6X
/* STM32N6 series need RTC enabled in Sleep mode to count during idle thread */
LL_RCC_EnableRTC_LP();
#endif /* CONFIG_SOC_SERIES_STM32N6X */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@basilegrunersmile Is that strictly required ?
Can't this just eb enabled via a call to clock_control_on?

Also note that clock_control_on on N6 always enable LP clock:

/* Set Low Power clock */
sys_set_bits(DT_REG_ADDR(DT_NODELABEL(rcc)) + pclken->bus + STM32_CLOCK_LP_BUS_SHIFT,
pclken->enr);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

clock_control_on\ is called here by rtc_stm32_init` :

/* Enable RTC bus clock */
if (clock_control_on(clk, (clock_control_subsys_t)&cfg->pclken[0]) != 0) {
LOG_ERR("clock op failed\n");
return -EIO;
}

After further investigation, it appears that this call does not affect RCC_APB4LLPENR register (rm0486) because access to backup domain is disabled.
If I modify rtc_stm32_init like this, it works for nucleo n657x0 Q :

	stm32_backup_domain_enable_access();

	/* Enable RTC bus clock */
	if (clock_control_on(clk, (clock_control_subsys_t)&cfg->pclken[0]) != 0) {
		LOG_ERR("clock op failed\n");
		return -EIO;
	}

But I don't know how it can affect other boards.

Registers values before moving stm32_backup_domain_enable_access :

(gdb) x/1xw 0x56028274
0x56028274:	0x00038000
(gdb) x/1xw 0x560282B4
0x560282b4:	0x00000000

Registers values after moving stm32_backup_domain_enable_access :

(gdb) x/1xw 0x56028274
0x56028274:	0x00038000
(gdb) x/1xw 0x560282B4
0x560282b4:	0x00010000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can put it under a series specific #ifdef. Or it won't probably hurt other series anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done !

@basilegrunersmile basilegrunersmile force-pushed the stm32n6_rtc_support branch 2 times, most recently from 0999a55 to df4fa83 Compare April 17, 2026 07:25
@basilegrunersmile
Copy link
Copy Markdown
Contributor Author

Force pushed to solve merge conflict.
Also made modifications to comply with #106827.

Copy link
Copy Markdown
Contributor

@djiatsaf-st djiatsaf-st left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

LGTM.

To get the full RTC be tested by default on these boards, could you also at in boards/st/{nucleo_n657x0_q|stm32n6570_dk}/Kconfig.defconfig:

 endif # VIDEO
 
+if RTC_STM32
+
+configdefault RTC_ALARM
+	default y
+
+configdefault RTC_CALIBRATION
+	default y
+
+endif # RTC_STM32
+
 endif # BOARD_STM32N6570_DK

on the model of #107342?

Comment thread drivers/rtc/rtc_stm32.c
Comment thread drivers/rtc/rtc_stm32.c Outdated
#if defined(CONFIG_SOC_SERIES_STM32N6X)
/* STM32N6 needs backup domain access before configuring RTC clock */
stm32_backup_domain_enable_access();
#endif /* CONFIG_SOC_SERIES_STM32N6X */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For sake of simplicity of the code, it would be worth to always enable backup domain here, before RTC clock is enabled, IMHO. Not a blocking comment.

@basilegrunersmile basilegrunersmile force-pushed the stm32n6_rtc_support branch 2 times, most recently from 6c8b123 to 2cb6720 Compare April 17, 2026 15:14
Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Could you add in the commit log someething like Enable by default RTC alarm and calibration on Nucleo-N657x0-Q and STM32N6570-DK when STM32 RTC is enabled?
Otherwise LGTM.

Copy link
Copy Markdown
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

Comment thread boards/st/nucleo_n657x0_q/Kconfig.defconfig Outdated
Comment thread boards/st/stm32n6570_dk/Kconfig.defconfig Outdated
erwango
erwango previously approved these changes Apr 24, 2026
Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Could you also add rtc to the supported tags in boards/st/stm32n6570_dk/twister.yaml and boards/st/nucleo_n657x0_q/twister.yaml?

Add rtc node on stm32n6 DT.
Enable backup domain access before RTC clock configuration and not after.
Add rtc to the supported tags

Signed-off-by: Basile GRUNER <basile.gruner@smile.fr>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

LGTM.
I wonder if it would be better to be split in to 2 commits: one for changes in drivers/rtc/...+dts/... and one for thoses in boards/.... Non-blocking.

Comment thread drivers/rtc/rtc_stm32.c

int err = 0;

stm32_backup_domain_enable_access();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would strongly recommend adding a comment explaining why this must go before clock_control_on() to ensure this isn't moved again by accident. (Even to me right now, I'm not sure I understand the rationale...)

@aescolar aescolar merged commit f78523b into zephyrproject-rtos:main Apr 27, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants