-
Notifications
You must be signed in to change notification settings - Fork 1k
Add RTC driver #177
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
Add RTC driver #177
Conversation
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.
One comment / proposal about the callback type but overall looks good to me
@@ -175,7 +175,7 @@ | |||
|
|||
/* Section 2: PHY configuration section */ | |||
|
|||
/* DP83848 PHY Address*/ | |||
/* DP83848 PHY Address*/ |
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.
You're mixing up 2 things in the commit - clean-up of various white spaces with the actual changes for RTC.
In such cases, please try to make 2 separate commits instead ...
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.
Done!
cores/arduino/stm32/rtc.c
Outdated
* @param func: pointer to the callback | ||
* @retval None | ||
*/ | ||
void attachAlarmCallback(void (*func)(void)) |
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.
rather than
void (*func)(void)
it could be useful from application to offer a callback of type
void (func)(void data)
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.
you would mean: void (*func)(void*)
?
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.
What information would you like to pass in parameter? rtc handler? other?
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 is up to application . It could the time when alarm was set, or a pointer to the led to be turned on. The application provides a pointer and you simply pass it back to application. This is useful for callback mecanisms. It would be particularly useful if setting several alarms.
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.
It is not the application that choice this parameter. It is the driver which can return a parameter.
If you don't say me the parameter to return, I think return a void* is useless.
Or I must change the prototype of attachAlarmCallback to take account another parameter with the data pointer (also useless).
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.
sorry if unclear, the user data is passed from application to driver, stored in driver and then passed back from driver to application. The driver doesn't know which informaition it contains.
This can be useful for coding generic callback where you don't need to store application data as globals or in context.
https://arduino.stackexchange.com/questions/23063/user-callback-functions
https://stackoverflow.com/questions/14270846/passing-a-parameter-in-a-callback-in-c
In the case of RTC alarm, this can be useful if application can set 2 different alarms in future, then application could pass the programmed time, or a different LED or whatever it needs
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.
It is clearer thank you. And done.
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 driver must handle all possible RTC clock config.
cores/arduino/stm32/rtc.c
Outdated
/* RTC prediv are set to the default values to match with the LSE clock source. | ||
If the clock source is modified, those prescalers must be changed */ | ||
/* Synchonuous prediv */ | ||
#define PREDIV_S 0x00FF |
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.
Main restriction of the driver is the RTC clock configuration.
The driver have to be able to dela with all possible source (HSE, LSE,LSI).
Refer to AN4759 Overview of the STM32 MCU advanced RTC
§ 1.1.4 RTC clock configuration
cores/arduino/stm32/rtc.c
Outdated
* the backup registers) and RCC_CSR register are set to their reset values. | ||
* @retval None | ||
*/ | ||
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) |
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.
ditto
cores/arduino/stm32/rtc.c
Outdated
* @param format: enable the RTC in 12 or 24 hours mode | ||
* @retval None | ||
*/ | ||
void RTC_init(hourFormat_t format) |
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.
Have to mange RTC clock config
RTC driver updated with clock source selection. Compilation OK. |
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.
It should be possible to define [HSE|LSE|LSI]_A?SYNC_PREDIVas for each variant clock values are defined.
Ex:
#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ |
cores/arduino/stm32/rtc.h
Outdated
((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ | ||
((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) | ||
|
||
#define IS_RTC_HOUR12(HOUR) IS_RTC_HOUR24(HOUR) |
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.
Seems F1 do not define it. Probably because it do not handle 12h format.
A comment could be added to give the reason.
cores/arduino/stm32/rtc.c
Outdated
} | ||
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | ||
if(source == LSE_CLOCK) { | ||
RtcHandle.Init.AsynchPrediv = LSE_ASYNCH_PREDIV; |
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.
[HSE|LSE|LSI]_A?SYNC_PREDIV should not be hard-coded. User should have a way to dynamically change them without add a dedicated define. At least an API to change the default value.
Anyway, as mentioned in rtc.h, it should be possible to define the best PREDIV
cores/arduino/stm32/rtc.h
Outdated
- LSE = 32.768 kHz | ||
- HSE = 8 MHz | ||
|
||
Prescalers should be set by user in case the clock configuration is different. |
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.
It should be possible to define [HSE|LSE|LSI]_A?SYNC_PREDIV as for each variant clock values are defined.
Ex:
#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ |
Have you considered adding an |
@lacklustrlabs |
@fpistm I guess std::function callbacks can be added at any time later on, the only thing that should be considered now is if std::function callbacks are good (fast and memory efficient) enough to replace C-style callbacks. If so, the switch-over should be made now, before the API is released. If you want plain C-style callbacks in the API, the std::function callbacks can be added at any time later. The downside of this option is a, possible, duplicated callback handling. |
… quakesense branch - Add RTC driver for STM32 boards - Fix some conflicts in cores/arduino/board.h
Hi @fprwi6labs |
@lacklustrlabs |
Signed-off-by: fpr <[email protected]>
Signed-off-by: fpr <[email protected]>
Hi @fpistm @lacklustrlabs |
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.
Some issues and restrictions found during the review.
Those have been fixed in #235
#235 include this PR rebased on top of the master. |
Driver to use the internal RTC:
This driver is linked with the STM32RTC library.