SDK4.0
This document shows Ameba SDK 4.0 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...
 

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.
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_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
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