1 <!-- HTML header for doxygen 1.9.6-->
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
5 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6 <meta http-equiv="X-UA-Compatible" content="IE=11"/>
7 <meta name="viewport" content="width=device-width, initial-scale=1"/>
8 <title>CMSIS-Core (Cortex-A): Memory Management Unit Files mmu_<device>.c</title>
9 <link href="doxygen.css" rel="stylesheet" type="text/css"/>
10 <link href="tabs.css" rel="stylesheet" type="text/css"/>
11 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
12 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
13 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
14 <script type="text/javascript" src="jquery.js"></script>
15 <script type="text/javascript" src="dynsections.js"></script>
16 <script type="text/javascript" src="printComponentTabs.js"></script>
17 <script type="text/javascript" src="footer.js"></script>
18 <script type="text/javascript" src="navtree.js"></script>
19 <link href="navtree.css" rel="stylesheet" type="text/css"/>
20 <script type="text/javascript" src="resize.js"></script>
21 <script type="text/javascript" src="navtreedata.js"></script>
22 <script type="text/javascript" src="navtree.js"></script>
23 <link href="search/search.css" rel="stylesheet" type="text/css"/>
24 <script type="text/javascript" src="search/searchdata.js"></script>
25 <script type="text/javascript" src="search/search.js"></script>
26 <script type="text/javascript">
27 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
28 $(document).ready(function() { init_search(); });
31 <script type="text/javascript" src="darkmode_toggle.js"></script>
32 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
33 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
34 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
35 <link href="version.css" rel="stylesheet" type="text/css" />
36 <script type="text/javascript" src="../../../version.js"></script>
39 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
41 <table cellspacing="0" cellpadding="0">
43 <tr style="height: 55px;">
44 <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
45 <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
46 <div id="projectname">CMSIS-Core (Cortex-A)
47  <span id="projectnumber"><script type="text/javascript">
49 writeHeader.call(this);
50 writeVersionDropdown.call(this);
55 <div id="projectbrief">CMSIS-Core support for Cortex-A processor-based devices</div>
57 <td> <div id="MSearchBox" class="MSearchBoxInactive">
59 <span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
60 <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
61 onfocus="searchBox.OnSearchFieldFocus(true)"
62 onblur="searchBox.OnSearchFieldFocus(false)"
63 onkeyup="searchBox.OnSearchFieldChange(event)"/>
64 </span><span class="right">
65 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
69 <!--END !PROJECT_NAME-->
74 <!-- end header part -->
75 <div id="CMSISnav" class="tabs1">
77 <script type="text/javascript">
78 writeComponentTabs.call(this);
82 <script type="text/javascript">
83 writeSubComponentTabs.call(this);
85 <!-- Generated by Doxygen 1.9.6 -->
86 <script type="text/javascript">
87 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
88 var searchBox = new SearchBox("searchBox", "search/",'.html');
92 <div id="side-nav" class="ui-resizable side-nav-resizable">
94 <div id="nav-tree-contents">
95 <div id="nav-sync" class="sync"></div>
98 <div id="splitbar" style="-moz-user-select:none;"
99 class="ui-resizable-handle">
102 <script type="text/javascript">
103 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
104 $(document).ready(function(){initNavTree('mmu_c_pg.html',''); initResizable(); });
107 <div id="doc-content">
108 <!-- window showing the filter options -->
109 <div id="MSearchSelectWindow"
110 onmouseover="return searchBox.OnSearchSelectShow()"
111 onmouseout="return searchBox.OnSearchSelectHide()"
112 onkeydown="return searchBox.OnSearchSelectKey(event)">
115 <!-- iframe showing the search results (closed by default) -->
116 <div id="MSearchResultsWindow">
117 <div id="MSearchResults">
120 <div id="SRResults"></div>
121 <div class="SRStatus" id="Loading">Loading...</div>
122 <div class="SRStatus" id="Searching">Searching...</div>
123 <div class="SRStatus" id="NoMatches">No Matches</div>
129 <div><div class="header">
130 <div class="headertitle"><div class="title">Memory Management Unit Files mmu_<device>.c </div></div>
132 <div class="contents">
133 <div class="textblock"><pre class="fragment">/**************************************************************************//**
134 * @file system_Device.c
135 * @brief MMU Configuration
136 * Device <DeviceAbbreviation>
138 * @date 23. November 2018
139 ******************************************************************************/
141 * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
143 * SPDX-License-Identifier: Apache-2.0
145 * Licensed under the Apache License, Version 2.0 (the License); you may
146 * not use this file except in compliance with the License.
147 * You may obtain a copy of the License at
149 * www.apache.org/licenses/LICENSE-2.0
151 * Unless required by applicable law or agreed to in writing, software
152 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
153 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
154 * See the License for the specific language governing permissions and
155 * limitations under the License.
158 /* Memory map description
160 ToDo: add in this file your device memory map description
161 following is an example of a Cortex-A9 Arm FVP device
164 0xFFFFFFFF |--------------------------| ------------
165 | FLAG SYNC | Device Memory
166 0xFFFFF000 |--------------------------| ------------
168 0xFFF00000 |--------------------------| ------------
174 0x80505000 |--------------------------| ------------
175 |TTB (L2 Sync Flags ) 4k | Normal
176 0x80504C00 |--------------------------| ------------
177 |TTB (L2 Peripherals-B) 16k| Normal
178 0x80504800 |--------------------------| ------------
179 |TTB (L2 Peripherals-A) 16k| Normal
180 0x80504400 |--------------------------| ------------
181 |TTB (L2 Priv Periphs) 4k | Normal
182 0x80504000 |--------------------------| ------------
183 | TTB (L1 Descriptors) | Normal
184 0x80500000 |--------------------------| ------------
186 |--------------------------| ------------
188 0x80400000 |--------------------------| ------------
190 0x80300000 |--------------------------| ------------
192 0x80200000 |--------------------------| ------------
194 |--------------------------| ------------
195 | RO Code | USH Normal
196 0x80000000 |--------------------------| ------------
197 | Daughterboard | Fault
199 0x40000000 |--------------------------| ------------
200 | Daughterboard | Fault
201 | test chips peripherals |
202 0x2C002000 |--------------------------| ------------
203 | Private Address | Device Memory
204 0x2C000000 |--------------------------| ------------
205 | Daughterboard | Fault
206 | test chips peripherals |
207 0x20000000 |--------------------------| ------------
208 | Peripherals | Device Memory RW/RO
210 0x00000000 |--------------------------|
213 // L1 Cache info and restrictions about architecture of the caches (CCSIR register):
214 // Write-Through support *not* available
215 // Write-Back support available.
216 // Read allocation support available.
217 // Write allocation support available.
219 // Note: You should use the Shareable attribute carefully.
220 // For cores without coherency logic (such as SCU) marking a region as shareable forces the processor to not cache that region regardless of the inner cache settings.
221 // Cortex-A versions of RTX use LDREX/STREX instructions relying on Local monitors. Local monitors will be used only when the region gets cached, regions that are not cached will use the Global Monitor.
222 // Some Cortex-A implementations do not include Global Monitors, so wrongly setting the attribute Shareable may cause STREX to fail.
224 // Recall: When the Shareable attribute is applied to a memory region that is not Write-Back, Normal memory, data held in this region is treated as Non-cacheable.
225 // When SMP bit = 0, Inner WB/WA Cacheable Shareable attributes are treated as Non-cacheable.
226 // When SMP bit = 1, Inner WB/WA Cacheable Shareable attributes are treated as Cacheable.
228 // Following MMU configuration is expected
229 // SCTLR.AFE == 1 (Simplified access permissions model - AP[2:1] define access permissions, AP[0] is an access flag)
230 // SCTLR.TRE == 0 (TEX remap disabled, so memory type and attributes are described directly by bits in the descriptor)
231 // Domain 0 is always the Client domain
232 // Descriptors should place all memory in domain 0
234 #include "<Device>.h" /* ToDo: replace '<Device>' with your device name */
237 //-----------------------------------------------------
238 #define PRIVATE_TABLE_L2_BASE_4k (0x80504000) //Map 4k Private Address space
239 #define SYNC_FLAGS_TABLE_L2_BASE_4k (0x80504C00) //Map 4k Flag synchronization
240 #define PERIPHERAL_A_TABLE_L2_BASE_64k (0x80504400) //Map 64k Peripheral #1
241 #define PERIPHERAL_B_TABLE_L2_BASE_64k (0x80504800) //Map 64k Peripheral #2
243 //--------------------- PERIPHERALS -------------------
244 #define PERIPHERAL_A_FAULT (0x00000000 + 0x1C000000)
245 #define PERIPHERAL_B_FAULT (0x00100000 + 0x1C000000)
247 //--------------------- SYNC FLAGS --------------------
248 #define FLAG_SYNC 0xFFFFF000
249 #define F_SYNC_BASE 0xFFF00000 //1M aligned
251 //Import symbols from linker
252 extern uint32_t Image$$VECTORS$$Base;
253 extern uint32_t Image$$RW_DATA$$Base;
254 extern uint32_t Image$$ZI_DATA$$Base;
255 extern uint32_t Image$$TTB$$ZI$$Base;
257 static uint32_t Sect_Normal; // outer & inner wb/wa, non-shareable, executable, rw, domain 0, base addr 0
258 static uint32_t Sect_Normal_Cod; // outer & inner wb/wa, non-shareable, executable, ro, domain 0, base addr 0
259 static uint32_t Sect_Normal_RO; // as Sect_Normal_Cod, but not executable
260 static uint32_t Sect_Normal_RW; // as Sect_Normal_Cod, but writeable and not executable
261 static uint32_t Sect_Device_RO; // device, non-shareable, non-executable, ro, domain 0, base addr 0
262 static uint32_t Sect_Device_RW; // as Sect_Device_RO, but writeable
264 /* Define global descriptors */
265 static uint32_t Page_L1_4k = 0x0; // generic
266 static uint32_t Page_L1_64k = 0x0; // generic
267 static uint32_t Page_4k_Device_RW; // shared device, not executable, rw, domain 0
268 static uint32_t Page_64k_Device_RW; // shared device, not executable, rw, domain 0
270 void MMU_CreateTranslationTable(void)
272 mmu_region_attributes_Type region;
274 // Create 4GB of faulting entries
275 MMU_TTSection (&Image$$TTB$$ZI$$Base, 0, 4096, DESCRIPTOR_FAULT);
278 * Generate descriptors. Refer to core_ca.h to get information about attributes
281 // Create descriptors for Vectors, RO, RW, ZI sections
282 section_normal(Sect_Normal, region);
283 section_normal_cod(Sect_Normal_Cod, region);
284 section_normal_ro(Sect_Normal_RO, region);
285 section_normal_rw(Sect_Normal_RW, region);
286 // Create descriptors for peripherals
287 section_Device_ro(Sect_Device_RO, region);
288 section_Device_rw(Sect_Device_RW, region);
289 // Create descriptors for 64k pages
290 page64k_Device_rw(Page_L1_64k, Page_64k_Device_RW, region);
291 // Create descriptors for 4k pages
292 page4k_Device_rw(Page_L1_4k, Page_4k_Device_RW, region);
295 * Define MMU flat-map regions and attributes
299 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$VECTORS$$Base , 1U, Sect_Normal_Cod);
300 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RW_DATA$$Base , 1U, Sect_Normal_RW);
301 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$ZI_DATA$$Base , 1U, Sect_Normal_RW);
303 // All DRAM executable, RW, cacheable - applications may choose to divide memory into RO executable
304 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$TTB$$ZI$$Base , 2043U, Sect_Normal);
306 //--------------------- PERIPHERALS -------------------
307 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_FLASH_BASE0 , 64U, Sect_Device_RO);
308 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_FLASH_BASE1 , 64U, Sect_Device_RO);
309 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_SRAM_BASE , 64U, Sect_Device_RW);
310 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_VRAM_BASE , 32U, Sect_Device_RW);
311 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_ETHERNET_BASE , 16U, Sect_Device_RW);
312 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_USB_BASE , 16U, Sect_Device_RW);
314 // Create (16 * 64k)=1MB faulting entries to cover peripheral range
315 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, PERIPHERAL_A_FAULT , 16U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, DESCRIPTOR_FAULT);
316 // Define peripheral range
317 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_DAP_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
318 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_SYSTEM_REG_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
319 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_SERIAL_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
320 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_AACI_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
321 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_MMCI_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
322 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_KMI0_BASE , 2U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
323 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_UART_BASE , 4U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
324 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_WDT_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
326 // Create (16 * 64k)=1MB faulting entries to cover peripheral range
327 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, PERIPHERAL_B_FAULT , 16U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, DESCRIPTOR_FAULT);
328 // Define peripheral range
329 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_TIMER_BASE , 2U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
330 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_DVI_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
331 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_RTC_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
332 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_UART4_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
333 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_CLCD_BASE , 1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
335 // Create (256 * 4k)=1MB faulting entries to cover private address space. Needs to be marked as Device memory
336 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, __get_CBAR() , 256U, Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, DESCRIPTOR_FAULT);
337 // Define private address space entry
338 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, __get_CBAR() , 2U, Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, Page_4k_Device_RW);
340 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_L2C_BASE , 1U, Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, Page_4k_Device_RW);
342 // Create (256 * 4k)=1MB faulting entries to synchronization space (Useful if some non-cacheable DMA agent is present in the SoC)
343 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, F_SYNC_BASE , 256U, Page_L1_4k, (uint32_t *)SYNC_FLAGS_TABLE_L2_BASE_4k, DESCRIPTOR_FAULT);
344 // Define synchronization space entry.
345 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, FLAG_SYNC , 1U, Page_L1_4k, (uint32_t *)SYNC_FLAGS_TABLE_L2_BASE_4k, Page_4k_Device_RW);
347 /* Set location of level 1 page table
348 ; 31:14 - Translation table base addr (31:14-TTBCR.N, TTBCR.N is 0 out of reset)
350 ; 6 - IRGN[0] 0x1 (Inner WB WA)
351 ; 5 - NOS 0x0 (Non-shared)
352 ; 4:3 - RGN 0x01 (Outer WB WA)
353 ; 2 - IMP 0x0 (Implementation Defined)
354 ; 1 - S 0x0 (Non-shared)
355 ; 0 - IRGN[1] 0x0 (Inner WB WA) */
356 __set_TTBR0(((uint32_t)&Image$$TTB$$ZI$$Base) | 0x48);
359 /* Set up domain access control register
360 ; We set domain 0 to Client and all other domains to No Access.
361 ; All translation table entries specify domain 0 */
365 </pre> </div></div><!-- contents -->
366 </div><!-- PageDoc -->
367 </div><!-- doc-content -->
368 <!-- start footer part -->
369 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
372 <script type="text/javascript">
374 writeFooter.call(this);