libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
g0/pwr.h
Go to the documentation of this file.
1/** @defgroup pwr_defines PWR Defines
2 *
3 * @brief <b>Defined Constants and Types for the STM32G0xx PWR Control</b>
4 *
5 * @ingroup STM32G0xx_defines
6 *
7 * @version 1.0.0
8 *
9 * LGPL License Terms @ref lgpl_license
10 */
11/*
12 * This file is part of the libopencm3 project.
13 *
14 * This library is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this library. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#ifndef LIBOPENCM3_PWR_H
29#define LIBOPENCM3_PWR_H
30/**@{*/
31
32/** @defgroup pwr_registers PWR Registers
33@{*/
34/** Power control register 1 (PWR_CR1) */
35#define PWR_CR1 MMIO32(POWER_CONTROL_BASE + 0x00)
36
37/** Power control register 2 (PWR_CR2) */
38#define PWR_CR2 MMIO32(POWER_CONTROL_BASE + 0x04)
39
40/** Power control register 3 (PWR_CR3) */
41#define PWR_CR3 MMIO32(POWER_CONTROL_BASE + 0x08)
42
43/** Power control register 4 (PWR_CR4) */
44#define PWR_CR4 MMIO32(POWER_CONTROL_BASE + 0x0c)
45
46/** Power status register 1 (PWR_SR1) */
47#define PWR_SR1 MMIO32(POWER_CONTROL_BASE + 0x10)
48
49/** Power status registery 2 (PWR_SR2) */
50#define PWR_SR2 MMIO32(POWER_CONTROL_BASE + 0x14)
51
52/** Power status clear register (PWR_SCR) */
53#define PWR_SCR MMIO32(POWER_CONTROL_BASE + 0x18)
54
55#define PWR_PORT_A MMIO32(POWER_CONTROL_BASE + 0x20)
56#define PWR_PORT_B MMIO32(POWER_CONTROL_BASE + 0x28)
57#define PWR_PORT_C MMIO32(POWER_CONTROL_BASE + 0x30)
58#define PWR_PORT_D MMIO32(POWER_CONTROL_BASE + 0x38)
59#define PWR_PORT_E MMIO32(POWER_CONTROL_BASE + 0x40)
60#define PWR_PORT_F MMIO32(POWER_CONTROL_BASE + 0x48)
61
62#define PWR_PUCR(pwr_port) MMIO32((pwr_port) + 0x00)
63#define PWR_PDCR(pwr_port) MMIO32((pwr_port) + 0x04)
64/**@}*/
65
66/* --- PWR_CR1 values ------------------------------------------------------- */
67
68#define PWR_CR1_LPR (1 << 14)
69
70#define PWR_CR1_VOS_SHIFT 9
71#define PWR_CR1_VOS_MASK 0x3
72/** @defgroup pwr_cr1_vos VOS
73 * @brief Voltage scaling range selection.
74@{*/
75#define PWR_CR1_VOS_RANGE_1 1
76#define PWR_CR1_VOS_RANGE_2 2
77/**@}*/
78
79#define PWR_CR1_DBP (1 << 8)
80
81#define PWR_CR1_FPD_LPSLP (1 << 5)
82#define PWR_CR1_FPD_LPRUN (1 << 4)
83#define PWR_CR1_FPD_STOP (1 << 3)
84
85#define PWR_CR1_LPMS_SHIFT 0
86#define PWR_CR1_LPMS_MASK 0x07
87/** @defgroup pwr_cr1_lpms LPMS
88 * @ingroup STM32G0xx_pwr_defines
89 * @brief Low-power mode selection
90@{*/
91#define PWR_CR1_LPMS_STOP_0 0
92#define PWR_CR1_LPMS_STOP_1 1
93#define PWR_CR1_LPMS_STANDBY 3
94#define PWR_CR1_LPMS_SHUTDOWN 4
95/**@}*/
96
97/* --- PWR_CR2 values ------------------------------------------------------- */
98
99#define PWR_CR2_PVDRT_SHIFT 4
100#define PWR_CR2_PVDRT_MASK 0x07
101/** @defgroup pwr_cr2_pvdrt PVDRT
102 * @brief Power voltage detector rising threshold selection
103@{*/
104#define PWR_CR2_PVDRT_2V1 0x00
105#define PWR_CR2_PVDRT_2V2 0x01
106#define PWR_CR2_PVDRT_2V5 0x02
107#define PWR_CR2_PVDRT_2V6 0x03
108#define PWR_CR2_PVDRT_2V7 0x04
109#define PWR_CR2_PVDRT_2V9 0x05
110#define PWR_CR2_PVDRT_3V0 0x06
111#define PWR_CR2_PVDRT_PVD_IN 0x07
112/**@}*/
113
114#define PWR_CR2_PVDFT_SHIFT 1
115#define PWR_CR2_PVDFT_MASK 0x07
116/** @defgroup pwr_cr2_pvdft PVDFT
117 * @brief Power voltage detector falling threshold selection
118@{*/
119#define PWR_CR2_PVDFT_2V0 0x00
120#define PWR_CR2_PVDFT_2V2 0x01
121#define PWR_CR2_PVDFT_2V4 0x02
122#define PWR_CR2_PVDFT_2V5 0x03
123#define PWR_CR2_PVDFT_2V6 0x04
124#define PWR_CR2_PVDFT_2V8 0x05
125#define PWR_CR2_PVDFT_2V9 0x06
126/**@}*/
127
128#define PWR_CR2_PVDE (1 << 0)
129
130/* --- PWR_CR3 values ------------------------------------------------------- */
131
132#define PWR_CR3_EIWUL (1 << 15)
133#define PWR_CR3_APC (1 << 10)
134#define PWR_CR3_ULPEN (1 << 9)
135#define PWR_CR3_RRS (1 << 8)
136#define PWR_CR3_EWUP6 (1 << 5)
137#define PWR_CR3_EWUP5 (1 << 4)
138#define PWR_CR3_EWUP4 (1 << 3)
139#define PWR_CR3_EWUP2 (1 << 1)
140#define PWR_CR3_EWUP1 (1 << 0)
141
142/* --- PWR_CR4 values ------------------------------------------------------- */
143
144#define PWR_CR4_VBRS (1 << 9)
145#define PWR_CR4_VBE (1 << 8)
146#define PWR_CR4_WP6 (1 << 5)
147#define PWR_CR4_WP5 (1 << 4)
148#define PWR_CR4_WP4 (1 << 3)
149#define PWR_CR4_WP2 (1 << 1)
150#define PWR_CR4_WP1 (1 << 0)
151
152/* --- PWR_SR1 values ------------------------------------------------------- */
153
154#define PWR_SR1_WUFI (1 << 15)
155#define PWR_SR1_SBF (1 << 8)
156#define PWR_SR1_WUF6 (1 << 5)
157#define PWR_SR1_WUF5 (1 << 4)
158#define PWR_SR1_WUF4 (1 << 3)
159#define PWR_SR1_WUF2 (1 << 1)
160#define PWR_SR1_WUF1 (1 << 0)
161
162/* --- PWR_SR2 values ------------------------------------------------------- */
163
164#define PWR_SR2_PVDO (1 << 11)
165#define PWR_SR2_VOSF (1 << 10)
166#define PWR_SR2_REGLPF (1 << 9)
167#define PWR_SR2_REGLPS (1 << 8)
168#define PWR_SR2_FLASHRDY (1 << 8)
169
170/* --- PWR_SCR values ------------------------------------------------------- */
171
172#define PWR_SCR_CSBF (1 << 8)
173#define PWR_SCR_CWUF6 (1 << 5)
174#define PWR_SCR_CWUF5 (1 << 4)
175#define PWR_SCR_CWUF4 (1 << 3)
176#define PWR_SCR_CWUF2 (1 << 1)
177#define PWR_SCR_CWUF1 (1 << 0)
178
179/* --- Function prototypes ------------------------------------------------- */
180
184};
185
187
188void pwr_set_vos_scale(enum pwr_vos_scale scale);
189
192
193void pwr_set_low_power_mode_selection(uint32_t lpms);
194
195void pwr_enable_power_voltage_detect(uint32_t pvdr_level, uint32_t pvdf_level);
197
199
200/**@}*/
201#endif
202
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
#define PWR_CR1_VOS_RANGE_2
Definition: g0/pwr.h:76
#define PWR_CR1_VOS_RANGE_1
Definition: g0/pwr.h:75
void pwr_set_low_power_mode_selection(uint32_t lpms)
Select the low power mode used in deep sleep.
Definition: pwr.c:66
void pwr_enable_backup_domain_write_protect(void)
Enable RTC domain write protect.
Definition: pwr.c:57
void pwr_disable_power_voltage_detect(void)
Disable Power Voltage Detector.
Definition: pwr.c:93
void pwr_enable_power_voltage_detect(uint32_t pvdr_level, uint32_t pvdf_level)
Enable Power Voltage Detector.
Definition: pwr.c:80
void pwr_disable_backup_domain_write_protect(void)
Disable RTC domain write protect.
Definition: pwr.c:49
void pwr_set_vos_scale(enum pwr_vos_scale scale)
Setup voltage scaling range.
Definition: pwr.c:37
pwr_vos_scale
Definition: g0/pwr.h:181
@ PWR_SCALE1
Definition: g0/pwr.h:182
@ PWR_SCALE2
Definition: g0/pwr.h:183