6. Embedded flash memory (FLASH)

6.1 FLASH introduction

The embedded flash memory (FLASH) manages the accesses of any master to the up to 1 Mbyte of embedded nonvolatile memory. It implements the read, program and erase operations, error corrections, as well as various integrity and confidentiality protection mechanisms.

The FLASH manages the automatic loading of nonvolatile user option bytes at power-on reset, and implements the dynamic update of these options.

The FLASH also features a one-time-programmable (OTP) area and a read-only area provisioned by STMicroelectronics during the product manufacturing.

6.2 FLASH main features

6.3 FLASH functional description

6.3.1 FLASH block diagram

The following figure shows the simplified FLASH block diagram.

Figure 9. FLASH block diagram (simplified)

Simplified FLASH block diagram showing internal components and external interfaces.

The diagram illustrates the internal architecture of the FLASH memory. It is divided into several functional blocks:

MSv76083V1

Simplified FLASH block diagram showing internal components and external interfaces.

6.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

Main AHB interface

The AHB data bus size is 128 bits. This interface is used to handle two different targets:

The main AHB interface is implemented as follows:

Caution: By default, all the AHB memory range is cacheable. For regions where caching is not permitted (OTP, RO, data area), MPU has to be used to disable local cacheability. An attempt to cache these regions will generate a Hard Fault.

6.3.3 Flash memory architecture and usage

Flash memory architecture

Figure 10 shows the nonvolatile memory organization supported by the FLASH.

Figure 10. Embedded flash memory organization

Figure 10: Embedded flash memory organization diagram. The diagram illustrates Flash interface logic connected to the Main AHB system bus and AHB config port. It shows Bank1 and Bank2 organization with User main memory (Page 0 to Page 63), System memory (Sys page 0 to Sys page 2), EDATA flash data area (EDATA page 0 to EDATA page 15), Write-protected areas, Write locked areas, Read-only region, OTP, and Option bytes, with details on ECC per bit/word configuration.
Figure 10: Embedded flash memory organization diagram. The diagram illustrates Flash interface logic connected to the Main AHB system bus and AHB config port. It shows Bank1 and Bank2 organization with User main memory (Page 0 to Page 63), System memory (Sys page 0 to Sys page 2), EDATA flash data area (EDATA page 0 to EDATA page 15), Write-protected areas, Write locked areas, Read-only region, OTP, and Option bytes, with details on ECC per bit/word configuration.

The embedded flash nonvolatile memory is composed of:

The overall flash memory architecture and its corresponding access interface is summarized in Table 24.

Partition usage

The figure below shows how the FLASH is used by both STMicroelectronics and the application software.

Figure 11. FLASH use

Diagram of STM32C5 nonvolatile memory partitioning. It shows three main sections: User memory, Flash data area, and System memory. User memory contains Application software. Flash data area contains Application data. System memory contains Bootloader, Reserved, Read-only and OTP area, User option bytes, and Reserved. The diagram also shows the mapping of these sections to SWAP_BANK 0 and SWAP_BANK 1. A yellow box indicates 'Mapped on AHB config port' for the Read-only and OTP area. Another yellow box indicates 'Managed through registers only' for the User option bytes. The diagram is labeled MSv76011V2.

The diagram illustrates the partitioning of STM32C5 nonvolatile memory. It is divided into three main sections: User memory, Flash data area, and System memory. User memory contains Application software. Flash data area contains Application data. System memory contains Bootloader, Reserved, Read-only and OTP area, User option bytes, and Reserved. The diagram also shows the mapping of these sections to SWAP_BANK 0 and SWAP_BANK 1. A yellow box indicates 'Mapped on AHB config port' for the Read-only and OTP area. Another yellow box indicates 'Managed through registers only' for the User option bytes. The diagram is labeled MSv76011V2.

Diagram of STM32C5 nonvolatile memory partitioning. It shows three main sections: User memory, Flash data area, and System memory. User memory contains Application software. Flash data area contains Application data. System memory contains Bootloader, Reserved, Read-only and OTP area, User option bytes, and Reserved. The diagram also shows the mapping of these sections to SWAP_BANK 0 and SWAP_BANK 1. A yellow box indicates 'Mapped on AHB config port' for the Read-only and OTP area. Another yellow box indicates 'Managed through registers only' for the User option bytes. The diagram is labeled MSv76011V2.

User and system memories are used differently according to RDP level and other option-byte settings.

The user memory contains the application code and associated constant data. The flash data area contains application nonvolatile data. The system memory contains the STM32 bootloader. When a reset occurs, the core jumps to the boot address configured through the BOOT pin (or BOOT option bit), the BOOTADD option bytes, and the RDP level.

Note: For more information on option-byte setup for boot, refer to Section 6.4.8.

6.3.4 FLASH read operations

Read operation overview

Read access to main flash memory and system flash memory operates as follows:

Read access to OTP, RO, and user data flash area operates as follows:

  1. 1. A FLASH data word of 137 bits is read and stored in a temporary buffer.
  2. 2. The interface parses the 137-bit data word, and selects the 16- or 32-bit data requested.
  3. 3. While parsing the 137-bit data word, two wait states are added and the AHB bus is stalled.
  4. 4. If the application reads an OTP data or user data FLASH not previously written, a double ECC error is reported, and only word full of set bits is returned (see Section 6.3.9 for details). The read data (in 16 bits) is stored in FLASH_ECCDR, so that the user can identify if the double ECC error is due to a virgin data or a real ECC error.
  5. 5. Reading two times the same address triggers two reads in the flash memory.
  6. 6. For 8-bit accesses, an AHB bus error is generated.

Note: The FLASH can perform single-error correction and double-error detection while read operations are being executed (see Section 6.3.8).

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 ICACHE 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 the ICACHE and executed by the CPU.

Prefetch is enabled by setting the PRFTEN bit in 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 FLASH clock must be enabled and running before reading data from a nonvolatile memory.

To correctly read data from the flash memory, the number of wait states (LATENCY) must be correctly programmed in FLASH_ACR, according to the FLASH main AHB interface clock frequency.

The table below shows the correspondence between the number of wait states (LATENCY), the programming delay parameter (WRHIGHFREQ) and the FLASH clock frequency.

Table 20. FLASH recommended number of wait states and programming delay

Number of wait states (LATENCY)Programming delay (WRHIGHFREQ)Interface clock frequency
0 WS (1 FLASH clock cycle)00[0 MHz; 34 MHz]
1 WS (2 FLASH clock cycles)[34 MHz; 68 MHz]
2 WS (3 FLASH clock cycles)01[68 MHz; 102 MHz]
3 WS (4 FLASH clock cycles)[102 MHz; 136 MHz]
4 WS (5 FLASH clock cycles)10[136 MHz; 144 MHz]

Adjusting system frequency

After power-on, the FLASH is clocked by the divided by 3 high speed internal oscillator HSIDIV3 at 48 MHz. As a result, a conservative 7 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 nonvolatile memory.

To increase the CPU frequency:

  1. 1. If necessary, program LATENCY and WRHIGHFREQ bits to the right value in the FLASH_ACR register, as described in Table 20.
  2. 2. Check that the new number of wait states is taken into account by reading back the FLASH_ACR register.
  3. 3. Modify the FLASH clock source and/or the clock prescaler in the RCC_CFGR register of the reset and clock controller (RCC).
  4. 4. Check that the new FLASH clock source and/or the new AHB clock prescaler value are taken in account by reading back the FLASH 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. 1. Modify the FLASH clock source and/or the clock prescaler in the RCC_CFGR register of reset and clock controller (RCC).
  2. 2. Check that the FLASH new clock source and/or the new clock prescaler value are taken in account by reading back the FLASH clock source status and/or the AHB interface prescaler value in the RCC_CFGR register of reset and clock controller (RCC).
  3. 3. If necessary, program the LATENCY and WRHIGHFREQ bits to the right value in FLASH_ACR register, as described in Table 20.
  4. 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 6.3.8.

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 6.8.5

Read interrupts

See Section 6.9 for details.

6.3.5 FLASH program operations

Program operation overview

Program operation consists in issuing write commands. The FLASH supports the execution of only one write-command at a time. Write-while-write are not supported. Nothing prevents overwriting a nonvirgin FLASH word but this is not recommended. The result may lead to invalid data and inconsistent ECC code.

User flash memory

For the user flash memory, 9-bit ECC is associated to each 128-bit data FLASH word. In this case, the FLASH must always perform write operations to nonvolatile memory with a 128-bit word granularity. Once the write buffer is full (128 bits), the busy flag BSY 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- to a 128-bit FLASH word. In this case, a force-write mechanism to the 128 bits + ECC is used (see FW bit in FLASH_CR 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, RO and flash data area

When the target memory is OTP, RO, and flash data area pages, 6-bit ECC code is associated to each 16-bit data FLASH word. The FLASH supports 16- 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 6.3.9.

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_SR register.

Note: For write protections of main FLASH, flash data area, and OTP, see Section 6.5.

Monitoring ongoing write operations

The application software can use a status flag located in FLASH_SR 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.

It is cleared when the current operation is ending or in case of error.

Note: BSY is also set when an OBL launch is triggered (OBL_LAUNCH in FLASH_OPTCR).

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 bank2, the application software must make sure that the PG bit is set to 1 in FLASH_CR. If it is not the case, an unlock sequence must be used (see Section 6.5.4), 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 6.5.4).

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 FLASH_CR and FLASH_OPTCR

The FLASH_CR and 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. 1. Make sure protection mechanism does not prevent to attempt programming.
  2. 2. Check that no flash memory operation is ongoing by checking the BSY bit in FLASH_SR and DBNE bit in FLASH_SR. Check that the write buffer is empty by checking the WBNE bit in FLASH_SR.
  3. 3. Check and clear all the error flags due to previous programming/erase operation.
  4. 4. Unlock the FLASH_CR register, as described in Section 6.5.4 (only if register is not already unlocked).
  5. 5. Enable write operations by setting PG bit in FLASH_CR.
  6. 6. Write one FLASH word at aligned address.

Note: WBNE flag indicates if the 128-bit write buffer is waiting for new data.

No erase request or options change request is allowed between the first write to the write buffer and the completion of the FLASH write operation.

  1. 7. Wait for the BSY bit to be cleared in the corresponding FLASH_SR register.
  2. 8. Clear PG bit in FLASH_CR 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 FW bit in FLASH_CR. In this particular case, the unwritten bits are automatically set to 1. If no bit in the write buffer is cleared to 0, the FW 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 FLASH clock frequency, which directly impacts the performance. If timing constraints are too tight, the nonvolatile 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 6.3.4 for the recommended programming delay depending on the FLASH 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 may corrupt the flash memory content.

Programming errors

When a program operation fails, an error can be reported as described in Section 6.8.

Programming interrupts

See Section 6.9 for details.

6.3.6 FLASH erase operations

Erase operation overview

The FLASH can perform erase operations on 8-Kbyte or 2-Kbyte user pages, 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 data flash, user options, and OTP erase protection, see Section 6.5.

Erase commands are issued through the AHB configuration interface. Since the FLASH 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 6.8 for details).

After successful completion of erase, all the bytes in the erased flash sectors are set to the flash default 0xFF value.

Erase and WRP

If the application software attempts to erase a user page that is write protected, the page erase operation is aborted, and the WRPERR flag is raised in FLASH_SR, as described in Section 6.8.1.

FLASH busy

Busy signals are described in Monitoring ongoing write operations.

Writing to FLASH_CR and FLASH_OPTCR

Refer to Writing to FLASH_CR and FLASH_OPTCR.

Enabling erase operations

Before erasing a page, the application software must make sure that FLASH_CR is unlocked. If this is not the case, an unlock sequence must be used (see Section 6.5.4).

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 page-erase sequence

To erase an 8-Kbyte, a 2-Kbyte user page, or a 1.5K-byte if in data flash without security protections, proceed as follows:

  1. 1. Make sure protection mechanism does not prevent to attempt page erase (WRP, HDP).
  2. 2. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in FLASH_SR, and that the write buffer is empty by checking the WBNE bit in the same register.
  3. 3. Check and clear all the error flags due to previous programming/erase operation (refer to Section 6.8 for details).
  4. 4. Unlock the FLASH_CR register, as described in Section 6.5.4 (only if register is not already unlocked).
  1. 5. Set BKSEL bit, PER bit, EDATASEL bit, and PNB bitfield in FLASH_CR.
    • – BKSEL indicates in which physical bank page has to be erased.
    • – PER indicates a page erase operation.
    • – EDATASEL indicates if the page targeted is a 2-Kbyte EDATA page or a standard page.
    • – PNB contains the target page number.
  2. 6. Set the STRT bit in FLASH_CR.
  3. 7. Wait for the BSY bit to be cleared in FLASH_SR.
  4. 8. STRT bit is automatically cleared at the end of the page erase or in case of error.
  5. 9. Clear PER in FLASH_CR if there are not anymore page erase request to be issued.

