Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. void enable_sram_execution()
  2. {
  3.     uint32_t attr_val = 0;
  4.     // disable MPU first
  5.     NVIC_MPU_CTRL_R = 0;
  6.    
  7.     // region 0
  8.     NVIC_MPU_NUMBER_R = 0;
  9.    
  10.     // SRAM Base = 0x2000.0000
  11.     NVIC_MPU_BASE_R = 0x20000000;
  12.     // SRAM Size = 0x8000
  13.     #define EXECUTABLE_REGION (0x0 << 28) // executable, i.e. XN = 0
  14.     #define ACCESS_PERMISSION (0x03 << 24) // R/W for both privileged and unprivileged
  15.     #define TEXSCB (0x8 << 16) // normal (TEX = b001, S = 0, C = 0, B = 0)
  16.     #define SRD (0x0 << 8) // no sub-region disabled
  17.     #define SIZE (0xE << 1) // size of 32K (2^15)
  18.     #define ENABLED (0x01 << 0)
  19.    
  20.    
  21.     attr_val = (EXECUTABLE_REGION | ACCESS_PERMISSION | TEXSCB | SRD | SIZE | ENABLED);
  22.    
  23.     NVIC_MPU_ATTR_R = attr_val;
  24.     NVIC_MPU_CTRL_R = 0x7; // enable PRIVDEFENA and enable the region
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement