Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ltchiptool/soc/ln882h/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from .util.ln882htool import LN882hTool

LN882H_GUIDE = [
"Connect UART1 of the LN882h to the USB-TTL adapter:",
"Connect UART0 of the LN882h to the USB-TTL adapter:",
[
("PC", "LN882h"),
("RX", "TX1 (GPIOA2 / P2)"),
("TX", "RX1 (GPIOA3 / P3)"),
("RX", "TX0 (GPIOA2 / P2)"),
("TX", "RX0 (GPIOA3 / P3)"),
("GND", "BOOT (GPIOA9 / P9)"),
("", ""),
("GND", "GND"),
],
Expand Down
11 changes: 11 additions & 0 deletions ltchiptool/soc/ln882h/util/ln882htool.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def flash_read(
chunk_size: int = 256, # maximum supported chunk size
) -> Generator[bytes, None, None]:
self.link()
prev_baudrate = self.s.baudrate
if not self.ramcode:
self.ram_boot()

Expand All @@ -177,6 +178,10 @@ def flash_read(
f"Chunk size {chunk_size} exceeds the maximum allowed (256)"
)

self.change_baudrate(LN882H_YM_BAUDRATE)
self.link()
self.push_timeout(0.02)

for start in range(offset, offset + length, chunk_size):
count = min(start + chunk_size, offset + length) - start
debug(f"Dumping bytes: start=0x{start:X}, count=0x{count:X}")
Expand All @@ -186,10 +191,16 @@ def flash_read(

valid, data = self.ym._verify_recv_checksum(True, data)
if verify and not valid:
self.change_baudrate(prev_baudrate)
self.pop_timeout()
raise RuntimeError(f"Invalid checksum")

yield data

self.change_baudrate(prev_baudrate)
self.pop_timeout()
info("Flash Read Successful.")

def flash_write(
self,
offset: int,
Expand Down