Add flash read/write API #758
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#758
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently the flash can be accessed using the two ROM functions
flash_range_programandflash_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 usingflash_range_programwith 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.How does that work when a flash-address is programmed with e.g.
0x55and you want to change it to0xAA?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!)
@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.
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 ).
Aha #531
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).
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