summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-15 10:11:01 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-15 10:11:01 -0600
commit4c809d5ca15f368b5df62cfeeeb30345d1bdbd1d (patch)
tree34560ba6a248fb4e6b858855e1f3648f29076275
parent5d9b977ff2096530d7d89fc3047608e529f707ea (diff)
downloadnuttx-4c809d5ca15f368b5df62cfeeeb30345d1bdbd1d.tar.gz
nuttx-4c809d5ca15f368b5df62cfeeeb30345d1bdbd1d.tar.bz2
nuttx-4c809d5ca15f368b5df62cfeeeb30345d1bdbd1d.zip
Add support for RTC driver to the STM32F4-Discovery board
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_rtc.h4
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_rtc_lowerhalf.c4
-rw-r--r--nuttx/configs/stm32f4discovery/src/stm32_bringup.c49
-rw-r--r--nuttx/configs/stm32f4discovery/src/stm32f4discovery.h7
-rw-r--r--nuttx/include/nuttx/rtc.h2
5 files changed, 56 insertions, 10 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_rtc.h b/nuttx/arch/arm/src/stm32/stm32_rtc.h
index 095b2f838..b90c2b11c 100644
--- a/nuttx/arch/arm/src/stm32/stm32_rtc.h
+++ b/nuttx/arch/arm/src/stm32/stm32_rtc.h
@@ -180,8 +180,8 @@ int stm32_rtc_cancelalarm(void);
****************************************************************************/
#ifdef CONFIG_RTC_DRIVER
-struct rtc_lower_half_s;
-FAR struct rtc_lower_half_s *stm32_rtc_lowerhalf(void);
+struct rtc_lowerhalf_s;
+FAR struct rtc_lowerhalf_s *stm32_rtc_lowerhalf(void);
#endif
#undef EXTERN
diff --git a/nuttx/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/nuttx/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
index 7d85d2d9d..1a7c1e27d 100644
--- a/nuttx/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
+++ b/nuttx/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
@@ -273,9 +273,9 @@ static int stm32_settime(FAR struct rtc_lowerhalf_s *lower,
*
****************************************************************************/
-FAR struct rtc_lower_half_s *stm32_rtc_lowerhalf(void)
+FAR struct rtc_lowerhalf_s *stm32_rtc_lowerhalf(void)
{
- return (FAR struct rtc_lower_half_s *)&g_rtc_lowerhalf;
+ return (FAR struct rtc_lowerhalf_s *)&g_rtc_lowerhalf;
}
#endif /* CONFIG_RTC_DRIVER */
diff --git a/nuttx/configs/stm32f4discovery/src/stm32_bringup.c b/nuttx/configs/stm32f4discovery/src/stm32_bringup.c
index 0b7f7adb1..0e4f55b43 100644
--- a/nuttx/configs/stm32f4discovery/src/stm32_bringup.c
+++ b/nuttx/configs/stm32f4discovery/src/stm32_bringup.c
@@ -1,7 +1,7 @@
/****************************************************************************
* config/stm32f4discovery/src/stm32_bringup.c
*
- * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -48,13 +48,24 @@
# include <apps/usbmonitor.h>
#endif
+#include "stm32.h"
+
#ifdef CONFIG_STM32_OTGFS
# include "stm32_usbhost.h"
#endif
-#include "stm32.h"
#include "stm32f4discovery.h"
+/* Conditional logic in stm32f4discover.h will determine if certain features
+ * are supported. Tests for these features need to be made after including
+ * stm32f4discovery.h.
+ */
+
+#ifdef HAVE_RTC_DRIVER
+# include <nuttx/rtc.h>
+# include "stm32_rtc.h"
+#endif
+
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
@@ -79,6 +90,9 @@
int stm32_bringup(void)
{
+#ifdef HAVE_RTC_DRIVER
+ FAR struct rtc_lowerhalf_s *lower;
+#endif
int ret = OK;
#ifdef HAVE_SDIO
@@ -87,7 +101,7 @@ int stm32_bringup(void)
ret = stm32_sdio_initialize();
if (ret != OK)
{
- fdbg("Failed to initialize MMC/SD driver: %d\n", ret);
+ fdbg("ERROR: Failed to initialize MMC/SD driver: %d\n", ret);
return ret;
}
#endif
@@ -100,7 +114,7 @@ int stm32_bringup(void)
ret = stm32_usbhost_initialize();
if (ret != OK)
{
- udbg("Failed to initialize USB host: %d\n", ret);
+ udbg("ERROR: Failed to initialize USB host: %d\n", ret);
return ret;
}
#endif
@@ -111,7 +125,32 @@ int stm32_bringup(void)
ret = usbmonitor_start(0, NULL);
if (ret != OK)
{
- udbg("Start USB monitor: %d\n", ret);
+ udbg("ERROR: Failed to start USB monitor: %d\n", ret);
+ return ret;
+ }
+#endif
+
+#ifdef HAVE_RTC_DRIVER
+ /* Instantiate the STM32 lower-half RTC driver */
+
+ lower = stm32_rtc_lowerhalf();
+ if (!lower)
+ {
+ sdbg("ERROR: Failed to instantiate the RTC lower-half driver\n");
+ return -ENOMEM;
+ }
+ else
+ {
+ /* Bind the lower half driver and register the combined RTC driver
+ * as /dev/rtc0
+ */
+
+ ret = rtc_initialize(0, lower);
+ if (ret < 0)
+ {
+ sdbg("ERROR: Failed to bind/register the RTC driver: %d\n", ret);
+ return ret;
+ }
}
#endif
diff --git a/nuttx/configs/stm32f4discovery/src/stm32f4discovery.h b/nuttx/configs/stm32f4discovery/src/stm32f4discovery.h
index 0992f1f4d..5c29e38b7 100644
--- a/nuttx/configs/stm32f4discovery/src/stm32f4discovery.h
+++ b/nuttx/configs/stm32f4discovery/src/stm32f4discovery.h
@@ -67,6 +67,7 @@
#define HAVE_USBHOST 1
#define HAVE_USBMONITOR 1
#define HAVE_SDIO 1
+#define HAVE_RTC_DRIVER 1
/* Can't support USB host or device features if USB OTG FS is not enabled */
@@ -133,6 +134,12 @@
# endif
#endif
+/* Check if we can support the RTC driver */
+
+#if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DRIVER)
+# undef HAVE_RTC_DRIVER
+#endif
+
/* STM32F4 Discovery GPIOs **************************************************/
/* LEDs */
diff --git a/nuttx/include/nuttx/rtc.h b/nuttx/include/nuttx/rtc.h
index 3ffc5f2f2..287a067ef 100644
--- a/nuttx/include/nuttx/rtc.h
+++ b/nuttx/include/nuttx/rtc.h
@@ -6,7 +6,7 @@
*
* With extensions, modifications by:
*
- * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved.
* Author: Gregroy Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without