cancel
Showing results for 
Search instead for 
Did you mean: 

time.h problem

aeolia_amha
Associate II
Posted on June 17, 2010 at 11:41

time.h problem

4 REPLIES 4
Posted on May 17, 2011 at 13:54

The Keil library does not support specific hardware implementation, it does not have it's own timers. You will need to implement time using the RTC, SysTick or other hardware timers within the STM32. The Keil library does support localtime(),globaltime(),asctime(),strftime().

You should look at RealTerm instead of HyperTerminal. If you want to time stamp the serial data, you could either write your own simple application, or buy one. The current version of RealTerm offers time stamping.

http://realterm.sourceforge.net/

http://www.lookrs232.com/

http://www.lmgtfy.com/?q=serial+port+time+stamp

Alternatively if you get the RTC running on the STM32, printing the time in HH:MM:SS just involves some trivial math with the value read with RTC_GetCounter().

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 13:54

That's one of reasons I really like IAR's Embbedded Workbench product line. They provide low-level stubs for implementing standard ANSI-C library functions (which I've done).

Keil also permits hosting of platform specific functions. People mainly use it to direct IO to/from the serial port, but time() can be implement too, or he could simply use RTC_GetCounter() directly if there is no legacy code being ported in.

http://www.keil.com/support/man/docs/gsac/gsac_retargetcortex.htm

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
swhite2
Associate III
Posted on May 17, 2011 at 13:54

That's one of reasons I really like IAR's Embbedded Workbench product line. They provide low-level stubs for implementing standard ANSI-C library functions (which I've done).

e.g.

time_t                                  time(time_t *t)

{

time_t      rtc_counter;

    // Return the STM32F103 RTC counter value (32-bit) if the RTC is running.

    rtc_counter = rtc_configured ? RTC_GetCounter() : INVALID_TIME_T_VALUE;

    if (t)

    {

        *t = rtc_counter;

    }

    return (rtc_counter);

}

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:54

I can get the time manually and use RTC set counter. How do you get the PC time automatically after turning on the MCU. Getting the timestamp is more efficient and accurate. Can you suggest a modification of my u32 time_regulate code to set up the time. Is there any way to implement this or do I need to use the program that you recommended.

Here is my code:

u32 Time_Regulate(void)    //input time

{

struct tm t;

time_t t_of_day;

printf(''\nYear:'');

t.tm_year = USART_Scanf(2038)-1900;

printf(''\nMonth:'');

t.tm_mon = USART_Scanf(12)-1; //Number of months since January. [0-11] Go figure.

printf(''\nDay:'');

t.tm_mday = USART_Scanf(31);

printf(''\nHour:'');

t.tm_hour = USART_Scanf(24);

printf(''\nMinutes:'');

t.tm_min = USART_Scanf(60);

printf(''\nSeconds:'');

t.tm_sec = USART_Scanf(60);

t.tm_isdst = 0;

t_of_day = mktime(&t);

printf(''\n'');

printf(ctime(&t_of_day));

printf(''tday = %d'',t_of_day);

//printf(''time(0)=%d'',time(0));

return(t_of_day); //Return the value to store in RTC counter register

}

/*******************************************************************************

* Function Name  : Time_Adjust

* Description    : Adjusts time.

*******************************************************************************/

void Time_Adjust(void)

{

  RTC_WaitForLastTask();       /* Wait until last write operation on RTC registers has finished */

  RTC_SetCounter(Time_Regulate());   /* Change the current time */

  RTC_WaitForLastTask();     /* Wait until last write operation on RTC registers has finished */

}