mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 189:f392fc9709a3 1
AnnaBridge 189:f392fc9709a3 2 /** \addtogroup hal */
AnnaBridge 189:f392fc9709a3 3 /** @{*/
AnnaBridge 189:f392fc9709a3 4 /* mbed Microcontroller Library
AnnaBridge 189:f392fc9709a3 5 * Copyright (c) 2018-2018 ARM Limited
AnnaBridge 189:f392fc9709a3 6 *
AnnaBridge 189:f392fc9709a3 7 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 189:f392fc9709a3 8 * you may not use this file except in compliance with the License.
AnnaBridge 189:f392fc9709a3 9 * You may obtain a copy of the License at
AnnaBridge 189:f392fc9709a3 10 *
AnnaBridge 189:f392fc9709a3 11 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 189:f392fc9709a3 12 *
AnnaBridge 189:f392fc9709a3 13 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 189:f392fc9709a3 14 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 189:f392fc9709a3 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 189:f392fc9709a3 16 * See the License for the specific language governing permissions and
AnnaBridge 189:f392fc9709a3 17 * limitations under the License.
AnnaBridge 189:f392fc9709a3 18 */
AnnaBridge 189:f392fc9709a3 19 #ifndef MBED_MPU_API_H
AnnaBridge 189:f392fc9709a3 20 #define MBED_MPU_API_H
AnnaBridge 189:f392fc9709a3 21
AnnaBridge 189:f392fc9709a3 22 #include "device.h"
AnnaBridge 189:f392fc9709a3 23 #include <stdbool.h>
AnnaBridge 189:f392fc9709a3 24
AnnaBridge 189:f392fc9709a3 25 #ifdef __cplusplus
AnnaBridge 189:f392fc9709a3 26 extern "C" {
AnnaBridge 189:f392fc9709a3 27 #endif
AnnaBridge 189:f392fc9709a3 28
AnnaBridge 189:f392fc9709a3 29 #if DEVICE_MPU
AnnaBridge 189:f392fc9709a3 30
AnnaBridge 189:f392fc9709a3 31 /**
AnnaBridge 189:f392fc9709a3 32 * \defgroup hal_mpu MPU hal
AnnaBridge 189:f392fc9709a3 33 *
AnnaBridge 189:f392fc9709a3 34 * The MPU hal provides a simple MPU API to enhance device security by preventing
AnnaBridge 189:f392fc9709a3 35 * execution from ram.
AnnaBridge 189:f392fc9709a3 36 *
AnnaBridge 189:f392fc9709a3 37 * # Defined behavior
AnnaBridge 189:f392fc9709a3 38 * * The function ::mbed_mpu_init is safe to call repeatedly - Verified by ::mpu_init_test
AnnaBridge 189:f392fc9709a3 39 * * The function ::mbed_mpu_free disables MPU protection - Verified by ::mpu_free_test
AnnaBridge 189:f392fc9709a3 40 * * Execution from RAM results in a fault when execute never is enabled.
AnnaBridge 189:f392fc9709a3 41 * This RAM includes heap, stack, data and zero init - Verified by ::mpu_fault_test_data,
AnnaBridge 189:f392fc9709a3 42 * ::mpu_fault_test_bss, ::mpu_fault_test_stack and ::mpu_fault_test_heap.
AnnaBridge 189:f392fc9709a3 43 * * Writing to ROM results in a fault when write never is enabled - Not verified
AnnaBridge 189:f392fc9709a3 44 *
AnnaBridge 189:f392fc9709a3 45 * # Undefined behavior
AnnaBridge 189:f392fc9709a3 46 * * Calling any function other than ::mbed_mpu_init before the initialization of the MPU.
AnnaBridge 189:f392fc9709a3 47 *
AnnaBridge 189:f392fc9709a3 48 * @see hal_mpu_tests
AnnaBridge 189:f392fc9709a3 49 *
AnnaBridge 189:f392fc9709a3 50 * @{
AnnaBridge 189:f392fc9709a3 51 */
AnnaBridge 189:f392fc9709a3 52
AnnaBridge 189:f392fc9709a3 53 /**
AnnaBridge 189:f392fc9709a3 54 * \defgroup hal_mpu_tests MPU hal tests
AnnaBridge 189:f392fc9709a3 55 * The MPU test validates proper implementation of the MPU hal.
AnnaBridge 189:f392fc9709a3 56 *
AnnaBridge 189:f392fc9709a3 57 * To run the MPU hal tests use the command:
AnnaBridge 189:f392fc9709a3 58 *
AnnaBridge 189:f392fc9709a3 59 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-mpu*
AnnaBridge 189:f392fc9709a3 60 */
AnnaBridge 189:f392fc9709a3 61
AnnaBridge 189:f392fc9709a3 62
AnnaBridge 189:f392fc9709a3 63 /**
AnnaBridge 189:f392fc9709a3 64 * Initialize the MPU
AnnaBridge 189:f392fc9709a3 65 *
AnnaBridge 189:f392fc9709a3 66 * Initialize or re-initialize the memory protection unit.
AnnaBridge 189:f392fc9709a3 67 * After initialization or re-initialization, ROM and RAM protection
AnnaBridge 189:f392fc9709a3 68 * are both enabled.
AnnaBridge 189:f392fc9709a3 69 */
AnnaBridge 189:f392fc9709a3 70 void mbed_mpu_init(void);
AnnaBridge 189:f392fc9709a3 71
AnnaBridge 189:f392fc9709a3 72 /**
AnnaBridge 189:f392fc9709a3 73 * Enable or disable ROM MPU protection
AnnaBridge 189:f392fc9709a3 74 *
AnnaBridge 189:f392fc9709a3 75 * This function is used to mark all of ROM as read and execute only.
AnnaBridge 189:f392fc9709a3 76 * When enabled writes to ROM cause a fault.
AnnaBridge 189:f392fc9709a3 77 *
AnnaBridge 189:f392fc9709a3 78 * By default writes to ROM are disabled.
AnnaBridge 189:f392fc9709a3 79 *
AnnaBridge 189:f392fc9709a3 80 * @param enable true to disable writes to ROM, false otherwise
AnnaBridge 189:f392fc9709a3 81 */
AnnaBridge 189:f392fc9709a3 82 void mbed_mpu_enable_rom_wn(bool enable);
AnnaBridge 189:f392fc9709a3 83
AnnaBridge 189:f392fc9709a3 84 /**
AnnaBridge 189:f392fc9709a3 85 * Enable or disable ram MPU protection
AnnaBridge 189:f392fc9709a3 86 *
AnnaBridge 189:f392fc9709a3 87 * This function is used to mark all of RAM as execute never.
AnnaBridge 189:f392fc9709a3 88 * When enabled code is only allowed to execute from flash.
AnnaBridge 189:f392fc9709a3 89 *
AnnaBridge 189:f392fc9709a3 90 * By default execution from RAM is disabled.
AnnaBridge 189:f392fc9709a3 91 *
AnnaBridge 189:f392fc9709a3 92 * @param enable true to disable execution from RAM, false otherwise
AnnaBridge 189:f392fc9709a3 93 */
AnnaBridge 189:f392fc9709a3 94 void mbed_mpu_enable_ram_xn(bool enable);
AnnaBridge 189:f392fc9709a3 95
AnnaBridge 189:f392fc9709a3 96 /** Deinitialize the MPU
AnnaBridge 189:f392fc9709a3 97 *
AnnaBridge 189:f392fc9709a3 98 * Powerdown the MPU in preparation for powerdown, reset or jumping to another application.
AnnaBridge 189:f392fc9709a3 99 */
AnnaBridge 189:f392fc9709a3 100 void mbed_mpu_free(void);
AnnaBridge 189:f392fc9709a3 101
AnnaBridge 189:f392fc9709a3 102 /**@}*/
AnnaBridge 189:f392fc9709a3 103
AnnaBridge 189:f392fc9709a3 104 #else
AnnaBridge 189:f392fc9709a3 105
AnnaBridge 189:f392fc9709a3 106 #define mbed_mpu_init()
AnnaBridge 189:f392fc9709a3 107
AnnaBridge 189:f392fc9709a3 108 #define mbed_mpu_enable_rom_wn(enable) (void)enable
AnnaBridge 189:f392fc9709a3 109
AnnaBridge 189:f392fc9709a3 110 #define mbed_mpu_enable_ram_xn(enable) (void)enable
AnnaBridge 189:f392fc9709a3 111
AnnaBridge 189:f392fc9709a3 112 #define mbed_mpu_free()
AnnaBridge 189:f392fc9709a3 113
AnnaBridge 189:f392fc9709a3 114 #endif
AnnaBridge 189:f392fc9709a3 115
AnnaBridge 189:f392fc9709a3 116 #ifdef __cplusplus
AnnaBridge 189:f392fc9709a3 117 }
AnnaBridge 189:f392fc9709a3 118 #endif
AnnaBridge 189:f392fc9709a3 119
AnnaBridge 189:f392fc9709a3 120 #endif
AnnaBridge 189:f392fc9709a3 121
AnnaBridge 189:f392fc9709a3 122 /** @}*/