STM32 MPU (F7 H7)常见应用场景配置示例

配置需要Device 或 Strongly order执行外设

== 引用硬汉嵌入式老哥的教程。==

配置参数可看我另一篇文章

读写Cache都是关闭的,比如FMC外设驱动,扩展IO,LCD,NOR FLASH SRAM,ETH收发描述符空间

特点:保证严格按照程序代码执行

缺点:不支持非对齐访问

配置 FMC 扩展 IO 的 MPU 属性为 Device 或者 Strongly Ordered

c 复制代码
/* 配置 FMC 扩展 IO 的 MPU 属性为 Device 或者 Strongly Ordered */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x60000000;
MPU_InitStruct.Size = ARM_MPU_REGION_SIZE_64KB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

以太网收发描述符空间MPU配置

c 复制代码
/* 配置以太网收发描述符部分为 Device */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x30040000;
MPU_InitStruct.Size = MPU_REGION_SIZE_256B;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

配置为最低性能NORMAL,关闭读写Cache

特点:可以像F1、F4那样使用内部SRAM。适合初学者

缺点:性能差

c 复制代码
/* 配置 AXI SRAM 的 MPU 属性为 Write back, Read allocate, Write allocate */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x24000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_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;

配置为NORMAL,此时关闭写Cache,开启读Cache(透写)

特点:SDRAM 做LCD显存和动态内存下非常方便,保证数据是直接写到显存的,开启读Cache,SDRAM 的读性能提升一倍,提升GUI性能(如LTDC)。

缺点:由于开启了读Cache,用户需要调用SCB_CleanInvalidateDCache()函数管理数据一致性问题。只有多主控操作此空间才需要处理

c 复制代码
    /* 配置SDRAM的MPU属性为Write through, read allocate,no write allocate */
	MPU_InitStruct.Enable           = MPU_REGION_ENABLE;
	MPU_InitStruct.BaseAddress      = 0xC0000000;
	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_NUMBER2;
	MPU_InitStruct.TypeExtField     = MPU_TEX_LEVEL0;
	MPU_InitStruct.SubRegionDisable = 0x00;
	MPU_InitStruct.DisableExec      = MPU_INSTRUCTION_ACCESS_ENABLE;

配置为NORMAL 读写Cache全开,最强性能

特点:性能最强

缺点:由于读写Cache全开,用户需要调用SCB_CleanInvalidateDCache()函数管理数据一致性问题。只有多主控操作此空间才需要处理

c 复制代码
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x24000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
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;
相关推荐
微信1532379424316 小时前
离线语音识别 ( 小语种国家都支持)可定制词组
嵌入式硬件
weixin_5088216516 小时前
1ms软延时,不用定时器,stm32
stm32·单片机·嵌入式硬件
月阳羊17 小时前
【无人机】无人机PX4飞控系统高级软件架构
嵌入式硬件·架构·系统架构·无人机
weixin_5088216518 小时前
stm32 主频216MHz,写个ms延时函数,us延时函数
stm32·单片机·嵌入式硬件
华清远见IT开放实验室18 小时前
【新书上市】《STM32嵌入式系统开发—基于STM32CubeMX和HAL库》,高校教学推荐,STM32入门必读书籍!
stm32·单片机·嵌入式硬件·虚拟仿真·必读书籍·高校教学
智木芯语18 小时前
【58】编程技巧:单片机编程命名规范
单片机·嵌入式硬件·嵌入式·#stm32·#stc8
捷配datasheet18 小时前
OP2177运算放大器:高性能模拟信号处理的关键元件
嵌入式硬件·信号处理
逼子格20 小时前
五种音频器件综合对比——《器件手册--音频器件》
嵌入式硬件·音视频·硬件工程师·硬件测试·电子器件·硬件笔试真题·音频器件
niuTaylor1 天前
STM32平衡车开发实战教程:从零基础到项目精通
stm32·单片机·嵌入式硬件