drv_mpu.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * File : drv_mpu.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, 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. * 2018-05-17 ZYH first implementation
  23. */
  24. #include "drv_mpu.h"
  25. #include <rtthread.h>
  26. #include "stm32f7xx.h"
  27. int bsp_mpu_hw_init(void)
  28. {
  29. MPU_Region_InitTypeDef MPU_InitStruct;
  30. /* Disables the MPU */
  31. HAL_MPU_Disable();
  32. /**Initializes and configures the Region and the memory to be protected
  33. */
  34. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  35. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  36. MPU_InitStruct.BaseAddress = 0x20000000;
  37. MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
  38. MPU_InitStruct.SubRegionDisable = 0x0;
  39. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  40. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  41. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  42. MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  43. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  44. MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  45. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  46. /* Enables the MPU */
  47. HAL_MPU_Enable(MPU_HFNMI_PRIVDEF);
  48. return 0;
  49. }