how to make spi interface rtc function work for imx8mq maaxboard ?

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

how to make spi interface rtc function work for imx8mq maaxboard ?

Jump to solution
6,476 Views
gonewithwind-peter
Senior Contributor I

Hello everyone,

I want to add RTC function to imx8 maaxboard,

We used another board with SPI interface and rtc chip M41T93RMY6F on the motherboard.

I found that there is a kernel driver file for the chip M41T93RMY6F.

and so

problem:

1.

I need to configure the kernel to select spi rtc M41T93RMY6F support, right?

So after the kernel is configured, should spi rtc work properly?

2. After the kernel is started, how to configure or read/set the time or date in the user space?

3. Or directly use hwclock command to set/read rtc? No other settings or configurations are needed after the kernel is started?

4. Any user space application source code?

 

 

thank you very much.

Labels (1)
0 Kudos
1 Solution
6,234 Views
gonewithwind-peter
Senior Contributor I

hi

@igorpadykov 

step 1

I have  successfully added the rtc spi m41t39 in maaxbaord.

I have fixed the issue,
 
the spi cs pin is wrong in dts file
it should change to cs-gpios = <&gpio5 9 0 > ; from  cs-gpios = <&gpio5 13 0 > ;
 
I checked the imx8mq processor hardware datasheet
 
the ecsp1_ss0 is gpio5.io9 not io13
 
the gpio5.io13 is ecsp2_ss0 , wrong at here.
 
correct:
 

237                 pinctrl_ecspi1: ecspi1grp {

238                                 fsl,pins = <

239                                 MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9               0x16

240                                 MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI    0x16

241                                 MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO    0x16

242                                 MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK    0x1816

243                         >;

244                 };

 
 

&ecspi1{

    fsl,spi-num-chipselects = < 1 >;

    cs-gpios = <&gpio5 9 0 > ;

    pinctrl-names = "default";

    pinctrl-0 = <&pinctrl_ecspi1 >;

    status = "okay";

    #address-cells=<1>;

    #size-cells=<0>;

    rtc@0x00{

        #address-cellss=<1>;

        #size-cells=<1>;

        compatible = "rtc-m41t93";

        spi-max-frequency = <5000000>;

        reg = <0>;

    };

};

 

step 2. config m41t39  in kernel config.

NOT use module, need to build in  kernel. because if use module. every time after kernel start up, the module should insert and the time should reset again so that it seems does not work.

 

 

 

 

View solution in original post

0 Kudos
22 Replies
222 Views
gonewithwind-peter
Senior Contributor I

I searched online with "how to directly read /write spi in linux user space"

results:

The most popular way for SPI read/write in user space is through character device /dev/spidev but this way gives you only half-duplex access. An other way for SPI read/write in user space is through ioctl SPI_IOC_MESSAGE(N) request that gives you full-duplex access.

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/680213/linux-am3352-spi-co...

https://stackoverflow.com/questions/36626214/can-i-select-on-a-dev-spidev-file-descriptor

 

Maybe it can hep you

0 Kudos
2,816 Views
gonewithwind-peter
Senior Contributor I

@igorpadykov 

 

Do you know, is there a way to get status of the RTC? for example to know if battery needs to be replaced?
 
I mean how to read RTC Battery low warning in user space app code?
Thank you
 
0 Kudos