drv_mpu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2025 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-04-14 whj4674672 first version
  9. */
  10. #include <rtthread.h>
  11. #include "stm32h7xx.h"
  12. #include "board.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 AXI SRAM */
  19. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  20. MPU_InitStruct.BaseAddress = 0x24000000;
  21. MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
  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. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  31. #ifdef BSP_USING_SDRAM
  32. /* Configure the MPU attributes as WT for SDRAM */
  33. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  34. MPU_InitStruct.BaseAddress = 0xC0000000;
  35. MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
  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_NUMBER1;
  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. #endif
  46. #ifdef BSP_USING_ETH_H750
  47. /* Configure the MPU attributes as Device not cacheable
  48. for ETH DMA descriptors and RX Buffers*/
  49. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  50. MPU_InitStruct.BaseAddress = 0x30040000;
  51. MPU_InitStruct.Size = MPU_REGION_SIZE_32KB;
  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_SHAREABLE;
  56. MPU_InitStruct.Number = MPU_REGION_NUMBER2;
  57. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
  58. MPU_InitStruct.SubRegionDisable = 0x00;
  59. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  60. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  61. #endif
  62. /* Configure the MPU attributes as WT for QSPI */
  63. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  64. MPU_InitStruct.BaseAddress = 0x90000000;
  65. MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
  66. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  67. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  68. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  69. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  70. MPU_InitStruct.Number = MPU_REGION_NUMBER3;
  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. /* Enable CACHE */
  78. #ifdef BSP_SCB_ENABLE_I_CACHE
  79. SCB_EnableICache();
  80. #endif
  81. #ifdef BSP_SCB_ENABLE_D_CACHE
  82. SCB_EnableDCache();
  83. #endif
  84. return RT_EOK;
  85. }
  86. INIT_BOARD_EXPORT(mpu_init);