In the past, you need modify rtc_api.c in mbed-dev source code. From this revision, you can just use RTC function all of conditions (Normal, Reset, Stand-by, Power OFF).

Note

From now on, you do NOT need any modification for mbed-dev library because STM team updates rtc_api.c source code and support RTC function under reset & standby condition includes power off condition (You need additional VBAT back-up hardware).

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

uart_as_stdio/uart_as_stdio.cpp

Committer:
kenjiArai
Date:
2021-03-06
Revision:
14:4b03106ece1f

File content as of revision 14:4b03106ece1f:

/*
 * mbed Application program
 *      Redirect Standard Input/Output
 *
 * Copyright (c) 2021 Kenji Arai / JH1PJL
 *  http://www7b.biglobe.ne.jp/~kenjia/
 *  https://os.mbed.com/users/kenjiArai/
 *      Created:    January   13th, 2021
 *      Revised:    March      5th, 2021
 */

//  Include --------------------------------------------------------------------
#include "mbed.h"

//  Definition -----------------------------------------------------------------

//  Constructor ----------------------------------------------------------------
static BufferedSerial pc(USBTX, USBRX, 9600);

//  RAM ------------------------------------------------------------------------

//  ROM / Constant data --------------------------------------------------------

//  Function prototypes --------------------------------------------------------

//------------------------------------------------------------------------------
//  Control Program
//------------------------------------------------------------------------------
uint8_t readable()
{
    return pc.readable();
}

void putc(uint8_t c)
{
    char dt[4];
    dt[0] = (char)c;
    pc.write(dt, 1);
}

uint8_t getc()
{
    char dt[4];
    pc.read(dt, 1);
    return (uint8_t)dt[0];
}

//https://os.mbed.com/users/kenjiArai/code/Check_DeepSleep_os6/
void sleep_preparation()
{
    pc.enable_input(false);
    sleep_manager_can_deep_sleep();
}