使用
STM32 HAL 和 STM32H7(我知道有些人劝阻使用这个)。我已经创建了 2 个不可缓存内存的 MPU 区域。
- void MPU_Config(void) {
- MPU_Region_InitTypeDef MPU_InitStruct = { 0 };
- /* Disables the MPU */
- HAL_MPU_Disable();
- /** Initializes and configures the Region and the memory to be protected
- */
- MPU_InitStruct.Enable = MPU_REGION_ENABLE;
- MPU_InitStruct.Number = MPU_REGION_NUMBER0;
- MPU_InitStruct.BaseAddress = 0x24060000;
- MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
- MPU_InitStruct.SubRegionDisable = 0;
- MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
- MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
- MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
- MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
- MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
- MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE
- HAL_MPU_ConfigRegion(&MPU_InitStruct);
- /** Initializes and configures the Region and the memory to be protected
- */
- MPU_InitStruct.Number = MPU_REGION_NUMBER1;
- MPU_InitStruct.BaseAddress = 0x240E0000;
- MPU_InitStruct.Size = MPU_REGION_SIZE_128KB;
- MPU_InitStruct.SubRegionDisable = 0x0;
- HAL_MPU_ConfigRegion(&MPU_InitStruct);
- /* Enables the MPU */
- HAL_MPU_Enable(MPU_HFNMI_PRIVDEF);
- }
并创建了一个装载机:
- MEMORY
- {
- ...
- RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 384K
- RAM_NOCACHE (xrw) : ORIGIN = 0x24060000, LENGTH = 1024K - 384K
- ...
- }
- ...
- .DATA_RAM_NOCACHE (NOLOAD) :
- { . = ALIGN(4);
- *(.DATA_RAM_NOCACHE)
- *(.DATA_RAM_NOCACHE*)
- . = ALIGN(4);
- } >RAM_NOCACHE
当使用仅 512Kb 的内存和 1 个 MPU 区域定义时,事情按预期工作,但当我尝试上述操作时发生硬故障 - 内存对齐错误 - 更多细节如下......)
这是因为有2个区域吗?怎么办 谢谢