|
39 | 39 | #define SDRAM_START_ADDRESS 0xD0000000
|
40 | 40 | #endif
|
41 | 41 |
|
| 42 | +// Provides the MPU_REGION_SIZE_X value when passed the size of region in bytes |
| 43 | +// "m" must be a power of 2 between 32 and 4G (2**5 and 2**32) and this formula |
| 44 | +// computes the log2 of "m", minus 1 |
| 45 | +#define MPU_REGION_SIZE(m) (((m) - 1) / (((m) - 1) % 255 + 1) / 255 % 255 * 8 + 7 - 86 / (((m) - 1) % 255 + 12) - 1) |
| 46 | + |
| 47 | +#define SDRAM_MPU_REGION_SIZE (MPU_REGION_SIZE(MICROPY_HW_SDRAM_SIZE)) |
| 48 | + |
42 | 49 | #ifdef FMC_SDRAM_BANK
|
43 | 50 |
|
44 | 51 | static void sdram_init_seq(SDRAM_HandleTypeDef
|
@@ -244,17 +251,33 @@ static void sdram_init_seq(SDRAM_HandleTypeDef
|
244 | 251 | /* Disable the MPU */
|
245 | 252 | HAL_MPU_Disable();
|
246 | 253 |
|
247 |
| - /* Configure the MPU attributes as Write-Through for External SDRAM */ |
| 254 | + /* Configure the MPU attributes for External SDRAM |
| 255 | + Initially disable all access for the entire SDRAM memory space, |
| 256 | + then enable access/caching for the size used |
| 257 | + */ |
248 | 258 | MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
| 259 | + MPU_InitStruct.Number = MPU_REGION_NUMBER4; |
249 | 260 | MPU_InitStruct.BaseAddress = SDRAM_START_ADDRESS;
|
250 |
| - MPU_InitStruct.Size = MPU_REGION_SIZE_256MB; |
251 |
| - MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; |
| 261 | + MPU_InitStruct.Size = MPU_REGION_SIZE_512MB; |
| 262 | + MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS; |
252 | 263 | MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
253 |
| - MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; |
| 264 | + MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE; |
254 | 265 | MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
255 |
| - MPU_InitStruct.Number = MPU_REGION_NUMBER0; |
256 | 266 | MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
257 | 267 | MPU_InitStruct.SubRegionDisable = 0x00;
|
| 268 | + MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE; |
| 269 | + HAL_MPU_ConfigRegion(&MPU_InitStruct); |
| 270 | + |
| 271 | + MPU_InitStruct.Enable = MPU_REGION_ENABLE; |
| 272 | + MPU_InitStruct.Number = MPU_REGION_NUMBER5; |
| 273 | + MPU_InitStruct.BaseAddress = SDRAM_START_ADDRESS; |
| 274 | + MPU_InitStruct.Size = SDRAM_MPU_REGION_SIZE; |
| 275 | + MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; |
| 276 | + MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE; |
| 277 | + MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; |
| 278 | + MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; |
| 279 | + MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1; |
| 280 | + MPU_InitStruct.SubRegionDisable = 0x00; |
258 | 281 | MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
259 | 282 | HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
260 | 283 |
|
|
0 commit comments