Example of usage of the MPU in AVR UC3.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include "mpu.h"
#include "board.h"
#include "compiler.h"
#include "sysclk.h"
#include "gpio.h"
Macros | |
Regions | |
#define | NB_CONFIG_MPU_ENTRIES 4 |
#define | REGION_0_FLASH_INDEX 0 |
#define | REGION_1_RAM_INDEX 1 |
#define | REGION_2_STACK_INDEX 2 |
#define | REGION_3_PERIPHERALS_INDEX 3 |
Enumerations | |
enum | exception_status { NO_EXCEPTION = 0, TLB_MULTIPLE_HIT_EXCEPTION = 1, ITLB_MISS_EXCEPTION = 2, ITLB_PROTECTION_EXCEPTION = 3, DTLB_WRITE_PROTECTION_EXCEPTION = 4, DTLB_WRITE_MISS_EXCEPTION = 5, DTLB_READ_PROTECTION_EXCEPTION = 6, DTLB_READ_MISS_EXCEPTION = 7, UNEXPECTED_EXCEPTION = -1, NO_EXCEPTION = 0, TLB_MULTIPLE_HIT_EXCEPTION = 1, ITLB_MISS_EXCEPTION = 2, ITLB_PROTECTION_EXCEPTION = 3, DTLB_WRITE_PROTECTION_EXCEPTION = 4, DTLB_WRITE_MISS_EXCEPTION = 5, DTLB_READ_PROTECTION_EXCEPTION = 6, DTLB_READ_MISS_EXCEPTION = 7, UNEXPECTED_EXCEPTION = -1 } |
Exception State. More... | |
Functions | |
static void | configure_memory_area (void) |
Configure the access permissions for different memory regions. More... | |
static void | forbidden_access_func (void) |
Function with restricted access. More... | |
void | handle_exception (uint32_t *sp, uint32_t exception_address, uint32_t exception_cause) |
Handle exception; called by the _evba assembly function. More... | |
int | main (void) |
Main function. More... | |
static void | mpu_configuration_error (void) |
Error occurred during MPU configuration. More... | |
Variables | |
mpu_entry_t | dmpu_entries [NB_CONFIG_MPU_ENTRIES] |
enum exception_status | exception_state = NO_EXCEPTION |
#define NB_CONFIG_MPU_ENTRIES 4 |
#define REGION_0_FLASH_INDEX 0 |
Referenced by configure_memory_area().
#define REGION_1_RAM_INDEX 1 |
Referenced by configure_memory_area().
#define REGION_2_STACK_INDEX 2 |
Referenced by configure_memory_area().
#define REGION_3_PERIPHERALS_INDEX 3 |
Referenced by configure_memory_area().
enum exception_status |
Exception State.
|
static |
Configure the access permissions for different memory regions.
Assign different access permissions to the memory regions
References _stack, mpu_entry_t::addr, enable_mpu(), Get_system_register, MPU_APRA_ID, MPU_APRB_ID, mpu_configuration_error(), mpu_convert_kbsize_to_eregionsize(), MPU_PRIVR_UNPRIVNONE, MPU_PRIVRW_UNPRIVNONE, MPU_PRIVRX_UNPRIVRX, MPU_REGION_SIZE_4KB, MPU_REGION_SIZE_64KB, REGION_0_FLASH_INDEX, REGION_1_RAM_INDEX, REGION_2_STACK_INDEX, REGION_3_PERIPHERALS_INDEX, select_subregion(), set_access_permissions(), set_mpu_entry(), mpu_entry_t::size, and mpu_entry_t::valid.
Referenced by main().
|
static |
Function with restricted access.
Forbidden_access_func() is placed in the section .ForbiddenText. This region is configured as non-executable in configure_memory_area(). .ForbiddenText is a section created for this example, placed in a well-known location in Flash. See the linker script bundled with the example.
Referenced by main().
void handle_exception | ( | uint32_t * | sp, |
uint32_t | exception_address, | ||
uint32_t | exception_cause | ||
) |
Handle exception; called by the _evba assembly function.
*sp | pointer to stack before the exception (provided through R12. At this point, sp[0]=SR, sp[1]=PC. |
exception_address | address of the offending instruction |
exception_cause | exception cause ((EVBA offset of the exception)>>2) |
int main | ( | void | ) |
Main function.
This example describes how to setup the AVR32 UC3 MPU with protected regions.
The following exceptions arises in the main function when trying to access the protected regions.
References configure_memory_area(), cpu_irq_enable, cpu_relax, Enable_global_exception, forbidden_access_func(), and sysclk_init().
|
static |
Error occurred during MPU configuration.
This function is called when an error occurs in configuring MPU.
References cpu_relax.
Referenced by configure_memory_area().
mpu_entry_t dmpu_entries[NB_CONFIG_MPU_ENTRIES] |
enum exception_status exception_state = NO_EXCEPTION |