void board_mpu_init(void)
{
/* - Region 0: 0x00000000 - 0x0007FFFF --- on-chip non-volatile memory
* + Size: 512kB
* + Acess permission: full access
*/
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_32MB)
|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");
//
}
__asm void JUMP_TO_APP(unsigned long address)
{
// __ASM("LDR SP, [R0] ;Load new stack pointer address");
// __ASM("LDR PC, [R0, #4] ;Load new program counter address");
LDR SP, [R0] ;Load new stack pointer address
LDR PC, [R0, #4] ;Load new program counter address
}
void board_jump_to_app(void)
{
//Copy target firmware to SDRAM
// memcpy((void *)SDRAM_BASE_ADDR,(void *)NOR_FLASH_BASE,NOR_FLASH_SIZE);
memcpy((void *)SDRAM_BASE_ADDR,(void *)0x0,0x80000);
__set_MSP(SDRAM_BASE_ADDR);
JUMP_TO_APP(SDRAM_BASE_ADDR);
}
int main(void)
{
SDRAMInit();//SDRAM驱动 board_mpu_init();
board_jump_to_app();
}
我在main函数中调用 board_jump_to_app函数,但是程序就一直停在这里 不会往下走了,各位大神帮帮忙,让程序运行在SDRAM中要如何实现
|