cancel
Showing results for 
Search instead for 
Did you mean: 

rtc time

yang hong
Associate II

Hello,

I am using NUCLEO-F429ZI. I add one battery on my board and work on RTC. RTC is working, however, all time(null), clock() and so on don't work properly as soon as I remove semi hosting. After I dig the information, I know time(NULL), clock() is working on semi hosting. Actual, I would like to have UTC time, local time, and RTC second for my application. Does anybody have some way to fix this issue? I know I can rewrite codes to get it, but if library is available, why we don't use it?

Thank you in advance.

3 REPLIES 3
KnarfB
Principal III

After you have removed semihosting, you may provide your custom implementation in syscalls.c.

I.e. clock() finally calls int _times(struct tms *buf), and time() finally calls int _gettimeofday().

See https://github.com/32bitmicro/newlib-nano-2/tree/master/newlib/libc/time about the library code.

hth

KnarfB

Hello, KnarfB:

Thank you for your information. I check my library list. it looks like sw4stm32 includes newlib-nano folder. I add battery in my NUCLEO-STM32F429ZI, so I am interested in using the rtc time to be my clock. When I call _times(struct tms *buf), it seems it works because I can get time, but it seems the second value is the second since controller start up. Do you have any idea to implement rtc to clock() or _time() ?

Regards,

Yang

KnarfB
Principal III

clock() calls _times(). So you implement _times as you need (for example RTC) and clock() should work.

Same for time(): implement _gettimeofday() as you need (RTC).

check with newlib https://sourceware.org/newlib/ under Docs Timefns

hth

KnarfB