Time going backwards: aon_timer_get_time() [SDK 2.1.1] #2374
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#2374
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
After upgrading from SDK version 2.1.0 to 2.1.1, I noticed weird behavior with aon_timer_get_time() on RP2040 (pico_w).
Time returned seems to randomly go backwards (and forwards) 1 hour.
I have a project that displays clock (among other things) on OLED panel, and after upgrading to new SDK (2.1.1), I noticed hour digit was randomly toggling back and forth.
So I added some 'debug' output in the function that gets the current (RTC) time:
This is from the function shown below (that gets called about once a second):
(switching back to SDK 2.1.0 seems to "fix" the issue)
Actually, seems like this is happening on SDK 2.1.0, but lot less frequently, it its minutes to hours between occurrences.
I left test running overnight and save couple occurrences logged:
When this happens time seems to jump forward 1 hour for about a second and then jump back....
As if this is somehow timezone (daylight savings) related, but doesn't seem aon_timer_get_time() does any timezone processing?
It calls mktime. I wonder if that's doing some daylight saving. It might be worth zeroing the struct timespec ts; memory which might indicate a bug in datetime_to_tm?
I think you might be right, if I clear the timespec struct before calling aon_timer_get_time(), it would seem like issue goes away....
Good find. I guess we should be setting tm_isdst to zero. Although how it determines day light saving is on is beyond me.
Actually, we should just make sure it's not -1? Or always use -1?
Seems like clearing timespec before making call to aon_timer_get_time() didn't really "help", just unlucky that didn't see the issue immediately...
Looks like datetime_to_tm() leaves three fields uninitialized (tm_wday, tm_yday, tm_isdst) that likely lead to the random issues I was seeing?
This change would seem to "fix" the issue for me:
Looks like workaround to the issue (that avoids having to patch the SDK) is to define following pico_mktime() function (that overrides the implementation in SDK, thanks to the __weak linker directive).
Seems like this issue is only triggered when timezone is set to a timezone that has daylight savings time.
I'm getting time from NTP, so I'm setting timezone in order to convert UTC time received from NTP server to local time
(I was using following timezone "PST8PDT7,M3.2.0/2,M11.1.0/02:00:00")
I'm setting timezone as follows:
less of a workaround and more of a fix, as
tm_isdstdoes need to be initialized, however in this case i would put it indatetime_to_tmmerged into develop
Thanks!
Btw, why doesn't datetime_to_tm() still fully initialize the struct tm? It would seem there should be at least warning in the docs that it doesn't do full convesion from "datetime" to "tm", etc? (and leaves tm_wday and tm_yday fields uninitialized)
@tjko If there's additional functionality you'd like to see, please open a new issue (or PR) 🙂