Note: If another erase flag is requested simultaneously to the page erase, an PGSERR error is generated.

Standard flash memory bank-erase sequence

To erase a bank , proceed as follows:

  1. 1. Make sure protection mechanism does not prevent to attempt bank erase.
  2. 2. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in FLASH_SR, and that the write buffer is empty by checking the WBNE bit in the same register.
  3. 3. Check and clear all the error flags due to previous programming/erase operation (refer to Section 6.8 for details).
  4. 4. Unlock the FLASH_CR register, as described in Section 6.5.4 (only if register is not already unlocked).
  5. 5. Set the BKSEL bit and the BER bit in FLASH_CR to the targeted physical bank (swap setting is ignored).
  6. 6. Set the STRT bit in FLASH_CR to start the bank erase operation. Then wait until the BSY bit is cleared in FLASH_SR.
  7. 7. STRT bit is automatically cleared at the end of erase sequence or in case of error.
  8. 8. Clear BER in FLASH_CR 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_CR, as described below:

  1. 1. Make sure protection mechanisms do not prevent to attempt mass erase (Section 6.5)
  2. 2. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in FLASH_SR, and that the write buffer is empty by checking the WBNE bit in the same register.
  3. 3. Check and clear all the error flags due to previous programming/erase operation (refer to Section 6.8 for details).
  4. 4. Unlock the FLASH_CR register as described in Section 6.5.4 (only if the registers are not already unlocked).
  5. 5. Set the MER bit to 1 in FLASH_CR.
  6. 6. Set the STRT bit in FLASH_CR. Then wait until BSY bit is cleared in FLASH_SR.
  7. 7. STRT bit is cleared automatically at the end of the erase sequence or in case of error.
  8. 8. Clear MER in FLASH_CR.

Note: Mass and bank erase also erase flash data area pages from the erased bank.

6.3.7 FLASH parallel operations

Since the nonvolatile 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. Same is valid for the flash data area.

In all cases, the sequences are described in Section 6.3.4, Section 6.3.5, and Section 6.3.6.

6.3.8 Flash memory error protections

Error correction codes (ECC)

The FLASH 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, and user flash data area, a stronger 6 ECC bits per 16-bit word is used. A double ECC error is generated for an OTP or flash data area virgin word (for example a word with 22 bits at 1). When this OTP or flash data area word is no more virgin, the ECC error disappears.

More specifically, during each read operation from a 128-bit FLASH word, the FLASH 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 6.8.5.

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 nonvolatile memory.

A similar mechanism applies to read-only, OTP, and user flash data area but with 6-bit ECC for 16-bit data.

6.3.9 OTP and RO memory access

OTP and RO memory are accessed through the main AHB interface. The OTP is accessible at the address 0x08FF E000 to 0x08FF F1FF, and the read only section is accessible from 0x08FF F800 to 0x08FF FDFF.

They are stored in a distinct way as data or user flash, filling first 4 bytes of a page, then 5th to 8th and finally 9th to 12th as columns. It does not impact addressing nor locking mechanism but requires caution to decode ECC double error or operation interruption. Indeed for OTP or RO the ECC address returned in ADDR_ECC bitfield indicate FLASH line.

In case of double error detection, the corrupted access can be identified thanks to DATA_ADDR_ECC bitfield returning OTP position on the line.

They are stored in a different way than user data, each sector being filled vertically 32-bit wise as described in the table below.

Table 21. OTP first page organization

FLASH lineOTP position on FLASH line
0b0000b0010b0100b0110b1000b101
0x00OTP0
0x08FF E000
OTP1
0x08FF E002
OTP256
0x08FF E200
OTP257
0x08FF E202
OTP512
0x08FF E400
OTP513
0x08FF E402
0x01OTP2
0x08FF E004
OTP3
0x08FF E006
OTP258
0x08FF E204
OTP259
0x08FF E206
OTP514
0x08FF E404
OTP515
0x08FF E406
............
0x7EOTP252
0x08FF E1F8
OTP253
0x08FF E1FA
OTP508
0x08FF E3F8
OTP509
0x08FF E3FA
OTP764
0x08FF E5F8
OTP765
0x08FF E5FA
0x7FOTP254
0x08FF E1FC
OTP255
0x08FF E1FE
OTP510
0x08FF E3FC
OTP511
0x08FF E3FE
OTP766
0x08FF E5FC
OTP767
0x08FF E5FE

FLASH one-time programmable area

