From 2af38d749c012448a9ad1c8b956065b38504e176 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Thu, 15 Feb 2018 21:12:40 +0100 Subject: [PATCH 1/2] cpu: efm32: fix RTC for Series 0 MCUs. Without fix: Setting alarm to 12627-11-30 15:00:05 Alarm is set to 12722-01-25 07:13:03 With fix: Setting alarm to 2011-12-13 14:15:17 Alarm is set to 2011-12-13 14:15:17 --- cpu/efm32/periph/rtc_series0.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/efm32/periph/rtc_series0.c b/cpu/efm32/periph/rtc_series0.c index ef75a7e675..08dbf535d4 100644 --- a/cpu/efm32/periph/rtc_series0.c +++ b/cpu/efm32/periph/rtc_series0.c @@ -34,7 +34,7 @@ typedef struct { rtc_alarm_cb_t alarm_cb; /**< callback called from RTC interrupt */ void *alarm_arg; /**< argument passed to the callback */ - uint32_t alarm; /**< scheduled alarm (may be defered) */ + time_t alarm; /**< scheduled alarm (may be deferred) */ uint8_t overflows; /**< number of overflows */ } rtc_state_t; @@ -95,7 +95,7 @@ void rtc_init(void) int rtc_set_time(struct tm *time) { - uint32_t timestamp = mktime(time); + time_t timestamp = mktime(time); rtc_state.overflows = (timestamp >> RTC_SHIFT_VALUE); RTC->CNT = timestamp & RTC_MAX_VALUE; @@ -105,7 +105,7 @@ int rtc_set_time(struct tm *time) int rtc_get_time(struct tm *time) { - uint32_t timestamp = RTC_CounterGet(); + time_t timestamp = RTC_CounterGet(); timestamp = timestamp + (rtc_state.overflows << RTC_SHIFT_VALUE); From 2329b84935b051ba10d848563d67aa2cdd8fa1b1 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Thu, 15 Feb 2018 21:14:09 +0100 Subject: [PATCH 2/2] cpu: efm32: fix ADC resolution selection The `res` argument is a combination of resolution and shifting, combined using `(y << 4) | x`. To yield x, `0x0F` should have been used. --- cpu/efm32/periph/adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/efm32/periph/adc.c b/cpu/efm32/periph/adc.c index f98ffac661..a015ab08b6 100644 --- a/cpu/efm32/periph/adc.c +++ b/cpu/efm32/periph/adc.c @@ -76,7 +76,7 @@ int adc_sample(adc_t line, adc_res_t res) init.acqTime = adc_channel_config[line].acq_time; init.reference = adc_channel_config[line].reference; - init.resolution = (ADC_Res_TypeDef) (res & 0xFF); + init.resolution = (ADC_Res_TypeDef) (res & 0x0F); #ifdef _SILICON_LABS_32B_SERIES_0 init.input = adc_channel_config[line].input; #else