FLASH
Ameba SDK » HAL

flash functions More...

## Ameba Common

typedef struct flash_s | flash_t
void | flash_erase_sector (flash_t *obj, uint32_t address)
| Erase flash sector. More...
void | flash_erase_block (flash_t *obj, uint32_t address)
| Erase flash block(64KB) More...
int | flash_read_word (flash_t *obj, uint32_t address, uint32_t *data)
| Read a word from specified address. More...
int | flash_write_word (flash_t *obj, uint32_t address, uint32_t data)
| Write a word to specified address. More...
int | flash_stream_read (flash_t *obj, uint32_t address, uint32_t len, uint8_t *data)
| Read a stream of data from specified address. More...
int | flash_stream_write (flash_t *obj, uint32_t address, uint32_t len, uint8_t *data)
| Write a stream of data to specified address. More...
void | flash_write_protect (flash_t *obj, uint32_t protect)
| Control the flash chip write protect enable/disable. More...
int | flash_get_status (flash_t *obj)
| Get the value of status register1. More...
int | flash_set_status (flash_t *obj, uint32_t data)
| Set Status register to enable desired operation. More...
void | flash_reset_status (flash_t *obj)
| This function aims to reset the status register, please make sure the operation is appropriate. More...
int | flash_burst_write (flash_t *obj, uint32_t address, uint32_t Length, uint8_t *data)
| It is the same with flash_stream_write function which is used to write a stream of data to specified address. More...
int | flash_burst_read (flash_t *obj, uint32_t address, uint32_t Length, uint8_t *data)
| It is the same with flash_stream_read function which is used to read a stream of data from specified address. More...
int | flash_set_extend_addr (flash_t *obj, uint32_t data)
| This function is only for Micron 128MB flash to access beyond 16MB by switching between eight 16MB-area(segment). Please refer to flash datasheet for more information about memory mapping. More...
int | flash_get_extend_addr (flash_t *obj)
| This function is only for Micron 128MB flash to read from Extended Address Register, which shows the current segment. Please refer to flash datasheet for more information about memory mapping. More...
int | flash_read_id (flash_t *obj, uint8_t *buf, uint8_t len)
| Get flash ID (command: 0x9F). More...
int | flash_read_unique_id (flash_t *obj, uint8_t *buf, uint8_t len)
| This function is only for Winbond flash to get unique ID (command: 0x4B). More...

## AmebaZ Only

void | flash_erase_chip (flash_t *obj)
| Erase the whole flash chip. More...

## Detailed Description

flash functions

## Function Documentation

int flash_burst_read | ( | flash_t * | obj,
|  | uint32_t | address,
|  | uint32_t | Length,
|  | uint8_t * | data
| ) |  |

It is the same with flash_stream_read function which is used to read a stream of data from specified address.

Parameters

  obj | Flash object define in application software.
  address | Specifies the starting address to read from.
  len | Specifies the length of the data to read.
  data | Specified the address to save the readback data.

Return values

  1 | Success

int flash_burst_write | ( | flash_t * | obj,
|  | uint32_t | address,
|  | uint32_t | Length,
|  | uint8_t * | data
| ) |  |

It is the same with flash_stream_write function which is used to write a stream of data to specified address.

Parameters

  obj | Flash object define in application software.
  address | Specifies the starting address to write to.
  len | Specifies the length of the data to write.
  data | Pointer to a byte array that is to be written.

Return values

  1 | Success

void flash_erase_block | ( | flash_t * | obj,
|  | uint32_t | address
| ) |  |

Erase flash block(64KB)

Parameters

  obj | Flash object define in application software.
  address | Specifies the starting address to be erased.LSB 16bits will be masked.

Return values

  none |

void flash_erase_chip | ( | flash_t * | obj | ) |

Erase the whole flash chip.

Parameters

  obj | Flash object define in application software.

Return values

  none |

void flash_erase_sector | ( | flash_t * | obj,
|  | uint32_t | address
| ) |  |

Erase flash sector.

Parameters

  obj | Flash object define in application software.
  address | Specifies the starting address to be erased.

Return values

  none |

int flash_get_extend_addr | ( | flash_t * | obj | ) |

