-
Notifications
You must be signed in to change notification settings - Fork 8.3k
samples: rtc: add sample app for rtc subsystem #79078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples: rtc: add sample app for rtc subsystem #79078
Conversation
825f00e to
44ed2c4
Compare
755a3f6 to
15f94a4
Compare
|
Has it been considered to just enabling the RTC shell (I see its manually disabled in the config file)? Time can be both set and gotten in ISO format, and it works with any board and any RTC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dashes in names don't have spaces:
clock-frequency = <I2C_BITRATE_STANDARD>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node should be indented here:
rtc0: ds1307 @68 {
compatible = "maxim,ds1307";
...
};
samples/drivers/rtc/ds1307/prj.conf
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONFIG_RTC_DS1307=y is automatically selected if the ds1307 exists in the devicetree with status "okay", so it can be removed
samples/drivers/rtc/ds1307/prj.conf
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONFIG_I2C=y is automatically selected by the RTC_DS1307 device driver, so can be removed
samples/drivers/rtc/ds1307/prj.conf
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default for these options is already =n, so these can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed all unnecessary Kconfig options and changed the overlay as you suggested.
15f94a4 to
b3736db
Compare
|
@bjarki-andreasen This sample was created to help anyone quickly learn the RTC API, saving time by skipping the need to sift through documentation. :) |
|
If you think this sample is helpful I thinks it good to add it, but as a sample, its important that it is portable :) That is, can be built for any board with any RTC :) If you look to the test suite in The sample should be in |
b3736db to
b618766
Compare
|
I have used |
b618766 to
91145c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sample should be built for an in-tree board which actually has an RTC, rather than a custom board with an external RTC attached, like a b_u585i_iot02a for example, along with an emulated board like the native_sim which has an emulated RTC.
The sample will still work fine with your custom board downstream naturally :)
samples/drivers/rtc/src/main.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not required as const struct device *const rtc = DEVICE_DT_GET(DT_ALIAS(rtc)); will result in a compilation error (undefined reference) if this pointer is "NULL", try removing the alias from your overlay, or set status of the rtc to "disabled" and you will see what I mean :)
samples/drivers/rtc/src/main.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialization is not required, its assigned before read later on, also just use int to match the return value type of the rtc_get_time() API :)
samples/drivers/rtc/src/main.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specific return value is not used, so this can be simplified to:
if (get_date_time(rtc)) {
printk("Failed to read from rtc\n");
return 0;
}
and even:
while (get_date_time(rtc) == 0) {
k_sleep(K_MSEC(1000));
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made changes as you requested.
b5ea98b to
289c8e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason the esp32_devkitc_wroom_proccpu overlay can't be included upstream is that its a modification you have made to your board locally. If someone else has the same board, but has a different RTC on a different bus, the overlay for your board will be applied to their different board if they try to build this sample...
Only boards can be used upstream, not boards with local additions/modifications (with exception for test fixtures like gpio_loopback but that's another story)
samples/drivers/rtc/src/main.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this sample, it should probably always set the time :) so SET_DATE_TIME should be removed. If you really want it, the define should be a Kconfig like CONFIG_TEST_SET_DATE_TIME
See:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/rtc/rtc_api/Kconfig
| static const uint16_t test_alarm_time_mask_set = CONFIG_TEST_RTC_ALARM_TIME_MASK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed #ifdef SET_DATE_TIME and custom overlay for esp32_devkitc_wroom.
samples/drivers/rtc/src/main.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper get_date_time() already prints that it failed to get the time, including the error code, so adding an additional get_date_time() call and printing printk("Failed to read from rtc\n"); is redundant IMO.
It would produce:
Current RTC time: ...
Cannot read date time: -1
Failed to read from rtc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, it can then be simplified to:
while (get_date_time(rtc) == 0) {
k_sleep(K_MSEC(1000));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the logic as you suggested. I appreciate your feedback and hope that this pull request is not taking too much of your time. :)
bjarki-andreasen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, nice work!
kartben
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All sample should have a README, can you please add one? You may use the sample.tmpl template (or other samples' READMEs) as a starting point. Thanks!
2db47d7 to
0151266
Compare
0151266 to
af8c20a
Compare
|
@kartben Could you please review the PR and let me know if any further changes are needed? After adding the README, all checks have passed, including the Documentation build. 🙂 |
af8c20a to
8b508f4
Compare
|
@pdgendt Could you please run the full CI and also review the changes? |
kartben
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work! a few remaining comments but virtually +1 as soon as they're addressed :) Thanks!
This sample app set and read date/time from the Real-Time Clock. Signed-off-by: Muhammad Waleed Badar <[email protected]>
8b508f4 to
7dff437
Compare
|
Hi @walidbadar! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
|
@walidbadar had you issues to set the month of the rtc with the stm32 driver? I saw during debugging, that the month november would be checked with the value 0x11. the rtc_ll_stm32.c module convert the bin to bcd and the stm32wlxx_ll_rtc.c convert it back to bin and checks with the value 0x11 (what is wrong)... |
This sample app sets and periodically reads date/time from the RTC.
Tested with stm32f3 discovery board internal RTC.