Skip to content

Commit 0a440f0

Browse files
committed
[WIP] Deassert the flash chip's WP pin on erase/write
Usually firmware asserts the flash chip's WP pin to protect the its content. Deassert WP during erase/write operations. TODO: probably board specific Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
1 parent 6711f5e commit 0a440f0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rtdmultiprog.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,17 @@ def get_flash_id():
135135

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

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

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

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

169173
data_crc = calculate_crc(data)
170174
chip_crc = isp_get_crc(0, len(data) - 1)

0 commit comments

Comments
 (0)