-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmpu.c
64 lines (49 loc) · 1.75 KB
/
mpu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdint.h>
#define MPU_BASE 0xe000ed90
#define MPU_CTLR_ENABLE (1 << 0)
#define MPU_CTLR_PRIVDEFENA (1 << 2)
#define MPU_RBAR_ADDR_MASK 0xffffffe0
#define MPU_RASR_AP_SHIFT 24
#define MPU_RASR_AP_RWRW (0x3 << MPU_RASR_AP_SHIFT)
#define MPU_RASR_TEX_SHIFT 19
#define MPU_RASR_S_SHIFT 18
#define MPU_RASR_C_SHIFT 17
#define MPU_RASR_B_SHIFT 16
#define MPU_RASR_SIZE_SHIFT 1
#define MPU_RASR_REG_ENABLE 0x1
#define MPU_RASR_SIZE_256M (28 << MPU_RASR_SIZE_SHIFT)
#define MPU_RASR_SIZE_32M (24 << MPU_RASR_SIZE_SHIFT)
#define MPU_RASR_SIZE_1M (19 << MPU_RASR_SIZE_SHIFT)
#define MPU_RASR_PERM_ATTRS(TEX, C, B, S) \
((TEX << MPU_RASR_TEX_SHIFT) |\
(C << MPU_RASR_C_SHIFT) | \
(B << MPU_RASR_B_SHIFT) | \
(S << MPU_RASR_S_SHIFT))
#define MPU_RASR_INT_FLASH_ATTR MPU_RASR_PERM_ATTRS(0, 1, 0, 0)
#define MPU_RASR_INT_RAM_ATTR MPU_RASR_PERM_ATTRS(0, 1, 0, 1)
#define MPU_RASR_EXT_RAM_ATTR MPU_RASR_PERM_ATTRS(0, 1, 1, 0)
#define MPU_RASR_PERIPH_ATTR MPU_RASR_PERM_ATTRS(0, 0, 1, 1)
#define MPU_RASR_PRIV_PERIPH_ATTR MPU_RASR_PERM_ATTRS(0, 0, 0, 0)
void mpu_config(uint32_t sdram_base)
{
volatile uint32_t *MPU_CTRL = (void *)(MPU_BASE + 0x04);
volatile uint32_t *MPU_RNR = (void *)(MPU_BASE + 0x08);
volatile uint32_t *MPU_RBAR = (void *)(MPU_BASE + 0x0c);
volatile uint32_t *MPU_RASR = (void *)(MPU_BASE + 0x10);
/* Configure external SDRAM */
*MPU_RNR = 0x0;
*MPU_RBAR = sdram_base;
*MPU_RASR = MPU_RASR_AP_RWRW |
MPU_RASR_EXT_RAM_ATTR |
MPU_RASR_SIZE_256M |
MPU_RASR_REG_ENABLE;
*MPU_RNR = 0x2;
*MPU_RBAR = 0x90000000;
*MPU_RASR = MPU_RASR_AP_RWRW |
MPU_RASR_EXT_RAM_ATTR|
MPU_RASR_SIZE_32M |
MPU_RASR_REG_ENABLE;
*MPU_CTRL = MPU_CTLR_ENABLE | MPU_CTLR_PRIVDEFENA;
asm volatile ("dsb");
asm volatile ("isb");
}