How to use flash if uni

From steamWiki
Jump to: navigation, search

This guide describes how to use the flash_if_uni system (which consists of flash_if_uni.c and flash_if_uni.h).

flash_if_uni allows a designer a simple means of communicating with Atmel Flash products (AT49BV322A, AT49BV322AT, AT49BV322D, AT49BV322DT) from a Xilinx EDK (Microblaze) project.




DEFINES

When using flash_if_uni all options are controlled by #defines at the top of flash_if_uni.h. The following constants are defined.

  • FLASH_ADDR: This is the Base Address of the XPS_EMC_MCH Memory Controller IP Core in your EDK Project that connects to your Atmel Flash. This should be set to the constant given for the Base Address for the XPS_EMC_MCH in the xparameters.h file generated by EDK.
  • FLASH_RDY_ADDR: This is the Base Address of the XPS_GPIO General Purpose IO IP Core in your EDK Project that connects to the Ready line from your Atmel Flash. This should be set to the constant given for the Base Address for the appropriate XPS_GPIO in the xparameters.h file generated by EDK.
  • FLASH_RDY_MASK: This is a hex number describing which bit in the XPS_GPIO (that FLASH_RDY_ADDR points to) is connected to the Ready line from your Atmel Flash. If the Ready line is the only thing connected to the XPS_GPIO then this should be set to 0xFFFFFFFF
  • EDK_VERSION: This define specifies which version of the Xilinx EDK software you are using. Currently flash_if_uni supports EDK 10.1 and EDK 12.1. Valid values for this define are "10" and "12".
  • DATA_WIDTH: This define specifies how wide your flash interface is. It currently supports 16-bit and 32-bit operation. Valid values afor this define are "16" and "32".


TYPEDEFS

There is, currently, a single typedef in flash_if_uni.h to account for the choice between 16-bit and 32-bit operation. f_data_type is either Xuint16 or Xuint32 based on the value of DATA_WIDTH.

FUNCTIONS

The following functions exist within flash_if_uni. Functions shown in italics are internal and not meant to be called by the end user.

  • void flash_init(void);
    This runs initialization code for EDK 10. This does nothing in 12 but won't hurt anything.
  • void erase_flash(void);
    This allows you to erase the entire Flash.
  • void erase_flash_sector(Xuint32 ui_sector_num);
    This allows you to erase only a single sector in Flash. ui_sector_num is a passed parameter with a value from 0 to 69.
  • void write_flash_data(Xuint32 ui_waddr, f_data_type us_wdata);
    This allows you to write to a single Flash address. You must pass it a valid address and data word.
    • ui_waddr must be from 0 to 2,097,151
    • ui_wdata must be an Xuint16 if DATA_WIDTH == 16 and an Xuint32 if DATA_WIDTH == 32
  • f_data_type read_flash_data(Xuint32 ui_raddr);
    This function allows you to read a single data value from a single Flash address.
    • ui_raddr must be from 0 to 2,097,151
    • This function will return an Xuint16 if DATA_WIDTH == 16 and an Xuint32 if DATA_WIDTH == 32
  • void _flash_write_cycle(Xuint32 ui_waddr, f_data_type us_wdata);
    This function is internal and not meant to be run by an end user. It write an address/data pair to the Flash. However, actual reads and writes require multiple, specially crafted write cycles in sequence.
  • Xint32 flash_busy(void);
    This checks to see if the Flash is busy completing an operation. It is used extensively by flash_if_uni (internally). But can be polled by a user to wait for things like an erase operation to complete. It returns a '1' if the part is busy and a '0' if the part is ready.
  • Xuint32 get_edk_version(void);
    This function simply returns the value of EDK_VERSION.
  • Xuint32 get_data_width(void);
    This function simply returns the value of DATA_WIDTH.