1
0

drv_mpu.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2006-2021, 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. int mpu_init(void)
  13. {
  14. MPU_Region_InitTypeDef MPU_InitStruct;
  15. /* Disable the MPU */
  16. HAL_MPU_Disable();
  17. /* Configure the MPU attributes as WT for AXI SRAM */
  18. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  19. MPU_InitStruct.BaseAddress = 0x24000000;
  20. MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
  21. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  22. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  23. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  24. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  25. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  26. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  27. MPU_InitStruct.SubRegionDisable = 0X00;
  28. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  29. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  30. #ifdef BSP_USING_SDRAM
  31. /* Configure the MPU attributes as WT for SDRAM */
  32. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  33. MPU_InitStruct.BaseAddress = 0xC0000000;
  34. MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
  35. MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  36. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  37. MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  38. MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  39. MPU_InitStruct.Number = MPU_REGION_NUMBER1;
  40. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  41. MPU_InitStruct.SubRegionDisable = 0x00;
  42. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  43. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  44. #endif
  45. /* Enable the MPU */
  46. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  47. /* Enable CACHE */
  48. SCB_EnableICache();
  49. SCB_EnableDCache();
  50. return 0;
  51. }
  52. INIT_BOARD_EXPORT(mpu_init);