Skip to content

Commit 7283f9b

Browse files
c1728p90xc0170
authored andcommitted
Add a formal HAL specification for the MPU API
Add a formal HAL specification consisting of: -defined and undefined behavior -test descriptions -enable doxygen for MPU
1 parent a4aa5ea commit 7283f9b

File tree

5 files changed

+130
-1
lines changed

5 files changed

+130
-1
lines changed

TESTS/mbed_hal/mpu/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stdlib.h>
2323

2424
#include "mpu_api.h"
25+
#include "mpu_test.h"
2526

2627
#if !DEVICE_MPU
2728
#error [NOT_SUPPORTED] MPU API not supported for this target

TESTS/mbed_hal/mpu/mpu_test.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018-2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** \addtogroup hal_mpu_tests
18+
* @{
19+
*/
20+
21+
#ifndef MBED_MPU_TEST_H
22+
#define MBED_MPU_TEST_H
23+
24+
#if DEVICE_MPU
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/** Test that ::mbed_mpu_init can be called multiple times.
31+
*
32+
* Given board provides MPU.
33+
* When ::mbed_mpu_init is called multiple times.
34+
* Then ::mbed_mpu_init are successfully performed (no exception is generated).
35+
*
36+
*/
37+
void mpu_init_test(void);
38+
39+
/** Test that ::mbed_mpu_free disables the MPU
40+
*
41+
* Given board provides MPU.
42+
* When ::mbed_mpu_free is called.
43+
* Then execution from RAM is allowed.
44+
*
45+
*/
46+
void mpu_free_test(void);
47+
48+
/** Test that MPU protection works for global data
49+
*
50+
* Given board provides MPU.
51+
* When RAM execution is disabled with a call to ::mbed_mpu_enable_ram_xn.
52+
* Then execution from global initialized data results in a fault.
53+
*
54+
*/
55+
void mpu_fault_test_data(void);
56+
57+
/** Test that MPU protection works for zero initialized data
58+
*
59+
* Given board provides MPU.
60+
* When RAM execution is disabled with a call to ::mbed_mpu_enable_ram_xn.
61+
* Then execution from global uninitialized data results in a fault.
62+
*
63+
*/
64+
void mpu_fault_test_bss(void);
65+
66+
/** Test that MPU protection works for the stack
67+
*
68+
* Given board provides MPU.
69+
* When RAM execution is disabled with a call to ::mbed_mpu_enable_ram_xn.
70+
* Then execution from stack memory results in a fault.
71+
*
72+
*/
73+
void mpu_fault_test_stack(void);
74+
75+
/** Test that MPU protection works for the heap
76+
*
77+
* Given board provides MPU.
78+
* When RAM execution is disabled with a call to ::mbed_mpu_enable_ram_xn.
79+
* Then execution from heap memory results in a fault.
80+
*
81+
*/
82+
void mpu_fault_test_heap(void);
83+
84+
/**@}*/
85+
86+
#ifdef __cplusplus
87+
}
88+
#endif
89+
90+
#endif
91+
92+
#endif
93+
94+
/** @}*/

doxyfile_options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,7 @@ PREDEFINED = DOXYGEN_ONLY \
20832083
DEVICE_INTERRUPTIN \
20842084
DEVICE_ITM \
20852085
DEVICE_LPTICKER \
2086+
DEVICE_MPU \
20862087
DEVICE_PORTIN \
20872088
DEVICE_PORTINOUT \
20882089
DEVICE_PORTOUT \

doxygen_options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"SEARCH_INCLUDES": "YES",
77
"INCLUDE_PATH": "",
88
"INCLUDE_FILE_PATTERNS": "",
9-
"PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_CRC DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_ITM DEVICE_LPTICKER DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_QSPI DEVICE_STORAGE \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\" \"MBED_DEPRECATED(s)=\"",
9+
"PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_CRC DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_ITM DEVICE_LPTICKER DEVICE_MPU DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_QSPI DEVICE_STORAGE \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\" \"MBED_DEPRECATED(s)=\"",
1010
"EXPAND_AS_DEFINED": "",
1111
"SKIP_FUNCTION_MACROS": "NO",
1212
"STRIP_CODE_COMMENTS": "NO",

hal/mpu_api.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,37 @@ extern "C" {
2828

2929
#if DEVICE_MPU
3030

31+
/**
32+
* \defgroup hal_mpu MPU hal
33+
*
34+
* The MPU hal provides a simple MPU API to enhance device security by preventing
35+
* execution from ram.
36+
*
37+
* # Defined behavior
38+
* * The function ::mbed_mpu_init is safe to call repeatedly - Verified by ::mpu_init_test
39+
* * The function ::mbed_mpu_free disables MPU protection - Verified by ::mpu_free_test
40+
* * Execution from RAM results in a fault when execute never is enabled.
41+
* This RAM includes heap, stack, data and zero init - Verified by ::mpu_fault_test_data,
42+
* ::mpu_fault_test_bss, ::mpu_fault_test_stack and ::mpu_fault_test_heap.
43+
*
44+
* # Undefined behavior
45+
* * Calling any function other than ::mbed_mpu_init before the initialization of the MPU.
46+
*
47+
* @see hal_mpu_tests
48+
*
49+
* @{
50+
*/
51+
52+
/**
53+
* \defgroup hal_mpu_tests MPU hal tests
54+
* The MPU test validates proper implementation of the MPU hal.
55+
*
56+
* To run the MPU hal tests use the command:
57+
*
58+
* mbed test -t <toolchain> -m <target> -n tests-mbed_hal-mpu*
59+
*/
60+
61+
3162
/**
3263
* Initialize the MPU
3364
*
@@ -53,6 +84,8 @@ void mbed_mpu_enable_ram_xn(bool enable);
5384
*/
5485
void mbed_mpu_free(void);
5586

87+
/**@}*/
88+
5689
#else
5790

5891
#define mbed_mpu_init()

0 commit comments

Comments
 (0)