libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
memctl.h
Go to the documentation of this file.
1/**
2 * @brief Memory Controller definitions for the Qorvo PAC55xx series of microcontrollers
3 *
4 * @addtogroup PAC55xx_memctl Memory Controller Defines
5 * @ingroup PAC55xx_defines
6 * @author Kevin Stefanik <kevin@allocor.tech>
7 * LGPL License Terms @ref lgpl_license
8 * @date 17 Mar 2020
9 *
10 * Definitions in this file come from the PAC55XX Family User Guide Rev 1.23
11 * by Active-Semi dated November 19, 2019.
12 */
13/*
14 * This file is part of the libopencm3 project.
15 *
16 * Copyright (C) 2020 Kevin Stefanik <kevin@allocor.tech>
17 *
18 * This library is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Lesser General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with this library. If not, see <http://www.gnu.org/licenses/>.
30 */
31#ifndef LIBOPENCM3_PAC55XX_MEMCTL_H_
32#define LIBOPENCM3_PAC55XX_MEMCTL_H_
33
36/**@{*/
37
38/** @defgroup memctl_reg Memory Controller Configuration Register
39@{*/
40/** Memory Controller Configuration Register */
41#define MEMCTL_MEMCTLR MMIO32(MEMCTL_BASE)
42#define MEMCTL_MEMCTLR_WSTATE_MASK (0xF)
43#define MEMCTL_MEMCTLR_WSTATE(ws) ((ws) & MEMCTL_MEMCTLR_WSTATE_MASK)
44#define MEMCTL_MEMCTLR_MCLKDIV_MASK (0xF)
45#define MEMCTL_MEMCTLR_MCLKDIV_SHIFT 4
46/* Supported MCLK divisors: 1-16 */
47#define MEMCTL_MEMCTLR_MCLKDIV(div) (((div-1) & MEMCTL_MEMCTLR_MCLKDIV_MASK) << MEMCTL_MEMCTLR_MCLKDIV_SHIFT)
48#define MEMCTL_MEMCTLR_WRITEWORDCNT_MASK (0x3)
49#define MEMCTL_MEMCTLR_WRITEWORDCNT_SHIFT 8
50#define MEMCTL_MEMCTLR_WRITEWORDCNT(cnt) (((cnt) & MEMCTL_MEMCTLR_WRITEWORDCNT_MASK) << MEMCTL_MEMCTLR_WRITEWORDCNT_SHIFT)
51#define MEMCTL_MEMCTLR_SEIE BIT16
52#define MEMCTL_MEMCTLR_DEIE BIT17
53#define MEMCTL_MEMCTLR_INVADDRIE BIT18
54#define MEMCTL_MEMCTLR_STBY BIT19
55#define MEMCTL_MEMCTLR_ECCDIS BIT20
56#define MEMCTL_MEMCTLR_CACHEDIS BIT21
57#define MEMCTL_MEMCTLR_MCLKSEL BIT22
58/**@}*/
59
60/** @defgroup memstatus_reg Memory Controller Status Register
61@{*/
62/** Memory Controller Status Register */
63#define MEMCTL_MEMSTATUS MMIO32(MEMCTL_BASE + 0x0004)
64#define MEMCTL_MEMSTATUS_WBUSY BIT0
65#define MEMCTL_MEMSTATUS_EBUSY BIT1
66#define MEMCTL_MEMSTATUS_WRITEWORDCNT_MASK (0x3)
67#define MEMCTL_MEMSTATUS_WRITEWORDCNT_SHIFT 8
68#define MEMCTL_MEMSTATUS_WRITEWORDCNT ((MEMCTL_MEMSTATUS >> MEMCTL_MEMSTATUS_WRITEWORDCNT_SHIFT) & MEMCTL_MEMSTATUS_WRITEWORDCNT_MASK)
69#define MEMCTL_MEMSTATUS_WRITEWORDCNT_4BYTES (0)
70#define MEMCTL_MEMSTATUS_WRITEWORDCNT_8BYTES (1)
71#define MEMCTL_MEMSTATUS_WRITEWORDCNT_12BYTES (2)
72#define MEMCTL_MEMSTATUS_WRITEWORDCNT_16BYTES (3)
73#define MEMCTL_MEMSTATUS_SE BIT16
74#define MEMCTL_MEMSTATUS_DE BIT17
75#define MEMCTL_MEMSTATUS_INVADDR BIT18
76/**@}*/
77
78/** @defgroup flashlock_vals Flash Lock/Write Enable Register values
79@{*/
80/** Flash Lock Access Register */
81#define MEMCTL_FLASHLOCK MMIO32(MEMCTL_BASE + 0x0008)
82#define MEMCTL_FLASHLOCK_CLEAR (0)
83#define MEMCTL_FLASHLOCK_ALLOW_FLASH_WRITE (0x43DF140A)
84#define MEMCTL_FLASHLOCK_ALLOW_MEMCTL_WRITE (0xD513B490)
85#define MEMCTL_FLASHLOCK_ALLOW_INFO2_SWDFUSE (0x79B4F762)
86/**@}*/
87
88/** Flash Page Address Register */
89#define MEMCTL_FLASHPAGE MMIO32(MEMCTL_BASE + 0x000C)
90/** SWD Unlock Register */
91#define MEMCTL_SWDUNLOCK MMIO32(MEMCTL_BASE + 0x0010)
92
93/** @defgroup flasherase_vals Flash Erase Enable Register values
94@{*/
95/** Flash Erase Enable Register */
96#define MEMCTL_FLASHERASE MMIO32(MEMCTL_BASE + 0x0020)
97#define MEMCTL_FLASHERASE_PAGE_ERASE (0x8C799CA7)
98#define MEMCTL_FLASHERASE_MASS_PAGE_ERASE (0x09EE76C9)
99#define MEMCTL_FLASHERASE_INFO3_ERASE (0x1266FF45)
100/**@}*/
101
102/**@}*/
103
105
106/**
107 * @defgroup memctl_api Memory Controller API
108 * @ingroup peripheral_apis
109 * @brief <b>PAC5xx MEMCTL Driver</b>
110 * @author @htmlonly &copy; @endhtmlonly 2020 Kevin Stefanik <kevin@allocor.tech>
111 * @date March 7, 2020
112 *
113 * This library supports the MEMCTL module in the PAC55xx SoC from Qorvo.
114 *
115 * LGPL License Terms @ref lgpl_license
116 */
117
118/*@{*/
119
120/** Set the number of wait states for Flash reads.
121 * @param[in] wstate Wait states: 0-15
122 */
123void memctl_flash_set_wstate(uint32_t wstate);
124/** Set the MCLK divisor.
125 * @param[in] div HCLK to MCLK divisor: 1-16
126 */
127void memctl_flash_set_mclkdiv(uint32_t div);
128/** Set WRITEWORDCOUNT to 0 to reset the Flash write data buffer */
130/** Enable Flash Standby Mode */
132/** Disable Flash Standby Mode */
134/** Enable Flash cache */
136/** Disable Flash cache */
138/** Select ROSCCLK as input to Flash Memory Controller */
140/** Select MCLK as input to Flash Memory Controller */
141void memctl_flash_select_mclk(void);
142/** Enable SRAM ECC */
143void memctl_sram_ecc_enable(void);
144/** Disable SRAM ECC */
145void memctl_sram_ecc_disable(void);
146/** Enable SRAM ECC Single Bit Detection Interrupt */
148/** Disable SRAM ECC Single Bit Detection Interrupt */
150/** Enable SRAM ECC Dual Bit Detection Interrupt */
152/** Disable SRAM ECC Dual Bit Detection Interrupt */
154/** Enable Invalid Memory Access Interrupt */
156/** Disable Invalid Memory Access Interrupt */
158
159/**@}*/
160
162
163#endif /* LIBOPENCM3_PAC55XX_MEMCTL_H_ */
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void memctl_sram_ecc_disable(void)
Disable SRAM ECC.
Definition: memctl.c:58
void memctl_flash_select_mclk(void)
Select MCLK as input to Flash Memory Controller.
Definition: memctl.c:52
void memctl_flash_reset_write_buffer(void)
Set WRITEWORDCOUNT to 0 to reset the Flash write data buffer.
Definition: memctl.c:34
void memctl_flash_standby_mode_disable(void)
Disable Flash Standby Mode.
Definition: memctl.c:40
void memctl_invaddr_interrupt_disable(void)
Disable Invalid Memory Access Interrupt.
Definition: memctl.c:76
void memctl_flash_select_roscclk(void)
Select ROSCCLK as input to Flash Memory Controller.
Definition: memctl.c:49
void memctl_flash_cache_enable(void)
Enable Flash cache.
Definition: memctl.c:43
void memctl_sram_ecc_dual_bit_interrupt_enable(void)
Enable SRAM ECC Dual Bit Detection Interrupt.
Definition: memctl.c:67
void memctl_sram_ecc_dual_bit_interrupt_disable(void)
Disable SRAM ECC Dual Bit Detection Interrupt.
Definition: memctl.c:70
void memctl_flash_standby_mode_enable(void)
Enable Flash Standby Mode.
Definition: memctl.c:37
void memctl_sram_ecc_single_bit_interrupt_disable(void)
Disable SRAM ECC Single Bit Detection Interrupt.
Definition: memctl.c:64
void memctl_sram_ecc_enable(void)
Enable SRAM ECC.
Definition: memctl.c:55
void memctl_invaddr_interrupt_enable(void)
Enable Invalid Memory Access Interrupt.
Definition: memctl.c:73
void memctl_flash_set_wstate(uint32_t wstate)
Set the number of wait states for Flash reads.
Definition: memctl.c:28
void memctl_flash_set_mclkdiv(uint32_t div)
Set the MCLK divisor.
Definition: memctl.c:31
void memctl_sram_ecc_single_bit_interrupt_enable(void)
Enable SRAM ECC Single Bit Detection Interrupt.
Definition: memctl.c:61
void memctl_flash_cache_disable(void)
Disable Flash cache.
Definition: memctl.c:46