drv_mpu.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include <rtthread.h>
  26. #include "stm32f7xx.h"
  27. int mpu_init(void)
  28. {
  29. MPU_Region_InitTypeDef MPU_InitStruct;
  30. /* Disable the MPU */
  31. HAL_MPU_Disable();
  32. /* Configure the MPU attributes as WT for SRAM */
  33. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  34. MPU_InitStruct.BaseAddress = 0x20010000;
  35. MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
  36. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  37. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  38. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  39. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  40. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  41. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  42. MPU_InitStruct.SubRegionDisable = 0x00;
  43. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  44. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  45. /* Configure the MPU attributes as WB for SDRAM */
  46. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  47. MPU_InitStruct.BaseAddress = 0xC0000000;
  48. MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
  49. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  50. MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  51. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  52. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  53. MPU_InitStruct.Number = MPU_REGION_NUMBER1;
  54. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  55. MPU_InitStruct.SubRegionDisable = 0x00;
  56. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  57. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  58. /* Configure the MPU attributes as none-cache for 1MB SDRAM */
  59. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  60. MPU_InitStruct.BaseAddress = 0xC0100000;
  61. MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
  62. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  63. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  64. MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  65. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  66. MPU_InitStruct.Number = MPU_REGION_NUMBER2;
  67. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  68. MPU_InitStruct.SubRegionDisable = 0x00;
  69. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  70. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  71. /* Enable the MPU */
  72. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  73. return 0;
  74. }
  75. //INIT_BOARD_EXPORT(mpu_init);