User Manual
Version 1.1
2011-07-15
deRFnode and deRFgateway
dresden elektronik
ingenieurtechnik gmbh
Enno-Heidebroek-Str. 12
12 7 Dr
n
rm  n
Tel.: +49 351 31 85 00
Fax: +49 351 3 18 50 10
wireless@dresden-elektronik.de
www. r
n- l k r nik.
Page 47 of 56
9.4.5. Accessing the external flash
Each deRFnode/gateway board provides a serial flash device which is accessed via the SPI
interface. Although being from Atmels AT25 family, if behaves similar to the well-known
AT26-Flash devices. So when using an ARM MCU, the AT91 Library functions from memo-
ries/spi-flash/spid.c and ~/at26.c may be employed, to allow chip identification
you still may add its JEDEC-ID (0x0001441F) to the table of device identifiers such like:
/// Array of recognized serial firmware dataflash chips.
static const At26Desc at26Devices[] = {
...
// Other
{"AT25DF041" , 0x0001441F, 1 * 512 * 1024, 256, 64 * 1024}
};
A typical initialization of the SPI flash driver may look like:
/// SPI0 pin definitions
#define PIN_SPI0_MISO {1 << 16, AT91C_BASE_PIOA, AT91C_ID_PIOA,
PIO_PERIPH_A, PIO_PULLUP}
#define PIN_SPI0_MOSI {1 << 17, AT91C_BASE_PIOA, AT91C_ID_PIOA,
PIO_PERIPH_A, PIO_DEFAULT}
#define PIN_SPI0_SPCK {1 << 18, AT91C_BASE_PIOA, AT91C_ID_PIOA,
PIO_PERIPH_A, PIO_DEFAULT}
#define PIN_SPI0_NPCS0 {1 << 14, AT91C_BASE_PIOA, AT91C_ID_PIOA,
PIO_PERIPH_A, PIO_DEFAULT}
#define PINS_SPI0 PIN_SPI0_MISO, PIN_SPI0_MOSI, PIN_SPI0_SPCK
// Base address of SPI peripheral connected to the serialflash.
#define BOARD_AT25_SPI_BASE AT91C_BASE_SPI0
// Identifier of SPI peripheral connected to the serialflash.
#define BOARD_AT25_SPI_ID AT91C_ID_SPI0
// Pins of the SPI peripheral connected to the serialflash.
#define BOARD_AT25_SPI_PINS PINS_SPI0, PIN_SPI0_NPCS0
static Spid spid; /// SPI driver instance.
static At26 at26; /// Serial flash driver instance.
static Pin pins[] = { BOARD_AT25_SPI_PINS };
PIO_Configure(pins, PIO_LISTSIZE(pins));
AIC_ConfigureIT(BOARD_AT25_SPI_ID, 0, ISR_Spi);
SPID_Configure(&spid, BOARD_AT25_SPI_BASE, BOARD_AT25_SPI_ID);
AT26_Configure(&at26, &spid, BOARD_AT25_NPCS);
AIC_EnableIT(BOARD_AT25_SPI_ID);
Afterwards you may evaluate the number of pages and the pagesize since this is important
for each further access:
unsigned int numPages = AT26_PageNumber(&at26);
unsigned int pageSize = AT26_PageSize(&at26);
Since low-level-accessing the flash device is not trivial, the application Example basic-
serialflash-project from the AT91-Library already provides a set of functions necessary to
perform read and write operations, erase, protect and unprotect the flash memory. For fur-
ther details, please refer to basic-serialflash-project/main.c.