29.4.3.4 Lock Bit Protection

The Flash memory features 128 lock bits.

Lock bits are associated with several pages in the embedded Flash memory plane. This defines lock regions in the embedded Flash memory plane. They prevent writing/erasing protected pages.

The lock sequence is the following:

  1. Execute the ‘Set Lock Bit’ command by writing EEFC_FCR.FCMD with the SLB command and EEFC_FCR.FARG with a page number to be protected.
  2. When the locking completes, the bit EEFC_FSR.FRDY rises. If an interrupt was enabled by setting the bit EEFC_FMR.FRDY, the interrupt line of the interrupt controller is activated.
  3. The result of the SLB command can be checked by running a ‘Get Lock Bit’ (GLB) command.
    Note: The value of the FARG argument passed together with the SLB command must not exceed the highest lock bit index available in the product.

Three errors can be detected in EEFC_FSR after a programming sequence:

  • Command error: a wrong keyword was written in EEFC_FCR.
  • Flash error: at the end of the programming, the EraseVerify or WriteVerify test of the Flash memory has failed.
  • ECC error on lock bits: a single or multiple ECC error is present, as indicated by MECCEMSBL, SECCEMSBL, MECCELSBL or SECCELSBL.

It is possible to clear lock bits previously set. After the lock bits are cleared, the locked region can be erased or programmed. The unlock sequence is the following:

  1. Execute the ‘Clear Lock Bit’ command by writing EEFC_FCR.FCMD with the CLB command and EEFC_FCR.FARG with a page number to be unprotected.
  2. When the unlock completes, the bit EEFC_FSR.FRDY rises. If an interrupt was enabled by setting the bit EEFC_FMR.FRDY, the interrupt line of the interrupt controller is activated.
    Note: The value of the FARG argument passed together with the CLB command must not exceed the highest lock bit index available in the product.

Three errors can be detected in EEFC_FSR after a programming sequence:

  • Command error: a wrong keyword was written in EEFC_FCR.
  • Flash error: at the end of the programming, the EraseVerify or WriteVerify test of the Flash memory has failed.
  • ECC error on lock bits: a single or multiple ECC error is present, as indicated by MECCEMSBL, SECCEMSBL, MECCELSBL or SECCELSBL.

The status of lock bits can be returned by the SEFC. The ‘Get Lock Bit’ sequence is the following:

  1. Execute the ‘Get Lock Bit’ command by writing EEFC_FCR.FCMD with the GLB command. Field EEFC_FCR.FARG is meaningless.
  2. Lock bits can be read by the software application in EEFC_FRR. The first word read corresponds to the first 32 lock bits; the next reads provide the next 32 lock bits as long as it is meaningful. Extra reads to EEFC_FRR return 0.

For example, if the third bit of the first word read in EEFC_FRR is set, the third lock region is locked.

One error can be detected in EEFC_FSR after a programming sequence:

  • Command error: a wrong keyword was written in EEFC_FCR.
    Note: Access to the Flash in read is permitted when a ‘Set Lock Bit’, ‘Clear Lock Bit’ or ‘Get Lock Bit’ command is executed, but the access is stalled until the command is completed.