9. Embedded flash memory (FLASH)

The flash controller implements the erase and program flash memory operation. The flash controller also implements the read and write protection.

9.1 Flash main features

Flash memory features:

Flash controller features:

9.2 Description

The flash memory is organized as follows:

Erasing the whole flash memory results in all ones in every bit cell of the flash memory.

In parallel, the flash controller manages 1 Kbyte OTP (One-Time Programmable) for user data. The OTP data cannot be erased. The OTP data area can no more be written only as soon as the last word (address 0x1000_1BFC) is different from 0xFFFF_FFFF and a system reset occurred.

The flash memory is mapped on the AHB-Lite bus with the range described below:

Table 20. Flash memory section address

SectionFlash AHB start addressFlash AHB end address
Main flash0x1004_00000x100B_FFFF (1)
User OTP0x1000_18000x1000_1BFF

1. Depends on flash size. See Table 22: Flash size information.

9.3 Flash controller registers

9.3.1 Command register (COMMAND)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.COMMAND
rw

Bits 31:8 Reserved, must be kept at reset value.

Bit 7:0 COMMAND: Command opcode to launch any operation on flash memory. See Table 21 for command list and detail.

Table 21. Command list available

CommandFlash sectorDescriptionCommand Opcode
ERASEMain memoryErase page defined by register ADDRESS.0x11
MASSERASEMain memoryMass erase (main flash memory is completely erased).0x22
WRITE (1)Main memoryProgram one location (defined by registers DATA and ADDRESS).0x33
MASSREADMain memoryRead all locations and compare with DATA register value or produce LFSR signature.0x55
SLEEPWhole memoryPut flash in sleep mode.
Warning: once this command is launched, no access (read) nor action (any command except WAKE) on the flash component are possible until the WAKE command is requested (and associated CMDDONE status is returned)
0xAA
WAKEUPWhole memoryGet flash out of sleep mode.0xBB
BURSTWRITEMain memoryProgram 4 locations (ADDRESS → ADDRESS+3) with data in DATA0-DATA3 registers.
Warning: burst always starts (=DATA0 is always written) on a 16-bytes aligned address even if ADDRESS is not 16-bytes aligned (register bit field ADDRESS[1:0] always considered as 0 at flash controller level).
0xCC
OTPWRITEUser OTPOne time writable 1Kbytes for customer.
No erase not second programming is possible.
0xEE
KEYWRITEMain memoryWrite the customer key used to protect the main flash.0xFF
  1. Each address can be programmed only 2 times without erase operation in between.

Status bits behavior versus commands:

The sequences to use the different commands are described in 9.4: Programmer’s model on page 189.

9.3.2 Configuration register (CONFIG)

Address offset: 0x04

Reset value:

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WAIT_STATESDIS_GROUP_WRITEREMAP
rwrwrwrw

Bits 31:6 Reserved, must be kept at reset value.

Bits 5:4 WAIT_STATES: Number of wait states to be inserted on flash read (AHB accesses).

The flash embedded in the STM32WB09xE device requires 1 wait_state when system clock frequency is 64 MHz.

Bit 3 Reserved, must be kept at reset value.

Bit 2 DIS_GROUP_WRITE:

0: burst write operations are allowed/enabled.

1: burst write operations are blocked and result in a single write.

Note: if this bit is set during an on-going burst write operation, the flash controller stops the write operation at the end of the current word writing even if some words are still to be written.

Bit 1 REMAP: bit to redirect boot area on SRAM0. See Table 5: Address remapping depending on the REMAP bit for details.

Bit 0 Reserved, must be kept at reset value.

The flash can be read in one system clock cycle (the best for power consumption) when the system clock is 32MHz maximum.

9.3.3 Interrupt status register (IRQSTAT)

The interrupt status register shows the masked version of the interrupt raw register.

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.READOK_MISILLCMD_MISCMDERR_MISCMDSTART_MISCMDDONE_MIS
rc_w1rc_w1rc_w1rc_w1rc_w1

Bits 31:5 Reserved, must be kept at reset value.

Bit 4 READOK_MIS: Mass read OK masked interrupt status.

This bit is set at the end of a MASSREAD operation if all the words read in the memory match the DATA0 register value.

Cleared by writing 1.

Bit 3 ILLCMD_MIS: Illegal command masked interrupt status.

This bit is set when a bad opcode command is written in the COMMAND register.

