STM32F10x library
Macros | Functions
fls_25.c File Reference

Spansion S25FL SPI flash routines. More...

#include <inttypes.h>
#include "spi.h"

Macros

#define FLS25_NSS_HIGH   fls25_cs(n, 1)
 
#define FLS25_NSS_LOW   fls25_cs(n, 0)
 

Functions

void _delay_ms (uint32_t)
 extern
 
void fls25_cs (uint8_t devnum, uint8_t nss)
 extern
 
uint8_t fls25_waitready (const uint8_t n, uint16_t to_ms)
 Wait for flash to become ready. More...
 
void fls25_init (const uint8_t n)
 Init flash. More...
 
uint8_t fls25_rd (const uint8_t n, const uint32_t adr, uint8_t *buf, uint16_t len)
 Read from flash. More...
 
void fls25_we (const uint8_t n)
 Flash write enable. More...
 
uint8_t fls25_wr (const uint8_t n, const uint32_t adr, uint8_t *buf, uint16_t len)
 Write to flash. More...
 
uint8_t fls25_chiperase (const uint8_t n)
 Execute erase device command. More...
 
uint8_t fls25_secterase (const uint8_t n, const uint16_t adr)
 Execute erase sector command. More...
 
uint32_t fls25_id (const uint8_t n)
 Execute read manufacturer/device ID command. More...
 
void fls25_clrstat (const uint8_t n)
 Clear status (unprotects blocks). More...
 

Detailed Description

Spansion S25FL SPI flash routines.

Author
Matej Kogovsek (matej.nosp@m.@ham.nosp@m.radio.nosp@m..si)
Note
This file is part of mat-stm32f1-lib
Tested with S25FL208 1Mbyte flash. Likely works with other densities and other manufacturers' x25 serial flash chips.
Warning
The code assumes 24 bit (3 byte) data addressing. Devices with more than 32MByte (or less than ?) will require code change.

Macro Definition Documentation

#define FLS25_NSS_HIGH   fls25_cs(n, 1)

Set NSS macro

#define FLS25_NSS_LOW   fls25_cs(n, 0)

Clear NSS macro

Function Documentation

uint8_t fls25_chiperase ( const uint8_t  n)

Execute erase device command.

Parameters
[in]nSPI peripheral number
Returns
Same as fls25_waitready
void fls25_clrstat ( const uint8_t  n)

Clear status (unprotects blocks).

Parameters
[in]nSPI peripheral number
uint32_t fls25_id ( const uint8_t  n)

Execute read manufacturer/device ID command.

Parameters
[in]nSPI peripheral number
Returns
32bit JEDEC assigned ID
void fls25_init ( const uint8_t  n)

Init flash.

Parameters
[in]nSPI peripheral number
uint8_t fls25_rd ( const uint8_t  n,
const uint32_t  adr,
uint8_t *  buf,
uint16_t  len 
)

Read from flash.

Parameters
[in]nSPI peripheral number
[in]adrStarting byte address
[out]bufCaller provided buffer for data
[in]lenNumber of bytes to read (len <= sizeof(buf))
Returns
Always returns 0.
uint8_t fls25_secterase ( const uint8_t  n,
const uint16_t  adr 
)

Execute erase sector command.

Parameters
[in]nSPI peripheral number
[in]adrAddress of any byte in sector to erase.
Returns
Same as fls25_waitready
uint8_t fls25_waitready ( const uint8_t  n,
uint16_t  to_ms 
)

Wait for flash to become ready.

Parameters
[in]nSPI peripheral number
[in]to_msTimeout in ms
Returns
True if timeout expired, false otherwise.
void fls25_we ( const uint8_t  n)

Flash write enable.

Parameters
[in]nSPI peripheral number
uint8_t fls25_wr ( const uint8_t  n,
const uint32_t  adr,
uint8_t *  buf,
uint16_t  len 
)

Write to flash.

Parameters
[in]nSPI peripheral number
[in]adrStarting byte address
[in]bufCaller provided buffer with data
[in]lenNumber of bytes to write (len <= sizeof(buf))
Returns
Same as fls25_waitready