---
# System prepended metadata

title: SDK Guideline
tags: [CAIDLAB]

---

# SDK Guideline
## Check if setup/hold time is correct then follow the steps
### Step 1 : Export hardware for SDK
* File -> Export -> Export hardware 並勾選 include bitstream
![image](https://hackmd.io/_uploads/ryEVp4jrT.png =x400)
![image](https://hackmd.io/_uploads/ByM_TNsST.png =x200)

### Step 2 : Launch SDK and write data into BRAM
#### Initial the environment
* File -> Launch SDK
![image](https://hackmd.io/_uploads/HymJR4jHp.png =x300)
* File -> New -> Application
![image](https://hackmd.io/_uploads/HJgcJHora.png =x300)
* Click "New" to create environment with .hdf file
![image](https://hackmd.io/_uploads/BJPh1SsBT.png =x300)
* Type the env. name at $1.$ & include the .hdf file at $2.$
![image](https://hackmd.io/_uploads/BkhkgSira.png =x300)
* Type the project name & Click next
![image](https://hackmd.io/_uploads/SJRBlSsH6.png =x300)
* Choose the proper template(We chose Empty Application)
![image](https://hackmd.io/_uploads/SylOlHsH6.png =x300)
#### Write the .c code for data movement into BRAM
* "your_file" -> src -> new -> file
![image](https://hackmd.io/_uploads/BkTEzroST.png =x300)
* Type the code for Bram writing
  * from DRAM to BRAM, then get data from BRAM to DRAM check if it's successful
  :::spoiler
  ```clike=
  #include "xil_printf.h"
  #include "xparameters.h"
  #include "xaxicdma.h"
  #include "xil_cache.h"
  #include "xil_io.h"

  #define PL_BRAM_Addr 0xC0000000
  #define PL_BRAM_Addr2 0xC2000000
  #define PL_BRAM_Addr3 0x45800000
  #define BUFF_LEN  3136  //28*28*4

  XAxiCdma_Config *axi_cdma_cfg;
  XAxiCdma axi_cdma;
  static int SourceAddr  = 0x11000000;
  static int DestAddr    = 0x12000000;
  static int DestAddr2   = 0x12000070;

  int main()
  {
  //    init_platform();
    print("Initial start......\n\r");

    int Status;
    int *SrcPtr;
    int *DestPtr;

    SrcPtr = (int*)SourceAddr;
    DestPtr = (int*)DestAddr;
    
    static int Array_0[28][28];
    int i,j;
    for (i=0;i<28;i++){
    	for (j=0;j<28;j++){
    		Array_0[i][j] = (i*28+j);
    	}
    }

    for (i=0;i<28;i++){
    	for (j=0;j<28;j++){
    		SrcPtr[i*28+j] = Array_0[i][j];
    		DestPtr[i*28+j] = 0;
    	}
    }

    printf("Original SRC_DDR DATA\n\r");
	for(i=0;i<28*1;i++){
		printf("%d  %d at %x\n\r",i,SrcPtr[i],&SrcPtr[i]);
	}
	printf("-------------------------------------------------\n\r");
	printf("Original DEST_DDR DATA\n\r");
	for(i=0;i<28*1;i++){
		printf("%d  %d at %x\n\r",i,DestPtr[i],&DestPtr[i]);
	}
    int *tx_buffer = (int *) SrcPtr;
    int *rx_buffer1 = (int *) PL_BRAM_Addr3;
    u32 *tx_buffer2 = (u32 *) PL_BRAM_Addr3;
    u32 *rx_buffer3 = (u32 *) DestAddr;

    // Set up the AXI CDMA
    for (i=0;i<28;i++){
        for (j=0;j<28;j++){
        	SrcPtr[i*28+j] = 999;     // 1100_0000
        }
    }

    printf("--Set up the AXI CDMA from DDR to BRAM3\n\r");
    axi_cdma_cfg = XAxiCdma_LookupConfig(XPAR_AXICDMA_0_DEVICE_ID);
    if (!axi_cdma_cfg) {
        printf("AXAxiCdma_LookupConfig failed\n\r");
    }

    Status = XAxiCdma_CfgInitialize(&axi_cdma, axi_cdma_cfg, axi_cdma_cfg->BaseAddress);
    if (Status == XST_SUCCESS ){
        printf("XAxiCdma_CfgInitialize succeed\n\r");
    }
    printf("--Disable Interrupt of AXI CDMA\n\r");
        XAxiCdma_IntrDisable(&axi_cdma, XAXICDMA_XR_IRQ_ALL_MASK);

    if (XAxiCdma_IsBusy(&axi_cdma)) {
    printf("AXI CDMA is busy...\n\r");
    while (XAxiCdma_IsBusy(&axi_cdma));
    }


	Xil_DCacheFlush();
	Status = XAxiCdma_SimpleTransfer(
		&axi_cdma,
		(u32) tx_buffer,
		(u32) rx_buffer1,
		BUFF_LEN,
		NULL,
		NULL);
	Xil_DCacheFlush();

    printf("transaction from DDR to BRAM1 is done\n\r");

  // Set up the AXI CDMA
	printf("--Set up the AXI CDMA from BRAM3 to DDR\n\r");
	axi_cdma_cfg = XAxiCdma_LookupConfig(XPAR_AXICDMA_0_DEVICE_ID);
	if (!axi_cdma_cfg) {
    	printf("AXAxiCdma_LookupConfig failed\n\r");
	}

    Status = XAxiCdma_CfgInitialize(&axi_cdma, axi_cdma_cfg, axi_cdma_cfg->BaseAddress);
    if (Status == XST_SUCCESS ){
        printf("XAxiCdma_CfgInitialize succeed\n\r");
    }
    printf("--Disable Interrupt of AXI CDMA\n\r");
    XAxiCdma_IntrDisable(&axi_cdma, XAXICDMA_XR_IRQ_ALL_MASK);

    if (XAxiCdma_IsBusy(&axi_cdma)) {
    printf("AXI CDMA is busy...\n\r");
    while (XAxiCdma_IsBusy(&axi_cdma));
    }


	Xil_DCacheFlush();
	Status = XAxiCdma_SimpleTransfer(
		&axi_cdma,
		(u32) tx_buffer2,
		(u32) rx_buffer3,
		BUFF_LEN/28,
		NULL,
		NULL);
	Xil_DCacheFlush();

	printf("transaction from BRAM1 to DDR is done\n\r");

	for(i=0;i<28;i++){
	    if (i == 0){
    	    printf("Data transfer from BRAM3 to DEST_DDR[0]~[27]\n\r");
            }
	    printf("%d  %d at %x\n\r",i,rx_buffer3[i],&rx_buffer3[i]);
	}

    return 0;
  }
  ```
  ::: 
#### Connect the ternimal with your device
* Open Setting in your computer & find the USB port number(COMX)
![image](https://hackmd.io/_uploads/rJOQrriH6.png =x300)
* Open terminal : Window -> Show view -> Other
![image](https://hackmd.io/_uploads/ByQKSSjB6.png =x300)
* Click "New Terminal Connection"
![image](https://hackmd.io/_uploads/Sy3NISjr6.png )
* Choose your USB port & set **Buad Rate =115200**
![image](https://hackmd.io/_uploads/SkFO8Sjra.png =x300)
* Then it shows CONNECT
![image](https://hackmd.io/_uploads/SJjhIHorp.png)
#### Program & run your code
* Clik "Program FPGA" in tool bar
![image](https://hackmd.io/_uploads/B1Y1vrsBp.png)
* Then run your code
![image](https://hackmd.io/_uploads/r15fDBoSa.png)


### Step  Open Hardware Manager
* Click open target -> Auto Connect 
![image](https://hackmd.io/_uploads/B1N-2EiBa.png)
* Then Program Device -> xc7z020_1 -> program
![image](https://hackmd.io/_uploads/BJ7Un4irT.png)
![image](https://hackmd.io/_uploads/r11F2ViHa.png)
* Finally 
