Skip to content

boards/nucleo-l1: use LSI as default RTC clock#6504

Closed
haukepetersen wants to merge 4 commits intoRIOT-OS:masterfrom
haukepetersen:fix_stm32l1_rtc_lse
Closed

boards/nucleo-l1: use LSI as default RTC clock#6504
haukepetersen wants to merge 4 commits intoRIOT-OS:masterfrom
haukepetersen:fix_stm32l1_rtc_lse

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

@haukepetersen haukepetersen commented Jan 27, 2017

fixes #6502
rebased on #6499 (needed for testing)

seems like not all nucleo-l1 boards have an external low-speed oscillator (LSE) attached. So I propose to make it configurable in the board's periph_conf and choose the LSI (internal low-speed oscillator) per default.

@haukepetersen haukepetersen added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Jan 27, 2017
@haukepetersen haukepetersen added this to the Release 2017.01 milestone Jan 27, 2017
@vincent-d
Copy link
Copy Markdown
Member

vincent-d commented Jan 27, 2017

The problem of the LSI is its accuracy. But it works if application does not require accuracy for long periods I guess.

However, I took a new look to the RTC application note. It seems that the stm32l1 LSI is a 37kHz oscillator, then the prescaler register needs to be adapted. (AN3371, part 1.1.2, page 9)

@PeterKietzmann
Copy link
Copy Markdown
Member

I'm on current master (includes #6499) without this PR running tests/periph_rtc. The output looks as expected:

2017-01-27 16:53:49,806 - INFO # RIOT RTC low-level driver test
2017-01-27 16:53:49,811 - INFO # This test will display 'Alarm' in 10 seconds
2017-01-27 16:53:49,811 - INFO # 
2017-01-27 16:53:49,812 - INFO # Initializing the RTC driver
2017-01-27 16:53:49,817 - INFO # Setting clock to 2011-12-13 14:15:15
2017-01-27 16:53:49,823 - INFO # Clock set to 2011-12-13 14:15:15
2017-01-27 16:53:49,824 - INFO # Setting alarm to 2011-12-13 14:15:25
2017-01-27 16:53:49,829 - INFO # Alarm set to 2011-12-13 14:15:25
2017-01-27 16:53:49,830 - INFO # The alarm should trigger every 10 seconds for 4 times.
2017-01-27 16:53:59,825 - INFO # Alarm!
2017-01-27 16:54:09,821 - INFO # Alarm!
2017-01-27 16:54:19,823 - INFO # Alarm!
2017-01-27 16:54:29,825 - INFO # Alarm!

So does with this PR.. Do we actually need it?

