private void WriteSPIFlash(UInt32 address, UInt32 size, byte[] data) { //Console.WriteLine("Flashin " + data.Length); byte[] cmd = new byte[9 + data.Length]; cmd[0] = 0x04; // SPIFLASHWRITE_NEW // address cmd[1] = (byte)(address & 0xFF); cmd[2] = (byte)((address >> 8) & 0xFF); cmd[3] = (byte)((address >> 16) & 0xFF); cmd[4] = (byte)((address >> 24) & 0xFF); // size cmd[5] = (byte)(size & 0xFF); cmd[6] = (byte)((size >> 8) & 0xFF); cmd[7] = (byte)((size >> 16) & 0xFF); cmd[8] = (byte)((size >> 24) & 0xFF); // copy Array.Copy(data, 0, cmd, 9, data.Length); uint res = STDFU.STDFU_Dnload(ref hDevice, cmd, (uint)cmd.Length, 1); STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status(); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); //Thread.Sleep(50); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); WaitUntilIdle(); byte[] bytes = new byte[data.Length]; res = STDFU.STDFU_Upload(ref hDevice, bytes, (uint)data.Length, 1); //Console.WriteLine("WriteSPIFlash: " + res); }
private void EraseSPI64kBlock(UInt32 address) { WaitUntilIdle(); byte[] cmd = new byte[5]; cmd[0] = 0x03; // SPIFLASHWRITE_NEW // address cmd[1] = (byte)(address & 0xFF); cmd[2] = (byte)((address >> 8) & 0xFF); cmd[3] = (byte)((address >> 16) & 0xFF); cmd[4] = (byte)((address >> 24) & 0xFF); STDFU.STDFU_Dnload(ref hDevice, cmd, (uint)cmd.Length, 1); STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status(); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); Thread.Sleep(50); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); // WaitUntilIdle(); Console.WriteLine(address); byte[] bytes = new byte[1024]; STDFU.STDFU_Upload(ref hDevice, bytes, 1024, 1); }
/*public bool DrawText(string msg, int a, int b) * { * * byte[] cmd = new byte[msg.Length + 3]; * cmd[0] = 0x80; * * a &= 0xFF; * b &= 0xFF; * * WaitUntilIdle(); * * cmd[1] = (byte)(address & 0xFF); * cmd[2] = (byte)((address >> 8) & 0xFF); * cmd[3] = (byte)((address >> 16) & 0xFF); * cmd[4] = (byte)((address >> 24) & 0xFF); * * STDFU.STDFU_Dnload(ref hDevice, cmd, 5, 0); * STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status(); * STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); * * WaitUntilIdle(); * * STDFU.STDFU_Dnload(ref hDevice, new byte[] { 0x84, 0, }, 2, 0); * * WaitUntilIdle(); * * * * * return true; * }*/ public byte[] ReadFrameLine(byte y) { int majorTries = 0; retryStart: WaitUntilIdle(); for (int i = 0; i < 2; i++) { byte[] cmd = new byte[5]; cmd[0] = 0x84; // SPIFLASHWRITE_NEW // address cmd[1] = (byte)(0); cmd[2] = (byte)(y & 0xFF); cmd[3] = (byte)(159 & 0xFF); cmd[4] = (byte)(y & 0xFF); STDFU.STDFU_Dnload(ref hDevice, cmd, (uint)cmd.Length, 1); STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status(); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); //Thread.Sleep(40); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); // WaitUntilIdle(); byte[] bytes = new byte[(160 * 3) + 5]; STDFU.STDFU_Upload(ref hDevice, bytes, (160 * 3) + 5, 1); if (bytes[4] == y) { byte[] ret = new byte[160 * 3]; Array.Copy(bytes, 5, ret, 0, 160 * 3); return(ret); } else { Thread.Sleep(3); } //Thread.Sleep(25); } return(null); /* * majorTries++; * Console.WriteLine("ERR: Frame line " + y); * * if (majorTries > 100) return null; * else * { * * TickleTickle(); * GetSpiID(); * * goto retryStart; * }*/ }
private byte[] ReadBlock(UInt32 BlockNumber, UInt32 BlockSize) { WaitUntilIdle(); byte[] data = new byte[BlockSize]; STDFU.STDFU_Upload(ref hDevice, data, BlockSize, (UInt16)BlockNumber); WaitUntilIdle(); return(data); }
public byte[] ReadSPIFlash(UInt32 address, UInt32 size) { byte[] retBytes = new byte[size]; for (int i = 0; i < size; i++) { retBytes[i] = 0; } byte[] cmd = new byte[5]; byte[] bytes = new byte[MAX_WRITE_BLOCK_SIZE]; for (int i = 0; i < MAX_WRITE_BLOCK_SIZE; i++) { bytes[i] = 0; } for (uint offset = 0; offset < size; offset += MAX_WRITE_BLOCK_SIZE) { progress = (int)(((float)offset / (float)size) * 100.0) + 1; cmd[0] = 0x01; // SPIFLASHWRITE_NEW // address cmd[1] = (byte)(address & 0xFF); cmd[2] = (byte)((address >> 8) & 0xFF); cmd[3] = (byte)((address >> 16) & 0xFF); cmd[4] = (byte)((address >> 24) & 0xFF); uint res = STDFU.STDFU_Dnload(ref hDevice, cmd, (uint)cmd.Length, 1); STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status(); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); //Thread.Sleep(3); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); WaitUntilIdle(); uint lenn = (uint)(size - offset < MAX_WRITE_BLOCK_SIZE ? (size - offset) : MAX_WRITE_BLOCK_SIZE); res = STDFU.STDFU_Upload(ref hDevice, bytes, lenn, 1); Array.Copy(bytes, 0, retBytes, offset, lenn); address += MAX_WRITE_BLOCK_SIZE; } return(retBytes); }
public UInt32 GetSpiID() { WaitUntilIdle(); byte[] cmd = new byte[1]; cmd[0] = 0x05; STDFU.STDFU_Dnload(ref hDevice, cmd, (uint)1, 1); STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status(); STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus); //Console.WriteLine("DFU iString: " + dfuStatus.iString); //Console.WriteLine("DFU State: " + dfuStatus.bState); //Console.WriteLine("DFU STATUS: " + dfuStatus.bStatus); WaitUntilIdle(); byte[] bytes = new byte[4]; STDFU.STDFU_Upload(ref hDevice, bytes, 4, 1); return(BitConverter.ToUInt32(bytes, 0)); }