1 /*----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support - ROUSSET -
3 *----------------------------------------------------------------------------
4 * The software is delivered "AS IS" without warranty or condition of any
5 * kind, either express, implied or statutory. This includes without
6 * limitation any warranty or condition with respect to merchantability or
7 * fitness for any particular purpose, or against the infringements of
8 * intellectual property rights of others.
9 *----------------------------------------------------------------------------
13 * 1.0 10/12/03 HIi : Creation.
14 * 1.01 03/05/04 HIi : Bug Fix in AT91F_DataFlashWaitReady() Function.
15 *----------------------------------------------------------------------------
19 #include "AT91RM9200.h"
20 #include "lib_AT91RM9200.h"
21 #include "dataflash.h"
25 /*----------------------------------------------------------------------------*/
26 /* \fn AT91F_SpiInit */
27 /* \brief SPI Low level Init */
28 /*----------------------------------------------------------------------------*/
29 void AT91F_SpiInit(void) {
31 AT91C_BASE_PIOA->PIO_ASR = AT91C_PA3_NPCS0 | AT91C_PA4_NPCS1 |
32 AT91C_PA1_MOSI | AT91C_PA5_NPCS2 |
33 AT91C_PA6_NPCS3 | AT91C_PA0_MISO |
35 AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_NPCS0 | AT91C_PA4_NPCS1 |
36 AT91C_PA1_MOSI | AT91C_PA5_NPCS2 |
37 AT91C_PA6_NPCS3 | AT91C_PA0_MISO |
40 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_SPI;
43 AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SWRST;
45 /* Configure SPI in Master Mode with No CS selected !!! */
46 AT91C_BASE_SPI->SPI_MR = AT91C_SPI_MSTR | AT91C_SPI_MODFDIS | AT91C_SPI_PCS;
48 /* Configure CS0 and CS3 */
49 *(AT91C_SPI_CSR + 0) = AT91C_SPI_CPOL | (AT91C_SPI_DLYBS & DATAFLASH_TCSS) |
50 (AT91C_SPI_DLYBCT & DATAFLASH_TCHS) |
51 ((AT91C_MASTER_CLOCK / (2*AT91C_SPI_CLK)) << 8);
52 *(AT91C_SPI_CSR + 3) = AT91C_SPI_CPOL | (AT91C_SPI_DLYBS & DATAFLASH_TCSS) |
53 (AT91C_SPI_DLYBCT & DATAFLASH_TCHS) |
54 ((AT91C_MASTER_CLOCK / (2*AT91C_SPI_CLK)) << 8);
58 /*----------------------------------------------------------------------------*/
59 /* \fn AT91F_SpiEnable */
60 /* \brief Enable SPI chip select */
61 /*----------------------------------------------------------------------------*/
62 static void AT91F_SpiEnable(int cs) {
64 case 0: /* Configure SPI CS0 for Serial DataFlash AT45DBxx */
65 AT91C_BASE_SPI->SPI_MR &= 0xFFF0FFFF;
66 AT91C_BASE_SPI->SPI_MR |= ((AT91C_SPI_PCS0_SERIAL_DATAFLASH << 16) & AT91C_SPI_PCS);
68 case 3: /* Configure SPI CS3 for Serial DataFlash Card */
69 /* Set up PIO SDC_TYPE to switch on DataFlash Card and not MMC/SDCard */
70 AT91C_BASE_PIOB->PIO_PER = AT91C_PIO_PB7; /* Set in PIO mode */
71 AT91C_BASE_PIOB->PIO_OER = AT91C_PIO_PB7; /* Configure in output */
73 AT91C_BASE_PIOB->PIO_CODR = AT91C_PIO_PB7;
75 AT91C_BASE_SPI->SPI_MR &= 0xFFF0FFFF;
76 AT91C_BASE_SPI->SPI_MR |= ((AT91C_SPI_PCS3_DATAFLASH_CARD<<16) & AT91C_SPI_PCS);
81 AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIEN;
84 /*----------------------------------------------------------------------------*/
85 /* \fn AT91F_SpiWrite */
86 /* \brief Set the PDC registers for a transfert */
87 /*----------------------------------------------------------------------------*/
88 static unsigned int AT91F_SpiWrite(AT91PS_DataflashDesc pDesc)
92 AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTDIS + AT91C_PDC_RXTDIS;
94 /* Initialize the Transmit and Receive Pointer */
95 AT91C_BASE_SPI->SPI_RPR = (unsigned int)pDesc->rx_cmd_pt ;
96 AT91C_BASE_SPI->SPI_TPR = (unsigned int)pDesc->tx_cmd_pt ;
98 /* Intialize the Transmit and Receive Counters */
99 AT91C_BASE_SPI->SPI_RCR = pDesc->rx_cmd_size;
100 AT91C_BASE_SPI->SPI_TCR = pDesc->tx_cmd_size;
102 if ( pDesc->tx_data_size != 0 ) {
103 /* Initialize the Next Transmit and Next Receive Pointer */
104 AT91C_BASE_SPI->SPI_RNPR = (unsigned int)pDesc->rx_data_pt ;
105 AT91C_BASE_SPI->SPI_TNPR = (unsigned int)pDesc->tx_data_pt ;
107 /* Intialize the Next Transmit and Next Receive Counters */
108 AT91C_BASE_SPI->SPI_RNCR = pDesc->rx_data_size ;
109 AT91C_BASE_SPI->SPI_TNCR = pDesc->tx_data_size ;
112 /* ARM simple, non interrupt dependent timer */
115 AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTEN + AT91C_PDC_RXTEN;
116 while(!(AT91C_BASE_SPI->SPI_SR & AT91C_SPI_RXBUFF));
118 AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTDIS + AT91C_PDC_RXTDIS;
120 if (timeout >= AT91C_DATAFLASH_TIMEOUT){
121 return AT91C_DATAFLASH_ERROR;
124 return AT91C_DATAFLASH_OK;
128 /*----------------------------------------------------------------------*/
129 /* \fn AT91F_DataFlashSendCommand */
130 /* \brief Generic function to send a command to the dataflash */
131 /*----------------------------------------------------------------------*/
132 static AT91S_DataFlashStatus AT91F_DataFlashSendCommand(
133 AT91PS_DataFlash pDataFlash,
134 unsigned char OpCode,
135 unsigned int CmdSize,
136 unsigned int DataflashAddress)
140 /* process the address to obtain page address and byte address */
141 adr = ((DataflashAddress / (pDataFlash->pDevice->pages_size))
142 << pDataFlash->pDevice->page_offset) +
143 (DataflashAddress % (pDataFlash->pDevice->pages_size));
145 /* fill the command buffer */
146 pDataFlash->pDataFlashDesc->command[0] = OpCode;
147 if (pDataFlash->pDevice->pages_number >= 16384)
149 pDataFlash->pDataFlashDesc->command[1] = (unsigned char)((adr & 0x0F000000) >> 24);
150 pDataFlash->pDataFlashDesc->command[2] = (unsigned char)((adr & 0x00FF0000) >> 16);
151 pDataFlash->pDataFlashDesc->command[3] = (unsigned char)((adr & 0x0000FF00) >> 8);
152 pDataFlash->pDataFlashDesc->command[4] = (unsigned char)(adr & 0x000000FF);
156 pDataFlash->pDataFlashDesc->command[1] = (unsigned char)((adr & 0x00FF0000) >> 16);
157 pDataFlash->pDataFlashDesc->command[2] = (unsigned char)((adr & 0x0000FF00) >> 8);
158 pDataFlash->pDataFlashDesc->command[3] = (unsigned char)(adr & 0x000000FF) ;
159 pDataFlash->pDataFlashDesc->command[4] = 0;
161 pDataFlash->pDataFlashDesc->command[5] = 0;
162 pDataFlash->pDataFlashDesc->command[6] = 0;
163 pDataFlash->pDataFlashDesc->command[7] = 0;
165 /* Initialize the SpiData structure for the spi write fuction */
166 pDataFlash->pDataFlashDesc->tx_cmd_pt = pDataFlash->pDataFlashDesc->command ;
167 pDataFlash->pDataFlashDesc->tx_cmd_size = CmdSize ;
168 pDataFlash->pDataFlashDesc->rx_cmd_pt = pDataFlash->pDataFlashDesc->command ;
169 pDataFlash->pDataFlashDesc->rx_cmd_size = CmdSize ;
171 return AT91F_SpiWrite(pDataFlash->pDataFlashDesc);
175 /*----------------------------------------------------------------------*/
176 /* \fn AT91F_DataFlashGetStatus */
177 /* \brief Read the status register of the dataflash */
178 /*----------------------------------------------------------------------*/
179 static AT91S_DataFlashStatus AT91F_DataFlashGetStatus(AT91PS_DataflashDesc pDesc)
181 AT91S_DataFlashStatus status;
183 /* first send the read status command (D7H) */
184 pDesc->command[0] = DB_STATUS;
185 pDesc->command[1] = 0;
187 pDesc->DataFlash_state = GET_STATUS;
188 pDesc->tx_data_size = 0 ; /* Transmit the command and receive response */
189 pDesc->tx_cmd_pt = pDesc->command ;
190 pDesc->rx_cmd_pt = pDesc->command ;
191 pDesc->rx_cmd_size = 2 ;
192 pDesc->tx_cmd_size = 2 ;
193 status = AT91F_SpiWrite (pDesc);
195 pDesc->DataFlash_state = *( (unsigned char *) (pDesc->rx_cmd_pt) +1);
199 /*-----------------------------------------------------------------------------
200 * Function Name : AT91F_DataFlashWaitReady
201 * Object : wait for dataflash ready (bit7 of the status register == 1)
202 * Input Parameters : DataFlash Service and timeout
203 * Return value : DataFlash status "ready or not"
204 *-----------------------------------------------------------------------------
206 static AT91S_DataFlashStatus AT91F_DataFlashWaitReady(
207 AT91PS_DataflashDesc pDataFlashDesc,
208 unsigned int timeout)
210 pDataFlashDesc->DataFlash_state = IDLE;
212 AT91F_DataFlashGetStatus(pDataFlashDesc);
215 while(((pDataFlashDesc->DataFlash_state & 0x80) != 0x80) && (timeout > 0));
217 if((pDataFlashDesc->DataFlash_state & 0x80) != 0x80)
218 return AT91C_DATAFLASH_ERROR;
220 return AT91C_DATAFLASH_OK;
224 /*------------------------------------------------------------------------------*/
225 /* Function Name : AT91F_DataFlashContinuousRead */
226 /* Object : Continuous stream Read */
227 /* Input Parameters : DataFlash Service */
228 /* : <src> = dataflash address */
229 /* : <*dataBuffer> = data buffer pointer */
230 /* : <sizeToRead> = data buffer size */
231 /* Return value : State of the dataflash */
232 /*------------------------------------------------------------------------------*/
233 static AT91S_DataFlashStatus AT91F_DataFlashContinuousRead(
234 AT91PS_DataFlash pDataFlash,
236 unsigned char *dataBuffer,
239 AT91S_DataFlashStatus status;
240 /* Test the size to read in the device */
241 if ( (src + sizeToRead) > (pDataFlash->pDevice->pages_size * (pDataFlash->pDevice->pages_number)))
242 return AT91C_DATAFLASH_MEMORY_OVERFLOW;
244 pDataFlash->pDataFlashDesc->rx_data_pt = dataBuffer;
245 pDataFlash->pDataFlashDesc->rx_data_size = sizeToRead;
246 pDataFlash->pDataFlashDesc->tx_data_pt = dataBuffer;
247 pDataFlash->pDataFlashDesc->tx_data_size = sizeToRead;
249 status = AT91F_DataFlashSendCommand(pDataFlash, DB_CONTINUOUS_ARRAY_READ, 8, src);
250 /* Send the command to the dataflash */
256 /*------------------------------------------------------------------------------*/
257 /* Function Name : AT91F_MainMemoryToBufferTransfer */
258 /* Object : Read a page in the SRAM Buffer 1 or 2 */
259 /* Input Parameters : DataFlash Service */
260 /* : Page concerned */
262 /* Return value : State of the dataflash */
263 /*------------------------------------------------------------------------------*/
264 static AT91S_DataFlashStatus AT91F_MainMemoryToBufferTransfer(
265 AT91PS_DataFlash pDataFlash,
266 unsigned char BufferCommand,
270 /* Test if the buffer command is legal */
271 if ((BufferCommand != DB_PAGE_2_BUF1_TRF) && (BufferCommand != DB_PAGE_2_BUF2_TRF))
272 return AT91C_DATAFLASH_BAD_COMMAND;
274 /* no data to transmit or receive */
275 pDataFlash->pDataFlashDesc->tx_data_size = 0;
277 if (pDataFlash->pDevice->pages_number >= 16384)
279 return(AT91F_DataFlashSendCommand(pDataFlash, BufferCommand, cmdsize,
280 page*pDataFlash->pDevice->pages_size));
285 /*----------------------------------------------------------------------------- */
286 /* Function Name : AT91F_DataFlashWriteBuffer */
287 /* Object : Write data to the internal sram buffer 1 or 2 */
288 /* Input Parameters : DataFlash Service */
289 /* : <BufferCommand> = command to write buffer1 or buffer2 */
290 /* : <*dataBuffer> = data buffer to write */
291 /* : <bufferAddress> = address in the internal buffer */
292 /* : <SizeToWrite> = data buffer size */
293 /* Return value : State of the dataflash */
294 /*------------------------------------------------------------------------------*/
295 static AT91S_DataFlashStatus AT91F_DataFlashWriteBuffer(
296 AT91PS_DataFlash pDataFlash,
297 unsigned char BufferCommand,
298 unsigned char *dataBuffer,
299 unsigned int bufferAddress,
303 /* Test if the buffer command is legal */
304 if ((BufferCommand != DB_BUF1_WRITE) && (BufferCommand != DB_BUF2_WRITE))
305 return AT91C_DATAFLASH_BAD_COMMAND;
307 /* buffer address must be lower than page size */
308 if (bufferAddress > pDataFlash->pDevice->pages_size)
309 return AT91C_DATAFLASH_BAD_ADDRESS;
311 /* Send first Write Command */
312 pDataFlash->pDataFlashDesc->command[0] = BufferCommand;
313 pDataFlash->pDataFlashDesc->command[1] = 0;
314 if (pDataFlash->pDevice->pages_number >= 16384)
316 pDataFlash->pDataFlashDesc->command[2] = 0;
317 pDataFlash->pDataFlashDesc->command[3] = (unsigned char)(((unsigned int)(bufferAddress & pDataFlash->pDevice->byte_mask)) >> 8) ;
318 pDataFlash->pDataFlashDesc->command[4] = (unsigned char)((unsigned int)bufferAddress & 0x00FF) ;
323 pDataFlash->pDataFlashDesc->command[2] = (unsigned char)(((unsigned int)(bufferAddress & pDataFlash->pDevice->byte_mask)) >> 8) ;
324 pDataFlash->pDataFlashDesc->command[3] = (unsigned char)((unsigned int)bufferAddress & 0x00FF) ;
325 pDataFlash->pDataFlashDesc->command[4] = 0;
329 pDataFlash->pDataFlashDesc->tx_cmd_pt = pDataFlash->pDataFlashDesc->command ;
330 pDataFlash->pDataFlashDesc->tx_cmd_size = cmdsize ;
331 pDataFlash->pDataFlashDesc->rx_cmd_pt = pDataFlash->pDataFlashDesc->command ;
332 pDataFlash->pDataFlashDesc->rx_cmd_size = cmdsize ;
334 pDataFlash->pDataFlashDesc->rx_data_pt = dataBuffer ;
335 pDataFlash->pDataFlashDesc->tx_data_pt = dataBuffer ;
336 pDataFlash->pDataFlashDesc->rx_data_size = SizeToWrite ;
337 pDataFlash->pDataFlashDesc->tx_data_size = SizeToWrite ;
339 return AT91F_SpiWrite(pDataFlash->pDataFlashDesc);
343 /*------------------------------------------------------------------------------*/
344 /* Function Name : AT91F_PageErase */
345 /* Object : Read a page in the SRAM Buffer 1 or 2 */
346 /* Input Parameters : DataFlash Service */
347 /* : Page concerned */
349 /* Return value : State of the dataflash */
350 /*------------------------------------------------------------------------------*/
351 static AT91S_DataFlashStatus AT91F_PageErase(
352 AT91PS_DataFlash pDataFlash,
356 /* Test if the buffer command is legal */
357 /* no data to transmit or receive */
358 pDataFlash->pDataFlashDesc->tx_data_size = 0;
361 if (pDataFlash->pDevice->pages_number >= 16384)
363 return(AT91F_DataFlashSendCommand(pDataFlash, DB_PAGE_ERASE, cmdsize,
364 page*pDataFlash->pDevice->pages_size));
368 /*------------------------------------------------------------------------------*/
369 /* Function Name : AT91F_WriteBufferToMain */
370 /* Object : Write buffer to the main memory */
371 /* Input Parameters : DataFlash Service */
372 /* : <BufferCommand> = command to send to buf1 or buf2 */
373 /* : <dest> = main memory address */
374 /* Return value : State of the dataflash */
375 /*------------------------------------------------------------------------------*/
376 static AT91S_DataFlashStatus AT91F_WriteBufferToMain (
377 AT91PS_DataFlash pDataFlash,
378 unsigned char BufferCommand,
382 /* Test if the buffer command is correct */
383 if ((BufferCommand != DB_BUF1_PAGE_PGM) &&
384 (BufferCommand != DB_BUF1_PAGE_ERASE_PGM) &&
385 (BufferCommand != DB_BUF2_PAGE_PGM) &&
386 (BufferCommand != DB_BUF2_PAGE_ERASE_PGM) )
387 return AT91C_DATAFLASH_BAD_COMMAND;
389 /* no data to transmit or receive */
390 pDataFlash->pDataFlashDesc->tx_data_size = 0;
393 if (pDataFlash->pDevice->pages_number >= 16384)
395 /* Send the command to the dataflash */
396 return(AT91F_DataFlashSendCommand (pDataFlash, BufferCommand, cmdsize, dest));
400 /*------------------------------------------------------------------------------*/
401 /* Function Name : AT91F_PartialPageWrite */
402 /* Object : Erase partially a page */
403 /* Input Parameters : <page> = page number */
404 /* : <AdrInpage> = adr to begin the fading */
405 /* : <length> = Number of bytes to erase */
406 /*------------------------------------------------------------------------------*/
407 static AT91S_DataFlashStatus AT91F_PartialPageWrite (
408 AT91PS_DataFlash pDataFlash,
414 unsigned int AdrInPage;
416 page = dest / (pDataFlash->pDevice->pages_size);
417 AdrInPage = dest % (pDataFlash->pDevice->pages_size);
419 /* Read the contents of the page in the Sram Buffer */
420 AT91F_MainMemoryToBufferTransfer(pDataFlash, DB_PAGE_2_BUF1_TRF, page);
421 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
423 /*Update the SRAM buffer */
424 AT91F_DataFlashWriteBuffer(pDataFlash, DB_BUF1_WRITE, src, AdrInPage, size);
425 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
427 /* Erase page if a 128 Mbits device */
428 if (pDataFlash->pDevice->pages_number >= 16384)
430 AT91F_PageErase(pDataFlash, page);
431 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
434 /* Rewrite the modified Sram Buffer in the main memory */
435 return(AT91F_WriteBufferToMain(pDataFlash, DB_BUF1_PAGE_ERASE_PGM,
436 (page*pDataFlash->pDevice->pages_size)));
440 /*------------------------------------------------------------------------------*/
441 /* Function Name : AT91F_DataFlashWrite */
443 /* Input Parameters : <*src> = Source buffer */
444 /* : <dest> = dataflash adress */
445 /* : <size> = data buffer size */
446 /*------------------------------------------------------------------------------*/
447 AT91S_DataFlashStatus AT91F_DataFlashWrite(
448 AT91PS_DataFlash pDataFlash,
457 AT91F_SpiEnable(pDataFlash->pDevice->cs);
459 if ( (dest + size) > (pDataFlash->pDevice->pages_size * (pDataFlash->pDevice->pages_number)))
460 return AT91C_DATAFLASH_MEMORY_OVERFLOW;
462 /* If destination does not fit a page start address */
463 if ((dest % ((unsigned int)(pDataFlash->pDevice->pages_size))) != 0 ) {
464 length = pDataFlash->pDevice->pages_size - (dest % ((unsigned int)(pDataFlash->pDevice->pages_size)));
469 if(!AT91F_PartialPageWrite(pDataFlash,src, dest, length))
470 return AT91C_DATAFLASH_ERROR;
472 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
474 /* Update size, source and destination pointers */
480 while (( size - pDataFlash->pDevice->pages_size ) >= 0 )
482 /* program dataflash page */
483 page = (unsigned int)dest / (pDataFlash->pDevice->pages_size);
485 status = AT91F_DataFlashWriteBuffer(pDataFlash, DB_BUF1_WRITE, src,
486 0, pDataFlash->pDevice->pages_size);
487 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
489 status = AT91F_PageErase(pDataFlash, page);
490 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
492 return AT91C_DATAFLASH_ERROR;
494 status = AT91F_WriteBufferToMain (pDataFlash, DB_BUF1_PAGE_PGM, dest);
496 return AT91C_DATAFLASH_ERROR;
498 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
500 /* Update size, source and destination pointers */
501 size -= pDataFlash->pDevice->pages_size ;
502 dest += pDataFlash->pDevice->pages_size ;
503 src += pDataFlash->pDevice->pages_size ;
506 /* If still some bytes to read */
508 /* program dataflash page */
509 if(!AT91F_PartialPageWrite(pDataFlash, src, dest, size) )
510 return AT91C_DATAFLASH_ERROR;
511 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
513 return AT91C_DATAFLASH_OK;
517 /*------------------------------------------------------------------------------*/
518 /* Function Name : AT91F_DataFlashRead */
519 /* Object : Read a block in dataflash */
520 /* Input Parameters : */
522 /*------------------------------------------------------------------------------*/
523 int AT91F_DataFlashRead(
524 AT91PS_DataFlash pDataFlash,
529 unsigned long SizeToRead;
531 AT91F_SpiEnable(pDataFlash->pDevice->cs);
533 if(AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT) != AT91C_DATAFLASH_OK)
538 SizeToRead = (size < 0x8000)? size:0x8000;
540 if (AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT)
541 != AT91C_DATAFLASH_OK)
544 if (AT91F_DataFlashContinuousRead (pDataFlash, addr, (unsigned char *)buffer,
545 SizeToRead) != AT91C_DATAFLASH_OK)
550 buffer += SizeToRead;
553 return AT91C_DATAFLASH_OK;
557 /*------------------------------------------------------------------------------*/
558 /* Function Name : AT91F_DataflashProbe */
560 /* Input Parameters : */
561 /* Return value : Dataflash status register */
562 /*------------------------------------------------------------------------------*/
563 int AT91F_DataflashProbe(int cs, AT91PS_DataflashDesc pDesc)
566 AT91F_DataFlashGetStatus(pDesc);
567 return ((pDesc->command[1] == 0xFF)? 0: (pDesc->command[1] & 0x3C));
570 /*------------------------------------------------------------------------------*/
571 /* Function Name : AT91F_DataFlashErase */
573 /* Input Parameters : <*pDataFlash> = Device info */
574 /*------------------------------------------------------------------------------*/
575 AT91S_DataFlashStatus AT91F_DataFlashErase(AT91PS_DataFlash pDataFlash)
580 AT91F_SpiEnable(pDataFlash->pDevice->cs);
582 for(page=0; page < pDataFlash->pDevice->pages_number; page++)
584 /* Erase dataflash page */
585 if ((page & 0x00FF) == 0)
586 printf("\rERA %d/%d", page, pDataFlash->pDevice->pages_number);
587 status = AT91F_PageErase(pDataFlash, page);
588 AT91F_DataFlashWaitReady(pDataFlash->pDataFlashDesc, AT91C_DATAFLASH_TIMEOUT);
590 return AT91C_DATAFLASH_ERROR;
593 return AT91C_DATAFLASH_OK;