add the external flash interface to nvm-read and write

This commit is contained in:
Mariano Alvira 2012-01-27 12:31:26 -05:00
parent 3a21eb18fe
commit abcfebb92b
3 changed files with 49 additions and 42 deletions

View file

@ -49,6 +49,10 @@
/* use uart1 for console */
#define uart_init uart1_init
/* nvm interface */
#define NVM_INTERFACE gNvmInternalInterface_c
/*#define NVM_INTERFACE gNvmExternalInterface_c */
/* nvm-read */
#define READ_ADDR 0x1f000
#define READ_NBYTES 1024

View file

@ -35,6 +35,7 @@
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include "tests.h"
#include "config.h"
@ -51,27 +52,30 @@ void main(void) {
vreg_init();
putstr("Detecting internal nvm\n\r");
if(NVM_INTERFACE == gNvmInternalInterface_c)
{
printf("Detecting internal nvm\n\r");
} else {
printf("Setting up gpio\r\n");
/* set SPI func */
GPIO->FUNC_SEL.GPIO_04 = 1;
GPIO->FUNC_SEL.GPIO_05 = 1;
GPIO->FUNC_SEL.GPIO_06 = 1;
GPIO->FUNC_SEL.GPIO_07 = 1;
printf("Detecting external nvm\n\r");
}
err = nvm_detect(gNvmInternalInterface_c, &type);
err = nvm_detect(NVM_INTERFACE, &type);
putstr("nvm_detect returned: 0x");
put_hex(err);
putstr(" type is: 0x");
put_hex32(type);
putstr("\n\r");
printf("nvm_detect returned: 0x%02x type is: 0x%08x\r\n", err, (unsigned int)type);
nvm_setsvar(0);
err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, READ_ADDR, READ_NBYTES);
putstr("nvm_read returned: 0x");
put_hex(err);
putstr("\n\r");
err = nvm_read(NVM_INTERFACE, type, (uint8_t *)buf, READ_ADDR, READ_NBYTES);
printf("nvm_read returned: 0x%02x\r\n", err);
for(i=0; i<READ_NBYTES/4; i++) {
putstr("0x");
put_hex32(buf[i]);
putstr("\n\r");
printf("0x%08x\r\n", (unsigned int)buf[i]);
}

View file

@ -35,6 +35,7 @@
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include "tests.h"
#include "config.h"
@ -51,46 +52,44 @@ void main(void) {
vreg_init();
putstr("Detecting internal nvm\n\r");
if(NVM_INTERFACE == gNvmInternalInterface_c)
{
printf("Detecting internal nvm\n\r");
} else {
printf("Setting up gpio\r\n");
/* set SPI func */
GPIO->FUNC_SEL.GPIO_04 = 1;
GPIO->FUNC_SEL.GPIO_05 = 1;
GPIO->FUNC_SEL.GPIO_06 = 1;
GPIO->FUNC_SEL.GPIO_07 = 1;
printf("Detecting external nvm\n\r");
}
err = nvm_detect(gNvmInternalInterface_c, &type);
err = nvm_detect(NVM_INTERFACE, &type);
putstr("nvm_detect returned: 0x");
put_hex(err);
putstr(" type is: 0x");
put_hex32(type);
putstr("\n\r");
printf("nvm_detect returned: 0x%02x type is: 0x%08x\r\n", err, (unsigned int)type);
buf[0] = WRITEVAL0;
buf[1] = WRITEVAL1;
err = nvm_erase(gNvmInternalInterface_c, type, 0x40000000); /* erase sector 30 --- sector 31 is the 'secret zone' */
putstr("nvm_erase returned: 0x");
put_hex(err);
putstr("\n\r");
err = nvm_erase(NVM_INTERFACE, type, 1 << WRITE_ADDR/4096);
printf("nvm_erase returned: 0x%02x\r\n", err);
err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
putstr("nvm_write returned: 0x");
put_hex(err);
putstr("\n\r");
putstr("writing\n\r");
err = nvm_write(NVM_INTERFACE, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
printf("nvm_write returned: 0x%02x\r\n", err);
printf("writing\n\r");
for(i=0; i<WRITE_NBYTES/4; i++) {
putstr("0x");
put_hex32(buf[i]);
putstr("\n\r");
printf("0x%08x\r\n", (unsigned int)buf[i]);
buf[i] = 0x00000000; /* clear buf for the read */
}
err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
putstr("nvm_read returned: 0x");
put_hex(err);
putstr("\n\r");
putstr("reading\n\r");
err = nvm_read(NVM_INTERFACE, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
printf("nvm_read returned: 0x%02x\r\n", err);
printf("reading\r\n");
for(i=0; i<WRITE_NBYTES/4; i++) {
putstr("0x");
put_hex32(buf[i]);
putstr("\n\r");
printf("0x%08x\r\n", (unsigned int)buf[i]);
}