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

long Flash_Write_Buffer(uint32_t address, uint8_t *buffer, uint16_t length);

Description

This 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

long Flash_Read_Buffer(uint32_t address, uint8_t *buffer, uint16_t length);

Description

This 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

int Flash_wait_semaphore();

Description

The 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) {
...
}
Notes

None.

Flash_release_semaphore

Prototype

void Flash_release_semaphore();

Description

The 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