Cleared by writing 1.

Bit 2 CMDERR_MIS: command error masked interrupt status.

This bit is set if a command opcode is written in COMMAND register while the flash is busy.

Cleared by writing 1.

Bit 1 CMDSTART_MIS: Command started masked interrupt status.

This bit is set once the requested command execution has started.

Cleared by writing 1.

Bit 0 CMDDONE_MIS: Command done masked interrupt status.

This it is set once the requested command execution is completed.

Cleared by writing 1.

The CMDDONE and CMDSTART bits are updated a few clock cycles after the requested command has been started by writing to the COMMAND register.

Note: Clearing a bit by writing in IRQSTAT (respectively IRQRAW) register also cleared the same bit in IRQRAW (respectively IRQSTAT) register as they are referring to a common condition/event.

9.3.4 Interrupt mask register (IRQMASK)

The mask bit in IRQMASK masks the condition in the status register IRQSTAT and prevent the generation of the interrupt.

Address offset: 0x0C

Reset value: 0x0000 003F

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ILLCMD
M
CMDERR
M
CMDSTART
M
CMDDONE
M
rwrwrwrw

Bits 31:4 Reserved, must be kept at reset value.

Bit 3 ILLCMDM: Illegal command mask.

Bit 2 CMDERRM: command error mask.

Bit 1 CMDSTARTM: Command started mask.

Bit 0 CMDDONEM: Command done mask.

9.3.5 Raw status register (IRQRAW)

The raw status register shows the unmasked condition of interrupt events.

Address offset: 0x10

Reset value: 0x0000 0001

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ILLCMD_RISCMDERR_RISCMDSTART_RISCMDDONE_RIS
rc_w1rc_w1rc_w1rc_w1

Bits 31:4 Reserved, must be kept at reset value.

Bit 3 ILLCMD_RIS: Illegal command raw/unmasked interrupt status.

This bit is set when a bad opcode command is written in the COMMAND register.

Cleared by writing 1.

Bit 2 CMDERR_RIS: command error raw/unmasked interrupt status.

This bit is set if a command opcode is written in COMMAND register while the flash is busy.

Cleared by writing 1.

Bit 1 CMDSTART_RIS: Command started raw/unmasked interrupt status.

This bit is set once the requested command execution has started.

Cleared by writing 1.

Bit 0 CMDDONE_RIS: Command done raw/unmasked interrupt status.

This it is set once the requested command execution is completed.

Cleared by writing 1.

The CMDDONE and CMDSTART bits are updated a few clock cycles after the requested command has been started by writing to the COMMAND register.

Note: Clearing a bit by writing in IRQSTAT (respectively IRQRAW) register also cleared the same bit in IRQRAW (respectively IRQSTAT) register as they are referring to a common condition/event.

9.3.6 SIZE register (SIZE)

Address offset: 0x14

Reset value: 0x000 XXXX (depends on device)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SWD_DISABLEFLASH_SECURERAM_SIZE[1:0]FLASH_SIZE[16]
-rrr
1514131211109876543210
FLASH_SIZE[15:0]
r

Bits 31:21 Reserved, must be kept at reset value.

Bit 20 SWD_DISABLE: Flash +SWD protection:

0: No SWD protection (refer to FLASH_SECURE)

1: FLASH and SWD protected

Bit 19 FLASH_SECURE: indicates the main FLASH is locked by a customer key.

0: the main FLASH is not protected.

1: the main FLASH is protected through a customer key.

Bits 18:17 RAM_SIZE: indicates the size of RAM available in the device:

00: 32 Kbytes of RAM available (RAM0 and RAM1 banks)

01: 32 Kbytes of RAM available (RAM0 and RAM1 banks)

10: 48 Kbytes of RAM available (RAM0, RAM1and RAM2 banks)

11: 64 Kbytes of RAM available (RAM0, RAM1, RAM2 and RAM3 banks)

Bits 16:0 FLASH_SIZE: indicates the last usable address of the flash using memory component address format. See Table 22 for relation between address at flash component level and AHB address mapping.

0xBFFF: 192 Kbytes of main flash are available on this device.

0xFFFF: 256 Kbytes of main flash are available on this device.

0x17FFF: 384 Kbytes of main flash are available on this device.

0x1FFFF: 512 Kbytes of main flash are available on this device.

Table 22. Flash size information

