drv_mpu.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * 2017-08-25 LongfeiMa the first version for stm32h7xx
  23. */
  24. #include "drv_mpu.h"
  25. #include <rtthread.h>
  26. #include "stm32h7xx.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. //
  45. // HAL_MPU_ConfigRegion(&MPU_InitStruct);
  46. //
  47. // /* Configure the MPU attributes as WB for SDRAM */
  48. // MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  49. // MPU_InitStruct.BaseAddress = 0xC0000000;
  50. // MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
  51. // MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  52. // MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  53. // MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  54. // MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  55. // MPU_InitStruct.Number = MPU_REGION_NUMBER1;
  56. // MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  57. // MPU_InitStruct.SubRegionDisable = 0x00;
  58. // MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  59. //
  60. // HAL_MPU_ConfigRegion(&MPU_InitStruct);
  61. //
  62. // /* Configure the MPU attributes as none-cache for 1MB SDRAM */
  63. // MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  64. // MPU_InitStruct.BaseAddress = 0xC0100000;
  65. // MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
  66. // MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  67. // MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  68. // MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  69. // MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  70. // MPU_InitStruct.Number = MPU_REGION_NUMBER2;
  71. // MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  72. // MPU_InitStruct.SubRegionDisable = 0x00;
  73. // MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  74. //
  75. // HAL_MPU_ConfigRegion(&MPU_InitStruct);
  76. /* Configure the MPU attributes as WT for SRAM */
  77. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  78. MPU_InitStruct.BaseAddress = 0x30040000;
  79. MPU_InitStruct.Size = MPU_REGION_SIZE_256B;
  80. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  81. MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  82. MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  83. MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  84. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  85. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  86. MPU_InitStruct.SubRegionDisable = 0x00;
  87. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  88. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  89. /* Enable the MPU */
  90. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  91. return 0;
  92. }
  93. //INIT_BOARD_EXPORT(mpu_init);