#else
/* Enable the LSI clock */
RCC->CSR = RCC_CSR_LSION;
while (!(RCC->CSR & RCC_CSR_LSIRDY)) {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For a F0 this didn't work. The LSI is off after each reboot but (RCC->BDCR & RCC_BDCR_RTCEN) == 1 so rtc_poweron() isn't called. Adding these 2 lines to clk_init() in cpu.c solved it for me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will look into this.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

@PeterKietzmann: probably your board is equipped with an external low-speed oscillator, so it works on master. But mine isn't, so it doesnt work on master -> ergo: this PR is needed.

@vincent-d
Copy link
Copy Markdown
Member

I proposed some more fixes in haukepetersen#37

  • prescaler values updated
  • LSI for stm32fx

But I don't really like the LSI as default...

@PeterKietzmann PeterKietzmann added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 31, 2017
@miri64 miri64 added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jan 31, 2017
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Jan 31, 2017

Confirmed that it works for nucleo-l152, but it breaks on nucleo-f091. Should this bug be postponed?

@PeterKietzmann
Copy link
Copy Markdown
Member

I'd say yes. The release should go out tomorrow. Testing has mostly passed and I already added this issue to known issues in the preliminary (still invisible) release notes. Will take care of all 2017.01 labelled PRs tomorrow.

@vincent-d
Copy link
Copy Markdown
Member

@kYc0o weird, I tested on a nucleo-f091 here and it worked :/

Anyway, I agree it should be postponed.

@PeterKietzmann PeterKietzmann modified the milestones: Release 2017.01, Release 2017.04 Feb 1, 2017
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Feb 2, 2017

Well, mine gets stuck in setting the clock:

2017-02-02 12:42:52,413 - INFO # main(): This is RIOT! (Version: 2017.04-devel-8-gd1df5-snake.lan-pr/stm32l_lsi)
2017-02-02 12:42:52,413 - INFO # 
2017-02-02 12:42:52,415 - INFO # RIOT RTC low-level driver test
2017-02-02 12:42:52,420 - INFO # This test will display 'Alarm' in 10 seconds
2017-02-02 12:42:52,420 - INFO # 
2017-02-02 12:42:52,421 - INFO # Initializing the RTC driver
2017-02-02 12:42:52,425 - INFO # Setting clock to 2011-12-13 14:15:15

Same question: Which revision of nucleo-f091 do you have? does it have an external oscillator?

@vincent-d
Copy link
Copy Markdown
Member

My nucleo-f091 has an external oscillator. I've just retested on it (with #define CLOCK_HAS_LSE (0) ) and I got the same issue, it gets stuck.

On a nucleo-f042 without LSE, it works fine.

@vincent-d
Copy link
Copy Markdown
Member

This is not a RTC issue, this is a timer configuration issue. It get stuck in xtimer_usleep.

@vincent-d
Copy link
Copy Markdown
Member

Seems related to #6494

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Feb 2, 2017

Oh yeah! We need to merge first #6494 and then this will work for both boards. I'll add the Waiting for other PR flag.

I rebased this one with #6494 and everything works for both nucleo-l1 and nucleo-f091 boards.

@kYc0o kYc0o added State: waiting for other PR State: The PR requires another PR to be merged first and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Feb 2, 2017
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Feb 7, 2017

@haukepetersen can you squash and optionally rebase to include #6494 ? Then I think this is ready.

@PeterKietzmann
Copy link
Copy Markdown
Member

Ping @haukepetersen

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Feb 27, 2017

any update on this one @haukepetersen ?

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Yes, that makes sense. One more reason to handle the clock LS(I/E) clock only at one place in the code.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

I am looking into refining the RTT/RTC interfaces right now, and will in the same run look into a way to handle this for all STM32 CPUs

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Apr 25, 2017

Can we merge this one for this release? I think that as long as the bug is solved, we can wait for the rework on this interface and merge it for the next release.

AFAIK this PR is a working state and can be merged asap (besides the need of squash).

@haukepetersen
Copy link
Copy Markdown
Contributor Author

nope, won't merge this in the current state. Have a far better solution to the problem now (based on some clock initialization restructuring as done in #6907), so I will adapt this PR accordingly.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Apr 26, 2017

And you think we can get it for the release? That's only my point, that is broken and it will stay broken for this release...

@haukepetersen haukepetersen added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 1, 2017
@haukepetersen
Copy link
Copy Markdown
Contributor Author

the solution as in this PR is sub-optimal, found something better by now: the rtc module should utilize stmclk_enable_lfclk() from newly introduced stm32_common/include/stmclk.h interface. The problem: this is not implement for many STM family members yet -> so once this is done, everything in this PR falls into place. Opened #7123 for tracking the implementation progress.

@haukepetersen haukepetersen force-pushed the fix_stm32l1_rtc_lse branch from 3fa0951 to cf0da44 Compare June 1, 2017 17:35
@haukepetersen
Copy link
Copy Markdown
Contributor Author

pushed an update to the rtc driver using the stmclk interface -> much easier to the eye... But as said: all WIP as of now...

@haukepetersen
Copy link
Copy Markdown
Contributor Author

closing in favor of #7504

@haukepetersen haukepetersen deleted the fix_stm32l1_rtc_lse branch August 23, 2017 13:37
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Jan 11, 2018

#8024 led me here... So, I propose to enable the internal oscillator only for the nucleo-l152 board, since anyways nobody will use it for accurate RTC and all stm32l152 have LSI. Should I open a PR for that small change? I tested it on a board with external oscillator and works correctly with LSI set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpu/stm32l1: RTC broken

8 participants