Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Apr 2006 15:52:15 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 96066 for review
Message-ID:  <200604251552.k3PFqFK8086159@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=96066

Change 96066 by imp@imp_hammer on 2006/04/25 15:52:09

	HOLY SHIT!  THIS WORKS NOW!  Wonder what I changed.

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/boot0spi/main.c#5 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.c#5 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.h#5 edit

Differences ...

==== //depot/projects/arm/src/sys/boot/arm/at91/boot0spi/main.c#5 (text) ====

@@ -35,47 +35,44 @@
 {
 	char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */
 	int len, i;
-#if 0
+#if 1
 	char *addr2 = (char *)SDRAM_BASE + (2 << 20); /* Load to base + 2MB */
-	unsigned this_sec;
+	char *addr3 = (char *)SDRAM_BASE + (3 << 20); /* Load to base + 2MB */
 #endif
+//	unsigned this_sec;
 
-	printf("b4\r\n");
 	SPI_InitFlash();
-	printf("after\r\n");
 #if 0
 	while ((len = xmodem_rx(addr)) == -1)
 		continue;
 #else
 	len = FLASH_PAGE_SIZE;
 	for (i = 0; i < FLASH_PAGE_SIZE; i++)
-		addr[i] = i;
-	SPI_GetId(0);
-	printf("Memory after init:\r\n");
-	for (i = 0; i < 4; i++)
-		printf("0x%x ", addr[i]);
-	printf("\r\n");
+		addr[i] = i * 3;
+	SPI_GetId(&i);
+	printf("I is %x\r\n", i);
 #endif
-#if 0
-	while (1) {
+#if 1
+//	while (1) {
+		p_memcpy(addr3, addr, len);
 		printf("Writing %u bytes to flash\r\n", len);
 		SPI_WriteFlash(FLASH_PAGE_SIZE, addr, len);
 		printf("Reading back %u bytes from flash\r\n", len);
 		SPI_ReadFlash(FLASH_PAGE_SIZE, addr2, len);
-		if (p_memcmp(addr, addr2, len) != 0) {
+		if (p_memcmp(addr3, addr2, len) != 0) {
 			printf("Readback failed:\r\n");
-			for (i = 0; i < 4; i++)
-				printf("0x%x ", addr[i]);
-			printf("\r\n");
-			for (i = 0; i < 4; i++)
-				printf("0x%x ", addr2[i]);
+			for (i = 0; i < 75; i++)
+				printf("%x ", addr[i]);
+			printf("\r\n----------\r\n");
+			for (i = 0; i < 75; i++)
+				printf("%x ", addr2[i]);
 			printf("\r\n");
 		} else
 			printf("Readback OK\r\n");
-		this_sec = GetSeconds() + 1;
-		while (GetSeconds() < this_sec)
-			continue;
-	}
+//		this_sec = GetSeconds() + 1;
+//		while (GetSeconds() < this_sec)
+//			continue;
+//	}
 #endif
 	return (1);
 }

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.c#5 (text+ko) ====

@@ -42,37 +42,31 @@
 static void
 SendCommand(spiCommand_t *pCommand)
 {
-	unsigned	value, i;
+	unsigned	i, v;
 
 	AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTDIS | AT91C_PDC_RXTDIS;
 
 	AT91C_BASE_SPI->SPI_RPR = (unsigned)pCommand->rx_cmd;
+	AT91C_BASE_SPI->SPI_RCR = pCommand->rx_cmd_size;
 	AT91C_BASE_SPI->SPI_TPR = (unsigned)pCommand->tx_cmd;
-
-	AT91C_BASE_SPI->SPI_RCR = pCommand->rx_cmd_size;
 	AT91C_BASE_SPI->SPI_TCR = pCommand->tx_cmd_size;
 
-	if (pCommand->tx_data_size != 0) {
+	AT91C_BASE_SPI->SPI_TNPR = (unsigned)pCommand->tx_data;
+	AT91C_BASE_SPI->SPI_TNCR = pCommand->tx_data_size;
+	AT91C_BASE_SPI->SPI_RNPR = (unsigned)pCommand->rx_data;
+	AT91C_BASE_SPI->SPI_RNCR = pCommand->rx_data_size;
 
-		AT91C_BASE_SPI->SPI_TNPR = (unsigned)pCommand->tx_data;
-		AT91C_BASE_SPI->SPI_TNCR = pCommand->tx_data_size;
-		AT91C_BASE_SPI->SPI_RNPR = (unsigned)pCommand->rx_data;
-		AT91C_BASE_SPI->SPI_RNCR = pCommand->rx_data_size;
-	} else {
-		AT91C_BASE_SPI->SPI_TNPR = 0;
-		AT91C_BASE_SPI->SPI_TNCR = 0;
-		AT91C_BASE_SPI->SPI_RNPR = 0;
-		AT91C_BASE_SPI->SPI_RNCR = 0;
-	}
+	AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN;
 
-	AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTEN + AT91C_PDC_RXTEN;
-
-	printf("Wait complete\r\n");
 	// wait for completion
-	i = 1000000;
-	while (!((value = AT91C_BASE_SPI->SPI_SR) & AT91C_SPI_SPENDRX) &&
-	    i > 0) i--;
-	printf("Done %x\r\n", value);
+	i = 100000;
+	while (!((v = AT91C_BASE_SPI->SPI_SR) & AT91C_SPI_SPENDRX) && --i > 0) {
+		if ((v & 0xffff) != 0)
+			printf("V is 0x%x\r\n", v);
+		continue;
+	}
+	if (i == 0)
+		printf("STALLED! %x\r\n", AT91C_BASE_SPI->SPI_SR);
 }
 
 
@@ -90,14 +84,14 @@
 	tx_commandBuffer[0] = STATUS_REGISTER_READ;
 	p_memset(rx_commandBuffer, 0, 8);
 	spi_command.tx_data_size = 0;
+	spi_command.tx_data = 0;
 	spi_command.rx_data_size = 0;
+	spi_command.rx_data = 0;
 	spi_command.tx_cmd = tx_commandBuffer;
 	spi_command.rx_cmd = rx_commandBuffer;
 	spi_command.rx_cmd_size = 2;
 	spi_command.tx_cmd_size = 2;
 	SendCommand(&spi_command);
-
-	printf("FlashStatus is %x\r\n", rx_commandBuffer[1]);
 	return (rx_commandBuffer[1]);
 }
 