Main flash sizeHighest usable address at flash level(1)Highest usable address at AHB level
192 Kbytes0xBFFF0x1006_FFFC
256 Kbytes0xFFFF0x1007_FFFC
384 Kbytes0x17FFF0x1009_FFFC
512 Kbytes0x1FFFF0x100B_FFFC

1. Value seen in FLASH_SIZE bit field.

9.3.7 Address register (ADDRESS)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.XADDR [10]
rw
1514131211109876543210
XADDR[9:0]YADDR[5:0]
rwrw

Bits 31:17 Reserved, must be kept at reset value.

Bits 16:6 XADDR[10:0]:

Bits 5:0 YADDR[5:0]: word number inside the selected row (from 0 to 63)

Address to provide to the flash is not the AHB device mapping address but the address respecting flash component format.

The main flash is composed of 256 pages containing 8 rows each with 64 words = 256 bytes by row.

To program the ADDRESS register, the formula is the following:

Example 1: To program a word (32-bit) at AHB address 0x1005_0454:

9.3.8 Linear Feedback Shift register (LFSRVAL)

the LFSRVAL register contains the signature issued by a MASSREAD command.

The LFSRVAL register is initialized with all ones when the MASS READ command is written to the COMMAND register. Then every read value is put through the LFSR.

The final signature can be read in this register once the CMDDONE information is set.
customer.

