3029|0

3

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

LPC1788 APP放在SDRAM中运行直接重启,求高人指点MPU的设置 [复制链接]

/*MPU设置宏,此处是网上大神写的,具体的都没有找到例子*/
#define MPU_REGION_SIZE_32B  0x04
#define MPU_REGION_SIZE_64B  0x05
#define MPU_REGION_SIZE_128B 0x06
#define MPU_REGION_SIZE_256B 0x07
#define MPU_REGION_SIZE_512B 0x08
#define MPU_REGION_SIZE_1KB  0x09
#define MPU_REGION_SIZE_2KB  0x0A
#define MPU_REGION_SIZE_4KB  0x0B
#define MPU_REGION_SIZE_8KB  0x0C
#define MPU_REGION_SIZE_16KB 0x0D
#define MPU_REGION_SIZE_32KB 0x0E
#define MPU_REGION_SIZE_64KB 0x0F
#define MPU_REGION_SIZE_128KB 0x10
#define MPU_REGION_SIZE_256KB 0x11
#define MPU_REGION_SIZE_512KB 0x12
#define MPU_REGION_SIZE_1MB  0x13
#define MPU_REGION_SIZE_2MB  0x14
#define MPU_REGION_SIZE_4MB  0x15
#define MPU_REGION_SIZE_8MB  0x16
#define MPU_REGION_SIZE_16MB 0x17
#define MPU_REGION_SIZE_32MB 0x18
#define MPU_REGION_SIZE_64MB 0x19
#define MPU_REGION_SIZE_128MB 0x1A
#define MPU_REGION_SIZE_256MB 0x1B
#define MPU_REGION_SIZE_512MB 0x1C
#define MPU_REGION_SIZE_1GB  0x1D
#define MPU_REGION_SIZE_2GB  0x1E
#define MPU_REGION_SIZE_4GB  0x1F
/* Access permission definitions */
#define MPU_NO_ACCESS       0x00
#define MPU_PRIVILEGED_ACESS_USER_NO_ACCESS  0x01
#define MPU_PRIVILEGED_RW_USER_READ_ONLY  0x02
#define MPU_FULL_ACCESS       0x03
#define MPU_UNPREDICTABLE      0x04
#define MPU_PRIVILEGED_READ_ONLY_USER_NO_ACCESS 0x05
#define MPU_READ_ONLY       0x06
/* RASR bit definitions */
#define MPU_RASR_REGION_SIZE(n)   ((uint32_t)(n<<1))
#define MPU_RASR_ACCESS_PERMISSION(n) ((uint32_t)(n<<24))
#define MPU_REGION_ENABLE    ((uint32_t)(1<<0))

__asm void boot_jump( uint32_t address )
{
LDR SP, [R0]  ;Load new stack pointer address
    LDR PC, [R0, #4] ;Load new program counter address
}
void ExecuteUserCode(uint32_t addr)
{
// SysTick->CTRL = 0;
// SCB->VTOR = addr & 0xFFFFFF80;
__set_MSP(addr);
boot_jump(addr);
}
//extern byte USB_SaveData;
uint32 LenS,bw_se1;
byte ReadBINFileFlag=0;
#define SDRAM1788_RUN_ADDR 0xA1D00000    //使用的是w9825G6KH-6 32M bytes
unsigned char * RunAPPaddr;
void SaveData_USBHOST(uint8_t WriteFlag)
{
char acBuffer_USB[20];
char * pBuffer_USB;
char tempbuf[100];
char *tbuf;
uint32 i = 0,num = 0;
unsigned int writeedSize = 0;
Write_flag = WriteFlag;
if(!ReadBINFileFlag)
if(g_msEdBulkIn||g_msEdBulkOut)//识别到U盘插入后进行操作
{
  ress = f_open(&g_fileHandle_A, "0:ProjectNews.bin", FA_READ); //从U盘读取bin文件
        if(ress==FR_OK)
  {
   ReadBINFileFlag=1;
   RunAPPaddr=(unsigned char *)(SDRAM1788_RUN_ADDR);
   LenS=f_size(&g_fileHandle_A);
   ress = f_read(&g_fileHandle_A,RunAPPaddr, LenS, &bw_se1);
   ress=f_close(&g_fileHandle_A);
   ress = f_open(&g_fileHandle_A, "1:ProjectNews.bin", FA_WRITE|FA_OPEN_ALWAYS); //写入nandflash下次直接从nandflash启动
   res_O=f_write(&g_fileHandle_A,RunAPPaddr,num,&writeedSize);
   board_mpu_init();
   ExecuteUserCode(SDRAM1788_RUN_ADDR);
  }
}
if(!g_msEdBulkIn&&!g_msEdBulkOut)
{
  SaveCurveToUSBFlag=FALSE;
  offset1=0;
}


}
void board_mpu_init(void) //贴出一段MPU设置代码,此段代码是网上抄的,网上的资料真是少的可怜
{
MPU->RNR  = 0;//indicate MPU region 0
MPU->RBAR = 0x00000000; // update the base address for the region 0
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)//full access
      |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_512KB) //512Kb size
      |MPU_REGION_ENABLE;//region enable

   /* - Region 1: 0x10000000 - 0x1000FFFF --- on-chip SRAM
   *+ Size: 64kB
   *+ Access permission: full access
   */
