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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SetRTC.h Source File

SetRTC.h

00001 /*
00002  * mbed Library program
00003  *      Check & set RTC function and set proper clock if we can set
00004  *      ONLY FOR "Nucleo Board"
00005  *
00006  *  Copyright (c) 2014,'15,'16 Kenji Arai / JH1PJL
00007  *  http://www.page.sannet.ne.jp/kenjia/index.html
00008  *  http://mbed.org/users/kenjiArai/
00009  *      Created: October   24th, 2014
00010  *      Revised: May       28th, 2016
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
00013  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00014  * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 
00019 /*
00020  * CAUTION! You need to modify "rtc_api.c" file in the mbed-dev library.
00021  *          Please refer "modify_info_xxx.h" file and/or following my notebook.
00022  *          http://developer.mbed.org/users/kenjiArai/notebook/
00023  *              nucleo-series-rtc-control-under-power-onoff-and-re/
00024  */
00025 
00026 #ifndef SET_RTC_H
00027 #define SET_RTC_H
00028 
00029 #include "mbed.h"
00030 
00031 #if defined(TARGET_STM32L152RE)
00032 #define USE_IRQ_FOR_RTC_BKUP    // Use interrupt for enter RTC backup mode
00033 #define USE_PB5_FOR_COMP        // Use PB5 port for low voltage detection (+5V line)
00034 //#define USE_PB6_FOR_COMP        // Use PB6 port for low voltage detection (+5V line)
00035 #endif
00036 
00037 #define TIMEOUT     ((uint32_t)5000)
00038 #define RTC_DAT0    0x55aa55aa
00039 #define RTC_DAT1    0xaa55aa55
00040 
00041 /** Check and set RTC module inside Nucleo STM32X CPU.
00042  *      Latest Nucleo board has external LSE Crystal X2 but no proper setting both HW ans SW.
00043  *      In addition, every power on and/or reset make initial condition even HW Backup condition.
00044  *      This is cased by mbed initial subroutine problem.
00045  *      This program intends to use RTC with X2 and works well with battery back-up hardware setting.
00046  *
00047  *
00048  * @code
00049  * #include "mbed.h"
00050  * #include "SetRTC.h"
00051  *
00052  * int main() {
00053  *   time_t seconds;
00054  *
00055  *   if (SetRTC(0) == 1) { // No use COMP(PB5 or 6) (only L152RE)
00056  *       PRINTF("Use External CLK (Good for RTC)\r\n");
00057  *   } else {
00058  *       PRINTF("Use Internal CLK (Bad for RTC)\r\n");
00059  *   }
00060  *   printf("Time: %s", ctime(&seconds));
00061  * }
00062  * @endcode
00063  */
00064 
00065 /** Check and Set RTC
00066   * @param use_comparator = 1 Use COMP(only for L152 PB5 or 6 set-up), =0 no HW modification
00067   * @return if proper setting = 1, if not = 0
00068   */
00069 int32_t SetRTC(uint8_t use_comparator);
00070 
00071 /** Show(print) RTC related registers
00072   * @param none
00073   * @return none
00074   */
00075 void show_RTC_reg( void );
00076 
00077 /** Enter RTC initial data from PC Vertual Com
00078   * @param none
00079   * @return none
00080   */
00081 void time_enter_mode(void);
00082 
00083 /** Go to Standbay Mode (Set I/O port and other peripheral low power condition)
00084   * @param none
00085   * @return none
00086   */
00087 void goto_standby(void);
00088 
00089 #endif      // SET_RTC_H