Forum: FPGA, VHDL & Co. XPS SPI Core und SD Karte


von Christian F. (christianf)


Lesenswert?

Moin !

Ich wollte mal fragen ob einer von Euch mittels Microblaze und XPS SPI 
Core eine SD Karte angesprochen bekommen hat.
Hab im Internet gefunden das es wohl nicht geht?


Gruss !

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Christian F. schrieb:
> Hab im Internet gefunden das es wohl nicht geht?
Und warum nicht?
> mittels Microblaze und XPS SPI Core eine SD Karte angesprochen
Nicht, dass ich diese spezielle Kombination am Laufen hätte, aber: warum 
sollte das nicht gehen? SPI an die Karte und ein uC zur Verwaltung. So 
wird das weltweit gemacht.

von Christian F. (christianf)


Lesenswert?

Moin und zwar hat einer in seiner Bachelorarbeit sowas (bzw. genau das) 
in der Art gemacht.

Zitat :

Um die SD Karte anzusteuern, wurde ein eigener SPI-Core entwickelt, da 
der XPS-SPI-Core nicht
flexibel genug ist, um SD-Karten anzusprechen. Das erste Problem war, 
dass bei jedem
Sendevorgang automatisch der eingestellte Slave selektiert wurde. Die 
SD-Ansteuerung erfordert
aber jeweils am Anfang des zu sendenden Kommandos 8 Takte im inaktiven 
Zustand der SD-Karte.

Keine Ahnung woher er das hat, sind damit die ~80 Dummybytes am Anfang 
der Initialisierung gemeint?


Gruss !

von Christian F. (christianf)


Lesenswert?

Also meine initialisierung sähe so aus (kleiner Ausschnitt eines 
Beispieles aus SP605 Board mit CF Karte ) :
1
/***************************** Include Files *********************************/
2
3
#include "xparameters.h"  /* EDK generated parameters */
4
#include "xspi.h"    /* SPI device driver */
5
#include "mb_interface.h"  /* Microblaze interface */
6
#include "xuartns550_l.h"
7
8
9
/*
10
 * The following constants map to the XPAR parameters created in the
11
 * xparameters.h file. They are defined here such that a user can easily
12
 * change all the needed parameters in one place.
13
 */
14
#define SPI_DEVICE_ID      XPAR_SPI_0_DEVICE_ID
15
16
17
static XSpi Spi;
18
19
/*
20
 * Initialize the SPI driver so that it's ready to use,
21
* specify the device ID that is generated in xparameters.h.
22
*/
23
24
status = XSpi_Initialize(&Spi, SPI_DEVICE_ID);
25
if(Status != XST_SUCCESS) {\
26
     xil_printf("Failure INIT\r\n");
27
  return XST_FAILURE;
28
}
29
30
31
/*
32
   * Set the SPI device as a master and in manual slave select mode such
33
   * that the slave select signal does not toggle for every byte of a
34
   * transfer, this must be done before the slave select is set.
35
   */
36
  Status = XSpi_SetOptions(&Spi, XSP_MASTER_OPTION |
37
            XSP_MANUAL_SSELECT_OPTION);
38
  if(Status != XST_SUCCESS) {
39
       xil_printf("Failure Options\r\n");
40
    return XST_FAILURE;
41
  }
42
43
  /*
44
   * Select the STM flash device on the SPI bus, so that it can be
45
   * read and written using the SPI bus.
46
   */
47
  Status = XSpi_SetSlaveSelect(&Spi, STM_SPI_SELECT);
48
  if(Status != XST_SUCCESS) {
49
       xil_printf("Failure Slave Select\r\n");
50
    return XST_FAILURE;
51
  }
52
53
  /*
54
   * Start the SPI driver so that interrupts and the device are enabled.
55
   */
56
  XSpi_Start(&Spi);

von Christian F. (christianf)


Lesenswert?

Moin.

Hab noch mal rumgewerkelt und es sollte in etwa so laufen:

