[DONE] stm32f0 RTC support
Moderator: RoccoMarco
[DONE] stm32f0 RTC support
Hello,
I'm trying to use the RTC on my stm32f0 chip with the latest trunk version of ChibiOS, but it seems that STM32F0xx/platform.mk doesn't include the common STM32 RTC code, and i'm getting the error "../../os/hal/include/rtc.h:76:21: fatal error: rtc_lld.h: No such file or directory" when I try to build with HAL_USE_RTC set to true. The other STM32 platforms build with either RTCv1 or RTCv2. Is stm32f0's RTC incompatible with existing code?
I'm trying to use the RTC on my stm32f0 chip with the latest trunk version of ChibiOS, but it seems that STM32F0xx/platform.mk doesn't include the common STM32 RTC code, and i'm getting the error "../../os/hal/include/rtc.h:76:21: fatal error: rtc_lld.h: No such file or directory" when I try to build with HAL_USE_RTC set to true. The other STM32 platforms build with either RTCv1 or RTCv2. Is stm32f0's RTC incompatible with existing code?
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: stm32f0 RTC support
Hi,
The RTC driver is not yet tested on the F0 this is why it is not present in platform.mk, you may try to add there the RTCv2 and see if something else is missing.
Giovanni
The RTC driver is not yet tested on the F0 this is why it is not present in platform.mk, you may try to add there the RTCv2 and see if something else is missing.
Giovanni
Re: stm32f0 RTC support
Hey
Added RTCv2 like this:
Build goes a little farther, but this new error pops up:
Compiling hal.c
In file included from ../../os/hal/include/rtc.h:76:0,
from ../../os/hal/include/hal.h:56,
from ../../os/hal/src/hal.c:30:
../../os/hal/platforms/STM32/RTCv2/rtc_lld.h:85:2: error: #error "STM32_PCLK1 frequency is too low to handle RTC without ugly workaround"
Any ideas?
Thanks
Added RTCv2 like this:
Code: Select all
diff --git a/os/hal/platforms/STM32F0xx/platform.mk b/os/hal/platforms/STM32F0xx/platform.mk
index c04d85c..a949036 100644
--- a/os/hal/platforms/STM32F0xx/platform.mk
+++ b/os/hal/platforms/STM32F0xx/platform.mk
@@ -11,6 +11,7 @@ PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/STM32F0xx/stm32_dma.c \
${CHIBIOS}/os/hal/platforms/STM32/I2Cv2/i2c_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/SPIv2/spi_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/USARTv2/serial_lld.c \
+ ${CHIBIOS}/os/hal/platforms/STM32/RTCv2/rtc_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/USARTv2/uart_lld.c
# Required include directories
@@ -19,4 +20,5 @@ PLATFORMINC = ${CHIBIOS}/os/hal/platforms/STM32F0xx \
${CHIBIOS}/os/hal/platforms/STM32/GPIOv2 \
${CHIBIOS}/os/hal/platforms/STM32/I2Cv2 \
${CHIBIOS}/os/hal/platforms/STM32/SPIv2 \
+ ${CHIBIOS}/os/hal/platforms/STM32/RTCv2 \
${CHIBIOS}/os/hal/platforms/STM32/USARTv2
Build goes a little farther, but this new error pops up:
Compiling hal.c
In file included from ../../os/hal/include/rtc.h:76:0,
from ../../os/hal/include/hal.h:56,
from ../../os/hal/src/hal.c:30:
../../os/hal/platforms/STM32/RTCv2/rtc_lld.h:85:2: error: #error "STM32_PCLK1 frequency is too low to handle RTC without ugly workaround"
Any ideas?
Thanks
Re: stm32f0 RTC support
Also here is my configuration: https://github.com/cdrttn/clock
The board is very similar to the F0 Discovery, with the only significant difference being that it has a 32khz external oscillator.
The board is very similar to the F0 Discovery, with the only significant difference being that it has a 32khz external oscillator.
Re: stm32f0 RTC support
Did you ever get the RTC working on the STM32F0?
What do you do to get STM32_PCLK1?
What do you do to get STM32_PCLK1?
- DeusExMachina
- Posts: 223
- Joined: Tue Apr 03, 2012 5:08 am
- Has thanked: 3 times
- Been thanked: 3 times
- DeusExMachina
- Posts: 223
- Joined: Tue Apr 03, 2012 5:08 am
- Has thanked: 3 times
- Been thanked: 3 times
- DeusExMachina
- Posts: 223
- Joined: Tue Apr 03, 2012 5:08 am
- Has thanked: 3 times
- Been thanked: 3 times
Re: stm32f0 RTC support
Heh, it was too good to be true...
I can't get RTC alarm using RTC and EXTI drivers. What could be wrong?
My board is stm32F0Discovery
I can't get RTC alarm using RTC and EXTI drivers. What could be wrong?
Code: Select all
static void extcb2(EXTDriver *extp, expchannel_t channel)
{
(void)extp;
(void)channel;
palTogglePad(GPIOC, GPIOC_LED4);
chSysUnlockFromIsr();
}
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb2},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL}
}
};
RTCAlarm alarm;
struct tm timp;
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
timp.tm_year = 114;
timp.tm_mon = 2;
timp.tm_mday = 11;
timp.tm_hour = 8;
timp.tm_min = 44;
timp.tm_wday = 1;
rtcSetTimeTm(&RTCD1, &timp);
int i = 10; //secs
alarm.tv_datetime = ((i / 10) & 7 << 4) | (i % 10) | RTC_ALRMAR_MSK4 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2; // from testhal example for F4
rtcSetAlarm(&RTCD1, 0, &alarm);
/*
* Activates the EXT driver 1.
*/
extStart(&EXTD1, &extcfg);
My board is stm32F0Discovery
- DeusExMachina
- Posts: 223
- Joined: Tue Apr 03, 2012 5:08 am
- Has thanked: 3 times
- Been thanked: 3 times
Re: stm32f0 RTC support
I have found a bug in a rtc driver. stm32f0 has 1 alarm unit. But in 125 line in rtc.c we have
RTC_ALARMS for STM32F0 is 1.
If we use 0 as second argument for rtcSetAlarm we miss the code in rtc_lld_set_alarm
If we use 1 we are cached by debug check.
Code: Select all
chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS), "rtcSetAlarm");RTC_ALARMS for STM32F0 is 1.
If we use 0 as second argument for rtcSetAlarm we miss the code in rtc_lld_set_alarm
Code: Select all
if (alarm == 1){
...
}
#if RTC_ALARMS == 2
else{
..
}
}If we use 1 we are cached by debug check.
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times