The FLASH offers a 4608-byte memory area dedicated to application nonconfidential, one-time programmable data (OTP). This area is composed of 2304 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 E000 to 0x08FF F1FE (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 FLASH reports read errors, as described in Section 6.8.5.

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 in FLASH_ECCDR register. ECCD implies a NMI raised, unless setting in SBS prevents that.

OTP write protection

OTP data are organized as 24 blocks of 96 OTP words, as shown in Table 22. An entire OTP block can be protected (locked) from write accesses by setting the LOCKBLi (i = 0 to 23) bit corresponding to each OTP block (i = 0 to 23) in FLASH_OTPBLR. 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 22. Flash memory OTP organization

OTP blockAHB addressAHB wordLock bit
[31:16][15:0]
Block 00x08FF E000OTP0001OTP0000LOCKBL0
0x08FF E004OTP0003OTP0002
...
0x08FF E0BCOTP0095OTP0094
Block 10x08FF E0C0OTP0097OTP0096LOCKBL1
0x08FF E0C4OTP0099OTP0098
...
0x08FF E17COTP0191OTP0190
Block 20x08FF E180OTP0193OTP0192LOCKBL2
0x08FF E184OTP0195OTP0194
...
0x08FF E23COTP0287OTP0286
...
Block 230x08FF F140OTP2209OTP2208LOCKBL23
0x08FF F144OTP2211OTP2210
...
0x08FF F1FCOTP2303OTP2302

OTP write sequence

Follow the sequence below to write an OTP word:

  1. 1. Check that no flash memory operation is ongoing by checking the BSY bit in FLASH_SR register, and that the data buffer is empty by checking the DBNE bit in the same register.
  2. 2. Check and clear all the error flags due to previous programming/erase operation.
  3. 3. Set PG bit in FLASH_CR.
  4. 4. Check the protection status of the target OTP word (see Table 22). The corresponding LOCKBLi bit must not be set to 1.
  5. 5. Write two OTP words (32 bits) corresponding to the 4-byte aligned address shown in Table 22. 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. 6. Wait for the BSY bit to be cleared in FLASH_SR.
  7. 7. Clear PG bit in FLASH_CR if there is not any programming request anymore in the bank.
  8. 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 FLASH offers a 1.5-Kbyte memory area to store read-only data, also referred to as RO. This area is mapped as described in Table 23. It can be accessed through the AHB main port. This read-only area is protected by a robust ECC scheme, as explained in Section 6.3.8.

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 23. Read-only public data organization

Read-only data nameAddressComment
Unique device ID0x08FF F800U_ID[31:0]
0x08FF F804U_ID[63:32]
0x08FF F808U_ID[96:64]
Flash memory size/
package
0x08FF F80CFlash memory size[15:0] || Package code[15:0]
Factory calibration0x08FF F810Vrefint calibration value[31:0]
0x08FF F814TS_CAL1[31:0]
0x08FF F818TS_CAL2[31:0]
Reserved0x08FF F81C to
0x08FF FDFF
Reserved information

6.3.10 FLASH data area

The FLASH offers 64 Kbytes to store extra code, data or emulate EEPROM in 16 EDATA pages per bank. Based on value of EDATA_EN option bit this area is one of the following:

Caution: This area cannot be used as a boot location in BOOTADD.

For greater efficiency, it is always recommended to use page on the other bank for the FLASH data area, so that the application benefits from RWW capability of the dual-bank arrangement.

When SWAP_BANK feature is enabled, the banks are swapped: the flash data area in bank 2 are accessible from 0x0900 000 to 0x0900 5FFF, and the data in bank 1 are accessible from 0x0900 6000 to 0x0900 BFFF.

A bus error is generated on:

Erasing these EDATA pages is possible by setting the EDATASEL bit and following a page erase request. The EDATA page erasure is not taking account EDATA_EN bit.

Protections and security of data FLASH area are detailed in Section 6.5.

Figure 12. FLASH data area memory map

Figure 12. FLASH data area memory map. The diagram shows the memory layout for Bank1 and Bank2. Bank1 (left) and Bank2 (right) both have a 'Code memory map' (light blue) and an 'EDATA' section (grey). The Code memory map for both banks is 128 bits wide with 9-bit ECC, spanning from 0x0800 0000 to 0x0807 FFFF for Bank1 and 0x0808 0000 to 0x080F FFFF for Bank2. Each page size is 8 Kbytes, with pages 0, 1, ..., 63. The EDATA section for both banks is 2 Kbytes wide, spanning from 0x0840 0000 to 0x0840 7FFF for Bank1 and 0x0840 8000 to 0x0840 FFFF for Bank2. Each EDATA page size is 2 Kbytes, with pages 0, 1, ..., 15. The central 'Data memory map' (green) has 6-bit ECC and an EDATA_EN option bit set, spanning from 0x0900 0000 to 0x0900 BFFF. Each page size is 1.5 Kbytes, with pages 0, 1, ..., 15. The diagram also shows the EDATA_EN option bit reset for the code memory maps and the EDATA_EN option bit set for the data memory map.
Figure 12. FLASH data area memory map. The diagram shows the memory layout for Bank1 and Bank2. Bank1 (left) and Bank2 (right) both have a 'Code memory map' (light blue) and an 'EDATA' section (grey). The Code memory map for both banks is 128 bits wide with 9-bit ECC, spanning from 0x0800 0000 to 0x0807 FFFF for Bank1 and 0x0808 0000 to 0x080F FFFF for Bank2. Each page size is 8 Kbytes, with pages 0, 1, ..., 63. The EDATA section for both banks is 2 Kbytes wide, spanning from 0x0840 0000 to 0x0840 7FFF for Bank1 and 0x0840 8000 to 0x0840 FFFF for Bank2. Each EDATA page size is 2 Kbytes, with pages 0, 1, ..., 15. The central 'Data memory map' (green) has 6-bit ECC and an EDATA_EN option bit set, spanning from 0x0900 0000 to 0x0900 BFFF. Each page size is 1.5 Kbytes, with pages 0, 1, ..., 15. The diagram also shows the EDATA_EN option bit reset for the code memory maps and the EDATA_EN option bit set for the data memory map.

MSv76086V1

6.3.11 FLASH bank swapping

The FLASH 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 a user option-byte flag controlled by the SWAP_BANK bit in FLASH_OPTCR register.

Bank specific settings for data area and security attributes follow the original bank and its contents. The control bit BKSEL always refers to physical bank, not the SWAP_BANK setting.

Table 24 shows the memory map that can be accessed depending on the SWAP_BANK bit configuration.

Table 24. Memory map and the swapping option (STM32C53x/542 devices)

Region nameStart addressEnd addressSizePage
(bytes) (bytes)Region name Region name
area SWAP_ BANK = 0SWAP_ BANK = 1
area SWAP_ BANK = 00x0800 00000x0800 1FFF8 KPage 0
area SWAP_ BANK = 00x0800 2000 Bank20x0800 3FFF8 KPage 1
area SWAP_ BANK = 0............
User main0x0801 E0000x0801 FFFF8 KPage 15
memory0x0802 00000x0802 1FFF8 KPage 0
memory0x0802 2000 Bank10x0802 3FFF8 KPage 1
memory............
memory0x0803 E0000x0803 FFFF8 KPage 15
memory0x0840 00000x0840 07FF2 KEDATA Page 0
memory0x0840 0800 Bank20x0840 0FFF2 KEDATA Page 1
User flash............
memory /0x0840 78000x0840 7FFF2 KEDATA Page 15
EDATA_E0x0840 80000x0840 87FF2 KEDATA Page 0
N cleared Bank20x0840 8800 Bank10x0840 8FFF2 KEDATA Page 1
N cleared Bank2............
N cleared Bank20x0840 F8000x0840 FFFF2 KEDATA Page 15
N cleared Bank20x0900 00000x0900 05FF1.5KEDATA Page 0
N cleared Bank20x0900 0600 Bank20x0900 0BFF1.5KEDATA Page 1
Data flash............
memory /0x0900 5A000x0900 5FFF1.5KEDATA Page 15
EDATA_E0x0900 60000x0900 65FF1.5KEDATA Page 0
N set Bank20x0900 6600 Bank10x0900 6BFF1.5KEDATA Page 1
N set Bank2............
N set Bank20x0900 B8000x0900 BFFF1.5KEDATA Page 15
N set Bank20x0BF8 00000x0BF8 1FFF8 KSystem 1 Page 0
Bank10x0BF8 20000x0BF8 3FFF8 KSystem 1 Page 1
System0x0BF8 40000x0BF8 5FFF8 KSystem 1 Page 2
memory0x0BF8 60000x0BF8 7FFF8 KSystem 2 Page 0
Bank20x0BF8 80000x0BF8 9FFF8 KSystem 2 Page 1
Bank20x0BF8 A0000x0BF8 BFFF8 KSystem 2 Page 2

Table 25. Memory map and the swapping option (STM32C55x/562 devices)

Region nameStart addressEnd addressSizePage
Bank2(bytes) (bytes)Region name Region name
area SWAP_ BANK = 0SWAP_ BANK = 1
area SWAP_ BANK = 00x0800 00000x0800 1FFF8 KPage 0
area SWAP_ BANK = 00x0800 2000 Bank20x0800 3FFF8 KPage 1
area SWAP_ BANK = 0............
User main0x0803 E0000x0803 FFFF8 KPage 31
memory0x0804 00000x0804 1FFF8 KPage 0
memory0x0804 2000 Bank10x0804 3FFF8 KPage 1
memory............
memory0x0807 E0000x0807 FFFF8 KPage 31
memory0x0840 00000x0840 07FF2 KEDATA Page 0
memory0x0840 0800 Bank20x0840 0FFF2 KEDATA Page 1
User flash............
memory /0x0840 78000x0840 7FFF2 KEDATA Page 15
EDATA_E0x0840 80000x0840 87FF2 KEDATA Page 0
N cleared Bank20x0840 8800 Bank10x0840 8FFF2 KEDATA Page 1
N cleared Bank2............
N cleared Bank20x0840 F8000x0840 FFFF2 KEDATA Page 15
N cleared Bank20x0900 00000x0900 05FF1.5KEDATA Page 0
N cleared Bank20x0900 0600 Bank20x0900 0BFF1.5KEDATA Page 1
Data flash............
memory /0x0900 5A000x0900 5FFF1.5KEDATA Page 15
EDATA_E0x0900 60000x0900 65FF1.5KEDATA Page 0
N set Bank20x0900 6600 Bank10x0900 6BFF1.5KEDATA Page 1
N set Bank2............
N set Bank20x0900 B8000x0900 BFFF1.5KEDATA Page 15
N set Bank20x0BF8 00000x0BF8 1FFF8 KSystem 1 Page 0
Bank10x0BF8 20000x0BF8 3FFF8 KSystem 1 Page 1
System0x0BF8 40000x0BF8 5FFF8 KSystem 1 Page 2
memory0x0BF8 60000x0BF8 7FFF8 KSystem 2 Page 0
Bank20x0BF8 80000x0BF8 9FFF8 KSystem 2 Page 1
Bank20x0BF8 A0000x0BF8 BFFF8 KSystem 2 Page 2

Table 26. Memory map and the swapping option (STM32C59x/5A3 devices)

Region nameStart addressEnd addressSizePage
Bank2(bytes) (bytes)Region name Region name
area SWAP_ BANK = 0SWAP_ BANK = 1
area SWAP_ BANK = 00x0800 00000x0800 1FFF8 KPage 0
area SWAP_ BANK = 00x0800 2000 Bank20x0800 3FFF8 KPage 1
area SWAP_ BANK = 0............
User main0x0807 E0000x0807 FFFF8 KPage 63
memory0x0808 00000x0808 1FFF8 KPage 0
memory0x0808 2000 Bank10x0808 3FFF8 KPage 1
memory............
memory0x080F E0000x080F FFFF8 KPage 63
memory0x0840 00000x0840 07FF2 KEDATA Page 0
memory0x0840 0800 Bank20x0840 0FFF2 KEDATA Page 1
User flash............
memory /0x0840 78000x0840 7FFF2 KEDATA Page 15
EDATA_E0x0840 80000x0840 87FF2 KEDATA Page 0
N cleared Bank20x0840 8800 Bank10x0840 8FFF2 KEDATA Page 1
N cleared Bank2............
N cleared Bank20x0840 F8000x0840 FFFF2 KEDATA Page 15
N cleared Bank20x0900 00000x0900 05FF1.5KEDATA Page 0
N cleared Bank20x0900 0600 Bank20x0900 0BFF1.5KEDATA Page 1
Data flash............
memory /0x0900 5A000x0900 5FFF1.5KEDATA Page 15
EDATA_E0x0900 60000x0900 65FF1.5KEDATA Page 0
N set Bank20x0900 6600 Bank10x0900 6BFF1.5KEDATA Page 1
N set Bank2............
N set Bank20x0900 B8000x0900 BFFF1.5KEDATA Page 15
N set Bank20x0BF8 00000x0BF8 1FFF8 KSystem 1 Page 0
Bank10x0BF8 20000x0BF8 3FFF8 KSystem 1 Page 1
System0x0BF8 40000x0BF8 5FFF8 KSystem 1 Page 2
memory0x0BF8 60000x0BF8 7FFF8 KSystem 2 Page 0
Bank20x0BF8 80000x0BF8 9FFF8 KSystem 2 Page 1
Bank20x0BF8 A0000x0BF8 BFFF8 KSystem 2 Page 2

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. 1. Check that no flash memory operation is ongoing by checking the BSY and DBNE bits in FLASH_SR, and that the write buffer is empty by checking the WBNE bit in the same register.
  2. 2. Clear all error flags due to a previous operation.
  3. 3. Unlock OPTLOCK bit, if not already unlocked.
  4. 4. Set the new desired SWAP_BANK value in the FLASH_OPTSR_PRG register.
  5. 5. Start the option-byte change sequence by setting the OPTSTRT bit in FLASH_OPTCR.
  6. 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. 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 must 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 RDP level. Instead of being locked by RDP_LEVEL, it is locked by BOOT_LOCK User OB.

The figure below gives an overview of the bank swapping sequence.

Figure 13. FLASH bank swapping sequence

Flowchart of FLASH bank swapping sequence. The process starts with 'Begin', followed by 'Update new firmware in user FLASH bank 1/2'. Then, 'Set/unset SWAP_BANK_OPT option-bit in FLASH_OPTSR_PRG'. This leads to 'Write START bit in FLASH_OPTCR to start option-byte change sequence'. A dashed line labeled 'System reset' separates this from the next step: 'SWAP_BANK of FLASH_OPTSR_CUR is copied to SWAP_BANK_OPT bit in FLASH_OPTCR'. The final step is 'End', leading to 'Execution of new firmware'. The diagram also shows the interaction with registers: FLASH_OPTSR_PRG (with SWAP BANK OPT bit) is programmed into Nonvolatile memory. After a system reset, Nonvolatile memory reloads the option-byte into FLASH_OPTSR_CUR (with SWAP BANK OPT bit). Finally, after another system reset, FLASH_OPTCR (with SWAP BANK bit) is updated. This new swap policy is effective on the AHB bus, controlling User flash memory SWAP logic, which then directs access to Nonvolatile memory bank1 or Nonvolatile memory bank2. Reference: MSv76012V1.
Flowchart of FLASH bank swapping sequence. The process starts with 'Begin', followed by 'Update new firmware in user FLASH bank 1/2'. Then, 'Set/unset SWAP_BANK_OPT option-bit in FLASH_OPTSR_PRG'. This leads to 'Write START bit in FLASH_OPTCR to start option-byte change sequence'. A dashed line labeled 'System reset' separates this from the next step: 'SWAP_BANK of FLASH_OPTSR_CUR is copied to SWAP_BANK_OPT bit in FLASH_OPTCR'. The final step is 'End', leading to 'Execution of new firmware'. The diagram also shows the interaction with registers: FLASH_OPTSR_PRG (with SWAP BANK OPT bit) is programmed into Nonvolatile memory. After a system reset, Nonvolatile memory reloads the option-byte into FLASH_OPTSR_CUR (with SWAP BANK OPT bit). Finally, after another system reset, FLASH_OPTCR (with SWAP BANK bit) is updated. This new swap policy is effective on the AHB bus, controlling User flash memory SWAP logic, which then directs access to Nonvolatile memory bank1 or Nonvolatile memory bank2. Reference: MSv76012V1.

6.3.12 FLASH reset and clocks

Reset management

The FLASH 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:

The FLASH can be reset by a power-on core domain reset, driven by the 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 FLASH 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 the 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 table below indicates how to use FLASH_OPSR and which operation is required.

Table 27. Recommended reactions to FLASH_OPSR contents

CODE_OPOperation interruptedOTP_OPBK_OPDATA_OPFlash memory areaADDR_OP minADDR_OP maxRecommended action
0b000No operation ongoing while reset000_(1)--No extra action
0b001Write operation00/10User flash0x00000x7FFF(2)Erase page and rewrite
110OTP(3)0x02000x037F
00/11EDATA Page(4)0x00000x07FF(2)
0b011Page erase(5)00/10User flash0x00000x7FFFRelaunch page erase
00/11EDATA Page0x00000x07FF
0b100Bank erase00/10User flash--Relaunch bank erase
0b101Mass erase000--Relaunch mass erase
0b110Option change000User configuration--New attempt on option change
  1. 1. '-' = does not matter.
  2. 2. ADDR_OP maximum depends on the flash memory size of the device.
  3. 3. OTP are organized per column, refer to Section 6.3.9.
  4. 4. Depends on EDATA setting in the OB.
  5. 5. Addresses indicated are aligned to page start, data area pages are erased by erase request to corresponding user flash memory page.

Clock management

The FLASH uses the microcontroller AHB interface clock HCLK.

6.4 FLASH option bytes

6.4.1 About option bytes

The FLASH includes a set of nonvolatile option bytes. They are loaded at power-on reset and can be read and modified only through configuration registers.

This section documents:

6.4.2 Option-byte loading

There are multiple ways of loading the option bytes into the FLASH:

  1. 1. Power-on wake-up
    When the device is first powered, the FLASH automatically loads all the option bytes. During the option-byte loading (OBL) sequence, the device remains under reset, and the FLASH cannot be accessed.
  2. 2. Wake-up from system Standby mode
    When the core power domain, which contains the FLASH, is switched from Standby mode to Run mode, the FLASH behaves as during a power-on sequence. During OBL time, the device is not under reset, unlike power-on sequence.
  3. 3. Dedicated option-byte reloading by the application
    When the user application successfully modifies the option-byte content through the FLASH registers, the nonvolatile option bytes are programmed, and the FLASH 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 6.4.3). This value differs from the initial values (user default configuration), and tends to be more restrictive.

6.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 nonvolatile option byte area.

There are numerous rules enforced when attempting to change a user option byte, they are all summarized in Section 6.4.9. Failing to stick to these rules usually results in error, described in Section 6.8.6.

The FLASH features two sets of option-byte registers:

When the OPTLOCK bit in FLASH_OPTCR is set, modifying the FLASH_XXX_PRG registers is not possible.

When OPTSTRT bit is set to 1, the FLASH checks the programming sequence (PGSERR), and the conditions described in Section 6.4.9 (OPTCHANGEERR). If no error has been detected (PGSERR/OPTCHANGEERR), the FLASH launches the option-byte modification in its nonvolatile memory, and updates the option-byte registers with _CUR extension.

If one of the condition described in Section 6.4.9, Section 6.8.6, or Section 6.8.2 is not respected, the FLASH aborts the option-byte change operation. In this case, 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 FLASH_OPTCR is locked. As a result, the application software must unlock the option configuration register before attempting to change the option bytes. FLASH_OPTCR unlock sequence is described in Section 6.5.4.

Option-byte modification sequence

To modify user option bytes, follow the sequence below:

  1. 1. Check that no flash memory operation is ongoing by checking the BSY bit in FLASH_SR, and that the write buffer is empty by checking the WBNE bit in the same register.
  2. 2. Check the data buffer is empty (DBNE = 0) in FLASH_SR.
  3. 3. Clear all error flags due to a previous operation.
  4. 4. Unlock FLASH_OPTCR register as described in Section 6.5.4, unless the register is already unlocked.
  5. 5. Write the desired new option byte values in the corresponding option registers (FLASH_XXX_PRG).
  6. 6. Set the option byte start change OPTSTRT bit to 1 in FLASH_OPTCR.
  7. 7. Wait until BSY bit is cleared in FLASH_SR.
  8. 8. OPTSTRT bit is cleared automatically at the end of the sequence (or in case of error).

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

6.4.4 Option-byte overview

Table 28 lists all the user option bytes managed through the FLASH registers, as well as initial values before the first option-byte change (user default configuration).

Table 28. Option-byte organization

Register313029282726252423222120191817161514131211109876543210
FLASH_OPTSRSWAP_BANKSINGLE_BANKEDATA_ENRes.Res.Res.Res.Res.BOOT0BOOT_SELIWDG_STDBYIWDG_STOPRes.Res.Res.Res.RDP_LEVELNRST_STDBYNRST_STOPRes.Res.Res.Res.Res.Res.Res.
0010011111011011111
FLASH_OPTSR2Res.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.Res.
111
FLASH_BOOTRBOOTADD[31:0]BOOT_LOCK
0x0800_000xC3
FLASH_WRPSG1RWRPG[31:0]
11111111111111111111111111111111
FLASH_WRPSG2RWRPG[31:0]
11111111111111111111111111111111
FLASH_OTPBLRRes.Res.Res.Res.Res.Res.Res.Res.LOCKBL
000000000000000000000000
FLASH_BL_COM_CFGBL_COM_CFG[31:0]
11111111111111111111111111111111
FLASH_HDP1RRes.Res.Res.Res.Res.Res.Res.Res.HDP1_ENDRes.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_STRT
0000000000000001
FLASH_HDP2RRes.Res.Res.Res.Res.Res.Res.Res.HDP2_ENDRes.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_STRT
0000000000000001
FLASH_OEMKEY R1OEMKEY[31:0]
11111111111111111111111111111111
FLASH_OEMKEY R2OEMKEY[63:32]
11111111111111111111111111111111

Table 28. Option-byte organization (continued)

Register313029282726252423222120191817161514131211109876543210
FLASH_OEMKEYR3OEMKEY[95:64]
1111111111111111111111111111111
FLASH_OEMKEYR4OEMKEY[127:96]
1111111111111111111111111111111
FLASH_BSKEYBSKEY[31:0]
10101010101010101010101010101010

6.4.5 Description of user and system option bytes

The general-purpose option bytes that can be used by the application are listed below:

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.

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.

ST logo
ST logo

After reset, if the STMicroelectronics bootloader is selected as boot location, it reads the contents of BL_COM_CFG, and only attempts to establish communication on selected interfaces. This setting allows using the bootloader safely in applications where it otherwise may cause trouble by reconfiguring some GPIOs.

When STMicroelectronics delivers the device, the values programmed in the general-purpose option bytes are the following:

Refer to Section 6.10 for details.

6.4.6 Description of data protection option bytes

The option bytes that can be used to enhance data protection are listed below:

Table 29. Write-protection management

WRP bit numberWrite-protected pages
STM32C53x/542/55x/562STM32C59x/5A3
Bit 0Page 0Page [0 to 1]
Bit 1Page 1Page [2 to 3]
.........
Bit NPage NPage [2 x N to 2 x N +1]

When factory programmed, values of the data-protection option bytes are the following:

Refer to Section 6.10 for details.

6.4.7 Description of data FLASH option bytes

The option bytes that can be used to address the data FLASH pages are:

6.4.8 Description of boot-address option byte

Below the list of option bytes that can be used to configure the appropriate boot address for an application:

When STMicroelectronics delivers the device, the RDP_LEVEL is L0, BOOT_LOCK is not set (0xC3). Address BOOTADD is 0x0800 0000.

Refer to Section 6.10 for details.

6.4.9 Specific rules for modifying option bytes

Besides the OPTLOCK bit and register access rules, there are additional protection means for selected security-sensitive option byte fields.

Multiple 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 section, failing to uphold the rules results in raising OPTCHANGEERR flag (Section 6.8.6 for additional details).

Table 30. Specific OB modifying rules overview

OBHDPLValueRDP level
RDP_LEVEL-Set of possible transitionsSet of possible transitions (Table 36)
HDP1(1)--
BOOTADD--L0 open
LOCKBL-One way switch(1)-
SWAP_BANK-BOOT_LOCK can restrict this change-
BOOT_LOCK--L0 open

1. No OPTCHANGEERR is raised in violation of this.

Even in the closed RDP_LEVEL progression, some OBs can still be modified, if all the other constraints are satisfied. An overview is presented in the table below.

Table 31. OBs modifiable in L2 product

RDP_LEVELOBs that can be modified
L2_wBS or L2SWAP_BANK, LOCKBL, RDP_LEVEL

Specific rules must be respected to update the following OBs:

Note: For all user option bytes above, default values are loaded and Tamper is signaled when a double ECC error occurs during OBL.

6.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 pages, or malicious flash memory erasing.

For that purpose, the flash memory implements the following protection mechanisms:

This section provides a detailed description of all these security mechanisms.

The flash memory interface evaluates the access restrictions in the following order:

  1. 1. Write protection (for write access)
  2. 2. HDP

6.5.1 Hide protection (HDP)

A nonvolatile hide-protection (HDP) area per bank can be defined with a page 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 the OB. With HDPL = 3, the HDP area remains activated and the extension is added. If an extension is added while the base user OB defined area is not active, the extension covers one more page, because HDPx_END page 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 pages .

The size of the inaccessible area can be extended using register FLASH_HDPEXTR values HDPx_EXT. The value HDPx_EXT is a number of pages added to the HDP area (past the HDPx_END page). The volatile HDPx_EXT value in the register can be increased, but cannot decrement.

In case of HDPx_STRT > HDPx_END, the extension covers (HDPx_EXT + 1) size area between pages marked by HDPx_END and HDPx_END + HDPx_EXT.

By default, 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 page).

For example, to protect area by HDP from 0x0800 2000 (included) to 0x0800 7FFF (included):

Figure 14. HDP in user flash memory

Diagram showing HDP protection in a Flash bank. A horizontal bar represents the 'Flash bank' from Page 0 to Page 31. Above the bar, a bracket labeled 'HDP1 - HDPL1 closes' spans from Page 0 to Page 3. A second bracket labeled 'HDP_EXT = 0x02' starts at Page 3 and extends to Page 5. Labels above the brackets indicate PSTRT = 0x01 and PEND = 0x03. The text 'MSv76013V1' is in the bottom right corner of the diagram area.
Diagram showing HDP protection in a Flash bank. A horizontal bar represents the 'Flash bank' from Page 0 to Page 31. Above the bar, a bracket labeled 'HDP1 - HDPL1 closes' spans from Page 0 to Page 3. A second bracket labeled 'HDP_EXT = 0x02' starts at Page 3 and extends to Page 5. Labels above the brackets indicate PSTRT = 0x01 and PEND = 0x03. The text 'MSv76013V1' is in the bottom right corner of the diagram area.

Alternatively, if:

Page 0 and page 1 are HDP protected.

Or a rather unusual example:

Note: For more details on the bank-swapping mechanism, refer to Section 6.5.3.

Table 32. Secure hide protection
HDPx watermark option byte values
(x = 1, 2)
Hide protection area
HDPL = 1-No inaccessible HDP area in user flash memory
HDPL = 2HDPx_END < HDPx_STRTNo inaccessible HDP area in user flash memory
HDPx_END = HDPx_STRTExactly one page is protected by HDP
HDPx_END > HDPx_STRTThe area between HDPx_STRT and HDPx_END is HDP protected.
HDPL = 3HDPx_END < HDPx_STRT and HDPx_EXT = 0No inaccessible HDP area in user flash memory
HDPx_END < HDPx_STRT and HDPx_EXT > 0The area between (HDPx_END + HDPx_EXT) is HDP protected
HDPx_END ≥ HDPx_STRT and HDPx_EXT > 0The area between min (HDPx_STRT, HDPx_END) and (HDPx_END + HDPx_EXT) is HDP protected
Table 33. HDP protections summary
HDP protectionUser flash memory
Access to OB HDP areaAccess to EXT HDP area
HDPL 2 or 3HDPL1HDPL3HDPL1 or HDPL 2
FetchBUS ERROROKBUS ERROROK
ReadRAZRAZ
WriteWI, WRPERRIf WRP disabled: OK
else: WI, WRPERR
WI, WRPERRIf not WRP: OK
Else: WI, WRPERR
Erase (mass erase)

6.5.2 Flash memory register privileged and unprivileged modes

The FLASH registers can be read and written by privileged and unprivileged accesses, depending on the PRIV bit in FLASH_PRIVCFGR.

6.5.3 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:

The SWAP_BANK is rendered immutable by setting BOOT_LOCK.

Note: The BK_ECC bit in FLASH_OEMKEYR2_CUR and FLASH_ECCDETR, BKSEL bit in FLASH_CR 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 15. Protection attributes in case of bank swap illustration

Diagram illustrating protection attributes in case of bank swap. It shows two states: 'Before Swap' and 'After Swap'. In the 'Before Swap' state, Bank 1 (purple) is at the top (0x0800 0000 to 0x0803 FFFF) and Bank 2 (green) is at the bottom (0x0804 0000 to 0x0807 FFFF). Bank 1 has an HDP area (pink) and write protection blocks (yellow). Bank 2 has no protections defined. In the 'After Swap' state, the banks are swapped: Bank 2 is at the top and Bank 1 is at the bottom, but their internal protection attributes (HDP area, write protection blocks) remain the same. A central 'SWAP' label with two crossed arrows indicates the transition.

MSv76014V1

Diagram illustrating protection attributes in case of bank swap. It shows two states: 'Before Swap' and 'After Swap'. In the 'Before Swap' state, Bank 1 (purple) is at the top (0x0800 0000 to 0x0803 FFFF) and Bank 2 (green) is at the bottom (0x0804 0000 to 0x0807 FFFF). Bank 1 has an HDP area (pink) and write protection blocks (yellow). Bank 2 has no protections defined. In the 'After Swap' state, the banks are swapped: Bank 2 is at the top and Bank 1 is at the bottom, but their internal protection attributes (HDP area, write protection blocks) remain the same. A central 'SWAP' label with two crossed arrows indicates the transition.

6.5.4 Flash memory configuration protection

The FLASH uses hardware mechanisms to protect the following assets against unwanted or spurious modifications (such as software bugs):

The FLASH configuration registers protection is summarized in Table 34. Registers not present in this table are not protected by a key.

Table 34. FLASH interface register protection summary

Register nameUnlocking registerProtected asset
FLASH_CRFLASH_KEYRWrite/erase control
FLASH_OPTCRFLASH_OPTKEYRFLASH bank option-byte words change

6.5.5 Write protection

The purpose of FLASH write protection is to prevent unwanted modifications to embedded nonvolatile code and/or data.

A write-protected group of pages can neither be erased nor programmed. As a result, a bank erase cannot be performed if some page is write-protected, unless a RDP level transition to L0 is triggered (erasing the whole user flash memory).

Note: Write protection errors are documented in Section 6.8.

6.5.6 FLASH data area protections

The FLASH can be configured to have 64-Kbyte (or 48-Kbyte if EDATA_EN is set) memory area to store data and emulate EEPROM (see Section 6.3.10: FLASH data area). These pages can not be protected by HDP or WRPGS whatever the setting of EDATA_EN.

6.5.7 RDP protection and life cycle management

Nonvolatile states, or debug states, are determined by the RDP levels 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.

Figure 16. RDP transitions

Diagram of RDP transitions between Level 0 and Level 2 states.

The diagram illustrates the transitions between different Readout Protection (RDP) levels. It features three main states: Level 0 (RDP = 0xED), Level 2 + boundary scan (RDP = 0xD1), and Level 2 (RDP = 0x72). Transitions are represented by colored arrows with specific conditions:

A legend at the bottom defines the arrow colors:

MSv76087V2

Diagram of RDP transitions between Level 0 and Level 2 states.

HDP works equally regardless of the RDP level.

Table 35. RDP levels description

RDP_LEVELCode in OBDescription
L0 (Open)0xED
  • – Full debug capabilities
  • – Read/Write/Erase Flash is possible
  • – Read/Modify the option bytes
  • – Boot in bootloader or user flash based on BOOT0 pin or option bytes
  • – Boundary scan available under reset
L2_wBS (Closed + boundary scan)0xD1
  • – No debug capabilities
  • – Read/Write/Erase Flash is possible
  • – All option bytes Read by user code
  • – SWAP_BANK (depending on BOOT_LOCK) & LOCKBL (for OTP) option bytes can be modified
  • – Boot in user flash only
  • – Boundary Scan available under reset
L2 (Closed)0x72
  • – No debug capabilities
  • – Read/Write/Erase Flash is possible
  • – All option bytes Read by user code
  • – SWAP_BANK (depending on BOOT_LOCK) & LOCKBL (for OTP) option bytes can be modified
  • – Boot in user flash only

Caution: STMicroelectronics cannot functionally analyze parts with level 2 protection enabled. Regress parts to RDP level 0 before returning them for analysis (refer to OEM RDP lock mechanism).

6.5.8 RDP level transitions

Progressing to more closed levels is the normal product life cycle, that does not require security measures. Transition in direction to open level (RDP Level 0) is a regression, and is possible only thanks to the OEM Key.

There is no restriction on reading the current RDP level.

Transitions to L2 with boundary scan (L2_wBS) or L2 (L2) closed states

Transition from L0 to L2 with or without boundary scan is managed either by software running on the device, or directly, using a debug interface. By software, it is assumed that transitions are triggered by the bootloader, but generally any software running on the device can do a progress transition.

Caution: The new RDP Level will only be valid after next system or power reset.

Transition from L2 with boundary scan to L2 is only feasible thanks the BSKEY option-byte key:

This key must be written under reset and L2 with boundary scan thanks to JTAG in order to progress to L2 RDP level.

Regression to L0 open debug level

This transition is a full regression, possible from either L2_wBS or L2 if an OEM key has been provisioned. The debug tools are used to provide the OEM key, if the key matches the one provisioned under L0, the device regresses securely in RDP L0.

The regression has the following consequences:

Table 36. RDP levels transitions

FromTo(1)
L0L2_wBSL2
L0-OB update thanks to debug or bootloader
L2_wBSOEM key regression-BSKEY
L2OEM key regressionX-

1. 'X' = transitions that are not permitted (OPTCHANGEERR raised). '-' = no change.

An attempt to make an illegal transition results in the OPTCHANGEERR.

An incorrect RDP_LEVEL (on OBL) is interpreted as L2.

6.5.9 OEM key management

The OEM 128-bit key (OEMKEY) can be defined in order to permit the RDP regression.

OEM lock activation

The 128-bit key is coded on four registers: FLASH_OEMKEYR1 to FLASH_OEMKEYR4. OEMKEY and BSKEY cannot be read through these registers. They are read as zero.

Caution: OEMKEY can only be modified in readout protection level 0.

In order to activate OEM regression mechanism, the following steps are needed:

  1. 1. Check that the RDP is at L0.
  2. 2. Write a 128-bit key in FLASH_OEMKEYR1 to FLASH_OEMKEYR4.
  3. 3. Launch option modification by setting the OPTSTRT bit in FLASH_CR.
  4. 4. Wait for the BSY bit to be cleared and check that OPTWERR is not set.
  5. 5. Check that OEMLOCK is set.

Note: Once the OEM KEY has been programmed a first time, the OEMLOCK bit remains set. The user can reprogram the key, but cannot erase it.

OEM key validation mechanism

The OEM RDP lock mechanism is active when the OEMLOCK bit is set. The OEMKEY, can

be validated while in RDP L0.

OEM RDP regression mechanism

The OEM RDP lock mechanism is active when the OEMLOCK bit is set. It authorizes RDP L2 to RDP L0 regression.

6.5.10 BS key management

The BS key is used to transition from RDP L2_wBS to L2. This key is coded in FLASH_BSKEYR, and can be modified only under RDP L0. During production, the value 0xAAAA AAAA is preprogrammed in BSKEY option bytes.

In order to personalize BSKEY transition mechanism, the following steps are needed:

  1. 1. Check that the RDP is at L0.
  2. 2. Write the desired key in FLASH_BSKEYR.
  3. 3. Launch option modification by setting the OPTSTRT bit in FLASH_CR.
  4. 4. Wait for the BSY bit to be cleared and check that OPTWERR is not set.
  5. 5. Check that BSLOCK bit has been set.

BSKEY RDP transition mechanism

In order to transition from RDP L2_wBS to L2 follow these steps:

  1. 1. Provide BSKEY[31:0] through JTAG or SWD under reset in DBGMCU_BSKEY_PWD. The key is 0xAAAA AAAA if not updated under L0, otherwise it is the value provisioned in BSKEYR.
  2. 2. If this key matches the BSKEY value:
    • – The RDP transition is launched by hardware (it is not possible to execute instructions when the key is matching).
    • – A power-on reset is applied (cycle VDD power supply off and on).

if the key does not match the BSKEY value, the RDP transition and any access to the flash memory are blocked until a next power-on reset.

6.5.11 One-time-programmable and read-only memory protections

OTP/RO in the flash memory are detailed in Section 6.3.9. 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. OTP write protection describes a method of locking out the OTP area.

The access conditions are summarized in the table below.

Table 37. OTP/RO access constraints

-Undefined addresses4.5-Kbyte page dedicated to OTP1.5-Kbyte page dedicated to RO
0x08FF_F200 - F7FF
0x08FF_FE00 - FFFF
0x08FF_E000 - F1FF OTP0x08FF_F800 - FDFF RO
XBus errorBus error
RIf correct size OK, else bus error
WBus error if incorrect size.
WRPERR if block is protected by LOCKBL, else OK.
If correct size WI, else bus error
eraseNot applicable

6.6 System memory

6.6.1 System memory introduction

System memory stores bootloader firmware that is programmed by ST during production. The bootloader provides runtime services to user firmware. These services are described hereafter in this section.

6.6.2 Bootloader user functions

As other microcontroller peripherals features and mapping, the bootloader library functions are exposed to user within the CMSIS device header file provided by the STM32CubeC5 firmware package. Refer to the online HAL/LL drivers documentation to get more details regarding STM32CubeC5 firmware package. Bootloader library provides runtime services through prefixed EXITHDP functions.

Table 38. C defined macro for HDP services

C defined macroLocation in flash memory
EXITHDP_PFUNC0x0BF883E0

EXITHDPLIB

The user firmware calls EXITHDPLIB functions using EXITHDPLIB_PFUNC C defined macro, that points to a location within system memory.

Table 39. EXITHDPlib interface function list
LibraryFunction
EXITHDP_PFUNCJumpHDPLvl2
JumpHDPLvl3

The EXITHDPLIB functions are described within section hereafter.

a) JumpHDPLvl2

Prototype:

uint32_t JumpHDPLvl2(uint32_t VectorTableAddr, uint32_t MPUIndex)

User code function call example:

EXITHDPLIB_PFUNC->JumpHDPLvl2((uint32_t)NextVectorTableAddr, 1U );

Arguments:

Input parameter, address of the next vector table to apply.

The vector table format is the one used by the Cortex-M33 core.

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:

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), EXITHDPLIB_Sec_JumpHDPLvl2 returns 0xF5F5F5F5.

b) JumpHDPLvl3

Prototype

uint32_t JumpHDPLv13(uint32_t VectorTableAddr, uint32_t MPUIndex)

User code function call example:

EXITHDPLIB_PFUNC->JumpHDPLv13((uint32_t)NextVectorTableAddr, 1U );

Arguments:

Descriptions:

User calls JumpHDPLv13 to:

After closing HDPL1/2, JumpHDPLv13 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. JumpHDPLv13 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), JumpHDPLv13 returns 0xF5F5F5F5.

6.7 FLASH low-power modes

The table below summarizes the FLASH behavior in STM32 low-power modes. The FLASH belongs to the core domain.

Table 40. Effect of low-power modes on the FLASH

Power modeAllowed if FLASH busyFLASH power mode
Run/SleepYesRun
Stop (clock stopped)NoClock gated (in normal or low-power mode)
StandbyNoOff

The procedure to switch the FLASH into various power mode (run, clock gated, stopped, off) is described hereafter.

Note: For more information on microcontroller power states, refer to Section 8: Power control (PWR).

Managing FLASH domain switching to Stop or Standby mode

As explain in Table 40, if the FLASH informs the RCC that it is busy (BSY, DBNE, WBNE is set), the microcontroller cannot switch the core domain to Stop or Standby mode.

There are two ways to release the FLASH:

The microcontroller can then switch the domain to Stop or Standby mode.

6.8 FLASH error management

The FLASH automatically reports when an error occurs during a read, program or erase operation. A wide range of errors are reported:

The application software can individually enable the interrupt for each error, as detailed in Section 6.9.

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:

6.8.1 Write protection error (WRPERR)

When an illegal erase/program operation is attempted to the nonvolatile memory, the FLASH sets the write protection error flag WRPERR in FLASH_SR.

An erase operation is rejected and flagged as illegal if it targets one of the following memory areas:

A program operation is ignored and flagged as illegal if it targets one of the following memory areas:

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_CCR.

If WRPERRIE bit in FLASH_CR is set to 1, an interrupt is generated when WRPERR flag is raised (see Section 6.9 for details).

6.8.2 Programming sequence error (PGSERR)

When the programming sequence is incorrect, the FLASH interface sets the programming sequence error flag PGSERR in FLASH_SR.

More specifically, PGSERR flag is set when one of below conditions is met:

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 to 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_CCR.

If PGSERRIE bit in FLASH_CR is set to 1, an interrupt is generated when PGSERR flag is raised (see Section 6.9 for details).

6.8.3 Strobe error (STRBERR)

When the application software writes several times to the same byte in the write buffer, the FLASH sets the strobe error flag STRBERR in FLASH_SR, whatever the target bank of the write access.

When STRBERR is raised, the current program operation is aborted and the write buffer is invalidated.

STRBERR is cleared by setting CLR_STRBERR bit to 1 in FLASH_CCR.

If STRBERRIE bit in FLASH_CR is set to 1, an interrupt is generated when STRBERR flag is raised (see Section 6.9 for details).

6.8.4 Inconsistency error (INCERR)

When a programming inconsistency is detected, the FLASH sets the inconsistency error flag INCERR in FLASH_SR.

More specifically, INCERR flag is set when the following condition is met:

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. 1. Execute a handler routine when INCERR flag is raised.
  2. 2. Stop all write requests to FLASH.
  3. 3. Clear INCERR bit.
  4. 4. Restart the write operations where they have been interrupted.

INCERR flag is cleared by setting CLR_INCERR bit to 1 in FLASH_CCR.

If INCERRIE bit in FLASH_CR register is set to 1, an interrupt is generated when INCERR flag is raised (see Section 6.9 for details).

6.8.5 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.

When two ECC errors are detected during a read, the FLASH interface sets the double error detection flag ECCD in FLASH_ECCDETR.

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 Section 12.5.12: SBS 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). If the address corresponds to a read-only area, to a EDATA page (in user mode or in FLASH data area mode) or to an OTP area, the OTP_ECC or SYSF_ECC or EDATA_ECC bit is also set to 1 in FLASH_ECCCORR (FLASHBS_ECCDETR). 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 41. Locating ECC failure

OTP_ECCSYSF_ECCBK_ECCDATA_EC
C
FLASH areaADDR_ECC
min
ADDR_ECC
max
000/10User FLASH0x00000x7FFF(1)
010/10System FLASH0x00000x0FFF
1010OTP0x02000x037F
000/11EDATA page 00x00000x007F
000/11EDATA page 10x00800x00FF
000/11EDATA page 20x01000x017F

Table 41. Locating ECC failure (continued)

OTP_ECCSYSF_ECCBK_ECCDATA_EC
C
FLASH areaADDR_ECC
min
ADDR_ECC
max
000/11EDATA page 30x01800x01FF
000/11EDATA page 40x02000x027F
000/11EDATA page 50x02800x02FF
000/11EDATA page 60x03000x037F
000/11EDATA page 70x03800x03FF
000/11EDATA page 80x04000x047F
000/11EDATA page 90x04800x04FF
000/11EDATA page 100x05000x057F
000/11EDATA page 110x05800x05FF
000/11EDATA page 120x06000x067F
000/11EDATA page 130x06800x06FF
000/11EDATA page 140x07000x077F
000/11EDATA page 150x07800x07FF

1. ADDR_ECC maximum depends on the flash memory size of the product.

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). It is mandatory to clear ECCC or ECCD flags before starting a new read operation. 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. ADDR_ECC value indicates the FLASH line where the ECC error occurred. If the EDATA_EN option bit is set, the EDATA sectors are programmed and read as 16-bit accesses, (memory row being 137 bits long: 128-bit + 9-bit ECC). Consequently, the arrangement of the memory is modified. The first 32 bits of each row of a sector are filled first, then the bits from 32 to 63 and finally from 64 to 96 (the rest of the memory row contains ECC code). The ADDR_ECC indicates the memory line holding the failure. To identify the data corrupted on the line, DATA_ADDR_ECC bitfield value can be used to

discriminate which column holds the failed data (only in case of error relative to data area or OTP).

Example: ADDR_ECC = 0x0312 and DATA_ADDR_ECC = 0x3.

ECCC (respectively ECCD) flag is cleared by setting to 1 the ECCC bit (respectively ECCD bit) in FLASH_ECCCORR (FLASH_ECCDETR).

If ECCC bit in FLASH_ECCCORR is set to 1, an interrupt is generated when ECCC flag is raised. Only NMI is generated for the ECCD (see Section 6.9 for details).

6.8.6 Option-byte change error (OPTCHANGEERR)

When the FLASH finds an error during an option-byte change operation, it aborts the operation, and sets the option-byte change error flag OPTCHANGEERR in FLASH_SR.

The error is raised after OPTSTRT bit set if one of the following occurs:

Note: Exceptions and details provided in the OB description (see Section 6.4.9).

OPTCHANGEERR flag is cleared by setting CLR_OPTCHANGEERR bit to 1 in FLASH_CCR.

If OPTCHANGEERRIE bit in FLASH_CR is set to 1, an interrupt is generated when OPTCHANGEERR flag is raised (see Section 6.9 for details).

It is mandatory to clean the OPTCHANGEERR flag before starting a new operation (option change, erase, or write).

6.8.7 Miscellaneous HardFault errors

The following events generate a bus error on the corresponding bus interface:

6.9 FLASH interrupts

The FLASH can generate a maskable interrupt to signal the following events on a given bank:

A NMI is raised on double-ECC-error detection during read operation.

The user can individually enable or disable FLASH interrupt sources by changing the mask bits in FLASH_CR, FLASH_ECCCORR, and FLASH_ECCDETR. Setting the appropriate mask bit to 1 enables the interrupt.

Note: Before writing, FLASH_CR must be unlocked as explained in Section 6.5.4.

The table below summarizes the available FLASH interrupt features. As mentioned, some flags need to be cleared before a new operation is triggered.

Table 42. FLASH interrupt request

Interrupt event flagError flag label in registerEnable control bitClear flag to resume operation
End of operation eventEOPEOPIEN/A
Write protection errorWRPERRWRPERRIEYes
Programming sequence errorPGSERRPGSERRIEYes
Strobe errorSTRBERRSTRBERRIEYes

Table 42. FLASH interrupt request (continued)

Interrupt event flagError flag label in registerEnable control bitClear flag to resume operation
Inconsistency errorINCERRINCERRIEYes
Option byte errorOPTCHANGEERR-Yes
ECC single error correction eventECCCECCCIENo
ECC double error detection event(1)ECCDDisabledNo

1. NMI.

The status of the individual maskable interrupt sources described in Table 42 (except for option-byte error and ECC) can be read in FLASH_SR register. They can be cleared by setting to 1 the adequate bit in FLASH_CCR.

Note: No unlocking mechanism is required to clear an interrupt.

End of operation event

Setting the end of operation interrupt enable bit (EOPIE) in FLASH_CR 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_CCR clears EOP flag.

6.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.

6.10.1 FLASH access control register (FLASH_ACR)

Address offset: 0x000

Reset value: 0x000X 0027

Bit 16 not reset by system reset

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. For more details, refer to Section 6.3.4 and Section 6.3.5.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EMPTY
rw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.PRFTENRes.Res.WRHIGHFREQ[1:0]LATENCY[3:0]
rwrwrwrwrwrwrw

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

Bit 16 EMPTY: Main flash memory area empty (not reset by system reset)

Set and reset by software. This bit indicates whether the boot location of the main flash memory area (indicated by BOOT_ADD) is erased or has a programmed value.

0: Boot address in main flash memory area programmed

1: Boot address in main flash memory area empty

Bits 15:9 Reserved, must be kept at reset value.

Bit 8 PRFTEN: Prefetch enable

When this bit value is modified, the user must read back this register to be sure PRFTEN has been taken into account. This bit is used to control the prefetch.

0: Prefetch disabled

1: Prefetch enabled when latency is at least 1 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 nonvolatile memory signals during programming operations. The application software has to program them to the correct value depending on the FLASH frequency. 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 nonvolatile memory banks. The application software has to program them to the correct value depending on the FLASH frequency and voltage conditions.

0000: 0 wait state

0001: 1 wait state

0010: 2 wait states

0011-1111: {v} wait states

Note: No check is performed by hardware to verify that the configuration is correct.

6.10.2 FLASH key register (FLASH_KEYR)

Address offset: 0x004

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is write-only.

The following values must be programmed consecutively to unlock FLASH_CR and to allow programming/erasing it. A wrong sequence locks FLASH_CR until next system reset.

1st key = 0x4567 0123

2nd key = 0xCDEF 89AB

31302928272625242322212019181716
KEY[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[31:0]: Nonvolatile memory configuration access unlock key

6.10.3 FLASH option key register (FLASH_OPTKEYR)

Address offset: 0x00C

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is write-only.

The following values must be programmed consecutively to unlock FLASH_OPTCR. A wrong sequence locks FLASH_OPTCR until next system reset.

1st key = 0x0819 2A3B

2nd key = 0x4C5D 6E7F

31302928272625242322212019181716
OPTKEY[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
OPTKEY[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 OPTKEY[31:0]: FLASH option-byte control access unlock key

6.10.4 FLASH operation status register (FLASH_OPSR)

Address offset: 0x018

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

31302928272625242322212019181716
CODE_OP[2:0]Res.Res.Res.Res.OTP_OPRes.BK_OPDATA_OPRes.Res.Res.Res.Res.
rrrrrr
1514131211109876543210
ADDR_OP[15:0]
rrrrrrrrrrrrrrrr

Bits 31:29 CODE_OP[2:0]: Flash memory operation code

Bits 28:25 Reserved, must be kept at reset value.

Bit 24 OTP_OP: OTP operation interrupted

This bit indicates that a reset interrupted an ongoing operation in the OTP area.

Bit 23 Reserved, must be kept at reset value.

Bit 22 BK_OP: Interrupted operation bank

This bit indicates which bank was concerned by operation. (Refer to Section Table 24.: Memory map and the swapping option (STM32C53x/542 devices))

Bit 21 DATA_OP: FLASH data area operation interrupted

This bit indicates if user data FLASH area is concerned by an operation.

Bits 20:16 Reserved, must be kept at reset value.

Bits 15:0 ADDR_OP[15:0]: Interrupted operation address

6.10.5 FLASH option control register (FLASH_OPTCR)

Address offset: 0x01C

Reset value: 0xX000 0001

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Access: No wait state when no flash memory operation is ongoing.

This 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.

31302928272625242322212019181716
SWAP_BANKRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
r
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OPTSTRTOPTLOCK
rwrs

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 is set only by software and cleared when the option-byte change is completed or an error occurs (PGSERR or OPTCHANGEERR). It is reset at the same time as BSY bit.

The user application cannot modify any FLASH_XXX_PRG register until the option change operation has been completed.

Before setting this bit, the user has to write the required values in FLASH_XXX_PRG.

FLASH_XXX_PRG registers are locked until the option-byte change operation has been executed in nonvolatile 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.

6.10.6 FLASH status register (FLASH_SR)

Address offset: 0x020

Reset value: 0x0000 000X

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.OPTCH
ANGEER
RR
Res.Res.INCER
R
STRBE
RR
PGSER
R
WRPE
RR
EOP
rrrrrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.BSLOC
K
OEML
OCK
Res.Res.Res.Res.DBNERes.WBNEBSY
rrrrr

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

Bit 23 OPTCHANGEERR: Option-byte change error flag

This flag indicates that an error occurred during an option-byte change operation. When This bit is set to 1, the option-byte change operation did not successfully complete. An interrupt is generated when this flag is raised if OPTCHANGEERRIE in FLASH_NSCR is set to 1.

Writing 1 to CLR_OPTCHANGEERR in FLASH_CCR clears OPTCHANGEERR.

0: No option-byte change errors occurred.

1: One or more errors occurred during an option-byte change operation.

Note: OPTSTRT 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

This flag is raised when an inconsistency error occurs. An interrupt is generated if INCERRIE is set to 1. Writing 1 to CLR_INCERR in FLASH_CCR clears INCERR.

0: No inconsistency error occurred.

1: An inconsistency error occurred.

Bit 19 STRBERR: Strobe error flag

This 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 STRBERRIE is set to 1.

Writing 1 to CLR_STRBERR in FLASH_CCR clears STRBERR.

0: No strobe error occurred.

1: A strobe error occurred.

Bit 18 PGSERR: Programming sequence error flag

This 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 in FLASH_CCR clears PGSERR.

0: No sequence error occurred.

1: A sequence error occurred.

Bit 17 WRPERR: Write protection error flag

This 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_CCR clears WRPERR.

0: No write-protection error occurred.

1: A write-protection error occurred.

Bit 16 EOP: End of operation flag

This flag is set when an operation (program/erase) completes. An interrupt is generated if 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 in FLASH_CCR.

Bits 15:10 Reserved, must be kept at reset value.

Bit 9 BSLOCK: BS lock

This bit indicates that the BS key read during the option byte loading is not default (default is 0xAAAA AAAA).

When set, the BS personalized key mechanism to transition to L2 from L2_wBS is active.

Bit 8 OEMLOCK: OEM lock

This bit indicates that the OEM key read during the OBL is not virgin. When set, the OEM RDP lock mechanism is active. The lock mechanism allows the user to regress from RDP L2_wBS or L2 to L0. This bit is set once a 128-bit password is written in OEMKEYRx registers and written in memory. It cannot be cleared.

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

Bit 3 DBNE: Data buffer not empty flag

This flag is set when the FLASH is processing 6-bit ECC data (OTP or EDATA area when EDATA_EN option bit set) in a dedicated buffer. This bit cannot be cleared by software. The hardware resets it once the buffer is free.

Bit 2 Reserved, must be kept at reset value.

Bit 1 WBNE: Write buffer not empty flag

This flag is set when the FLASH 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:

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.

Bit 0 BSY: Busy flag

This 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.

6.10.7 FLASH control register (FLASH_CR)

Address offset: 0x028

Reset value: 0x0000 0001

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Access: No wait state when no flash memory operation is ongoing.

This 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.

31302928272625242322212019181716
BKSELRes.EDATASELRes.Res.Res.Res.Res.OPTCHANGEERRIERes.Res.INCERRIESTRBEERRIEPGSERRIEWRPEERRIEEOPIE
rwrwrwrwrwrwrwrw
1514131211109876543210
MERRes.Res.PNB[6:0]STRTFWBERPERPGLOCK
rwrwrwrwrwrwrwrwrsrwrwrwrwrs

Bit 31 BKSEL: Bank selector bit

This bit can only be programmed when LOCK is cleared to 0. This bit selects physical bank, SWAP_BANK setting is ignored.

0: Bank1 is selected for bank erase (BER)/page erase (PER)/interrupt enable.

1: Bank2 is selected for BER/PER.

Bit 30 Reserved, must be kept at reset value.

Bit 29 EDATASEL: EDATA erase selector bit

This bit can only be programmed when LOCK is cleared to 0. This bit selects if page erased concern EDATA page or User main flash pages. This bit has no effect if PER bit is reset.

0: Main FLASH page erase

1: FLASH data area EDATA page erase

Note: During a bank erase, the user and the EDATA sectors are always erased, regardless of this bit setting.

Bits 28:24 Reserved, must be kept at reset value.

Bit 23 OPTCHANGEERRIE: Option-byte change error interrupt enable bit

This 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 4 FW: Write forcing control bit

This bit 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 FLASH resets this bit 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: Bank-erase request

Setting this 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 PER 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 pages are protected.

Bit 2 PER: Page-erase request

Setting this bit to 1 requests a sector erase. PER can be programmed only when LOCK is cleared to 0. If MER and PER are also set, a PGSERR is raised.

0: Page erase not requested

1: Page erase requested

Bit 1 PG: Programming control bit

This bit can be programmed only when LOCK is cleared to 0. It allows programming in bank1 and bank2.

0: Programming disabled

1: Programming enabled

Bit 0 LOCK: Configuration lock bit

This bit locks FLASH_CR. The correct write sequence to FLASH_KEYR unlocks this bit. If a wrong sequence is executed, or if the unlock sequence to FLASH_KEYR 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_CR register do not change.

0: FLASH_CR unlocked

1: FLASH_CR locked

6.10.8 FLASH clear control register (FLASH_CCR)

Address offset: 0x030

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.CLR_OPTCHANGEERRRes.Res.CLR_INCERRCLR_STRBERRCLR_PGSERRCLR_WRPERRCLR_EOP
wwwwww
1514131211109876543210
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: OPTCHANGEERR clear bit
Setting this bit to 1 clears the corresponding flag in FLASH_SR.

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_SR.

Bit 19 CLR_STRBERR: STRBERR flag clear bit
Setting this bit to 1 resets to 0 STRBERR flag in FLASH_SR.

Bit 18 CLR_PGSERR: PGSERR flag clear bit
Setting this bit to 1 resets to 0 PGSERR flag in FLASH_SR.

Bit 17 CLR_WRPERR: WRPERR flag clear bit
Setting this bit to 1 resets to 0 WRPERR flag in FLASH_SR.

Bit 16 CLR_EOP: EOP flag clear bit
Setting this bit to 1 resets to 0 EOP flag in FLASH_SR.

Bits 15:0 Reserved, must be kept at reset value.

6.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 privileged mode.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PRIVRes.
rw

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

Bit 1 PRIV: Privilege attribute

0: Access to registers is always granted.

1: Access to registers is denied in case of unprivileged access.

Bit 0 Reserved, must be kept at reset value.

6.10.10 FLASH HDP extension register (FLASH_HDPEXTR)

Address offset: 0x048

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. 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.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_EXT[5:0]
rwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_EXT[5:0]
rwrwrwrwrwrw

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

Bits 21:16 HDP2_EXT[5:0]: HDP area extension in 8-Kbyte pages in bank2
Extension is added after the HDP2_END page (included).

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

Bits 5:0 HDP1_EXT[5:0]: HDP area extension in 8-Kbyte pages in bank1
Extension is added after the HDP1_END page (included).

6.10.11 FLASH option status register (FLASH_OPTSR_CUR)

Address offset: 0x050

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0x20B0 72D8 (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This read-only register reflects the current values of corresponding option bits.

(Register bits 0 to 31 are loaded with values from the flash memory at OBL)

31302928272625242322212019181716
SWAP_BANKSINGLE_BANKEDATA_ENRes.Res.Res.Res.Res.BOOT0BOOT_SELIWDG_STDBYIWDG_STOPRes.Res.Res.Res.
rrrrrrr
1514131211109876543210
RDP_LEVEL[7:0]NRST_STDBYNRST_STOPRes.WWDG_SWIWDG_SWRes.Res.Res.
rrrrrrrrrrrr

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 in FLASH_OPTCR after a reset.

0: Bank1 and bank2 not swapped

1: Bank1 and bank2 swapped

Bit 30 SINGLE_BANK: Dual-bank selection option status bit

For products:

- STM32C53x/542 with 128-Kbyte user memory

- STM32C55x/562 with 256-Kbyte user memory

- STM32C59x/5A3 with 512-Kbyte user memory

SINGLE_BANK reflects single or dual-bank memory selection.

0: User flash is split between bank 1 and bank 2

1: User flash is located in one bank

Note: This bit has no impact on EDATA sectors.

Bit 29 EDATA_EN: FLASH data area enable

0: No FLASH data area (EDATA pages are 128-bit writable)

1: FLASH data area is enabled (EDATA pages are 16/32-bit writable)

Bits 28:24 Reserved, must be kept at reset value.

Bit 23 BOOT0: Boot 0 option bit

0: BOOT0 = 0

1: BOOT0 = 1

Bit 22 BOOT_SEL: Boot 0 source selection

0: BOOT0 signal is defined by the BOOT0 option bit.

1: BOOT0 signal is defined by BOOT0 pin value (legacy mode).

6.10.12 FLASH option status register (FLASH_OPTSR_PRG)

Address offset: 0x054

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is used to program values in corresponding option bits. Values after reset reflects the current values of the corresponding option bits.

(Register bits 0 to 31 are loaded with values from the flash memory at OBL)

31302928272625242322212019181716
SWAP_BANKSINGLE_BANKEDATA_ENRes.Res.Res.Res.Res.BOOT0BOOT_SELIWDG_STDBYIWDG_STOPRes.Res.Res.Res.
rwrwrwrwrwrwrw
1514131211109876543210
RDP_LEVEL[7:0]NRST_STDBYNRST_STOPRes.WWDG_SWIWDG_SWRes.Res.Res.
rwrwrwrwrwrwrwrwrwrwrwrw
ST logo
ST logo

Bit 4 WWDG_SW: WWDG control mode option configuration bit

Bit 3 IWDG_SW: IWDG control mode option configuration bit

Bits 2:0 Reserved, must be kept at reset value.

6.10.13 FLASH option status register 2 (FLASH_OPTSR2_CUR)

Address offset: 0x070

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0x0000 0010 (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This read-only register reflects the current values of corresponding option bits.

(Register bits 0 to 31 are loaded with values from the flash memory at OBL)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SRAM2_ECCRes.Res.SRAM2_RSTSRAM1_RST
rrr

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

Bit 4 SRAM2_ECC: SRAM2 ECC detection and correction disable

Bits 3:2 Reserved, must be kept at reset value.

Bit 1 SRAM2_RST: SRAM2 erase when system reset

Bit 0 SRAM1_RST: SRAM1 erase upon system reset

6.10.14 FLASH option status register 2 (FLASH_OPTSR2_PRG)

Address offset: 0x074

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is used to program values in corresponding option bits. Values after reset reflects the current values of the corresponding option bits.

(Register bits 0 to 31 are loaded with values from the flash memory at OBL)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SRAM2_ECCRes.Res.SRAM2_RSTSRAM1_RST
rwrwrw

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

Bit 4 SRAM2_ECC: SRAM2 ECC detection and correction disable

0: SRAM2 ECC check enabled

1: SRAM2 ECC check disabled

Bits 3:2 Reserved, must be kept at reset value.

Bit 1 SRAM2_RST: SRAM2 erase when system reset

0: SRAM2 erased when a system reset occurs

1: SRAM2 not erased when a system reset occurs.

Note: SRAM erase is triggered by option-byte change operation, when enabling this feature.

Bit 0 SRAM1_RST: SRAM1 erase upon system reset

0: SRAM1 erased when a system reset occurs

1: SRAM1 not erased when a system reset occurs

Note: SRAM erase is triggered by option-byte change operation, when enabling this feature.

6.10.15 FLASH unique boot entry register (FLASH_BOOTR_CUR)

Address offset: 0x080

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0xFFFF FFB4 (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This register reflects the current values of corresponding option bits.

(Register bits 0 to 31 are loaded with values from the flash memory at OBL)

31302928272625242322212019181716
BOOTADD[23:8]
rrrrrrrrrrrrrrrr
1514131211109876543210
BOOTADD[7:0]BOOT_LOCK[7:0]
rrrrrrrrrrrrrrrr

Bits 31:8 BOOTADD[23:0]: Unique boot-entry address

These bits reflect the user memory boot address.

Caution: The BOOTADD must be a valid address within user main flash area. Otherwise, the boot stalls, and the flash memory becomes unreadable.

Note: The SRAM or EDATA areas cannot be selected as BOOTADD.

Bits 7:0 BOOT_LOCK[7:0]: BOOT0, BOOT_SEL, SWAP_BANK, and BOOTADD option settings lock

0xC3: BOOT0, BOOT_SEL, SWAP_BANK, and BOOTADD can still be modified following their individual rules.

0xB4: BOOT0, BOOT_SEL, SWAP_BANK, and BOOTADD are frozen.

6.10.16 FLASH unique boot entry address (FLASH_BOOTR_PRG)

Address offset: 0x084

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is used to program values in corresponding option bits.

(Register bits 0 to 31 are loaded with values from the flash memory at OBL)

31302928272625242322212019181716
BOOTADD[23:8]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
BOOTADD[7:0]BOOT_LOCK[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:8 BOOTADD[23:0]: Unique boot entry address

These bits reflect the user memory boot address.

Bits 7:0 BOOT_LOCK[7:0]: BOOT0, BOOT_SEL, SWAP_BANK, and BOOTADD option settings lock
0xC3: BOOT0, BOOT_SEL, SWAP_BANK, and BOOTADD can still be modified following their individual rules.

0xB4: BOOT0, BOOT_SEL, SWAP_BANK, and BOOTADD are frozen.

6.10.17 FLASH OTP block lock (FLASH_OTPBLR_CUR)

Address offset: 0x090

Reset value: 0x00XX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0xFFFF FFFF (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This register reflects the current values of corresponding option bits.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.LOCKBL[23:16]
rrrrrrrr
1514131211109876543210
LOCKBL[15:0]
rrrrrrrrrrrrrrrr

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

Bits 23:0 LOCKBL[23:0]: OTP block lock

Block n corresponds to OTP 16-bit word 96 × n to 96 × n+95.

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.

Also if not locked, it is not possible to erase OTP words.

6.10.18 FLASH OTP block lock (FLASH_OTPBLR_PRG)

Address offset: 0x094

Reset value: 0x00XX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is used to program values in corresponding option bits.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.LOCKBL[23:16]
rsrsrsrsrsrsrsrs
1514131211109876543210
LOCKBL[15:0]
rsrsrsrsrsrsrsrsrsrsrsrsrsrsrsrs

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

Bits 23:0 LOCKBL[23:0]: OTP block lock

Block n corresponds to OTP 16-bit word 96 × n to 96 × n+95.

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.

6.10.19 FLASH bootloader interface selection (FLASH_BL_COM_CFG_CUR)

Address offset: 0x098

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0xFFFF FFFF (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This register reflects the current values of corresponding option bits.

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

Bits 31:0 BL_COM_CFG[31:0]: Bootloader interface selection/configuration

This register is used to configure the set of interfaces on which the ST bootloader is active.

BL_COM_CFG[n] = 1 indicates that the corresponding interface is used by the bootloader.

BL_COM_CFG[n] = 0 indicates that the corresponding interface is not used by the bootloader. The GPIO remains in default state.

Note: For assignment of interfaces to register bits, see the bootloader documentation.

6.10.20 FLASH bootloader interface selection (FLASH_BL_COM_CFG_PRG)

Address offset: 0x09C

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is used to program values in the corresponding option bits.

31302928272625242322212019181716
BL_COM_CFG[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
BL_COM_CFG[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 BL_COM_CFG[31:0]: Bootloader interface selection/configuration

This register is used to configure the set of interfaces on which the ST bootloader is active.

BL_COM_CFG[n] = 1 indicates that the corresponding interface is used by the bootloader.

BL_COM_CFG[n] = 0 indicates that the corresponding interface is not used by the bootloader. The GPIO remains in default state.

Note: For assignment of interfaces to register bits see the bootloader documentation.

6.10.21 FLASH OEM key register 1 (FLASH_OEMKEYR1_PRG)

Address offset: 0xA4

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is read as zero.

31302928272625242322212019181716
OEMKEY[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
OEMKEY[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 OEMKEY[31:0]: Least significant bytes of OEMKEY

6.10.22 FLASH OEM key register 2 (FLASH_OEMKEYR2_PRG)

Address offset: 0xAC

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is read as zero.

31302928272625242322212019181716
OEMKEY[63:48]
wwwwwwwwwwwwwwww
1514131211109876543210
OEMKEY[47:32]
wwwwwwwwwwwwwwww

Bits 31:0 OEMKEY[63:32]: Mid-least significants bytes of OEMKEY

6.10.23 FLASH OEM key register 3 (FLASH_OEMKEYR3_PRG)

Address offset: 0xB4

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is read as zero.

31302928272625242322212019181716
OEMKEY[95:80]
wwwwwwwwwwwwwwww
1514131211109876543210
OEMKEY[79:64]
wwwwwwwwwwwwwwww

Bits 31:0 OEMKEY[95:64]: Mid-most significants bytes of OEMKEY

6.10.24 FLASH OEM key register 4 (FLASH_OEMKEYR4_PRG)

Address offset: 0xBC

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is read as zero.

31302928272625242322212019181716
OEMKEY[127:112]
wwwwwwwwwwwwwwww
1514131211109876543210
OEMKEY[111:96]
wwwwwwwwwwwwwwww

Bits 31:0 OEMKEY[127:96]: Most significants bytes of OEMKEY

ST logo
ST logo

6.10.25 FLASH boundary scan key register (FLASH_BSKEYR_PRG)

Address offset: 0xC4

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is read as zero.

31302928272625242322212019181716
BSKEY[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
BSKEY[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 BSKEY[31:0]: Boundary scan key

6.10.26 FLASH write page protection for bank1 (FLASH_WRP1R_CUR)

Address offset: 0x0E8

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0x0000 0000 (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This read-only register reflects the current values of corresponding option bits.

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

Bits 31:0 WRPSG1[31:0]: Bank1 page protection option status byte

Each bit reflects the write protection status of the corresponding group of pages in Bank1.

0: Write protected

1: Not write protected

Note: Refer to Table 29: Write-protection management for group definition.

6.10.27 FLASH write-page protection for bank1 (FLASH_WRP1R_PRG)

Address offset: 0x0EC

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. This register is used to program values in corresponding option bits.

31302928272625242322212019181716
WRPSG1[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
WRPSG1[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 WRPSG1[31:0]: Bank1 page protection option status byte
Setting these bits to 0 write-protects the corresponding pages in bank 1
0: Write protected
1: Not write protected

Note: Refer to Table 29: Write-protection management for group definition.

6.10.28 FLASH HDP bank1 register (FLASH_HDP1R_CUR)

Address offset: 0x0F8

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is initially loaded with the values of corresponding option bits.

Default value: 0x000F 0000 (value in case of double ECC issue during OBL) for STM32C53x/542.

Default value: 0x001F 0000 (value in case of double ECC issue during OBL) for STM32C55x/562.

Default value: 0x003F 0000 (value in case of double ECC issue during OBL) for STM32C59x/5A3.

ST production value: refer to Table 28: Option-byte organization

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_END[5:0]
rrrrrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_STRT[5:0]
rrrrrr

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

Bits 21:16 HDP1_END[5:0]: HDPL barrier end set in number of 8-Kbyte pages

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

Bits 5:0 HDP1_STRT[5:0]: HDPL barrier start set in number of 8-Kbyte pages

6.10.29 FLASH HDP bank1 register (FLASH_HDP1R_PRG)

Address offset: 0x0FC

Reset value: 0XXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR. Register is accessible only in HDPL1. In HDPL=2 or 3 it is WI, RAZ.

This register is used to program values in corresponding option bits.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_END[5:0]
rwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_STRT[5:0]
rwrwrwrwrwrw

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

Bits 21:16 HDP1_END[5:0]: Bank 1 HDPL barrier end set in number of 8-Kbyte pages

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

Bits 5:0 HDP1_STRT[5:0]: Bank 1 HDPL barrier start set in number of 8-Kbyte pages

6.10.30 FLASH ECC correction register (FLASH_ECCCORR)

Address offset: 0x100

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

31302928272625242322212019181716
Res.ECCCRes.Res.Res.Res.ECCCI
E
OTP_E
CC
SYSF_
ECC
BK_EC
C
EDATA_
ECC
Res.Res.Res.Res.Res.
rwrwrrrr
1514131211109876543210
ADDR_ECC[15:0]
rrrrrrrrrrrrrrrr

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.

Bits 20:16 Reserved, must be kept at reset value.

6.10.31 FLASH ECC detection register (FLASH_ECCDETR)

Address offset: 0x104

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

column_1column_2Bit 25 Bit 24 Bit 23 Bit 22 Bit 21 Bits 15:0ECCCIE OTP_ECC SYSF_ECC BK_ECC EDATA_ECCcolumn_5column_6column_7column_8column_9column_10column_11column_12column_13column_14column_15RM0522
31302928272625242322212019181716
ECCDRes.Res.Res.Res.Res.Res.OTP_ESYSF_BK_ECEDATA
CCECCC_ECCRes.Res.Res.Res.Res.
rc_w1rrrr
151413121110987 ADDR_ECC[15:0]6543210
rrrrrrrrrrrrrrrr
Bit 31ECCD:ECC detection set by hardware when two ECC errors have been detected
Bit 24OTP_ECC: OTP ECC error bit

Bits 30:25 Reserved, must be kept at reset value.

ST logo
ST logo

Bit 23 SYSF_ECC: ECC fail for double ECC error in system flash memory
This bit indicates if system flash memory is concerned by an ECC error.

Bit 22 BK_ECC: ECC fail bank for double ECC Error
This bit indicates which bank is concerned by an ECC error.

Bit 21 EDATA_ECC: ECC fail for double ECC error in FLASH data area
This bit indicates if FLASH EDATA sector is concerned by an ECC error.

Bits 20: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, this bitfield contains the address that generated the error. It is reset when the flag error is reset.

The FLASH 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).

6.10.32 FLASH ECC data (FLASH_ECCDR)

Address offset: 0x108

Reset value: 0x0000 0000

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DATA_ADDR_ECC[2:0]
rrr
1514131211109876543210
DATA_ECC[15:0]
rrrrrrrrrrrrrrrr

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

Bits 18:16 DATA_ADDR_ECC[2:0]: DATA ECC error address

When a double detection ECC error occurs on special areas with 6-bit ECC on 16-bit data (data area, read-only/OTP area), the position of the failing word on the FLASH line can be read to this register.

000: Double error on first 16-bit data or first 32-bit data accessed on the FLASH line

001: Double error on second 16-bit data accessed on the FLASH line

010: Double error on third 16-bit data or second 32-bit data accessed on the FLASH line

011: Double error on fourth 16-bit data accessed on the FLASH line

100: Double error on fifth 16-bit data or third 32-bit data accessed on the FLASH line

101: Double error on sixth 16-bit data

Note: If the data access was 16 bits, the corrupted word can be fully located. If access was 32 bits, use DATA_ECC value to discriminate which one of the two 16-bit word is faulty.

Bits 15:0 DATA_ECC[15:0]: ECC error data

When a double detection ECC error occurs on special areas with 6-bit ECC on 16-bit 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.

6.10.33 FLASH write page protection for bank2 (FLASH_WRP2R_CUR)

Address offset: 0x1E8

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0x0000 0000 (value in case of double ECC issue during OBL).

ST production value: refer to Table 28: Option-byte organization

This read-only register reflects the current values of corresponding option bits.

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

Bits 31:0 WRPSG2[31:0]: Bank2 page protection option status byte

Each bit reflects the write protection status of the corresponding group of pages in Bank2.

0: Write protected

1: Not write protected

Note: Refer to Table 29: Write-protection management group definition.

6.10.34 FLASH write page protection for bank2 (FLASH_WRP2R_PRG)

Address offset: 0x1EC

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

This register is used to program values in corresponding option bits.

31302928272625242322212019181716
WRPSG2[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
WRPSG2[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 WRPSG2[31:0]: Bank2 page protection option status byte

Setting WRPSG2 bits to 0 write protects the corresponding pages in bank 2

0: write protected;

1: not write protected

Note: Refer to Table 29: Write-protection management group definition.

6.10.35 FLASH HDP bank2 register (FLASH_HDP2R_CUR)

Address offset: 0x1F8

Reset value: 0xXXXX XXXX

This register is initially loaded with the values of corresponding option bits.

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

Default value: 0x000F 0000 (value in case of double ECC issue during OBL) for STM32C53x/542.

Default value: 0x001F 0000 (value in case of double ECC issue during OBL) for STM32C55x/562.

Default value: 0x003F 0000 (value in case of double ECC issue during OBL) for STM32C59x/5A3.

ST production value: refer to Table 28: Option-byte organization

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_END[5:0]
rrrrrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_STRT[5:0]
rrrrrr

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

Bits 21:16 HDP2_END[5:0]: Bank 2 HDPL barrier end set in number of 8-Kbyte pages

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

Bits 5:0 HDP2_STRT[5:0]: Bank 2 HDPL barrier start set in number of 8-Kbyte pages

6.10.36 FLASH HDP bank2 register (FLASH_HDP2R_PRG)

Address offset: 0x1FC

Reset value: 0xXXXX XXXX

This register can be protected against unprivileged access when PRIV = 1 in FLASH_PRIVCFGR.

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.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_END[5:0]
rwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_STRT[5:0]
rwrwrwrwrwrw

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

Bits 21:16 HDP2_END[5:0]: Bank 2 HDPL barrier end set in number of 8-Kbyte pages

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

Bits 5:0 HDP2_STRT[5:0]: Bank 2 HDPL barrier start set in number of 8-Kbyte pages

6.10.37 FLASH register map

Table 43. FLASH register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000FLASH_ACRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EMPTYRes.Res.Res.Res.Res.Res.Res.PRFTENRes.Res.WRHIGHFREQ[1:0]LATENCY[3:0]
Reset valuex0100111
0x004FLASH_KEYRKEY[31:0]
Reset value00000000000000000000000000000000
0x008Reserved
0x00CFLASH_OPTKEYROPTKEY[31:0]
Reset value00000000000000000000000000000000
0x010 - 0x014Reserved
0x018FLASH_OPSRCODE_OP[2:0]Res.Res.Res.Res.OTP_OPRes.BK_OPDATA_OPRes.Res.Res.Res.ADDR_OP[15:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxx
0x01CFLASH_OPTCRSWAP_BANKRes.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.OPTSTRTOPTLOCK
Reset valuex01
0x020FLASH_SRRes.Res.Res.Res.Res.Res.Res.Res.OPTCHANGEERRRes.Res.INCERRSTRBERRPGSERRWRPERREOPRes.Res.Res.Res.Res.Res.Res.BSLOCKOEMLOCKRes.Res.Res.Res.DBNERes.WBNE
Reset value00000000xx
0x024Reserved
ST logo
ST logo
Table 43. FLASH register map and reset values (continued)
OffsetRegister name313029282726252423222120191817161514131211109876543210
0x028FLASH_CRBKSELRes.EDATASELRes.Res.Res.Res.Res.OPTCHANGEERRIERes.Res.INCERIESTRBERRIEPGSERRIEWRPERIEEOPIEMERRes.Res.PNB[6:0]STRTFWBERPERPGLOCK
Reset value0000000000000000000001
0x02CReserved
0x030FLASH_CCRRes.Res.Res.Res.Res.Res.Res.Res.CLR_OPTCHANGEERRRes.Res.CLR_INCERRCLR_STRBERRCLR_PGSERRCLR_WRPERRCLR_EOPRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value000000
0x034 -
0x038
Reserved
0x03CFLASH_PRIVCFGRRes.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.PRIVRes.
Reset value0
0x040 -
0x044
Reserved
0x048FLASH_HDPEXTRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_EXT[5:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_EXT[5:0]
Reset value000000000000
0x04CReserved
0x050FLASH_OPTSR_CURSWAP_BANKSINGLE_BANKEDATA_ENRes.Res.Res.Res.Res.BOOT0BOOT_SELIWDG_STDBYIWDG_STOPRes.Res.Res.Res.RDP_LEVEL[7:0]NRST_STDBYNRST_STOPRes.WWDG_SWIWDG_SWRes.Res.Res.
Reset valuexxxxxxxxxxxxxxxxxxx
0x054FLASH_OPTSR_PRGSWAP_BANKSINGLE_BANKEDATA_ENRes.Res.Res.Res.Res.BOOT0BOOT_SELIWDG_STDBYIWDG_STOPRes.Res.Res.Res.RDP_LEVEL[7:0]NRST_STDBYNRST_STOPRes.WWDG_SWIWDG_SWRes.Res.Res.
Reset valuexxxxxxxxxxxxxxxxxxx
0x058 -
0x06C
Reserved
0x070FLASH_OPTSR2_CURRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SRAM2_ECCRes.Res.SRAM2_RSTSRAM1_RSTRes.
Reset valuexxx

Table 43. FLASH register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x074FLASH_OPTSR2_PRGRes.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.SRAM2_ECC
Reset valuex
0x078 - 0x07CReserved
0x080FLASH_BOOTR_CURBOOTADD[23:0]BOOT_LOCK[7:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x084FLASH_BOOTR_PRGBOOTADD[23:0]BOOT_LOCK[7:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x088 - 0x08CReserved
0x090FLASH_OTPBLR_CURRes.Res.Res.Res.Res.Res.Res.Res.Res.LOCKBL[23:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxx
0x094FLASH_OTPBLR_PRGRes.Res.Res.Res.Res.Res.Res.Res.Res.LOCKBL[23:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxx
0x098FLASH_BL_COM_CFG_CURBL_COM_CFG[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x09CFLASH_BL_COM_CFG_PRGBL_COM_CFG[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0A0Reserved
0x0A4FLASH_OEMKEYR1_PRGOEMKEY[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0A8Reserved
0x0ACFLASH_OEMKEYR2_PRGOEMKEY[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0B0Reserved
0x0B4FLASH_OEMKEYR3_PRGOEMKEY[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0B8Reserved
0x0BCFLASH_OEMKEYR4_PRGOEMKEY[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0C0Reserved
ST logo
ST logo

Table 43. FLASH register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x0C4FLASH_BSKEYR_PRGBSKEY[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0C8 - 0x0E4Reserved
0x0E8FLASH_WRP1R_CURWRPSG1[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0ECFLASH_WRP1R_PRGWRPSG1[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x0F0 - 0x0F4Reserved
0x0F8FLASH_HDP1R_CURRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_END[5:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_STRT[5:0]
Reset valuexxxxxxxxxxxx
0x0FCFLASH_HDP1R_PRGRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_END[5:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP1_STRT[5:0]
Reset valuexxxxxxxxxxxx
0x100FLASH_ECCCORRRes.ECCCRes.Res.Res.Res.Res.ECCIEOTP_ECCSYSF_ECCBK_ECCEDATA_ECCRes.Res.Res.Res.Res.ADDR_ECC[15:0]
Reset value000000000000000000000
0x104FLASH_ECCDETRECCDRes.Res.Res.Res.Res.Res.Res.OTP_ECCSYSF_ECCBK_ECCEDATA_ECCRes.Res.Res.Res.Res.ADDR_ECC[15:0]
Reset value00000000000000000000
0x108FLASH_ECCDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DATA_ADDR_ECC[2:0]DATA_ECC[15:0]
Reset value0000000000000000000
0x10C - 0x1E4Reserved
0x1E8FLASH_WRP2R_CURWRPSG2[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x1ECFLASH_WRP2R_PRGWRPSG2[31:0]
Reset valuexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0x1F0 - 0x1F4Reserved

Table 43. FLASH register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x1F8FLASH_HDP2R_CURRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_END[5:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_STRT[5:0]
Reset valuexxxxxxxxxxxx
0x1FCFLASH_HDP2R_PRGRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_END[5:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.HDP2_STRT[5:0]
Reset valuexxxxxxxxxxxx

Refer to Section 2.2: Memory organization for the register boundary addresses.