Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
G4_mpu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
pro
G4_mpu
Commits
9cfe91a1
Commit
9cfe91a1
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: ex1 seemingly finished
parent
d064a263
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assembleur.s
+4
-1
4 additions, 1 deletion
assembleur.s
macro.h
+31
-0
31 additions, 0 deletions
macro.h
mpu_user_console_etu.c
+35
-3
35 additions, 3 deletions
mpu_user_console_etu.c
with
70 additions
and
4 deletions
assembleur.s
+
4
−
1
View file @
9cfe91a1
...
@@ -11,7 +11,10 @@
...
@@ -11,7 +11,10 @@
switch_to_user_mode
:
switch_to_user_mode
:
ldr
r0
,
=
user_stack
msr
PSP
,
r0
mov
r1
,
#
1
msr
CONTROL
,
r1
bx
lr
bx
lr
...
...
This diff is collapsed.
Click to expand it.
macro.h
0 → 100644
+
31
−
0
View file @
9cfe91a1
/*
* macro.h
*
* Created on: 20 Dec 2023
* Author: iliya
*/
#ifndef MACRO_H_
#define MACRO_H_
// Region enable bit
#define REGION_ENABLE (0x1 << 0)
// Memory region sizes
#define SET_SIZE_512KB (0x12 << 1)
#define SET_SIZE_32KB (0xE << 1)
#define SET_SIZE_16KB (0xD << 1)
// Access permission attribute
#define BTEX_NORMAL_NOT_SHAREABLE (0x1 << 19)
#define BTEX_NOT_SHAREABLE_DEVICE (0x2 << 19)
// Access permission field
#define RO (0x7 << 24)
#define RW (0x3 << 24)
#define RW_PRIV (0x1 << 24)
#define RW_PRIV_R_UNPRIV (0x2 << 24)
#endif
/* MACRO_H_ */
This diff is collapsed.
Click to expand it.
mpu_user_console_etu.c
+
35
−
3
View file @
9cfe91a1
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include
"globals.h"
#include
"globals.h"
#include
"user_cmd.h"
#include
"user_cmd.h"
#include
"uart.h"
#include
"uart.h"
#include
"macro.h"
#define MMFAR *(unsigned *)0xE000ED34
#define MMFAR *(unsigned *)0xE000ED34
...
@@ -31,8 +32,6 @@ void switch_to_user_mode();
...
@@ -31,8 +32,6 @@ void switch_to_user_mode();
void
asm_test_fault
();
void
asm_test_fault
();
void
MemManage_Handler
()
{
void
MemManage_Handler
()
{
SCB
->
SHCSR
|=
(
1
<<
16
);
// Activez le MPU
}
}
void
test_supervisor_mode
()
{
void
test_supervisor_mode
()
{
...
@@ -55,11 +54,44 @@ void test_user_mode() {
...
@@ -55,11 +54,44 @@ void test_user_mode() {
n
=
LPC_TIM0
->
TC
;
// not OK (privileged access only)
n
=
LPC_TIM0
->
TC
;
// not OK (privileged access only)
}
}
int
main
(
void
)
{
int
main
(
void
)
{
// MPU configuration here...
// MPU configuration here...
// Region 0 (Flash)
MPU
->
RNR
=
0
;
MPU
->
RBAR
=
0x00000000
;
MPU
->
RASR
=
RO
|
BTEX_NORMAL_NOT_SHAREABLE
|
SET_SIZE_512KB
|
REGION_ENABLE
;
// Region 1 (SRAM1)
MPU
->
RNR
=
1
;
MPU
->
RBAR
=
0x10000000
;
MPU
->
RASR
=
RW
|
BTEX_NORMAL_NOT_SHAREABLE
|
SET_SIZE_32KB
|
REGION_ENABLE
;
// Region 2 (SRAM1)
MPU
->
RNR
=
2
;
MPU
->
RBAR
=
0x2007C000
;
MPU
->
RASR
=
RW_PRIV_R_UNPRIV
|
BTEX_NORMAL_NOT_SHAREABLE
|
SET_SIZE_32KB
|
REGION_ENABLE
;
// Region 3 (GPIO)
MPU
->
RNR
=
3
;
MPU
->
RBAR
=
0x2009C000
;
MPU
->
RASR
=
RW_PRIV_R_UNPRIV
|
BTEX_NOT_SHAREABLE_DEVICE
|
SET_SIZE_16KB
|
REGION_ENABLE
;
// Region 4 (périphériques dont timers)
MPU
->
RNR
=
4
;
MPU
->
RBAR
=
0x40000000
;
MPU
->
RASR
=
RW_PRIV
|
BTEX_NOT_SHAREABLE_DEVICE
|
SET_SIZE_32KB
|
REGION_ENABLE
;
// Region 5 (UART)
MPU
->
RNR
=
5
;
MPU
->
RBAR
=
0x4000C000
;
MPU
->
RASR
=
RW
|
BTEX_NOT_SHAREABLE_DEVICE
|
SET_SIZE_16KB
|
REGION_ENABLE
;
SCB
->
SHCSR
|=
(
1
<<
16
);
MPU
->
CTRL
|=
0x1
<<
0
;
// testing memory accesses in supervisor mode:
// testing memory accesses in supervisor mode:
test_supervisor_mode
();
// to be removed after checking
//
test_supervisor_mode(); // to be removed after checking
user_start:
user_stating_address
=
&&
user_start
;
// save the address of the label 'user_start' (for exercise 2)
user_start:
user_stating_address
=
&&
user_start
;
// save the address of the label 'user_start' (for exercise 2)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment