2024-07-09 01:35 PM
Hello!
I'm currently working with a stm32mp157f-dk2 development kit and designing a custom PCB with a STM32MP153A. I have working with the Developer/Distribution package of openST. I want to enable the TimeStamp function of the RTC, and be able to read the TimeStamp Time Register (RTC_TSTR) and Date Register (RTC_TSDR). I have been looking information for some time and I didn't found any support in the RTC linux driver bindings (<linux/rtc.h>), or in the stm32-rtc linux driver (<linux/drivers/rtc/rtc-stm32.c>). Also in the wiki I have not been able to find information about it's integration with the device tree. I have already check this post about reading from the M4: https://community.st.com/t5/stm32-mpus-products/how-can-the-cortex-m4-access-to-rtc-timestamp/td-p/276948 . But for reading the timestamp I have to enable it from the linux core.
Does anyone have any suggestions on how this situation can be addressed?
I have been modifying the linux driver, but I'm not sure if there is a more simplier way to do it.
Thank you!
2024-07-16 02:01 PM - edited 2024-07-16 02:09 PM
/* Function to enable the timestamp edge detection in the control register */
static int stm32_rtc_set_timestamp(struct platform_device *pdev, struct stm32_rtc *rtc)
{
const struct stm32_rtc_registers *regs = &rtc->data->regs;
unsigned int cr;
/* Start the configuration for the timestamp */
stm32_rtc_wpr_unlock(rtc);
cr = readl_relaxed(rtc->base + regs->cr);
dev_dbg(&pdev->dev, "CR: %u\n", cr);
cr &= ~STM32_RTC_CR_TSE; // Turn off the TSE
writel_relaxed(0b0, rtc->base + regs->cr);
cr |= STM32_RTC_CR_TSEDGE; // Set the TSE Edge
writel_relaxed(cr, rtc->base + regs->cr);
cr |= STM32_RTC_CR_TSE; // Turn on the TSE
writel_relaxed(cr, rtc->base + regs->cr);
/* Read to CR to check the data*/
cr = readl_relaxed(rtc->base + regs->cr);
dev_dbg(&pdev->dev, "CR modified: %u \n", cr);
stm32_rtc_wpr_lock(rtc);
return 0;
}
Currently we have modified the rtc-stm32.c file from the Developer Package linux source code (linux/drivers/rtc/rtc-stm32.c), following the steps in the reference manual to enable write access to the RTC protected registers, without success.
I have made the function stm32_rtc_set_timestamp() to modify the control register (CR), and be call in the