Skip to content

Commit 1615488

Browse files
committed
flash: relax requirement on full-page writes
Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
1 parent 16bb3d3 commit 1615488

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

lib/flash/flash.hh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "jedec.hh"
99
#include "sfdp.hh"
1010
#include <cstdint>
11+
#include <cassert>
1112

1213
namespace flash {
1314

@@ -135,8 +136,9 @@ class Generic {
135136

136137
Option<Sector> quad_read_sector(uint32_t address) { return quad_read<4096>(address); }
137138

138-
Option<bool>
139-
quad_page_program(uint32_t address, std::span<uint8_t, 256> data, uint8_t upcode = 0x32) {
139+
Option<bool> quad_page_program(uint32_t address, std::span<uint8_t> data, uint8_t upcode = 0x32) {
140+
// Page program commands should not cross page boundaries.
141+
assert((address % flash::PageSize) + data.size() <= flash::PageSize);
140142
write_enable();
141143
std::array<uint8_t, 1> cmd = {upcode};
142144

@@ -250,7 +252,9 @@ class Generic {
250252
}
251253

252254
template <size_t ADDR_SIZE = 3>
253-
Option<bool> single_page_program_non_blocking(uint32_t address, std::span<uint8_t, 256> data) {
255+
Option<bool> single_page_program_non_blocking(uint32_t address, std::span<uint8_t> data) {
256+
// Page program commands should not cross page boundaries.
257+
assert((address % flash::PageSize) + data.size() <= flash::PageSize);
254258
static_assert(ADDR_SIZE == 3 || ADDR_SIZE == 4, "Only 3 or 4 byte addresses supported");
255259

256260
Opcode op;
@@ -274,7 +278,9 @@ class Generic {
274278
}
275279

276280
template <size_t ADDR_SIZE = 3>
277-
Option<bool> single_page_program(uint32_t address, std::span<uint8_t, 256> data) {
281+
Option<bool> single_page_program(uint32_t address, std::span<uint8_t> data) {
282+
// Page program commands should not cross page boundaries.
283+
assert((address % flash::PageSize) + data.size() <= flash::PageSize);
278284
write_enable();
279285
single_page_program_non_blocking(address, data);
280286
wait_not_busy();

0 commit comments

Comments
 (0)