Access to RTC from Cortex-M4 on i.MX8M Mini

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Access to RTC from Cortex-M4 on i.MX8M Mini

1,068 Views
Patryk
Contributor I

Hi, 
I am using Cortex-M4 with FreeRTOS to communicate with an external sensor. The data is received by the M4 and available to the A53 via RPMsg. It works fine. Additionally, I would like to be able to configure the internal RTC using A53 and read the time from the RTC using M4. It is possible? Currently with Linux running on A53 I can set and get the time from RTC (SNVS_LP). I tried to read value from RTC with M4 directly from registers but unfortunately can't do that.

Function for read time in Cortex-M4:

static uint32_t SNVS_LP_RTC_GetSeconds(SNVS_Type *base)
{
    uint32_t seconds = 0;
    uint32_t tmp     = 0;

    /* Do consecutive reads until value is correct */
    do
    {
        seconds = tmp;
        tmp     = (base->LPSMCMR << 17U);
        tmp |= (base->LPSMCLR >> 15U);
    } while (tmp != seconds);

    return seconds;
}

 

Device tree configuration:

			snvs: snvs@30370000 {
				compatible = "fsl,sec-v4.0-mon","syscon", "simple-mfd";
				reg = <0x30370000 0x10000>;

				snvs_rtc: snvs-rtc-lp {
					compatible = "fsl,sec-v4.0-mon-rtc-lp";
					regmap = <&snvs>;
					offset = <0x34>;
					interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>,
						     <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
					clocks = <&clk IMX8MM_CLK_SNVS_ROOT>;
					clock-names = "snvs-rtc";
				};

				snvs_pwrkey: snvs-powerkey {
					compatible = "fsl,sec-v4.0-pwrkey";
					regmap = <&snvs>;
					interrupts = <GIC_SPI 4 IRQ_TYPE_LEVEL_HIGH>;
					clocks = <&clk IMX8MM_CLK_SNVS_ROOT>;
					clock-names = "snvs";
					linux,keycode = <KEY_POWER>;
					wakeup-source;
					status = "disabled";
				};
			};

 

In the documentation I found information that: "The SNVS_HP provides an interface between SNVS_LP and the rest of the system", so I modified ATF in the following way:

--- a/plat/imx/imx8m/imx8mm/imx8mm_bl31_setup.c	2022-01-25 15:28:29.000000000 +0100
+++ b/plat/imx/imx8m/imx8mm/imx8mm_bl31_setup.c	2022-01-25 15:42:05.000000000 +0100
@@ -58,8 +58,7 @@
 	RDC_MDAn(RDC_MDA_M4, DID1),
 
 	/* peripherals domain permission */
-	RDC_PDAPn(RDC_PDAP_UART4, D0R | D0W),
-	RDC_PDAPn(RDC_PDAP_UART2, D0R | D0W),
+	RDC_PDAPn(RDC_PDAP_eCSPI2, D1R | D1W),
+	RDC_PDAPn(RDC_PDAP_SNVS_HP, D1R | D0R | D0W),
 
 	/* memory region */

 

I am confused on how to access the RTC with Cortex-M4 and kindly ask for help.

Thank you in advance for your help

Best Regards,

Patryk

 

 

 

Labels (2)
Tags (3)
0 Kudos
Reply
1 Reply

1,033 Views
RoccoBr
Contributor I

Hello,

I'm trying to achieve the same.

 

this is the dump of the registers

SNVS_HP Command Register: 80002100
SNVS_HP Control Register: 0
SNVS_HP Status Register: 80009b00
SNVS_HP Real Time Counter MSB Register: 0
SNVS_HP Real Time Counter LSB Register: 0

SNVS_LP Control Register: 21
SNVS_LP Status Register: 40000000
SNVS_LP Lock Register: 0
SNVS_LP Real Time Counter MSB Register: 0
SNVS_LP Real Time Counter LSB Register: 0

 

Writing 1 to SNVS_HP Control Register will enable the HP real time counter, but then it will become just another independent real time counter at 32KHz, that's not want we want.

SNVS_LP Real Time Counter is always returning 0 , that is strange as bit 31 in SNVS_HP Command Register should guarantee access to privileged registers.

0 Kudos
Reply