libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
g4/pwr.h
Go to the documentation of this file.
1/** @defgroup pwr_defines PWR Defines
2 *
3 * @ingroup STM32G4xx_defines
4 *
5 * @brief <b>Defined Constants and Types for the 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 * LGPL License Terms @ref lgpl_license
16 * */
17
18/*
19 * This file is part of the libopencm3 project.
20 *
21 * Copyright (C) 2016 Benjamin Levine <benjamin@jesco.karoo.co.uk>
22 * Copyright (C) 2019 Guillaume Revaillot <g.revaillot@gmail.com>
23 * Copyright (C) 2020 Ben Brewer <ben.brewer@codethink.co.uk>
24 *
25 * This library is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU Lesser General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
29 *
30 * This library is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * along with this library. If not, see <http://www.gnu.org/licenses/>.
37 */
38
39/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA PWR.H
40The order of header inclusion is important. pwr.h includes the device
41specific memorymap.h header before including this header file.*/
42
43/**@{*/
44#ifndef LIBOPENCM3_PWR_H
45#define LIBOPENCM3_PWR_H
46
47
48
49/* --- PWR registers ------------------------------------------------------- */
50
51#define PWR_CR1 MMIO32(POWER_CONTROL_BASE + 0x00)
52#define PWR_CR2 MMIO32(POWER_CONTROL_BASE + 0x04)
53#define PWR_CR3 MMIO32(POWER_CONTROL_BASE + 0x08)
54#define PWR_CR4 MMIO32(POWER_CONTROL_BASE + 0x0C)
55#define PWR_CR5 MMIO32(POWER_CONTROL_BASE + 0x80)
56#define PWR_SR1 MMIO32(POWER_CONTROL_BASE + 0x10)
57#define PWR_SR2 MMIO32(POWER_CONTROL_BASE + 0x14)
58#define PWR_SCR MMIO32(POWER_CONTROL_BASE + 0x18)
59
60#define PWR_PORT_A MMIO32(POWER_CONTROL_BASE + 0x20)
61#define PWR_PORT_B MMIO32(POWER_CONTROL_BASE + 0x28)
62#define PWR_PORT_C MMIO32(POWER_CONTROL_BASE + 0x30)
63#define PWR_PORT_D MMIO32(POWER_CONTROL_BASE + 0x38)
64#define PWR_PORT_E MMIO32(POWER_CONTROL_BASE + 0x40)
65#define PWR_PORT_F MMIO32(POWER_CONTROL_BASE + 0x48)
66#define PWR_PORT_G MMIO32(POWER_CONTROL_BASE + 0x50)
67
68#define PWR_PUCR(pwr_port) MMIO32((pwr_port) + 0x00)
69#define PWR_PDCR(pwr_port) MMIO32((pwr_port) + 0x04)
70
71/* --- PWR_CR1 values ------------------------------------------------------- */
72
73#define PWR_CR1_LPR (1 << 14)
74
75#define PWR_CR1_VOS_SHIFT 9
76#define PWR_CR1_VOS_MASK 0x3
77#define PWR_CR1_VOS_RANGE_1 1
78#define PWR_CR1_VOS_RANGE_2 2
79
80#define PWR_CR1_DBP (1 << 8)
81
82#define PWR_CR1_LPMS_SHIFT 0
83#define PWR_CR1_LPMS_MASK 0x07
84#define PWR_CR1_LPMS_STOP_0 0
85#define PWR_CR1_LPMS_STOP_1 1
86#define PWR_CR1_LPMS_STOP_2 2
87#define PWR_CR1_LPMS_STANDBY 3
88#define PWR_CR1_LPMS_SHUTDOWN 4
89
90/* --- PWR_CR2 values ------------------------------------------------------- */
91
92#define PWR_CR2_PVMEN2 (1 << 7)
93#define PWR_CR2_PVMEN1 (1 << 6)
94
95#define PWR_CR2_PLS_SHIFT 1
96#define PWR_CR2_PLS_MASK 0x07
97/** @defgroup pwr_pls PVD level selection
98@ingroup STM32G4_pwr_defines
99@{*/
100#define PWR_CR2_PLS_2V0 0x00
101#define PWR_CR2_PLS_2V2 0x01
102#define PWR_CR2_PLS_2V4 0x02
103#define PWR_CR2_PLS_2V5 0x03
104#define PWR_CR2_PLS_2V6 0x04
105#define PWR_CR2_PLS_2V8 0x05
106#define PWR_CR2_PLS_2V9 0x06
107#define PWR_CR2_PLS_PVD_IN 0x07
108/**@}*/
109
110#define PWR_CR2_PVDE (1 << 0)
111
112/* --- PWR_CR3 values ------------------------------------------------------- */
113
114#define PWR_CR3_EIWUL (1 << 15)
115#define PWR_CR3_UCPD1_DBDIS (1 << 14)
116#define PWR_CR3_UCPD1_STDBY (1 << 13)
117#define PWR_CR3_APC (1 << 10)
118#define PWR_CR3_RRS (1 << 8)
119#define PWR_CR3_EWUP5 (1 << 4)
120#define PWR_CR3_EWUP4 (1 << 3)
121#define PWR_CR3_EWUP3 (1 << 2)
122#define PWR_CR3_EWUP2 (1 << 1)
123#define PWR_CR3_EWUP1 (1 << 0)
124
125/* --- PWR_CR4 values ------------------------------------------------------- */
126
127#define PWR_CR4_VBRS (1 << 9)
128#define PWR_CR4_VBE (1 << 8)
129#define PWR_CR4_WP5 (1 << 4)
130#define PWR_CR4_WP4 (1 << 3)
131#define PWR_CR4_WP3 (1 << 2)
132#define PWR_CR4_WP2 (1 << 1)
133#define PWR_CR4_WP1 (1 << 0)
134
135/* --- PWR_CR4 values ------------------------------------------------------- */
136
137#define PWR_CR5_R1MODE_SHIFT 8
138#define PWR_CR5_R1MODE_MASK 0x1
139#define PWR_CR5_R1MODE_BOOST 0
140#define PWR_CR5_R1MODE_NORMAL 1
141#define PWR_CR5_R1MODE (PWR_CR5_R1MODE_MASK << PWR_CR5_R1MODE_SHIFT)
142
143/* --- PWR_SR1 values ------------------------------------------------------- */
144
145#define PWR_SR1_WUFI (1 << 15)
146#define PWR_SR1_SBF (1 << 8)
147#define PWR_SR1_WUF5 (1 << 4)
148#define PWR_SR1_WUF4 (1 << 3)
149#define PWR_SR1_WUF3 (1 << 2)
150#define PWR_SR1_WUF2 (1 << 1)
151#define PWR_SR1_WUF1 (1 << 0)
152
153/* --- PWR_SR2 values ------------------------------------------------------- */
154
155#define PWR_SR2_PVMO2 (1 << 15)
156#define PWR_SR2_PVMO1 (1 << 14)
157#define PWR_SR2_PVDO (1 << 11)
158#define PWR_SR2_VOSF (1 << 10)
159#define PWR_SR2_REGLPF (1 << 9)
160#define PWR_SR2_REGLPS (1 << 8)
161
162/* --- PWR_SCR values ------------------------------------------------------- */
163
164#define PWR_SCR_CSBF (1 << 8)
165#define PWR_SCR_CWUF5 (1 << 4)
166#define PWR_SCR_CWUF4 (1 << 3)
167#define PWR_SCR_CWUF3 (1 << 2)
168#define PWR_SCR_CWUF2 (1 << 1)
169#define PWR_SCR_CWUF1 (1 << 0)
170
171/* --- PWR function prototypes ------------------------------------------- */
172
176};
177
179
180void pwr_set_vos_scale(enum pwr_vos_scale scale);
181
184
185void pwr_set_low_power_mode_selection(uint32_t lpms);
186
187void pwr_enable_power_voltage_detect(uint32_t pvd_level);
189
190void pwr_enable_boost(void);
191void pwr_disable_boost(void);
192
194
195#endif
196/**@}*/
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
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
#define PWR_CR1_VOS_RANGE_2
Definition: g4/pwr.h:78
pwr_vos_scale
Definition: g4/pwr.h:173
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
#define PWR_CR1_VOS_RANGE_1
Definition: g4/pwr.h:77
@ PWR_SCALE1
Definition: g4/pwr.h:174
@ PWR_SCALE2
Definition: g4/pwr.h:175