This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335X: RTC synchronization

Other Parts Discussed in Thread: AM3352

Hi Everyone,

We are using a custom board with AM3352 processor. We are using an External rtc on the board which is battery backup-ed. 

I would greatly appreciate if someone can give me suggestions regarding syncronizing the external rtc to internal rtc.

1)  I am trying to implement the functionality in SPL code. is it a good idea to do the sync in the SPL or U-Boot?? or is it even possible in SPL code? I could able to configure the External RTC and read the date but is there any info on how to configure this date from external rtc to the internal rtc?

Thanks,

Ray

  • Hi Ray,
     
    Some comments on your questions:
    SPL may not be the best place to do this, because SPL code has to fit into the AM335X internal memory. So it depends on how much code you add. The AM335X internal RTC is decribed in detail in section 20.3 of the AM335X Technical Reference Manual, Rev.I. The typical setup sequence is shown in section 20.3.4. Note that there are two kick registers (KICK0R, KICK1R), that have to be written with correct values in order to unlock the RTC for writing. A note also on the RTC clock source - you will need to to use the OSC1 oscillator (32.768kHz crystal) or an external 32.768kHz clock source on RTC_XTALIN in order to keep accurate time. The internal RC oscillator is not precise enough for timekeeping purposes.
  • Thank you for your response Biser.

    I am changing the board.c file of ti/am335x. I have read the TRM of AM335x and i guess the init part of internal rtc is taken care by

    static void rtc32k_enable(void)

    {

    struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;

    writel(0x83e70b13, &rtc->kick0r);

    writel(0x95a4f1e0, &rtc->kick1r);

    /* Enable the RTC 32K OSC by setting bits 3 and 6. */

    writel((1 << 3) | (1 << 6), &rtc->osc);

    }

    I have just started my coding. We are using an external rtc and planning to sync the internal rtc of the Am335x( will use as a system clk)  after every regular intervals. The external rtc is on i2c bus. I was wondering about the size of the SPL if this sync is implemented. I will verify today..

     

  • Hi ,

    I am trying to read the external RTC (ds1307) attached to the i2c-1 bus of the beaglebone black but  i am getting the

    "timed out in wait_for_pin: I2C_STAT=0 " error messages.

    I am implementing inthe SPL code..

    enable_i2c1_pin_mux();

    i2c_set_bus_num(1);

    i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);

    I have made sure that i enable the i2c-1 pin mux and also set the bus_num to 1...I could not able to probe the external RTC device. it gives me a time out error..

    I have also included

    #define CONFIG_I2C_MULTI_BUS 1 in my config file..

    Iwould really appreciate if anyone can help me point the mistake i a doing..

    Thank you

  • Hi Roy,
     
    The BB Black does not have pullup resistors on the I2C1 interface. You will need to install external pullups to 3.3V for I2C1 to function properly.
  • Hi Biser. 

    Thank you for the reply. 

    I am able to access the RTC from the user space. I have added the RTC1 in device tree and it now shows up in the /dev list. Also when i do a i2cdetect -y -r 1 it recognizes it on address 0x68. I am able to do all the operation on it from the user space (hwclock -r. -w ,. -s....)

    The problem is when its in the SPL..

    board.c code....

    .

    .

    enable_i2c0_pin_mux();
    i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);


    if (read_eeprom() < 0)
    puts("Could not get board ID.\n");

    enable_board_pin_mux(&header);

    /* sync function for External RTC and Internal RTC */
    enable_i2c1_pin_mux();
    i2c_set_bus_num(1);
    i2c_init(50000, CONFIG_SYS_I2C_SLAVE);
    if(sync_rtcs()<0)
    puts("***************************Could not set the RTC******************\n");

    i am making sure i am using the i2c after the pin mux is initialized. I have also debuged the omap24xx_i2c.c file...

    when i change the bus to 1, the base address is getting changed( thats correct!) but in the i2c probe(rtc_address), it fails in the wait_for_pin(void)...its getting timed out...

    When i change the bus to 1 the base address is changed correspondingly in i2cprobe() too..but still i have this timeout error....

    I was thinking should we deinitialize the bus 0 to make the bus1 active?? we are calling the eeprom on i2c 0 and rtc on i2c1...like a reset required???

    Thank you..

  • Hi ,

    I am still having problem communicating with an external RTC on i2c-1 bus in the SPL code. I keep on getting this message when i am trying to probe the slave device on the i2c-1 bus...

    I have initialized the i2c1 mux and also verified that the current bus is changed to 1 and also the i2c_base address is changed to i2c1 base.

    puts("***************************Setting the ERTC******************\n");
    enable_i2c1_pin_mux();
    i2c_set_bus_num(1);
    if(sync_rtcs()<0)
    puts("***************************Could not set the RTC******************\n");

    enable_i2c0_pin_mux();
    i2c_set_bus_num(0);
    i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);


    if (read_eeprom() < 0)
    puts("Could not get board ID.\n");

    i have problem only with External RTC, the eeprom is read properly after changing the bus to 0 again...

    Is it the problem with the External rtc pins on the i2c bus1??? but i could able to see the device and set the time from the user space.

    When does the timed out error occur???

    Thank you and appreciate your reply

  • Have you resolved the problem? I have a similar time out issue when probing stuff on Beagle Bone Black i2c1 or i2c2 bus on u-boot spl. The bus is always busy. Even this patch didn't resolve it. I'm trying to detect my cryptocape during boot.

    Best Regards

    Jussi

  • Hi Jussi,

    Make sure the pin mux is initalized properly and initialize the Bus to correct one (0 or 1 or 2).  I think i got it working on the beaglebone-black sometime back.

    Thanks,

    Harsha

  • Hello Biser,

    In the above answer:

    The internal RC oscillator is not precise enough for timekeeping purposes.

    Does it mean that we can still use internal RC oscillator (32.768KHz) for time keeping purposes with less precision?

    Thanks and regards,

    Paul

  • Hello Biser,

    Thank you for the response. But it does not answer my question. Let me put in a clear way.

    (1) Can we use the internal RC Oscillator for RTC purpose? (Even if the accuracy is less, it is not a problem)

    (2) AM335x Datasheet, section 6.2.1 says that RTC can be configured to receive clock from internal RC Oscillator. Please see the snapshot below. Is it true?

    Thanks and regards,

    Paul

  • Yes, you can. This is the default setting.

  • Hello Biser,

    Then could you please tell us how to do that?

    We could not see any options in the Clock Tree tool or in the TRM. Also we see a contradictory block diagram in TRM where there is no option to connect the internal RC Oscillator to the RTC block. Please find below.

    Thanks and regards,

    Paul

  • Sorry, sorry, sorry... I was misguiding you. The RC oscillator is not available for the RTC, it can be used with the WDT and DMTimer0. The RTC can be clocked either from the external crystal/oscillator, or from a dedicated divider from the Peripheral PLL.