Skip to content
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

implement a One-Second interrupt on stm32 MCUs #57

Merged
merged 4 commits into from
Dec 15, 2021

Conversation

FRASTM
Copy link
Contributor

@FRASTM FRASTM commented Nov 25, 2021

This Enhancement is adding a interrupt on each second for the stm32xx MCUs

for the stm32F1 : the RTC One-Second flag interrupt is asserted on each RTC Core 1Hz clock cycle
for other MCUS the RTC WakeUP feature is programmed to interrupt each second
depending on the stm32 serie, this interrupt channel is a global or a specific one.
In the the stm32F0xx serie, other than STM32F071xB, STM32F072xB, STM32F078xx, STM32F091xC, STM32F098xx, STM32F070xB, STM32F030xC do not support the WakeUp capability.

A simple example RTC_Seconds demonstrating the feature with a basic callback function that toggle a bit each second
This test is passed on stm32F1 (nucleo f103rb), stm32G4 (nucleo g474re), stm32L4 (nucleo l476rg), stm32WB (nucleo wb55rg), stm32L1 (nucleo l152re), stm32F7 (nucleo 144 f767zi)

This PR is inspired by the #42

Signed-off-by: Francois Ramu francois.ramu@st.com

@FRASTM
Copy link
Contributor Author

FRASTM commented Nov 25, 2021

The stm32 MCUs have different name/ position for the wakeUp interrupt to be used as the one-second interrupt ; defining single ONESECOND_IRQn depending on the soc serie

@FRASTM
Copy link
Contributor Author

FRASTM commented Nov 26, 2021

The stm32 MCUs have different name/ position for the wakeUp interrupt to be used as the one-second interrupt ; defining single ONESECOND_IRQn depending on the soc serie
Adapt for stm32 mcus with "Wakeup auto-reload output clear value" where the HAL_RTCEx_SetWakeUpTimer_IT differs.

@FRASTM FRASTM force-pushed the seconds_int branch 2 times, most recently from ad28be4 to 871786c Compare November 26, 2021 11:16
examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
src/rtc.c Outdated Show resolved Hide resolved
@FRASTM
Copy link
Contributor Author

FRASTM commented Nov 26, 2021

Note that STM32F030x4/6, STM32F070x6 and STM32F030x8 devices do not have WakeUp feature in their RTC and only one Alarm

@FRASTM FRASTM force-pushed the seconds_int branch 2 times, most recently from c9c7e96 to 0895dd7 Compare November 30, 2021 08:40
@FRASTM
Copy link
Contributor Author

FRASTM commented Nov 30, 2021

Ada a #error when a device which does not support the feature, is choosen for the sketch or driver

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First please rebase on top of the main to avoid to have the get/set prescaler commits.
Fix the build issues raised by the STM32RTC Continuous Integration / Library compilation, example:

/github/home/Arduino/libraries/workspace/src/rtc.c: In function 'attachSecondsIrqCallback':
/github/home/Arduino/libraries/workspace/src/rtc.c:757:46: error: 'RTC_WAKEUPCLOCK_CK_SPRE_16BITS' undeclared (first use in this function); did you mean 'LL_RTC_WAKEUPCLOCK_CKSPRE_WUT'?
  757 |   HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, 0, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                              LL_RTC_WAKEUPCLOCK_CKSPRE_WUT
/github/home/Arduino/libraries/workspace/src/rtc.c:757:46: note: each undeclared identifier is reported only once for each function it appears in

Error during build: exit status 1


|   2/45   | NUCLEO_F031K6                              |   failed   |  4.82 s |
/github/home/Arduino/libraries/workspace/src/rtc.c: In function 'attachSecondsIrqCallback':
/github/home/Arduino/libraries/workspace/src/rtc.c:757:46: error: 'RTC_WAKEUPCLOCK_CK_SPRE_16BITS' undeclared (first use in this function); did you mean 'LL_RTC_WAKEUPCLOCK_CKSPRE_WUT'?
  757 |   HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, 0, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                              LL_RTC_WAKEUPCLOCK_CKSPRE_WUT
/github/home/Arduino/libraries/workspace/src/rtc.c:757:46: note: each undeclared identifier is reported only once for each function it appears in

Error during build: exit status 1


|   3/45   | NUCLEO_F042K6                              |   failed   |  5.20 s |

src/rtc.c Outdated Show resolved Hide resolved
src/rtc.c Outdated Show resolved Hide resolved
@FRASTM
Copy link
Contributor Author

FRASTM commented Dec 10, 2021

rebase
Raise a compilation error on the sketch when the feature is not supported on the MCU

@fpistm fpistm added this to the 1.2.0 milestone Dec 13, 2021
examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
src/STM32RTC.h Outdated Show resolved Hide resolved
src/rtc.c Outdated Show resolved Hide resolved
src/rtc.c Outdated Show resolved Hide resolved
src/rtc.c Outdated Show resolved Hide resolved
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think to update the README.md

src/rtc.h Show resolved Hide resolved
src/rtc.h Show resolved Hide resolved
src/rtc.c Show resolved Hide resolved
src/rtc.c Outdated Show resolved Hide resolved
examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
@FRASTM
Copy link
Contributor Author

FRASTM commented Dec 14, 2021

The code added for this feature is under #ifdef ONESECOND_IRQn
In the attachSecondsIrqCallback, the ONESECOND_IRQn is enabled
In the detachSecondsIrqCallback, the except for the stm32F1, the ONESECOND_IRQn is not disabled. becasue it could be used elsewhere. The callback is reset though.

A callback function is attached for this interrupt
The same callback is referenced whatever the device
(stm32F1 or other stm32 soc)

Signed-off-by: Francois Ramu <francois.ramu@st.com>
The stm32F1 device has specific one-second interrupt.
For stm32 devices that do not have a seconds interrupt
the RTC WakeUp is programmed to interrupt the system
on a one-second period.
The HAL_RTCEx_WakeUpTimerEventCallback is called instead
keeping the same naming RTCSecondsIrqCallback.
Some stm32F0 mcus do not support the wakeUp feature.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Signed-off-by: Francois Ramu <francois.ramu@st.com>
@FRASTM
Copy link
Contributor Author

FRASTM commented Dec 14, 2021

updates the README.md

examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
examples/RTC_Seconds/RTC_Seconds.ino Outdated Show resolved Hide resolved
enable the second interrupt and display time
each second, thanks to its callback function
Raise an error if the sketch not running on the devices
(not stm32F1 and no wakeUp interrupt available)

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants