为了防止OTP误写,可以使用如下MPU的方式保护一下:
static void OtpProtectByMpu(void)
{
ARM_MPU_Region_t mpuTable[1] = {
// BASE SH RO NP XN LIMIT ATTR
{ .RBAR = ARM_MPU_RBAR(0x10003A00U, ARM_MPU_SH_NON, 1UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x10003BFFU, 0UL) },
};
ARM_MPU_SetMemAttr(0, ARM_MPU_ATTR( /* Normal memory */
ARM_MPU_ATTR_MEMORY_(1U, 0U, 1U, 0U), /* Outer Write-Through non-transient with read allocate and write not allocate */
ARM_MPU_ATTR_MEMORY_(1U, 0U, 1U, 0U) /* Inner Write-Through non-transient with read allocate and write not allocate */
));
ARM_MPU_Load(0U, mpuTable, 1);
ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk);
}