Commit 63cbf13b authored by Jake Read's avatar Jake Read
Browse files

here's a mystery

parent 46a60a4c
...@@ -47,9 +47,9 @@ void Step_CL::init(void){ ...@@ -47,9 +47,9 @@ void Step_CL::init(void){
//lut = flash_lut.read(); //lut = flash_lut.read();
} }
#define BYTES_PER_PAGE 512 // #define BYTES_PER_PAGE 512
#define FLOATS_PER_PAGE 128 // #define FLOATS_PER_PAGE 128
#define PAGES_PER_BLOCK 16 // for 8192 bytes / block // #define PAGES_PER_BLOCK 16 // for 8192 bytes / block
#define LUT_SIZE 2048 #define LUT_SIZE 2048
//const float __attribute__((__aligned__(BYTES_PER_PAGE))) lut[LUT_SIZE] = {}; //const float __attribute__((__aligned__(BYTES_PER_PAGE))) lut[LUT_SIZE] = {};
...@@ -63,46 +63,104 @@ typedef struct { ...@@ -63,46 +63,104 @@ typedef struct {
float f[LUT_SIZE]; float f[LUT_SIZE];
} flts; } flts;
typedef struct {
float f[ENCODER_COUNTS];
} flts_14b;
flts readbuf;
flts inbuf; flts inbuf;
uint32_t bi = 0; uint32_t bi = 0;
uint32_t pi = 0;
FlashStorage(flash_storage, flts); FlashStorage(flash_storage_0, flts);
FlashStorage(flash_storage_1, flts);
FlashStorage(flash_storage_2, flts);
FlashStorage(flash_storage_3, flts);
FlashStorage(flash_storage_4, flts);
FlashStorage(flash_storage_5, flts);
FlashStorage(flash_storage_6, flts);
FlashStorage(flash_storage_7, flts);
void flash_write_init(void){ void flash_write_init(void){
bi = 0; bi = 0;
pi = 0;
} }
void flash_write_page(void){ void flash_write_page(void){
sysError("writing"); sysError("writing");
flash_storage.write(inbuf); switch(pi){
sysError("written"); case 0:
// sysError("unlocking block"); flash_storage_0.write(inbuf);
// NVMCTRL->ADDR.reg = (uint32_t)((const uint8_t*)(lut)); sysError("wrote brick 0");
// NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_UR; break;
// while(NVMCTRL->STATUS.bit.READY == 0); case 1:
// sysError("erasing block"); flash_storage_1.write(inbuf);
// //flashClass.erase((const uint8_t*)lut, 0); sysError("wrote brick 1");
// NVMCTRL->ADDR.reg = (uint32_t)((const uint8_t*)(lut)); break;
// NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_EB; case 2:
// // is it hung, or is there an error to catch ? flash_storage_2.write(inbuf);
// // hung ! sysError("wrote brick 2");
// //while(NVMCTRL->STATUS.bit.READY == 0); break;
// sysError("writing page"); case 3:
// flashClass.write((const uint8_t*)lut, (const uint8_t*)buffer, BYTES_PER_PAGE); flash_storage_3.write(inbuf);
sysError("wrote brick 3");
break;
case 4:
flash_storage_4.write(inbuf);
sysError("wrote brick 4");
break;
case 5:
flash_storage_5.write(inbuf);
sysError("wrote brick 5");
break;
case 6:
flash_storage_6.write(inbuf);
sysError("wrote brick 6");
break;
case 7:
flash_storage_7.write(inbuf);
sysError("wrote brick 7");
break;
default:
sysError("oob page write");
break;
} // end switch
pi ++;
delay(100);
} }
void flash_write_value(float val){ void flash_write_value(float val){
inbuf.f[bi ++] = val; inbuf.f[bi ++] = val;
if(bi >= LUT_SIZE){ if(bi >= LUT_SIZE){
flash_write_page(); flash_write_page();
bi = 0;
} }
} }
void Step_CL::print_table(void){ void Step_CL::print_table(void){
sysError("reading"); sysError("reading 0");
flts read = flash_storage.read(); inbuf = flash_storage_0.read();
for(uint16_t e = 0; e < LUT_SIZE; e ++){
sysError(String(inbuf.f[e]));
delay(2);
}
sysError("reading 1");
inbuf = flash_storage_1.read();
for(uint16_t e = 0; e < LUT_SIZE; e ++){
sysError(String(inbuf.f[e]));
delay(2);
}
sysError("reading 2");
inbuf = flash_storage_2.read();
for(uint16_t e = 0; e < LUT_SIZE; e ++){
sysError(String(inbuf.f[e]));
delay(5);
}
sysError("reading 3");
inbuf = flash_storage_3.read();
for(uint16_t e = 0; e < LUT_SIZE; e ++){ for(uint16_t e = 0; e < LUT_SIZE; e ++){
sysError(String(read.f[e])); sysError(String(inbuf.f[e]));
delay(5); delay(5);
} }
} }
...@@ -110,7 +168,7 @@ void Step_CL::print_table(void){ ...@@ -110,7 +168,7 @@ void Step_CL::print_table(void){
// the calib routine // the calib routine
boolean Step_CL::calibrate(void){ boolean Step_CL::calibrate(void){
flash_write_init(); flash_write_init();
for(uint32_t i = 0; i < LUT_SIZE; i ++){ for(uint32_t i = 0; i < ENCODER_COUNTS; i ++){
flash_write_value(i * 1.1F); flash_write_value(i * 1.1F);
} }
return true; return true;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "FlashStorage.h" #include "FlashStorage.h"
#include "syserror.h"
static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 }; static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 };
...@@ -46,15 +47,18 @@ static inline uint32_t read_unaligned_uint32(const void *data){ ...@@ -46,15 +47,18 @@ static inline uint32_t read_unaligned_uint32(const void *data){
// Invalidate all CMCC cache entries if CMCC cache is enabled. // Invalidate all CMCC cache entries if CMCC cache is enabled.
static void invalidate_CMCC_cache(){ static void invalidate_CMCC_cache(){
if (CMCC->SR.bit.CSTS) { // CR -> SR /*
CMCC->CTRL.bit.CEN = 0; if (CMCC->SR.bit.CSTS) { // CR -> SR
while (CMCC->SR.bit.CSTS) {} CMCC->CTRL.bit.CEN = 0;
CMCC->MAINT0.bit.INVALL = 1; while (CMCC->SR.bit.CSTS) {}
CMCC->CTRL.bit.CEN = 1; CMCC->MAINT0.bit.INVALL = 1;
} CMCC->CTRL.bit.CEN = 1;
}
*/
} }
void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_t size){ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_t size){
/*
// Calculate data boundaries // Calculate data boundaries
size = (size + 3) / 4; size = (size + 3) / 4;
volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr; volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr;
...@@ -85,6 +89,7 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_ ...@@ -85,6 +89,7 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_
} }
// Execute "WP" Write Page // Execute "WP" Write Page
sysError("write 0x" + String((uint32_t)flash_ptr));
NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_WP; NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_WP;
while (NVMCTRL->INTFLAG.bit.DONE == 0) { } while (NVMCTRL->INTFLAG.bit.DONE == 0) { }
invalidate_CMCC_cache(); invalidate_CMCC_cache();
...@@ -92,26 +97,32 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_ ...@@ -92,26 +97,32 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_
NVMCTRL->CTRLA.bit.CACHEDIS0 = original_CACHEDIS0; NVMCTRL->CTRLA.bit.CACHEDIS0 = original_CACHEDIS0;
NVMCTRL->CTRLA.bit.CACHEDIS1 = original_CACHEDIS1; NVMCTRL->CTRLA.bit.CACHEDIS1 = original_CACHEDIS1;
} }
*/
} }
void FlashClass::erase(const volatile void *flash_ptr, uint32_t size){ void FlashClass::erase(const volatile void *flash_ptr, uint32_t size){
const uint8_t *ptr = (const uint8_t *)flash_ptr; /*
while (size > ROW_SIZE) { const uint8_t *ptr = (const uint8_t *)flash_ptr;
while (size > ROW_SIZE) {
erase(ptr);
ptr += ROW_SIZE;
size -= ROW_SIZE;
}
erase(ptr); erase(ptr);
ptr += ROW_SIZE; */
size -= ROW_SIZE;
}
erase(ptr);
} }
void FlashClass::erase(const volatile void *flash_ptr){ void FlashClass::erase(const volatile void *flash_ptr){
NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr); /*
NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_EB; sysError("erase 0x" + String((uint32_t)flash_ptr));
while (!NVMCTRL->INTFLAG.bit.DONE) { } NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr);
invalidate_CMCC_cache(); NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_EB;
while (!NVMCTRL->INTFLAG.bit.DONE) { }
invalidate_CMCC_cache();
*/
} }
void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size){ void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size){
memcpy(data, (const void *)flash_ptr, size); memcpy(data, (const void *)flash_ptr, size);
} }
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
// Write data into flash memory. // Write data into flash memory.
// Compiler is able to optimize parameter copy. // Compiler is able to optimize parameter copy.
inline void write(T data) { flash.erase(); flash.write(&data); } inline void write(T data) { flash.erase(); flash.write(&data); } // erase &data ?
// Read data from flash into variable. // Read data from flash into variable.
inline void read(T *data) { flash.read(data); } inline void read(T *data) { flash.read(data); }
......
...@@ -874,4 +874,28 @@ OK, today will bring this library into the local build and see about figuring wh ...@@ -874,4 +874,28 @@ OK, today will bring this library into the local build and see about figuring wh
This means a block is 8192, makes sense this is where flashstorage aligns itself. I need 8 blocks total for the full LUT. This means a block is 8192, makes sense this is where flashstorage aligns itself. I need 8 blocks total for the full LUT.
Interesting, now that I fixed this error which appeared when it was compiling locally, I can get past 512 bytes with my example. Could try the big one... Interesting, now that I fixed this error which appeared when it was compiling locally, I can get past 512 bytes with my example. Could try the big one...
\ No newline at end of file
OK, but doesn't work past 8192 bytes - I'll try just over the boundary to check again. At the full spec, it indeed doesn't even start up. Can get to 4096 floats, but 8192 breaks things.
Last check for easy answers, I'll see if I can just tag 4x4096 FlashStorage instances together. OK, looks like I can get away with this. Damn, that was promising but it locks up on block #3. It doesn't matter which one I try to write first: i.e. it's not that prior writes fill up space for the latter, even if I try to write to the 3rd brick at the start, it hangs. OK very strange: can write all bricks except for the 3rd...
Eh, IDK anymore, I can't write more than twice regardless of which brick I'm writing to. Big shrug, going to try with bricks of 2048 size. Need 8 of those for the same total-bounds errors... OK, having the same problem here. These should be blocks. I can try once more, with 1024 floats each, just to be sure.
Nope, errors around the same spot. So I should check in the code to see if I can figure out where this is hanging up... At this point I suspect I am having some low level error from an NVMCTRL command, or, somehow the ptrs are pointing into bad spaces.
Trying:
- no write (fails block 3)
- no erase (fails block 3)
- no invalidate cache (same)
- *no* write fn (same)
- *no* erase fn
Suspect ROW_SIZE something is up,
- no while(>size) in erase
- no ptr op in erase fn
OK this is crazy, I have every fn in the class commented out, and the thing still locks up.
- neil suggests watching the power rails, flash req
- nuclear option is asking neil to chat w/ microchip contacts
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment