This is a RTC additional function. This is only for Nucleo F401RE & F411RE mbed(Added L152RE, F334R8, L476RG & F746xx). If you connected battery backup circuit for internal RTC, you can make a power-off and reset condition. RTC still has proper time and date.

Dependents:   Nucleo_rtos_sample PB_Emma_Ethernet

Please refer following NOTE information.
/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/

Committer:
kenjiArai
Date:
Mon Feb 16 12:33:22 2015 +0000
Revision:
2:765470eab2a6
Parent:
0:e4c20fd769f1
Child:
5:1a8e7aed053d
L152RE sets an interrupt driven sleep mode when +5V is off

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:e4c20fd769f1 1 /*
kenjiArai 0:e4c20fd769f1 2 * mbed Library program
kenjiArai 0:e4c20fd769f1 3 * Check & set RTC function and set proper clock if we can set
kenjiArai 0:e4c20fd769f1 4 * ONLY FOR "Nucleo Board"
kenjiArai 0:e4c20fd769f1 5 *
kenjiArai 0:e4c20fd769f1 6 * Copyright (c) 2014-2015 Kenji Arai / JH1PJL
kenjiArai 0:e4c20fd769f1 7 * http://www.page.sannet.ne.jp/kenjia/index.html
kenjiArai 0:e4c20fd769f1 8 * http://mbed.org/users/kenjiArai/
kenjiArai 0:e4c20fd769f1 9 * Created: October 24th, 2014
kenjiArai 2:765470eab2a6 10 * Revised: Feburary 16th, 2015
kenjiArai 0:e4c20fd769f1 11 *
kenjiArai 0:e4c20fd769f1 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
kenjiArai 0:e4c20fd769f1 13 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
kenjiArai 0:e4c20fd769f1 14 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kenjiArai 0:e4c20fd769f1 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenjiArai 0:e4c20fd769f1 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kenjiArai 0:e4c20fd769f1 17 */
kenjiArai 0:e4c20fd769f1 18
kenjiArai 2:765470eab2a6 19 /*
kenjiArai 2:765470eab2a6 20 * CAUTION! You need to modify "rtc_api.c" file in the mbed-src library.
kenjiArai 2:765470eab2a6 21 * Please refer "modify_info_xxx.h" file and/or following NOTE.
kenjiArai 2:765470eab2a6 22 * http://developer.mbed.org/users/kenjiArai/notebook/
kenjiArai 2:765470eab2a6 23 * nucleo-series-rtc-control-under-power-onoff-and-re/
kenjiArai 2:765470eab2a6 24 */
kenjiArai 2:765470eab2a6 25
kenjiArai 0:e4c20fd769f1 26 #ifndef SET_RTC_H
kenjiArai 0:e4c20fd769f1 27 #define SET_RTC_H
kenjiArai 0:e4c20fd769f1 28
kenjiArai 0:e4c20fd769f1 29 #include "mbed.h"
kenjiArai 0:e4c20fd769f1 30
kenjiArai 2:765470eab2a6 31 #if defined(TARGET_NUCLEO_L152RE)
kenjiArai 2:765470eab2a6 32 #define USE_IRQ_FOR_RTC_BKUP // Use interrupt for enter RTC backup mode
kenjiArai 2:765470eab2a6 33 #define USE_PB5_FOR_COMP // Use PB5 port for low voltage detection (+5V line)
kenjiArai 2:765470eab2a6 34 //#define USE_PB6_FOR_COMP // Use PB6 port for low voltage detection (+5V line)
kenjiArai 2:765470eab2a6 35 #endif
kenjiArai 2:765470eab2a6 36
kenjiArai 0:e4c20fd769f1 37 #define TIMEOUT ((uint32_t)5000)
kenjiArai 0:e4c20fd769f1 38 #define RTC_DAT0 0x55aa55aa
kenjiArai 0:e4c20fd769f1 39 #define RTC_DAT1 0xaa55aa55
kenjiArai 0:e4c20fd769f1 40
kenjiArai 0:e4c20fd769f1 41 enum {
kenjiArai 0:e4c20fd769f1 42 UNKNOWN = -1,
kenjiArai 0:e4c20fd769f1 43 OK = 0,
kenjiArai 0:e4c20fd769f1 44 NG
kenjiArai 0:e4c20fd769f1 45 };
kenjiArai 0:e4c20fd769f1 46
kenjiArai 0:e4c20fd769f1 47 /** Check and set RTC module inside Nucleo STM32X CPU.
kenjiArai 0:e4c20fd769f1 48 * Latest Nucleo board has external LSE Crystal X2 but no proper setting both HW ans SW.
kenjiArai 0:e4c20fd769f1 49 * In addition, every power on and/or reset make initial condition even HW Backup condition.
kenjiArai 0:e4c20fd769f1 50 * This is cased by mbed initial subroutine problem.
kenjiArai 0:e4c20fd769f1 51 * This program intends to use RTC with X2 and works well with battery back-up hardware setting.
kenjiArai 0:e4c20fd769f1 52 *
kenjiArai 2:765470eab2a6 53 *
kenjiArai 0:e4c20fd769f1 54 * @code
kenjiArai 0:e4c20fd769f1 55 * #include "mbed.h"
kenjiArai 0:e4c20fd769f1 56 * #include "SetRTC.h"
kenjiArai 0:e4c20fd769f1 57 *
kenjiArai 0:e4c20fd769f1 58 * int main() {
kenjiArai 0:e4c20fd769f1 59 * time_t seconds;
kenjiArai 0:e4c20fd769f1 60 *
kenjiArai 0:e4c20fd769f1 61 * CheckRTC();
kenjiArai 0:e4c20fd769f1 62 * printf("Time: %s", ctime(&seconds));
kenjiArai 0:e4c20fd769f1 63 * }
kenjiArai 0:e4c20fd769f1 64 * @endcode
kenjiArai 0:e4c20fd769f1 65 */
kenjiArai 0:e4c20fd769f1 66
kenjiArai 0:e4c20fd769f1 67 /** Check and Set RTC
kenjiArai 0:e4c20fd769f1 68 * @param none
kenjiArai 0:e4c20fd769f1 69 * @return if proper setting = OK, if not = NG and UNKNOWN-> no support this program
kenjiArai 0:e4c20fd769f1 70 */
kenjiArai 0:e4c20fd769f1 71 int32_t SetRTC(void);
kenjiArai 0:e4c20fd769f1 72
kenjiArai 2:765470eab2a6 73 /** Show(print) RTC related registers
kenjiArai 2:765470eab2a6 74 * @param none
kenjiArai 2:765470eab2a6 75 * @return none
kenjiArai 2:765470eab2a6 76 */
kenjiArai 0:e4c20fd769f1 77 void show_RTC_reg( void );
kenjiArai 0:e4c20fd769f1 78
kenjiArai 2:765470eab2a6 79 /** Enter RTC initial data from PC Vertual Com
kenjiArai 2:765470eab2a6 80 * @param none
kenjiArai 2:765470eab2a6 81 * @return none
kenjiArai 2:765470eab2a6 82 */
kenjiArai 0:e4c20fd769f1 83 void time_enter_mode(void);
kenjiArai 0:e4c20fd769f1 84
kenjiArai 2:765470eab2a6 85 /** Preparation for Deep Sleep (Set I/O port and other peripheral low power condition)
kenjiArai 2:765470eab2a6 86 * @param none
kenjiArai 2:765470eab2a6 87 * @return none
kenjiArai 2:765470eab2a6 88 */
kenjiArai 2:765470eab2a6 89 void deepsleep_preparation(void);
kenjiArai 2:765470eab2a6 90
kenjiArai 0:e4c20fd769f1 91 #endif // SET_RTC_H