8000 stm32/sdram: On stm32f7, enable MPU on external ram to fix hard-fault… · micropython/micropython@a03fecc · GitHub
[go: up one dir, main page]

Skip to content

Commit a03fecc

Browse files
committed
stm32/sdram: On stm32f7, enable MPU on external ram to fix hard-faults on non-aligned access
ref: http://www.keil.com/support/docs/3777.htm Expose SDRAM refresh time setting.
1 parent e8200b7 commit a03fecc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ports/stm32/sdram.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,35 @@ static void sdram_init_seq(SDRAM_HandleTypeDef
228228
*/
229229
#define REFRESH_COUNT (MICROPY_HW_SDRAM_REFRESH_RATE*90000/8192-20)
230230
HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT);
231+
232+
#if defined(STM32F7)
233+
/* Enable MPU for the SDRAM Memory Region to allow non-aligned
234+
accesses (hard-fault otherwise)
235+
*/
236+
237+
MPU_Region_InitTypeDef MPU_InitStruct;
238+
239+
/* Disable the MPU */
240+
HAL_MPU_Disable();
241+
242+
/* Configure the MPU attributes for SDRAM */
243+
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
244+
MPU_InitStruct.BaseAddress = SDRAM_START_ADDRESS;
245+
MPU_InitStruct.Size = MPU_REGION_SIZE_4MB;
246+
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
247+
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
248+
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
249+
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
250+
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
251+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
252+
MPU_InitStruct.SubRegionDisable = 0x00;
253+
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
254+
255+
HAL_MPU_ConfigRegion(&MPU_InitStruct);
256+
257+
/* Enable the MPU */
258+
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
259+
#endif
231260
}
232261
#endif //FMC_SDRAM_BANK
233262

0 commit comments

Comments
 (0)
0