KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sflash.h File Reference

This driver implements access to the Serial Flash. More...

#include <stdbool.h>
#include <stdint.h>
#include <errorcode.h>

Go to the source code of this file.

Data Structures

struct  SfInfo
 

Macros

#define SF_MF_SPANSION   0x01
 Manufacturer Spansion.
 
#define SF_MF_MICRON   0x20
 Manufacturer Micron.
 
#define SF_DEV_MICRON_N25QA   0xBA
 
#define SF_DEV_SPANSION_S25FL   0x02
 
#define E_SF_DEVNOTFOUND   ( E_SFLASH + 1 )
 
#define E_SF_DEVNOTFOUND_DESCR   "Device not supported or no device found"
 
#define E_SF_WRITEERASE   ( E_SFLASH + 2 )
 
#define E_SF_WRITEERASE_DESCR   "Flash write or erase error"
 
#define E_SF_PASSWORD   ( E_SFLASH + 3 )
 
#define E_SF_PASSWORD_DESCR   "Password failed"
 
#define SF_INFO_CAP_PASSWORD   0x1
 Device supports password protection. More...
 
#define SF_INFO_CAP_SECTOR_PROTECT   0x2
 Device support per sector protection.
 
#define SF_INFO_STS_PASSWORD_PROTECT   0x1
 Whether (part of) the flash is password. More...
 
#define SF_INFO_STS_LOCKED   0x2
 Whether part of the flash is locked. More...
 

Typedefs

typedef uint8_t SfPassword [8]
 Serial Flash password.
 

Functions

bool sfInit ()
 Initializes the Serial Flash. More...
 
bool sfReset ()
 Resets the flash. More...
 
bool sfRead (uint32_t address, uint8_t *data, uint32_t count)
 Read from a specific address in flash. More...
 
bool sfProg (uint32_t address, uint8_t *data, uint32_t count)
 Program an page in flash. More...
 
bool sfProgXPage (uint32_t address, uint8_t *data, uint32_t count)
 Program cross pages. More...
 
bool sfErase (uint32_t address)
 Erase a sector in flash. More...
 
bool sfQuadEnable (bool enable)
 Quad enable,. More...
 
bool sfSetPasswordOTP (SfPassword *password)
 Password protects specific sectors from being modified. More...
 
bool sfLockUnlock (SfPassword *password)
 Unlocks or locks the flash with the specified password. More...
 
bool sfProtect (uint32_t address)
 Protects a specific sector from being erased or programmed. More...
 
bool sfUnProtect ()
 Unprotects the entire flash array. More...
 
void sfSpDiag ()
 Shows diagnostic state of Spansion Flash.
 

Variables

SfInfo sfInfo
 Flash info, only valid after successful initialization.
 

Detailed Description

This driver implements access to the Serial Flash.

Note that this interface is probably a standard, but I could not find it.

Definition in file sflash.h.

Macro Definition Documentation

#define SF_INFO_CAP_PASSWORD   0x1

Device supports password protection.

Definition at line 49 of file sflash.h.

#define SF_INFO_STS_LOCKED   0x2

Whether part of the flash is locked.

Definition at line 54 of file sflash.h.

#define SF_INFO_STS_PASSWORD_PROTECT   0x1

Whether (part of) the flash is password.

protected.

Definition at line 52 of file sflash.h.

Function Documentation

bool sfErase ( uint32_t  address)

Erase a sector in flash.

Erases a 'sfInfo.sectorSize'-sized sector in flash. Note that though a full 32 bit address is accepted, only the most significant bits will be used.

Parameters
addressOffset address
Return values
trueFlash read successfully.
falseSome error occurred. Check error module for error.

Definition at line 564 of file sflash.c.

bool sfInit ( )

Initializes the Serial Flash.

Return values
trueFlash detected and initialized
falseSome error occurred. Check error module for error.

Definition at line 435 of file sflash.c.

bool sfLockUnlock ( SfPassword password)

Unlocks or locks the flash with the specified password.

Parameters
passwordA pointer to the password, or NULL to lock.
Return values
trueCommand successful
falseCommand failed, check error module for error.

Definition at line 645 of file sflash.c.

bool sfProg ( uint32_t  address,
uint8_t *  data,
uint32_t  count 
)

Program an page in flash.

Note that a maximum of 'sfInfo.pageSize' bytes can be programmed at once, and only per page. If programming continues over the page boundary it will continue at the beginning of the same page.

Parameters
addressOffset address
dataData array to read up to 'count' bytes.
countNo. of bytes to write.
Return values
trueFlash read successfully.
falseSome error occurred. Check error module for error.

Definition at line 519 of file sflash.c.

bool sfProgXPage ( uint32_t  address,
uint8_t *  data,
uint32_t  count 
)

Program cross pages.

Unlike sfProg this function can write over page boundaries and multiple pages, e.g. it does not really matter where you start or end. There is a small performance penalty.

Parameters
addressOffset address
dataData array to read up to 'count' bytes.
countNo. of bytes to write.
Return values
trueFlash read successfully.
falseSome error occurred. Check error module for error.

Definition at line 547 of file sflash.c.

bool sfProtect ( uint32_t  address)

Protects a specific sector from being erased or programmed.

Parameters
addressFirst location of the sector to be protected.
Note
This command can only be issued before SetPasswordOTP, or after issuing the right password using sfLockUnlock().
Though a full 32 bit address is accepted, only the first byte on the first page of each sector should be addressed.
Return values
trueCommand successful
falseCommand failed, check error module for error.

Definition at line 672 of file sflash.c.

bool sfQuadEnable ( bool  enable)

Quad enable,.

Parameters
enableEnables the quad mode
Return values
trueCommand successful
falseCommand failed, check error module for error.

Definition at line 442 of file sflash.c.

bool sfRead ( uint32_t  address,
uint8_t *  data,
uint32_t  count 
)

Read from a specific address in flash.

Parameters
addressOffset address
dataData array to fill up to 'count' bytes.
countNo. of bytes to read.
Return values
trueFlash read successfully.
falseSome error occurred. Check error module for error.

Definition at line 491 of file sflash.c.

bool sfReset ( )

Resets the flash.

Return values
trueFlash detected and initialized
falseSome error occurred. Check error module for error.

Definition at line 320 of file sflash.c.

bool sfSetPasswordOTP ( SfPassword password)

Password protects specific sectors from being modified.

Before setting the password you can select wich sectors need to be protected.

Note
sfProtect can only be used before issuing this command, or after unlocking the flash using sfLockUnlock().
Parameters
passwordA poiner to the password.
Return values
trueCommand successful
falseCommand failed, check error module for error.

Definition at line 589 of file sflash.c.

bool sfUnProtect ( )

Unprotects the entire flash array.

Note
This command can only be issued before SetPasswordOTP, or after issuing the right password using sfLockUnlock().
Return values
trueCommand successful
falseCommand failed, check error module for error.

Definition at line 690 of file sflash.c.