drt_mpu.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * File : application.c
  3. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Change Logs:
  20. * Date Author Notes
  21. * 2017-11-14 Tanek porting from stm32f429-apollo
  22. */
  23. #include <rthw.h>
  24. #include <rtthread.h>
  25. #include <LPC54608.h>
  26. #define DEBUG
  27. #ifdef DEBUG
  28. #define MPU_PRINT(...) rt_kprintf(__VA_ARGS__)
  29. #else
  30. #define MPU_PRINT((...))
  31. #endif
  32. /* initialize for gui driver */
  33. int rt_hw_mpu_init(void)
  34. {
  35. uint32_t rbar;
  36. uint32_t rasr;
  37. MPU_PRINT("\nnumber of regions: %d\n", (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos);
  38. /* Disable MPU */
  39. ARM_MPU_Disable();
  40. /* - Region 0: 0x00000000 - 0x0007FFFF --- on-chip non-volatile memory
  41. * + Size: 512kB
  42. * + Acess permission: full access
  43. */
  44. rbar = ARM_MPU_RBAR(0, 0x00000000);
  45. rasr = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_512KB);
  46. ARM_MPU_SetRegion(rbar, rasr);
  47. /* - Region 1:0x20000000 - 0x20027FFF --- on chip SRAM
  48. * + Size: 160kB
  49. * + Access permission: full access
  50. */
  51. rbar = ARM_MPU_RBAR(1, 0x20000000);
  52. rasr = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_256KB);
  53. ARM_MPU_SetRegion(rbar, rasr);
  54. /* - Region 2: 0x40000000 - 0x43FFFFFF --- APB peripheral
  55. * + Size: 64MB
  56. * + Access permission: full access
  57. */
  58. rbar = ARM_MPU_RBAR(2, 0x40000000);
  59. rasr = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_64MB);
  60. ARM_MPU_SetRegion(rbar, rasr);
  61. /* - Region 3: 0xA0000000 - 0xA0800000 --- External SDRAM
  62. * + Size: 8MB
  63. * + AP=b011: full access
  64. */
  65. rbar = ARM_MPU_RBAR(3, 0xA0000000);
  66. rasr = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_8MB);
  67. ARM_MPU_SetRegion(rbar, rasr);
  68. /* - Region 4: 0xE0000000 - 0xE00FFFFF --- System control
  69. * + Size: 1MB
  70. * + Access permission: full access
  71. */
  72. rbar = ARM_MPU_RBAR(4, 0xE0000000);
  73. rasr = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_1MB);
  74. ARM_MPU_SetRegion(rbar, rasr);
  75. ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk);
  76. return 0;
  77. }
  78. INIT_BOARD_EXPORT(rt_hw_mpu_init);