EasyManua.ls Logo

Maxim Integrated MAX32665 - Flash Write; Page Erase

Maxim Integrated MAX32665
457 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
MAX32665-MAX32668 User Guide
Maxim Integrated Page 136 of 457
7.2.4 Flash Write
Writes to a flash location are only successful if the targeted location is already in its erased state. Perform the following
steps to write to a flash memory instance:
1. If desired, enable flash controller interrupts by setting the FLCn_INTR.access_error_ie and FLCn_INTR.done_ie bits.
2. Read the FLCn_CTRL.busy bit until it returns 0.
3. Configure FLCn_CTRL.clkdiv to match the SYS_CLK frequency.
4. Set the FLCn_ADDR register to a valid target address. Reference Table 7-2.
5. Set FLCn_DATA3, FLCn_DATA2, FLCn_DATA1, and FLCn_DATA0 to the data to write. FLCn_DATA3 is the most
significant word and FLCn_DATA0 is the least significant word. Each word of the data to write follows the little-
endian format where the least significant byte of the word is stored at the lowest-numbered byte and the most
significant byte is stored at the highest-numbered byte.
6. Set FLCn_CTRL.unlock to 0x2 to unlock the flash instance.
7. Set FLCn_CTRL.write to 1. This field is automatically cleared by the Flash Controller when the write operation is
finished.
8. FLCn_INTR.done is set by hardware when the write completes and if an error occurred, the FLCn_INTR.access_fail
flag is set. These bits generate a flash IRQ if the interrupt enable bits are set.
9. Set FLCn_CTRL.unlock to any value other than 0x2 to re-lock the flash instance.
Note: Code execution can occur within the same flash instance as targeted programming.
7.2.5 Page Erase
CAUTION: Care must be taken to not erase the page from which application code is currently executing.
Perform the following to erase a page of a flash memory instance:
1. If desired, enable flash controller interrupts by setting the FLCn_INTR.access_error_ie and FLCn_INTR.done_ie bits.
2. Read the FLCn_CTRL.busy bit until it returns 0.
3. Configure FLCn_CLKDIV.clkdiv to match the SYS_CLK frequency.
4. Set the FLCn_ADDR register to an address within the target page to be erased. FLCn_ADDR[12:0] are ignored by
the Flash Controller to ensure the address is page aligned.
5. Set FLCn_CTRL.unlock to 0x2 to unlock the flash instance.
6. Set FLCn_CTRL.erase_code to 0x55 for page erase.
7. Set FLCn_CTRL.page_erase to 1 to start the page erase operation.
8. The FLCn_CTRL.busy bit is set by the flash controller while the page erase is in progress and the
FLCn_CTRL.page_erase and FLCn_CTRL.busy are cleared by the flash controller when the page erase is complete.
9. FLCn_INTR.done is set by hardware when the page erase completes and if an error occurred, the
FLCn_INTR.access_fail flag is set. These bits generate a flash IRQ if the interrupt enable bits are set.
10. Set FLCn_CTRL.unlock to any value other than 0x2 to re-lock the flash instance.

Table of Contents