This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:ztex_boards:ztex_fpga_boards:sd_cards_on_series_2_fpga_boards [2014/07/21 12:51] – stefan | en:ztex_boards:ztex_fpga_boards:sd_cards_on_series_2_fpga_boards [2016/09/14 19:45] (current) – stefan | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== SD card support on Series 2 FPGA Boards ====== | + | ====== SD card support on FX2 based Series 2 FPGA Boards ====== |
+ | ZTEX uses the FX3S on its FPGA Boards. These boards have native SD card support (including SDIO). | ||
- | By introduction of [[http:// | + | On FX2 based based Series 2 FPGA Boards |
+ | |||
+ | This page described how this is done and how firmware support is activated. This is explained best by an example: | ||
A SD card is connected to an [[http:// | A SD card is connected to an [[http:// | ||
Line 12: | Line 15: | ||
| DO | B19 | H15 | → (out) | PA2 | H15 | | | DO | B19 | H15 | → (out) | PA2 | H15 | | ||
- | The HDL code for routing the signals | + | The HDL code for routing the signals |
<code ucf> | <code ucf> | ||
# ... | # ... | ||
+ | |||
NET " | NET " | ||
NET " | NET " | ||
Line 56: | Line 60: | ||
In order to enable firmware support the following lines have to be inserted between ''# | In order to enable firmware support the following lines have to be inserted between ''# | ||
+ | |||
+ | < | ||
+ | ENABLE_FLASH2; | ||
+ | # | ||
+ | # | ||
+ | // can be omitted if equal to input port) | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | From the firmware the SD card now can be accessed using the functions '' | ||
+ | |||
+ | From host software the SD card can be accessed using then functions [[http:// | ||
+ | |||
+ | Their usage can be explained with '' | ||
<code c> | <code c> | ||
+ | # | ||
+ | # | ||
+ | |||
+ | // select ZTEX USB FPGA Module 2.01 as target | ||
+ | IDENTITY_UFM_2_01(10.18.0.0, | ||
+ | |||
+ | // enable Flash support | ||
+ | ENABLE_FLASH; | ||
+ | ENABLE_FLASH_BITSTREAM; | ||
+ | |||
ENABLE_FLASH2; | ENABLE_FLASH2; | ||
# | # | ||
Line 66: | Line 97: | ||
# | # | ||
# | # | ||
+ | |||
+ | // this product string is also used for identification by the host software | ||
+ | # | ||
+ | |||
+ | __code char flash2_string[] = "Hello World!"; | ||
+ | |||
+ | // include the main part of the firmware kit, define the descriptors, | ||
+ | # | ||
+ | |||
+ | void main(void) | ||
+ | { | ||
+ | __xdata DWORD sector; | ||
+ | |||
+ | init_USB(); | ||
+ | |||
+ | if ( flash2_enabled ) { | ||
+ | flash2_read_init( 0 ); // prepare reading sector 0 | ||
+ | flash2_read((__xdata BYTE*) & | ||
+ | flash2_read_finish(flash2_sector_size - 4); // dummy-read the rest of the sector + finish read operation | ||
+ | |||
+ | sector++; | ||
+ | if ( sector > flash2_sectors || sector == 0 ) { | ||
+ | sector = 1; | ||
+ | } | ||
+ | |||
+ | flash2_write_init( 0 ); // prepare writing sector 0 | ||
+ | flash2_write((__xdata BYTE*) & | ||
+ | flash2_write_finish_sector(flash2_sector_size - 4); // dummy-write the rest of the sector + CRC | ||
+ | flash2_write_finish(); | ||
+ | |||
+ | flash2_write_init( sector ); // prepare writing sector sector | ||
+ | flash2_write((__xdata BYTE*) flash2_string, | ||
+ | flash2_write_finish_sector(flash2_sector_size - sizeof(flash2_string)); | ||
+ | flash2_write_finish(); | ||
+ | } | ||
+ | |||
+ | while (1) { } // | ||
+ | } | ||
</ | </ | ||
- | The SD card now can be accessed using the functions '' | + | and the host software is defined by |
+ | <code java> | ||
+ | import java.io.*; | ||
+ | import java.util.*; | ||
+ | import ch.ntb.usb.*; | ||
+ | |||
+ | import ztex.*; | ||
+ | |||
+ | // ***************************************************************************** | ||
+ | // ******* ParameterException ************************************************** | ||
+ | // ***************************************************************************** | ||
+ | // Exception the prints a help message | ||
+ | class ParameterException extends Exception { | ||
+ | public final static String helpMsg = new String ( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | | ||
+ | public ParameterException (String msg) { | ||
+ | super( msg + " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // ***************************************************************************** | ||
+ | // ******* Test0 *************************************************************** | ||
+ | // ***************************************************************************** | ||
+ | class FlashDemo extends Ztex1v1 { | ||
+ | |||
+ | // ******* FlashDemo *********************************************************** | ||
+ | // constructor | ||
+ | public FlashDemo ( ZtexDevice1 pDev ) throws UsbException { | ||
+ | super ( pDev ); | ||
+ | } | ||
+ | |||
+ | // ******* main **************************************************************** | ||
+ | public static void main (String args[]) { | ||
+ | | ||
+ | int devNum = 0; | ||
+ | boolean force = false; | ||
+ | boolean workarounds = false; | ||
+ | |||
+ | try { | ||
+ | // init USB stuff | ||
+ | LibusbJava.usb_init(); | ||
+ | |||
+ | // scan the USB bus | ||
+ | ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, | ||
+ | if ( bus.numberOfDevices() <= 0) { | ||
+ | System.err.println(" | ||
+ | System.exit(0); | ||
+ | } | ||
+ | | ||
+ | // scan the command line arguments | ||
+ | for (int i=0; i< | ||
+ | if ( args[i].equals(" | ||
+ | i++; | ||
+ | try { | ||
+ | if (i> | ||
+ | devNum = Integer.parseInt( args[i] ); | ||
+ | } | ||
+ | catch (Exception e) { | ||
+ | throw new ParameterException(" | ||
+ | } | ||
+ | } | ||
+ | else if ( args[i].equals(" | ||
+ | force = true; | ||
+ | } | ||
+ | else if ( args[i].equals(" | ||
+ | bus.printBus(System.out); | ||
+ | System.exit(0); | ||
+ | } | ||
+ | else if ( args[i].equals(" | ||
+ | workarounds = true; | ||
+ | } | ||
+ | else if ( args[i].equals(" | ||
+ | System.err.println(ParameterException.helpMsg); | ||
+ | System.exit(0); | ||
+ | } | ||
+ | else if ( !args[i].equals(" | ||
+ | throw new ParameterException(" | ||
+ | } | ||
+ | | ||
+ | |||
+ | // create the main class | ||
+ | FlashDemo ztex = new FlashDemo ( bus.device(devNum) ); | ||
+ | ztex.certainWorkarounds = workarounds; | ||
+ | | ||
+ | // upload the firmware if necessary | ||
+ | if ( force || ! ztex.valid() || ! ztex.dev().productString().equals(" | ||
+ | System.out.println(" | ||
+ | } | ||
+ | |||
+ | for (int i=0; i< | ||
+ | if ( args[i].equals(" | ||
+ | ztex.eepromDisable(); | ||
+ | } | ||
+ | else if ( args[i].equals(" | ||
+ | System.out.println(" | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | // print some information | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | ztex.printMmc2State(); | ||
+ | | ||
+ | if ( ztex.getFlash2EC() == ztex.FLASH_EC_PENDING ) { | ||
+ | System.out.print(" | ||
+ | int i = 20; | ||
+ | do { | ||
+ | System.out.print(" | ||
+ | try { | ||
+ | Thread.sleep( 1000 ); | ||
+ | } | ||
+ | catch ( InterruptedException e) { | ||
+ | } | ||
+ | i--; | ||
+ | } while ( ztex.getFlash2EC()==ztex.FLASH_EC_PENDING && i>0 ); | ||
+ | System.out.println(); | ||
+ | } | ||
+ | | ||
+ | byte[] buf = new byte[ztex.flash2SectorSize()]; | ||
+ | ztex.flash2ReadSector(0, | ||
+ | int sector = (buf[0] & 255) | ((buf[1] & 255) << 8) | ((buf[1] & 255) << 16) | ((buf[1] & 255) << 24); | ||
+ | System.out.println(" | ||
+ | |||
+ | ztex.flash2ReadSector(sector, | ||
+ | int i=0; | ||
+ | while ( buf[i] != ' | ||
+ | i++; | ||
+ | System.out.println(" | ||
+ | } | ||
+ | catch (Exception e) { | ||
+ | System.out.println(" | ||
+ | } | ||
+ | | ||
+ | |||
+ | } | ||
+ | </ |