From ce703c88d0d6c3328834fab016eddc838c6c6b4b Mon Sep 17 00:00:00 2001 From: alexandrovilya Date: Tue, 20 Oct 2020 11:05:08 +0300 Subject: [cm3cpp]: Add lock_block method --- cm3cpp/flash_otp.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cm3cpp/flash_otp.hpp b/cm3cpp/flash_otp.hpp index 159d072..f0d4909 100644 --- a/cm3cpp/flash_otp.hpp +++ b/cm3cpp/flash_otp.hpp @@ -129,12 +129,30 @@ class FlashOtp FLASH_SR |= (uint32_t)flag; } + static void lock_block(OtpBlock block) + { + flash_unlock(); + clear_flag(Flag::EOP); + clear_flag(Flag::OPERR); + clear_flag(Flag::WRPERR); + clear_flag(Flag::PGAERR); + clear_flag(Flag::PGPERR); + clear_flag(Flag::PGSERR); + flash_wait_for_last_operation(); + uint32_t address = _OTP_LOCK_ADDR + static_cast(block); + __disable_irq(); + flash_program_byte(address, _OTP_LOCK_BLOCK); + __enable_irq(); + flash_lock(); + } + private: static constexpr uint32_t _OTP_START_ADDR = (0x1FFF7800); static constexpr uint32_t _OTP_LOCK_ADDR = (0x1FFF7A00); static constexpr uint32_t _OTP_BLOCKS = 16; static constexpr uint32_t _OTP_BYTES_IN_BLOCK = 32; static constexpr uint32_t _OTP_SIZE = (_OTP_BLOCKS * _OTP_BYTES_IN_BLOCK); + static constexpr uint8_t _OTP_LOCK_BLOCK = 0x00; }; } /* namespace flash */ -- cgit v1.2.3