drv_mpu.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-17 ZYH first implementation
  9. */
  10. #include "drv_mpu.h"
  11. #include <rtthread.h>
  12. #include "stm32f7xx.h"
  13. int bsp_mpu_hw_init(void)
  14. {
  15. MPU_Region_InitTypeDef MPU_InitStruct;
  16. /* Disables the MPU */
  17. HAL_MPU_Disable();
  18. /**Initializes and configures the Region and the memory to be protected
  19. */
  20. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  21. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  22. MPU_InitStruct.BaseAddress = 0x20000000;
  23. MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
  24. MPU_InitStruct.SubRegionDisable = 0x0;
  25. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  26. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  27. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  28. MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  29. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  30. MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  31. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  32. /* Enables the MPU */
  33. HAL_MPU_Enable(MPU_HFNMI_PRIVDEF);
  34. return 0;
  35. }