Skip to content

Commit bbfcee3

Browse files
committed
flash: allow page program to program less than a whole page at a time
Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
1 parent a22d671 commit bbfcee3

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/flash/flash.hh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,17 @@ class Generic {
264264
op = Opcode::PageProgram4b;
265265
}
266266

267-
std::array<uint8_t, 256 + 1 + ADDR_SIZE> cmd = {op};
267+
auto total_size = 1 + ADDR_SIZE + data.size();
268+
std::array<uint8_t, 1 + ADDR_SIZE + flash::PageSize> cmd = {op};
268269
for (size_t i = 0; i < ADDR_SIZE; ++i) {
269270
// This calculates the correct shift (24, 16, 8, 0 for 4-byte; 16, 8, 0 for 3-byte)
270271
cmd[1 + i] = static_cast<uint8_t>(address >> (8 * (ADDR_SIZE - 1 - i)));
271272
}
272273

273-
auto slice = std::span<uint8_t>(cmd).last<256>();
274+
auto payload = std::span<uint8_t>(cmd).last<flash::PageSize>();
275+
std::ranges::copy(data, payload.begin());
274276

275-
std::ranges::copy(data, slice.begin());
276-
TRY_OPT(spih.transfer(cmd, std::span<uint8_t>()));
277+
TRY_OPT(spih.transfer(std::span<uint8_t>(cmd).subspan(0, total_size), std::span<uint8_t>()));
277278
return true;
278279
}
279280

0 commit comments

Comments
 (0)