Das einzige Problem das ich habe, ist die Xspi_transfer Funktion.

Sofern irgendeiner schon mit der Xspi.h Xspi.c Bibliothek gearbeitet 
hat. Bitte melden :)
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
  }

von Christian F. (christianf)


Lesenswert?

Gibt es keinen hier der schonmal mit dem SPI Core versucht hat eine SD 
Karte anzusprechen? :(

Gruss !

von Duke Scarring (Gast)


Lesenswert?

Christian F. schrieb:
> Gibt es keinen hier der schonmal mit dem SPI Core versucht hat eine SD
> Karte anzusprechen? :(
Sieht nicht so aus. Wo hängt es denn jetzt? Kann doch nicht so schwer 
sein. Machen hier im Forum doch alle mit AVR & Co.

Duke

von Christian F. (christianf)


Lesenswert?

Naja das Problem das ich habe ist der SPI Core an sich und die Xilinx 
Treiber.

Es gibt vorgefertigte Funktionen wie z.B. XSpi_Transfer etc.

Allerdings ist es dort wohl kritisch in Sachen CS Signal.

Jedenfalls hat es wohl einer damit versucht :

Beitrag "SD Karte Spartan 3A XPS_SPI Modul"

Allerdings keine Ahnung wo genau da sein Problem ist.


Es hakt halt in der Timing Sache, also z.B. 80x Dummyclock Senden ohne 
die SD Karte anzusprechen.

Das geht wohl nicht, da die XSpi_Transfer funktion immer ein Slave 
eingestellt haben will und ansonsten:
1
/*
2
   * If configured as a master, be sure there is a slave select bit set
3
   * in the slave select register. If no slaves have been selected, the
4
   * value of the register will equal the mask.  When the device is in
5
   * loopback mode, however, no slave selects need be set.
6
   */
7
  if (ControlReg & XSP_CR_MASTER_MODE_MASK) {
8
    if ((ControlReg & XSP_CR_LOOPBACK_MASK) == 0) {
9
      if (InstancePtr->SlaveSelectReg ==
10
        InstancePtr->SlaveSelectMask) {
11
        if (GlobalIntrReg == TRUE) {
12
          /* Interrupt Mode of operation */
13
          XSpi_IntrGlobalEnable(InstancePtr);
14
        }
15
        return XST_SPI_NO_SLAVE;
16
      }
17
    }
18
  }

Es ist halt schwierig zu erklären, deswegen habe ich gehofft das einer 
sich mit dem XPS SPI Core auseinandergesetzt hat.

von Duke Scarring (Gast)


Angehängte Dateien:

Lesenswert?

Hast Du einen Simulator? Hast Du einen Logic-Analyzer?

Meine Simulation und die Messung auf der Hardware habe ich mal 
angehangen. Ich verwende allerdings den SPI-Flash (im 2x-Mode) auf dem 
SP601 Eval-Board. Angesteuert wird der Chip von spimctrl aus der grlib.

Ich hab das Ganze solange simuliert bis es gut aussah; dann erst bin ich 
auf die Hardware gegangen.

Duke

von Christian F. (christianf)


Lesenswert?

Hi,

Ich könnte auf ChipScope zugreifen. Allerdings habe ich noch nie damit 
gearbeitet.

Ich glaub ich werde nicht die Xilinx Treiber nehmen, sondern die low 
level Treiber auf denen auch dieses Treiber existieren.

Dann schreibe ich direkt in die Register und erzeuge mir so eine low 
level Routine zum Schreiben/Lesen eines Bytes.

Das ist dazu die Beschreibung des Cores :

http://www.xilinx.com/support/documentation/ip_documentation/xps_spi.pdf

Nur versteh ich da nicht die Verwendung vom CS Signal (einfach SPISSR 
auf Low ? ) sowie den genauen Start eines Transferes ( Clock wird 
erzeugt? ).

" Angesteuert wird der Chip von spimctrl aus der grlib." = ? :)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.