SDK3.5
This document shows Ameba SDK 3.5 APIs
FLASH

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...
 
void flash_set_lock_mode (uint32_t mode)
 This function is only for Winbond flash to set lock mode. More...
 
void flash_global_lock (void)
 This function is only for Winbond flash to lock whole flash chip. More...
 
void flash_global_unlock (void)
 This function is only for Winbond flash to unlock whole flash chip. More...
 
void flash_individual_lock (uint32_t address)
 This function is only for Winbond flash to lock individual sector or block region, should refer to the datasheet for more details. More...
 
void flash_individual_unlock (uint32_t address)
 This function is only for Winbond flash to unlock individual sector or block region, should refer to the datasheet for more details. More...
 
int flash_read_individual_lock_state (uint32_t address)
 This function is only for Winbond flash to get the individual lock state on certain address. 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
objFlash object define in application software.
addressSpecifies the starting address to read from.
lenSpecifies the length of the data to read.
dataSpecified the address to save the readback data.
Return values
1Success
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
objFlash object define in application software.
addressSpecifies the starting address to write to.
lenSpecifies the length of the data to write.
dataPointer to a byte array that is to be written.
Return values
1Success
void flash_erase_block ( flash_t *  obj,
uint32_t  address 
)

Erase flash block(64KB)

Parameters
objFlash object define in application software.
addressSpecifies 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
objFlash object define in application software.
Return values
none
void flash_erase_sector ( flash_t *  obj,
uint32_t  address 
)

Erase flash sector.

Parameters
objFlash object define in application software.
addressSpecifies 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
objFlash 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
objFlash object define in application software.
Return values
The value of status register1.
void flash_global_lock ( void  )

This function is only for Winbond flash to lock whole flash chip.

Parameters
none
Return values
none
Note
But not all Winbond flash supports the function, plase refer to data sheets of the target flashes.
void flash_global_unlock ( void  )

This function is only for Winbond flash to unlock whole flash chip.

Parameters
none
Return values
none
Note
But not all Winbond flash supports the function, plase refer to data sheets of the target flashes.
void flash_individual_lock ( uint32_t  address)

This function is only for Winbond flash to lock individual sector or block region, should refer to the datasheet for more details.

Parameters
address
Return values
none
Note
But not all Winbond flash supports the function, plase refer to data sheets of the target flashes.
void flash_individual_unlock ( uint32_t  address)

This function is only for Winbond flash to unlock individual sector or block region, should refer to the datasheet for more details.

Parameters
address
Return values
none
Note
But not all Winbond flash supports the function, plase refer to data sheets of the target flashes.
int flash_read_id ( flash_t *  obj,
uint8_t *  buf,
uint8_t  len 
)

Get flash ID (command: 0x9F).

Parameters
objFlash object define in application software.
bufPointer to a byte array to save the readback ID.
lenSpecifies the length of the buf. It should be 3.
Return values
-1Fail.
int flash_read_individual_lock_state ( uint32_t  address)

This function is only for Winbond flash to get the individual lock state on certain address.

Parameters
address
Return values
1the target sector/block is locked. 0: the target sector/block is not locked.
Note
But not all Winbond flash supports the function, plase refer to data sheets of the target flashes.
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
objFlash object define in application software.
bufPointer to a byte array to save the readback unique ID.
lenSpecifies the length of the buf. It should be 8.
Return values
-1Fail.
int flash_read_word ( flash_t *  obj,
uint32_t  address,
uint32_t *  data 
)

Read a word from specified address.

Parameters
objFlash object define in application software.
addressSpecifies the address to read from.
dataSpecified the address to save the readback data.
Return values
1Success
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
objSpecifies 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
objFlash object define in application software.
dataSpecified which segment to choose.
Return values
1Success
void flash_set_lock_mode ( uint32_t  mode)

This function is only for Winbond flash to set lock mode.

Parameters
modeThis parameter can be 1 or 0.
  • 1: Enable individual sector / block protect feature.
  • 0: Set status register 1 to enble write protect feature.
Return values
none
Note
But not all Winbond flash supports the function, plase refer to data sheets of the target flashes.
int flash_set_status ( flash_t *  obj,
uint32_t  data 
)

Set Status register to enable desired operation.

Parameters
objSpecifies the parameter of flash object.
dataSpecifies which bit users like to set. ex: if users want to set the third bit, data = 0x8.
Return values
1Success
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
objFlash object define in application software.
addressSpecifies the starting address to read from.
lenSpecifies the length of the data to read.
dataSpecified the address to save the readback data.
Return values
1Success
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
objFlash object define in application software.
addressSpecifies the starting address to write to.
lenSpecifies the length of the data to write.
dataPointer to a byte array that is to be written.
Return values
1Success
void flash_write_protect ( flash_t *  obj,
uint32_t  protect 
)

Control the flash chip write protect enable/disable.

Parameters
objFlash object define in application software.
protectThis 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
objFlash object define in application software.
addressSpecifies the address to be programmed to.
dataSpecified the data to be programmed.
Return values
1Success
Note
user mode write used