Question to Hardware / RTC: datetime #2540
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 milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#2540
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?
Dear Pico and Raspberry Pi developers,
regarding to
hardawre/rtcit came up a simple question to me.The stuct for datetime looks like this:
pico hardware/rtc
Would it be not great do it like that:
instead of do it like that?
you can reuse
struct tmand feed directly intortc?Would it not be a great thing to align it to the official
struct tmcpp struct tm
To be able to use directly the struct tm to feed the rtc and also be able to get a struct tm back from rtc?
Then you easily ca request a
timestampfrom ntp create atmand set rtc with thetm.hardware_rtcis a low-level wrapper around the hardware itself (and is also specific to RP2040 - see section 12.10.2 of https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf for RP2350 details).For a higher-level API, see
pico_timeanddatetime(the latter includes conversion to and fromsruct tm).@lurch
this results in a further question.
How can I then set the rtc from High-level API functions?
And how is the procedure when getting the time from rtc and to use in pico_time?
PS: the
datetime_thas the same member information thanstruct tmwhy don't use existing stuff?Perhaps you also want to look at https://github.com/raspberrypi/pico-examples/?tab=readme-ov-file#rtc and https://github.com/raspberrypi/pico-examples/?tab=readme-ov-file#timer ?
And in terms of "Why does the API work the way it does", those are questions that only @kilograham can answer.
But if you have any suggestions for how the existing APIs can be improved, we happily take Pull Requests 🙂
The point is what I want to do with the pico W is;
But if I understand the things right I need to convert the
struct tm => datetime_tto feed the rtc, isn't it right?Presumably you've seen the picow_ntp_client example then? (although it looks like that just retrieves the time, and doesn't update the RTC)
Thanks for answering so fast yes I have seen the ntp client example.
Thats right it is not updating the rtc, but what is then the benefit of rtc?
I think it is much mor accurate and keeps also track of time during sleep, right?
The ntp client example does not set the time on cpu/pico, it keeps the time only in variables!
The ntp client example query the ntp time and show it, but I dont want to query the ntp all the time.
I want to set the time on the pico and use it and only query the ntp very less amounts.
Please correct when I am wrong!
See picture:
@frankhaefele Unless you have concrete suggestions, it's sounding more and more like you should be asking for help at https://forums.raspberrypi.com/viewforum.php?f=143 rather than on GitHub.
No I am not asking for help, it came up as you mentioned the example
ntp_client, because it does not save the time on the pico.@kilograham as I mentioned above #1,
datetime_thas the same information thanstruct tm.Why there are two structs like that?
Nor would I expect it to. All of the examples in https://github.com/raspberrypi/pico-examples/ are deliberately small, simple and focus on doing just one thing; in order make the code easier to read and understand, without multiple things going on at once.
So if you want to know how to control the RTC, look at the
hello_rtcexample. If you want to know how to read the time from an NTP server, look at thepicow_ntp_client example.If you want to "set the time on the pico and use it and only query the ntp very less amounts" then you'll need to understand how the examples are working, and write that code yourself. (Or ask for help on the forums)
@lurch
I checked now the
pico_ntp_clientexample.But a small feedback.
The documentation is on very poor level for this example.
Just take an example to mention only on item:
#define NTP_RESEND_TIME (10 * 1000)Resend time has nothing to do with resend!
It is the time when the failed handler is executed.
If the user should easily understand the code, the coders should be also precise in coding.
@hasenradball Please feel free to create an issue (or PR) on the
pico-examplesrepo 🙂@lurch
would do hat but my other PR not reviewed since years, I have not so much free space to prepare an PR which would noch reviewed for months.
By the way I restructured a litte the example where I now set the
system timeandRTCby the NTP.So I am used a example look like.
cheers frank