/***************************************************************************//** * @brief * Set WRITE ENABLE, Clear UART Tx Buffer, Get Status * ******************************************************************************/ void write_enable(void) { printf("setting write enable\r\n"); serial_tx_flush(); spiflash_set_write_enable(true, NULL, NULL); printf("write enabled\r\n"); serial_tx_flush(); get_status(); }
/***************************************************************************//** * @brief * Read Status Register of Device, Clear UART Tx Buffer * ******************************************************************************/ void get_status(void) { uint8_t status[2]; spiflash_read_status(2, status, NULL, NULL); printf("status = %02x %02x\r\n", status[0], status[1]); serial_tx_flush(); }
/*! It will never return */ static int do_testhw_watchdog_reset( int argc, char* argv[] ) { printf( "Resetting system\n" ); serial_tx_flush(); TriggerWatchdogResetAndWait(); /* never reached */ return 0; }
/***************************************************************************//** * @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(); }