Address offset: 0x24

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
LFSRVAL[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
LFSRVAL[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 LSFRVAL: signature after a MASSREAD command, generated through a Linear Feedback Shift Register block.

9.3.9 Main flash page protection registers (PAGEPROTx)

The PAGEPROTx registers allows protecting from accidental write a contiguous set of pages called segment in the following description. A maximum of four segments can be defined.

An example of usage is available in the

PAGEPROT0

Address offset: 0x34

Reset value: 0x0000 0000

31302928272625242322212019181716
SEG1[15:0]
rw
1514131211109876543210
SEG0[15:0]
rw

Bits 31:16 SEG1: second segment definition.

See SEG0 description for details on SEG1[15:0] content.

Bits 15:0 SEG0: First segment definition.

A segment SEGx is built as follows:

Notes:

PAGEPROT1

Address offset: 0x38

Reset value: 0x0000 0000

31302928272625242322212019181716
SEG3[15:0]
rw
1514131211109876543210
SEG2[15:0]
rw

9.3.10 Data registers (DATA0-DATA3)

The DATA0 register needs to be written with:

The DATA1-DATA3 registers need to be written only for burst write.

DATA0

Address offset: 0x40

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
DATA0[31:16]
rw
1514131211109876543210
DATA0[15:0]
rw

DATA1

Address offset: 0x44

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
DATA1[31:16]
rw
1514131211109876543210
DATA1[15:0]
rw
Bits 31:0 DATA1 : data that is written at ADDRESS+1 during a BURSTWRITE command. Note: this register is used only on burst write.

DATA2

Address offset: 0x48

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
DATA2[31:16]
rw
1514131211109876543210
DATA2[15:0]
rw
Bits 31:0 DATA2 : data that is written at ADDRESS+2 during a BURSTWRITE command. Note: this register is used only on burst write.

DATA3

Address offset: 0x4C

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
DATA3[31:16]
rw
1514131211109876543210
DATA3[15:0]
rw
Bits 31:0 DATA3 : data that is written at ADDRESS+3 during a BURSTWRITE command. Note: this register is used only on burst write.

9.3.11 Flash controller register map

Refer to Table 3: Memory map and peripheral register boundary addresses for the flash controller base address location in the STM32WB09xE.

Table 23. Flash controller register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00COMMANDRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.COMMAND[7:0]
Reset value0000000
0x04CONFIGRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WAIT_STATE[1:0]Res.Res.Res.Res.
Reset value01001
0x08IRQSTATRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.READOK_MISILLCMD_MISCMDERR_MISCMDSTART_MISCMDDONE_MIS
Reset value000000
0x0CIRQMASKRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ILLCMDMILLCMDMISCMDERRMCMDSTARTMCMDDONEM
Reset value11111
0x10IRQRAWRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ILLCMD_RISCMDERR_RISCMDSTART_RISCMDDONE_RIS
Reset value00001
0x14SIZERes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SWD_DISABLEFLASH_SECURERAM_SIZE[1:0]FLASH_SIZE[16:0]
Reset value--1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0x18ADDRESSRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.XADDR[10:0]YADDR[5:0]
Reset value0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0
0x24LFSRVALLFSRVAL[31:0]
Reset value1111111111111111111111111111111
ST logo
ST logo

Table 23. Flash controller register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x34PAGEPROT0SEG1[15:0]SEG0[15:0]
Reset value00000000000000000000000000000000
0x38PAGEPROT1SEG3[15:0]SEG2[15:0]
Reset value00000000000000000000000000000000
0x3CReserved
0x40DATA0DATA0[31:0]
Reset value11111111111111111111111111111111
0x44DATA1DATA1[31:0]
Reset value11111111111111111111111111111111
0x48DATA2DATA2[31:0]
Reset value11111111111111111111111111111111
0x4CDATA3DATA3[31:0]
Reset value11111111111111111111111111111111

9.4 Programmer’s model

The STM32WB09xE embeds up to 512 Kbytes of internal flash memory. A flash interface implements instruction access and data access based on the AHB protocol. It implements the logic necessary to carry out the flash memory operations (Program/Erase) controlled through the flash registers.

9.4.1 General information

Writing to flash memory only allows clearing bits from ‘1’ to ‘0’. This means any write from ‘0’ to ‘1’ implies erasing before performing a write.

Flash memory is composed of 256 pages containing 8 rows of 64 words (256 x 8 x 64 = 131072 words). Each word is 32-bit = 4 bytes long which means 512kB of flash.

The address inside the flash controller ADDRESS register is built as follows:

ADDRESS[15:0] = XADR[10:0] & YADR[5:0] with

Note: One specific address can be written only twice between two erase actions even if each writing only clears bits.

ST logo
ST logo

9.4.2 Read function example

There are two possible read accesses:

There are two ways of using MASSREAD:

MASSREAD sequence:

  1. 1. Write in the flash controller DATA register the expected value (if MASSREAD is used in combination with the READOK flag).
  2. 2. Write the MASSREAD command (0x55) in the flash controller COMMAND register.
  3. 3. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command has been taken into account and is under execution.
  4. 4. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  5. 5. Then, wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command is completed.
  6. 6. Check the READOK flag (expected high) in the IRQSTAT register or the LFSRVAL register value to ensure flash memory content is the expected result.
  7. 7. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register.

9.4.3 Erase function example

The flash controller allows the erasure of one page, or full erasure of the main flash-memory.

ERASE sequence (erase one page):

  1. 1. Write the page address to be erased by writing in the flash controller ADDRESS register the following value:
  2. 2. ADDRESS[16:9] = XADR[10:3] = page address to erase
  3. 3. ADDRESS[8:0] = 9'b0 (row and word addresses at zero).
  4. 4. Write the ERASE command (0x11) in the flash controller COMMAND register.
  5. 5. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating command is taken into account and under execution.
  6. 6. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  7. 7. Wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command is completed.
  8. 8. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register.
  9. 9. After this command, the erased page contains only bits set to '1'.

MASSERASE sequence (erase whole main flash):

  1. 1. Write the MASSERASE command (0x22) in the flash controller COMMAND register.
  2. 2. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command has been taken into account and is under execution.
  3. 3. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  4. 4. Wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command is completed.
  5. 5. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register.
  6. 6. After this command, the full main flash contains only bits set to '1'.

9.4.4 Write function example

The flash controller allows writing one word (WRITE), up to 4 words (BURSWRITE) or the full main flash memory (with a single fixed word).

Note: As a write can only program to '0' on bits already set to '1', it is necessary to erase the page and request that the bits be set to '1' (instead of '0') in order to re-write to '0'.

WRITE sequence:

  1. 1. Indicate the location to write by filling the flash controller ADDRESS register with the targeted address (page, row and word number)
  2. 2. Write the value to program in the flash controller DATA register.
  3. 3. Write the WRITE command (0x33) in the flash controller COMMAND register.
  4. 4. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command has been taken into account and is under execution.
  5. 5. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  6. 6. Wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command is completed.
  7. 7. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register.

BUSRTWRITE sequence:

  1. 1. Indicate the location to write by filling the flash controller ADDRESS register with the targeted address of the first data to write (page, row and word number). DATA0 is written at ADDRESS, DATA1 at ADDRESS+1, etc.
  2. 2. Write the values to program in the flash controller DATA0-3 registers. To write less than four words, write 0xFFFFFFFF in the unused DATA1-3 registers.
  3. 3. Write the BURSTWRITE command (0xCC) in the flash controller COMMAND register.
  4. 4. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command has been taken into account and is under execution.
  5. 5. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  6. 6. Wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command is completed.
  7. 7. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register.

9.4.5 Enabling protection example

The device offers three level of protection to prevent application cloning and or altering of application code. The different levels are described in the Table 24. It is important to notice that disabling of SWD access is an irreversible operation.

Table 24. System memory protection

ProtectionUserKey[Data0]UserKey[Data1]Disable protectionDescription
None0xFFFFFFFF0xFFFFFFFFNot applicableDebugger can access and modify flash memory and RAM content. This is the default configuration. All the bootloader commands are available.
Readout0xAAAAAAAA0xAAAAAAAAPerform mass eraseDebugger cannot read or modify both flash memory and RAM content. The bootloader commands READ_MEMORY, WRITE_MEMORY and GO are disabled and MASS ERASE is available.
SWD0xABACABAD0xABACABADThis selection is irreversibleDebugger connection is not possible. There is no possibility to access to the device via SWD and all the bootloader commands are disabled.
Not specifiedAny other valueAny other valueNot applicableThis configuration is forbidden and can lead to unrecoverable damage of the device

In order to activate the desired level of protection, the following KEYWRITE sequence should be used:

  1. 1. Write DATA0 (LSB key) and DATA1 (MSB key) registers with the value to program
  2. 2. Write 0xC7EF584D to DATA2 and 0xB3A21096 to DATA3
  3. 3. Write the KEYWRITE command (0xFF) in the flash controller COMMAND register
  4. 4. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command has been taken into account and is under execution.
  5. 5. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  6. 6. Wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode), indicating that the command is completed.
  7. 7. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register. The key are activated (and flash and RAM banks are protected) after a reset.

Note: The secure bootloader capability offers a further security level for preventing unwanted control from external users.

When the secure bootloader capability is enabled the flash and RAM contents are readable. The GO command of the bootloader is disabled and all the other bootloader commands are available. Only signed firmware can be executed.

For more information about the secure bootloader capability refer to application note AN6140: How to use the secure bootloader on STM32WB0 MCUs.

9.4.6 OTP function example

OTPWRITE sequence:

ST logo
ST logo
  1. 1. Write DATA0 register with the value to program (no burst write feature is available as only few bytes to be written once only)
  2. 2. Write ADDRESS register according to the following rule:
    ADDRESS[16:9] = don't care (page number frozen by hardware on this command)
    ADDRESS[8:6] = 0, 1, 2 or 3
    ADDRESS[5:0] = full area possible (from 0x00 to 0x3F)
  3. 3. Write the OTPWRITE command (0xEE) in the flash controller COMMAND register
  4. 4. Wait for the CMDSTART flag in the IRQSTAT register (polling mode or interrupt mode) indicating that the command has been taken into account and is under execution.
  5. 5. Clear the CMDSTART flag by writing CMDSTART to '1' in the flash controller IRQSTAT register.
  6. 6. Wait for the CMDDONE flag in the IRQSTAT register (polling mode or interrupt mode), indicating that the command is completed.
  7. 7. Clear the CMDDONE flag by writing CMDDONE to '1' in the flash controller IRQSTAT register.

Note: The OTP locations are following flash memory rules, that is, a second write only flip bit from 1 to 0. If the user wishes to lock the OTP values and prevent any further modification in the OTP area, it must write the last OTP word (address 0x10001BFC) with a value different from 0xFFFFFFFF and perform system reset. The operation of locking the OTP area is irreversible.

9.4.7 Write page protection example

Example to write protect against accidental programming knowing the flash starts at address 0x1004_0000 and contains 256 pages of 2 Kbytes (pages 0 to 255).

Starting page: 0xC000/0x800 = 0x18

SEG0[15:8] = 0x18 (OFFSET = 0x18)

Number of pages: (0x10000-0xC000)/0x800 = 0x8

SEG0[7:0] = 0x08 (SIZE = 0x08)

Starting page: 0x1E000/0x800 = 0x3C

SEG1[15:8] = 0x3C (OFFSET = 0x3C)

Number of pages: (0x20000-0x1E000)/0x800 = 0x4

SEG1[7:0] = 0x04 (SIZE = 0x04)

Conclusion: Program the PAGEPROT0 = 0x3C041808.