libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
pwr.c
Go to the documentation of this file.
1/** @defgroup pwr_file PWR peripheral API
2 *
3 * @ingroup peripheral_apis
4 *
5 * @brief <b>libopencm3 STM32G4xx Power Control</b>
6 *
7 * @version 1.0.0
8 *
9 * @author @htmlonly &copy; @endhtmlonly 2016 Benjamin Levine <benjamin@jesco.karoo.co.uk>
10 * @author @htmlonly &copy; @endhtmlonly 2019 Guillaume Revaillot <g.revaillot@gmail.com>
11 * @author @htmlonly &copy; @endhtmlonly 2020 Ben Brewer <ben.brewer@codethink.co.uk>
12 *
13 * @date 29 July 2020
14 *
15 * This library supports the power control system for the
16 * STM32G4 series of ARM Cortex Microcontrollers by ST Microelectronics.
17 *
18 * LGPL License Terms @ref lgpl_license
19 */
20/*
21 * This file is part of the libopencm3 project.
22 *
23 * Copyright (C) 2016 Benjamin Levine <benjamin@jesco.karoo.co.uk>
24 * Copyright (C) 2019 Guillaume Revaillot <g.revaillot@gmail.com>
25 * Copyright (C) 2020 Ben Brewer <ben.brewer@codethink.co.uk>
26 *
27 * This library is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU Lesser General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
31 *
32 * This library is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU Lesser General Public License for more details.
36 *
37 * You should have received a copy of the GNU Lesser General Public License
38 * along with this library. If not, see <http://www.gnu.org/licenses/>.
39 */
40/**@{*/
42
44{
45 uint32_t reg32;
46
48 reg32 |= (scale & PWR_CR1_VOS_MASK) << PWR_CR1_VOS_SHIFT;
49 PWR_CR1 = reg32;
50}
51
52/** Disable Backup Domain Write Protection
53 *
54 * This allows backup domain registers to be changed. These registers are write
55 * protected after a reset.
56 */
58{
60}
61
62/** Re-enable Backup Domain Write Protection
63 *
64 * This protects backup domain registers from inadvertent change.
65 */
67{
68 PWR_CR1 &= ~PWR_CR1_DBP;
69}
70
71/*---------------------------------------------------------------------------*/
72/** @brief Select the low power mode used in deep sleep.
73 * @param lpms low power mode @ref pwr_cr1_lpms
74 */
76{
77 uint32_t reg32;
78
79 reg32 = PWR_CR1;
81 PWR_CR1 = (reg32 | (lpms << PWR_CR1_LPMS_SHIFT));
82}
83
84/*---------------------------------------------------------------------------*/
85/** @brief Enable Power Voltage Detector.
86 * @param[in] pvd_level Power Voltage Detector Falling Threshold voltage @ref pwr_pls.
87*/
88void pwr_enable_power_voltage_detect(uint32_t pvd_level)
89{
90 uint32_t reg32;
91
92 reg32 = PWR_CR2;
94 PWR_CR2 = (reg32 | (pvd_level << PWR_CR2_PLS_SHIFT) | PWR_CR2_PVDE);
95}
96
97/*---------------------------------------------------------------------------*/
98/** @brief Disable Power Voltage Detector.
99*/
101{
102 PWR_CR2 &= ~PWR_CR2_PVDE;
103}
104
105/*---------------------------------------------------------------------------*/
106/** @brief Enable Boost Mode.
107*/
109{
110 PWR_CR5 &= ~PWR_CR5_R1MODE;
111}
112
113/*---------------------------------------------------------------------------*/
114/** @brief Disable Boost Mode.
115*/
117{
119}
120
121/**@}*/
#define PWR_CR5_R1MODE
Definition: g4/pwr.h:141
#define PWR_CR1_DBP
Definition: g4/pwr.h:80
#define PWR_CR1_VOS_MASK
Definition: g4/pwr.h:76
#define PWR_CR1_LPMS_SHIFT
Definition: g4/pwr.h:82
#define PWR_CR2_PLS_SHIFT
Definition: g4/pwr.h:95
#define PWR_CR1_VOS_SHIFT
Definition: g4/pwr.h:75
#define PWR_CR2_PLS_MASK
Definition: g4/pwr.h:96
pwr_vos_scale
Definition: g4/pwr.h:173
#define PWR_CR5
Definition: g4/pwr.h:55
#define PWR_CR2_PVDE
Definition: g4/pwr.h:110
#define PWR_CR1_LPMS_MASK
Definition: g4/pwr.h:83
#define PWR_CR1
Definition: g4/pwr.h:51
#define PWR_CR2
Definition: g4/pwr.h:52
void pwr_set_low_power_mode_selection(uint32_t lpms)
Select the low power mode used in deep sleep.
Definition: pwr.c:75
void pwr_enable_backup_domain_write_protect(void)
Re-enable Backup Domain Write Protection.
Definition: pwr.c:66
void pwr_disable_power_voltage_detect(void)
Disable Power Voltage Detector.
Definition: pwr.c:100
void pwr_disable_backup_domain_write_protect(void)
Disable Backup Domain Write Protection.
Definition: pwr.c:57
void pwr_enable_boost(void)
Enable Boost Mode.
Definition: pwr.c:108
void pwr_set_vos_scale(enum pwr_vos_scale scale)
Definition: pwr.c:43
void pwr_disable_boost(void)
Disable Boost Mode.
Definition: pwr.c:116
void pwr_enable_power_voltage_detect(uint32_t pvd_level)
Enable Power Voltage Detector.
Definition: pwr.c:88