Created
November 6, 2020 07:59
-
-
Save glegrain/d8aadaddeb3d25b800349c565ee26c1d to your computer and use it in GitHub Desktop.
STM32H7 MPU Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief Configure the MPU attributes as Write Through for External SDRAM. | |
* @note The Base Address is 0xD0000000 . | |
* The Configured Region Size is 32MB because same as SDRAM size. | |
* @param None | |
* @retval None | |
*/ | |
void MPU_Config(void) | |
{ | |
MPU_Region_InitTypeDef MPU_InitStruct; | |
/* Disable the MPU */ | |
HAL_MPU_Disable(); | |
#if 1 | |
/* Configure SDRAM as Write through, no write allocate (WT-NWA) */ | |
MPU_InitStruct.Enable = MPU_REGION_ENABLE; | |
MPU_InitStruct.BaseAddress = 0xD0000000; | |
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB; | |
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; | |
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE; | |
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; | |
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; | |
MPU_InitStruct.Number = MPU_REGION_NUMBER0; | |
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0; | |
MPU_InitStruct.SubRegionDisable = 0x00; | |
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; | |
HAL_MPU_ConfigRegion(&MPU_InitStruct); | |
#elif 0 | |
/* Configure SDRAM as Write-back, no write allocate (WB-NWA) */ | |
MPU_InitStruct.Enable = MPU_REGION_ENABLE; | |
MPU_InitStruct.BaseAddress = 0xD0000000; | |
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB; | |
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; | |
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE; | |
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; | |
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; | |
MPU_InitStruct.Number = MPU_REGION_NUMBER0; | |
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0; | |
MPU_InitStruct.SubRegionDisable = 0x00; | |
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; | |
HAL_MPU_ConfigRegion(&MPU_InitStruct); | |
#else | |
/* Configure SDRAM as Write-back, read and write allocate (WB-RWA) */ | |
MPU_InitStruct.Enable = MPU_REGION_ENABLE; | |
MPU_InitStruct.BaseAddress = 0xD0000000; | |
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB; | |
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; | |
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE; | |
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; | |
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; | |
MPU_InitStruct.Number = MPU_REGION_NUMBER0; | |
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1; | |
MPU_InitStruct.SubRegionDisable = 0x00; | |
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; | |
HAL_MPU_ConfigRegion(&MPU_InitStruct); | |
#endif | |
/* Enable the MPU */ | |
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment