7. Embedded flash memory (FLASH)
7.1 Introduction
The embedded flash memory (FLASH) manages the accesses of any master to the 128 Kbytes of embedded non-volatile memory. It implements the read, program and erase operations, error corrections, as well as various integrity and confidentiality protection mechanisms.
The embedded flash memory manages the automatic loading of non-volatile user option bytes at power-on reset, and implements the dynamic update of these options.
The embedded flash memory also features a one-time-programmable (OTP) area and a read-only area provisioned by STMicroelectronics during the product manufacturing.
7.2 FLASH main features
- • 128 Kbytes of non-volatile memory divided into two banks of 64 Kbytes
- • Flash memory read operations supporting multiple lengths: 128 bits, 64 bits, 32 bits, 16 bits or one byte
- • Flash memory programming by 128 bits (user area) and 16 bits (OTP)
- • 8 Kbytes sector erase, bank erase and dual-bank mass erase
- • Dual-bank organization supporting:
- – simultaneous operations: read-while-write (program and erase) is supported.
- – the two banks share the same interface, write and erase can not be performed in parallel (write-while-write is not supported).
- – bank swapping: the address mapping of the user flash memory of each bank can be swapped, along with the corresponding registers. Security flags remain valid for the physical bank, so the data are not revealed by swapping to a bank with lower security configuration.
- • Error code correction (ECC): one error detection/correction or two error detections per 128-bit Flash word using 9 ECC bits
- • User configurable non-volatile option bytes
- • Flash memory enhanced protections, activated by option bytes
- – different product states for protecting memory content from debug access
- – sector write-protection (WRPSG), configurable by sector
- – HDP protection providing temporal isolation for startup code
- • 2 Kbytes one-time programmable (OTP) area
- • Read-only area provisioned by STMicroelectronics
- • Prefetch is reading the next sequential instruction from flash memory
7.3 FLASH functional description
7.3.1 FLASH block diagram
The following figure presents the embedded flash memory block diagram.
Figure 12. Flash block diagram (simplified)

7.3.2 FLASH signals
The flash memory has two AHB connections: the flash AHB register interface and the main AHB interface.
Flash AHB register interface
- • Data size is 32 bits
- • Except for some registers (FLASH_NSKEYR and FLASH_OPTKEYR registers that are used to insert unlock sequences for control and option registers and can be wrote by 32 bits), it is possible to read and write all registers by 8, 16 and 32 bits
- • When unlock sequence for control and option registers is wrong, a bus error is raised, otherwise no read or write errors are generated on the bus
Main AHB interface
The AHB data bus size is 128 bits.
This interface is used to handle three different targets:
- • Code placed in user and system memory. It is protected by 9 bits of ECC
- • OTP, read only protected by 6 bits of ECC.
The main AHB interface is implemented as follows:
- • User and system memory:
- – Supports multiple length: 128-, 64-, 32-, 16- and 8-bit data width
- – There is a read buffer of 128 bits for each bank where the last data read is stored. If the data is available in the read buffer, no read access is done to the flash memory. Buffer is flushed when write access, OTP access, user option change request or erase operation occurs
- – There is a prefetch of the same size as the read buffer
- – A 9-bit ECC is associated to each 128-bit data flash memory word
- • OTP, read only
- – Two dedicated data buffer of 137 bits are used to manage 16-bit data with 6-bit ECC
- – Reading two times the same address triggers two Flash read access
- – During a read access, two wait states are added in addition of the memory wait states. These wait states are necessary to parse the data buffer
- – Each write access triggers a write in the flash memory
- – 6-bit ECC is associated to each 16-bit data.
By default, all the AHB memory range is cacheable. For regions where caching is not practical (OTP, RO), MPU has to be used to disable local cacheability.
7.3.3 Flash memory architecture and usage
Flash memory architecture
The following figure shows the non-volatile memory organization supported by the embedded flash memory.
Figure 13. Embedded flash memory organization

The diagram illustrates the embedded flash memory organization. It features two main banks, Bank1 and Bank2, managed by Flash Interface Logic. The Main AHB system bus and AHB config port are connected to the Flash Interface Logic. Bank2 is divided into System memory (per bank) and a Read-only area. The System memory (per bank) in Bank2 consists of 4 sectors of 8 kB each, with 9-bit ECC per 128-bit flash word. The Read-only area in Bank2 is labeled 'Read-only'. Bank1 is divided into User main memory (per bank) and a Special region (Bank 1 only). The User main memory (per bank) in Bank1 consists of 8 sectors of 8 kB each, with 9-bit ECC per 128-bit flash word. The Special region (Bank 1 only) has 6-bit ECC per 16-bit, is OTP writable only once, and is Read-only writable only by STMicroelectronics. The diagram also shows OTP, Option Bytes, and various access protection labels like 'No user access' and 'Write-protected'.
The embedded Flash non-volatile memory is composed of:
- • A 128-Kbyte main memory block, organized in two banks, 64 Kbyte each. Each bank is divided in 8 sectors of 8 Kbytes each, and features Flash-word rows of 128 bits + 9 bits of ECC per word
- • A system memory block of 64 Kbytes, divided into two 32-Kbyte banks. Each bank is divided in four 8 Kbytes sectors. The system flash memory is ECC protected (9-bit ECC per 128-bit word)
- • A set of non-volatile option bytes loaded at reset by the embedded flash memory and accessible by the application software only through the AHB configuration register interface.
- • A 2-Kbyte one-time-programmable (OTP) area that can be written only once by the application software
- • A 2-Kbyte read-only area. It contains a unique device ID and product information
The overall flash memory architecture and its corresponding access interface is summarized in Table 24.
Partition usage
The following figure shows how the embedded flash memory is used both by STMicroelectronics and the application software.
Figure 14. Embedded flash memory usage

User and system memories are used differently according to product state and other option bytes settings:
- • The user memory contains the application code and data, the root secure services (RSS), the debug authentication code (ST-DA), and the STM32 bootloader. When a reset occurs, the core jumps to the boot address configured through the BOOT pin, the BOOT_ADDR option bytes and the product state
- • If the debugger is attached to the product, the entry point is the debug authentication policy, used to unlock the device via the SBS when attached to debugger. A digital signature must be provided to perform a regression to product state, where debug is allowed
Note:For more information on option byte setup for boot, refer to Section 7.4.7.
7.3.4 FLASH read operations
Read operation overview
Read access to main flash memory and system flash memory operates as follows:
- • There is a 128-bit read data buffer associated to each bank, which stores the last data read. If several consecutive read accesses request data belonging to the same Flash data word (128 bits), the data are read directly from the current data read buffer, without triggering additional Flash read operations. This mechanism occurs each time a read access is granted. When a read access is rejected for security reasons, the corresponding read error response is issued by the embedded flash memory and no read operation to flash memory is triggered
- • The read data buffer is disabled when write access or OTP access, user option change request or other erase operation occurs
Read access to OTP, RO operates as follows:
- 1. Flash data word of 137 bits is read and stored in a temporary buffer
- 2. The interface parses the 137 bits data word and selects the 16-bit or 32-bit data requested
- 3. While parsing the 137-bit data word, two wait states are added and the AHB bus is stalled
- 4. If the application reads an OTP data not previously written, a double ECC error is reported and only word full of set bits is returned (see Section 7.3.9: OTP and RO memory access for details). The read data (in 16 bits) is stored in FLASH_ECCDR register so that the user can identify if the double ECC error is due to a virgin data or a real ECC error
- 5. Reading two times the same address triggers two reads in the flash memory
- 6. For 8-bit accesses, an AHB bus error is generated.
Note: The embedded flash memory can perform single-error correction and double-error detection while read operations are being executed (see Section 7.3.8: Flash memory error protections).
Instruction prefetch
The Cortex-M33 fetches instructions and literal pools (constants/data) over the C-Bus and through the instruction cache if it is enabled. The prefetch block aims at increasing the efficiency of C-Bus accesses when the instruction cache is enabled, by reducing the cache refill latency.
Prefetch is efficient in case of sequential code; prefetch in the flash memory allows the next sequential instruction line to be read from the flash memory, while the current instruction line is being filled in instruction cache and executed by the CPU.
Prefetch is enabled by setting the PRFTEN bit in the flash memory access control register (FLASH_ACR). PRFTEN must be set only if at least one wait state is needed to access the Flash memory.
Adjusting read timing constraints
The embedded flash memory clock must be enabled and running before reading data from a non-volatile memory.
To correctly read data from the flash memory, the number of wait states (LATENCY) must be correctly programmed in the Flash access control register (FLASH_ACR) according to the embedded flash memory main AHB interface clock frequency, and the internal voltage range of the device (\(V_{core}\)).
The table below shows the correspondence between the number of wait states (LATENCY), the programming delay parameter (WRHIGHFREQ), the embedded flash memory clock frequency and the supply voltage ranges.
Table 20. FLASH recommended number of wait states and programming delay
| Number of wait states (LATENCY) | Programming delay (WRHIGHFREQ) | Interface clock frequency v.s. \(V_{core}\) range | |||
|---|---|---|---|---|---|
| VOS3 range 0.95 V - 1.05 V | VOS2 range 1.05 V - 1.15 V | VOS1 range 1.15 V - 1.26 V | VOS0 range 1.30 V - 1.40 V | ||
| 0 WS (1 FLASH clock cycle) | 00 | [0 MHz; 20 MHz] | [0 MHz; 30 MHz] | [0 MHz; 34 MHz] | [0 MHz; 42 MHz] |
| 1 WS (2 FLASH clock cycles) | [20 MHz; 40 MHz] | [30 MHz; 60 MHz] | [34 MHz; 68 MHz] | [42 MHz; 84 MHz] | |
| 2 WS (3 FLASH clock cycles) | 01 | [40 MHz; 60 MHz] | [60 MHz; 90 MHz] | [68 MHz; 102 MHz] | [84 MHz; 126 MHz] |
| 3 WS (4 FLASH clock cycles) | [60 MHz; 80 MHz] | [90 MHz; 120 MHz] | [102 MHz; 136 MHz] | [126 MHz; 168 MHz] | |
| 4 WS (5 FLASH clock cycles) | 10 | [80 MHz; 100 MHz] | [120 MHz; 150 MHz] | [136 MHz; 170 MHz] | [168 MHz; 210 MHz] |
| 5 WS (6 FLASH clock cycles) | N/A | N/A | [170 MHz; 200 MHz] | [210 MHz; 250 MHz] | |
Note: The voltage range from 1.26 to 1.30 V is not supported.
Adjusting system frequency
After power-on, the embedded flash memory is clocked by the 32 MHz high-speed internal oscillator (HSI), with a voltage range set at a voltage scaling value of VOS3. As a result, a conservative 3 wait-state latency is specified in FLASH_ACR register (see the previous table).
When changing the bus frequency, the application software must follow the sequence described below, in order to tune the number of wait states required to access the non-volatile memory.
To increase the CPU frequency:
- 1. If necessary, program the LATENCY and WRHIGHFREQ bits to the right value in the FLASH_ACR register, as described in Table 20.
- 2. Check that the new number of wait states is taken into account by reading back the FLASH_ACR register.
- 3. Modify the embedded flash memory clock source and/or the clock prescaler in the RCC_CFGR register of the reset and clock controller (RCC).
- 4. Check that the new embedded flash memory clock source and/or the new AHB clock prescaler value are taken in account by reading back the embedded flash memory
clock source status and/or the prescaler value in the RCC_CFGR register of the reset and clock controller (RCC).
To decrease the CPU frequency:
- 1. Modify the embedded flash memory clock source and/or the clock prescaler in the RCC_CFGR register of reset and clock controller (RCC).
- 2. Check that the embedded flash memory new clock source and/or the new clock prescaler value are taken in account by reading back the embedded flash memory clock source status and/or the AHB interface prescaler value in the RCC_CFGR register of reset and clock controller (RCC).
- 3. If necessary, program the LATENCY and WRHIGHFREQ bits to the right value in FLASH_ACR register, as described in Table 20.
- 4. Check that the new number of wait states has been taken into account by reading back the FLASH_ACR register.
Error code correction (ECC)
The embedded flash memory embeds an error correction mechanism. Single-error correction and double-error detection are performed for each read operation. For more details, refer to Section 7.3.8: Flash memory error protections.
Read errors
When the ECC mechanism is not able to correct the read operation, the embedded flash memory reports read errors as described in Section 7.8.6: Error correction code error (ECCC/ECCD)
Read interrupts
See Section 7.9: FLASH interrupts for details.
7.3.5 FLASH program operations
Program operation overview
Program operation consists in issuing write commands. The embedded flash memory supports the execution of only one write-command at a time. Write-while-write are not supported. Nothing prevents overwriting a non-virgin flash word but this is not recommended. The result may lead to invalid data and inconsistent ECC code.
User Flash and system Flash memories sectors:
For the user and system flash memories, 9-bits ECC is associated to each 128-bits data Flash word. In this case, the embedded flash memory must always perform write operations to non-volatile memory with a 128-bit word granularity. Once the write buffer is full (128 bits), the Busy flag is set and a programming operation is triggered.
There is a write buffer common to Bank1 and 2 which support multiple write-access types (128, 64, 32, 16 or 8 bits). The application can decide to write as little as 8 bits to a 128 Flash word. In this case, a force-write mechanism to the 128 bits + ECC is used (see NSFW bit of FLASH_NSCR register).
When the write request is issued to the memory any new write request stalls the main AHB bus.
Moreover, while a write operation is ongoing, any new read request to the same bank stalls the main AHB bus.
OTP and RO:
When the target memory is OTP, RO sectors, 6-bits ECC code is associated to each 16-bit data Flash word. The embedded flash memory supports 16-bit or 32-bit write operations (8-bit write operations are not supported). For 8-bit accesses, write accesses are ignored. There is no write data buffer. Each write access triggers a write in the flash memory.
Note: The OTP area is typically write-protected on the final product, as described in Section 7.3.9: OTP and RO memory access.
The write protection check is performed at the reception of the write request (during address phase). Write protection is not checked anymore at the output of the write buffer. If a write protection violation is detected, the write operation is canceled and write protection error (WRPERR) is raised in FLASH_NSSR register.
For write protections of main Flash, ICP, and OTP see Section 7.5.
Monitoring ongoing write operations
The application software can use a status flags located in FLASH_NSSR to monitor ongoing write operations. Since only one operation is possible at a time, this flag indicates if any operation (write, erase, option change) is ongoing; whatever the banks.
- • BSY: this bits indicate that an effective write, erase, option byte change is ongoing in the non-volatile memory. This flag is not dedicated to a specific bank. It is set when an operation is starting on the memory, whatever the bank. An operation is triggered by:
- – An erase (FLASH_NSCR.STRT)
- – A write (FLASH_NSCR.PG + AHB write)
- – An option modification (FLASH_OPTCR.OPTSTRT)
They are cleared when the current operation is ending or in case of error.
- • NSWBNE: this bit indicates that the embedded flash memory is waiting for new data to complete the 128-bit write buffer. In this state the write buffer is not empty. It is reset as soon as the application software fills the write buffer, or forces the writes by using NSFW bit in FLASH_NSCR, or an error is detected. When NSWBNE is high, it is not possible to launch an erase, an option modification on flash memory.
- • DBNE: this bit indicates that the data buffer for parsing 16-bits data is not empty:
- – 16-bits data write access is received and that the data buffer is being filled. It is set at the receipt of the a valid write access and it is reset as soon as the write request preparation has been processed.
Note: If the flash memory is busy at the receipt of the AHB write request, the CPU execution is stalled.
Enabling write operations
Before programming the user flash memory in Bank1 or in Bank2, the application software must make sure that the PG bit is set to 1 in FLASH_NSCR. If it is not the case, an unlock sequence must be used (see Section 7.5.5: Flash memory configuration protection) and the PG bit must be set.
When the option bytes must be modified, the application software must make sure that FLASH_OPTCR is unlocked. If this is not the case, an unlock sequence must be used (see Section 7.5.5: Flash memory configuration protection).
Note: The application software must not unlock an already unlocked register, otherwise this register remains locked until the next system reset.
If needed, the application software can update the programming delay, as described in Adjusting programming timing constraints.
Writing to the FLASH control register FLASH_NSCR and FLASH_OPTCR
The FLASH_NSCR, FLASH_OPTCR registers are not accessible in write mode when the BSY bit is set. Any attempt to write these registers while the BSY bit is set causes the AHB bus to stall until BSY bit is cleared.
Single-write sequence
The recommended single-write sequence is the following:
- 1. Make sure protection mechanism does not prevent to attempt programming
- 2. Check that no flash memory operation is ongoing by checking the BSY bit in the FLASH_NSSR register and DBNE bits in the FLASH_NSSR register. Check that the write buffer is empty by checking the NSWBNE bit in the FLASH_NSSR register
- 3. Check and clear all the error flags due to previous programming/erase operation
- 4. Unlock the FLASH_NSCR register, as described in Section 7.5.5: Flash memory configuration protection (only if register is not already unlocked)
- 5. Enable write operations by setting PG bit in the FLASH_NSCR register
- 6. Write one Flash-word at aligned address
Note: NSWBNE flag indicates if the 128-bit write buffer is waiting for new data.
Note: No erase request, options change request is allowed between the first write and the completion of the Flash write operation.
- 7. Wait for the BSY bit to be cleared in the corresponding FLASH_NSSR register
- 8. Clear PG bit in FLASH_NSCR register if there are not any more programming requests
If step 6 is executed incrementally (for example byte per byte), the write buffer can become partially filled. In this case the application software can decide to force-write what is stored in the write buffer by using NSFW bit in FLASH_NSCR register. In this particular case, the unwritten bits are automatically set to 1. If no bit in the write buffer is cleared to 0, the NSFW bit has no effect.
Note: Using a force-write operation prevents the application from updating later the missing bits with a value different from 1, which is likely to lead to a unexpected or inconsistent data or ECC.
Adjusting programming timing constraints
Program operation timing constraints depend of the embedded flash memory clock frequency, which directly impacts the performance. If timing constraints are too tight, the non-volatile memory does not operate correctly, if they are too lax, the programming speed is not optimal.
The user must therefore trim the optimal programming delay through the WRHIGHFREQ parameter in the FLASH_ACR register. Refer to Table 20 in Section 7.3.4: FLASH read operations for the recommended programming delay depending on the embedded flash memory clock frequency.
FLASH_ACR configuration register is common to both banks.
The application software must check that no program/erase operation is ongoing before modifying WRHIGHFREQ parameter.
Caution: Modifying WRHIGHFREQ while programming/erasing the flash memory can corrupt the flash memory content.
Programming errors
When a program operation fails, an error can be reported as described in Section 7.8: FLASH error management.
Programming interrupts
See Section 7.9: FLASH interrupts for details.
7.3.6 FLASH erase operations
Erase operation overview
The embedded flash memory can perform erase operations on 8-Kbyte user sectors, on one user flash memory bank or on two user flash memory banks (for example mass erase).
For more details in user flash memory, user options and OTP erase protection see Section 7.5: FLASH security and protections.
Erase commands are issued through the AHB configuration interface. Since the embedded flash memory supports one operation at a time, if it receives simultaneously a write and an erase request an error flag is raised and both operation are canceled. See Section 7.8: FLASH error management for details.
Erase and WRP
If the application software attempts to erase a user sector that is write protected, the sector erase operation is aborted and the WRPERR flag is raised in the FLASH_NSSR register, as described in Section 7.8.2: Write protection error (WRPERR).
Flash Busy
Busy signals is described in Section : Monitoring ongoing write operations in Section 7.3.5: FLASH program operations
Writing to the FLASH control register FLASH_NSCR and FLASH_OPTCR
Refer to Writing to the FLASH control register FLASH_NSCR and FLASH_OPTCR in Section 7.3.5: FLASH program operations
Enabling erase operations
Before erasing a sector, the application software must make sure that FLASH_NSCR is unlocked. If this is not the case, an unlock sequence must be used (see Section 7.5.5: Flash memory configuration protection).
Note: The application software must not unlock a register that is already unlocked, otherwise this register remains locked until next system reset. This can be used to deliberately lock-out a register from further accesses.
Similar constraints apply to bank erase requests.
Flash sector erase sequence
To erase a 8-Kbyte user sector , proceed as follows:
- 1. Make sure protection mechanism does not prevent to attempt sector erase (WRP, HDP).
- 2. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in the FLASH_NSSR register and that the write buffer is empty by checking the WBNE bit in the FLASH_NSSR register.
- 3. Check and clear all the error flags due to previous programming/erase operation. Refer to Section 7.8: FLASH error management for details
- 4. Unlock the FLASH_NSCR register, as described in Section 7.5.5: Flash memory configuration protection (only if register is not already unlocked)
- 5. Set the BKSEL bit, the SER bit and SNB bitfield in the FLASH_NSCR register. BKSEL indicates in which physical bank sector has to be erased, then SER indicates a sector erase operation, while SNB contains the target sector number.
- 6. Set the STRT bit in the FLASH_NSCR register.
- 7. Wait for the BSY bit to be cleared in the FLASH_NSSR register.
- 8. STRT bit is automatically cleared at the end of the sector erase or in case of error.
- 9. Clear SER in FLASH_NSCR register if there are not anymore sector erase request to be issued.
Note: If another erase flag is requested simultaneously to the sector erase, an PGSERR error is generated.
Standard flash memory bank erase sequence
To erase bank :
- 1. Make sure protection mechanism does not prevent to attempt sector erase.
- 2. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in the FLASH_NSSR register and that the write buffer is empty by checking the WBNE bit in the same register.
- 3. Check and clear all the error flags due to previous programming/erase operation. Refer to Section 7.8: FLASH error management for details.
- 4. Unlock the FLASH_NSCR register, as described in Section 7.5.5: Flash memory configuration protection (only if register is not already unlocked).
- 5. Set the BKSEL bit and the BER bit in the FLASH_NSCR register to the targeted physical bank (swap setting is ignored).
- 6. Set the STRT bit in the FLASH_NSCR register to start the bank erase operation. Then wait until the BSY bit is cleared in the FLASH_NSSR register.
- 7. STRT bit is automatically cleared at the end of erase sequence or in case of error.
- 8. Clear BER in FLASH_NSCR register if there is not other bank erase request to be issued.
Flash mass erase sequence
The application software can set the MER bit to 1 in FLASH_NSCR register, as described below:
- 1. Make sure protection mechanisms do not prevent to attempt mass erase (Chapter 7.5)
- 2. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in the FLASH_NSSR register and that the write buffer is empty by checking the WBNE bit in the FLASH_NSSR register
- 3. Check and clear all the error flags due to previous programming/erase operation. Refer to Section 7.8: FLASH error management for details
- 4. Unlock the FLASH_NSCR register as described in Section 7.5.5: Flash memory configuration protection (only if the registers are not already unlocked)
- 5. Set the MER bit to 1 in FLASH_NSCR register
- 6. Set the STRT bit in the FLASH_NSCR register. Then wait until BSY bit is cleared in the FLASH_NSSR register
- 7. STRT bit is cleared automatically at the end of the erase sequence or in case of error
- 8. Clear MER in FLASH_NSCR register
7.3.7 FLASH parallel operations
Since the non-volatile memory is divided into two independent banks but encapsulated in the same macro, the embedded flash memory interface only supports reading in one bank while writing or erasing is executed in the other bank. This feature is called read-while-write capability (RWW). It does not support write-while-write or read-while-read.
In all cases, the sequences are described in Section 7.3.4: FLASH read operations, Section 7.3.5: FLASH program operations and Section 7.3.6: FLASH erase operations apply.
7.3.8 Flash memory error protections
Error correction codes (ECC)
The embedded flash memory supports an error correction code (ECC) mechanism. It is based on the SECDED algorithm in order to correct single errors and detect double errors.
This mechanism uses 9 ECC bits per 128-bit Flash word, and applies to user and system memory. For read-only, OTP, a stronger 6 ECC bits per 16-bit word is used. A double ECC error is generated for an OTP virgin word (for example a word with 22 bits at 1). When this OTP word is no more virgin, the ECC error disappears.
More specifically, during each read operation from a 128-bit Flash word, the embedded flash memory retrieves the 9-bit ECC information, computes the ECC of the Flash word, and compares the result with the reference value. If they do not match, the corresponding ECC error is raised as described in Section 7.8.6: Error correction code error (ECCC/ECCD)
During each program operation, a 9-bit ECC code is associated to each 128-bit data Flash word, and the resulting 137-bit Flash word information is written in non-volatile memory.
A similar mechanism applies to read-only and OTP areas, but with 6-bit ECC for 16-bit data.
7.3.9 OTP and RO memory access
OTP and RO memory are accessed through main AHB interface. The OTP is accessible at the address 0x08FF_F000 to 0x08FF_F7FF and the read only section is accessible from 0x08FF_F800 to 0x08FF_FFFF.
FLASH one-time programmable area
The embedded flash memory offers a 2048-byte memory area dedicated to application non-confidential, one-time programmable data (OTP). This area is composed of 1024 words of 16 bits (plus 6 bits of ECC). It cannot be erased, and can be written only once. The OTP area can be accessed through the main AHB interface from address 0x08FF_F000 to 0x08FF_F7FE (last whole readable 16-bit word).
OTP data can be programmed by the application software by chunks of 16 bits. Overwriting an already programmed 16-bit half-word can lead to data and ECC errors and is therefore not supported.
Note: The OTP area is virgin when the device is delivered by STMicroelectronics.
When reading OTP data with a single error corrected or a double error detected, the embedded flash memory reports read errors as described in Section 7.8.6: Error correction code error (ECCC/ECCD).
When reading OTP data not written by the application software (such as virgin OTP), the ECC correction reports a double-error detection (ECCD), and the data are to be found if FLASH_ECCDR register. ECCD implies a NMI raised, unless setting in SBS prevents that.
OTP write protection
OTP data are organized as 32 blocks of 32 OTP words, as shown in Table 21. An entire OTP block can be protected (locked) from write accesses by setting the LOCKBLi (i = 0 to 31) bit corresponding to each OTP block (i = 0 to 31) in the FLASH_OTPBLR option byte register. A block can be write-protected whether or not it has been programmed (even partially).
The OTP block locking operation is irreversible and independent from the product life state.
Note: The OTP area can only be accessed in read mode.
Table 21. Flash memory OTP organization
| OTP block | AHB address | AHB word | Lock bit | |
|---|---|---|---|---|
| [31:16] | [15:0] | |||
| Block 0 | 0x08FF F000 | OTP001 | OTP000 | LOCKBL0 |
| 0x08FF F004 | OTP003 | OTP002 | ||
| ... | ||||
| 0x08FF F03C | OTP031 | OTP030 | ||
| Block 1 | 0x08FF F040 | OTP033 | OTP032 | LOCKBL1 |
| 0x08FF F044 | OTP035 | OTP034 | ||
| ... | ||||
| 0x08FF F07C | OTP063 | OTP062 | ||
| Block 2 | 0x08FF F080 | OTP065 | OTP064 | LOCKBL2 |
| 0x08FF F084 | OTP067 | OTP066 | ||
| ... | ||||
| 0x08FF F0BC | OTP95 | OTP94 | ||
| ... | ||||
| Block 31 | 0x08FF F7C0 | OTP993 | OTP992 | LOCKBL31 |
| 0x08FF F7C4 | OTP995 | OTP994 | ||
| ... | ||||
| 0x08FF F7FC | OTP1023 | OTP1022 | ||
OTP write sequence
Follow the sequence below to write an OTP word:
- 1. Check that no flash memory operation is ongoing by checking the BSY bit in the FLASH_NSSR register and that the data buffer is empty by checking the DBNE bit in the FLASH_NSSR register
- 2. Check and clear all the error flags due to previous programming/erase operation.
- 3. Set PG bit in the FLASH_NSCR register
- 4. Check the protection status of the target OTP word (see Table 21). The corresponding LOCKBLi bit must not be set to 1
- 5. Write two OTP words (32 bits) corresponding to the 4-byte aligned address shown in Table 21. Alternatively, the application software can program separately the 16-bit MSB
- or 16-bit LSB. In this case the first 16-bit write operation starts immediately without waiting for the second one
- 6. Wait for the BSY bit to be cleared in the FLASH_NSSR register
- 7. Clear PG bit in FLASH_NSCR register if there is not any programming request anymore in the bank
- 8. Optionally, lock the OTP block using LOCKBLi to prevent further data changes.
Note: Do not write twice an OTP 16-bit word, otherwise an ECC error can be generated. Writing OTP data at byte level is not supported and generates a bus error. To avoid data corruption, it is important to complete the OTP write process (for example by reading back the OTP value), before starting an option change.
Flash read-only area
The embedded flash memory offers a 2-Kbyte memory area to store read-only data. This area is mapped as described in Table 22: Read-only public data organization. It can be accessed through the AHB main port. This read-only area is protected by a robust ECC scheme, as explained in Section 7.3.8: Flash memory error protections.
The read-only information that can be used by the application software are described in the table below. This information is programmed by STMicroelectronics.
Table 22. Read-only public data organization
| Read-only data name | Address | Comment |
|---|---|---|
| Unique device ID | 0x08FF F800 | U_ID[31:0] |
| 0x08FF F804 | U_ID[63:32] | |
| 0x08FF F808 | U_ID[96:64] | |
| Flash memory size/ package | 0x08FF F80C | Flash memory size[15:0] || Package code[15:0] |
| Reserved | 0x08FF F810 to 0x08FF FFFF | Reserved information |
7.3.10 Flash bank swapping
The embedded flash memory Bank1 and Bank2 can be swapped for the user Flash. This feature can be used after a firmware upgrade to restart the device on the new firmware. Bank swapping is an User Option byte flag controlled by the SWAP_BANK bit of the FLASH_OPTCR register.
Bank specific settings for data area and security attributes follow the original bank and its contents. Control bit always refers to physical bank, not the SWAP_BANK setting.
The following table shows the memory map that can be accessed depending on the SWAP_BANK bit configuration.
Table 24. memory map and the swapping option
| Flash memory area | Flash memory corresponding bank | Start address | End address | Size (bytes) | Region name | |
|---|---|---|---|---|---|---|
| SWAP_BANK=0 | SWAP_BANK=1 | |||||
| User main memory | Bank1 | Bank2 | 0x0800 0000 | 0x0800 1FFF | 8 K | Sector 0 |
| 0x0800 2000 | 0x0800 3FFF | 8 K | Sector 1 | |||
| ... | ... | ... | ... | |||
| 0x0800 E000 | 0x0800 FFFF | 8 K | Sector 7 | |||
| Bank2 | Bank1 | 0x0801 0000 | 0x0801 1FFF | 8 K | Sector 0 | |
| 0x0801 2000 | 0x0801 3FFF | 8 K | Sector 1 | |||
| ... | ... | ... | ... | |||
| 0x0801 E000 | 0x0801 FFFF | 8 K | Sector 7 | |||
| System memory | Bank1 | 0x0BF8 0000 | 0x0BF8 1FFF | 8 K | System 1 Sector 0 | |
| 0x0BF8 2000 | 0x0BF8 3FFF | 8 K | System 1 Sector 1 | |||
| ... | ... | ... | ... | |||
| 0x0BF8 6000 | 0x0BF8 7FFF | 8 K | System 1 Sector 3 | |||
| Bank2 | 0x0BF9 8000 | 0x0BF9 9FFF | 8 K | System 2 Sector 0 | ||
| 0x0BF9 A000 | 0x0BF9 BFFF | 8 K | System 2 Sector 1 | |||
| ... | ... | ... | ... | |||
| 0x0BF8 E000 | 0x0BF9 FFFF | 8 K | System 2 Sector 3 | |||
The SWAP_BANK bit in FLASH_OPTCR register is loaded from the SWAP_BANK option bit only after system reset or POR.
To change the SWAP_BANK bit (for example to apply a new firmware update), respect the sequence below:
- 1. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in the FLASH_NSSR register and that the write buffer is empty by checking the NSWBNE bit in the FLASH_NSSR register
- 2. Clear all error flags due to a previous operation
- 3. Unlock OPTLOCK bit, if not already unlocked
- 4. Set the new desired SWAP_BANK value in the FLASH_OPTSR_PRG register
- 5. Start the option byte change sequence by setting the OPTSTRT bit in the FLASH_OPTCR register
- 6. Once the option byte change has completed, FLASH_OPTSR_CUR contains the expected SWAP_BANK value, but SWAP_BANK bit in FLASH_OPTCR has not yet been modified and the bank swapping is not yet effective
- 7. Force a system reset or a POR. When the reset rises up, the bank swapping is effective (SWAP_BANK value updated in FLASH_OPTCR) and the new firmware shall be executed.
Note: The SWAP_BANK bit in FLASH_OPTCR is read-only and cannot be modified by the application software.
The SWAP_BANK option bit in FLASH_OPTSR_PRG can be modified whatever the product state. Instead of being locked by PRODUCT_STATE, it is locked by NSBOOT_LOCK User OB.
The following figure gives an overview of the bank swapping sequence.
Figure 15. Flash bank swapping sequence

graph TD
Begin([Begin]) --> Update[Update new firmware in user Flash bank 1/2]
Update --> Set[Set/unset SWAP_BANK_OPT option bit in FLASH_OPTSR_PRG]
Set --> Write[Write START bit in FLASH_OPTCR to start option byte change sequence]
Write --> Reset1[System reset]
Reset1 --> Copy[SWAP_BANK of FLASH_OPTSR_CUR is copied to SWAP_BANK_OPT bit in FLASH_OPTCR]
Copy --> End([End])
End --> Execution[Execution of new firmware]
subgraph Registers
FLASH_OPTSR_PRG[FLASH_OPTSR_PRG: SWAP BANK OPT]
FLASH_OPTSR_CUR[FLASH_OPTSR_CUR: SWAP BANK OPT]
FLASH_OPTCR[FLASH_OPTCR: SWAP BANK]
end
FLASH_OPTSR_PRG -- "Option byte programming" --> NonVol[Non-volatile memory]
NonVol -- "Option byte reload" --> FLASH_OPTSR_CUR
FLASH_OPTSR_CUR -- "System reset option byte reload" --> FLASH_OPTCR
FLASH_OPTCR -- "New swap policy effective" --> SWAPLogic[User Flash memory SWAP logic]
SWAPLogic <-->|AHB bus| NonVolBank1[Non-volatile memory Bank1]
SWAPLogic <-->|AHB bus| NonVolBank2[Non-volatile memory Bank2]
7.3.11 FLASH reset and clocks
Reset management
The embedded flash memory can be reset by a core domain reset, driven by the reset and clock control (RCC). The main effects of this reset are the following:
- • All registers, except for option byte registers, are cleared, including read and write latencies. If the bank swapping option is changed, it is applied.
- • Most control registers are automatically protected against write operations. To unprotect them, new unlock sequences must be used as described in Section 7.5.5: Flash memory configuration protection.
The embedded flash memory can be reset by a power-on core domain reset, driven by the reset and clock control (RCC). When the reset falls, all option byte registers are reset. When the reset rises up, the option bytes are loaded, potentially applying new features. During this loading sequence, the device remains under reset and the embedded flash memory is not accessible.
Reset occurring during Flash operation
If a reset occurs during a Flash operation (programing, erase or option change), the content of the flash memory is not guaranteed. It is mandatory for flash memory integrity than user restarts operation. The status register FLASH_OPSR gives information if any Flash operation has been interrupted by a reset.
FLASH_OPSR.CODE_OP gives opcode of operation. The following table indicates how to use FLASH_OPSR and which operation is required.
Table 25. Recommended reactions to FLASH_OPSR contents
| CODE_OP | Operation interrupted | OTP_OP | SYSF_OP | BK_OP | Flash area | ADDR_O P min | ADDR_O P max | Recommended action |
|---|---|---|---|---|---|---|---|---|
| 0x000 | No Flash operation ongoing while reset | 0 | 0 | 0 | _(1) | - | - | No extra action |
| 0x001 | Write operation | 0 | 0 | 0/1 | User Flash | 0x0000 | 0xFFFF | Erase sector and rewrite |
| 1 | 0 | 0 | OTP | 0x0600 | 0x07FF | |||
| 0x011 | Sector erase(2) | 0 | 0 | 0/1 | User Flash | 0x0000 | 0xFFFF | Relaunch sector erase |
| 0x100 | Bank erase | 0 | 0 | 0/1 | User Flash | - | - | Relaunch bank erase |
| 0x101 | Mass erase | 0 | 0 | 0 | User Flash | - | - | Relaunch mass erase |
| 0x110 | Option change | 0 | 0 | 0 | User configuration | - | - | New attempt on option change |
1. Dash represents “does not matter”.
2. Addresses indicated are aligned to sector start, data area sectors are erased by erase request to corresponding user flash memory sector.
Clock management
The embedded flash memory uses the microcontroller system clock (sys_ck), here the AHB interface clock.
7.4 FLASH option bytes
7.4.1 About option bytes
The embedded flash memory includes a set of non-volatile option bytes. They are loaded at power-on reset and can be read and modified only through configuration registers. This section documents:
- • When option bytes are loaded
- • How application software can modify them
- • The detailed list of option bytes, together with their initial values (before the first option byte change, user default configuration).
7.4.2 Option-byte loading
There are multiple ways of loading the option bytes into embedded flash memory:
1. Power-on wakeup
When the device is first powered, the embedded flash memory automatically loads all the option bytes. During the option byte loading sequence, the device remains under reset and the embedded flash memory cannot be accessed.
2. Wakeup from system Standby
When the core power domain, which contains the embedded flash memory, is switched from Standby mode to Run mode, the embedded flash memory behaves as during a power-on sequence. During loading time the device is not under reset, unlike power-on sequence.
3. Dedicated option byte reloading by the application
When the user application successfully modifies the option byte content through the embedded flash memory registers, the non-volatile option bytes are programmed and the embedded flash memory automatically reloads all option bytes to update the option registers.
Note: The option-byte read sequence is protected by error correction code.
In case of error, the option bytes are loaded with default values (see Section 7.4.3: Option-byte modification). This value differs from the initial values (user default configuration) and tends to be more restrictive.
7.4.3 Option-byte modification
Changing user option bytes
A user option-byte change operation can be used to modify the configuration and the protection settings saved in the non-volatile option byte area.
There are numerous rules enforced when attempting to change a user option byte, they are all summarized in Section 7.4.8: Specific rules for modifying option bytes. Failing to stick to those rules usually results in error, described in Section 7.8.7: Option byte change error (OPTCHANGEERR).
The embedded flash memory features two sets of option byte registers:
- • The first register set contains the current values of the option bytes. Their names have the _CUR extension. All “_CUR” registers are read-only. Their values are automatically loaded from the non-volatile memory after power-on reset, wakeup from system standby or after an option byte change operation.
- • The second register set allows the modification of the option bytes. Their names contain the _PRG extension. All “_PRG” registers can be accessed in read/write mode.
When the OPTLOCK bit in FLASH_OPTCR register is set, modifying the FLASH_XXX_PRG registers is not possible.
When OPTSTRT bit is set to 1, the embedded flash memory checks the programming sequence (PGSERR) and the conditions described in Section 7.4.8: Specific rules for modifying option bytes (OPTCHANGEERR). If no error has been detected (PGSERR/OPTCHANGEERR), the embedded flash memory launches the option byte modification in its non-volatile memory and updates the option byte registers with _CUR extension.
If one of the condition described in Section 7.4.8: Specific rules for modifying option bytes, Section 7.8.7: Option byte change error (OPTCHANGEERR) or Section 7.8.3: Programming sequence error (PGSERR) is not respected, the embedded flash memory aborts the option byte change operation. In this case, the FLASH_XXX_PRG registers are not overwritten by current option value. The user application can check what was wrong in their configuration.
Unlocking the option-byte modification
After reset, the OPTLOCK bit is set to 1 and the FLASH_OPTCR is locked. As a result, the application software must unlock the option configuration register before attempting to change the option bytes. The FLASH_OPTCR unlock sequence is described in Section 7.5.5: Flash memory configuration protection.
Option-byte modification sequence
To modify user option bytes, follow the sequence below:
- 1. Check that no flash memory operation is ongoing by checking the BSY bit in the FLASH_NSSR register and that the write buffer is empty by checking the NSWBNE bit in the FLASH_NSSR register
- 2. Check the data buffer is empty (DBNE=0) in FLASH_NSSR register.
- 3. Clear all error flags due to a previous operation
- 4. Unlock FLASH_OPTCR register as described in Section 7.5.5: Flash memory configuration protection, unless the register is already unlocked.
- 5. Write the desired new option byte values in the corresponding option registers (FLASH_XXX_PRG).
- 6. Set the option byte start change OPTSTRT bit to 1 in the FLASH_OPTCR register.
- 7. Wait that BSY bit is cleared in FLASH_NSSR register
- 8. OPTSTRT bit is cleared automatically at the end of the sequence (or in case of error)
- 9. Reset the device. This step is mandatory in case any of the following OB were included in the modification: Product state and NSBOOTADDR. Reset is recommended for other option-byte, but it is not strictly required.
Note: If a reset or a power-down occurs while the option byte modification is ongoing, the original option byte value is kept. A new option byte modification sequence is required to program the new value
7.4.4 Option-byte overview
The following table lists all the user option bytes managed through the embedded flash memory registers, as well as initial values before the first option byte change (user default configuration).
Table 26. Option-byte organization
| Register | Bitfield | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FLASH_OPTSR[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| SWAP_BANK | Res | Res. | IWDG_STDBY | IWDG_STOP | Res. | IO_VDDIO2_HSLV IO_VDD_HSLV | ||||||||||
| Default factory value | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| FLASH_OPTSR[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| PRODUCT_STATE | NRST_STDBY | NRST_STOP | Res. | WWDG_SW | IWDG_SW | BORH_EN | BOR_LEV | |||||||||
| Default factory value | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
Table 26. Option-byte organization (continued)
| Register | Bitfield | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FLASH_OPTSR2[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | |
| Default factory value | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| FLASH_OPTSR2[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | SRAM1_ECC | SRAM1_RST | Res. | Res. | SRAM2_ECC | Res. | BKPRAM_ECC | SRAM2_RST | Res. | Res. | Res. | |
| Default factory value | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| FLASH_NSBOOTR[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| NSBOOTADD[23:8] | ||||||||||||||||
| Default factory value | 0x0800 | |||||||||||||||
| FLASH_NSBOOTR[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| NSBOOTADD[7:0] | NSBOOT_LOCK | |||||||||||||||
| Default factory value | 0x00 | 0xC3 | ||||||||||||||
| FLASH_WRP1R[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | |
| Default factory value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| FLASH_WRP1R[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRP[7] | WRP[6] | WRP[5] | WRP[4] | WRP[3] | WRP[2] | WRP[1] | WRP[0] | |
| Default factory value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| FLASH_WRP2R[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | |
| Default factory value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| FLASH_WRP2R[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRP[7] | WRP[6] | WRP[5] | WRP[4] | WRP[3] | WRP[2] | WRP[1] | WRP[0] | |
| Default factory value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| FLASH_OTPBLR[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| LOCKBL | ||||||||||||||||
| Default factory value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Table 26. Option-byte organization (continued)
| Register | Bitfield | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FLASH_OTPBLR[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| LOCKBL | ||||||||||||||||
| Default factory value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| FLASH_HDP1R[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_END | |||
| Default factory value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| FLASH_HDP1R[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_STRT | |||
| Default factory value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| FLASH_HDP2R[31:16] | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_END | |||
| Default factory value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| FLASH_HDP2R[15:0] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_STRT | |||
| Default factory value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
7.4.5 Description of user and system option bytes
The general-purpose option bytes that can be used by the application are listed below:
- • Watchdog management
- – IWDG_STOP: independent watchdog IWDG counter active in Stop mode if 1 (stop counting or freeze if 0)
- – IWDG_STDBY: independent watchdog IWDG counter active in Standby mode if 1 (stop counting or freeze if 0)
- – IWDG_SW: hardware (0) or software (1) IWDG watchdog control selection
Note: If the hardware watchdog “control selection” feature is enabled (set to 0), the watchdog is automatically enabled at power-on, thus generating a reset unless the watchdog key register is written to or the down-counter is reloaded before the end-of-count is reached. Depending on the configuration of IWDG_STOP and IWDG_STDBY options, the IWDG can continue counting (1) or not (0) when the device is in Stop or Standby mode, respectively.
When the IWDG is kept running during Stop or Standby mode, it can wake up the device from these modes.
- • Reset management
- – BOR_LEV: Brownout reset (BOR) level, indicating the supply level threshold that activates/releases the reset. BOR can be enabled by setting BORH_EN option bit. Refer to Section 9: Power control (PWR)
- – NRST_STDBY: generates a reset when entering Standby mode if cleared to 0
- – NRST_STOP: generates a reset when entering Stop or Stop2 mode if cleared to 0
- – BORH_EN: enables brownout reset (BOR). Refer to Section 9: Power control (PWR)
Note: Whenever a Standby (respectively Stop) mode entry sequence is successfully executed, the device is reset instead of entering Standby (respectively Stop) mode if NRST_STDBY (respectively NRST_STOP) is cleared to 0.
- • Device options
- – IO_VDDIO2_HSLV: enables the configuration of pads below 2.7 V for VDDIO2 power rail if set to 1
- – IO_VDD_HSLV: enables the configuration of pads below 2.7 V for VDD power rail if set to 1
When STMicroelectronics delivers the device, the values programmed in the general-purpose option bytes are the following:
- • Watchdog management
- – IWDG active in Standby and Stop modes (option value = 0x1)
- – IWDG not automatically enabled at power-on (option byte value = 0x1)
- • Reset management:
- – BOR: brownout level option (reset level) equals 2.1 V (option byte value = 0x0). A reset is not generated when the device enters Standby, Stop or Stop2 low-power mode (option byte value = 0x1)
- • Device working in the full voltage range with I/O speed optimization at low-voltage disabled (IO_VDDIO2_HSLV=IO_VDD_HSLV=0)
Refer to Section 7.10: FLASH registers for details.
7.4.6 Description of data protection option bytes
The option bytes that can be used to enhance data protection are listed below:
- • PRODUCT_STATE[7:0]: A product life cycle state (see Section 7.5.8: Product state transitions for details).
- • WRP1/2: write protection option of sectors in Bank1 (respectively Bank2). It is active low. Refer to Section 7.5.6: Write protection for details.
- – Bit N: sector N write protected.
- • HDPx: HDPL exclusive area control in the user flash memory.
When factory programmed, values of the data protection option bytes are the following:
- • Product state depends on sales type
- • Write protection disabled (all option byte bits set to 1)
Refer to Section 7.10: FLASH registers for details.
7.4.7 Description of boot address option bytes
Below the list of option bytes that can be used to configure the appropriate boot address for an application:
- • PRODUCT_STATE
Influences the boot sequence indirectly. - • NSBOOTADD
Selects default boot address. - • BOOT_LOCK
Protects the boot configuration from further modification attempts. - • SWAP_BANK: bank swapping option, set to 1 to swap user Flash banks after boot (see Section 7.3.10: Flash bank swapping). If BOOT_LOCK is active, the value in SWAP_BANK is fixed, read-only.
When STMicroelectronics delivers the device, the PRODUCT_STATE is Open, BOOT_LOCK is not set (0xC3). Address NSBOOTADD = 0x0800 0000.
Refer to Section 7.10: FLASH registers for details.
7.4.8 Specific rules for modifying option bytes
On top of OPTLOCK bit and register access rules, there are also other protection means for selected security-sensitive option byte fields.
More option bytes can be modified simultaneously, but if they rely on each other for protection, both states are checked.
With few exceptions listed in this chapter, failing to uphold the rules results in raising OPTCHANGEERR flag (Section 7.8.7: Option byte change error (OPTCHANGEERR) for additional details).
Table 27. Specific OB modifying rules overview
| OB | HDPL | Value | Product state |
|---|---|---|---|
| PRODUCT_STATE | 0,1(1) | Set of possible transitions | Set of possible transitions (Table 37) |
| HDP | 0,1(1) | - | - |
| NSBOOTADD | - | - | Open or Provisioning, NSBOOT_LOCK disabled |
| LOCKBL | - | One way switch(1) | - |
| SWAP_BANK | - | - | - |
| NSBOOT_LOCK | - | - | Open, Regression or Provisioning to unlock |
1. Most transitions are possible regardless of HDPL. Only selected few require specific HDPL, see text below.
Even in the closed PRODUCT_STATE progression, some OB can still be modified, if all the other constraints are satisfied. An overview is presented in the following table.
Table 28. OB modifiable in closed product
| PRODUCT_STATE | OBs that may be modified |
|---|---|
| Closed | SWAP_BANK, LOCKBL, PRODUCT_STATE |
| Locked | SWAP_BANK, LOCKBL |
Specific rules must be respected to update the following OB:
- • PRODUCT_STATE
PRODUCT_STATE transitions follow a state machine with two types of transition. Locking down the product is allowed without restriction. Opening the product is only possible using a debug interface and following a digital signature verification. The regression to “Open PRODUCT_STATE” results in the erasing of the protected content. More details are given in Section 7.5.8: Product state transitions.
Summary: Selected changes only possible in HDPL1, regression in HDPL0. - • HDP
Can only be modified in HDPL0 and HDPL1. - • NSBOOTADD
Can only be changed in Open and Provisioning. Locked by NSBOOT_LOCK. - • LOCKBL
Can only be changed freely in one direction. A permanent irreversible switch. - • SWAP_BANK
Not modifiable when NSBOOT_LOCK is active (0xB4). - • NSBOOT_LOCK
Can only be changed freely in locking direction. Unlock is possible in Open, Provisioning and Regression.
Note: For all user option bytes above: default values are loaded and Tamper is signaled when a double ECC error occurs during OBL.
7.5 FLASH security and protections
Since sensitive information are stored in the flash memory, it is important to protect it against unwanted operations such as reading confidential areas, illegal programming of immutable sectors, or malicious flash memory erasing.
For that purpose flash memory implements the following protection mechanisms:
- • Temporal isolation protection (HDP)
- • Configuration protection
- • User Flash write protection
- • Device boot state management
- • OTP locking
This section provides a detailed description of all these security mechanisms.
Two access modes are possible:
- – Unprivilege
- – Privilege.
The flash memory interface evaluates the access restrictions in the following order:
- 1. Write protection (for write access)
- 2. HDP
- 3. Privilege
7.5.1 Hide protection (HDP)
One non-volatile secure hide protection (HDP) area per bank can be defined with a sector granularity. Access to the hide protection area can be denied by progressing the HDPL level in the SBS.
When the HDPL = 1, no user Flash is protected by the HDP. With HDPL ≥ 2 the user OB defined HDP area in each bank is closed. No read, write, fetch or erase is allowed in the HDP area.
The HDP area can be extended, the extension setting is only a register value, not stored in OB. With HDPL = 3 the HDP area remains activated and the extension is added. If extension is added while the base user OB defined area is not active, the extension covers one more sector, because HDPx_END sector is also protected.
The HDPL level can be only cleared by a system reset, there is no means to deactivate the HDP area.
The protected HDP area is defined by setting its size using start and end sectors .
The size of the inaccessible area can be extended using register FLASH_HDPEXTR values HDPx_EXT. The value HDPx_EXT is a number of sectors added to the HDP area (past the HDPx_END sector). The volatile HDPx_EXT value in the register can be increased, but cannot decrement.
In case of HDPx_STRT > HDPx_END the extension will cover (HDPx_EXT + 1) size area between sectors marked by HDPx_END and HDPx_END + HDPx_EXT.
By default both the HDPx_END is set to zero and HDPx_STRT is set to one. This means that the HDP area in user Flash is zero size and extends from the Flash start address (first sector).
For example, to protect area by HDP from the address 0x0800 2000 (included) to the address 0x0800 5FFF (included):
- • For physical Bank1, the option-byte registers must be programmed with:
- – HDP1_STRT = 0x01,
- – HDP1_END = 0x03.
Figure 16. HDP in user flash memory

The diagram illustrates the HDP protection mechanism in user flash memory. A horizontal bar represents the 'Flash bank' from Sector 0 to Sector 7. Above the bar, a protection region is defined by two markers: PSTRT = 0x01 and PEND = 0x03. The region between these markers is divided into two parts: 'HDP1- HDPL1 closes' and 'HDP_EXT=0x02'. The 'Flash bank' label is centered within the bar, and 'Sector 0' and 'Sector 7' are labeled at the ends.
- Once the HDPL is incremented to 2, the marked area becomes inaccessible. The HDPL = 2 code then sets the extension size to 2. Once the HDPL is incremented to 3, the extension area becomes also inaccessible.
Alternatively, if:
HDP1_END = 0
HDP1_START = 1
HDPx_EXT = 1
Sector 0 and Sector 1 are HDP protected.
Or a rather unusual example:
HDP1_END = 2
HDP1_START = 7
HDPx_EXT = 3 - Sectors 2 until 5 are HDP protected. Here the user should know that if his application needs sectors 2 until 4 only as HDP area, they should program HDPx_EXT at 2 instead of 3.
- If the two banks are swapped, the protection defined to physical Bank1 remains on the physical Bank1, unaffected by swapping. Separate protection applies to physical Bank2 and the option bytes registers must also be programmed with:
- – HDP2_STRT = 0x01
- – HDP2_END = 0x03
Note: For more details on the bank swapping mechanism, refer to Section 7.5.4: Flash memory banks attributes in case of bank swap.
Table 29. HDP protected definition
| User Flash | OB HDP Area enabled | HDP extension enabled |
|---|---|---|
| HDPL = 0,1 | HDP protected = 0 | HDP protected = 0 |
| HDPL = 2 | HDP protected = 1 | HDP protected = 0 |
| HDPL = 3 | HDP protected = 1 | HDP protected = 1 |
Table 30. Secure hide protection
| HDPx watermark option bytes values (x = 1,2) | Hide protection area |
|---|---|
| HDPL ≤ 1 | - No inaccessible HDP area in user Flash |
Table 30. Secure hide protection
| HDPx watermark option bytes values (x = 1,2) | Hide protection area | |
|---|---|---|
| HDPL = 2 | HDPx_END < HDPx_STRT | No inaccessible HDP area in user flash memory |
| HDPx_END = HDPx_STRT | Exactly one sector is protected by HDP | |
| HDPx_END > HDPx_STRT | The area between HDPx_STRT and HDPx_END is HDP protected | |
| HDPL = 3 | HDPx_END < HDPx_STRT and HDPx_EXT=0 | No inaccessible HDP area in user flash memory |
| HDPx_END ≥ HDPx_STRT or HDPx_EXT>0 | The area between min(HDPx_STRT, HDPx_END) and (HDPx_END + HDPx_EXT) is HDP protected | |
Table 31. HDP protections summary
| HDP protection | User Flash | |||
|---|---|---|---|---|
| Access to OB HDP area | Access to EXT HDP area | |||
| HDPL 2 or 3 | HDPL0 or HDPL1 | HDPL3 | HDPL0, 1 or 2 | |
| Fetch | BUS ERROR | OK | BUS ERROR | OK |
| Read | RAZ | RAZ | ||
| Write | WI, WRPERR | If WRP disabled: OK else: WI, WRPERR | WI, WRPERR | If WRP disabled: OK else: WI, WRPERR |
| Erase (mass erase) | ||||
7.5.2 Privileged flash memory area protection
Any sector can be programmed on-the-fly as privileged or unprivileged using the configuration registers. FLASH_PRIVBB1x (respectively FLASH_PRIVBB2x) registers are used to configure the privilege attribute for sectors in Bank1 (respectively Bank2).
When the sector privilege attribute PRIVBByx[i] bit is set, the sector is only accessible by a privileged access. An unprivileged sector is accessible by a privileged or unprivileged access.
To modify a block-based privilege attribution, it is recommended to:
- • Check that no Flash operation is ongoing on the related sector
- • Add an ISB instruction after modifying the sector security attribute PRIVBByx[i]
Caution: Switching a sector from privileged to unprivileged does not erase the content of the associated sector.
Table 32. Privilege protection summary
| Access | Main Flash | ||
|---|---|---|---|
| Unprivilege sector | Privilege sector | ||
| Privilege | Fetch | OK | |
| Read | |||
| Write | |||
| Erase | |||
| Unprivilege | Fetch | OK | RAZ |
| Read | WI, WRPERR | ||
| Write | |||
| Erase | |||
Table 33. Privilege and mass or bank erase
| Access | Main Flash | ||
|---|---|---|---|
| Unprivilege FLASH | Privilege FLASH | Mix unprivilege and privilege FLASH | |
| Privilege mass erase | OK | ||
| Unprivilege mass erase | OK | WI, WRPERR | |
Note: For PRIVBByx[ij] access control, refer to Table 34: Privilege configuration register access conditions.
Table 34. Privilege configuration register access conditions
| Access | Sector setting access in PRIVBBRxy | |
|---|---|---|
| X | P/NP | Bus error |
| R | P/NP | OK |
| W | P | OK |
| W | NP | WI |
7.5.3 Flash memory registers privileged and unprivileged modes
The Flash registers can be read and written by privileged and unprivileged accesses depending on the NSPRIV bits in FLASH privilege configuration register (FLASH_PRIVCFGR).
- • When the NSPRIV bit is reset, all flash memory registers could be read and written by both privileged or unprivileged access.
- • When the NSPRIV bit is set, all flash memory registers could be read and written by privileged access only. Unprivileged access to a privileged registers is RAZ/WI.
7.5.4 Flash memory banks attributes in case of bank swap
The SWAP_BANK option bit modifies the address of each bank in the memory map. When SWAP_BANK is reset, Flash Bank1 is mapped at the lower address range. When SWAP_BANK is set, Flash Bank1 is mapped at the higher address range. Flash bank attributes follow their bank contents so there is no need to modify their setting registers when swapping banks:
- • Flash write protection sector FLASH_WRPSG (refer to Section 7.5.6: Write protection)
- • Hide Protection in FLASH_HDPx registers.
- • Flash privilege block based bank x register y FLASH_PRIVBBxy
The SWAP_BANK is rendered immutable by setting NSBOOT_LOCK.
Note: The BK_ECC bit in the FLASH ECC correction register (FLASH_ECCCORR) and FLASH ECC detection register (FLASH_ECCDETR), BKSEL bit in FLASH control register (FLASH_NSCR) always refers to Bank1 (respectively Bank2) when it is low (respectively high), regardless of the SWAP_BANK value.
The figure below shows how security attributes and protections behave in case of bank swap.
Figure 17. Protection attributes in case of bank swap illustration

The diagram illustrates the protection attributes in case of bank swap. It shows two memory banks, Bank 1 and Bank 2, each with a specific protection structure. Bank 1 (purple) contains an HDP area (pink) at the top, followed by a Write protection blocks section (yellow), and then a large Bank 1 area. Bank 2 (green) contains a large Bank 2 area with no protections defined. A central 'SWAP' icon with two crossed arrows indicates the swap between the banks. The memory addresses for Bank 1 are 0x0800_0000 to 0x0800_FFFF, and for Bank 2 are 0x0801_0000 to 0x0801_FFFF.
7.5.5 Flash memory configuration protection
The embedded flash memory uses hardware mechanisms to protect the following assets against unwanted or spurious modifications (such as software bugs):
- • Option bytes change
- • Write operations
- • Erase commands
- • Interrupt masking
The embedded flash memory configuration registers protection is summarized in the next table. Registers not present in this table are not protected by a key.
Table 35. Flash interface register protection summary| Register name | Unlocking register | Protected asset |
|---|---|---|
| FLASH_NSCR | FLASH_NSKEYR | Write/erase control |
| FLASH_OPTCR | FLASH_OPTKEYR | Flash bank option byte words change |
7.5.6 Write protection
The purpose of embedded flash memory write protection is to prevent unwanted modifications to embedded non-volatile code and/or data.
Any 8 Kbytes sector can be independently write-protected or unprotected by clearing/setting the corresponding WRP1/2 bit in the FLASH_WRP1/2 register (see FLASH write sector protection for Bank1 (FLASH_WRP1R_CUR) and FLASH write sector protection for Bank2 (FLASH_WRP2R_CUR)).
A write-protected sectors can neither be erased nor programmed. As a result, a bank erase cannot be performed if some sector is write-protected.
Note: Write protection errors are documented in Section 7.8: FLASH error management.
7.5.7 Life cycle management
Non-volatile states, or debug states, are determined by the product state set by user option bytes. Debug possibility and possibility to change selected security settings are related to this state. While the state is stored in the OB, it is the SBS that controls the debug policy.
HDP works equally regardless of the debug state. Even in debug the HDP area is hidden when HDPL increments.
The following states are defined:
Table 36. Product states, debug states and debug policy| PRODUCT_STATE | Code in OB | Description |
|---|---|---|
| Open | 0xED | User Flash open (~RDP0) |
| Provisioning | 0x17 | Provisioning - OEM immutable root of trust is being installed. |
| Provisioned | 0x2E | OEM complete - the OEM immutable root of trust is installed. (~RDP 0.5) |
| Closed | 0x72 | State for running application. Debug disabled, regression is possible. |
| Locked | 0x5C | Transition to other state, policy change or debug is not permitted.(1) |
| Regression | 0x9A | The temporary state initiated by the debug authentication system in transition to Open |
1. Effectively the same situation is Closed state with incorrect or not defined debug certificates.
1. no debug protection
Read, program and erase operations into the Flash main memory area are possible. Least restriction on the option bytes.
2. full product protection
All debug features are disabled:
- • User mode: code executing in user mode (boot Flash) can access Flash main memory and selected option bytes with all operations (read, erase, program).
- • Boot RAM mode: boot from SRAM is not possible.
- • Transition to Open state is possible with the consequence of Flash mass erase. Depends on debug unlock policy (see below).
7.5.8 Product state transitions
Progressing to more closed state is the normal product life cycle, that does not require security measures. Transition in direction to open state is a regression, controlled by the debug authentication control. If debug unlock policy is set to “locked”, no regression is accepted. Locked state may be reinforced by invalidating the debug authentication certificates.
All transitions not listed in this chapter are invalid.
There is no restriction on reading the current product state.
Transitions in progress direction
Transition from Open to any of the closed states is matter of correct product configuration and provisioning. The transitions must be done in correct order.
The normal progression is:
- – Open to Provisioning or Provisioned
- – Provisioning to Provisioned
- – Provisioned to Locked or Closed
Transition is managed either by a software running on the device, or directly, using a debug interface. By software it is assumed that transitions are triggered by bootloader, or root of trust services, but generally any software running on the device can do a progress transition.
Transition to open debug state
This transition is a full regression. The starting state is any except Open and Locked. The debug tools are used to authenticate debug regression access rights with the debug authentication library, running on the device in HDPL=1 (refer to Section 13.3.6: SBS debug control). After verifying the credentials, it puts the device into intermediate state Regression. From this state the device regresses securely in HDPL=0 to Open.
The transition has the following consequence:
- – Product state updated
- – User options updated (security settings reset)
- – Flash memory mass erase (even write protected sectors)
- – Backup RAM erase (even if backup domain write protection is enabled)
Table 37. PRODUCT_STATE transitions
| From | To(1) | |||||
|---|---|---|---|---|---|---|
| Open | Provisioning | Provisioned | Closed | Locked | (Full) regression | |
| Open | - | OK | OK | X | X | X |
| Provisioning | X | - | OK | OK | OK | OK (HDPL1) |
| Provisioned | X | X | - | OK | OK | OK (HDPL1) |
| Closed | X | X | X | - | X | OK (HDPL1) |
| Locked | X | X | X | X | - | X |
| (Full) regression | OK (HDPL0) | X | X | X | X | - |
- 1. X = transitions that are not permitted (OPTCHANGEERR raised)
- = no change
OK = valid transitions.
In the Table 37: PRODUCT_STATE transitions the X marks transitions that are not permitted, dash marks no change, OK marks valid transitions. Some transitions are only possible in correct HDPL provided in parenthesis. Attempt to do a illegal transition results on OPTCHANGEERR.
Incorrect PRODUCT_STATE (on OBL) is interpreted as Locked.
7.5.9 One-time-programmable and read-only memory protections
Sections of OTP/RO in the flash memory are described in details in Section 7.3.9: OTP and RO memory access. There is no protection provided by the Flash interface other than the dedicated write protection.
No write is possible to the RO area, once it was established in manufacturing. The OTP write protection section describes a method of locking out the OTP area.
The access conditions are summarized in the following table.
Table 38. OTP/RO access constraints| - | 8 Kbytes sector dedicated to RO/OTP | |||
|---|---|---|---|---|
| 0x08FF_E000 - E7FF | 0x08FF_E800 - EFFF Reserved | 0x08FF_F000 - F7FF OTP | 0x08FF_F800 - FFFF RO | |
| X | BUS ERROR | BUS ERROR | ||
| R | If correct size(1) RAZ, else Bus Error | If correct size OK, else Bus Error | ||
| W | If correct size WI, else Bus Error | Bus Error if incorrect size. WRPERR if block is protected by LOCKBL, else OK. | If correct size WI, else Bus Error | |
| erase | WI | |||
1. Word size is 16-bits, 32b access is possible. Other access attempt leads to bus error.
7.6 System memory
7.6.1 System memory introduction
System memory stores RSS (root secure services) firmware that is programmed by ST during STM32H503xx production. The RSS provides runtime services to user firmware. These services are described hereafter in this section.
7.6.2 RSS user functions
The RSS provides runtime services thanks to RSS library. As other microcontroller peripherals features and mapping, the RSS library functions are exposed to user within the CMSIS device header file provided by the STM32CubeH5 firmware package. Please refer to UM2656 to get more details regarding STM32CubeH5 firmware package. RSS library provides runtime services through prefixed NSSLIB functions.
Table 39. C defined macro for RSS services| C defined macro | Location in flash memory |
|---|---|
| NSSLIB_PFUNC | 0x0BF8FE6C |
NSSLIB
The user firmware calls NSSLIB functions using NSSLIB_PFUNC C defined macro, that points to a location within system memory.
Table 40. NSSlib interface function list| Library | Function |
|---|---|
| NSSLIB_PFUNC | JumpHDPLvl2 |
| JumpHDPLvl3 |
The NSSLIB functions are described within section hereafter.
a) JumpHDPLvl2
Prototype:
uint32_t JumpHDPLvl2(uint32_t VectorTableAddr, uint32_t MPUIndex)
User code function call example:
NSSLIB_PFUNC->JumpHDPLvl2((uint32_t)NextVectorTableAddr, 1U );
Arguments:
- • VectorTableAddr:
Input parameter, address of the next vector table to apply.
The vector table format is the one used by the Cortex-M33 core.
- • MPUIndex:
Input parameter, MPU region index. Caller function shall define but keep disable the corresponding MPU region before calling JumpHDPLvl2. The function enables the MPU region before jumping to the Reset Handler of the vector table. The vector table Reset Handler function shall belong to the MPU region.
Descriptions:
User calls JumpHDPLvl2 to:
- • Close user Flash HDPL1 area by incrementing HDPL to 2
- • Jump to the reset handler embedded within the Vector Table which address is passed as input parameter
After closing HDPL1, JumpHDPLvl2 enables the MPU region provided as input parameter. Once the MPU is enabled, the function sets the SP to the address provided by the passed Vector Table and jumps to the Reset Handler function supported by the Vector Table too. JumpHDPLvl2 does not set the new vector table.
On successful execution, the function does not return and does not push LR onto the stack.
Errors:
In case of failure (bad input parameter value), RSSLIB_Sec_JumpHDPLvl2 returns 0xF5F5F5F5.
b) JumpHDPLvl3
Prototype
uint32_t JumpHDPLvl3(uint32_t VectorTableAddr, uint32_t MPUIndex)
User code function call example:
NSSLIB_PFUNC->JumpHDPLvl3((uint32_t)NextVectorTableAddr, 1U );
Arguments:
- • VectorTableAddr:
Input parameter, address of the next vector table to apply.
The vector table format is the one used by the Cortex-M33 core. - • MPUIndex:
Input parameter, MPU region index. Caller function shall define but keep disable the corresponding MPU region before calling JumpHDPLvl3. The function enables the MPU region before jumping to the Reset Handler of the vector table. The vector table Reset Handler function shall belong to the MPU region.
Descriptions:
User calls JumpHDPLvl3 to:
- • Close user Flash HDPL1 and HDPL2 areas by incrementing HDPL up to 3
- • Then jump to the reset handler embedded within the Vector Table which address is passed as input parameter
After closing HDPL1/2, JumpHDPLvl3 enables the MPU region provided as input parameter. Once the MPU is enabled, the function sets the SP to the address provided by the passed Vector Table and jumps to the Reset Handler function supported by the Vector Table too. JumpHDPLvl3 does not set the new vector table.
On successful execution, the function does not return and does not push LR onto the stack.
Errors:
In case of failure (bad input parameter value), JumpHDPLvl3 returns 0xF5F5F5F5.
7.7 FLASH low-power modes
Table 41 summarizes the behavior of embedded flash memory in STM32 low-power modes. Embedded flash memory belongs to the core domain.
Table 41. Effect of low-power modes on the embedded flash memory
| Power mode | Core domain voltage range | Allowed if FLASH Busy | FLASH power mode |
|---|---|---|---|
| Run/Sleep | VOS0/1/2/3 | Yes | Run |
| Stop (clock stopped) | SVOS3/4/5 | No | Clock gated (in normal or Low-power mode)(1) |
| Standby | Off | No | Off |
1. Flash is forced in Low-power mode when SVOS5 is selected.
When the system state changes or within a given system state, the embedded flash memory might get a different voltage supply range (VOS) according to the application. The procedure to switch the embedded flash memory into various power mode (run, clock gated, stopped, off) is described hereafter.
Note: For more information in the microcontroller power states, refer to the Power control section (PWR).
Managing the FLASH domain switching to Stop or Standby
As explain in Table 41, if the embedded flash memory informs the reset and clock controller (RCC) that it is busy (BSY, DBNE, NS/WBNE is set), the microcontroller cannot switch the core domain to Stop or Standby mode.
There are two ways to release the embedded flash memory:
- • Reset the NSWBNE busy flag in FLASH_NSSR register by any of the following actions:
- a) Complete the write buffer with missing data.
- b) Force the write operation without filling the missing data by activating the NSFW bit in FLASH_NSCR register. This forces all missing data “high”.
- • Poll BSY busy bits in FLASH_NSSR register until they are cleared. This indicates that all recorded write, erase and option change operations are complete.
The microcontroller can then switch the domain to Stop or Standby mode.
7.8 FLASH error management
7.8.1 Introduction
The embedded flash memory automatically reports when an error occurs during a read, program or erase operation. A wide range of errors are reported:
- • Write protection error (WRPERR)
- • Programming sequence error (PGSERR)
- • Error correction code error (ECCC/ECCD)
- • Option byte change error (OPTCHANGEERR)
The application software can individually enable the interrupt for each error, as detailed in Section 7.9: FLASH interrupts.
Note: For all errors, the application software must clear the error flag before attempting a new modify operation.
Since there is just one write buffer and only one operation is allowed at a time, the write control bits and status bits are shared by both banks:
- • Write control bits (PG, NSFW, EOPIE, WRPERRIE, PGSERRIE, STRBERRIE, INCERRIE, CLR_EOP, CLR_WRPERR, CLR_STRBERR, CLR_INCERR, CLR_PGSERR) controls bank1 and 2 at the same time.
- • Write status flag reports (NSWBNE, DBNE, EOP, WRPERR, PGSERR, STRBERR, INCERR, BSY) error for Bank1 and 2 at the same time.
7.8.2 Write protection error (WRPERR)
When an illegal erase/program operation is attempted to the non-volatile memory, the embedded flash memory sets the write protection error flag WRPERR in FLASH_NSSR register.
An erase operation is rejected and flagged as illegal if it targets one of the following memory areas:
- • A sector write-protected with WRP.
- • An HDP area while the HDPL has made it inaccessible.
- • Attempt to erase privilege sector within unprivileged mode.
A program operation is ignored and flagged as illegal if it targets one of the following memory areas:
- • The system flash memory
- • A user sector write-protected with WRP
- • An OTP block, locked with LOCKBL
- • A read-only section
- • A reserved area
- • Privileged area from within unprivileged mode
When WRPERR flag is raised, the operation is rejected and nothing is changed in the corresponding bank.
If this error is detected the write buffer is invalidated.
Note: WRPERR flag has to be cleared before any erase/program operation.
WRPERR flag is cleared by setting CLR_WRPERR bit to 1 in FLASH_NSCCR register.
If WRPERRIE bit in FLASH_NSCR register is set to 1, an interrupt is generated when WRPERR flag is raised (see Section 7.9: FLASH interrupts for details).
7.8.3 Programming sequence error (PGSERR)
When the programming sequence is incorrect, the Flash interface sets the programming sequence error flag PGSERR in FLASH_NSSR register.
More specifically, PGSERR flag is set when one of below conditions is met:
- • An error like INCERR, WRPERR, PGSERR, STRBERR, OPTCHANGEERR have not been cleared before requesting a new write or erase operation or options change.
- • For erase, PGSERR is set if:
- – missing erase operation (FLASH_NSCR): STRT=1 with (MER=0, SER=0 and BER=0)
- – sector and bank erase requested at the same time (STRT and more than one of MER, SER and BER)
- – PG set during erase operation (it ensures that no erase req and write req happen at the same time): (STRT=1) with (PG=1)
- – erase operation is started while write buffer is waiting for next data: (STRT=1) with WBNE=1.
- – erase operation is started while DBNE=1
- • For programming, PGSERR is set if:
- – missing write flag: A write operation is requested but the program enable bit PG has not been set in FLASH_NSCR register prior to the request.
- – AHB write request is received and (SER=1, BER=1 or MER=1)
- – 16 bit data access requested while WBNE=1
- • For options change, PGSERR is set if:
- – option change is started while write buffer is waiting for next data: OPTSTRT=1 with NSWBNE=1
- – OPTSTRT set with DBNE=1.
When PGSERR flag is raised as consequence of failed write attempt (Flash programming), the current program operation is aborted and nothing is changed in the corresponding bank. The write data buffer is also invalidated.
Note: When PGSERR flag is raised, there is a risk that the last write operation performed by the application has been lost because of the above protection mechanism. Hence it is recommended to generate interrupts on PGSERR and verify in the interrupt handler if the last write operation has been successful by reading back the value in the flash memory.
The PGSERR flag also blocks any new program operation. This means that PGSERR must be cleared before starting a new program operation.
PGSERR flag is cleared by setting CLR_PGSERR bit to 1 in FLASH_NSCCR register.
If PGSERRIE bit in FLASH_NSCR register is set to 1, an interrupt is generated when PGSERR flag is raised. See Section 7.9: FLASH interrupts for details.
7.8.4 Strobe error (STRBERR)
When the application software writes several times to the same byte in the write buffer, the Flash interface sets the strobe error flag STRBERR (FLASH_NSSR) whatever the target bank of the write access.
When STRBERR flag is raised, the current program operation is aborted and the write buffer is invalidated.
STRBERR flag is cleared by setting CLR_STRBERR bit to 1 in FLASH_NSCCR register.
If STRBERRIE bit in FLASH_NSCR register is set to 1, an interrupt is generated when STRBERR flag is raised. See Section 7.9: FLASH interrupts for details.
7.8.5 Inconsistency error (INCERR)
When a programming inconsistency in access is detected, the Flash interface sets the inconsistency error flag INCERR in register FLASH_NSSR.
More specifically, INCERR flag is set when one of the following conditions is met:
- • A write operation is attempted before completion of the previous write operation, for example:
- – The application software starts a write operation to fill the 128-bit write buffer, but sends a new write burst request to a different flash memory address before the buffer is full.
- – One master starts a write operation, but before the buffer is full, another master starts a new write operation to the same address or to a different address.
Note: INCERR flag must be cleared before starting a new write operation, otherwise a sequence error (PGSERR) is raised.
It is recommended to follow the sequence below to avoid losing data when an inconsistency error occurs:
- 1. Execute a handler routine when INCERR flag is raised.
- 2. Stop all write requests to embedded flash memory.
- 3. Clear INCERR bit.
- 4. Restart the write operations where they have been interrupted.
INCERR flag is cleared by setting CLR_INCERR bit to 1 in FLASH_NSCCR register.
If INCERRIE bit in FLASH_NSCR register is set to 1, an interrupt is generated when INCERR flag is raised (see Section 7.9: FLASH interrupts for details).
7.8.6 Error correction code error (ECCC/ECCD)
When a single-error correction is detected during a read, the Flash interface sets the single-error correction flag ECCC in FLASH_ECCCORR register.
When two ECC errors are detected during a read, the Flash interface sets the double error detection flag ECCD in FLASH_ECCDETR register.
When ECCC flag is raised, the corrected read data are returned. Hence the application can ignore the error and request new read operations. When ECCD flag is raised a NMI is generated. The software must invalidate the instruction cache (CACHEINV=1) in the NMI interrupt service routine when the ECCD flag is set. This NMI can be masked in SBS registers SBS flit ECC NMI mask register (SBS_ECCNMIR) for data access (OTP, data area, RO data).
When ECCC or ECCD flag is raised, the address of the Flash word that generated the error is saved in the FLASH_ECCCORR (FLASH_ECCDETR) register. If the address corresponds to a read-only area or to an OTP area, the OTP_ECC bit is also set to 1 in the FLASH_ECCCORR (FLASH_ECCDETR) register. This register is automatically cleared when the associated flag that generated the error is reset.
A BK_ECC flag indicates in which Flash bank the error occurred.
A SYSF_ECC flag indicates error detected in the system Flash area.
Table 42. Locating ECC failure
| OTP_ECC | SYSF_ECC | BK_ECC | Flash area | ADDR_ECC min | ADDR_ECC max |
|---|---|---|---|---|---|
| 0 | 0 | 0/1 | User Flash | 0x0000 | 0xFFFF |
| 0 | 1 | 0/1 | System Flash | 0x0000 | 0x0FFF |
| 1 | 0 | 0 | OTP | 0x0600 | 0x07FF |
Note: In case of successive single correction or double detection errors, only the address corresponding to the first error is stored in FLASH_ECCCORR (FLASH_ECCDETR) register.
Note: It is mandatory to clear ECCC or ECCD flags before starting a new read operation.
Note: As the ECC interface is shared by the two banks, if the same error is registered simultaneously, a physical Bank1 error is registered. Both errors are registered if one bank reports ECCD and the other bank ECCC.
ECCC (respectively ECCD) flag is cleared by setting to 1 ECCC bit (respectively ECCD bit) in FLASH_ECCCORR (FLASH_ECCDETR) register.
If ECCC bit in FLASH_ECCCORR register is set to 1, an interrupt is generated when ECCC flag is raised. Only NMI is generated for the ECCD. See Section 7.9: FLASH interrupts for details.
7.8.7 Option byte change error (OPTCHANGEERR)
When the Flash interface finds an error during an option change operation, it aborts the operation and sets the option byte change error flag OPTCHANGEERR in FLASH_NSSR register.
The error is raised after OPTSTRT bit set if:
- • Any forbidden PRODUCT_STATE transition (Table 37).
- • SWAP_BANK is locked out by NSBOOT_LOCK.
- • OB modification is attempted in wrong HDPL (selected PRODUCT_STATE transitions)
- • Attempt to modify OB with invalid value not recognized by the specification (enumerated magic numbers only)
- • Attempt to modify OB in product state where it is not allowed (usually a state open for debug is required for change).
Note: Exceptions and details provided in the OB description (see Section 7.4.8: Specific rules for modifying option bytes) and Table 27.
OPTCHANGEERR flag is cleared by setting CLR_OPTCHANGEERR bit to 1 in FLASH_CCR register.
If OPTCHANGEERRIE bit in FLASH_NSCR register is set to 1, an interrupt is generated when OPTCHANGEERR flag is raised (see Section 7.9: FLASH interrupts for details).
It is mandatory to clean the OPTCHANGEERR flag before starting a new operation (option change, erase or write).
7.8.8 Miscellaneous HardFault errors
The following events generate a bus error on the corresponding bus interface:
- • On main AHB system bus for access targeting code and data with 9 bits ECC.
- – Access to invalid address (including data addresses forbidden for code use).
- – Fetching from HDP area with incorrect HDPL value.
- – Fetching from privilege area in unprivilege mode.
- • On AHB configuration or system bus for accesses targeting OTP/RO (all addresses using 6-bits ECC):
- – wrong key input to FLASH_KEYR or FLASH_OPTKEYR.
- – 8-bit accesses to system AHB interface.
- – Wrong unlock sequence on a register.
7.9 FLASH interrupts
The Flash interface can generate a maskable interrupt to signal the following events on a given bank:
- • Read and write errors (see Section 7.8: FLASH error management)
- – Single ECC error correction during read operation
- – Write inconsistency error
- – Bad programming sequence
- – Strobe error during write operations
- – option change operation error
- • Security errors (see Section 7.8: FLASH error management)
- – Write protection error
- • Miscellaneous events (described below)
- – End of programming
A NMI is raised on double ECC error detection during read operation.
The user can individually enable or disable Flash interface interrupt sources by changing the mask bits in the FLASH_CR, FLASH_ECCCORR and FLASH_ECCDETR register. Setting the appropriate mask bit to 1 enables the interrupt.
Note: Prior to writing, FLASH_CR register must be unlocked as explained in Section 7.5.5: Flash memory configuration protection.
Table 43 gives a summary of the available Flash interface interrupt features. As mentioned in the table below, some flags need to be cleared before a new operation is triggered.
Table 43. Flash interrupt request
| Interrupt event Event flag | Error flag label in register | Enable control bit | Clear flag to resume operation |
|---|---|---|---|
| End of operation event | EOP | EOPIE | N/A |
| Write protection error | WRPERR | WRPERRIE | Yes |
| Programming sequence error | PGSERR | PGSERRIE | Yes |
| Strobe error | STRBERR | STRBERRIE | Yes |
| Inconsistency error | INCERR | INCERRIE | Yes |
| Option byte error | OPTCHANGEERR | - | Yes |
| ECC single error correction event | ECCC | ECCCIE | No |
| ECC double error detection event(1) | ECCD | Disabled | No |
1. NMI.
The status of the individual maskable interrupt sources described in Table 43 (except for option byte error and ECC) can be read from the FLASH_NSSR register. They can be cleared by setting to 1 the adequate bit in FLASH_NSCCR register.
Note: No unlocking mechanism is required to clear an interrupt.
End of operation event
Setting the end of operation interrupt enable bit (EOPIE) in the FLASH_NSCR register enables the generation of an interrupt at the end of an erase operation, a program operation or an option byte change.
Setting CLR_EOP bit to 1 in FLASH_NSCCR register clears EOP flag.
7.10 FLASH registers
Each register is assigned a offset address and a reset value. In case of registers representing option byte value, the reset value is determined by the OBL process. In case of success the reset value is loaded from OB. In case of OBL failure, a highly restrictive default value is set.
7.10.1 FLASH access control register (FLASH_ACR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
For more details, refer to Section 7.3.4: FLASH read operations and Section 7.3.5: FLASH program operations.
Address offset: 0x000
Reset value: 0x0000 0013
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | PRFTEN | Res. | Res. | WRHIGHFREQ[1:0] | LATENCY[3:0] | ||||
| rw | rw | rw | rw | rw | rw | rw | |||||||||
Bits 31:9 Reserved, must be kept at reset value.
Bit 8 PRFTEN: Prefetch enable. When bit value is modified, user must read back ACR register to be sure PRFTEN has been taken into account.
Bits used to control the prefetch.
0: prefetch disabled.
1: prefetch enabled when latency is at least one wait state.
Bits 7:6 Reserved, must be kept at reset value.
Bits 5:4 WRHIGHFREQ[1:0]: Flash signal delay
These bits are used to control the delay between non-volatile memory signals during programming operations. Application software has to program them to the correct value depending on the embedded flash memory interface frequency. Please refer to Table 20 for details.
Note: No check is performed to verify that the configuration is correct.
Two WRHIGHFREQ values can be selected for some frequencies.
Bits 3:0 LATENCY[3:0]: Read latency
These bits are used to control the number of wait states used during read operations on both non-volatile memory banks. The application software has to program them to the correct value depending on the embedded flash memory interface frequency and voltage conditions.
0000: zero wait state used to read a word from non-volatile memory
0001: one wait state used to read a word from non-volatile memory
0010: two wait states used to read a word from non-volatile memory
...
0111: seven wait states used to read a word from non-volatile memory
1111: 15 wait states used to read from non-volatile memory
Note: No check is performed by hardware to verify that the configuration is correct.
7.10.2 FLASH key register (FLASH_NSKEYR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
FLASH_NSKEYR is a write-only register. The following values must be programmed consecutively to unlock FLASH_NSCR register and allow programming/erasing it. A wrong sequence locks the FLASH_NSCR register until next system reset.
1st key = 0x4567 0123
2nd key = 0xCDEF 89AB
Address offset: 0x004
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| NSKEY[31:16] | |||||||||||||||
| w | w | w | w | w | w | w | w | w | w | w | w | w | w | w | w |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| NSKEY[15:0] | |||||||||||||||
| w | w | w | w | w | w | w | w | w | w | w | w | w | w | w | w |
Bits 31:0 NSKEY[31:0]: Non-volatile memory configuration access unlock key
7.10.3 FLASH option key register (FLASH_OPTKEYR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
FLASH_OPTKEYR is a write-only register. The following values must be programmed consecutively to unlock FLASH_OPTCR register. A wrong sequence locks FLASH_OPTCR register until next system reset.
1st key = 0x0819 2A3B
2nd key = 0x4C5D 6E7F
Address offset: 0x00C
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| OPTKEY[31:16] | |||||||||||||||
| w | w | w | w | w | w | w | w | w | w | w | w | w | w | w | w |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OPTKEY[15:0] | |||||||||||||||
| w | w | w | w | w | w | w | w | w | w | w | w | w | w | w | w |
Bits 31:0 OPTKEY[31:0]: FLASH option bytes control access unlock key
7.10.4 FLASH operation status register (FLASH_OPSR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x0018
Reset value: 0xXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CODE_OP[2:0] | Res. | Res. | Res. | Res. | OTP_OP | SYSF_OP | BK_OP | Res. | Res. | ADDR_OP[19:16] | |||||
| r | r | r | r | r | r | r | r | r | r | ||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ADDR_OP[15:0] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bits 31:29 CODE_OP[2:0]: Flash memory operation code
- 000: No Flash operation on going during previous reset
- 001: Single write operation interrupted
- 010: reserved
- 011: Sector erase operation interrupted
- 100: Bank erase operation interrupted
- 101: Mass erase operation interrupted
- 110: Option change operation interrupted
- 111: reserved
Bits 28:25 Reserved, must be kept at reset value.
Bit 24 OTP_OP: OTP operation interrupted
Indicates that reset interrupted an ongoing operation in OTP area.
Bit 23 SYSF_OP: Operation in system flash memory interrupted
Indicates that reset interrupted an ongoing operation in System Flash.
Bit 22 BK_OP: Interrupted operation bank
It indicates which bank was concerned by operation.
Bits 21:20 Reserved, must be kept at reset value.
Bits 19:0 ADDR_OP[19:0]: Interrupted operation address.
7.10.5 FLASH option control register (FLASH_OPTCR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Access: No wait state when no flash memory operation is ongoing. The FLASH_OPTCR register is not accessible in write mode when the BSY bit is set. Any attempt to write to it while the BSY bit set causes the AHB bus to stall until the BSY bit is cleared.
Address offset: 0x01C
Reset value: 0xX000 0001
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| SWAP_BANK | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| r | |||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OPTSTRT | OPTLOCK |
| rw | rs |
Bit 31 SWAP_BANK: Bank swapping option configuration bit
SWAP_BANK controls whether Bank1 and Bank2 are swapped or not. This bit is loaded with the SWAP_BANK bit of FLASH_OPTSR_CUR register only after reset or POR.
0: Bank1 and Bank2 not swapped
1: Bank1 and Bank2 swapped
Bits 30:2 Reserved, must be kept at reset value.
Bit 1 OPTSTRT: Option byte start change option configuration bit
OPTSTRT triggers an option byte change operation. The user can set OPTSTRT only when the OPTLOCK bit is cleared to 0. It's set only by Software and cleared when the option byte change is completed or an error occurs (PGSERR or OPTCHANGEERR). It's reseted at the same time as BSY bit.
The user application cannot modify any FLASH_XXX_PRG flash memory register until the option change operation has been completed.
Before setting this bit, the user has to write the required values in the FLASH_XXX_PRG registers. The FLASH_XXX_PRG registers are locked until the option byte change operation has been executed in non-volatile memory.
Bit 0 OPTLOCK: FLASH_OPTCR lock option configuration bit
The OPTLOCK bit locks the FLASH_OPTCR register as well as all _PRG registers. The correct write sequence to FLASH_OPTKEYR register unlocks this bit. If a wrong sequence is executed, or the unlock sequence to FLASH_OPTKEYR is performed twice, this bit remains locked until next system reset.
It is possible to set OPTLOCK by programming it to 1. When set to 1, a new unlock sequence is mandatory to unlock it. When OPTLOCK changes from 0 to 1, the others bits of FLASH_OPTCR register do not change.
0: FLASH_OPTCR register unlocked
1: FLASH_OPTCR register locked.
7.10.6 FLASH status register (FLASH_NSSR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x020
Reset value: 0x0000 000X
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OPTCH ANGEER RR | Res. | Res. | INCER R | STRBE RR | PGSER R | WRPE RR | EOP |
| r | r | r | r | r | r | ||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBNE | Res. | WBNE | BSY |
| r | r | r |
Bits 31:24 Reserved, must be kept at reset value.
Bit 23 OPTCHANGEERR: Option byte change error flag
OPTCHANGEERR flag indicates that an error occurred during an option byte change operation. When OPTCHANGEERR is set to 1, the option byte change operation did not successfully complete. An interrupt is generated when this flag is raised if the OPTCHANGEERRIE bit of FLASH_NSCR register is set to 1.
Writing 1 to CLR_OPTCHANGEERR of register FLASH_CCR clears OPTCHANGEERR.
0: no option byte change errors occurred
1: one or more errors occurred during an option byte change operation.
Note: The OPTSTRT bit in FLASH_OPTCR cannot be set while OPTCHANGEERR is set.
Bits 22:21 Reserved, must be kept at reset value.
Bit 20 INCERR: inconsistency error flag
INCERR flag is raised when a inconsistency error occurs. An interrupt is generated if INCERRIE is set to 1. Writing 1 to CLR_INCERR bit in the FLASH_NSCCR register clears INCERR.
0: no inconsistency error occurs
1: a inconsistency error occurs
Bit 19 STRBERR: strobe error flag
STRBERR flag is raised when a strobe error occurs (when the master attempts to write several times the same byte in the write buffer). An interrupt is generated if the STRBERRIE bit is set to 1. Writing 1 to CLR_STRBERR bit in FLASH_NSCCR register clears STRBERR.
0: no strobe error occurred
1: a strobe error occurred
Bit 18 PGSERR: programming sequence error flag
PGSERR flag is raised when a sequence error occurs. An interrupt is generated if the PGSERRIE bit is set to 1. Writing 1 to CLR_PGSERR bit in FLASH_NSCCR register clears PGSERR.
0: no sequence error occurred
1: a sequence error occurred
Bit 17 WRPERR: write protection error flag
WRPERR flag is raised when a protection error occurs during a program operation. An interrupt is also generated if the WRPERRIE is set to 1. Writing 1 to CLR_WRPERR bit in FLASH_NSCCR register clears WRPERR.
0: no write protection error occurred
1: a write protection error occurred
Bit 16 EOP: end of operation flag
EOP flag is set when a operation (program/erase) completes. An interrupt is generated if the EOPIE is set to 1. It is not necessary to reset EOP before starting a new operation. EOP bit is cleared by writing 1 to CLR_EOP bit in FLASH_NSCCR register.
0: no operation completed
1: a operation completed
Bits 15:4 Reserved, must be kept at reset value.
Bit 3 DBNE: data buffer not empty flag
DBNE flag is set when the flash memory interface is processing 6-bits ECC data in dedicated buffer. This bit cannot be set to 0 by software. The hardware resets it once the buffer is free.
0: data buffer not used
1: data buffer used, wait
Bit 2 Reserved, must be kept at reset value.
Bit 1 WBNE: write buffer not empty flag
WBNE flag is set when the embedded flash memory is waiting for new data to complete the write buffer. In this state, the write buffer is not empty. WBNE is reset by hardware each time the write buffer is complete or the write buffer is emptied following one of the event below:
- – the application software forces the write operation using FW bit in FLASH_NSCR
- – the embedded flash memory detects an error that involves data loss
This bit cannot be reset by software writing 0 directly. To reset it, clear the write buffer by performing any of the above listed actions, or send the missing data.
0: write buffer empty or full
1: write buffer waiting data to complete
Bit 0 BSY: busy flag
BSY flag indicates that a flash memory is busy by an operation (write, erase, option byte change). It is set at the beginning of a flash memory operation and cleared when the operation finishes or an error occurs.
0: no programming, erase or option byte change operation being executed
1: programming, erase or option byte change operation being executed
7.10.7 FLASH control register (FLASH_NSCR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register..
Access: No wait state when no flash memory operation is ongoing. The FLASH_NSCR register is not accessible in write mode when the BSY bit is set. Any attempt to write to it with the BSY bit set causes the AHB bus to stall until the BSY bit is cleared.
Address offset: 0x028
Reset value: 0x0000 0001
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BKSEL | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OPTCH ANGEER RRIE | Res. | Res. | INCER RIE | STRBE RRIE | PGSER RIE | WRPE RRIE | EOPIE |
| rw | rw | rw | rw | rw | rw | rw | |||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| MER | Res. | Res. | Res. | Res. | Res. | Res. | SNB[2:0] | STRT | FW | BER | SER | PG | LOCK | ||
| rw | rw | rw | rw | rs | rw | rw | rw | rw | rs | ||||||
Bit 31 BKSEL: Bank selector bit
BKSEL can only be programmed when LOCK is cleared to 0. The bit selects physical bank, SWAP_BANK setting is ignored.
0: Bank1 is selected for Bank erase / sector erase / interrupt enable
1: Bank2 is selected for BER / SER
Bits 30:24 Reserved, must be kept at reset value.
Bit 23 OPTCHANGEERRIE: Option byte change error interrupt enable bit
OPTCHANGEERRIE bit controls if an interrupt has to be generated when an error occurs during an option byte change. This bit can be programmed only when LOCK bit is cleared to 0.
0: no interrupt is generated when an error occurs during an option byte change
1: an interrupt is generated when and error occurs during an option byte change.
Bits 22:21 Reserved, must be kept at reset value.
Bit 20 INCERRIE: inconsistency error interrupt enable bit
When INCERRIE bit is set to 1, an interrupt is generated when an inconsistency error occurs during a write operation. INCERRIE can be programmed only when LOCK is cleared to 0.
0: no interrupt generated when a inconsistency error occurs
1: interrupt generated when a inconsistency error occurs.
Bit 19 STRBERRIE: strobe error interrupt enable bit
When STRBERRIE bit is set to 1, an interrupt is generated when a strobe error occurs (the master programs several times the same byte in the write buffer) during a write operation. STRBERRIE can be programmed only when LOCK is cleared to 0.
0: no interrupt generated when a strobe error occurs
1: interrupt generated when strobe error occurs.
Bit 18 PGSERRIE: programming sequence error interrupt enable bit
When PGSERRIE bit is set to 1, an interrupt is generated when a sequence error occurs during a program operation. PGSERRIE can be programmed only when LOCK is cleared to 0.
0: no interrupt generated when a sequence error occurs
1: interrupt generated when sequence error occurs
Bit 17 WRPERRIE: write protection error interrupt enable bit
When WRPERRIE bit is set to 1, an interrupt is generated when a protection error occurs during a program operation. WRPERRIE can be programmed only when LOCK is cleared to 0.
0: no interrupt generated when a protection error occurs
1: interrupt generated when a protection error occurs
Bit 16 EOPIE: end of operation interrupt control bit
Setting EOPIE bit to 1 enables the generation of an interrupt at the end of a program or erase operation. EOPIE can be programmed only when LOCK is cleared to 0.
- 0: no interrupt generated at the end of operation.
- 1: interrupt enabled when at the end of operation
Bit 15 MER: Mass erase request
Setting MER bit to 1 requests a mass erase operation (user flash memory only). MER can be programmed only when LOCK is cleared to 0.
If BER or SER are both set, a PGSERR is raised.
- 0: mass erase not requested
- 1: mass erase requested
Error is triggered when a mass erase is required and some sectors are protected.
Bits 14:9 Reserved, must be kept at reset value.
Bits 8:6 SNB[2:0]: sector erase selection number
These bits are used to select the target sector for an erase operation (they are unused otherwise). SNB can be programmed only when LOCK is cleared to 0.
- 0x00: Sector 0 selected
- 0x01: Sector 1 selected
- ...
- 0x07: Sector 7 selected
Bit 5 STRT: erase start control bit
STRT bit is used to start a sector erase or a bank erase operation. STRT can be programmed only when LOCK is cleared to 0.
STRT is reset at the end of the operation or when an error occurs. It cannot be reseted by software.
Bit 4 FW: write forcing control bit
FW forces a write operation even if the write buffer is not full. In this case all bits not written are set to 1 by hardware. FW can be programmed only when LOCK is cleared to 0.
The embedded flash memory resets FW when the corresponding operation has been acknowledged.
Note: Using a force-write operation prevents the application from updating later the missing bits with something else than 1, because it is likely that it leads to permanent ECC error.
Write forcing is effective only if the write buffer is not empty (in particular, FW does not start several write operations when the force-write operations are performed consecutively).
Since there is just one write buffer, FW can force a write in bank1 or bank2.
Bit 3 BER: erase request
Setting BER bit to 1 requests a bank erase operation (user flash memory only). BER can be programmed only when LOCK is cleared to 0.
If MER and SER are also set, a PGSERR is raised.
- 0: bank erase not requested
- 1: bank erase requested
Note: Write protection error is triggered when a bank erase is required and some sectors are protected.
Bit 2 SER: sector erase request
Setting SER bit to 1 requests a sector erase. SER can be programmed only when LOCK is cleared to 0.
If MER and SER are also set, a PGSERR is raised.
0: sector erase not requested
1: sector erase requested
Bit 1 PG: programming control bit
PG can be programmed only when LOCK is cleared to 0.
PG allows programming in Bank1 and Bank2.
0: programming disabled
1: programming enabled
Bit 0 LOCK: configuration lock bit
This bit locks the FLASH_NSCR register. The correct write sequence to FLASH_NSKEYR register unlocks this bit. If a wrong sequence is executed, or if the unlock sequence to FLASH_NSKEYR is performed twice, this bit remains locked until the next system reset.
LOCK can be set by programming it to 1. When set to 1, a new unlock sequence is mandatory to unlock it. When LOCK changes from 0 to 1, the other bits of FLASH_NSCR register do not change.
0: FLASH_NSCR register unlocked
1: FLASH_NSCR register locked
7.10.8 FLASH clear control register (FLASH_NSCCR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x030
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CLR_OPTCHANGEERR | Res. | Res. | CLR_INCERR | CLR_STRBERR | CLR_PGSERR | CLR_WRPERR | CLR_EOP |
| w | w | w | w | w | w | ||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
Bits 31:24 Reserved, must be kept at reset value.
Bit 23 CLR_OPTCHANGEERR: Clear the flag corresponding flag in FLASH_NSSR by writing this bit.
Bits 22:21 Reserved, must be kept at reset value.
Bit 20 CLR_INCERR: INCERR flag clear bit
Setting this bit to 1 resets to 0 INCERR flag in FLASH_NSSR register.
Bit 19 CLR_STRBERR: STRBERR flag clear bit
Setting this bit to 1 resets to 0 STRBERR flag in FLASH_NSSR register.
Bit 18 CLR_PGSERR: PGSERR flag clear bit
Setting this bit to 1 resets to 0 PGSERR flag in FLASH_NSSR register.
Bit 17 CLR_WRPERR: WRPERR flag clear bit
Setting this bit to 1 resets to 0 WRPERR flag in FLASH_NSSR register.
Bit 16 CLR_EOP: EOP flag clear bit
Setting this bit to 1 resets to 0 EOP flag in FLASH_NSSR register.
Bits 15:0 Reserved, must be kept at reset value.
7.10.9 FLASH privilege configuration register (FLASH_PRIVCFGR)
Address offset: 0x03C
Reset value: 0x0000 0000
This register can be read by both privileged and unprivileged access. It can only be written by privilege mode.
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | NSPRIV | Res. |
| rw |
Bits 31:2 Reserved, must be kept at reset value.
Bit 1 NSPRIV: privilege attribute
0: access to registers is always granted
1: access to registers is denied in case of non privileged access.
Bit 0 Reserved, must be kept at reset value.
7.10.10 FLASH HDP extension register (FLASH_HDPEXTR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
The register can only be modified in HDPL<=2.
The values in this register cannot be decremented. Attempt to write a lower value that current is ignored.
Address offset: 0x048
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_EXT[2:0] | ||
| rw | rw | rw | |||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_EXT[2:0] | ||
| rw | rw | rw | |||||||||||||
Bits 31:19 Reserved, must be kept at reset value.
Bits 18:16 HDP2_EXT[2:0]: HDP area extension in 8 Kbytes sectors in Bank2. Extension is added after the HDP2_END sector (included).
Bits 15:3 Reserved, must be kept at reset value.
Bits 2:0 HDP1_EXT[2:0]: HDP area extension in 8 Kbytes sectors in Bank1. Extension is added after the HDP1_END sector (included).
7.10.11 FLASH option status register (FLASH_OPTSR_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Default value: 0x0030 5CD8 (value in case of double ECC issue during OBL).
This read-only register reflects the current values of corresponding option bits.
Address offset: 0x050
Reset value: 0XXXXX XXXX
(Register bits 0 to 31 are loaded with values from the flash memory at OBL)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| SWAP_BANK | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | IWDG_STDBY | IWDG_STOP | Res. | Res. | IO_VDDIO2_HSLV | IO_VDDIO2_HSLV |
| r | r | r | r | r | |||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| PRODUCT_STATE[7:0] | NRST_STDBY | NRST_STOP | Res. | WWDG_SW | IWDG_SW | BORH_EN | BOR_LEV[1:0] | ||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | |
Bit 31 SWAP_BANK: Bank swapping option status bit
SWAP_BANK reflects whether Bank1 and Bank2 are swapped or not.
SWAP_BANK is loaded to SWAP_BANK of FLASH_OPTCR after a reset.
0: Bank1 and Bank2 not swapped
1: Bank1 and Bank2 swapped
Bits 30:22 Reserved, must be kept at reset value.
Bit 21 IWDG_STDBY: IWDG Standby mode freeze option status bit
When set to 0 the independent watchdog IWDG is frozen in system Standby mode.
0: Independent watchdog frozen in Standby mode
1: Independent watchdog keep running in Standby mode.
Bit 20 IWDG_STOP: IWDG Stop mode freeze option status bit
When set to 0 the independent watchdog IWDG is frozen in system Stop mode.
0: Independent watchdog frozen in system Stop mode
1: Independent watchdog keep running in system Stop mode.
Bits 19:18 Reserved, must be kept at reset value.
Bit 17 IO_VDDIO2_HSLV: High-speed IO at low VDDIO2 voltage status bit. This bit can be set only with VDDIO2 below 2.7 V.
0: High-speed IO at low VDDIO2 voltage feature disabled (VDDIO2 can exceed 2.7 V)
1: High-speed IO at low VDDIO2 voltage feature enabled (VDDIO2 remains below 2.7 V)
- Bit 16 IO_VDD_HSLV: High-speed IO at low VDD voltage status bit. This bit can be set only with VDD below 2.7 V.
0: High-speed IO at low VDD voltage feature disabled (VDD can exceed 2.7 V)
1: High-speed IO at low VDD voltage feature enabled (VDD remains below 2.7 V) - Bits 15:8 PRODUCT_STATE[7:0]: Life state code (based on Hamming 8,4). More information in Section 7.5.8: Product state transitions.
- Bit 7 NRST_STDBY: Core domain Standby entry reset option status bit
0: a reset is generated when entering Standby mode on core domain
1: no reset generated when entering Standby mode on core domain. - Bit 6 NRST_STOP: Core domain Stop entry reset option status bit
0: a reset is generated when entering Stop mode on core domain
1: no reset generated when entering Stop mode on core domain. - Bit 5 Reserved, must be kept at reset value.
- Bit 4 WWDG_SW: WWDG control mode option status bit
0: WWDG watchdog is controlled by hardware
1: WWDG watchdog is controlled by software - Bit 3 IWDG_SW: IWDG control mode option status bit
0: IWDG watchdog is controlled by hardware
1: IWDG watchdog is controlled by software - Bit 2 BORH_EN: Brownout high enable status bit
0: brownout reset (BOR) disabled
1: brownout reset (BOR) enabled - Bits 1:0 BOR_LEV[1:0]: Brownout level option status bit
These bits reflects the power level that generates a system reset.
00 or 11: BOR Level 1, the threshold level is low (VBOR1 around 2.1 V)
01: BOR Level 2, the threshold level is medium (VBOR2 around 2.4 V)
10: BOR Level 3, the threshold level is high (VBOR3 around 2.7 V)
7.10.12 FLASH option status register (FLASH_OPTSR_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is used to program values in corresponding option bits. Values after reset reflects the current values of the corresponding option bits.
Address offset: 0x054
Reset value: 0xXXXX XXXX
(Register bits 0 to 31 are loaded with values from the flash memory at OBL)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| SWAP_BANK | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | IWDG_STDBY | IWDG_STOP | Res. | Res. | IO_VDDIO2_HSLV | IO_VDD_HSLV |
| rw | rw | rw | rw | rw | |||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| PRODUCT_STATE[7:0] | NRST_STDBY | NRST_STOP | Res. | WWDG_SW | IWDG_SW | BORH_EN | BOR_LEV[1:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |
Bit 31 SWAP_BANK: Bank swapping option configuration bit
SWAP_BANK option bit is used to configure whether the Bank1 and Bank2 are swapped or not. This bit is loaded with the SWAP_BANK bit of FLASH_OPTSR_CUR register after a reset.
0: Bank1 and Bank2 not swapped
1: Bank1 and Bank2 swapped
Bits 30:22 Reserved, must be kept at reset value.
Bit 21 IWDG_STDBY: IWDG Standby mode freeze option configuration bit
When set the independent watchdog IWDG is frozen in system Standby mode.
0: Independent watchdog frozen in Standby mode
1: Independent watchdog keep running in Standby mode.
Bit 20 IWDG_STOP: IWDG Stop mode freeze option configuration bit
When set the independent watchdog IWDG is in system Stop mode.
0: Independent watchdog frozen in system Stop mode
1: Independent watchdog keep running in system Stop mode.
Bits 19:18 Reserved, must be kept at reset value.
Bit 17 IO_VDDIO2_HSLV: High-speed IO at low VDDIO2 voltage configuration bit. This bit can be set only with VDDIO2 below 2.7 V.
0: High-speed IO at low VDDIO2 voltage feature disabled (VDDIO2 can exceed 2.7 V)
1: High-speed IO at low VDDIO2 voltage feature enabled (VDDIO2 remains below 2.7 V)
Bit 16 IO_VDD_HSLV: High-speed IO at low VDD voltage configuration bit. This bit can be set only with VDD below 2.7 V.
0: High-speed IO at low VDD voltage feature disabled (VDD can exceed 2.7 V)
1: High-speed IO at low VDD voltage feature enabled (VDD remains below 2.7 V)
Bits 15:8 PRODUCT_STATE[7:0]: Life state code (based on Hamming 8,4). More information in Section 7.5.8: Product state transitions.
- Bit 7 NRST_STDBY: Core domain Standby entry reset option configuration bit
- 0: a reset is generated when entering Standby mode on core domain
- 1: no reset generated when entering Standby mode on core domain.
- Bit 6 NRST_STOP: Core domain Stop entry reset option configuration bit
- 0: a reset is generated when entering Stop mode on core domain
- 1: no reset generated when entering Stop mode on core domain.
- Bit 5 Reserved, must be kept at reset value.
- Bit 4 WWDG_SW: WWDG control mode option configuration bit
- 0: WWDG watchdog is controlled by hardware
- 1: WWDG watchdog is controlled by software
- Bit 3 IWDG_SW: IWDG control mode option configuration bit
- 0: IWDG watchdog is controlled by hardware
- 1: IWDG watchdog is controlled by software
- Bit 2 BORH_EN: Brownout high enable configuration bit
- 0: brownout reset (BOR) disabled
- 1: brownout reset (BOR) enabled
- Bits 1:0 BOR_LEV[1:0]: Brownout level option configuration bit
- These bits reflects the power level that generates a system reset.
- 00 or 11: BOR Level 1, the threshold level is low (VBOR1 around 2.1 V)
- 01: BOR Level 2, the threshold level is medium (VBOR2 around 2.4 V)
- 10: BOR Level 3, the threshold level is high (VBOR3 around 2.7 V)
7.10.13 FLASH option status register 2 (FLASH_OPTSR2_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Default value: 0xC300 0658
This read-only register reflects the current values of corresponding option bits.
Address offset: 0x070
Reset value: 0XXXXX XXXX
(Register bits 0 to 31 are loaded with values from the flash memory at OBL)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | SRAM1_ECC | SRAM1_RST | Res. | Res. | SRAM2_ECC | Res. | BKPRA M_ECC | SRAM2_RST | Res. | Res. | Res. |
| r | r | r | r | r |
Bits 31:11 Reserved, must be kept at reset value.
Bit 10 SRAM1_ECC: SRAM1 ECC detection and correction disable
- 0: SRAM1 ECC check enabled
- 1: SRAM1 ECC check disabled
Bit 9 SRAM1_RST: SRAM1 erase upon system reset
- 0: SRAM1 erased when a system reset occurs
- 1: SRAM1 not erased when a system reset occurs
Bits 8:7 Reserved, must be kept at reset value.
Bit 6 SRAM2_ECC: SRAM2 ECC detection and correction disable
- 0: SRAM2 ECC check enabled
- 1: SRAM2 ECC check disabled
Bit 5 Reserved, must be kept at reset value.
Bit 4 BKPRAM_ECC: Backup RAM ECC detection and correction disable
- 0: BKPRAM ECC check enabled
- 1: BKPRAM ECC check disabled
Bit 3 SRAM2_RST: SRAM2 erase when system reset
- 0: SRAM2 erased when a system reset occurs
- 1: SRAM2 not erased when a system reset occurs.
Bits 2:0 Reserved, must be kept at reset value.
7.10.14 FLASH option status register 2 (FLASH_OPTSR2_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is used to program values in corresponding option bits. Values after reset reflects the current values of the corresponding option bits.
Address offset: 0x074
Reset value: 0xXXXX XXXX
(Register bits 0 to 31 are loaded with values from the flash memory at OBL)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | SRAM1_ECC | SRAM1_RST | Res. | Res. | SRAM2_ECC | Res. | BKPRAM_ECC | SRAM2_RST | Res. | Res. | Res. |
| rw | rw | rw | rw | rw |
Bits 31:11 Reserved, must be kept at reset value.
Bit 10 SRAM1_ECC: SRAM1 ECC detection and correction disable
0: SRAM1 ECC check enabled
1: SRAM1 ECC check disabled
Bit 9 SRAM1_RST: SRAM1 erase upon system reset
0: SRAM1 erased when a system reset occurs
1: SRAM1 not erased when a system reset occurs
Bits 8:7 Reserved, must be kept at reset value.
Bit 6 SRAM2_ECC: SRAM2 ECC detection and correction disable
0: SRAM2 ECC check enabled
1: SRAM2 ECC check disabled
Bit 5 Reserved, must be kept at reset value.
Bit 4 BKPRAM_ECC: Backup RAM ECC detection and correction disable
0: BKPRAM ECC check enabled
1: BKPRAM ECC check disabled
Bit 3 SRAM2_RST: SRAM2 erase when system reset
0: SRAM2 erased when a system reset occurs
1: SRAM2 not erased when a system reset occurs.
Bits 2:0 Reserved, must be kept at reset value.
7.10.15 FLASH unique boot entry register (FLASH_NSBOOTR_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register reflects the current values of corresponding option bits.
Address offset: 0x080
Reset value: 0xXXXX XXXX
(Register bits 0 to 31 are loaded with values from the flash memory at OBL)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| NSBOOTADD[23:8] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| NSBOOTADD[7:0] | NSBOOT_LOCK[7:0] | ||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bits 31:8 NSBOOTADD[23:0]: unique boot entry address
These bits reflect the UBE address
Bits 7:0 NSBOOT_LOCK[7:0]: A field locking the values of SWAP_BANK, and NSBOOTADD settings.
0xC3: The SWAP_BANK and NSBOOTADD can still be modified following their individual rules.
0xB4: The NSBOOTADD and SWAP_BANK are frozen.

7.10.16 FLASH unique boot entry address (FLASH_NSBOOTR_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is used to program values in corresponding option bits.
Address offset: 0x084
Reset value: 0xXXXX XXXX
(Register bits 0 to 31 are loaded with values from the flash memory at OBL)
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| NSBOOTADD[23:8] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| NSBOOTADD[7:0] | NSBOOT_LOCK[7:0] | ||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:8 NSBOOTADD[23:0]: Unique boot entry address
These bits allow configuring the BOOT address
Bits 7:0 NSBOOT_LOCK[7:0]: A field locking the values of SWAP_BANK, and NSBOOTADD settings.
0xC3: The SWAP_BANK and NSBOOTADD can still be modified following their individual rules.
0xB4: The NSBOOTADD and SWAP_BANK are frozen.
7.10.17 FLASH OTP block lock (FLASH_OTPBLR_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register reflects the current values of corresponding option bits.
Address offset: 0x090
Reset value: 0xXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| LOCKBL[31:16] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| LOCKBL[15:0] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bits 31:0 LOCKBL[31:0]: OTP block lock
Block n corresponds to OTP 16-bit word 32 × n to 32 × n+31.
LOCKBL[n] = 1 indicates that all OTP 16-bit words in OTP Block n are locked and attempt to program them results in WRPERR.
LOCKBL[n] = 0 indicates that all OTP 16-bit words in OTP Block n are not locked.
When one block is locked, it's not possible to remove the write protection.
Also if not locked, it is not possible to erase OTP words.
7.10.18 FLASH OTP block lock (FLASH_OTPBLR_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is used to program values in corresponding option bits.
Address offset: 0x094
Reset value: 0XXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| LOCKBL[31:16] | |||||||||||||||
| rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| LOCKBL[15:0] | |||||||||||||||
| rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs | rs |
Bits 31:0 LOCKBL[31:0]: OTP block lock
Block n corresponds to OTP 16-bit word 32 × n to 32 × n+31.
LOCKBL[n] = 1 indicates that all OTP 16-bit words in OTP Block n are locked and attempt to program them results in WRPERR.
LOCKBL[n] = 0 indicates that all OTP 16-bit words in OTP Block n are not locked.
When one block is locked, it is not possible to remove the write protection.
LOCKBL bits can be set if the corresponding bit in FLASH_OTPBLR_CUR is cleared.
7.10.19 FLASH privilege register for bank 1 (FLASH_PRIVBB1R1)
This register is privileged. It can be read written only by a privileged access.
Address offset: 0x0C0
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | PRIVBB1[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bits 7:0 PRIVBB1[7:0]: Privileged / unprivileged 8 Kbytes Flash Bank1 sector attribute (y = 0 to 7)
0: sectors y in bank 1 is non privileged
1: sector y in bank 1 is privileged
7.10.20 FLASH write sector protection for Bank1 (FLASH_WRP1R_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This read-only register reflects the current values of corresponding option bits.
Address offset: 0x0E8
Reset value: 0xXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRPSG1[7:0] | |||||||
| r | r | r | r | r | r | r | r | ||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bits 7:0 WRPSG1[7:0]: Bank1 sector protection option status byte
Setting WRPSG1 bits to 0 write protects the corresponding sectors in bank 1 (0: write protected; 1: not write protected)
7.10.21 FLASH write sector protection for Bank1 (FLASH_WRP1R_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is used to program values in corresponding option bits.
Address offset: 0x0EC
Reset value: 0xXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRPSG1[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bits 7:0 WRPSG1[7:0]: Bank1 sector protection option status byte
Setting WRPSG1 bits to 0 write protects the corresponding sectors in bank 1 (0: write protected; 1: not write protected)
7.10.22 FLASH HDP Bank1 register (FLASH_HDP1R_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is initially loaded with the values of corresponding option bits.
Address offset: 0x0F8
Reset value: 0XXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_END[2:0] | ||
| w | w | w | |||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_STRT[2:0] | ||
| w | w | w | |||||||||||||
Bits 31:19 Reserved, must be kept at reset value.
Bits 18:16 HDP1_END[2:0]: HDPL barrier end set in number of 8 Kbytes sectors
Bits 15:3 Reserved, must be kept at reset value.
Bits 2:0 HDP1_STRT[2:0]: HDPL barrier start set in number of 8 Kbytes sectors
7.10.23 FLASH HDP Bank1 register (FLASH_HDP1R_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Register is accessible only in HDPL0 and HDPL1. In HDPL=2 or 3 it is WI, RAZ.
This register is used to program values in corresponding option bits.
Address offset: 0x0FC
Reset value: 0XXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_END[2:0] | ||
| r | r | r | |||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_STRT[2:0] | ||
| r | r | r | |||||||||||||
Bits 31:19 Reserved, must be kept at reset value.
Bits 18:16 HDP1_END[2:0]: Bank 1 HDPL barrier end set in number of 8 Kbytes sectors
Bits 15:3 Reserved, must be kept at reset value.
Bits 2:0 HDP1_STRT[2:0]: Bank 1 HDPL barrier start set in number of 8 Kbytes sectors
7.10.24 FLASH ECC correction register (FLASH_ECCCORR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x100
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | ECCC | Res. | Res. | Res. | Res. | ECCCI E | OTP_E CC | SYSF_ ECC | BK_EC C | Res. | Res. | Res. | Res. | Res. | Res. |
| rw | rw | r | r | r | |||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ADDR_ECC[15:0] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bit 31 Reserved, must be kept at reset value.
Bit 30 ECCC: ECC correction set by hardware when single ECC error has been detected and corrected.
Cleared by writing 1.
Bits 29:26 Reserved, must be kept at reset value.
Bit 25 ECCIE: ECC single correction error interrupt enable bit When ECCIE bit is set to 1, an interrupt is generated when an ECC single correction error occurs during a read operation.
0: no interrupt generated when an ECC single correction error occurs
1: interrupt generated when an ECC single correction error occurs
Bit 24 OTP_ECC: OTP ECC error bit
This bit is set to 1 when one single ECC correction occurred during the last successful read operation from the read-only/ OTP area. The address of the ECC error is available in ADDR_ECC bitfield.
Bit 23 SYSF_ECC: ECC flag for corrected ECC error in system FLASH
It indicates if system flash memory is concerned by ECC error.
Bit 22 BK_ECC: ECC bank flag for corrected ECC error
It indicates which bank is concerned by ECC error
Bits 21:16 Reserved, must be kept at reset value.
Bits 15:0 ADDR_ECC[15:0]: ECC error address
When an ECC error occurs (for single correction) during a read operation, the ADDR_ECC contains the address that generated the error.
ADDR_ECC is reset when the flag error is reset.
The embedded flash memory programs the address in this register only when no ECC error flags are set. This means that only the first address that generated an ECC error is saved.
The address in ADDR_ECC is relative to the flash memory area where the error occurred (user flash memory, system flash memory, data area, read-only/OTP area).
7.10.25 FLASH ECC detection register (FLASH_ECCDETR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x104
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| ECCD | Res. | Res. | Res. | Res. | Res. | Res. | OTP_ECC | SYSF_ECC | BK_ECC | Res. | Res. | Res. | Res. | Res. | Res. |
| rw | r | r | r | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ADDR_ECC[15:0] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bit 31 ECCD: ECC detection set by hardware when two ECC error has been detected.
When this bit is set, a NMI is generated.
Cleared by writing 1. Needs to be cleared in order to detect subsequent double ECC errors.
Bits 30:25 Reserved, must be kept at reset value.
Bit 24 OTP_ECC: OTP ECC error bit
This bit is set to 1 when double ECC detection occurred during the last read operation from the read-only/ OTP area. The address of the ECC error is available in ADDR_ECC bit field.
Bit 23 SYSF_ECC: ECC fail for double ECC error in system flash memory
It indicates if system flash memory is concerned by ECC error.
Bit 22 BK_ECC: ECC fail bank for double ECC Error
It indicates which bank is concerned by ECC error
Bits 21:16 Reserved, must be kept at reset value.
Bits 15:0 ADDR_ECC[15:0]: ECC error address
When an ECC error occurs (double detection) during a read operation, the ADDR_ECC contains the address that generated the error.
ADDR_ECC is reset when the flag error is reset.
The embedded flash memory programs the address in this register only when no ECC error flags are set. This means that only the first address that generated an double ECC error is saved.
The address in ADDR_ECC is relative to the flash memory area where the error occurred (user flash memory, system flash memory, data area, read-only/OTP area).
7.10.26 FLASH ECC data (FLASH_ECCDR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x108
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| DATA_ECC[15:0] | |||||||||||||||
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:0 DATA_ECC[15:0]: ECC error data
When an double detection ECC error occurs on special areas with 6-bit ECC on 16-bit of data (data area, read-only/OTP area), the failing data is read to this register.
By checking if it is possible to determine whether the failure was on a real data, or due to access to uninitialized memory.
7.10.27 FLASH privilege register for Bank2 (FLASH_PRIVBB2R1)
This register is privileged. It can be read written only by a privileged access.
Address offset: 0x1C0
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | PRIVBB2[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bits 7:0 PRIVBB2[7:0]: Privileged / unprivileged 8 Kbytes Flash Bank2 sector attribute (y = 0 to 7)
0: sectors y in bank 2 is non privileged
1: sector y in bank 2 is privileged
7.10.28 FLASH write sector protection for Bank2 (FLASH_WRP2R_CUR)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This read-only register reflects the current values of corresponding option bits.
Address offset: 0x1E8
Reset value: 0xXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRPSG2[7:0] | |||||||
| r | r | r | r | r | r | r | r | ||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bits 7:0 WRPSG2[7:0]: Bank2 sector protection option status byte
Setting WRPSG2 bits to 0 write protects the corresponding sectors in bank 2 (0: write protected; 1: not write protected)
7.10.29 FLASH write sector protection for Bank2 (FLASH_WRP2R_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
This register is used to program values in corresponding option bits.
Address offset: 0x1EC
Reset value: 0xXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRPSG2[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bits 7:0 WRPSG2[7:0]: Bank2 sector protection option status byte
Setting WRPSG2 bits to 0 write protects the corresponding sectors in bank 2 (0: write protected; 1: not write protected)
7.10.30 FLASH HDP Bank2 register (FLASH_HDP2R_CUR)
This register is initially loaded with the values of corresponding option bits.
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Address offset: 0x1F8
Reset value: 0XXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_END[2:0] | ||
| r | r | r | |||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_STRT[2:0] | ||
| r | r | r | |||||||||||||
Bits 31:19 Reserved, must be kept at reset value.
Bits 18:16 HDP2_END[2:0]: Bank 2 HDPL barrier end set in number of 8 Kbytes sectors
Bits 15:3 Reserved, must be kept at reset value.
Bits 2:0 HDP2_STRT[2:0]: Bank 2 HDPL barrier start set in number of 8 Kbytes sectors
7.10.31 FLASH HDP Bank2 register (FLASH_HDP2R_PRG)
This register can be protected against unprivileged access when NSPRIV = 1 in the FLASH_PRIVCFGR register.
Register is accessible only in HDPL0 and HDPL1. In HDPL=2 or 3 it is WI, RAZ.
This register is used to program values in corresponding option bits.
Address offset: 0x1FC
Reset value: 0XXXXX XXXX
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_END[2:0] | ||
| rw | rw | rw | |||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_STRT[2:0] | ||
| rw | rw | rw | |||||||||||||
Bits 31:19 Reserved, must be kept at reset value.
Bits 18:16 HDP2_END[2:0]: Bank 2 HDPL barrier end set in number of 8 Kbytes sectors
Bits 15:3 Reserved, must be kept at reset value.
Bits 2:0 HDP2_STRT[2:0]: Bank 2 HDPL barrier start set in number of 8 Kbytes sectors
7.10.32 FLASH register map
Table 44. Register map and reset value table
| Offset | Register name reset value | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x000 | FLASH_ACR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | PRFTEN | Res. | Res. | WRHIGHFREQ[1:0] | LATENCY[3:0] | |||||
| 0x0000 0013 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | |||||||||||||||||||||||||||
| 0x004 | FLASH_NSKEYR | NSKEY[31:0] | ||||||||||||||||||||||||||||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||
| 0x00C | FLASH_OPTKEYR | OPTKEY | ||||||||||||||||||||||||||||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||
| 0x018 | FLASH_OPSR | CODE_OP[2:0] | Res. | Res. | Res. | Res. | OTP_OP | SYSF_OP | BK_OP | Res. | Res. | ADDR_OP[19:0] | ||||||||||||||||||||||
| 0xXXXX XXXX | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | ||||||||
| 0x01C | FLASH_OPTCR | SWAP_BANK | 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. | Res. | Res. | Res. | OPTSTRT | OPTLOCK | |
| 0xX000 0001 | 0 | 0 | 1 | |||||||||||||||||||||||||||||||
| 0x020 | FLASH_NSSR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OPTCHANGERR | Res. | Res. | INCERR | STRBERR | PGSERR | WRPERR | EOP | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBNE | Res. | WBNE | BSY | |
| 0x0000 000X | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||||||||
| 0x028 | FLASH_NSCR | BKSEL. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OPTCHANGEERRIE | Res. | Res. | INCERRIE. | STRBERRIE | PGSERRIE | WRPERRIE | EOPIE | MER | Res. | Res. | Res. | Res. | Res. | Res. | Res. | SNB[2:0] | STRT | FW | BER | SER | PG | LOCK | ||
| 0x0000 0001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |||||||||||||||||
| 0x030 | FLASH_NSCCR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CLR_OPTCHANGEERR. | Res. | Res. | CLR_INCERR | CLR_STRBERR | CLR_PGSERR | CLR_WRPERR | CLR_EOP | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | |
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||

Table 44. Register map and reset value table (continued)
| Offset | Register name reset value | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x03C | FLASH_PRIVCFGR | 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 | Res | Res | Res | Res | NSPRIV | Res | |
| 0x0000 0000 | 0 | |||||||||||||||||||||||||||||||||
| 0x048 | FLASH_HDPEXTR | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | HDP2_EXT[2:0] | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | HDP1_EXTT[2:0] | ||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||
| 0x050 | FLASH_OPTSR_CUR | SWAP_BANK | Res | Res | Res | Res | Res | Res | Res | Res | Res | IWDG_STDBY | IWDG_STOP | Res | Res | IO_VDDIO2_HSLV | IO_VDD_HSLV | PRODUCT_STATE[7:0] | NRST_STDBY | NRST_STOP | Res | Res | Res | Res | Res | BORH_EN | BOR_LEV[1:0] | |||||||
| 0XXXXX XXXX | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | |||||||||||||||||
| 0x054 | FLASH_OPTSR_PRG | SWAP_BANK | Res | Res | Res | Res | Res | Res | Res | Res | Res | IWDG_STDBY | IWDG_STOP | Res | Res | IO_VDDIO2_HSLV | IO_VDD_HSLV | PRODUCT_STATE[7:0] | NRST_STDBY | NRST_STOP | Res | Res | Res | Res | Res | BORH_EN | BOR_LEV[1:0] | |||||||
| 0XXXXX XXXX | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | |||||||||||||||||||
| 0x070 | FLASH_OPTSR2_CUR | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | SRAM1_ECC | SRAM1_RST | Res | Res | Res | Res | Res | Res | Res | Res | |
| 0XXXXX XXXX | X | X | ||||||||||||||||||||||||||||||||
| 0x074 | FLASH_OPTSR2_PRG | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | SRAM1_ECC | SRAM1_RST | Res | Res | Res | Res | Res | Res | Res | Res | |
| 0XXXXX XXXX | X | X | ||||||||||||||||||||||||||||||||
| 0x080 | FLASH_NSBOOTR_CUR | NSBOOTADD[23:0] | NSBOOT_LOCK[7:0] | |||||||||||||||||||||||||||||||
| 0XXXXX XXXX | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | ||
| 0x084 | FLASH_NSBOOTR_PRG | NSBOOTADD[23:0] | NSBOOT_LOCK[7:0] | |||||||||||||||||||||||||||||||
| 0XXXXX XXXX | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | ||
| 0x090 | FLASH_OTPBLR_CUR | LOCKBL[31:0] | ||||||||||||||||||||||||||||||||
| 0XXXXX XXXX | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | ||
| 0x094 | FLASH_OTPBLR_PRG | LOCKBL[31:0] | ||||||||||||||||||||||||||||||||
| 0XXXXX XXXX | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | ||
Table 44. Register map and reset value table (continued)
| Offset | Register name reset value | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x0C0 | FLASH_PRIVBB1R1 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | PRIVBB1[7:0] | |||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||||||||
| 0x0E8 | FLASH_WRP1RCUR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRP1[7:0] | |||||||
| 0xXXXX XXXX | X | X | X | X | X | X | X | X | |||||||||||||||||||||||||
| 0x0EC | FLASH_WRP1R_PRG | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRP1[7:0] | |||||||
| 0xXXXX XXXX | X | X | X | X | X | X | X | X | |||||||||||||||||||||||||
| 0x0F8 | FLASH_HDP1R_CUR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_END[2:0] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_STRT[2:0] | ||||
| 0xXXXX XXXX | X | X | X | X | X | X | |||||||||||||||||||||||||||
| 0x0FC | FLASH_HDP1R_PRG | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_END[2:0] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP1_STRT[2:0] | ||||
| 0xXXXX XXXX | X | X | X | X | X | X | |||||||||||||||||||||||||||
| 0x100 | FLASH_ECCCORR | Res. | ECCR | Res. | Res. | Res. | Res. | ECCCIE | OTP_ECC | SYSF_ECC | BK_ECC | Res. | Res. | Res. | Res. | Res. | Res. | ADDR_ECC[15:0] | |||||||||||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||
| 0x104 | FLASH_ECCDETR | ECCR | Res. | Res. | Res. | Res. | Res. | Res. | OTP_ECC | SYSF_ECC | BK_ECC | Res. | Res. | Res. | Res. | Res. | Res. | ADDR_ECC[15:0] | |||||||||||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | |||||||||||||||||||||||||||||
| 0x108 | FLASH_ECCDR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DATA_ECC[15:0] | |||||||||||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||
| 0x1C0 | FLASH_PRIVBB2R1 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | PRIVBB2[7:0] | |||||||
| 0x0000 0000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||||||||
| 0x1E8 | FLASH_WRP2R_CUR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRPSG2[7:0] | |||||||
| 0xXXXX XXXX | X | X | X | X | X | X | X | X | |||||||||||||||||||||||||
| 0x1EC | FLASH_WRP2R_PRG | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WRPSG2[7:0] | |||||||
| 0xXXXX XXXX | X | X | X | X | X | X | X | X | |||||||||||||||||||||||||
Table 44. Register map and reset value table (continued)
| Offset | Register name reset value | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x1F8 | FLASH_HDP2R_CUR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_END[2:0] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_STRT[2:0] | ||||
| 0XXXXX XXXX | X | X | X | X | X | X | |||||||||||||||||||||||||||
| 0x1FC | FLASH_HDP2R_PRG | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_END[2:0] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | HDP2_STRT[2:0] | ||||
| 0XXXXX XXXX | X | X | X | X | X | X | |||||||||||||||||||||||||||
Refer to Section 2.2 for the register boundary addresses.