drv_mpu.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. * 2017-08-25 LongfeiMa the first version for stm32h7xx
  9. */
  10. #include "drv_mpu.h"
  11. #include <rtthread.h>
  12. #include "stm32h7xx.h"
  13. int mpu_init(void)
  14. {
  15. MPU_Region_InitTypeDef MPU_InitStruct;
  16. /* Disable the MPU */
  17. HAL_MPU_Disable();
  18. // /* Configure the MPU attributes as WT for SRAM */
  19. // MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  20. // MPU_InitStruct.BaseAddress = 0x20010000;
  21. // MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
  22. // MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  23. // MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  24. // MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  25. // MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  26. // MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  27. // MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  28. // MPU_InitStruct.SubRegionDisable = 0x00;
  29. // MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  30. //
  31. // HAL_MPU_ConfigRegion(&MPU_InitStruct);
  32. //
  33. // /* Configure the MPU attributes as WB for SDRAM */
  34. // MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  35. // MPU_InitStruct.BaseAddress = 0xC0000000;
  36. // MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
  37. // MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  38. // MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  39. // MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  40. // MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  41. // MPU_InitStruct.Number = MPU_REGION_NUMBER1;
  42. // MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  43. // MPU_InitStruct.SubRegionDisable = 0x00;
  44. // MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  45. //
  46. // HAL_MPU_ConfigRegion(&MPU_InitStruct);
  47. //
  48. // /* Configure the MPU attributes as none-cache for 1MB SDRAM */
  49. // MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  50. // MPU_InitStruct.BaseAddress = 0xC0100000;
  51. // MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
  52. // MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  53. // MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  54. // MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  55. // MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  56. // MPU_InitStruct.Number = MPU_REGION_NUMBER2;
  57. // MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  58. // MPU_InitStruct.SubRegionDisable = 0x00;
  59. // MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  60. //
  61. // HAL_MPU_ConfigRegion(&MPU_InitStruct);
  62. /* Configure the MPU attributes as WT for SRAM */
  63. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  64. MPU_InitStruct.BaseAddress = 0x30040000;
  65. MPU_InitStruct.Size = MPU_REGION_SIZE_256B;
  66. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  67. MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
  68. MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  69. MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  70. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  71. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  72. MPU_InitStruct.SubRegionDisable = 0x00;
  73. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  74. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  75. /* Enable the MPU */
  76. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  77. return 0;
  78. }
  79. //INIT_BOARD_EXPORT(mpu_init);