nRF52832 how to write or read to internal flash? SDK IS 15:00
nRF52832 how to write or read to internal flash? SDK IS 15:00
Hi jinxiuqueling73,
So if I understand this correctly; You are able to run the Flash Storage Example, and get the expected behaviour? (SDK15.0.0)
Have you seen how you can Write and Read data from the Flash Storage library Documentation?
If you are having issues, please provide information in what steps, error code from debugging would be helpful?
The first time I let m_data =0xDEADBEEF , reading data is 0xDEADBEEF, that is OK. But the second time I let m_data =0x5E8D7E4F; reading data is 0x5E8D3E4F, that is FAULT . why?.
At the hardware level, an erased Flash bit is a 1.
A write can only change a 1 to a 0 - to change a 0 to a 1, you need to do an erase.
The library documentation, and the example, do not make it at all clear that the library does not do this for you.
You must "manually" do an erase before a write.
If you look at the bit patterns you are writing, you can see what is happening:
| D | E | A | D | B | E | E | F | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 1 : 1 : 0 : 1 | 1 : 1 : 1 : 0 : 1 | 0 : 1 : 0 : 1 | 1 : 0 : 1 : 1 : 0 | 1 : 1 : 1 : 1 | 1 : 0 : 1 : 1 : 1 | 0 : 1 : 1 : 1 | 1 : +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 5 | E | 8 | D | 7 | E | 4 | F | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 : 1 : 0 : 1 | 1 : 1 : 1 : 0 : 1 | 0 : 0 : 0 : 1 | 1 : 0 : 1 : 0 : 1 | 1 : 1 : 1 : 1 | 1 : 0 : 0 : 1 : 0 | 0 : 1 : 1 : 1 | 1 : +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 : 1 : 0 : 1 | 1 : 1 : 1 : 0 : 1 | 0 : 0 : 0 : 1 | 1 : 0 : 1 : 0 : 0 | 1 : 1 : 1 : 1 | 1 : 0 : 0 : 1 : 0 | 0 : 1 : 1 : 1 | 1 : +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | | | | | *** | | | | | 5 | E | 8 | D | 3 | E | 4 | F |
It is only in the case of the 'B' nibble trying to change to '7' that you try to change a 0 to a 1 - every other bit is either unchanged, or a 1 being cleared to 0
I should say that I fell into this trap myself.
As I said, it was unclear from the documentation whether an erase was needed before a write.
I tested by writing "hello" and then writing "HELLO" (with no erase between) - it worked, so I thought that was OK.
But then my application didn't work.
The reason being that going from "hello" to "HELLO" involves only clearing bits.
If I had written "HELLO" first, and then "hello" I would have seen the issue sooner.
The Flash Data Storage library says it manages this for you, but I found the descriptions of "files" and "records" very unclear and confusing.