This function is only for Micron 128MB flash to read from Extended Address Register, which shows the current segment. Please refer to flash datasheet for more information about memory mapping.

Parameters

  obj | Flash object define in application software.

Return values

  | The value of current Extended Address Register.

int flash_get_status | ( | flash_t * | obj | ) |

Get the value of status register1.

Parameters

  obj | Flash object define in application software.

Return values

  | The value of status register1.

int flash_read_id | ( | flash_t * | obj,
|  | uint8_t * | buf,
|  | uint8_t | len
| ) |  |

Get flash ID (command: 0x9F).

Parameters

  obj | Flash object define in application software.
  buf | Pointer to a byte array to save the readback ID.
  len | Specifies the length of the buf. It should be 3.

Return values

  -1 | Fail.

int flash_read_unique_id | ( | flash_t * | obj,
|  | uint8_t * | buf,
|  | uint8_t | len
| ) |  |

This function is only for Winbond flash to get unique ID (command: 0x4B).

Parameters

  obj | Flash object define in application software.
  buf | Pointer to a byte array to save the readback unique ID.
  len | Specifies the length of the buf. It should be 8.

Return values

  -1 | Fail.

int flash_read_word | ( | flash_t * | obj,
|  | uint32_t | address,
|  | uint32_t * | data
| ) |  |

Read a word from specified address.

Parameters

  obj | Flash object define in application software.
  address | Specifies the address to read from.
  data | Specified the address to save the readback data.

Return values

  1 | Success

Note
  auto mode read is ok, because we have flash cache

void flash_reset_status | ( | flash_t * | obj | ) |

This function aims to reset the status register, please make sure the operation is appropriate.

Parameters

  obj | Specifies the parameter of flash object.

Return values

  none |

int flash_set_extend_addr | ( | flash_t * | obj,
|  | uint32_t | data
| ) |  |

This function is only for Micron 128MB flash to access beyond 16MB by switching between eight 16MB-area(segment). Please refer to flash datasheet for more information about memory mapping.

Parameters

  obj | Flash object define in application software.
  data | Specified which segment to choose.

Return values

  1 | Success

int flash_set_status | ( | flash_t * | obj,
|  | uint32_t | data
| ) |  |

Set Status register to enable desired operation.

Parameters

  obj | Specifies the parameter of flash object.
  data | Specifies which bit users like to set. ex: if users want to set the third bit, data = 0x8.

Return values

  1 | Success

Note
  Please refer to the datatsheet of flash for more details of the content of status register. The block protected area and the corresponding control bits are provided in the flash datasheet.

int flash_stream_read | ( | flash_t * | obj,
|  | uint32_t | address,
|  | uint32_t | len,
|  | uint8_t * | data
| ) |  |

Read a stream of data from specified address.

Parameters

  obj | Flash object define in application software.
  address | Specifies the starting address to read from.
  len | Specifies the length of the data to read.
  data | Specified the address to save the readback data.

Return values

  1 | Success

Note
  auto mode is ok, because we have flash cache

int flash_stream_write | ( | flash_t * | obj,
|  | uint32_t | address,
|  | uint32_t | len,
|  | uint8_t * | data
| ) |  |

Write a stream of data to specified address.

Parameters

  obj | Flash object define in application software.
  address | Specifies the starting address to write to.
  len | Specifies the length of the data to write.
  data | Pointer to a byte array that is to be written.

Return values

  1 | Success

void flash_write_protect | ( | flash_t * | obj,
|  | uint32_t | protect
| ) |  |

Control the flash chip write protect enable/disable.

Parameters

  obj | Flash object define in application software.

  protect

  This parameter can be 1 or 0.
  - 1: Protect the whole chip from being programmed/erased.
  - 0: Unprotect the whole chip from being programmed/erased.

Return values

  none |

int flash_write_word | ( | flash_t * | obj,
|  | uint32_t | address,
|  | uint32_t | data
| ) |  |

Write a word to specified address.

Parameters

  obj | Flash object define in application software.
  address | Specifies the address to be programmed to.
  data | Specified the data to be programmed.

Return values

  1 | Success

Note
  user mode write used