Sounds like a good thing to pull your hair out trying to understand! Is this even more clear and understandable as the ADC_ETC stuff? Maybe I should do the checkout at Digikey with it!
// No protection, WP-E off, WP-E prevents use of IO2
w25n01g_writeStatusRegister(W25N01G_PROT_REG, W25N01G_PROT_CLEAR);
w25n01g_readStatusRegister(W25N01G_PROT_REG, true);
You have to use the write enable command (0x06) to set that bit, you can't do it by writing to the status register.
EDIT: Actually maybe that's just for the regular writes and you need to use the Status Register Protect Bits as described in section 7.1.3 to modify that register.
The ability to write to the protection register is controlled by 3 bits of the status register as shown on the chart on page 16 of the datasheet.
Begin Init
0
18
Status of reg 0xb0:
(HEX: ) 0x18, (Binary: )11000
Found W25N01G Flash Chip
Loading data
w25n01g_programExecute:
Reading Data
-1, 0
Write Page Addr Complete
0, 0
READING DATA START
Command 14 Complete
CHECKING ECC-CODE
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@defragster
Your soldering job is better than mine.
...
w25n01g_programDataLoad(W25N01G_LINEAR_TO_COLUMN(0), [B][U]xData[/U][/B], 16);
w25n01g_programDataLoad(W25N01G_LINEAR_TO_COLUMN(0), [B]buffer[/B], 16);
FLEXSPI2_FLSHA2CR0 = 0x1F400 * 2; //Flash Size in KByte, 1F400
static bool w25n01g_waitForReady()
{
while (!w25n01g_isReady()) {
uint32_t now = millis();
[B]if (now >= timeoutAt)[/B] {
static bool w25n01g_waitForReady()
{
uint32_t now = millis();
while (!w25n01g_isReady()) {
[B]if (millis() - now >= timeoutAt)[/B] {
#define Dprint(a) Serial.print( a );
....
Dprint( "wFReady Timeout" );
return false;
Begin Init
Found W25N01G Flash Chip
0
Status of reg 0xa0:
(HEX: ) 0x7C, (Binary: )1111100
18
Status of reg 0xb0:
(HEX: ) 0x18, (Binary: )11000
w25n01g_programExecute:
Reading Data
-1, 0
Write Page Addr Complete
0, 0
READING DATA START
Command 14 Complete
CHECKING ECC-CODE
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
saw it in an example. If I don't use it doesn't make a difference. Going to ask a couple of questions as a double check because I think I am confusing myself now.Also - KByte count is write hex value - why doubled here?
Yeah - didn't spend too much time on that one just threw it in as a something quick to test with - have to really fix it up. Max timout is 500ms once set by the way.The value in : w25n01g_setTimeout() should just be : timeoutAt = timeoutMillis;
Was thinking about that but didn't have many prints but looks like they are growingThat Dprint Macro would allow Debug_print sprinkling to be commented out easily
Was experimenting - really need to clean up the example.Should line ~29 the first read like the second?
#define DHprint( a ) { Serial.print( #a); Serial.println ( (uint32_t)a,HEX ); }
• Flash access start address:
Determined by register field IPCR0[SFAR]
• Flash Chip Select:
Determined by flash access address and Flash size setting (FLSHxCR0[FLSHSZ]).
// FLEXSPI2_IPCR0 = addr;
FLEXSPI2_IPCR0 = flashBaseAddr;
FLEXSPI2_IPCR1 = FLEXSPI_IPCR1_ISEQID(index) | FLEXSPI_IPCR1_IDATSZ(length);
src = (const uint8_t *)data;
FLEXSPI2_IPCMD = FLEXSPI_IPCMD_TRG;
while (!((n = FLEXSPI2_INTR) & FLEXSPI_INTR_IPCMDDONE)) {
if (n & FLEXSPI_INTR_IPTXWE) {
wrlen = length;
if (wrlen > 8) wrlen = 8;
if (wrlen > 0) {
//Serial.print("%");
//memcpy((void *)&FLEXSPI2_TFDR0, src, wrlen);
FLEXSPI2_TFDR0 = 0x11111111; FLEXSPI2_TFDR1 = 0x11111111;
src += wrlen;
length -= wrlen;
FLEXSPI2_INTR = FLEXSPI_INTR_IPTXWE;
}
}
}
FLEXSPI2_MCR0 &= ~FLEXSPI_MCR0_MDIS;
FLEXSPI2_LUTKEY = FLEXSPI_LUTKEY_VALUE;
FLEXSPI2_LUTCR = FLEXSPI_LUTCR_UNLOCK;
#if 0
volatile uint32_t *luttable = &FLEXSPI2_LUT0;
for (int i=0; i < 64; i++) luttable[i] = 0;
[B]...[/B]
// No PSRAM
}
#endif
}
#endif // ARDUINO_TEENSY41
FLEXSPI2_FLSHA2CR1 = FLEXSPI_FLSHCR1_CSINTERVAL(2) //minimum interval between flash device Chip selection deassertion and flash device Chip selection assertion.
| [COLOR="#FF0000"]FLEXSPI_FLSHCR1_CAS(16)[/COLOR]
| FLEXSPI_FLSHCR1_TCSH(3) //Serial Flash CS Hold time.
| FLEXSPI_FLSHCR1_TCSS(3); //Serial Flash CS setup time
ERAM (rwx): ORIGIN = 0x70000000, LENGTH = 16384K
FLEXSPI2_FLSHA2CR2 = FLEXSPI_FLSHCR2_AWRSEQID(6) //Sequence Index for AHB Write triggered Command
| FLEXSPI_FLSHCR2_AWRSEQNUM(0) //Sequence Number for AHB Read triggered Command in LUT.
| FLEXSPI_FLSHCR2_ARDSEQID(5) //Sequence Index for AHB Read triggered Command in LUT
| FLEXSPI_FLSHCR2_ARDSEQNUM(0); //Sequence Number for AHB Read triggered Command in LUT.
AWRSEQID(6)
ARDSEQID(5)
You shouldnt have to. Let me give it a try and see if I can figure anything out. What I did see in play around WREN is 10 on entering but get reset to 8 so maybe thats why you have to go to usding rdrx1.This is seriously hacked up and I'm only trying to write to the on chip buffer and read it back, not even attempting to store the page, but it's doing a little bit better than the stuff from GitHub. I cannot wrap my head around why I need to write a constant to the TX FIFO but maybe the morning coffee will help.
Wasn't sure you needed the add the STOP command. Looking at what we did for W25G128JV the LUTS didn't need the STOP. Not sure why you need so many. But it did fix the issue I was having with 0ing the PROT status.Ok, found a bug in the writeStatusRegister LUT, this is still hacked up, but a big step toward working.
STOP is different than 0 which is what it's all initialized to, but I'm not sure if that matters - the bug was skipping over a LUT entry, from 40 to 42.
for(uint16_t i = 0; i < 32; i++) {
Serial.printf("0x%02x, ",buffer[i]);
} Serial.println();
[B]const uint8_t beefy[] = "DEADBEEFdeadbeef\n";
//Serial.println("Loading data");
Dprint( (char *)beefy )
w25n01g_writeEnable(true); //sets the WEL in Status Reg to 1 (bit 2)
w25n01g_programDataLoad(W25N01G_LINEAR_TO_COLUMN(4004), beefy, 16);
//w25n01g_randomProgramDataLoad(W25N01G_LINEAR_TO_COLUMN(40000), buffer, 16);
w25n01g_programExecute(W25N01G_LINEAR_TO_PAGE(4004));
Serial.println("Reading Data");
memset(buffer, 0, 2048);
w25n01g_writeEnable(false);
w25n01g_readBytes(W25N01G_LINEAR_TO_COLUMN(4000), buffer, 32);
for(uint16_t i = 0; i < 20; i++) {
Serial.printf("0x%02x[%c], ",buffer[i],buffer[i]);
} Serial.println();[/B]
Begin Init
Found W25N01G Flash Chip
0
Status of reg 0xa0:
(HEX: ) 0x00, (Binary: )0
18
Status of reg 0xb0:
(HEX: ) 0x18, (Binary: )11000
w25n01g_programDataLoad
w25n01g_programExecute
Reading Data
-1, 0
Write Page Addr Complete
READING DATA START
Command 14 Complete
CHECKING ECC-CODE
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
DEADBEEFdeadbeef
w25n01g_programDataLoad
w25n01g_programExecute
Reading Data
0, 0
READING DATA START
Command 14 Complete
CHECKING ECC-CODE
0x49, 0xb0[�], 0x01[], 0x8e[�], 0x82[�], 0x7a[z], 0xfa[�], 0x87[�], 0x61[a], 0xf2[�], 0xcc[�], 0x4d[M], 0x24[$], 0x1a[], 0xb2[�], 0x2b[+], 0xff[�], 0xff[�], 0xff[�], 0xff[�],