drv_mpu.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * File : drv_mpu.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-08-01 xiaonong the first version for stm32f7xx
  23. */
  24. #include "drv_mpu.h"
  25. void mpu_init(void)
  26. {
  27. MPU_Region_InitTypeDef MPU_InitStruct;
  28. /* Disable the MPU */
  29. HAL_MPU_Disable();
  30. /* Configure the MPU attributes as WT for SRAM */
  31. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  32. MPU_InitStruct.BaseAddress = 0x20010000;
  33. MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
  34. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  35. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  36. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  37. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  38. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  39. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  40. MPU_InitStruct.SubRegionDisable = 0x00;
  41. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  42. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  43. /* Enable the MPU */
  44. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  45. }