1 | static void InitSDRAM(void) {
|
2 | /*
|
3 | * Configure the EBI port with 12 address lines, no address latches or
|
4 | * low pin count, and set it in SDRAM mode with 3-port EBI port.
|
5 | */
|
6 | ebi_setup_port(12, 0, 0, EBI_PORT_3PORT | EBI_PORT_SDRAM);
|
7 |
|
8 | /*
|
9 | * Configure the EBI chip select for an 8 MB SDRAM located at
|
10 | * \ref BOARD_EBI_SDRAM_BASE.
|
11 | */
|
12 | ebi_cs_set_mode(&cs_config, EBI_CS_MODE_SDRAM_gc);
|
13 | ebi_cs_set_address_size(&cs_config, EBI_CS_ASIZE_8MB_gc);
|
14 | ebi_cs_set_base_address(&cs_config, BOARD_EBI_SDRAM_BASE);
|
15 |
|
16 | /* Configure the EBI chip select to be in SDRAM mode. */
|
17 | ebi_sdram_set_mode(&cs_config, EBI_CS_SDMODE_NORMAL_gc);
|
18 |
|
19 | /* Setup the number of SDRAM rows and columns. */
|
20 | ebi_sdram_set_row_bits(&sdram_config, 12);
|
21 | ebi_sdram_set_col_bits(&sdram_config, 10);
|
22 |
|
23 | /* Further, setup the SDRAM timing. */
|
24 | ebi_sdram_set_cas_latency(&sdram_config, 3);
|
25 | ebi_sdram_set_mode_delay(&sdram_config, EBI_MRDLY_2CLK_gc);
|
26 | ebi_sdram_set_row_cycle_delay(&sdram_config, EBI_ROWCYCDLY_7CLK_gc);
|
27 | ebi_sdram_set_row_to_precharge_delay(&sdram_config, EBI_RPDLY_7CLK_gc);
|
28 | ebi_sdram_set_write_recovery_delay(&sdram_config, EBI_WRDLY_1CLK_gc);
|
29 | ebi_sdram_set_self_refresh_to_active_delay(&sdram_config,
|
30 | EBI_ESRDLY_7CLK_gc);
|
31 | ebi_sdram_set_row_to_col_delay(&sdram_config, EBI_ROWCOLDLY_7CLK_gc);
|
32 | ebi_sdram_set_refresh_period(&sdram_config, BOARD_EBI_SDRAM_REFRESH);
|
33 | ebi_sdram_set_initialization_delay(&sdram_config,
|
34 | BOARD_EBI_SDRAM_INITDLY);
|
35 |
|
36 | /* Write SDRAM configuration into the EBI registers. */
|
37 | ebi_sdram_write_config(&sdram_config);
|
38 | /* Write the chip select configuration into the EBI registers. */
|
39 | ebi_cs_write_config(EBI_SDRAM_CS, &cs_config);
|
40 |
|
41 | ebi_enable_cs(EBI_SDRAM_CS, &cs_config);
|
42 | do {
|
43 | // Wait for SDRAM to initialize.
|
44 | } while (!ebi_sdram_is_ready());
|
45 |
|
46 | /* Debug: Enable LED1: SDRAM is ready. */
|
47 | LED_PORT.OUTCLR = OLED1;
|
48 | _delay_ms(100);
|
49 | LED_PORT.OUTSET = OLED1;
|
50 | }
|