MPU->RNR = 1;
MPU->RBAR = 0x10000000; // update the base address for the region 1
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
    |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_64KB)
    |MPU_REGION_ENABLE;
/* - Region 2: 0x40000000 - 0x400FFFFF --- APB peripheral
*+ Size: 1MB
*+ Access permission: full access
*/
MPU->RNR = 2;
MPU->RBAR = 0x40000000; // update the base address for the region 2
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
    |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_1MB)
    |MPU_REGION_ENABLE;
/* - Region 3: 0x20080000 - 0x200BFFFF --- AHB peripheral
*+ Size: 256KB
*+ AP=b011: full access
*/
MPU->RNR = 3;
MPU->RBAR = 0x20080000; // update the base address for the region 3
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
    |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_256KB)
    |MPU_REGION_ENABLE;
/* - Region 4: 0xE0000000 - 0xE00FFFFF --- System control
*+ Size: 1MB
*+ Access permission: full access
*/
MPU->RNR = 4;
MPU->RBAR = 0xE0000000; // update the base address for the region 4
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
    |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_1MB)
    |MPU_REGION_ENABLE;
/* - Region 5:0x20000000 - 0x20007FFF --- on chip SRAM
*+ Size: 32kB
*+ Access permission: full access
*/
MPU->RNR = 5;
MPU->RBAR = 0x20000000; // update the base address for the region 5
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
    |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_32KB)
    |MPU_REGION_ENABLE;
/* - Region 6:0xA0000000 - 0xA1000000 --- NorFlash
*+ Size: 16MB
*+ Access permission: full access
*/
MPU->RNR = 6;
MPU->RBAR = 0x90000000; // update the base address for the region 5
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
   |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_16MB)
   |MPU_REGION_ENABLE;
/* - Region 6:0xA0000000 - 0xA1000000 --- Ext SRAM
*+ Size: 16MB
*+ Access permission: full access
*/
MPU->RNR = 7;
MPU->RBAR = 0xA0000000; // update the base address for the region 5
MPU->RASR = MPU_RASR_ACCESS_PERMISSION(MPU_FULL_ACCESS)
   |MPU_RASR_REGION_SIZE(MPU_REGION_SIZE_16MB)
   |MPU_REGION_ENABLE;
SCB->SHCSR |=(1<<16);//Enable Memory management fault
MPU->CTRL =(1<<0);//Enable the MPU

////_DBG_("Setup MPU: \n\r"
////"This provide 6 regions: \n\r"
////"Region 0 - Privileged code: 0x00000000 - 0x0007FFFF(512kB)\n\r"
////"Region 1 - Privileged data: 0x10000000 - 0x1000FFFF(64kB)\n\r"
////"Region 2 - APB Peripheral:  0x40000000 - 0x400FFFFF(1MB)\n\r"
////"Region 3 - AHB peripheral:  0x20080000 - 0x200BFFFF(256KB)\n\r"
////"Region 4 - System control:  0xE0000000 - 0xE00FFFFF(1MB)\n\r"
//// "Region 5 - On-chip SRAM:  0x20000000 - 0x20007FFF(32kB)\n\r"
//// "Region 6 - Ext SRAM:   0xA0000000 - 0xA1000000(16MB)\n\r");
//
}
此帖出自NXP MCU论坛
点赞 关注
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表