Exemple #1
0
/**************************************************************************//**
 * @brief Initialize the EBI interface for accessing the onboard nandflash.
 *
 * @note This function is not relevant for Gxxx_STK's.
 *
 * @return
 *   @ref BSP_STATUS_OK or @ref BSP_STATUS_NOT_IMPLEMENTED
 *****************************************************************************/
int BSP_EbiInit(void)
{
#if defined( BSP_STK_USE_EBI )
  /* ------------------------------------------ */
  /* NAND Flash, Bank0, Base Address 0x80000000 */
  /* Micron flash NAND256W3A                    */
  /* ------------------------------------------ */

  EBI_Init_TypeDef ebiConfig =
  {   ebiModeD8A8,       /* 8 bit address, 8 bit data */
      ebiActiveLow,      /* ARDY polarity */
      ebiActiveLow,      /* ALE polarity */
      ebiActiveLow,      /* WE polarity */
      ebiActiveLow,      /* RE polarity */
      ebiActiveLow,      /* CS polarity */
      ebiActiveLow,      /* BL polarity */
      false,             /* disble BL */
      true,              /* enable NOIDLE */
      false,             /* disable ARDY */
      true,              /* disable ARDY timeout */
      EBI_BANK0,         /* enable bank 0 */
      0,                 /* no chip select */
      0,                 /* addr setup cycles */
      0,                 /* addr hold cycles */
      false,             /* disable half cycle ALE strobe */
      0,                 /* read setup cycles */
      2,                 /* read strobe cycles */
      1,                 /* read hold cycles */
      false,             /* disable page mode */
      false,             /* disable prefetch */
      false,             /* disable half cycle REn strobe */
      0,                 /* write setup cycles */
      2,                 /* write strobe cycles */
      1,                 /* write hold cycles */
      false,             /* enable the write buffer */
      false,             /* disable half cycle WEn strobe */
      ebiALowA24,        /* ALB - Low bound, address lines */
      ebiAHighA26,       /* APEN - High bound, address lines */
      ebiLocation1,      /* Use Location 1 */
      true,              /* enable EBI */
  };

  /* Enable clocks */
  CMU_ClockEnable(cmuClock_HFPER, true);
  CMU_ClockEnable(cmuClock_GPIO, true);
  CMU_ClockEnable(cmuClock_EBI, true);

  /* Enable GPIO's */
  /* ALE and CLE */
  GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);

  /* WP, CE and R/B */
  GPIO_PinModeSet(gpioPortD, 13, gpioModePushPull, 0);   /* active low write-protect */
  GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1);   /* active low chip-enable */
  GPIO_PinModeSet(gpioPortD, 15, gpioModeInput, 0);      /* ready/busy */

  /* IO pins */
  GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);

  /* WE and RE */
  GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 1);
  GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 1);

  /* NAND Power Enable */
  GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);

  EBI_Init(&ebiConfig);
  EBI->NANDCTRL = (EBI_NANDCTRL_BANKSEL_BANK0 | EBI_NANDCTRL_EN);

  return BSP_STATUS_OK;
#else
  return BSP_STATUS_NOT_IMPLEMENTED;
#endif
}
Exemple #2
0
extern void ebi_init()
{
    EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;

    CMU_ClockEnable(cmuClock_EBI, true);
    CMU_ClockEnable(cmuClock_GPIO, true);


    /* --- Configure GPIO pins as push pull -------------------- */

    /* EBI AD9..15 */
    GPIO_PinModeSet( gpioPortA,  0, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA,  1, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA,  2, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA,  3, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA,  4, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA,  5, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA,  6, gpioModePushPull, 0 );

    /* EBI AD8 */
    GPIO_PinModeSet( gpioPortA, 15, gpioModePushPull, 0 );

    /* EBI A00-A06 */
    GPIO_PinModeSet( gpioPortA, 12, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA, 13, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortA, 14, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortB,  9, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortB, 10, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortC,  6, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortC,  7, gpioModePushPull, 0 );

    /* EBI A07-A14 */
    GPIO_PinModeSet( gpioPortE,  0, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE,  1, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortC,  9, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortC,  10, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE,  4, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE,  5, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE,  6, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE,  7, gpioModePushPull, 0 );

    /* EBI A15-A18 */
    GPIO_PinModeSet( gpioPortC,  8, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortB,  0, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortB,  1, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortB,  2, gpioModePushPull, 0 );

    /* EBI CS0-CS3 */
    GPIO_PinModeSet( gpioPortD,  9, gpioModePushPull, 1 );
//    GPIO_PinModeSet( gpioPortD, 11, gpioModePushPull, 1 );
//    GPIO_PinModeSet( gpioPortD, 12, gpioModePushPull, 1 );

    /* EBI AD0..7 */
    GPIO_PinModeSet( gpioPortE,  8, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE,  9, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE, 10, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE, 11, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE, 12, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE, 13, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE, 14, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortE, 15, gpioModePushPull, 0 );

    /* EBI ARDY/WEN/REN/ALE */
    GPIO_PinModeSet( gpioPortF,  2, gpioModeInput,    0 );
    GPIO_PinModeSet( gpioPortF,  8, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortF,  9, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortC, 11, gpioModePushPull, 0 );

    /* EBI Byte Lane 0 support BL0/BL1 */
    GPIO_PinModeSet( gpioPortF, 6, gpioModePushPull, 0 );
    GPIO_PinModeSet( gpioPortF, 7, gpioModePushPull, 0 );


    /* --------------------------------------------------------- */
    /* SRAM, Bank 0, Base Address 0x80000000  */
    /* --------------------------------------------------------- */
    ebiConfig.banks       = EBI_BANK0;
    ebiConfig.csLines     = EBI_CS0;
    ebiConfig.mode        = ebiModeD16;
    ebiConfig.alePolarity = ebiActiveHigh;
    ebiConfig.location    = ebiLocation1;
    /* keep blEnable */
    ebiConfig.blEnable     = false;
    ebiConfig.addrHalfALE  = false;
    ebiConfig.readPrefetch = false;
    ebiConfig.noIdle       = true;

    /* keep alow/ahigh configuration */
    ebiConfig.aLow = ebiALowA0;
    ebiConfig.aHigh = ebiAHighA19;

    /* set polarity to active low */
    ebiConfig.wePolarity = ebiActiveLow;
    ebiConfig.rePolarity = ebiActiveLow;

    /* Address Setup and hold time */
    ebiConfig.addrHoldCycles  = 3;
    ebiConfig.addrSetupCycles = 3;


    /* Read cycle times */
    ebiConfig.readStrobeCycles = 7;
    ebiConfig.readHoldCycles   = 3;
    ebiConfig.readSetupCycles  = 3;

    /* Write cycle times */
    ebiConfig.writeStrobeCycles = 7;
    ebiConfig.writeHoldCycles   = 3;
    ebiConfig.writeSetupCycles  = 3;

    /* Configure EBI bank 0 */
    EBI_Init(&ebiConfig);

}
/**************************************************************************//**
 * @brief Configure DK3x50 EBI (external bus interface) access for
 *    - 0x80000000: Board Control registers (Xilinx Spartan FPGA)
 *    - 0x84000000: TFT memory mapped drive (URT/SSD2119 controller)
 *    - 0x88000000: PSRAM external memory (Micron MT45W2MW16PGA-70 IT)
 *    - 0x8c000000: NOR flash (Spansion flash S29GLxxx_FBGA)
 * @return true if successful, false if board controller access failed
 *****************************************************************************/
