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

RTC prescaler overflow on nRF(52) #22014

Closed
ChristianHirsch opened this issue Jan 17, 2020 · 1 comment · Fixed by #22019
Closed

RTC prescaler overflow on nRF(52) #22014

ChristianHirsch opened this issue Jan 17, 2020 · 1 comment · Fixed by #22019
Labels
bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx

Comments

@ChristianHirsch
Copy link
Contributor

Describe the bug
when setting prescaler of a (nRF52840) RTC to a value greater than 256, the value overflows. therefore, it is not possible to use all the 12bit of the prescaler as mentioned in the nRF52840 datasheet.

To Reproduce
Steps to reproduce the behavior:

  1. set prescaler to a value >256 (e.g., RTC2 to 4096)
  2. execute on nRF52840:
struct device *counter_dev = device_get_binding(DT_RTC_2_NAME);
counter_start(counter_dev);
k_sleep(1000);
counter_stop(counter_dev);
u32_t ticks = counter_read(counter_dev);

Expected behavior
the value of tick should be 8, however it is 128. the counter is 16 times faster because of the overflow: 256 * 16 = 4096).

Screenshots or console output
warning indicating the overflow:

zephyr/drivers/counter/counter_nrfx_rtc.c: In function 'counter_2_init':
zephyr/include/generated/generated_dts_board_unfixed.h:661:53: warning: unsigned conversion from 'int' to 'u8_t' {aka 'unsigned char'} changes value from '4095' to '255' [-Woverflow]
 #define DT_NORDIC_NRF_RTC_40024000_PRESCALER        4096
zephyr/include/generated/generated_dts_board_unfixed.h:663:53: note: in expansion of macro 'DT_NORDIC_NRF_RTC_40024000_PRESCALER'
 #define DT_NORDIC_NRF_RTC_RTC_2_PRESCALER           DT_NORDIC_NRF_RTC_40024000_PRESCALER
                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/chirsch/workspace/zephyrproject/zephyr/drivers/counter/counter_nrfx_rtc.c:662:5: note: in expansion of macro 'DT_NORDIC_NRF_RTC_RTC_2_PRESCALER'
     DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER - 1);  \
     ^~~~~~~~~~~~~~~~~~~~~~
/home/chirsch/workspace/zephyrproject/zephyr/drivers/counter/counter_nrfx_rtc.c:702:1: note: in expansion of macro 'COUNTER_NRF_RTC_DEVICE'
 COUNTER_NRF_RTC_DEVICE(2);

Environment (please complete the following information):

  • nRF52840 (particle_xenon board)
  • OS: Linux
  • Zephyr SDK 0.10.3
  • 33929cb

Additional context
the effected function is static int init_rtc(struct device *dev, u8_t prescaler) in zephyr/drivers/counter/counter_nrfx_rtc.c. I already tried to change u8_t prescaler to u16_t prescaler wich eliminates the warning, but zephyr crashes..

@ChristianHirsch ChristianHirsch added the bug The issue is a bug, or the PR is fixing a bug label Jan 17, 2020
@ChristianHirsch
Copy link
Contributor Author

I just realized that I had some settings in the prj.conf file which caused the zephyr crashes. changing u8_t prescaler to u16_t prescaler actually fixed the problem.

ChristianHirsch added a commit to ChristianHirsch/zephyr that referenced this issue Jan 20, 2020
use u32_t in init_rtc to be able to use the full 12 bit prescaler values
fixes zephyrproject-rtos#22014

Signed-off-by: Christian Hirsch <christian.hirsch@tuwien.ac.at>
@ioannisg ioannisg added the platform: nRF Nordic nRFx label Jan 20, 2020
ioannisg pushed a commit that referenced this issue Jan 21, 2020
use u32_t in init_rtc to be able to use the full 12 bit prescaler values
fixes #22014

Signed-off-by: Christian Hirsch <christian.hirsch@tuwien.ac.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants