cancel
Showing results for 
Search instead for 
Did you mean: 

USB configuration conflicts with RTC_SetTime

abelloni
Associate II
Posted on October 31, 2013 at 15:08

Hi everybody,

I'm using a STM32 L152CB microcontroller with external clock. Initially I used it without USB and the RTC_SetTime worked. Since I configured the USB, the function (RTC_SetTime) doesn't work and my RTC_TimeTypeDef struct is always to 0 for each parameters (day, month, etc..)

The micro's frequency is 16Mhz and the USB's clock is 48Mhz.

Have you suggestions?

Thanks!

#rtc #clock #usb
11 REPLIES 11
chen
Associate II
Posted on November 01, 2013 at 12:16

Check your interrupt set up.

You mentioned the RTC is an external device - does it use IRQs??

The USB code relies heavily on IRQs, this may be interfering with the RTC code.

Amel NASRI
ST Employee
Posted on November 01, 2013 at 13:37

Is the function ''RTC_SetTime'' reached or the execution is stuck somewhere before?

Try to check this.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on November 01, 2013 at 14:45

I'm not entirely convinced there is a conflict between the RTC and USB.

Perhaps you can modify a VCP or MSC example to demonstrate this?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kevin1078
Associate II
Posted on October 13, 2014 at 09:44

I also encountered this problem. It's stuck at RTC_EnterInitMode, waiting for RTC_ISR_INITF flag to be set. It succeeds before USB_Start, whereas fails after it.

Posted on October 13, 2014 at 10:13

When stuck, read out and post the content of RTC_ISR and RCC_CSR registers.

JW
kevin1078
Associate II
Posted on October 13, 2014 at 10:32

In STM32L1XX_StdPeriph_Lib_V1.2.0,  there is no RCC_CSR, do you mean RCC_CR?

RCC_ISR: 0x00000234 (I also saw 0x0000003F before), RCC_CR: 0x00007340.

This stuck occurs right after the following code:

/*** Set interrupt mask ***/

  wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;

  _SetCNTR(wInterrupt_Mask);

Regards,

Posted on October 13, 2014 at 10:54

> In STM32L1XX_StdPeriph_Lib_V1.2.0,  there is no RCC_CSR, do you mean RCC_CR?

Who cares about the ''library''? See RM0038 ch.5.3.14.

>This stuck occurs right after the following code:

>

>/*** Set interrupt mask ***/

>  wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;

>  _SetCNTR(wInterrupt_Mask);

I have no idea, what is _SetCNTR(). Before, you told us that the stuck occurs at waiting for RTC_ISR.INITF. Show us the real code.

JW

kevin1078
Associate II
Posted on October 13, 2014 at 11:10

Sorry, I typed RCC->CSR as RTC->CSR and got no result.

RTC->ISR: 0x00000234

RCC->CSR: 0x1E410300.

Code:

ErrorStatus RTC_EnterInitMode(void)

{

  __IO uint32_t initcounter = 0x00;

  ErrorStatus status = ERROR;

  uint32_t initstatus = 0x00;

     

  /* Check if the Initialization mode is set */

  if ((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)

  {

    /* Set the Initialization mode */

    RTC->ISR = (uint32_t)RTC_INIT_MASK;

    

    /* Wait till RTC is in INIT state and if Time out is reached exit */

    do

    {

      initstatus = RTC->ISR & RTC_ISR_INITF;

      initcounter++;  

    } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00));

    

    if ((RTC->ISR & RTC_ISR_INITF) != RESET)

    {

      status = SUCCESS;

    }

    else

    {

      status = ERROR;

    }        

  }

  else

  {

    status = SUCCESS;  

  }

    

  return (status);  

}

INITMODE_TIMEOUT = 0x2000

Thanks.

kevin1078
Associate II
Posted on October 13, 2014 at 11:51

About _SetCNTR:

#define RegBase  (0x40005C00L)  /* USB_IP Peripheral Registers base address */

/* Control register */

#define CNTR    ((__IO unsigned *)(RegBase + 0x40))

#define _SetCNTR(wRegValue)  (*CNTR   = (uint16_t)wRegValue)

this function operates USB_CNTR register.