static bool EbiInit(void)
{
  EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;

  /* Enable clocks */
  CMU_ClockEnable(cmuClock_EBI, true);
  CMU_ClockEnable(cmuClock_GPIO, true);

#if defined(_EFM32_GECKO_FAMILY)

  /* Configure LCD_SELECT (EBI and LCD cannot be shared) */
  GPIO_PinModeSet( gpioPortC, 12, gpioModePushPull, 1 );

  /* Configure GPIO pins as push pull */
  /* EBI AD9..15 */
  GPIO_PinModeSet( gpioPortA,  0, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  1, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  2, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  3, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  4, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  5, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  6, gpioModePushPull, 0 );

  /* EBI AD8 */
  GPIO_PinModeSet( gpioPortA, 15, gpioModePushPull, 0 );

  /* EBI CS0-CS3 */
  GPIO_PinModeSet( gpioPortD,  9, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortD, 10, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortD, 11, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortD, 12, gpioModePushPull, 1 );

  /* EBI AD0..7 */
  GPIO_PinModeSet( gpioPortE,  8, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE,  9, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 10, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 11, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 12, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 13, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 14, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 15, gpioModePushPull, 0 );

  /* EBI ARDY/ALEN/Wen/Ren */
  GPIO_PinModeSet( gpioPortF,  2, gpioModeInput,    0 );
  GPIO_PinModeSet( gpioPortF,  3, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortF,  4, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortF,  5, gpioModePushPull, 1 );

  /* Byte Lanes */
  GPIO_PinModeSet( gpioPortF,  6, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortF,  7, gpioModePushPull, 0 );

  /* Configure EBI controller, changing default values */
  ebiConfig.mode = ebiModeD16A16ALE;

  /* --------------------------------------------------------- */
  /* Board Control Registers, Bank 0, Base Address 0x80000000  */
  /* FPGA Xilinx Spartan XC6SLX9 CSG324                        */
  /* --------------------------------------------------------- */

  /* ----------------------------------------------------- */
  /* TFT-LCD Registers, Bank1, Base Address 0x84000000     */
  /* URT USMH_8252MD_320X240_RGB                           */
  /* Solomon Systech SSD 2119                              */
  /* ----------------------------------------------------- */

  /* ---------------------------------------------------- */
  /* External 4MB PSRAM, Bank 2, Base Address 0x88000000  */
  /* Micron MT45W2MW16PGA-70 IT, 32Mb Cellular RAM        */
  /* ---------------------------------------------------- */

  /* ----------------------------------------- */
  /* NOR Flash, Bank3, Base Address 0x8c000000 */
  /* Spansion flash S29GLxxx_FBGA              */
  /* ----------------------------------------- */

  ebiConfig.banks   = EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3;
  ebiConfig.csLines = EBI_CS0 | EBI_CS1 | EBI_CS2 | EBI_CS3;

  /* Address Setup and hold time */
  ebiConfig.addrHoldCycles  = 3;
  ebiConfig.addrSetupCycles = 3;

  /* Read cycle times */
  ebiConfig.readStrobeCycles = 7;
  ebiConfig.readHoldCycles   = 3;
  ebiConfig.readSetupCycles  = 3;

  /* Write cycle times */
  ebiConfig.writeStrobeCycles = 7;
  ebiConfig.writeHoldCycles   = 3;
  ebiConfig.writeSetupCycles  = 3;

  /* Address Latch Enable polarity is active high */
  ebiConfig.alePolarity = ebiActiveHigh;

  /* Configure EBI */
  EBI_Init(&ebiConfig);

#else

  /* Giant or Leopard family. */

  /* Configure GPIO pins as push pull */
  /* EBI AD9..15 */
  GPIO_PinModeSet( gpioPortA,  0, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  1, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  2, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  3, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  4, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  5, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortA,  6, gpioModePushPull, 0 );

  /* EBI AD8 */
  GPIO_PinModeSet( gpioPortA, 15, gpioModePushPull, 0 );

  /* EBI A16-A22 */
  GPIO_PinModeSet( gpioPortB,  0, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortB,  1, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortB,  2, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortB,  3, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortB,  4, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortB,  5, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortB,  6, gpioModePushPull, 0 );

  /* EBI CS0-CS3 */
  GPIO_PinModeSet( gpioPortD,  9, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortD, 10, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortD, 11, gpioModePushPull, 1 );
  GPIO_PinModeSet( gpioPortD, 12, gpioModePushPull, 1 );

  /* EBI AD0..7 */
  GPIO_PinModeSet( gpioPortE,  8, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE,  9, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 10, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 11, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 12, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 13, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 14, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortE, 15, gpioModePushPull, 0 );

  /* EBI ARDY/WEN/REN/ALE */
  GPIO_PinModeSet( gpioPortF,  2, gpioModeInput,    0 );
  GPIO_PinModeSet( gpioPortF,  8, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortF,  9, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortC, 11, gpioModePushPull, 0 );

  /* EBI Byte Lane 0 support BL0/BL1 */
  GPIO_PinModeSet( gpioPortF, 6, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortF, 7, gpioModePushPull, 0 );

  /* ---------------------------------------------------- */
  /* External 4MB PSRAM, Bank 2, Base Address 0x88000000  */
  /* Micron MT45W2MW16PGA-70 IT, 32Mb Cellular RAM        */
  /* ---------------------------------------------------- */
  ebiConfig.banks        = EBI_BANK2;
  ebiConfig.csLines      = EBI_CS2;
  ebiConfig.mode         = ebiModeD16A16ALE;
  ebiConfig.alePolarity  = ebiActiveHigh;
  ebiConfig.blEnable     = true;
  ebiConfig.noIdle       = true;
  ebiConfig.ardyEnable   = false;
  ebiConfig.addrHalfALE  = true;
  ebiConfig.readPrefetch = true;
  ebiConfig.aLow         = ebiALowA16;
  ebiConfig.aHigh        = ebiAHighA23;
  ebiConfig.location     = ebiLocation1;

  /* Address Setup and hold time */
  ebiConfig.addrHoldCycles  = 0;
  ebiConfig.addrSetupCycles = 0;

  /* Read cycle times */
  ebiConfig.readStrobeCycles = 4;
  ebiConfig.readHoldCycles   = 0;
  ebiConfig.readSetupCycles  = 0;

  /* Write cycle times */
  ebiConfig.writeStrobeCycles = 2;
  ebiConfig.writeHoldCycles   = 0;
  ebiConfig.writeSetupCycles  = 0;

  /* Configure EBI bank 2 - external PSRAM */
  EBI_Init(&ebiConfig);

  /* --------------------------------------------------------- */
  /* Board Control Registers, Bank 0, Base Address 0x80000000  */
  /* FPGA Xilinx Spartan XC6SLX9 CSG324                        */
  /* --------------------------------------------------------- */
  ebiConfig.banks       = EBI_BANK0;
  ebiConfig.csLines     = EBI_CS0;
  ebiConfig.mode        = ebiModeD16A16ALE;;
  ebiConfig.alePolarity = ebiActiveHigh;
  /* keep blEnable */
  ebiConfig.blEnable     = false;
  ebiConfig.addrHalfALE  = true;
  ebiConfig.readPrefetch = false;
  ebiConfig.noIdle       = true;

  /* keep alow/ahigh configuration */
  /* ebiConfig.aLow = ebiALowA0; - needs to be set for PSRAM */
  /* ebiConfig.aHigh = ebiAHighA0; - needs to be set for PSRAM */

  /* Address Setup and hold time */
  ebiConfig.addrHoldCycles  = 3;
  ebiConfig.addrSetupCycles = 3;

  /* Read cycle times */
  ebiConfig.readStrobeCycles = 7;
  ebiConfig.readHoldCycles   = 3;
  ebiConfig.readSetupCycles  = 3;

  /* Write cycle times */
  ebiConfig.writeStrobeCycles = 7;
  ebiConfig.writeHoldCycles   = 3;
  ebiConfig.writeSetupCycles  = 3;

  /* Configure EBI bank 0 */
  EBI_Init(&ebiConfig);

  /* ----------------------------------------------------- */
  /* TFT-LCD Registers, Bank1, Base Address 0x84000000     */
  /* URT USMH_8252MD_320X240_RGB                           */
  /* Solomon Systech SSD 2119                              */
  /* ----------------------------------------------------- */
  ebiConfig.banks   = EBI_BANK1;
  ebiConfig.csLines = EBI_CS1;

  /* Address Setup and hold time */
  ebiConfig.addrHoldCycles  = 1;
  ebiConfig.addrSetupCycles = 1;

  /* Read cycle times */
  ebiConfig.readStrobeCycles = 7;
  ebiConfig.readHoldCycles   = 3;
  ebiConfig.readSetupCycles  = 3;

  /* Write cycle times */
  ebiConfig.writeStrobeCycles = 2;
  ebiConfig.writeHoldCycles   = 1;
  ebiConfig.writeSetupCycles  = 1;

  /* Configure EBI bank 1 */
  EBI_Init(&ebiConfig);

  /* ----------------------------------------- */
  /* NOR Flash, Bank3, Base Address 0x8c000000 */
  /* Spansion flash S29GLxxx_FBGA              */
  /* ----------------------------------------- */
  ebiConfig.banks       = EBI_BANK3;
  ebiConfig.csLines     = EBI_CS3;
  ebiConfig.mode        = ebiModeD16A16ALE;
  ebiConfig.alePolarity = ebiActiveHigh;

  /* keep blEnable */
  ebiConfig.blEnable     = true;
  ebiConfig.addrHalfALE  = true;
  ebiConfig.readPrefetch = false;
  ebiConfig.noIdle       = true;

  /* Address Setup and hold time */
  ebiConfig.addrHoldCycles  = 0;
  ebiConfig.addrSetupCycles = 0;

  /* Read cycle times */
  ebiConfig.readStrobeCycles = 6;
  ebiConfig.readHoldCycles   = 0;
  ebiConfig.readSetupCycles  = 0;

  /* Write cycle times */
  ebiConfig.writeStrobeCycles = 5;
  ebiConfig.writeHoldCycles   = 0;
  ebiConfig.writeSetupCycles  = 0;

  /* Configure EBI bank 3 */
  EBI_Init(&ebiConfig);

  /* Enable extended address range */
  BSP_EbiExtendedAddressRange(true);
#endif

  /* Verify connectivity to Board Control registers */
  if (BC_REGISTER->MAGIC != 0xef32)
  {
    return false;
  }
  else
  {
    return true;
  }
}
int main(void)
{
  CHIP_Init();

  // Enable clocks
  CMU_ClockEnable(cmuClock_EBI, true);
  CMU_ClockEnable(cmuClock_GPIO, true);

  CMU_HFRCOBandSet(cmuHFRCOBand_28MHz);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Configure board. Select either EBI or SPI mode. */
  BSP_Init(BSP_INIT_DK_SPI);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  // EBI config
  EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;



  // Set EBI address pins PE[15:8]
  GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);

  // Set EBI data pins PA15 + PA[6:0]
  GPIO_PinModeSet(gpioPortA, 15, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 6, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 4, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);

  /* EBI ARDY/WEN/REN/ALE */
  GPIO_PinModeSet( gpioPortF,  2, gpioModeInput,    0 );
  GPIO_PinModeSet( gpioPortF,  8, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortF,  9, gpioModePushPull, 0 );
  GPIO_PinModeSet( gpioPortC, 11, gpioModePushPull, 0 );

  /* --------------------------------------------------------- */
  /* Second bank needs a name, Bank 0, Base Address 0x80000000 */
  /* --------------------------------------------------------- */
      ebiConfig.banks       = EBI_BANK0;
      ebiConfig.csLines     = EBI_CS1;
      ebiConfig.mode        = ebiModeD8A8;
      ebiConfig.alePolarity = ebiActiveHigh;
      ebiConfig.location    = ebiLocation1;
      /* keep blEnable */
      ebiConfig.blEnable     = false;
      ebiConfig.addrHalfALE  = false;
      ebiConfig.readPrefetch = false;
      ebiConfig.noIdle       = true;

      /* keep alow/ahigh configuration */
      ebiConfig.aLow = ebiALowA0;
      ebiConfig.aHigh = ebiAHighA18;

      /* Address Setup and hold time */
      ebiConfig.addrHoldCycles  = 3;
      ebiConfig.addrSetupCycles = 3;

      /* Read cycle times */
      ebiConfig.readStrobeCycles = 7;
      ebiConfig.readHoldCycles   = 3;
      ebiConfig.readSetupCycles  = 3;

      /* Write cycle times */
      ebiConfig.writeStrobeCycles = 7;
      ebiConfig.writeHoldCycles   = 3;
      ebiConfig.writeSetupCycles  = 3;

      /* Configure EBI bank 1 */
      EBI_Init(&ebiConfig);


  uint16_t *BANK0_BASE_ADDR = 0x80000000;
  uint16_t DATA = 0xF000;
  uint32_t cnt = 0;
		  *BANK0_BASE_ADDR = 0x1;
		  BSP_LedsSet(0xff00);
  while (1) {
	  //if(cnt > 500000){
		  *BANK0_BASE_ADDR = DATA;
		  BSP_LedsSet(DATA);
		  Delay(500);
	  //}else{
		  *BANK0_BASE_ADDR = 0x0000;
		  BSP_LedsSet(0x0000);
	  //}
		  Delay(500);
	  //if(cnt>1000000)
	//	  cnt=0;
	  //cnt++;

  }
}