Content originally posted in LPCWare by enyi on Sat Feb 15 10:05:54 MST 2014
Hi TheFallGuy
Thanks for replying so quickly
I have copied the code for initializing external SRAM ( 512KB X 8 bits) and writing a pixel to the frame buffer at 0x1C000000 .
void init_SRAM (void)
{
// External Memory Controller Definitions
/*----------------------------------------------------------------------------*/
uint32_t *ptr;
uint32_t *ptrdata;
/*----------------------------------------------------------------------------
Initialize external memory controller
*----------------------------------------------------------------------------*/
/* Select and enable EMC branch clock */
// CLK_M3_EMC_CFG is connect to BASE_M3_CLK (PPL1 180MHZ) to used only with SRAM
LPC_CCU1->CLK_M3_EMC_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN;
while (!(LPC_CCU1->CLK_M3_EMC_STAT & CCU_CLK_STAT_RUN))
/* Configure EMC port pins */
scu_pinmux(0x1,0,MD_PLN_FAST,FUNC2); /* P1_0: A5 */
scu_pinmux(0x1,1,MD_PLN_FAST,FUNC2); /* P1_1: A6 */
scu_pinmux(0x1,2,MD_PLN_FAST,FUNC2); /* P1_2: A7 */
scu_pinmux(0x1,3,MD_PLN_FAST,FUNC3); /* P1_3: OE */
//scu_pinmux(0x1,4,MD_PLN_FAST,FUNC3); /* P1_4: BLS0 */
scu_pinmux(0x1,5,MD_PLN_FAST,FUNC3); /* P1_5: CS0 */
scu_pinmux(0x1,6,MD_PLN_FAST,FUNC3); /* P1_6: WE */
scu_pinmux(0x1,7,MD_PLN_FAST,FUNC3); /* P1_7: D0 */
scu_pinmux(0x1,8,MD_PLN_FAST,FUNC3); /* P1_8: D1 */
scu_pinmux(0x1,9,MD_PLN_FAST,FUNC3); /* P1_9: D2 */
scu_pinmux(0x1,10,MD_PLN_FAST,FUNC3); /* P1_10: D3 */
scu_pinmux(0x1,11,MD_PLN_FAST,FUNC3); /* P1_11: D4 */
scu_pinmux(0x1,12,MD_PLN_FAST,FUNC3); /* P1_12: D5 */
scu_pinmux(0x1,13,MD_PLN_FAST,FUNC3); /* P1_13: D6 */
scu_pinmux(0x1,14,MD_PLN_FAST,FUNC3); /* P1_14: D7 */
scu_pinmux(0x2,0,MD_PLN_FAST,FUNC2); /* P2_0: A13 */
scu_pinmux(0x2,1,MD_PLN_FAST,FUNC2); /* P2_1: A12 */
scu_pinmux(0x2,2,MD_PLN_FAST,FUNC2); /* P2_2: A11 */
scu_pinmux(0x2,6,MD_PLN_FAST,FUNC2); /* P2_6: A10 */
scu_pinmux(0x2,7,MD_PLN_FAST,FUNC3); /* P2_7: A9 */
scu_pinmux(0x2,8,MD_PLN_FAST,FUNC3); /* P2_8: A8 */
scu_pinmux(0x2,9,MD_PLN_FAST,FUNC3); /* P2_9: A0 */
scu_pinmux(0x2,10,MD_PLN_FAST,FUNC3); /* P2_10: A1 */
scu_pinmux(0x2,11,MD_PLN_FAST,FUNC3); /* P2_11: A2 */
scu_pinmux(0x2,12,MD_PLN_FAST,FUNC3); /* P2_12: A3 */
scu_pinmux(0x2,13,MD_PLN_FAST,FUNC3); /* P2_13: A4 */
scu_pinmux(0x6,7,MD_PLN_FAST,FUNC1); /* P6_7: A15 */
scu_pinmux(0x6,8,MD_PLN_FAST,FUNC1); /* P6_8: A14 */
scu_pinmux(0xd,15,MD_PLN_FAST,FUNC2); /* PD_15: A17 */
scu_pinmux(0xd,16,MD_PLN_FAST,FUNC2); /* PD_16: A16 */
scu_pinmux(0xe,0,MD_PLN_FAST,FUNC3); /* PE_0: A18 */
LPC_EMC->CONTROL = 0x00000001; /* EMC Enable */
LPC_EMC->CONFIG = 0x00000000; /* Little-endian, Clock Ratio 1:1 */
/* Static memory configuration (chip select 0) */
LPC_EMC->STATICCONFIG0 =
(0 << 0) | // MW [1:0] = 0 (8 bit Memeory Width)
(0 << 3) | // PM = 0 Page Mode disabled
(0 << 6) | // PC = 0 Active Low Chip Select
(1 << 7) | // PB = 1 Byte lane state (All BLS High for Read / Must be 1 to use WE signal
(0 << 8) | // EW = 0 Disabled extended wait
(0 << 19)| // B = 0 Disabled Buffer
(0 << 20) ; // P = 0 Disabled Write Protect
LPC_EMC->STATICWAITOEN0 = 0x1 ; // 1 NO Delay (Selects the delay from chip select n or address change, whichever is later, to output enable)
LPC_EMC->STATICWAITWEN0 = 0x0 ; // 0 1 EMC_CCLK Cylce delay (180MZ = 5.55r ns) (Selects the delay from chip select n to write enable.)
LPC_EMC->STATICWAITRD0 = 0x4 ; // 4 EMC_CCLK Cylce delay (180MZ = 5.55r ns) (Selects the delay from chip select n to a read access)
LPC_EMC->STATICWAITPAG0 = 0x0 ; // 0 Page Mode Previously disabled (180MZ = 5.55r ns) (Selects the delay for asynchronous page mode sequential accesses for chip select n.)
LPC_EMC->STATICWAITWR0 = 0x4 ; // 0x4 4 EMC_CCLK Cylce delay (180MZ = 5.55r ns * 4) (Selects the delay from chip select n to a write access.)
LPC_EMC->STATICWAITTURN0 = 0x4 ; // 0 1 EMC_CCLK Cylce (180MZ = 5.55r ns) (Selects bus turnaround cycles.)
}
#define BASE_ADDR 0x1C000000 // 2Mb (512K x 8bit) SRAM
LPC_LCD->UPBASE = BASE_ADDR; // Set upper base address to SRAM base address
putpixel(100, 100,GuiConst_PIXEL_ON);
uint8_t *fbptr8bit = (uint8_t *)BASE_ADDR;
/************************ Local auxiliary functions ***************************/
void putpixel(uint32_t x, uint32_t y, uint32_t val){
//fbptr[x+y*480] = (uint32_t) 0x00000000;
uint32_t i;
uint32_t j;
fbptr = (uint32_t *) BASE_ADDR;
fbptr8bit = (uint8_t *) BASE_ADDR;
for(j=0;j<480*y;j++){
fbptr8bit++;
fbptr8bit++;
fbptr8bit++;
fbptr8bit++;
}
for(i=0;i<x;i++){
fbptr8bit++;
fbptr8bit++;
fbptr8bit++;
fbptr8bit++;
}
*fbptr8bit++ = (uint8_t) 0x00;
*fbptr8bit++ = (uint8_t) 0x00;
*fbptr8bit++ = (uint8_t) 0x00;
*fbptr8bit++ = (uint8_t) 0x00;
}