Strange, looks like it gets stuck in flash_program, but maybe I need to give it bigger timeout. Hm, I used 200ms and original code has 1s
Helpful post? Buy me a coffee.
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tamp.kaczmarek2 wrote:By the way, it currently reads flash in 0x100 chunks, futhermore, the read is done via text - ASCII. So two chars per byte. So already twice as slow as it could be.
flash_otp_read 0x0 0x100\r\n
AE BE 4F 2D 5A
Command formate: fdump flash_offset dump_size(dump_size < 0x100)
Example: fdump 0xD000 0x100
version
ERROR
Not found <" > command!
int main(int argc, char* argv[])
{
SetSysClock();
set_interrupt_priority();
__enable_irq();
hal_flash_init();
flash_cache_disable();
//bootram_ctrl_init();
//bootram_ctrl_loop();
bootram_serial_init();
//hal_wdt_en(WDT_BASE,HAL_DISABLE);
bootram_serial_setbaudrate(460800);
uint32_t flash_size = 0;
uint32_t startAddr = 0;
uint32_t readLen = 32;
uint8_t buf[readLen+2];
uint32_t ret = bootram_flash_info();
flash_size = ((1 << ((ret & 0xFF) - 0x11)) / 8) * 0x100000;
bootram_serial_write(&flash_size, sizeof(flash_size));
for(int k = 0; k < 0x10000; k++)
{
__ASM("nop");
}
for(uint32_t remaining = flash_size; remaining > 0; remaining -= readLen){
hal_flash_read(startAddr, readLen, buf);
uint16_t crc = crc16_ccitt(buf, readLen);
memcpy(&buf[readLen], &crc, sizeof(crc));
startAddr += readLen;
size_t sent = 0;
for(int j = 0; j < readLen + 2; j++)
{
bootram_serial_write(&buf[j], 1);
}
bootram_serial_flush();
memset(buf, 0, readLen + 2);
}
while (1)
__ASM("nop");
}
public void read_flash_to_file(string filename, int flash_size, bool is_otp = false)
{
int addr = 0;
_port.BaudRate = 460800;
byte[] flashsize = new byte[4];
var read = 0;
while(read < 4)
{
read += _port.Read(flashsize, read, 4 - read);
}
int total_flash_size = flashsize[3] << 24 | flashsize[2] << 16 | flashsize[1] << 8 | flashsize[0];
Console.WriteLine($"Reading flash to file {filename}, flash size is {total_flash_size / 0x100000} MB");
int packetsize = 32 + 2;
using(FileStream fs = new FileStream("test.bin", FileMode.Create))
{
while(addr < 0x200000)
{
byte[] buf = new byte[packetsize];
byte[] nocrc = new byte[packetsize - 2];
byte[] crc = new byte[2];
//if (read_flash(addr, is_otp, out byte[] data))
//{
// fs.Write(data, 0, data.Length);
//}
//Console.Write(".");
//addr += 0x100;
read = 0;
while(read < packetsize)
{
read += _port.Read(buf, read, packetsize - read);
}
Array.Copy(buf, nocrc, packetsize - 2);
Array.ConstrainedCopy(buf, packetsize - 2, crc, 0, 2);
ushort calc_crc = YModem.calc_crc(nocrc);
ushort sentcrc = (ushort)(crc[1] << 8 | crc[0]);
if(sentcrc != calc_crc)
{
Console.WriteLine("CRC FAIL");
break;
}
addr += packetsize - 2;
fs.Write(buf, 0, packetsize - 2);
}
}
Console.WriteLine("\ndone");
}