Proxmark3 community

Research, development and trades concerning the powerful Proxmark3 device.

Remember; sharing is caring. Bring something back to the community.


"Learn the tools of the trade the hard way." +Fravia

You are not logged in.

Announcement

Time changes and with it the technology
Proxmark3 @ discord

Users of this forum, please be aware that information stored on this site is not private.

#1 2010-09-22 04:08:57

mb300sd
Member
Registered: 2010-09-19
Posts: 6

Connecting a SPI EEPROM

I'm trying to attach a SPI EEPROM to my proxmark and modify the standalone mode to persist through power loss... The EEPROM is a Microchip 22AA1024, and I have only implemented byte read/write and chip erase. I simply hot-glued the EEPROM to the top of the MCU and used magnet wire to connect the pins.

Heres a diff from the current svn if anyone is interested.

Index: armsrc/EEPROM.c
===================================================================
--- armsrc/EEPROM.c  (revision 0)
+++ armsrc/EEPROM.c  (revision 0)
@@ -0,0 +1,70 @@
+#include "proxmark3.h"
+#include "apps.h"
+#include "EEPROM.h"
+
+uint8_t EEPROMSend(uint8_t data, uint8_t endOfTransfer)
+{
+  // 9th bit set for data, clear for command
+  while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0);  // wait for the transfer to complete
+  
+  AT91C_BASE_SPI->SPI_TDR = data;              // Send the data/command
+
+  while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0);  // wait for the transfer to complete
+
+  return AT91C_BASE_SPI->SPI_RDR;
+
+  // Wait for SPI to raise the CS line
+  if (endOfTransfer == 1) {
+    SpinDelay(10);
+  }
+}
+
+uint8_t EEPROMReadByte (uint32_t address)
+{
+  // Wait for chip to be ready
+  EEPROMBusyWait();
+
+  // Read Byte
+  EEPROMSend(EEPROM_READ, 0);
+  EEPROMSend((address >> 16) & 0xFF, 0);
+  EEPROMSend((address >>  8) & 0xFF, 0);
+  EEPROMSend(address & 0xFF, 0);
+  return EEPROMSend(0, 1);
+}
+
+void EEPROMWriteByte (uint32_t address, uint8_t data)
+{
+  // Wait for chip to be ready
+  EEPROMBusyWait();
+
+  // Write Enable
+  EEPROMSend(EEPROM_WREN, 1);
+
+  // Write Byte
+  EEPROMSend(EEPROM_WRITE, 0);
+  EEPROMSend((address >> 16) & 0xFF, 0);
+  EEPROMSend((address >>  8) & 0xFF, 0);
+  EEPROMSend(address & 0xFF, 0);
+  EEPROMSend(data, 1);
+
+}
+
+void EEPROMChipErase (void)
+{
+  // Wait for chip to be ready
+  EEPROMBusyWait();
+
+  // Erase Chip
+  EEPROMSend(EEPROM_CE, 1);
+}
+
+void EEPROMBusyWait (void) {
+  do {
+    EEPROMSend(EEPROM_RDSR, 0);
+  }while (EEPROMSend(0, 1) & 0x01);
+}
+
+void EEPROMInit (void)
+{
+  SetupSpi(SPI_EEPROM_MODE);
+}
\ No newline at end of file
Index: armsrc/EEPROM.h
===================================================================
--- armsrc/EEPROM.h  (revision 0)
+++ armsrc/EEPROM.h  (revision 0)
@@ -0,0 +1,25 @@
+#ifndef __EEPROM_H
+#define __EEPROM_H
+
+
+// Microchip 25AA1024
+#define EEPROM_READ    0x03
+#define EEPROM_WRITE  0x02
+#define EEPROM_WREN    0x06
+#define EEPROM_WRDI    0x04
+#define EEPROM_RDSR    0x05
+#define EEPROM_WRSR    0x01
+#define EEPROM_PE    0x42
+#define EEPROM_SE    0xD8
+#define EEPROM_CE    0xC7
+#define EEPROM_RDID    0xAB
+#define EEPROM_DPD    0xB9
+
+#endif
+
+uint8_t EEPROMSend(uint8_t data, uint8_t endOfTransfer);
+uint8_t EEPROMReadByte (uint32_t address);
+void EEPROMWriteByte (uint32_t address, uint8_t data);
+void EEPROMChipErase (void);
+void EEPROMBusyWait (void);
+void EEPROMInit (void);
\ No newline at end of file
Index: armsrc/fpgaloader.c
===================================================================
--- armsrc/fpgaloader.c  (revision 447)
+++ armsrc/fpgaloader.c  (working copy)
@@ -21,6 +21,7 @@
 //-----------------------------------------------------------------------------
 void SetupSpi(int mode)
 {
+  // PA5  -> SPI_NCS3 chip select (EEPROM)
   // PA10 -> SPI_NCS2 chip select (LCD)
   // PA11 -> SPI_NCS0 chip select (FPGA)
   // PA12 -> SPI_MISO Master-In Slave-Out
@@ -31,6 +32,7 @@
   AT91C_BASE_PIOA->PIO_PDR =
     GPIO_NCS0  |
     GPIO_NCS2   |
+    GPIO_NCS3  |
     GPIO_MISO  |
     GPIO_MOSI  |
     GPIO_SPCK;
@@ -41,7 +43,9 @@
     GPIO_MOSI  |
     GPIO_SPCK;
 
-  AT91C_BASE_PIOA->PIO_BSR = GPIO_NCS2;
+  AT91C_BASE_PIOA->PIO_BSR = 
+    GPIO_NCS2  |
+    GPIO_NCS3;
 
   //enable the SPI Peripheral clock
   AT91C_BASE_PMC->PMC_PCER = (1<<AT91C_ID_SPI);
@@ -85,6 +89,24 @@
         ( 1 << 1)  |  // Clock Phase data captured on leading edge, changes on following edge
         ( 0 << 0);    // Clock Polarity inactive state is logic 0
       break;
+    case SPI_EEPROM_MODE:
+      AT91C_BASE_SPI->SPI_MR =
+        ( 0 << 24)  |  // Delay between chip selects (take default: 6 MCK periods)
+        ( 7 << 16)  |  // Peripheral Chip Select (selects EEPROM SPI_NCS3 or PA5)
+        ( 0 << 7)  |  // Local Loopback Disabled
+        ( 1 << 4)  |  // Mode Fault Detection disabled
+        ( 0 << 2)  |  // Chip selects connected directly to peripheral
+        ( 0 << 1)   |  // Fixed Peripheral Select
+        ( 1 << 0);    // Master Mode
+      AT91C_BASE_SPI->SPI_CSR[3] =
+        ( 1 << 24)  |  // Delay between Consecutive Transfers (32 MCK periods)
+        ( 1 << 16)  |  // Delay Before SPCK (1 MCK period)
+        ( 6 << 8)  |  // Serial Clock Baud Rate (baudrate = MCK/6 = 24Mhz/6 = 4M baud
+        ( 0 << 4)  |  // Bits per Transfer (8 bits)
+        ( 0 << 3)  |  // Chip Select inactive after transfer
+        ( 1 << 1)  |  // Clock Phase data captured on leading edge, changes on following edge
+        ( 0 << 0);    // Clock Polarity inactive state is logic 0
+      break;
     default:        // Disable SPI
       AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS;
       break;
Index: include/config_gpio.h
===================================================================
--- include/config_gpio.h  (revision 447)
+++ include/config_gpio.h  (working copy)
@@ -19,6 +19,7 @@
 #define GPIO_LRST      AT91C_PIO_PA7
 #define GPIO_LED_B      AT91C_PIO_PA8
 #define GPIO_LED_C      AT91C_PIO_PA9
+#define GPIO_NCS3      AT91C_PA5_NPCS3
 #define GPIO_NCS2      AT91C_PA10_NPCS2
 #define GPIO_NCS0      AT91C_PA11_NPCS0
 #define GPIO_MISO      AT91C_PA12_MISO
Index: include/proxmark3.h
===================================================================
--- include/proxmark3.h  (revision 447)
+++ include/proxmark3.h  (working copy)
@@ -56,6 +56,7 @@
 
 #define SPI_FPGA_MODE  0
 #define SPI_LCD_MODE  1
+#define SPI_EEPROM_MODE  2
 
 #define TRUE 1
 #define FALSE 0

Last edited by mb300sd (2010-09-22 04:12:52)

Offline

#2 2010-11-01 10:29:18

atrox
Contributor
Registered: 2010-01-08
Posts: 35

Re: Connecting a SPI EEPROM

my wish for the next proxmark board layout: feature some spi/i2c/gpio pins to connect external components.

Offline

Board footer

Powered by FluxBB