Driver for the LVD and PVD peripherals on RA MCUs. This module implements the Low Voltage Detection Interface.
- Note
- In the below usage notes, "LVD" refers to both LVD and PVD.
Overview
The Low Voltage Detection module configures the voltage monitors to detect when a power supply pin or a voltage detector pin voltages crosses a specified threshold.
Features
The LVD HAL module supports the following functions:
- Seven run-time configurable voltage monitors (Voltage Monitor 1, Voltage Monitor 2, Voltage Monitor 4, Voltage Monitor 5, LVD VBAT, LVD VRTC, EXLVD)
- Configurable voltage threshold
- Digital filter (Available on specific MCUs)
- Support for both interrupt or polling
- NMI or maskable interrupt can be configured (NMI support for Voltage Monitor 1 & Voltage Monitor 2 only).
- Voltage monitor interrupt generation condition can be configured (rising, falling, or both edge event detection).
- Support for resetting the MCU when VCC falls below/rises above configured threshold.
Note: Voltage monitor availability is limited based on the selected MCU.
Supported Devices
| Device Group | Devices |
| RA0 | RA0E1, RA0E2, RA0E3, RA0L1 |
| RA2 | RA2A1, RA2A2, RA2E1, RA2E2, RA2E3, RA2L1, RA2L2, RA2T1 |
| RA4 | RA4C1, RA4E1, RA4E2, RA4L1, RA4M1, RA4M2, RA4M3, RA4T1, RA4W1 |
| RA6 | RA6E1, RA6E2, RA6M1, RA6M2, RA6M3, RA6M4, RA6M5, RA6T1, RA6T2, RA6T3 |
| RA8 | RA8D1, RA8D2, RA8E1, RA8E2, RA8M1, RA8M2, RA8P1, RA8T1, RA8T2 |
Configuration
Build Time Configurations for r_lvd
The following build time configurations are defined in fsp_cfg/r_lvd_cfg.h:
| Configuration | Options | Default | Description |
| Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Configurations for Monitoring > Low/Programmable Voltage Detection (r_lvd)
This module can be added to the Stacks tab via New Stack > Monitoring > Low/Programmable Voltage Detection (r_lvd). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.
| Configuration | Options | Default | Description |
| Name | Name must be a valid C symbol | g_lvd0 | Module name. |
| Monitor Number | MCU Specific Options | | Select the LVD monitor. |
| Digital Filter | MCU Specific Options | | Enable the digital filter and select the digital filter clock divider. |
| Voltage Threshold | MCU Specific Options | | Select the low voltage detection threshold. |
| Detection Response | MCU Specific Options | | Select what happens when the voltage crosses the threshold voltage. |
| Voltage Slope | MCU Specific Options | | Select interrupt generation on rising voltage, falling voltage or both. |
| Negation Delay | MCU Specific Options | | Negation of the monitor signal can either be delayed from the reset event or from voltage returning to normal range. |
| Monitor Interrupt Callback | Name must be a valid C symbol. | NULL | A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the IRQ triggers. |
| LVD Monitor Interrupt Priority | MCU Specific Options | | Select the LVD Monitor interrupt priority. |
Clock Configuration
The LOCO clock must be enabled in order to use the digital filter.
Pin Configuration
To use LVD module, you need to switch pin function of EXLVDVBAT pin, VRTC pin, EXLVD pin to enable LVD function on this pin.
Usage Notes
Startup Edge Detection
If VCC is below the threshold prior to configuring the voltage monitor for falling edge detection, the monitor will immediately detect the a falling edge condition. If VCC is above the threshold prior to configuring the monitor for rising edge detection, the monitor will not detect a rising edge condition until VCC falls below the threshold and then rises above it again.
Voltage Monitor 0
The LVD HAL module only supports configuring voltage monitor 1 and voltage monitor 2. Voltage monitor 0 can be configured by setting the appropriate bits in the OFS1 register. This means that voltage monitor 0 settings cannot be changed at runtime.
Voltage monitor 0 supports the following features
- Configurable Voltage Threshold (VDET0)
- Reset the device when VCC falls below VDET0
Limitations
- The digital filter must be disabled when using voltage monitors in Software Standby or Deep Software Standby.
- Deep Software Standby mode is not possible if the voltage monitor is configured to reset the MCU.
- Reset generated by the VCC-rise detection is supported only on devices with PVD.
- On RA0, when LVD0 is used the detection voltage of LVD1 must be higher than LVD0's. See in hardware manual: LVD > Register Descriptions > LVD1CR.
- Voltage Monitor 4, Voltage Monitor 5 does not support interrupt feature.
- LVD Monitor 1 and LVD Monitor 2 must have the same security attribution. Either both monitors are used in the secure project, or both monitors are used in the non-secure project.
Examples
Basic Example
This is a basic example of minimal use of the LVD in an application.
void basic_example (void)
{
assert(FSP_SUCCESS == err);
while (1)
{
assert(FSP_SUCCESS == err);
{
assert(FSP_SUCCESS == err);
}
}
}
Interrupt Example
This is a basic example of using a LVD instance that is configured to generate an interrupt.
void interrupt_example (void)
{
assert(FSP_SUCCESS == err);
while (1)
{
}
}
{
{
}
}
Reset Example
This is a basic example of using a LVD instance that is configured to reset the MCU.
void reset_example (void)
{
if (1U == R_SYSTEM->RSTSR0_b.LVD1RF)
{
R_SYSTEM->RSTSR0_b.LVD1RF = 0;
}
assert(FSP_SUCCESS == err);
while (1)
{
}
}
◆ lvd_instance_ctrl_t
| struct lvd_instance_ctrl_t |
LVD instance control structure
◆ R_LVD_Open()
Initializes a voltage monitor and detector according to the passed-in configuration structure.
- Parameters
-
| [in] | p_api_ctrl | Pointer to the control structure for the driver instance |
| [in] | p_cfg | Pointer to the configuration structure for the driver instance |
- Note
- Digital filter is not to be used with standby modes.
-
Startup time can take on the order of milliseconds for some configurations.
Example:
- Return values
-
| FSP_SUCCESS | Successful |
| FSP_ERR_ASSERTION | Requested configuration was invalid |
| FSP_ERR_ALREADY_OPEN | The instance was already opened |
| FSP_ERR_IN_USE | Another instance is already using the desired monitor |
| FSP_ERR_UNSUPPORTED | Digital filter was enabled on a device that does not support it |
◆ R_LVD_StatusGet()
Get the current state of the monitor (threshold crossing detected, voltage currently above or below threshold).
- Parameters
-
| [in] | p_api_ctrl | Pointer to the control structure for the driver instance |
| [out] | p_lvd_status | Pointer to status structure |
Example:
- Return values
-
| FSP_SUCCESS | Successful |
| FSP_ERR_ASSERTION | An argument was NULL |
| FSP_ERR_NOT_OPEN | Driver is not open |
| FSP_ERR_UNSUPPORTED | This monitor does not support status feature |
◆ R_LVD_StatusClear()
Clears the latched status of the monitor.
- Parameters
-
| [in] | p_api_ctrl | Pointer to the control structure for the driver instance |
- Return values
-
| FSP_SUCCESS | Successful |
| FSP_ERR_ASSERTION | An argument was NULL |
| FSP_ERR_NOT_OPEN | Driver is not open |
| FSP_ERR_UNSUPPORTED | This monitor does not support status feature |
◆ R_LVD_CallbackSet()
Updates the user callback and has option of providing memory for callback structure. Implements lvd_api_t::callbackSet
- Return values
-
| FSP_SUCCESS | Callback updated successfully. |
| FSP_ERR_ASSERTION | A required pointer is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened. |
| FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
◆ R_LVD_Close()
Disables the LVD peripheral. Closes the driver instance.
- Parameters
-
| [in] | p_api_ctrl | Pointer to the control block structure for the driver instance |
- Return values
-
| FSP_SUCCESS | Successful |
| FSP_ERR_ASSERTION | An argument was NULL |
| FSP_ERR_NOT_OPEN | Driver is not open |