EEPROM Memory Library
This library provides routines for accessing microcontroller's (internal) EEPROM memory. Only the STM32L and Tiva series have internal EEPROM memory.
STM32L Series Library Routines
- EEPROM_Unlock
- EEPROM_Lock
- EEPROM_EraseSector
- EEPROM_EraseAllSectors
- EEPROM_Write_Word
- EEPROM_Write_HalfWord
- EEPROM_Write_Byte
Tiva Series Library Routines
- EEPROM_Init
- EEPROM_BlockCountGet
- EEPROM_BlockHide
- EEPROM_BlockProtectGet
- EEPROM_BlockProtectSet
- EEPROM_BlockLock
- EEPROM_BlockUnlock
- EEPROM_BlockPasswordSet
- EEPROM_MassErase
- EEPROM_Program
- EEPROM_ProgramWord
- EEPROM_Read
EEPROM_Unlock
Prototype |
procedure EEPROM_Unlock(); |
---|---|
Description |
This routine will unlock the EEPROM control register access. This routine is valid only for STM32L devices. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
Nothing. |
Example |
EEPROM_Unlock(); |
Notes |
This routine is valid only for STM32L devices. |
EEPROM_lock
Prototype |
procedure EEPROM_lock(); |
---|---|
Description |
This routine will lock the EEPROM control register access. This routine is valid only for STM32L devices. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
Nothing. |
Example |
EEPROM_lock(); |
Notes |
This routine is valid only for STM32L devices. It is recommended that EEPROM lock is performed right after the EEPROM write is finished to avoid any unwanted subsequent EEPROM writing. |
EEPROM_EraseWord
Prototype |
function EEPROM_EraseWord(Address : dword) : dword; |
---|---|
Description |
This routine will erase a word (32-bit) from the specified EEPROM address. This routine is valid only for STM32L devices. |
Parameters |
|
Returns |
|
Requires |
Requires unlock procedure to be performed afterwards. |
Example |
status := EEPROM_EraseWord(0); |
Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Write_Word
Prototype |
function EEPROM_Write_Word(Address : dword; lData : dword) : dword; |
---|---|
Description |
Writes a word (32-bit) at a specified address. The address has to be in the EEPROM address range or else the result can be unpredictable. This routine is valid only for STM32L devices. |
Parameters |
|
Returns |
|
Requires |
Requires unlock procedure to be performed afterwards. |
Example |
status := EEPROM_Write_Word(); |
Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Write_HalfWord
Prototype |
function EEPROM_Write_HalfWord(Address : dword; lData : word) : dword; |
---|---|
Description |
Writes a half word (16-bit) at a specified address. The address has to be in the EEPROM address range or else the result can be unpredictable. This routine is valid only for STM32L devices. |
Parameters |
|
Returns |
|
Requires |
Requires unlock procedure to be performed afterwards. |
Example |
status := EEPROM_Write_HalfWord(); |
Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Write_Byte
Prototype |
function EEPROM_Write_Byte(Address : dword; lData : byte) : dword; |
---|---|
Description |
Writes a byte (8-bit) at a specified address. The address has to be in the EEPROM address range or else the result can be unpredictable. This routine is valid only for STM32L devices. |
Parameters |
|
Returns |
|
Requires |
Requires unlock procedure to be performed afterwards. |
Example |
status := EEPROM_Write_Byte(); |
Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Init
Prototype |
function EEPROM_Init() : word; |
---|---|
Description |
This routine will initialize the EEPROM. |
Parameters |
None. |
Returns |
|
Requires |
Nothing. |
Example |
value := EEPROM_Init(); |
Notes |
This routine is valid only for Tiva devices. |
EEPROM_BlockCountGet
Prototype |
function EEPROM_BlockCountGet() : word; |
---|---|
Description |
This routine will get the number of blocks in the EEPROM. |
Parameters |
None. |
Returns |
Total number of blocks in the device EEPROM. |
Requires |
Nothing. |
Example |
blockcount := EEPROM_BlockCountGet(); |
Notes |
This routine is valid only for Tiva devices. |
EEPROM_BlockHide
Prototype |
procedure EEPROM_BlockHide(block : word); |
---|---|
Description |
This routine hides an EEPROM block until the next reset. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const HIDE_ADDRESS : word = 128; const HIDE_BLOCK_NUMBER : word = HIDE_ADDRESS/BLOCK_SIZE; // hide block containing written data this block is now inaccesible until next reset EEPROM_BlockHide(HIDE_BLOCK_NUMBER); |
Notes |
|
EEPROM_BlockProtectGet
Prototype |
function EEPROM_BlockProtectGet(block : word) : dword; |
---|---|
Description |
This routine returns the current protection level for an EEPROM block. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const LOCK_ADDRESS : word = 256; const LOCK_BLOCK_NUMBER : word = LOCK_ADDRESS/BLOCK_SIZE; // read the protection level selected for a block i := EEPROM_BlockProtectGet(LOCK_BLOCK_NUMBER); |
Notes |
|
EEPROM_BlockProtectSet
Prototype |
function EEPROM_BlockProtectSet(block : word; protect : dword) : dword; |
---|---|
Description |
This routine sets the current protection options for an EEPROM block. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const LOCK_ADDRESS : word = 256; const LOCK_BLOCK_NUMBER : word = LOCK_ADDRESS/BLOCK_SIZE; // This setting is the default. If there is no password, the block is not protected and is readable and writable. // If there is a password, the block is readable, but only writable when unlocked. EEPROM_BlockProtectSet(LOCK_BLOCK_NUMBER, 0x0); |
Notes |
|
EEPROM_BlockLock
Prototype |
function EEPROM_BlockLock(block : word) : dword; |
---|---|
Description |
This routine locks a password-protected EEPROM block. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const LOCK_ADDRESS : word = 256; const LOCK_BLOCK_NUMBER : word = LOCK_ADDRESS/BLOCK_SIZE; // lock block containing written data; this block is now inaccesible EEPROM_BlockLock(LOCK_BLOCK_NUMBER); |
Notes |
|
EEPROM_BlockUnlock
Prototype |
function EEPROM_BlockUnlock(block : word; password : ^dword; count : word) : dword; |
---|---|
Description |
This routine unlocks a password-protected EEPROM block. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const LOCK_ADDRESS : word = 256; const LOCK_BLOCK_NUMBER : word = LOCK_ADDRESS/BLOCK_SIZE; const PASS_SIZE : word = 2; var password : array[DATA_SIZE] of dword; password[0] := 0x0a; password[1] := 0xc2; // unlock locked block EEPROM_BlockUnlock(LOCK_BLOCK_NUMBER, @password, PASS_SIZE); |
Notes |
|
EEPROM_BlockPasswordSet
Prototype |
function EEPROM_BlockPasswordSet(block : word; password : ^dword; count : word) : word |
---|---|
Description |
This routine sets the password used to protect an EEPROM block. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const LOCK_ADDRESS : word = 256; const LOCK_BLOCK_NUMBER : word = LOCK_ADDRESS/BLOCK_SIZE; const PASS_SIZE : word = 2; var password : array[DATA_SIZE] of dword; password[0] := 0x0a; password[1] := 0xc2; // lock block EEPROM_BlockPasswordSet(LOCK_BLOCK_NUMBER, @password, PASS_SIZE); |
Notes |
|
EEPROM_MassErase
Prototype |
function EEPROM_MassErase() : dword |
---|---|
Description |
This routine erases the EEPROM and returns it to the factory default condition. |
Parameters |
None. |
Returns |
|
Requires |
Nothing. |
Example |
// delete entire EEPROM EEPROM_MassErase(); |
Notes |
|
EEPROM_Program
Prototype |
function EEPROM_Program(data_ : ^dword; address : word; count : word) : dword |
---|---|
Description |
This routine writes data to EEPROM. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const DATA_SIZE : word = BLOCK_SIZE/4; // block size in words const HIDE_ADDRESS : word = 128; const LOCK_ADDRESS : word = 256; var writeData: array[DATA_SIZE] of dword; var i : integer; for i := 0 to DATA_SIZE-1 do begin writeData[i] := i; end; // write data to EEPROM EEPROM_Program(@writeData, LOCK_ADDRESS, BLOCK_SIZE); EEPROM_Program(@writeData, HIDE_ADDRESS, BLOCK_SIZE); |
Notes |
|
EEPROM_ProgramWord
Prototype |
function EEPROM_ProgramWord(data_ : dword; address : dword) : dword |
---|---|
Description |
This routine writes a word to EEPROM. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
const START_ADDRESS : word = 0; // program one word EEPROM_ProgramWord(0xbb, START_ADDRESS); |
Notes |
|
EEPROM_Read
Prototype |
procedure EEPROM_Read(data_ : dword; address : word; count : word); |
---|---|
Description |
This routine reads data from EEPROM. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
const BLOCK_SIZE : word = 64; // block size in bytes const DATA_SIZE : word = BLOCK_SIZE/4; // block size in words const START_ADDRESS : word = 0; var writeData: array[DATA_SIZE] of dword; // read DATA_SIZE words of data from EEPROM starting from START_ADDRESS EEPROM_Read(@readData, START_ADDRESS, BLOCK_SIZE); |
Notes |
|