/* Initialize nand flash access */ hndsflash_t * hndsflash_init(si_t *sih) { uint32 origidx; ASSERT(sih); /* Already initialized ? */ if (hndsflash) return hndsflash; /* spin lock here */ origidx = si_coreidx(sih); #ifdef __mips__ if (!hndsflash) hndsflash = ccsflash_init(sih); #endif /* __mips__ */ #ifdef __ARM_ARCH_7A__ if (!hndsflash) hndsflash = spiflash_init(sih); #endif /* __ARM_ARCH_7A__ */ si_setcoreidx(sih, origidx); return hndsflash; }
int main(int argc, char **argv) { /* initialize interrupt handling */ VIDEOIF->flags = 0; IRQController->Enable = IRQ_FLAG_VSYNC | IRQ_FLAG_PAD | IRQ_FLAG_GLOBALEN; VIDEOIF->settings = VIDEOIF_SET_CABLEDETECT; // temporary during init /* run initializations */ settings_init(); osd_init(); spiflash_init(); VIDEOIF->settings = video_settings[current_videomode]; VIDEOIF->osd_bg = osdbg_settings; while (1) { screen_idle(); screen_mainmenu(); } }
/***************************************************************************//** * @brief * Serial Output Demo, Prints out Data Wrote and Read back from Device * ******************************************************************************/ void demo_serial(void) { int i; int hex_dump_size = 256; CMU_ClockEnable(cmuClock_CORELE, true); CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO); CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO); serial_init(9600, raw_serial_rx_buf, sizeof(raw_serial_rx_buf), raw_serial_tx_buf, sizeof(raw_serial_tx_buf)); printf("\r\nEmbedded Masters SPI Flash Demo\r\n"); if (! spiflash_init(2000000)) { printf("SPI flash failed to initialize\r\n"); while(true) ; } get_status(); printf("reading\r\n"); spiflash_read(0x00000, sizeof(buf1), buf1, NULL, NULL); printf("read done\r\n"); serial_tx_flush(); printf("data read"); if (hex_dump_size != sizeof(buf1)) printf(", first %d bytes", hex_dump_size); printf (":\r\n"); hex_dump(buf1, hex_dump_size, 0); serial_tx_flush(); printf("erasing\r\n"); spiflash_erase(0x00000, sizeof(buf1), 0, true, NULL, NULL); printf("erase done\r\n"); serial_tx_flush(); get_status(); printf("setting buffer to increment from %02x\r\n", buf1[0]+1); buf2[0]++; for (i = 1; i < sizeof(buf2); i++) buf2[i] = buf2[i-1] + 1; serial_tx_flush(); write_enable(); printf("setting sector unprotect\r\n"); spiflash_set_sector_protection(false, 0x00000, NULL, NULL); get_status(); printf("writing\r\n"); serial_tx_flush(); spiflash_write(0x00000, sizeof(buf2), buf2, true, NULL, NULL); printf("write done\r\n"); serial_tx_flush(); get_status(); printf("reading\r\n"); serial_tx_flush(); spiflash_read(0x00000, sizeof(buf3), buf3, NULL, NULL); printf("read done\r\n"); serial_tx_flush(); printf("data read"); if (hex_dump_size != sizeof(buf1)) printf(", first %d bytes", hex_dump_size); printf (":\r\n"); serial_tx_flush(); hex_dump(buf3, hex_dump_size, 0); spiflash_ultra_deep_power_down(true, NULL, NULL); serial_tx_flush(); serial_close(); }