If I understand the UM correctly, using the FLASH peripheral flash can be read at a granularity of 16 bytes ("physical word"), and erased, written and programmed at a granularity of 512 bytes (1 page, 32 physical words). Also according to my understanding of the UM, writing proceeds by filling an peripheral-internal page register with 32 columns of physical words, and then calling the PROGRAM command on an erased page.
Is it possible to write in smaller units? My goal is to use a filesystem (ARM mbed's littlefs), and for this smaller writes would be great.
I have tried to following:
- erase page
- fill page register with zeros
- set specific page register column to a non-zero value
- fill page register with zeros again
- set different column to non-zero value
This "works" in the sense of no error or failure condition reported. However there are additional bits being set. As a specific example, on an LPC55S69 dev board, using the page starting 0x4_0200, I first write 0x1234567 (as physical word or 128 bit integer) to 0x4_0200, then 0x7654321 (again as physical word) to 0x4_0210 (second such word in the page). In this setup, I end up with the following data at the two addresses (note the spurious bits, bit 94 for the first location, bit 104 for the second location):
Is this expected behaviour? Is there any way to write smaller units to a previously "unwritten" part of a flash page?
For LPC55Sxx, the flash page size is 512 bytes, the sector size is 32768(*64 pages). You can read flash with byte, half word(16 bits) or word(32 bits) whatever you like. For the programming, as you know that erasing flash will set the flash cell bit as 1, programming flash can clear the flash cell bit or remain the flash cell bit as 1. In general, we program one page after the page is erased. But you can program one BYTE if only the flash cell bits are all ONE.
Hope it canm help you
What you say does not match what I see.
1. After erasing, all bits are set to 0, not 1 (as is usual for flash). Can you confirm this?
2. After writing, e.g., two 32-bit words to the same 128-bit memory word, the bit errors as described above occur. The same happens when writing in other granularities (byte, 128-bit words, etc.). Are you certain that it is possible to write smaller units than page (512 bytes)?
I am sure that the flash cell bits are all ONE after you erase the flash, all flash complies to the law no matter whether it is from NXP, whatever.
Regarding the error when you program flash, I suggest you download SDK for LPC55S6x from the link:
In the package, there is example to erase/program flash as the following fig, I suggest you try to run the example.
Hope it can help you
you mentioned that the LPC55s6x flash can be program in BYTE. But this is not supported by the ROM API, right? So I have to configure the FLash control register directly if I want to program certain bytes after ERASE?
Do you have some suggestion about which registers have to be configured? e.g write 0xAA55B3DE to 0x10070000 (secure Flash region).
CMD = 8 (CMD_WRITE) with STARTA = 0x10070 or 0x0700 (?) --> Question: the STARTA takes only 17bits which is the is a physical word address. Is the physical word 32 bits or 128bit? Is there any difference between the secure/non-seucre flash address?
I need to perform a CMD_PROGRAM after the CMD_WRITE to program the flash, right?
I am aware of the SDK and its use of the bootloader API.
But, my question concerns the FLASH peripheral itself, and use of its registers as (partially) documented in UM 11126, Chapter 5. It is when calling command CMD_ERASE_RANGE (value 4, parameters STARTA = STOPA set to a specific page) that I see the zeros instead of the ones. Can you confirm and tell me more about this?
for those readers who (like me) are eager to know the answer to the question raised in this 4 year old post:
Rong is wrong, all erased Flash bits are 0.
See this knowledge base article: LPC55xx Erased Memory State, 0 or 1?