Add flash read/write API #758

Open
opened 2022-03-16 16:05:36 -05:00 by yonsch · 6 comments
yonsch commented 2022-03-16 16:05:36 -05:00 (Migrated from github.com)

Currently the flash can be accessed using the two ROM functions flash_range_program and flash_range_erase. However, there is no proper way to read from the flash, and to write individual bytes. Having these two features would allow users to use parts of the flash as non volatile memory.

Considered alternatives
Reading can be implemented using flash_do_cmd, though it requires allocating a large tx array to satisfy the API. Writing to arbitrary byte ranges can be implemented using flash_range_program with 0xff padding for unaffected bytes. Both can be implemented by writing directly to the SSI. But it would be better to have this done in the SDK and not application code.

Currently the flash can be accessed using the two ROM functions `flash_range_program` and `flash_range_erase`. However, there is no proper way to read from the flash, and to write individual bytes. Having these two features would allow users to use parts of the flash as non volatile memory. **Considered alternatives** Reading can be implemented using `flash_do_cmd`, though it requires allocating a large tx array to satisfy the API. Writing to arbitrary byte ranges can be implemented using `flash_range_program` with 0xff padding for unaffected bytes. Both can be implemented by writing directly to the SSI. But it would be better to have this done in the SDK and not application code.
lurch commented 2022-03-16 18:58:37 -05:00 (Migrated from github.com)

Writing to arbitrary byte ranges can be implemented using flash_range_program with 0xff padding for unaffected bytes.

How does that work when a flash-address is programmed with e.g. 0x55 and you want to change it to 0xAA ?

If you want to read/write from the flash as a filesystem, MicroPython contains support for that. (although I know that doesn't help if you're a C programmer!)

> Writing to arbitrary byte ranges can be implemented using flash_range_program with 0xff padding for unaffected bytes. How does that work when a flash-address is programmed with e.g. `0x55` and you want to change it to `0xAA` ? If you want to read/write from the flash as a filesystem, [MicroPython](https://micropython.org/) contains support for that. (although I know that doesn't help if you're a C programmer!)
yonsch commented 2022-03-17 01:46:51 -05:00 (Migrated from github.com)

@lurch Thanks, I'll take a deeper look into the micropython implementation, though in a quick glance it seemed that it writes in blocks, not bytes.
As for your question, it can't be done without erasing the flash first, but I'm assuming a higher level file system will take care of that.

@lurch Thanks, I'll take a deeper look into the micropython implementation, though in a quick glance it seemed that it writes in blocks, not bytes. As for your question, it can't be done without erasing the flash first, but I'm assuming a higher level file system will take care of that.
lurch commented 2022-03-17 04:50:46 -05:00 (Migrated from github.com)

IIRC @kilograham did mention previously that he wanted to add some kind of filesystem support to the SDK eventually, but he's simply been too busy with other stuff (including this ).

IIRC @kilograham _did_ mention previously that he wanted to add some kind of filesystem support to the SDK eventually, but he's simply been too busy with other stuff (including [this](https://www.raspberrypi.com/news/doom-comes-to-raspberry-pi-pico/) ).
lurch commented 2022-03-17 04:51:57 -05:00 (Migrated from github.com)

Aha #531

Aha #531
yonsch commented 2022-03-20 06:33:25 -05:00 (Migrated from github.com)

OK, good to know filesystem support is on its way. In my case I already have a filesystem, so I only need a read/write API (I'm writing a Zephyr flash driver).

OK, good to know filesystem support is on its way. In my case I already have a filesystem, so I only need a read/write API (I'm writing a Zephyr flash driver).
sophec commented 2022-04-01 08:37:29 -05:00 (Migrated from github.com)

I have been using the flash as non-volatile memory without issue--there's even an example program for this in the pico-examples repo. I just write in full pages, which is slightly inefficient for smaller data, but not enough to make a difference. I can then read arbitrarily from flash using a pointer. See here for an example: https://github.com/raspberrypi/pico-examples/blob/master/flash/program/flash_program.c

I have been using the flash as non-volatile memory without issue--there's even an example program for this in the pico-examples repo. I just write in full pages, which is slightly inefficient for smaller data, but not enough to make a difference. I can then read arbitrarily from flash using a pointer. See here for an example: https://github.com/raspberrypi/pico-examples/blob/master/flash/program/flash_program.c
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#758
No description provided.