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/
SetRTC.h@6:ef7d2c83034d, 2015-02-19 (annotated)
- Committer:
- kenjiArai
- Date:
- Thu Feb 19 02:56:12 2015 +0000
- Revision:
- 6:ef7d2c83034d
- Parent:
- 5:1a8e7aed053d
- Child:
- 7:fa32602e23ec
Bug fix when External Xtal is not avairable. In addtion change checking method for STM32xxx register status
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:ef7d2c83034d | 10 | * Revised: Feburary 19th, 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 | /** Check and set RTC module inside Nucleo STM32X CPU. |
kenjiArai | 0:e4c20fd769f1 | 42 | * Latest Nucleo board has external LSE Crystal X2 but no proper setting both HW ans SW. |
kenjiArai | 0:e4c20fd769f1 | 43 | * In addition, every power on and/or reset make initial condition even HW Backup condition. |
kenjiArai | 0:e4c20fd769f1 | 44 | * This is cased by mbed initial subroutine problem. |
kenjiArai | 0:e4c20fd769f1 | 45 | * This program intends to use RTC with X2 and works well with battery back-up hardware setting. |
kenjiArai | 0:e4c20fd769f1 | 46 | * |
kenjiArai | 2:765470eab2a6 | 47 | * |
kenjiArai | 0:e4c20fd769f1 | 48 | * @code |
kenjiArai | 0:e4c20fd769f1 | 49 | * #include "mbed.h" |
kenjiArai | 0:e4c20fd769f1 | 50 | * #include "SetRTC.h" |
kenjiArai | 0:e4c20fd769f1 | 51 | * |
kenjiArai | 0:e4c20fd769f1 | 52 | * int main() { |
kenjiArai | 0:e4c20fd769f1 | 53 | * time_t seconds; |
kenjiArai | 0:e4c20fd769f1 | 54 | * |
kenjiArai | 0:e4c20fd769f1 | 55 | * CheckRTC(); |
kenjiArai | 0:e4c20fd769f1 | 56 | * printf("Time: %s", ctime(&seconds)); |
kenjiArai | 0:e4c20fd769f1 | 57 | * } |
kenjiArai | 0:e4c20fd769f1 | 58 | * @endcode |
kenjiArai | 0:e4c20fd769f1 | 59 | */ |
kenjiArai | 0:e4c20fd769f1 | 60 | |
kenjiArai | 0:e4c20fd769f1 | 61 | /** Check and Set RTC |
kenjiArai | 0:e4c20fd769f1 | 62 | * @param none |
kenjiArai | 6:ef7d2c83034d | 63 | * @return if proper setting = 1, if not = 0 |
kenjiArai | 0:e4c20fd769f1 | 64 | */ |
kenjiArai | 0:e4c20fd769f1 | 65 | int32_t SetRTC(void); |
kenjiArai | 0:e4c20fd769f1 | 66 | |
kenjiArai | 2:765470eab2a6 | 67 | /** Show(print) RTC related registers |
kenjiArai | 2:765470eab2a6 | 68 | * @param none |
kenjiArai | 2:765470eab2a6 | 69 | * @return none |
kenjiArai | 2:765470eab2a6 | 70 | */ |
kenjiArai | 0:e4c20fd769f1 | 71 | void show_RTC_reg( void ); |
kenjiArai | 0:e4c20fd769f1 | 72 | |
kenjiArai | 2:765470eab2a6 | 73 | /** Enter RTC initial data from PC Vertual Com |
kenjiArai | 2:765470eab2a6 | 74 | * @param none |
kenjiArai | 2:765470eab2a6 | 75 | * @return none |
kenjiArai | 2:765470eab2a6 | 76 | */ |
kenjiArai | 0:e4c20fd769f1 | 77 | void time_enter_mode(void); |
kenjiArai | 0:e4c20fd769f1 | 78 | |
kenjiArai | 5:1a8e7aed053d | 79 | /** Go to Standbay Mode (Set I/O port and other peripheral low power condition) |
kenjiArai | 2:765470eab2a6 | 80 | * @param none |
kenjiArai | 2:765470eab2a6 | 81 | * @return none |
kenjiArai | 2:765470eab2a6 | 82 | */ |
kenjiArai | 5:1a8e7aed053d | 83 | void goto_standby(void); |
kenjiArai | 2:765470eab2a6 | 84 | |
kenjiArai | 0:e4c20fd769f1 | 85 | #endif // SET_RTC_H |