diff --git a/firmware/cl-step-controller/src/drivers/step_cl.cpp b/firmware/cl-step-controller/src/drivers/step_cl.cpp index 4c7e77efa7ea351bacca39ef1eb732357d4960ec..3f7d637c6fb8104a6c59472aaafa1912ad555f6b 100644 --- a/firmware/cl-step-controller/src/drivers/step_cl.cpp +++ b/firmware/cl-step-controller/src/drivers/step_cl.cpp @@ -50,7 +50,7 @@ void Step_CL::init(void){ // s/o to mechaduino code for this #define PAGE_SIZE 512 // start_flash_write reports this bit value, use datasheet 25.8.3 to reference const float __attribute__((__aligned__(PAGE_SIZE))) lut[ENCODER_COUNTS] = {}; -const uint32_t start_addr = 0x10000000; +uint32_t start_addr = 0x00000000; float temp_quad[4]; uint8_t temp_indice; @@ -60,40 +60,47 @@ void flash_wait_ready(void){ // erase block at this addr void flash_erase_block(uint32_t *dst){ + sysError("erasing 0x" + String((uint32_t)dst, HEX)); flash_wait_ready(); // do 'erase row' - NVMCTRL->ADDR.reg = start_addr;//(uint32_t)dst; + NVMCTRL->ADDR.reg = (uint32_t)dst; NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_EB; flash_wait_ready(); } // writes blocks of four four bit words: i.e. 4 floats per row, 4 uint32, etc +// dst address, src address... #define QUAD_WORD (4 * 4) void flash_write_words(uint32_t *dst, uint32_t *src, uint32_t n_words){ - sysError("writing quad to addr: 0x" + String(dst[0], HEX)); + sysError("writing quad to addr: 0x" + String((uint32_t)dst, HEX)); // set manuel page write NVMCTRL->CTRLA.bit.WMODE = NVMCTRL_CTRLA_WMODE_MAN; + sysError("pbc"); // execute page buffer clear flash_wait_ready(); NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_PBC; flash_wait_ready(); // write em ? + sysError("writing..."); while(n_words > 0){ + sysError(String(n_words)); // more than 4 words left? uint32_t len = 4 < n_words ? 4 : n_words; // write one quad word into page buffer (is ... the flash address?) + flash_wait_ready(); + sysError("past wait"); for(uint32_t i = 0; i < 4; i ++){ if(i < len){ dst[i] = src[i]; } else { - dst[i] = 0xffffffff; // tail ends write to solid 1's + //((uint32_t*)dst)[i] = 0xffffffff; // tail ends write to solid 1's } } - // erase the block - flash_erase_block(dst); // trigger the write + sysError("write: 0x" + String((uint32_t)dst, HEX)); + delay(100); NVMCTRL->ADDR.reg = (uint32_t)dst; NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_WQW; // advance thru quad words @@ -117,7 +124,8 @@ void flash_write_value(float val){ sysError("flt: " + String(val)); temp_quad[temp_indice ++] = val; if(temp_indice > 3){ - flash_write_words((uint32_t *)lut, (uint32_t *)temp_quad, 4); + flash_erase_block(&start_addr); + flash_write_words(&start_addr, (uint32_t*)(&temp_quad), 4); temp_indice = 0; } } @@ -279,7 +287,7 @@ boolean Step_CL::calibrate(void){ void Step_CL::print_table(void){ for(uint16_t e = 0; e < 4; e ++){ - float ra = lut[e]; + float ra = ((float*)start_addr)[e];//lut[e]; sysError("e: " + String(e) + " ra: " + String(ra, 4)); delay(5); } diff --git a/log/cl-step-control-log.md b/log/cl-step-control-log.md index e3092716f75d4fe098ff6df8dd8ab0dd077533c0..cdae39f35cabbcd3d7497b1014337219690aaee6 100644 --- a/log/cl-step-control-log.md +++ b/log/cl-step-control-log.md @@ -810,4 +810,16 @@ Well, I think I might be writing into memory, but I've no way of reading it out I suspect I am writing into some bad spaces. This code (which *is* better) is expecting a pointer to a uint32, not the actual 'raw' uint32 addr... and I was previously trying to write to 0xF0000000 which is well out of range, I meant to do 0x10000000... -To clarify, I'll write the base fns with real void* rs... \ No newline at end of file +To clarify, I'll write the base fns with real void* rs... or in uint32_t addresses, as uint32_t s... + +Have isolated down to this `((uint32_t*)dst)[i] = ((uint32_t*)src)[i];` call... I suspect I'm pointing at something poorly. And I still get the sense I'm writing into the bootloader block. + +OK, I can read out of the start_addr, but after I've written to it, cannot do this anymore - processor hangs. Altho: + +`// bossac writes at 0x20005000` + +so that should be OK, I'm writing at 0x1... tho this program uses 42kb, but indeed once I've done the flash write, the bootloader fails. Tried writing at the lut address, fails also. + +I don't know what is real anymore, the libraries failed me, the datasheet is opaque AF, I am writing somewhere I shouldn't, etc. Might be time to bring out the atmel studio guns. + +Or the small guns: I'm going to try to get a minimum viable something up with this library. \ No newline at end of file