Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Unset the flash chip's WP pin on erase #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions rtdmultiprog.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ def get_flash_id():

def erase_flash():
print("Erasing... ", end='')
write_reg(0xe3, read_reg(0xe3)[0] | (1<<2)) # deassert WP pin
isp_custom_instruction(CI_WRITE_AFTER_WREN, WRSR, 0, 1, 0x00) # Unprotect the flash
isp_custom_instruction(CI_ERASE, ERAS, 0, 0, 0x00) # Erase the flash
isp_custom_instruction(CI_WRITE_AFTER_WREN, WRSR, 0, 1, 0x1C) # Protect the flash
write_reg(0xe3, read_reg(0xe3)[0] & ~(1<<2)) # assert WP pin
print("done")

def program_flash(data, progress_callback=lambda s, e, c: None):
print(f"Will write {len(data) / 1024:.1f} KiB")

write_reg(0xe3, read_reg(0xe3)[0] | (1<<2)) # deassert WP pin
isp_custom_instruction(CI_WRITE_AFTER_WREN, WRSR, 0, 1, 0x00) # Unprotect the flash
pages = list(div_to_chunks(data, PAGE_SIZE))
for page_n, page in enumerate(pages):
Expand All @@ -165,6 +168,7 @@ def program_flash(data, progress_callback=lambda s, e, c: None):

poll(lambda: not read_reg (0x6F)[0] & 0x40, "Programming done timeout")
isp_custom_instruction(CI_WRITE_AFTER_WREN, WRSR, 0, 1, 0x1C) # Protect the flash
write_reg(0xe3, read_reg(0xe3)[0] & ~(1<<2)) # assert WP pin

data_crc = calculate_crc(data)
chip_crc = isp_get_crc(0, len(data) - 1)
Expand Down