/******************************************************************************/ | |
/* LPC43XX-FLASH-DEBUG.INI: External Memory Interface initialization for */ | |
/* LPC43xx first revision (Sept 2011). */ | |
/* The purpose is to be able to debug a program */ | |
/* located in the external flash. */ | |
/******************************************************************************/ | |
FUNC void Pre_Setup (void) { | |
/* configure M0 for infinite loop */ | |
_WDWORD(0x10080000,0x00001F00); /* dummy stack pointer */ | |
_WDWORD(0x10080004,0x000000D5); /* reset handler */ | |
_WDWORD(0x100800D4,0xE7FEE7FE); /* jump to itself instruction for M0a */ | |
_WDWORD(0x40043404,0x10080000); /* M0 shadow pointer. */ | |
/* release M0 from reset to allow Jtag access */ | |
_WDWORD(0x40053104,(~(_RDWORD(0x40053154))) & (~(1<<24))); | |
// u32Val = (~(u32REG) & (~(1 << 24))); // clear the control bit | |
// LPC_RGU->RESET_CTRL1 = (~( LPC_RGU->RESET_ACTIVE_STATUS1 )) & (0 << 24); //Release M0 | |
} | |
FUNC void Setup (void) | |
{ | |
// With the values used here, the program had to be linked to CS0 memory | |
// located at 0x1C000000 in the LPC43xx. | |
/* This would be used in case there is a 16-byte header in the image */ | |
/* | |
SP = _RDWORD(0x1c000100); // Setup Stack Pointer | |
PC = _RDWORD(0x1C000104); // Setup Program Counter | |
_WDWORD(0xE000ED08, 0x1C000100); // Setup Vector Table Offset Register | |
*/ | |
/* This is used for plain images, without a 16-byte header */ | |
SP = _RDWORD(0x1C000000); // Setup Stack Pointer | |
PC = _RDWORD(0x1C000004); // Setup Program Counter | |
_WDWORD(0xE000ED08, 0x1C000000); // Setup Vector Table Offset Register | |
} | |
FUNC void emc_setup (void) | |
{ | |
// bus signals for external memory | |
_WDWORD(0x4008609C, 0x000000F3); /* P1_7: D0 (function 3) */ | |
_WDWORD(0x400860A0, 0x000000F3); /* P1_8: D1 (function 3) */ | |
_WDWORD(0x400860A4, 0x000000F3); /* P1_9: D2 (function 3) */ | |
_WDWORD(0x400860A8, 0x000000F3); /* P1_10: D3 (function 3) */ | |
_WDWORD(0x400860AC, 0x000000F3); /* P1_11: D4 (function 3) */ | |
_WDWORD(0x400860B0, 0x000000F3); /* P1_12: D5 (function 3) */ | |
_WDWORD(0x400860B4, 0x000000F3); /* P1_13: D6 (function 3) */ | |
_WDWORD(0x400860B8, 0x000000F3); /* P1_14: D7 (function 3) */ | |
_WDWORD(0x40086280, 0x000000F2); /* P5_0: D12 (function 2) */ | |
_WDWORD(0x40086284, 0x000000F2); /* P5_1: D13 (function 2) */ | |
_WDWORD(0x40086288, 0x000000F2); /* P5_2: D14 (function 2) */ | |
_WDWORD(0x4008628C, 0x000000F2); /* P5_3: D15 (function 2) */ | |
_WDWORD(0x40086290, 0x000000F2); /* P5_4: D8 (function 2) */ | |
_WDWORD(0x40086294, 0x000000F2); /* P5_5: D9 (function 2) */ | |
_WDWORD(0x40086298, 0x000000F2); /* P5_6: D10 (function 2) */ | |
_WDWORD(0x4008629C, 0x000000F2); /* P5_7: D11 (function 2) */ | |
_WDWORD(0x40086688, 0x000000F2); /* PD_2: D16 (function 2) */ | |
_WDWORD(0x4008668C, 0x000000F2); /* PD_3: D17 (function 2) */ | |
_WDWORD(0x40086690, 0x000000F2); /* PD_4: D18 (function 2) */ | |
_WDWORD(0x40086694, 0x000000F2); /* PD_5: D19 (function 2) */ | |
_WDWORD(0x40086698, 0x000000F2); /* PD_6: D20 (function 2) */ | |
_WDWORD(0x4008669C, 0x000000F2); /* PD_7: D21 (function 2) */ | |
_WDWORD(0x400866A0, 0x000000F2); /* PD_8: D22 (function 2) */ | |
_WDWORD(0x400866A4, 0x000000F2); /* PD_9: D23 (function 2) */ | |
_WDWORD(0x40086714, 0x000000F3); /* PE_5: D24 (function 3) */ | |
_WDWORD(0x40086718, 0x000000F3); /* PE_6: D25 (function 3) */ | |
_WDWORD(0x4008671C, 0x000000F3); /* PE_7: D26 (function 3) */ | |
_WDWORD(0x40086720, 0x000000F3); /* PE_8: D27 (function 3) */ | |
_WDWORD(0x40086724, 0x000000F3); /* PE_9: D28 (function 3) */ | |
_WDWORD(0x40086728, 0x000000F3); /* PE_10: D29 (function 3) */ | |
_WDWORD(0x4008672C, 0x000000F3); /* PE_11: D30 (function 3) */ | |
_WDWORD(0x40086730, 0x000000F3); /* PE_12: D31 (function 3) */ | |
_WDWORD(0x40086124, 0x000000F3); /* P2_9: A0 (function 3) */ | |
_WDWORD(0x40086128, 0x000000F3); /* P2_10: A1 (function 3) */ | |
_WDWORD(0x4008612C, 0x000000F3); /* P2_11: A2 (function 3) */ | |
_WDWORD(0x40086130, 0x000000F3); /* P2_12: A3 (function 3) */ | |
_WDWORD(0x40086134, 0x000000F3); /* P2_13: A4 (function 3) */ | |
_WDWORD(0x40086080, 0x000000F2); /* P1_0: A5 (function 2) */ | |
_WDWORD(0x40086084, 0x000000F2); /* P1_1: A6 (function 2) */ | |
_WDWORD(0x40086088, 0x000000F2); /* P1_2: A7 (function 2) */ | |
_WDWORD(0x40086120, 0x000000F3); /* P2_8: A8 (function 3) */ | |
_WDWORD(0x4008611C, 0x000000F3); /* P2_7: A9 (function 3) */ | |
_WDWORD(0x40086118, 0x000000F2); /* P2_6: A10 (function 2) */ | |
_WDWORD(0x40086108, 0x000000F2); /* P2_2: A11 (function 2) */ | |
_WDWORD(0x40086104, 0x000000F2); /* P2_1: A12 (function 2) */ | |
_WDWORD(0x40086100, 0x000000F2); /* P2_0: A13 (function 2) */ | |
_WDWORD(0x40086320, 0x000000F1); /* P6_8: A14 (function 1) */ | |
_WDWORD(0x4008631C, 0x000000F1); /* P6_7: A15 (function 1) */ | |
_WDWORD(0x400866C0, 0x000000F2); /* PD_16: A16 (function 2) */ | |
_WDWORD(0x400866BC, 0x000000F2); /* PD_15: A17 (function 2) */ | |
_WDWORD(0x40086700, 0x000000F3); /* PE_0: A18 (function 3) */ | |
_WDWORD(0x40086704, 0x000000F3); /* PE_1: A19 (function 3) */ | |
_WDWORD(0x40086708, 0x000000F3); /* PE_2: A20 (function 3) */ | |
_WDWORD(0x4008670C, 0x000000F3); /* PE_3: A21 (function 3) */ | |
_WDWORD(0x40086710, 0x000000F3); /* PE_4: A22 (function 3) */ | |
// control signals for static memory | |
_WDWORD(0x40086094, 0x000000F3); /* P1_5: CS0 (function 3) */ | |
_WDWORD(0x400866B0, 0x000000F2); /* PD_12: CS2 (function 2) */ | |
_WDWORD(0x40086098, 0x000000F3); /* P1_6: WE (function 3) */ | |
_WDWORD(0x4008608C, 0x000000F3); /* P1_3: OE (function 3) */ | |
_WDWORD(0x40086090, 0x000000F3); /* P1_4: BLS0 (function 3) */ | |
_WDWORD(0x40086318, 0x000000F1); /* P6_6: BLS1 (function 1) */ | |
// configure EMC static memory registers | |
_WDWORD(0x40005000, 0x00000001); /* Enable the EMC block */ | |
_WDWORD(0x40005200, 0x00000081); /* CS0: 16 bit, WE */ | |
_WDWORD(0x40005208, 0x00000000); /* CS0: WAITOEN = 0 */ | |
_WDWORD(0x4000520C, 0x00000008); /* CS0: WAITRD = 8 @120MHz for 70ns flash */ | |
_WDWORD(0x40005240, 0x00000081); /* CS2: 16 bit, WE */ | |
_WDWORD(0x40005248, 0x00000000); /* CS2: WAITOEN = 0 */ | |
_WDWORD(0x4000524C, 0x00000007); /* CS2: WAITRD = 7 */ | |
} | |
/******************************************************************************/ | |
/* */ | |
/* */ | |
/* */ | |
/******************************************************************************/ | |
_sleep_(100); | |
//Pre_setup(); | |
// Just set up the memory interface to enable the correct access to the external | |
// flash memory on CS0. | |
emc_setup(); | |
// Download the image. This is not a physical download as the image is | |
// (already) in the flash. | |
// If working with ULINK devices an alternative is to check the checkbox "Load Application at Startup" in the | |
// debug settings of µVision (comment the LOAD instruction out). | |
// This mechanism is not used here, because somehow it does not work with the JLINK devices. | |
LOAD Flash\LPC43xx_M4_FLASH.axf INCREMENTAL | |
// Setup for running from a specific memory location | |
Setup(); | |