/*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:
"
////"This provide 6 regions:
"
////"Region 0 - Privileged code: 0x00000000 - 0x0007FFFF(512kB)
"
////"Region 1 - Privileged data: 0x10000000 - 0x1000FFFF(64kB)
"
////"Region 2 - APB Peripheral: 0x40000000 - 0x400FFFFF(1MB)
"
////"Region 3 - AHB peripheral: 0x20080000 - 0x200BFFFF(256KB)
"
////"Region 4 - System control: 0xE0000000 - 0xE00FFFFF(1MB)
"
//// "Region 5 - On-chip SRAM: 0x20000000 - 0x20007FFF(32kB)
"
//// "Region 6 - Ext SRAM: 0xA0000000 - 0xA1000000(16MB)
");
//
}
此帖出自
小平头技术问答
一周热门 更多>