Flash Memory Library

This library provides routines for accessing microcontroller's (internal) Flash memory.


  Important :

Please bear in mind that when the Flash memory is acquired and not released from the CPU I/O interface, any further Flash memory manipulation is not possible until the MCU is reprogrammed.
Use the Flash_release_semaphore and Flash_wait_semaphore routines to release/check the current status of the Flash memory controller.

Library Routines

Flash_Write_Buffer

Prototype

sub function Flash_Write_Buffer(dim address as longword, dim buffer as ^byte, dim length as word) as longint

Description

This sub function will write an array of bytes into the on-chip Flash memory.

Parameters
  • address: Flash memory address.
  • buffer: pointer to an array to be written.
  • length: number of bytes to be written.
Returns
  • 0 - if writing was successful.
  • 1 - if Flash control block is not ready.
  • 2 - if writing was not enabled.
  • 3 - if transfer was not completed.
Requires

Nothing.

Example
Flash_Write_Buffer(Address, @buff, 16)     ' write 16 bytes to Flash memory
Notes

None.

Flash_Read_Buffer

Prototype

sub function Flash_Read_Buffer(dim address as longword, dim buffer as ^byte, dim length as word) as longint

Description

This sub function will read an array of bytes from the on-chip Flash memory.

Parameters
  • address: Flash memory address.
  • buffer: pointer to an array that will hold the read data.
  • length: number of bytes to be read.
Returns
  • 0 - if writing was successful.
  • 1 - if Flash control block is not ready.
  • 2 - if reading was not enabled.
  • 3 - if transfer was not completed.
Requires

Nothing.

Example
Flash_Read_Buffer(Address, @buff, 16)     ' read 16 bytes from the Flash memory
Notes

None.

Flash_wait_semaphore

Prototype

sub function Flash_wait_semaphore() as integer

Description

The sub function tests if the Flash memory resource is acquired by the CPU I/O interface.

Parameters

None.

Returns
  • 0 - the interface acquired the Flash memory resource.
  • 1 - the Flash memory resource is not released from the interface (i.e. not free).
Requires

Nothing.

Example
if (Flash_wait_semaphore() = 0) then
...
end if
Notes

None.

Flash_release_semaphore

Prototype

sub procedure Flash_release_semaphore()

Description

The sub function releases the Flash memory resource from CPU I/O interface.

Parameters

None.

Returns

None.

Requires

Nothing.

Example
Flash_release_semaphore()
Notes

None.

Copyright (c) 2002-2015 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code