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 <script type="text/javascript" src="jquery.js"></script>
11 <script type="text/javascript" src="dynsections.js"></script>
12 <script type="text/javascript" src="tabs.js"></script>
13 <script type="text/javascript" src="footer.js"></script>
14 <script type="text/javascript" src="navtree.js"></script>
15 <link href="navtree.css" rel="stylesheet" type="text/css"/>
16 <script type="text/javascript" src="resize.js"></script>
17 <script type="text/javascript" src="navtreedata.js"></script>
18 <script type="text/javascript" src="navtree.js"></script>
19 <link href="search/search.css" rel="stylesheet" type="text/css"/>
20 <script type="text/javascript" src="search/searchdata.js"></script>
21 <script type="text/javascript" src="search/search.js"></script>
22 <script type="text/javascript">
23 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
24 $(document).ready(function() { init_search(); });
27 <script type="text/javascript" src="darkmode_toggle.js"></script>
28 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
29 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
30 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
31 <link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
32 <link href="version.css" rel="stylesheet" type="text/css"/>
33 <script type="text/javascript" src="../../version.js"></script>
36 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
38 <table cellspacing="0" cellpadding="0">
40 <tr style="height: 55px;">
41 <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
42 <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
43 <div id="projectname">CMSIS-Core (Cortex-A)
44  <span id="projectnumber"><script type="text/javascript">
46 writeHeader.call(this);
47 writeVersionDropdown.call(this, "CMSIS-Core (Cortex-A)");
52 <div id="projectbrief">CMSIS-Core support for Cortex-A processor-based devices</div>
54 <td> <div id="MSearchBox" class="MSearchBoxInactive">
56 <span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
57 <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
58 onfocus="searchBox.OnSearchFieldFocus(true)"
59 onblur="searchBox.OnSearchFieldFocus(false)"
60 onkeyup="searchBox.OnSearchFieldChange(event)"/>
61 </span><span class="right">
62 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
66 <!--END !PROJECT_NAME-->
71 <!-- end header part -->
72 <div id="CMSISnav" class="tabs1">
74 <script type="text/javascript">
75 writeComponentTabs.call(this);
79 <script type="text/javascript">
80 writeSubComponentTabs.call(this);
82 <!-- Generated by Doxygen 1.9.6 -->
83 <script type="text/javascript">
84 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
85 var searchBox = new SearchBox("searchBox", "search/",'.html');
89 <div id="side-nav" class="ui-resizable side-nav-resizable">
91 <div id="nav-tree-contents">
92 <div id="nav-sync" class="sync"></div>
95 <div id="splitbar" style="-moz-user-select:none;"
96 class="ui-resizable-handle">
99 <script type="text/javascript">
100 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
101 $(document).ready(function(){initNavTree('mmu_c_pg.html',''); initResizable(); });
104 <div id="doc-content">
105 <!-- window showing the filter options -->
106 <div id="MSearchSelectWindow"
107 onmouseover="return searchBox.OnSearchSelectShow()"
108 onmouseout="return searchBox.OnSearchSelectHide()"
109 onkeydown="return searchBox.OnSearchSelectKey(event)">
112 <!-- iframe showing the search results (closed by default) -->
113 <div id="MSearchResultsWindow">
114 <div id="MSearchResults">
117 <div id="SRResults"></div>
118 <div class="SRStatus" id="Loading">Loading...</div>
119 <div class="SRStatus" id="Searching">Searching...</div>
120 <div class="SRStatus" id="NoMatches">No Matches</div>
126 <div><div class="header">
127 <div class="headertitle"><div class="title">Memory Management Unit Files mmu_<device>.c </div></div>
129 <div class="contents">
130 <div class="textblock"><pre class="fragment">/**************************************************************************//**
131 * @file system_Device.c
132 * @brief MMU Configuration
133 * Device <DeviceAbbreviation>
135 * @date 23. November 2018
136 ******************************************************************************/
138 * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
140 * SPDX-License-Identifier: Apache-2.0
142 * Licensed under the Apache License, Version 2.0 (the License); you may
143 * not use this file except in compliance with the License.
144 * You may obtain a copy of the License at
146 * www.apache.org/licenses/LICENSE-2.0
148 * Unless required by applicable law or agreed to in writing, software
149 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
150 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151 * See the License for the specific language governing permissions and
152 * limitations under the License.
155 /* Memory map description
157 ToDo: add in this file your device memory map description
158 following is an example of a Cortex-A9 Arm FVP device
161 0xFFFFFFFF |--------------------------| ------------
162 | FLAG SYNC | Device Memory
163 0xFFFFF000 |--------------------------| ------------
165 0xFFF00000 |--------------------------| ------------
171 0x80505000 |--------------------------| ------------
172 |TTB (L2 Sync Flags ) 4k | Normal
173 0x80504C00 |--------------------------| ------------
174 |TTB (L2 Peripherals-B) 16k| Normal
175 0x80504800 |--------------------------| ------------
176 |TTB (L2 Peripherals-A) 16k| Normal
177 0x80504400 |--------------------------| ------------
178 |TTB (L2 Priv Periphs) 4k | Normal
179 0x80504000 |--------------------------| ------------
180 | TTB (L1 Descriptors) | Normal
181 0x80500000 |--------------------------| ------------
183 |--------------------------| ------------
185 0x80400000 |--------------------------| ------------
187 0x80300000 |--------------------------| ------------
189 0x80200000 |--------------------------| ------------
191 |--------------------------| ------------
192 | RO Code | USH Normal
193 0x80000000 |--------------------------| ------------
194 | Daughterboard | Fault
196 0x40000000 |--------------------------| ------------
197 | Daughterboard | Fault
198 | test chips peripherals |
199 0x2C002000 |--------------------------| ------------
200 | Private Address | Device Memory
201 0x2C000000 |--------------------------| ------------
202 | Daughterboard | Fault
203 | test chips peripherals |
204 0x20000000 |--------------------------| ------------
205 | Peripherals | Device Memory RW/RO
207 0x00000000 |--------------------------|
210 // L1 Cache info and restrictions about architecture of the caches (CCSIR register):
211 // Write-Through support *not* available
212 // Write-Back support available.
213 // Read allocation support available.
214 // Write allocation support available.
216 // Note: You should use the Shareable attribute carefully.
217 // 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.
218 // 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.
219 // Some Cortex-A implementations do not include Global Monitors, so wrongly setting the attribute Shareable may cause STREX to fail.
221 // 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.
222 // When SMP bit = 0, Inner WB/WA Cacheable Shareable attributes are treated as Non-cacheable.
223 // When SMP bit = 1, Inner WB/WA Cacheable Shareable attributes are treated as Cacheable.
225 // Following MMU configuration is expected
226 // SCTLR.AFE == 1 (Simplified access permissions model - AP[2:1] define access permissions, AP[0] is an access flag)
227 // SCTLR.TRE == 0 (TEX remap disabled, so memory type and attributes are described directly by bits in the descriptor)
228 // Domain 0 is always the Client domain
229 // Descriptors should place all memory in domain 0
231 #include "<Device>.h" /* ToDo: replace '<Device>' with your device name */
234 //-----------------------------------------------------
235 #define PRIVATE_TABLE_L2_BASE_4k (0x80504000) //Map 4k Private Address space
236 #define SYNC_FLAGS_TABLE_L2_BASE_4k (0x80504C00) //Map 4k Flag synchronization
237 #define PERIPHERAL_A_TABLE_L2_BASE_64k (0x80504400) //Map 64k Peripheral #1
238 #define PERIPHERAL_B_TABLE_L2_BASE_64k (0x80504800) //Map 64k Peripheral #2
240 //--------------------- PERIPHERALS -------------------
241 #define PERIPHERAL_A_FAULT (0x00000000 + 0x1C000000)
242 #define PERIPHERAL_B_FAULT (0x00100000 + 0x1C000000)
244 //--------------------- SYNC FLAGS --------------------
245 #define FLAG_SYNC 0xFFFFF000
246 #define F_SYNC_BASE 0xFFF00000 //1M aligned
248 //Import symbols from linker
249 extern uint32_t Image$$VECTORS$$Base;
250 extern uint32_t Image$$RW_DATA$$Base;
251 extern uint32_t Image$$ZI_DATA$$Base;
252 extern uint32_t Image$$TTB$$ZI$$Base;
254 static uint32_t Sect_Normal; // outer & inner wb/wa, non-shareable, executable, rw, domain 0, base addr 0
255 static uint32_t Sect_Normal_Cod; // outer & inner wb/wa, non-shareable, executable, ro, domain 0, base addr 0
256 static uint32_t Sect_Normal_RO; // as Sect_Normal_Cod, but not executable
257 static uint32_t Sect_Normal_RW; // as Sect_Normal_Cod, but writeable and not executable
258 static uint32_t Sect_Device_RO; // device, non-shareable, non-executable, ro, domain 0, base addr 0
259 static uint32_t Sect_Device_RW; // as Sect_Device_RO, but writeable
261 /* Define global descriptors */
262 static uint32_t Page_L1_4k = 0x0; // generic
263 static uint32_t Page_L1_64k = 0x0; // generic
264 static uint32_t Page_4k_Device_RW; // shared device, not executable, rw, domain 0
265 static uint32_t Page_64k_Device_RW; // shared device, not executable, rw, domain 0
267 void MMU_CreateTranslationTable(void)
269 mmu_region_attributes_Type region;
271 // Create 4GB of faulting entries
272 MMU_TTSection (&Image$$TTB$$ZI$$Base, 0, 4096, DESCRIPTOR_FAULT);
275 * Generate descriptors. Refer to core_ca.h to get information about attributes
278 // Create descriptors for Vectors, RO, RW, ZI sections
279 section_normal(Sect_Normal, region);
280 section_normal_cod(Sect_Normal_Cod, region);
281 section_normal_ro(Sect_Normal_RO, region);
282 section_normal_rw(Sect_Normal_RW, region);
283 // Create descriptors for peripherals
284 section_Device_ro(Sect_Device_RO, region);
285 section_Device_rw(Sect_Device_RW, region);
286 // Create descriptors for 64k pages
287 page64k_Device_rw(Page_L1_64k, Page_64k_Device_RW, region);
288 // Create descriptors for 4k pages
289 page4k_Device_rw(Page_L1_4k, Page_4k_Device_RW, region);
292 * Define MMU flat-map regions and attributes
296 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$VECTORS$$Base , 1U, Sect_Normal_Cod);
297 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RW_DATA$$Base , 1U, Sect_Normal_RW);
298 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$ZI_DATA$$Base , 1U, Sect_Normal_RW);
300 // All DRAM executable, RW, cacheable - applications may choose to divide memory into RO executable
301 MMU_TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$TTB$$ZI$$Base , 2043U, Sect_Normal);
303 //--------------------- PERIPHERALS -------------------
304 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_FLASH_BASE0 , 64U, Sect_Device_RO);
305 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_FLASH_BASE1 , 64U, Sect_Device_RO);
306 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_SRAM_BASE , 64U, Sect_Device_RW);
307 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_VRAM_BASE , 32U, Sect_Device_RW);
308 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_ETHERNET_BASE , 16U, Sect_Device_RW);
309 MMU_TTSection (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_USB_BASE , 16U, Sect_Device_RW);
311 // Create (16 * 64k)=1MB faulting entries to cover peripheral range
312 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, PERIPHERAL_A_FAULT , 16U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, DESCRIPTOR_FAULT);
313 // Define peripheral range
314 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);
315 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);
316 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);
317 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);
318 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);
319 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);
320 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);
321 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);
323 // Create (16 * 64k)=1MB faulting entries to cover peripheral range
324 MMU_TTPage64k(&Image$$TTB$$ZI$$Base, PERIPHERAL_B_FAULT , 16U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, DESCRIPTOR_FAULT);
325 // Define peripheral range
326 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);
327 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);
328 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);
329 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);
330 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);
332 // Create (256 * 4k)=1MB faulting entries to cover private address space. Needs to be marked as Device memory
333 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, __get_CBAR() , 256U, Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, DESCRIPTOR_FAULT);
334 // Define private address space entry
335 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, __get_CBAR() , 2U, Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, Page_4k_Device_RW);
337 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, <DeviceAbbreviation>_L2C_BASE , 1U, Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, Page_4k_Device_RW);
339 // Create (256 * 4k)=1MB faulting entries to synchronization space (Useful if some non-cacheable DMA agent is present in the SoC)
340 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, F_SYNC_BASE , 256U, Page_L1_4k, (uint32_t *)SYNC_FLAGS_TABLE_L2_BASE_4k, DESCRIPTOR_FAULT);
341 // Define synchronization space entry.
342 MMU_TTPage4k (&Image$$TTB$$ZI$$Base, FLAG_SYNC , 1U, Page_L1_4k, (uint32_t *)SYNC_FLAGS_TABLE_L2_BASE_4k, Page_4k_Device_RW);
344 /* Set location of level 1 page table
345 ; 31:14 - Translation table base addr (31:14-TTBCR.N, TTBCR.N is 0 out of reset)
347 ; 6 - IRGN[0] 0x1 (Inner WB WA)
348 ; 5 - NOS 0x0 (Non-shared)
349 ; 4:3 - RGN 0x01 (Outer WB WA)
350 ; 2 - IMP 0x0 (Implementation Defined)
351 ; 1 - S 0x0 (Non-shared)
352 ; 0 - IRGN[1] 0x0 (Inner WB WA) */
353 __set_TTBR0(((uint32_t)&Image$$TTB$$ZI$$Base) | 0x48);
356 /* Set up domain access control register
357 ; We set domain 0 to Client and all other domains to No Access.
358 ; All translation table entries specify domain 0 */
362 </pre> </div></div><!-- contents -->
363 </div><!-- PageDoc -->
364 </div><!-- doc-content -->
365 <!-- start footer part -->
366 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
369 <script type="text/javascript">
371 writeFooter.call(this);