|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * SPDX-License-Identifier: BSD-3-Clause |
| 3 | + ****************************************************************************** |
| 4 | + * |
| 5 | + * Copyright (c) 2015-2021 STMicroelectronics. |
| 6 | + * All rights reserved. |
| 7 | + * |
| 8 | + * This software component is licensed by ST under BSD 3-Clause license, |
| 9 | + * the "License"; You may not use this file except in compliance with the |
| 10 | + * License. You may obtain a copy of the License at: |
| 11 | + * opensource.org/licenses/BSD-3-Clause |
| 12 | + * |
| 13 | + ****************************************************************************** |
| 14 | + */ |
| 15 | +#include "stm32h5xx.h" |
| 16 | +#include "mbed_error.h" |
| 17 | + |
| 18 | +/** |
| 19 | + * @brief Enable ICACHE and define a MPU region to avoid HardFaults when accessing OTP and RO regions |
| 20 | + * @param None |
| 21 | + * @retval None |
| 22 | + */ |
| 23 | + |
| 24 | +void Cache_Init() |
| 25 | +{ |
| 26 | + MPU_Attributes_InitTypeDef attr; |
| 27 | + MPU_Region_InitTypeDef region; |
| 28 | + |
| 29 | + /* Disable MPU before perloading and config update */ |
| 30 | + HAL_MPU_Disable(); |
| 31 | + |
| 32 | + /* Configurate 0x00000000-0x08FFF7FF as Read Only, Executable and Cacheable */ |
| 33 | + region.Enable = MPU_REGION_ENABLE; |
| 34 | + region.Number = MPU_REGION_NUMBER0; |
| 35 | + region.AttributesIndex = MPU_ATTRIBUTES_NUMBER0; |
| 36 | + region.BaseAddress = 0x00000000; |
| 37 | + region.LimitAddress = 0x08FFF7FF; |
| 38 | + region.AccessPermission = MPU_REGION_ALL_RO; |
| 39 | + region.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; |
| 40 | + region.IsShareable = MPU_ACCESS_NOT_SHAREABLE; |
| 41 | + HAL_MPU_ConfigRegion(®ion); |
| 42 | + |
| 43 | + /* Define cacheable memory via MPU */ |
| 44 | + attr.Number = MPU_ATTRIBUTES_NUMBER5; |
| 45 | + attr.Attributes = INNER_OUTER(MPU_NOT_CACHEABLE); |
| 46 | + HAL_MPU_ConfigMemoryAttributes(&attr); |
| 47 | + |
| 48 | + /* Configurate 0x08FFF800-0X0FFFFFFF as Read Only, Not Executable and Non-cacheable */ |
| 49 | + region.Enable = MPU_REGION_ENABLE; |
| 50 | + region.Number = MPU_REGION_NUMBER5; |
| 51 | + region.AttributesIndex = MPU_ATTRIBUTES_NUMBER5; |
| 52 | + region.BaseAddress = 0x08FFF800; |
| 53 | + region.LimitAddress = MBED_CONF_TARGET_MPU_ROM_END; |
| 54 | + region.AccessPermission = MPU_REGION_ALL_RO; |
| 55 | + region.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE; |
| 56 | + region.IsShareable = MPU_ACCESS_NOT_SHAREABLE; |
| 57 | + HAL_MPU_ConfigRegion(®ion); |
| 58 | + |
| 59 | + /* Enable the MPU */ |
| 60 | + HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); |
| 61 | + |
| 62 | + /* Enable ICACHE */ |
| 63 | + HAL_ICACHE_Enable(); |
| 64 | +} |
0 commit comments