Description
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:
- set prescaler to a value >256 (e.g., RTC2 to 4096)
- 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..