@@ -109,15 +103,16 @@
 	tx_commandBuffer[0] = 0x9f;
 	p_memset(rx_commandBuffer, 0, 8);
 	spi_command.tx_data_size = 0;
+	spi_command.tx_data = 0;
 	spi_command.rx_data_size = 0;
+	spi_command.rx_data = 0;
 	spi_command.tx_cmd = tx_commandBuffer;
 	spi_command.rx_cmd = rx_commandBuffer;
 	spi_command.rx_cmd_size = 5;
-	spi_command.tx_cmd_size = 2;
+	spi_command.tx_cmd_size = 5;
 	SendCommand(&spi_command);
-
-	printf("Id bytes are %x %x %x %x\r\n", rx_commandBuffer[1],
-	  rx_commandBuffer[2], rx_commandBuffer[3], rx_commandBuffer[4]);
+	*id = rx_commandBuffer[1] | (rx_commandBuffer[2] << 8) |
+	    (rx_commandBuffer[3] << 16);
 }
 
 /*
@@ -148,8 +143,10 @@
     char *src_addr, unsigned size)
 {
 
+	printf("PA %x BA %x Size %u\r\n", pageAddress, byteAddress, size);
 	p_memset(tx_commandBuffer, 0, 8);
 	tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER;
+//	tx_commandBuffer[0] = 0x84;	// write buffer 1
 	tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
 	tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
 				((byteAddress >> 8) & 0x7);
@@ -172,7 +169,6 @@
 	WaitForDeviceReady();
 }
 
-
 /*************************** GLOBAL FUNCTIONS ********************************/
 
 
@@ -194,21 +190,22 @@
 	// determine byte address
 	byteAddress = flash_addr % FLASH_PAGE_SIZE;
 
+	printf("Flash addr %x PA %x BA %x\r\n", flash_addr, pageAddress, byteAddress);
 	p_memset(tx_commandBuffer, 0, 8);
+	tx_commandBuffer[0] = CONTINUOUS_ARRAY_READ_HF;
+//	tx_commandBuffer[0] = 0xD4;	// read buffer 1
 	tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
 	tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
 				((byteAddress >> 8) & 0x7);
-	tx_commandBuffer[3] = (byteAddress & 0xFF);
+	tx_commandBuffer[3] = byteAddress & 0xFF;
+	spi_command.tx_cmd = tx_commandBuffer;
+	spi_command.tx_cmd_size = 5;
+	spi_command.tx_data_size = size;
+	spi_command.tx_data = dest_addr;
 
 	p_memset(rx_commandBuffer, 0, 8);
-
-	spi_command.tx_cmd = tx_commandBuffer;
 	spi_command.rx_cmd = rx_commandBuffer;
-	spi_command.rx_cmd_size = 8;
-	spi_command.tx_cmd_size = 8;
-
-	spi_command.tx_data_size = size;
-	spi_command.tx_data = dest_addr;
+	spi_command.rx_cmd_size = 5;
 	spi_command.rx_data_size = size;
 	spi_command.rx_data = dest_addr;
 
@@ -278,9 +275,10 @@
 	// reset the SPI
 	pSPI->SPI_CR = AT91C_SPI_SWRST;
 
-	pSPI->SPI_MR = ((0xf << 24) | AT91C_SPI_MSTR | AT91C_SPI_MODFDIS | (0xE << 16));
+	pSPI->SPI_MR = (0xf << 24) | AT91C_SPI_MSTR | AT91C_SPI_MODFDIS |
+	    (0xE << 16);
 
-	pSPI->SPI_CSR[0] = (AT91C_SPI_CPOL | (AT91C_SPI_DLYBS & (0x4 <<16 )) | (3 << 8));
+	pSPI->SPI_CSR[0] = AT91C_SPI_CPOL | (4 << 16) | (2 << 8);
 	pSPI->SPI_CR = AT91C_SPI_SPIEN;
 
 	pSPI->SPI_PTCR = AT91C_PDC_TXTDIS;

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.h#5 (text+ko) ====

@@ -42,9 +42,11 @@
 
 // Flash commands
 
-#define CONTINUOUS_ARRAY_READ	0xE8
-#define STATUS_REGISTER_READ	0xD7
-#define PROGRAM_THROUGH_BUFFER	0x82
-#define MANUFACTURER_ID		0x9F
+#define CONTINUOUS_ARRAY_READ		0xE8
+#define CONTINUOUS_ARRAY_READ_HF	0x0B
+#define CONTINUOUS_ARRAY_READ_LF	0x03
+#define STATUS_REGISTER_READ		0xD7
+#define PROGRAM_THROUGH_BUFFER		0x82
+#define MANUFACTURER_ID			0x9F
 
 #endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604251552.k3PFqFK8086159>