(offset, size)
| 286 | this.#serial.set({DTR: false, RTS: false}); |
| 287 | } |
| 288 | async erase(offset, size) { |
| 289 | if ((undefined === offset) && (undefined === size)) { |
| 290 | await this.command(Bootloader.ERASE_FLASH); |
| 291 | this.parseReply(await this.getReply(120 * 1000), Bootloader.ERASE_FLASH); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | if ((offset % 4096) || (size % 4096)) |
| 296 | throw new Error("must be aligned to sectors"); |
| 297 | |
| 298 | const payload = new DataView(new ArrayBuffer(2 * 4)); |
| 299 | payload.setUint32(0, offset, 1); |
| 300 | payload.setUint32(4, size, 1); |
| 301 | const timeout = Math.max(100, 50 + (size / 1_000_000) * 30_000); // 30 seconds per MB |
| 302 | await this.command(Bootloader.ERASE_REGION, new Uint8Array(payload.buffer)); |
| 303 | this.parseReply(await this.getReply(timeout), Bootloader.ERASE_REGION); |
| 304 | } |
| 305 | async read(offset, size) { |
| 306 | const result = new Uint8Array(size); |
| 307 | let position = 0; |
no test coverage detected