aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mn/project_template/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mn/project_template/board.c')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mn/project_template/board.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mn/project_template/board.c b/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mn/project_template/board.c
new file mode 100644
index 000000000..e1be73e67
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mn/project_template/board.c
@@ -0,0 +1,157 @@
1/*
2 * Copyright 2018 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include "fsl_common.h"
9#include "fsl_debug_console.h"
10#include "fsl_rdc.h"
11#include "fsl_iomuxc.h"
12#include "pin_mux.h"
13#include "board.h"
14#include "fsl_clock.h"
15
16/*******************************************************************************
17 * Variables
18 ******************************************************************************/
19
20/*******************************************************************************
21 * Code
22 ******************************************************************************/
23/* Initialize debug console. */
24void BOARD_InitDebugConsole(void)
25{
26 uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
27 CLOCK_EnableClock(kCLOCK_Uart4);
28 DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
29}
30
31/* Initialize MPU, configure memory attributes for each region */
32void BOARD_InitMemory(void)
33{
34 /* Disable I cache and D cache */
35 if (SCB_CCR_IC_Msk == (SCB_CCR_IC_Msk & SCB->CCR))
36 {
37 SCB_DisableICache();
38 }
39 if (SCB_CCR_DC_Msk == (SCB_CCR_DC_Msk & SCB->CCR))
40 {
41 SCB_DisableDCache();
42 }
43
44 /* Disable MPU */
45 ARM_MPU_Disable();
46
47 /* MPU configure:
48 * Use ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable,
49 * SubRegionDisable, Size)
50 * API in mpu_armv7.h.
51 * param DisableExec Instruction access (XN) disable bit,0=instruction fetches enabled, 1=instruction fetches
52 * disabled.
53 * param AccessPermission Data access permissions, allows you to configure read/write access for User and
54 * Privileged mode.
55 * Use MACROS defined in mpu_armv7.h:
56 * ARM_MPU_AP_NONE/ARM_MPU_AP_PRIV/ARM_MPU_AP_URO/ARM_MPU_AP_FULL/ARM_MPU_AP_PRO/ARM_MPU_AP_RO
57 * Combine TypeExtField/IsShareable/IsCacheable/IsBufferable to configure MPU memory access attributes.
58 * TypeExtField IsShareable IsCacheable IsBufferable Memory Attribtue Shareability Cache
59 * 0 x 0 0 Strongly Ordered shareable
60 * 0 x 0 1 Device shareable
61 * 0 0 1 0 Normal not shareable Outer and inner write
62 * through no write allocate
63 * 0 0 1 1 Normal not shareable Outer and inner write
64 * back no write allocate
65 * 0 1 1 0 Normal shareable Outer and inner write
66 * through no write allocate
67 * 0 1 1 1 Normal shareable Outer and inner write
68 * back no write allocate
69 * 1 0 0 0 Normal not shareable outer and inner
70 * noncache
71 * 1 1 0 0 Normal shareable outer and inner
72 * noncache
73 * 1 0 1 1 Normal not shareable outer and inner write
74 * back write/read acllocate
75 * 1 1 1 1 Normal shareable outer and inner write
76 * back write/read acllocate
77 * 2 x 0 0 Device not shareable
78 * Above are normal use settings, if your want to see more details or want to config different inner/outter cache
79 * policy.
80 * please refer to Table 4-55 /4-56 in arm cortex-M7 generic user guide <dui0646b_cortex_m7_dgug.pdf>
81 * param SubRegionDisable Sub-region disable field. 0=sub-region is enabled, 1=sub-region is disabled.
82 * param Size Region size of the region to be configured. use ARM_MPU_REGION_SIZE_xxx MACRO in
83 * mpu_armv7.h.
84 */
85
86 /* Region 0 [0x0000_0000 - 0x4000_0000] : Memory with Device type, not executable, not shareable, non-cacheable. */
87 MPU->RBAR = ARM_MPU_RBAR(0, 0x00000000U);
88 MPU->RASR = ARM_MPU_RASR(1, ARM_MPU_AP_FULL, 0, 0, 0, 1, 0, ARM_MPU_REGION_SIZE_1GB);
89
90 /* Region 1 TCML[0x0000_0000 - 0x0001_FFFF]: Memory with Normal type, shareable, non-cacheable */
91 MPU->RBAR = ARM_MPU_RBAR(1, 0x00000000U);
92 MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 1, 0, 0, 0, ARM_MPU_REGION_SIZE_128KB);
93
94 /* Region 2 QSPI[0x0800_0000 - 0x0FFF_FFFF]: Memory with Normal type, shareable, non-cacheable */
95 MPU->RBAR = ARM_MPU_RBAR(2, 0x08000000U);
96 MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 1, 0, 0, 0, ARM_MPU_REGION_SIZE_128MB);
97
98 /* Region 3 TCMU[0x2000_0000 - 0x2002_0000]: Memory with Normal type, shareable, non-cacheable */
99 MPU->RBAR = ARM_MPU_RBAR(3, 0x20000000U);
100 MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 1, 0, 0, 0, ARM_MPU_REGION_SIZE_128KB);
101
102 /* Region 4 DDR[0x4000_0000 - 0x8000_0000]: Memory with Normal type, shareable, non-cacheable */
103 MPU->RBAR = ARM_MPU_RBAR(4, 0x40000000U);
104 MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 1, 0, 0, 0, ARM_MPU_REGION_SIZE_1GB);
105
106 /* Region 5 DDR[0x8000_0000 - 0xF000_0000]: Memory with Normal type, shareable, non-cacheable */
107 MPU->RBAR = ARM_MPU_RBAR(5, 0x80000000U);
108 MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 1, 0, 0, 0, ARM_MPU_REGION_SIZE_1GB);
109
110 /*
111 * Enable MPU and HFNMIENA feature
112 * HFNMIENA ensures that M7 core uses MPU configuration when in hard fault, NMI, and FAULTMASK handlers,
113 * otherwise all memory regions are accessed without MPU protection, which has high risks of cacheable,
114 * especially for AIPS systems.
115 */
116 ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_HFNMIENA_Msk);
117
118 /* Configure the force_incr programmable bit in GPV_5 of PL301_display, which fixes partial write issue.
119 * The AXI2AHB bridge is used for masters that access the TCM through system bus.
120 * Please refer to errata ERR050362 for more information */
121 *(uint32_t *)(GPV5_BASE_ADDR + FORCE_INCR_OFFSET) =
122 *(uint32_t *)(GPV5_BASE_ADDR + FORCE_INCR_OFFSET) | FORCE_INCR_BIT_MASK;
123}
124
125void BOARD_RdcInit(void)
126{
127 /* Move M7 core to specific RDC domain 1 */
128 rdc_domain_assignment_t assignment = {0};
129
130 assignment.domainId = BOARD_DOMAIN_ID;
131 RDC_SetMasterDomainAssignment(RDC, kRDC_Master_M7, &assignment);
132
133 /*
134 * The M7 core is running at domain 1, enable clock gate for Iomux to run at domain 1.
135 */
136 CLOCK_EnableClock(kCLOCK_Iomux0);
137 CLOCK_EnableClock(kCLOCK_Iomux1);
138 CLOCK_EnableClock(kCLOCK_Iomux2);
139 CLOCK_EnableClock(kCLOCK_Iomux3);
140 CLOCK_EnableClock(kCLOCK_Iomux4);
141
142 /*
143 * The M7 core is running at domain 1, enable the QSPI clock sources to domain 1 for flash target.
144 */
145#if defined(FLASH_TARGET)
146 CLOCK_EnableClock(kCLOCK_Qspi);
147#endif
148 /*
149 * The M7 core is running at domain 1, enable the PLL clock sources to domain 1.
150 */
151 CLOCK_ControlGate(kCLOCK_SysPll1Gate, kCLOCK_ClockNeededAll); /* Enabel SysPLL1 to Domain 1 */
152 CLOCK_ControlGate(kCLOCK_SysPll2Gate, kCLOCK_ClockNeededAll); /* Enable SysPLL2 to Domain 1 */
153 CLOCK_ControlGate(kCLOCK_SysPll3Gate, kCLOCK_ClockNeededAll); /* Enable SysPLL3 to Domain 1 */
154 CLOCK_ControlGate(kCLOCK_AudioPll1Gate, kCLOCK_ClockNeededAll); /* Enable AudioPLL1 to Domain 1 */
155 CLOCK_ControlGate(kCLOCK_AudioPll2Gate, kCLOCK_ClockNeededAll); /* Enable AudioPLL2 to Domain 1 */
156 CLOCK_ControlGate(kCLOCK_VideoPll1Gate, kCLOCK_ClockNeededAll); /* Enable VideoPLL1 to Domain 1 */
157}