1 | #include "xparameters.h" /* EDK generated parameters */
|
2 | #include "xspi.h" /* SPI device driver */
|
3 | #include "mb_interface.h" /* Microblaze interface */
|
4 |
|
5 | /*
|
6 | * The following constants map to the XPAR parameters created in the
|
7 | * xparameters.h file. They are defined here such that a user can easily
|
8 | * change all the needed parameters in one place.
|
9 | */
|
10 | #define SPI_DEVICE_ID XPAR_SPI_0_DEVICE_ID
|
11 |
|
12 | /*
|
13 | * The following constant defines the slave select signal that is used to
|
14 | * to select the Flash device on the SPI bus, this signal is typically
|
15 | * connected to the chip select of the device.
|
16 | */
|
17 | #define STM_SPI_SELECT 0x01 // 0x01 for Port 1 CS ?
|
18 | /*
|
19 | * The instances to support the device drivers are global such that they
|
20 | * are initialized to zero each time the program runs. They could be local
|
21 | * but should at least be static so they are zeroed.
|
22 | */
|
23 | static XSpi Spi;
|
24 |
|
25 | /*
|
26 | * Initialize the SPI driver so that it's ready to use,
|
27 | * specify the device ID that is generated in xparameters.h.
|
28 | */
|
29 | Status = XSpi_Initialize(&Spi, SPI_DEVICE_ID);
|
30 | if(Status != XST_SUCCESS) {\
|
31 | xil_printf("Failure INIT\r\n");
|
32 | return XST_FAILURE;
|
33 | }
|
34 | /*
|
35 | * Set the SPI device as a master and in manual slave select mode such
|
36 | * that the slave select signal does not toggle for every byte of a
|
37 | * transfer, this must be done before the slave select is set.
|
38 | */
|
39 | Status = XSpi_SetOptions(&Spi, XSP_MASTER_OPTION |
|
40 | XSP_MANUAL_SSELECT_OPTION);
|
41 | if(Status != XST_SUCCESS) {
|
42 | xil_printf("Failure Options\r\n");
|
43 | return XST_FAILURE;
|
44 | }
|
45 | /*
|
46 | * Select the device on the SPI bus, so that it can be
|
47 | * read and written using the SPI bus.
|
48 | */
|
49 | Status = XSpi_SetSlaveSelect(&Spi, STM_SPI_SELECT);
|
50 | if(Status != XST_SUCCESS) {
|
51 | xil_printf("Failure Slave Select\r\n");
|
52 | return XST_FAILURE;
|
53 | }
|
54 | /*
|
55 | * Start the SPI driver so that the device are enabled.
|
56 | */
|
57 | XSpi_Start(&Spi);
|
58 |
|
59 | // ****************** SD INIT ***********************
|
60 | /*
|
61 | * Prepare the WriteBuffer.
|
62 | */
|
63 | WriteBuffer[BYTE1] = CMD 0;
|
64 | WriteBuffer[BYTE2] = Argument Byte 1/4;
|
65 | WriteBuffer[BYTE3] = Argument Byte 2/4;
|
66 | WriteBuffer[BYTE4] = Argument Byte 3/4;
|
67 | WriteBuffer[BYTE5] = Argument Byte 4/4;
|
68 | WriteBuffer[BYTE6] = CRC BYTE
|
69 |
|
70 |
|
71 | /*
|
72 | * Initiate the Transfer.
|
73 | */
|
74 | TransferInProgress = TRUE;
|
75 | Status = XSpi_Transfer(SpiPtr, WriteBuffer, NULL,
|
76 | STM_WRITE_ENABLE_BYTES);
|
77 | if(Status != XST_SUCCESS) {
|
78 | xil_printf("Error in transfer\r\n");
|
79 | return XST_FAILURE;
|
80 | }
|