github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/runtime_mimxrt1062_mpu.go (about)

     1  //go:build mimxrt1062
     2  
     3  package runtime
     4  
     5  import (
     6  	"device/nxp"
     7  )
     8  
     9  func initCache() {
    10  
    11  	nxp.MPU.Enable(false)
    12  
    13  	// add Default [0] region to deny access to whole address space to workaround
    14  	// speculative prefetch. Refer to Arm errata 1013783-B for more details.
    15  
    16  	// [0] Default {OVERLAY}: 4 GiB, -access, @device, -exec, -share, -cache, -buffer, -subregion
    17  	nxp.MPU.SetRBAR(0, 0x00000000)
    18  	nxp.MPU.SetRASR(nxp.RGNSZ_4GB, nxp.PERM_NONE, nxp.EXTN_DEVICE, false, false, false, false, false)
    19  
    20  	// [1] Peripherals {OVERLAY}: 64 MiB, +ACCESS, @device, +EXEC, -share, -cache, -buffer, -subregion
    21  	nxp.MPU.SetRBAR(1, 0x40000000)
    22  	nxp.MPU.SetRASR(nxp.RGNSZ_64MB, nxp.PERM_FULL, nxp.EXTN_DEVICE, true, false, false, false, false)
    23  
    24  	// [2] RAM {OVERLAY}: 1 GiB, +ACCESS, @device, +EXEC, -share, -cache, -buffer, -subregion
    25  	nxp.MPU.SetRBAR(2, 0x00000000)
    26  	nxp.MPU.SetRASR(nxp.RGNSZ_1GB, nxp.PERM_FULL, nxp.EXTN_DEVICE, true, false, false, false, false)
    27  
    28  	// [3] ITCM: 512 KiB, +ACCESS, #NORMAL, +EXEC, -share, -cache, -buffer, -subregion
    29  	nxp.MPU.SetRBAR(3, 0x00000000)
    30  	nxp.MPU.SetRASR(nxp.RGNSZ_512KB, nxp.PERM_FULL, nxp.EXTN_NORMAL, true, false, false, false, false)
    31  
    32  	// [4] DTCM: 512 KiB, +ACCESS, #NORMAL, +EXEC, -share, -cache, -buffer, -subregion
    33  	nxp.MPU.SetRBAR(4, 0x20000000)
    34  	nxp.MPU.SetRASR(nxp.RGNSZ_512KB, nxp.PERM_FULL, nxp.EXTN_NORMAL, true, false, false, false, false)
    35  
    36  	// [5] RAM (AXI): 512 KiB, +ACCESS, #NORMAL, +EXEC, -share, +CACHE, +BUFFER, -subregion
    37  	nxp.MPU.SetRBAR(5, 0x20200000)
    38  	nxp.MPU.SetRASR(nxp.RGNSZ_512KB, nxp.PERM_FULL, nxp.EXTN_NORMAL, true, false, true, true, false)
    39  
    40  	// [6] FlexSPI: 512 MiB, +ACCESS, #NORMAL, +EXEC, -share, +CACHE, +BUFFER, -subregion
    41  	nxp.MPU.SetRBAR(6, 0x70000000)
    42  	nxp.MPU.SetRASR(nxp.RGNSZ_512MB, nxp.PERM_FULL, nxp.EXTN_NORMAL, true, false, true, true, false)
    43  
    44  	// [7] QSPI flash: 2 MiB, +ACCESS, #NORMAL, +EXEC, -share, +CACHE, +BUFFER, -subregion
    45  	nxp.MPU.SetRBAR(7, 0x60000000)
    46  	nxp.MPU.SetRASR(nxp.RGNSZ_2MB, nxp.PERM_FULL, nxp.EXTN_NORMAL, true, false, true, true, false)
    47  
    48  	nxp.MPU.Enable(true)
    49  }