DATAFLASH PAGES API test.
Toolkit:STM Development System
Location:/bipom/devtools/STM32/examples/nanoWipom/df_pages
#define WRITE_TEST // **************************************************************************** UCB uart0; DSCB dfDriver; UBYTE dfBuffer[DATAFLASH_PAGE_SIZE]; ERRCODE DFApiTest(void); // **************************************************************************** int main (void) { ERRCODE ec; /* Initialize all port pins */ NWDIO_Init(); delayMs(250); /* Initialize Device Manager */ DM_Init(); /* Initialize SPI1 and register to Device Manager */ SPI1_Init(SPI1_INTERFACE_TYPE,DEVICE_INTERFACE_IN_PROGRESS); /* Initialize UART0 */ uart0.baudRate = 115200; // uart baudrate uart0.parity = SERIALAPI_PARITY_NO; // uart parity uart0.stop = SERIALAPI_STOP_1; // uart stop bit uart0.word_length = SERIALAPI_WORLD_LENGTH_8; // uart word length uart0.rxFifo = SERIALAPI_FIFO_14; // uart RX FIFO trigger level uart0.txFifo = SERIALAPI_FIFO_14; // uart TX FIFO trigger level // NATIVE UART0 uart0.iface = SERIALAPI_UART1_INTERFACE; // interface // ec = serialAPI_init(&uart0); if(ec) { // Print the error using the standard 19200 serial channel tprintf("\r\nUART0 ERROR: ec =%d",ec); for (;;); } /* Send messages to TERMINAL window */ serialAPI_tiprintf(&uart0,"\r\nnanoWiPOM DF Pages Test VER 1.01"); serialAPI_tiprintf(&uart0,"\r\nUART0 init is OK"); // dfDriver.dataBuffer = dfBuffer; dfDriver.iface = DATASTORAGEAPI_SPI1_INTERFACE; dfDriver.clock = DATAFLASH_SPI_CLOCK; // SPI clock = 1MHz dataflash_spi1cs10_init(&dfDriver); if(ec) { serialAPI_tiprintf(&uart0,"\r\nERROR: DF INIT, ec=%d",ec); goto func_end; } serialAPI_tiprintf(&uart0,"\r\nDF init is OK"); /* Run the test */ serialAPI_tiprintf(&uart0,"\r\n>"); ec = DFApiTest(); func_end: tprintf("\r\nEND, ec =%d",ec); for(;;); return 0; } //******************************************************************************************** ERRCODE DFApiTest(void) { ERRCODE ec=SUCCESS; int dataInt=-1; int escape_cnt=0; UINT len; UINT dataFlashPage =0; DATAFLASH_STATUS dataFlashStatus; for (;;) { // try to get data byte from uart0 if (uart0.getRxCounter()) { dataInt = uart0.getData(); if(dataInt != -1 ) { // Check if(dataInt == '-') { if (++escape_cnt == 3) break; } else { escape_cnt =0; } // Print statistics if(dataInt == '?') { // Wait for 1ms to allow to get the data byte back // to show correct statistics delayMs(1); serialAPI_tiprintf(&uart0,"\n\rUART0: rx=%08lu tx=%08lu errors=%08lu overflows=%08lu", uart0.getRxCnt(),uart0.getTxCnt(),uart0.getErrors(),uart0.getOverflows()); serialAPI_tiprintf(&uart0,"\n\rDATAFLASH: rx=%08lu tx=%08lu errors=%08lu", dfDriver.getRxCnt(),dfDriver.getTxCnt(),dfDriver.getErrors()); serialAPI_tiprintf(&uart0,"\n\r"); continue; } #ifdef WRITE_TEST // WRITE NEXT PAGE for(len=0;len<DATAFLASH_PAGE_SIZE;len++) dfDriver.dataBuffer[len]= dataFlashPage & 0xFF; dfDriver.writePage(dataFlashPage); do{ dataFlashStatus = dfDriver.getStatus(); } while(DATAFLASH_BUSY == dataFlashStatus); serialAPI_tiprintf(&uart0,"\n\rDATAFLASH: status %d ",dataFlashStatus); // if (DATAFLASH_SUCCESS == dataFlashStatus) { serialAPI_tiprintf(&uart0,"\n\rDATAFLASH: page %d is written",dataFlashPage); } if (DATAFLASH_ERROR == dataFlashStatus) { serialAPI_tiprintf(&uart0,"\n\rDATAFLASH: page %d is NOT written",dataFlashPage); } #endif // READ NEXT PAGE for(len=0;len<DATAFLASH_PAGE_SIZE;len++) dfDriver.dataBuffer[len]= 0x00; dfDriver.readPage(dataFlashPage); do{dataFlashStatus = dfDriver.getStatus();} while(DATAFLASH_BUSY == dataFlashStatus); if (DATAFLASH_SUCCESS == dataFlashStatus) { serialAPI_tiprintf(&uart0,"\n\rDATAFLASH: page %d is read",dataFlashPage); for(len=0;len<DATAFLASH_PAGE_SIZE;len++) { if (!(len%16)) serialAPI_tiprintf(&uart0,"\n\r%04x",len); serialAPI_tiprintf(&uart0," %02X",dfDriver.dataBuffer[len]); } } if (DATAFLASH_ERROR == dataFlashStatus) serialAPI_tiprintf(&uart0,"\n\rDATAFLASH: page %d is NOT read",dataFlashPage); if(4095 < ++dataFlashPage) dataFlashPage=0; } } } return ec; }